rs_hal.h revision 41e373d91a60043afa0f9abd026218b49cbc1201
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
22namespace android {
23namespace renderscript {
24
25class Context;
26class ObjectBase;
27class Element;
28class Type;
29class Allocation;
30class Script;
31class ScriptC;
32class Path;
33class Program;
34class ProgramStore;
35class ProgramRaster;
36class ProgramVertex;
37class ProgramFragment;
38class Mesh;
39class Sampler;
40class FBOCache;
41
42typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName);
43
44typedef struct {
45    const void *in;
46    void *out;
47    const void *usr;
48    size_t usr_len;
49    uint32_t x;
50    uint32_t y;
51    uint32_t z;
52    uint32_t lod;
53    RsAllocationCubemapFace face;
54    uint32_t ar[16];
55} RsForEachStubParamStruct;
56
57/**
58 * Script management functions
59 */
60typedef struct {
61    bool (*initGraphics)(const Context *);
62    void (*shutdownGraphics)(const Context *);
63    bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow);
64    void (*swap)(const Context *);
65
66    void (*shutdownDriver)(Context *);
67    void (*getVersion)(unsigned int *major, unsigned int *minor);
68    void (*setPriority)(const Context *, int32_t priority);
69
70
71
72    struct {
73        bool (*init)(const Context *rsc, ScriptC *s,
74                     char const *resName,
75                     char const *cacheDir,
76                     uint8_t const *bitcode,
77                     size_t bitcodeSize,
78                     uint32_t flags);
79
80        void (*invokeFunction)(const Context *rsc, Script *s,
81                               uint32_t slot,
82                               const void *params,
83                               size_t paramLength);
84        int (*invokeRoot)(const Context *rsc, Script *s);
85        void (*invokeForEach)(const Context *rsc,
86                              Script *s,
87                              uint32_t slot,
88                              const Allocation * ain,
89                              Allocation * aout,
90                              const void * usr,
91                              uint32_t usrLen,
92                              const RsScriptCall *sc);
93        void (*invokeInit)(const Context *rsc, Script *s);
94        void (*invokeFreeChildren)(const Context *rsc, Script *s);
95
96        void (*setGlobalVar)(const Context *rsc, const Script *s,
97                             uint32_t slot,
98                             void *data,
99                             size_t dataLength);
100        void (*setGlobalBind)(const Context *rsc, const Script *s,
101                              uint32_t slot,
102                              void *data);
103        void (*setGlobalObj)(const Context *rsc, const Script *s,
104                             uint32_t slot,
105                             ObjectBase *data);
106
107        void (*destroy)(const Context *rsc, Script *s);
108    } script;
109
110    struct {
111        bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
112        void (*destroy)(const Context *rsc, Allocation *alloc);
113
114        void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
115                       bool zeroNew);
116        void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
117        void (*markDirty)(const Context *rsc, const Allocation *alloc);
118        int32_t (*initSurfaceTexture)(const Context *rsc, const Allocation *alloc);
119
120        void (*data1D)(const Context *rsc, const Allocation *alloc,
121                       uint32_t xoff, uint32_t lod, uint32_t count,
122                       const void *data, uint32_t sizeBytes);
123        void (*data2D)(const Context *rsc, const Allocation *alloc,
124                       uint32_t xoff, uint32_t yoff, uint32_t lod,
125                       RsAllocationCubemapFace face, uint32_t w, uint32_t h,
126                       const void *data, uint32_t sizeBytes);
127        void (*data3D)(const Context *rsc, const Allocation *alloc,
128                       uint32_t xoff, uint32_t yoff, uint32_t zoff,
129                       uint32_t lod, RsAllocationCubemapFace face,
130                       uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
131
132        // Allocation to allocation copies
133        void (*allocData1D)(const Context *rsc,
134                            const Allocation *dstAlloc,
135                            uint32_t dstXoff, uint32_t dstLod, uint32_t count,
136                            const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
137        void (*allocData2D)(const Context *rsc,
138                            const Allocation *dstAlloc,
139                            uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
140                            RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
141                            const Allocation *srcAlloc,
142                            uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
143                            RsAllocationCubemapFace srcFace);
144        void (*allocData3D)(const Context *rsc,
145                            const Allocation *dstAlloc,
146                            uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
147                            uint32_t dstLod, RsAllocationCubemapFace dstFace,
148                            uint32_t w, uint32_t h, uint32_t d,
149                            const Allocation *srcAlloc,
150                            uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
151                            uint32_t srcLod, RsAllocationCubemapFace srcFace);
152
153        void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
154                              const void *data, uint32_t elementOff, uint32_t sizeBytes);
155        void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
156                              const void *data, uint32_t elementOff, uint32_t sizeBytes);
157
158
159    } allocation;
160
161    struct {
162        bool (*init)(const Context *rsc, const ProgramStore *ps);
163        void (*setActive)(const Context *rsc, const ProgramStore *ps);
164        void (*destroy)(const Context *rsc, const ProgramStore *ps);
165    } store;
166
167    struct {
168        bool (*init)(const Context *rsc, const ProgramRaster *ps);
169        void (*setActive)(const Context *rsc, const ProgramRaster *ps);
170        void (*destroy)(const Context *rsc, const ProgramRaster *ps);
171    } raster;
172
173    struct {
174        bool (*init)(const Context *rsc, const ProgramVertex *pv,
175                     const char* shader, uint32_t shaderLen);
176        void (*setActive)(const Context *rsc, const ProgramVertex *pv);
177        void (*destroy)(const Context *rsc, const ProgramVertex *pv);
178    } vertex;
179
180    struct {
181        bool (*init)(const Context *rsc, const ProgramFragment *pf,
182                     const char* shader, uint32_t shaderLen);
183        void (*setActive)(const Context *rsc, const ProgramFragment *pf);
184        void (*destroy)(const Context *rsc, const ProgramFragment *pf);
185    } fragment;
186
187    struct {
188        bool (*init)(const Context *rsc, const Mesh *m);
189        void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
190        void (*destroy)(const Context *rsc, const Mesh *m);
191    } mesh;
192
193    struct {
194        bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
195        bool (*initDynamic)(const Context *rsc, const Path *m);
196        void (*draw)(const Context *rsc, const Path *m);
197        void (*destroy)(const Context *rsc, const Path *m);
198    } path;
199
200    struct {
201        bool (*init)(const Context *rsc, const Sampler *m);
202        void (*destroy)(const Context *rsc, const Sampler *m);
203    } sampler;
204
205    struct {
206        bool (*init)(const Context *rsc, const FBOCache *fb);
207        void (*setActive)(const Context *rsc, const FBOCache *fb);
208        void (*destroy)(const Context *rsc, const FBOCache *fb);
209    } framebuffer;
210
211} RsdHalFunctions;
212
213
214}
215}
216
217
218bool rsdHalInit(android::renderscript::Context *, uint32_t version_major, uint32_t version_minor);
219
220#endif
221
222