rs_hal.h revision 35e429ebf817130d8590d11d441a77aa697bd7d4
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 uint32_t slot, 74 const Allocation * ain, 75 Allocation * aout, 76 const void * usr, 77 uint32_t usrLen, 78 const RsScriptCall *sc); 79 void (*invokeInit)(const Context *rsc, Script *s); 80 81 void (*setGlobalVar)(const Context *rsc, const Script *s, 82 uint32_t slot, 83 void *data, 84 size_t dataLength); 85 void (*setGlobalBind)(const Context *rsc, const Script *s, 86 uint32_t slot, 87 void *data); 88 void (*setGlobalObj)(const Context *rsc, const Script *s, 89 uint32_t slot, 90 ObjectBase *data); 91 92 void (*destroy)(const Context *rsc, Script *s); 93 } script; 94 95 struct { 96 bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero); 97 void (*destroy)(const Context *rsc, Allocation *alloc); 98 99 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType, 100 bool zeroNew); 101 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src); 102 void (*markDirty)(const Context *rsc, const Allocation *alloc); 103 104 void (*data1D)(const Context *rsc, const Allocation *alloc, 105 uint32_t xoff, uint32_t lod, uint32_t count, 106 const void *data, uint32_t sizeBytes); 107 void (*data2D)(const Context *rsc, const Allocation *alloc, 108 uint32_t xoff, uint32_t yoff, uint32_t lod, 109 RsAllocationCubemapFace face, uint32_t w, uint32_t h, 110 const void *data, uint32_t sizeBytes); 111 void (*data3D)(const Context *rsc, const Allocation *alloc, 112 uint32_t xoff, uint32_t yoff, uint32_t zoff, 113 uint32_t lod, RsAllocationCubemapFace face, 114 uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes); 115 116 // Allocation to allocation copies 117 void (*allocData1D)(const Context *rsc, 118 const Allocation *dstAlloc, 119 uint32_t dstXoff, uint32_t dstLod, uint32_t count, 120 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod); 121 void (*allocData2D)(const Context *rsc, 122 const Allocation *dstAlloc, 123 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod, 124 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h, 125 const Allocation *srcAlloc, 126 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod, 127 RsAllocationCubemapFace srcFace); 128 void (*allocData3D)(const Context *rsc, 129 const Allocation *dstAlloc, 130 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, 131 uint32_t dstLod, RsAllocationCubemapFace dstFace, 132 uint32_t w, uint32_t h, uint32_t d, 133 const Allocation *srcAlloc, 134 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, 135 uint32_t srcLod, RsAllocationCubemapFace srcFace); 136 137 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x, 138 const void *data, uint32_t elementOff, uint32_t sizeBytes); 139 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y, 140 const void *data, uint32_t elementOff, uint32_t sizeBytes); 141 142 143 } allocation; 144 145 struct { 146 bool (*init)(const Context *rsc, const ProgramStore *ps); 147 void (*setActive)(const Context *rsc, const ProgramStore *ps); 148 void (*destroy)(const Context *rsc, const ProgramStore *ps); 149 } store; 150 151 struct { 152 bool (*init)(const Context *rsc, const ProgramRaster *ps); 153 void (*setActive)(const Context *rsc, const ProgramRaster *ps); 154 void (*destroy)(const Context *rsc, const ProgramRaster *ps); 155 } raster; 156 157 struct { 158 bool (*init)(const Context *rsc, const ProgramVertex *pv, 159 const char* shader, uint32_t shaderLen); 160 void (*setActive)(const Context *rsc, const ProgramVertex *pv); 161 void (*destroy)(const Context *rsc, const ProgramVertex *pv); 162 } vertex; 163 164 struct { 165 bool (*init)(const Context *rsc, const ProgramFragment *pf, 166 const char* shader, uint32_t shaderLen); 167 void (*setActive)(const Context *rsc, const ProgramFragment *pf); 168 void (*destroy)(const Context *rsc, const ProgramFragment *pf); 169 } fragment; 170 171 struct { 172 bool (*init)(const Context *rsc, const Mesh *m); 173 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len); 174 void (*destroy)(const Context *rsc, const Mesh *m); 175 } mesh; 176 177 struct { 178 bool (*init)(const Context *rsc, const Sampler *m); 179 void (*destroy)(const Context *rsc, const Sampler *m); 180 } sampler; 181 182 struct { 183 bool (*init)(const Context *rsc, const FBOCache *fb); 184 void (*setActive)(const Context *rsc, const FBOCache *fb); 185 void (*destroy)(const Context *rsc, const FBOCache *fb); 186 } framebuffer; 187 188} RsdHalFunctions; 189 190 191} 192} 193 194 195bool rsdHalInit(android::renderscript::Context *, uint32_t version_major, uint32_t version_minor); 196 197#endif 198 199