rs_hal.h revision b81a0eb8180791e4eaab1253b59fa8bd562b046b
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
43/**
44 * Script management functions
45 */
46typedef struct {
47    bool (*initGraphics)(const Context *);
48    void (*shutdownGraphics)(const Context *);
49    bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow);
50    void (*swap)(const Context *);
51
52    void (*shutdownDriver)(Context *);
53    void (*getVersion)(unsigned int *major, unsigned int *minor);
54    void (*setPriority)(const Context *, int32_t priority);
55
56
57
58    struct {
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,
64                     uint32_t flags);
65
66        void (*invokeFunction)(const Context *rsc, Script *s,
67                               uint32_t slot,
68                               const void *params,
69                               size_t paramLength);
70        int (*invokeRoot)(const Context *rsc, Script *s);
71        void (*invokeForEach)(const Context *rsc,
72                              Script *s,
73                              const Allocation * ain,
74                              Allocation * aout,
75                              const void * usr,
76                              uint32_t usrLen,
77                              const RsScriptCall *sc);
78        void (*invokeInit)(const Context *rsc, Script *s);
79
80        void (*setGlobalVar)(const Context *rsc, const Script *s,
81                             uint32_t slot,
82                             void *data,
83                             size_t dataLength);
84        void (*setGlobalBind)(const Context *rsc, const Script *s,
85                              uint32_t slot,
86                              void *data);
87        void (*setGlobalObj)(const Context *rsc, const Script *s,
88                             uint32_t slot,
89                             ObjectBase *data);
90
91        void (*destroy)(const Context *rsc, Script *s);
92    } script;
93
94    struct {
95        bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
96        void (*destroy)(const Context *rsc, Allocation *alloc);
97
98        void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
99                       bool zeroNew);
100        void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
101        void (*markDirty)(const Context *rsc, const Allocation *alloc);
102
103        void (*data1D)(const Context *rsc, const Allocation *alloc,
104                       uint32_t xoff, uint32_t lod, uint32_t count,
105                       const void *data, uint32_t sizeBytes);
106        void (*data2D)(const Context *rsc, const Allocation *alloc,
107                       uint32_t xoff, uint32_t yoff, uint32_t lod,
108                       RsAllocationCubemapFace face, uint32_t w, uint32_t h,
109                       const void *data, uint32_t sizeBytes);
110        void (*data3D)(const Context *rsc, const Allocation *alloc,
111                       uint32_t xoff, uint32_t yoff, uint32_t zoff,
112                       uint32_t lod, RsAllocationCubemapFace face,
113                       uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
114
115        void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
116                              const void *data, uint32_t elementOff, uint32_t sizeBytes);
117        void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
118                              const void *data, uint32_t elementOff, uint32_t sizeBytes);
119
120
121    } allocation;
122
123    struct {
124        bool (*init)(const Context *rsc, const ProgramStore *ps);
125        void (*setActive)(const Context *rsc, const ProgramStore *ps);
126        void (*destroy)(const Context *rsc, const ProgramStore *ps);
127    } store;
128
129    struct {
130        bool (*init)(const Context *rsc, const ProgramRaster *ps);
131        void (*setActive)(const Context *rsc, const ProgramRaster *ps);
132        void (*destroy)(const Context *rsc, const ProgramRaster *ps);
133    } raster;
134
135    struct {
136        bool (*init)(const Context *rsc, const ProgramVertex *pv,
137                     const char* shader, uint32_t shaderLen);
138        void (*setActive)(const Context *rsc, const ProgramVertex *pv);
139        void (*destroy)(const Context *rsc, const ProgramVertex *pv);
140    } vertex;
141
142    struct {
143        bool (*init)(const Context *rsc, const ProgramFragment *pf,
144                     const char* shader, uint32_t shaderLen);
145        void (*setActive)(const Context *rsc, const ProgramFragment *pf);
146        void (*destroy)(const Context *rsc, const ProgramFragment *pf);
147    } fragment;
148
149    struct {
150        bool (*init)(const Context *rsc, const Mesh *m);
151        void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
152        void (*destroy)(const Context *rsc, const Mesh *m);
153    } mesh;
154
155    struct {
156        bool (*init)(const Context *rsc, const Sampler *m);
157        void (*destroy)(const Context *rsc, const Sampler *m);
158    } sampler;
159
160    struct {
161        bool (*init)(const Context *rsc, const FBOCache *fb);
162        void (*setActive)(const Context *rsc, const FBOCache *fb);
163        void (*destroy)(const Context *rsc, const FBOCache *fb);
164    } framebuffer;
165
166} RsdHalFunctions;
167
168
169}
170}
171
172
173bool rsdHalInit(android::renderscript::Context *, uint32_t version_major, uint32_t version_minor);
174
175#endif
176
177