• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 struct ANativeWindow;
23 
24 namespace android {
25 namespace renderscript {
26 
27 class Context;
28 class ObjectBase;
29 class Element;
30 class Type;
31 class Allocation;
32 class Script;
33 class ScriptKernelID;
34 class ScriptFieldID;
35 class ScriptMethodID;
36 class ScriptC;
37 class ScriptGroup;
38 class Path;
39 class Program;
40 class ProgramStore;
41 class ProgramRaster;
42 class ProgramVertex;
43 class ProgramFragment;
44 class Mesh;
45 class Sampler;
46 class FBOCache;
47 
48 typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName);
49 
50 typedef struct {
51     const void *in;
52     void *out;
53     const void *usr;
54     size_t usrLen;
55     uint32_t x;
56     uint32_t y;
57     uint32_t z;
58     uint32_t lod;
59     RsAllocationCubemapFace face;
60     uint32_t ar[16];
61     uint32_t lid;
62 
63     uint32_t dimX;
64     uint32_t dimY;
65     uint32_t dimZ;
66     uint32_t dimArray;
67 
68     const uint8_t *ptrIn;
69     uint8_t *ptrOut;
70     uint32_t eStrideIn;
71     uint32_t eStrideOut;
72     uint32_t yStrideIn;
73     uint32_t yStrideOut;
74     uint32_t slot;
75 } RsForEachStubParamStruct;
76 
77 /**
78  * Script management functions
79  */
80 typedef struct {
81     bool (*initGraphics)(const Context *);
82     void (*shutdownGraphics)(const Context *);
83     bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow);
84     void (*swap)(const Context *);
85 
86     void (*shutdownDriver)(Context *);
87     void (*getVersion)(unsigned int *major, unsigned int *minor);
88     void (*setPriority)(const Context *, int32_t priority);
89 
90     void* (*allocRuntimeMem)(size_t size, uint32_t flags);
91     void (*freeRuntimeMem)(void* ptr);
92 
93     struct {
94         bool (*init)(const Context *rsc, ScriptC *s,
95                      char const *resName,
96                      char const *cacheDir,
97                      uint8_t const *bitcode,
98                      size_t bitcodeSize,
99                      uint32_t flags);
100         bool (*initIntrinsic)(const Context *rsc, Script *s,
101                               RsScriptIntrinsicID iid,
102                               Element *e);
103 
104         void (*invokeFunction)(const Context *rsc, Script *s,
105                                uint32_t slot,
106                                const void *params,
107                                size_t paramLength);
108         int (*invokeRoot)(const Context *rsc, Script *s);
109         void (*invokeForEach)(const Context *rsc,
110                               Script *s,
111                               uint32_t slot,
112                               const Allocation * ain,
113                               Allocation * aout,
114                               const void * usr,
115                               size_t usrLen,
116                               const RsScriptCall *sc);
117         void (*invokeInit)(const Context *rsc, Script *s);
118         void (*invokeFreeChildren)(const Context *rsc, Script *s);
119 
120         void (*setGlobalVar)(const Context *rsc, const Script *s,
121                              uint32_t slot,
122                              void *data,
123                              size_t dataLength);
124         void (*getGlobalVar)(const Context *rsc, const Script *s,
125                              uint32_t slot,
126                              void *data,
127                              size_t dataLength);
128         void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s,
129                                          uint32_t slot,
130                                          void *data,
131                                          size_t dataLength,
132                                          const Element *e,
133                                          const size_t *dims,
134                                          size_t dimLength);
135         void (*setGlobalBind)(const Context *rsc, const Script *s,
136                               uint32_t slot,
137                               Allocation *data);
138         void (*setGlobalObj)(const Context *rsc, const Script *s,
139                              uint32_t slot,
140                              ObjectBase *data);
141 
142         void (*destroy)(const Context *rsc, Script *s);
143     } script;
144 
145     struct {
146         bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
147         void (*destroy)(const Context *rsc, Allocation *alloc);
148 
149         void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
150                        bool zeroNew);
151         void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
152         void (*markDirty)(const Context *rsc, const Allocation *alloc);
153 
154         void * (*getSurface)(const Context *rsc, const Allocation *alloc);
155         void (*setSurface)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
156         void (*ioSend)(const Context *rsc, Allocation *alloc);
157         void (*ioReceive)(const Context *rsc, Allocation *alloc);
158 
159         void (*data1D)(const Context *rsc, const Allocation *alloc,
160                        uint32_t xoff, uint32_t lod, size_t count,
161                        const void *data, size_t sizeBytes);
162         void (*data2D)(const Context *rsc, const Allocation *alloc,
163                        uint32_t xoff, uint32_t yoff, uint32_t lod,
164                        RsAllocationCubemapFace face, uint32_t w, uint32_t h,
165                        const void *data, size_t sizeBytes, size_t stride);
166         void (*data3D)(const Context *rsc, const Allocation *alloc,
167                        uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
168                        uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes,
169                        size_t stride);
170 
171         void (*read1D)(const Context *rsc, const Allocation *alloc,
172                        uint32_t xoff, uint32_t lod, size_t count,
173                        void *data, size_t sizeBytes);
174         void (*read2D)(const Context *rsc, const Allocation *alloc,
175                        uint32_t xoff, uint32_t yoff, uint32_t lod,
176                        RsAllocationCubemapFace face, uint32_t w, uint32_t h,
177                        void *data, size_t sizeBytes, size_t stride);
178         void (*read3D)(const Context *rsc, const Allocation *alloc,
179                        uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
180                        uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes,
181                        size_t stride);
182 
183         // Lock and unlock make a 1D region of memory available to the CPU
184         // for direct access by pointer.  Once unlock is called control is
185         // returned to the SOC driver.
186         void * (*lock1D)(const Context *rsc, const Allocation *alloc);
187         void (*unlock1D)(const Context *rsc, const Allocation *alloc);
188 
189         // Allocation to allocation copies
190         void (*allocData1D)(const Context *rsc,
191                             const Allocation *dstAlloc,
192                             uint32_t dstXoff, uint32_t dstLod, size_t count,
193                             const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
194         void (*allocData2D)(const Context *rsc,
195                             const Allocation *dstAlloc,
196                             uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
197                             RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
198                             const Allocation *srcAlloc,
199                             uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
200                             RsAllocationCubemapFace srcFace);
201         void (*allocData3D)(const Context *rsc,
202                             const Allocation *dstAlloc,
203                             uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
204                             uint32_t dstLod,
205                             uint32_t w, uint32_t h, uint32_t d,
206                             const Allocation *srcAlloc,
207                             uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
208                             uint32_t srcLod);
209 
210         void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
211                               const void *data, uint32_t elementOff, size_t sizeBytes);
212         void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
213                               const void *data, uint32_t elementOff, size_t sizeBytes);
214 
215         void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
216     } allocation;
217 
218     struct {
219         bool (*init)(const Context *rsc, const ProgramStore *ps);
220         void (*setActive)(const Context *rsc, const ProgramStore *ps);
221         void (*destroy)(const Context *rsc, const ProgramStore *ps);
222     } store;
223 
224     struct {
225         bool (*init)(const Context *rsc, const ProgramRaster *ps);
226         void (*setActive)(const Context *rsc, const ProgramRaster *ps);
227         void (*destroy)(const Context *rsc, const ProgramRaster *ps);
228     } raster;
229 
230     struct {
231         bool (*init)(const Context *rsc, const ProgramVertex *pv,
232                      const char* shader, size_t shaderLen,
233                      const char** textureNames, size_t textureNamesCount,
234                      const size_t *textureNamesLength);
235         void (*setActive)(const Context *rsc, const ProgramVertex *pv);
236         void (*destroy)(const Context *rsc, const ProgramVertex *pv);
237     } vertex;
238 
239     struct {
240         bool (*init)(const Context *rsc, const ProgramFragment *pf,
241                      const char* shader, size_t shaderLen,
242                      const char** textureNames, size_t textureNamesCount,
243                      const size_t *textureNamesLength);
244         void (*setActive)(const Context *rsc, const ProgramFragment *pf);
245         void (*destroy)(const Context *rsc, const ProgramFragment *pf);
246     } fragment;
247 
248     struct {
249         bool (*init)(const Context *rsc, const Mesh *m);
250         void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
251         void (*destroy)(const Context *rsc, const Mesh *m);
252     } mesh;
253 
254     struct {
255         bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
256         bool (*initDynamic)(const Context *rsc, const Path *m);
257         void (*draw)(const Context *rsc, const Path *m);
258         void (*destroy)(const Context *rsc, const Path *m);
259     } path;
260 
261     struct {
262         bool (*init)(const Context *rsc, const Sampler *m);
263         void (*destroy)(const Context *rsc, const Sampler *m);
264     } sampler;
265 
266     struct {
267         bool (*init)(const Context *rsc, const FBOCache *fb);
268         void (*setActive)(const Context *rsc, const FBOCache *fb);
269         void (*destroy)(const Context *rsc, const FBOCache *fb);
270     } framebuffer;
271 
272     struct {
273         bool (*init)(const Context *rsc, ScriptGroup *sg);
274         void (*setInput)(const Context *rsc, const ScriptGroup *sg,
275                          const ScriptKernelID *kid, Allocation *);
276         void (*setOutput)(const Context *rsc, const ScriptGroup *sg,
277                           const ScriptKernelID *kid, Allocation *);
278         void (*execute)(const Context *rsc, const ScriptGroup *sg);
279         void (*destroy)(const Context *rsc, const ScriptGroup *sg);
280     } scriptgroup;
281 
282 } RsdHalFunctions;
283 
284 
285 }
286 }
287 
288 #ifdef __cplusplus
289 extern "C" {
290 #endif
291 
292 bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor);
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 
298 #endif
299 
300