rs_hal.h revision 4b3c34e6833e39bc89c2128002806b654b8e623d
1/* 2 * Copyright (C) 2011-2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef RS_HAL_H 18#define RS_HAL_H 19 20#include <rsDefines.h> 21 22struct ANativeWindow; 23 24namespace android { 25namespace renderscript { 26 27class Context; 28class ObjectBase; 29class Element; 30class Type; 31class Allocation; 32class Script; 33class ScriptKernelID; 34class ScriptFieldID; 35class ScriptMethodID; 36class ScriptC; 37class ScriptGroup; 38class Path; 39class Program; 40class ProgramStore; 41class ProgramRaster; 42class ProgramVertex; 43class ProgramFragment; 44class Mesh; 45class Sampler; 46class FBOCache; 47 48typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); 49 50/** 51 * Script management functions 52 */ 53typedef struct { 54 bool (*initGraphics)(const Context *); 55 void (*shutdownGraphics)(const Context *); 56 bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow); 57 void (*swap)(const Context *); 58 59 void (*shutdownDriver)(Context *); 60 void (*getVersion)(unsigned int *major, unsigned int *minor); 61 void (*setPriority)(const Context *, int32_t priority); 62 63 void* (*allocRuntimeMem)(size_t size, uint32_t flags); 64 void (*freeRuntimeMem)(void* ptr); 65 66 struct { 67 bool (*init)(const Context *rsc, ScriptC *s, 68 char const *resName, 69 char const *cacheDir, 70 uint8_t const *bitcode, 71 size_t bitcodeSize, 72 uint32_t flags); 73 bool (*initIntrinsic)(const Context *rsc, Script *s, 74 RsScriptIntrinsicID iid, 75 Element *e); 76 77 void (*invokeFunction)(const Context *rsc, Script *s, 78 uint32_t slot, 79 const void *params, 80 size_t paramLength); 81 int (*invokeRoot)(const Context *rsc, Script *s); 82 void (*invokeForEach)(const Context *rsc, 83 Script *s, 84 uint32_t slot, 85 const Allocation * ain, 86 Allocation * aout, 87 const void * usr, 88 size_t usrLen, 89 const RsScriptCall *sc); 90 void (*invokeInit)(const Context *rsc, Script *s); 91 void (*invokeFreeChildren)(const Context *rsc, Script *s); 92 93 void (*setGlobalVar)(const Context *rsc, const Script *s, 94 uint32_t slot, 95 void *data, 96 size_t dataLength); 97 void (*getGlobalVar)(const Context *rsc, const Script *s, 98 uint32_t slot, 99 void *data, 100 size_t dataLength); 101 void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s, 102 uint32_t slot, 103 void *data, 104 size_t dataLength, 105 const Element *e, 106 const uint32_t *dims, 107 size_t dimLength); 108 void (*setGlobalBind)(const Context *rsc, const Script *s, 109 uint32_t slot, 110 Allocation *data); 111 void (*setGlobalObj)(const Context *rsc, const Script *s, 112 uint32_t slot, 113 ObjectBase *data); 114 115 void (*destroy)(const Context *rsc, Script *s); 116 void (*invokeForEachMulti)(const Context *rsc, 117 Script *s, 118 uint32_t slot, 119 const Allocation ** ains, 120 size_t inLen, 121 Allocation * aout, 122 const void * usr, 123 size_t usrLen, 124 const RsScriptCall *sc); 125 } script; 126 127 struct { 128 bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero); 129 void (*destroy)(const Context *rsc, Allocation *alloc); 130 uint32_t (*grallocBits)(const Context *rsc, Allocation *alloc); 131 132 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType, 133 bool zeroNew); 134 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src); 135 void (*markDirty)(const Context *rsc, const Allocation *alloc); 136 137 void (*setSurface)(const Context *rsc, Allocation *alloc, ANativeWindow *sur); 138 void (*ioSend)(const Context *rsc, Allocation *alloc); 139 140 /** 141 * A new gralloc buffer is in use. The pointers and strides in 142 * mHal.drvState.lod[0-2] will be updated with the new values. 143 * 144 * The new gralloc handle is provided in mHal.state.nativeBuffer 145 * 146 */ 147 void (*ioReceive)(const Context *rsc, Allocation *alloc); 148 149 void (*data1D)(const Context *rsc, const Allocation *alloc, 150 uint32_t xoff, uint32_t lod, size_t count, 151 const void *data, size_t sizeBytes); 152 void (*data2D)(const Context *rsc, const Allocation *alloc, 153 uint32_t xoff, uint32_t yoff, uint32_t lod, 154 RsAllocationCubemapFace face, uint32_t w, uint32_t h, 155 const void *data, size_t sizeBytes, size_t stride); 156 void (*data3D)(const Context *rsc, const Allocation *alloc, 157 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, 158 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, 159 size_t stride); 160 161 void (*read1D)(const Context *rsc, const Allocation *alloc, 162 uint32_t xoff, uint32_t lod, size_t count, 163 void *data, size_t sizeBytes); 164 void (*read2D)(const Context *rsc, const Allocation *alloc, 165 uint32_t xoff, uint32_t yoff, uint32_t lod, 166 RsAllocationCubemapFace face, uint32_t w, uint32_t h, 167 void *data, size_t sizeBytes, size_t stride); 168 void (*read3D)(const Context *rsc, const Allocation *alloc, 169 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, 170 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, 171 size_t stride); 172 173 // Lock and unlock make a 1D region of memory available to the CPU 174 // for direct access by pointer. Once unlock is called control is 175 // returned to the SOC driver. 176 void * (*lock1D)(const Context *rsc, const Allocation *alloc); 177 void (*unlock1D)(const Context *rsc, const Allocation *alloc); 178 179 // Allocation to allocation copies 180 void (*allocData1D)(const Context *rsc, 181 const Allocation *dstAlloc, 182 uint32_t dstXoff, uint32_t dstLod, size_t count, 183 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod); 184 void (*allocData2D)(const Context *rsc, 185 const Allocation *dstAlloc, 186 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod, 187 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h, 188 const Allocation *srcAlloc, 189 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod, 190 RsAllocationCubemapFace srcFace); 191 void (*allocData3D)(const Context *rsc, 192 const Allocation *dstAlloc, 193 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, 194 uint32_t dstLod, 195 uint32_t w, uint32_t h, uint32_t d, 196 const Allocation *srcAlloc, 197 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, 198 uint32_t srcLod); 199 200 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x, 201 const void *data, uint32_t elementOff, size_t sizeBytes); 202 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y, 203 const void *data, uint32_t elementOff, size_t sizeBytes); 204 205 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc); 206 } allocation; 207 208 struct { 209 bool (*init)(const Context *rsc, const ProgramStore *ps); 210 void (*setActive)(const Context *rsc, const ProgramStore *ps); 211 void (*destroy)(const Context *rsc, const ProgramStore *ps); 212 } store; 213 214 struct { 215 bool (*init)(const Context *rsc, const ProgramRaster *ps); 216 void (*setActive)(const Context *rsc, const ProgramRaster *ps); 217 void (*destroy)(const Context *rsc, const ProgramRaster *ps); 218 } raster; 219 220 struct { 221 bool (*init)(const Context *rsc, const ProgramVertex *pv, 222 const char* shader, size_t shaderLen, 223 const char** textureNames, size_t textureNamesCount, 224 const size_t *textureNamesLength); 225 void (*setActive)(const Context *rsc, const ProgramVertex *pv); 226 void (*destroy)(const Context *rsc, const ProgramVertex *pv); 227 } vertex; 228 229 struct { 230 bool (*init)(const Context *rsc, const ProgramFragment *pf, 231 const char* shader, size_t shaderLen, 232 const char** textureNames, size_t textureNamesCount, 233 const size_t *textureNamesLength); 234 void (*setActive)(const Context *rsc, const ProgramFragment *pf); 235 void (*destroy)(const Context *rsc, const ProgramFragment *pf); 236 } fragment; 237 238 struct { 239 bool (*init)(const Context *rsc, const Mesh *m); 240 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len); 241 void (*destroy)(const Context *rsc, const Mesh *m); 242 } mesh; 243 244 struct { 245 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops); 246 bool (*initDynamic)(const Context *rsc, const Path *m); 247 void (*draw)(const Context *rsc, const Path *m); 248 void (*destroy)(const Context *rsc, const Path *m); 249 } path; 250 251 struct { 252 bool (*init)(const Context *rsc, const Sampler *m); 253 void (*destroy)(const Context *rsc, const Sampler *m); 254 } sampler; 255 256 struct { 257 bool (*init)(const Context *rsc, const FBOCache *fb); 258 void (*setActive)(const Context *rsc, const FBOCache *fb); 259 void (*destroy)(const Context *rsc, const FBOCache *fb); 260 } framebuffer; 261 262 struct { 263 bool (*init)(const Context *rsc, ScriptGroup *sg); 264 void (*setInput)(const Context *rsc, const ScriptGroup *sg, 265 const ScriptKernelID *kid, Allocation *); 266 void (*setOutput)(const Context *rsc, const ScriptGroup *sg, 267 const ScriptKernelID *kid, Allocation *); 268 void (*execute)(const Context *rsc, const ScriptGroup *sg); 269 void (*destroy)(const Context *rsc, const ScriptGroup *sg); 270 } scriptgroup; 271 272 void (*finish)(const Context *rsc); 273} RsdHalFunctions; 274 275 276} 277} 278 279#ifdef __cplusplus 280extern "C" { 281#endif 282 283bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor); 284 285#ifdef __cplusplus 286} 287#endif 288 289#endif 290