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