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