Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 <RenderScriptDefines.h> |
| 21 | |
| 22 | namespace android { |
| 23 | namespace renderscript { |
| 24 | |
| 25 | class Context; |
| 26 | class ObjectBase; |
| 27 | class Element; |
| 28 | class Type; |
| 29 | class Allocation; |
| 30 | class Script; |
| 31 | class ScriptC; |
Alex Sakhartchouk | 4385054 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 32 | class Program; |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 33 | class ProgramStore; |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 34 | class ProgramRaster; |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 35 | class ProgramVertex; |
| 36 | class ProgramFragment; |
| 37 | class Mesh; |
Alex Sakhartchouk | 4385054 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 38 | class Sampler; |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 39 | class FBOCache; |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 40 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 41 | typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); |
| 42 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 43 | /** |
| 44 | * Script management functions |
| 45 | */ |
| 46 | typedef struct { |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 47 | bool (*initGraphics)(const Context *); |
| 48 | void (*shutdownGraphics)(const Context *); |
Alex Sakhartchouk | 6c72eec | 2011-05-17 12:32:47 -0700 | [diff] [blame] | 49 | bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow); |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 50 | void (*swap)(const Context *); |
| 51 | |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 52 | void (*shutdownDriver)(Context *); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 53 | void (*getVersion)(unsigned int *major, unsigned int *minor); |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 54 | void (*setPriority)(const Context *, int32_t priority); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 55 | |
| 56 | |
| 57 | |
| 58 | struct { |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 59 | bool (*init)(const Context *rsc, ScriptC *s, |
| 60 | char const *resName, |
| 61 | char const *cacheDir, |
| 62 | uint8_t const *bitcode, |
| 63 | size_t bitcodeSize, |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 64 | uint32_t flags); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 65 | |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 66 | void (*invokeFunction)(const Context *rsc, Script *s, |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 67 | uint32_t slot, |
| 68 | const void *params, |
| 69 | size_t paramLength); |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 70 | int (*invokeRoot)(const Context *rsc, Script *s); |
| 71 | void (*invokeForEach)(const Context *rsc, |
| 72 | Script *s, |
Jason Sams | 92b0eab | 2011-07-13 11:26:26 -0700 | [diff] [blame] | 73 | uint32_t slot, |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 74 | const Allocation * ain, |
| 75 | Allocation * aout, |
| 76 | const void * usr, |
| 77 | uint32_t usrLen, |
| 78 | const RsScriptCall *sc); |
| 79 | void (*invokeInit)(const Context *rsc, Script *s); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 80 | |
| 81 | void (*setGlobalVar)(const Context *rsc, const Script *s, |
| 82 | uint32_t slot, |
| 83 | void *data, |
| 84 | size_t dataLength); |
| 85 | void (*setGlobalBind)(const Context *rsc, const Script *s, |
| 86 | uint32_t slot, |
| 87 | void *data); |
| 88 | void (*setGlobalObj)(const Context *rsc, const Script *s, |
| 89 | uint32_t slot, |
| 90 | ObjectBase *data); |
| 91 | |
| 92 | void (*destroy)(const Context *rsc, Script *s); |
| 93 | } script; |
| 94 | |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 95 | struct { |
Jason Sams | 7e8aae7 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 96 | bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero); |
| 97 | void (*destroy)(const Context *rsc, Allocation *alloc); |
| 98 | |
| 99 | void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType, |
| 100 | bool zeroNew); |
| 101 | void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src); |
| 102 | void (*markDirty)(const Context *rsc, const Allocation *alloc); |
| 103 | |
| 104 | void (*data1D)(const Context *rsc, const Allocation *alloc, |
| 105 | uint32_t xoff, uint32_t lod, uint32_t count, |
| 106 | const void *data, uint32_t sizeBytes); |
| 107 | void (*data2D)(const Context *rsc, const Allocation *alloc, |
| 108 | uint32_t xoff, uint32_t yoff, uint32_t lod, |
| 109 | RsAllocationCubemapFace face, uint32_t w, uint32_t h, |
| 110 | const void *data, uint32_t sizeBytes); |
| 111 | void (*data3D)(const Context *rsc, const Allocation *alloc, |
| 112 | uint32_t xoff, uint32_t yoff, uint32_t zoff, |
| 113 | uint32_t lod, RsAllocationCubemapFace face, |
| 114 | uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes); |
| 115 | |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 116 | // Allocation to allocation copies |
| 117 | void (*allocData1D)(const Context *rsc, |
| 118 | const Allocation *dstAlloc, |
| 119 | uint32_t dstXoff, uint32_t dstLod, uint32_t count, |
| 120 | const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod); |
| 121 | void (*allocData2D)(const Context *rsc, |
| 122 | const Allocation *dstAlloc, |
| 123 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod, |
| 124 | RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h, |
| 125 | const Allocation *srcAlloc, |
| 126 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod, |
| 127 | RsAllocationCubemapFace srcFace); |
| 128 | void (*allocData3D)(const Context *rsc, |
| 129 | const Allocation *dstAlloc, |
| 130 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, |
| 131 | uint32_t dstLod, RsAllocationCubemapFace dstFace, |
| 132 | uint32_t w, uint32_t h, uint32_t d, |
| 133 | const Allocation *srcAlloc, |
| 134 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, |
| 135 | uint32_t srcLod, RsAllocationCubemapFace srcFace); |
| 136 | |
Jason Sams | 7e8aae7 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 137 | void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x, |
| 138 | const void *data, uint32_t elementOff, uint32_t sizeBytes); |
| 139 | void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y, |
| 140 | const void *data, uint32_t elementOff, uint32_t sizeBytes); |
| 141 | |
| 142 | |
| 143 | } allocation; |
| 144 | |
| 145 | struct { |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 146 | bool (*init)(const Context *rsc, const ProgramStore *ps); |
| 147 | void (*setActive)(const Context *rsc, const ProgramStore *ps); |
| 148 | void (*destroy)(const Context *rsc, const ProgramStore *ps); |
| 149 | } store; |
| 150 | |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 151 | struct { |
| 152 | bool (*init)(const Context *rsc, const ProgramRaster *ps); |
| 153 | void (*setActive)(const Context *rsc, const ProgramRaster *ps); |
| 154 | void (*destroy)(const Context *rsc, const ProgramRaster *ps); |
| 155 | } raster; |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 156 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 157 | struct { |
| 158 | bool (*init)(const Context *rsc, const ProgramVertex *pv, |
| 159 | const char* shader, uint32_t shaderLen); |
| 160 | void (*setActive)(const Context *rsc, const ProgramVertex *pv); |
| 161 | void (*destroy)(const Context *rsc, const ProgramVertex *pv); |
| 162 | } vertex; |
| 163 | |
| 164 | struct { |
| 165 | bool (*init)(const Context *rsc, const ProgramFragment *pf, |
| 166 | const char* shader, uint32_t shaderLen); |
| 167 | void (*setActive)(const Context *rsc, const ProgramFragment *pf); |
| 168 | void (*destroy)(const Context *rsc, const ProgramFragment *pf); |
| 169 | } fragment; |
| 170 | |
| 171 | struct { |
| 172 | bool (*init)(const Context *rsc, const Mesh *m); |
| 173 | void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len); |
| 174 | void (*destroy)(const Context *rsc, const Mesh *m); |
| 175 | } mesh; |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 176 | |
Alex Sakhartchouk | 4385054 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 177 | struct { |
| 178 | bool (*init)(const Context *rsc, const Sampler *m); |
| 179 | void (*destroy)(const Context *rsc, const Sampler *m); |
| 180 | } sampler; |
| 181 | |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 182 | struct { |
| 183 | bool (*init)(const Context *rsc, const FBOCache *fb); |
| 184 | void (*setActive)(const Context *rsc, const FBOCache *fb); |
| 185 | void (*destroy)(const Context *rsc, const FBOCache *fb); |
| 186 | } framebuffer; |
| 187 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 188 | } RsdHalFunctions; |
| 189 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 190 | |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | |
| 195 | bool rsdHalInit(android::renderscript::Context *, uint32_t version_major, uint32_t version_minor); |
| 196 | |
| 197 | #endif |
| 198 | |