Home | History | Annotate | Download | only in rs
      1 /*
      2  * Copyright (C) 2011-2012 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 <rsDefines.h>
     21 
     22 struct ANativeWindow;
     23 
     24 namespace android {
     25 namespace renderscript {
     26 
     27 class Context;
     28 class ObjectBase;
     29 class Element;
     30 class Type;
     31 class Allocation;
     32 class Script;
     33 class ScriptKernelID;
     34 class ScriptFieldID;
     35 class ScriptMethodID;
     36 class ScriptC;
     37 class ScriptGroup;
     38 class Path;
     39 class Program;
     40 class ProgramStore;
     41 class ProgramRaster;
     42 class ProgramVertex;
     43 class ProgramFragment;
     44 class Mesh;
     45 class Sampler;
     46 class FBOCache;
     47 
     48 /**
     49  * Define the internal object types.  This ia a mirror of the
     50  * definition in rs_types.rsh except with the p value typed
     51  * correctly.
     52  *
     53  * p = pointer to internal object implementation
     54  * r = reserved by libRS runtime
     55  * v1 = Mirror of p->mHal.drv
     56  * v2 = reserved for use by vendor drivers
     57  */
     58 
     59 #ifndef __LP64__
     60 #define RS_BASE_OBJ(_t_) typedef struct { const _t_* p; } __attribute__((packed, aligned(4)))
     61 #else
     62 #define RS_BASE_OBJ(_t_) typedef struct { const _t_* p; const void* r; const void* v1; const void* v2; }
     63 #endif
     64 
     65 RS_BASE_OBJ(ObjectBase) rs_object_base;
     66 RS_BASE_OBJ(Element) rs_element;
     67 RS_BASE_OBJ(Type) rs_type;
     68 RS_BASE_OBJ(Allocation) rs_allocation;
     69 RS_BASE_OBJ(Sampler) rs_sampler;
     70 RS_BASE_OBJ(Script) rs_script;
     71 RS_BASE_OBJ(ScriptGroup) rs_script_group;
     72 
     73 #ifndef __LP64__
     74 typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_mesh;
     75 typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_path;
     76 typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_fragment;
     77 typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_vertex;
     78 typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_raster;
     79 typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_store;
     80 typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_font;
     81 #endif // __LP64__
     82 
     83 
     84 typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName);
     85 
     86 /**
     87  * Script management functions
     88  */
     89 typedef struct {
     90     bool (*initGraphics)(const Context *);
     91     void (*shutdownGraphics)(const Context *);
     92     bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow);
     93     void (*swap)(const Context *);
     94 
     95     void (*shutdownDriver)(Context *);
     96     void (*getVersion)(unsigned int *major, unsigned int *minor);
     97     void (*setPriority)(const Context *, int32_t priority);
     98 
     99     void* (*allocRuntimeMem)(size_t size, uint32_t flags);
    100     void (*freeRuntimeMem)(void* ptr);
    101 
    102     struct {
    103         bool (*init)(const Context *rsc, ScriptC *s,
    104                      char const *resName,
    105                      char const *cacheDir,
    106                      uint8_t const *bitcode,
    107                      size_t bitcodeSize,
    108                      uint32_t flags);
    109         bool (*initIntrinsic)(const Context *rsc, Script *s,
    110                               RsScriptIntrinsicID iid,
    111                               Element *e);
    112 
    113         void (*invokeFunction)(const Context *rsc, Script *s,
    114                                uint32_t slot,
    115                                const void *params,
    116                                size_t paramLength);
    117         int (*invokeRoot)(const Context *rsc, Script *s);
    118         void (*invokeForEach)(const Context *rsc,
    119                               Script *s,
    120                               uint32_t slot,
    121                               const Allocation * ain,
    122                               Allocation * aout,
    123                               const void * usr,
    124                               size_t usrLen,
    125                               const RsScriptCall *sc);
    126         void (*invokeInit)(const Context *rsc, Script *s);
    127         void (*invokeFreeChildren)(const Context *rsc, Script *s);
    128 
    129         void (*setGlobalVar)(const Context *rsc, const Script *s,
    130                              uint32_t slot,
    131                              void *data,
    132                              size_t dataLength);
    133         void (*getGlobalVar)(const Context *rsc, const Script *s,
    134                              uint32_t slot,
    135                              void *data,
    136                              size_t dataLength);
    137         void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s,
    138                                          uint32_t slot,
    139                                          void *data,
    140                                          size_t dataLength,
    141                                          const Element *e,
    142                                          const uint32_t *dims,
    143                                          size_t dimLength);
    144         void (*setGlobalBind)(const Context *rsc, const Script *s,
    145                               uint32_t slot,
    146                               Allocation *data);
    147         void (*setGlobalObj)(const Context *rsc, const Script *s,
    148                              uint32_t slot,
    149                              ObjectBase *data);
    150 
    151         void (*destroy)(const Context *rsc, Script *s);
    152         void (*invokeForEachMulti)(const Context *rsc,
    153                                    Script *s,
    154                                    uint32_t slot,
    155                                    const Allocation ** ains,
    156                                    size_t inLen,
    157                                    Allocation * aout,
    158                                    const void * usr,
    159                                    size_t usrLen,
    160                                    const RsScriptCall *sc);
    161         void (*updateCachedObject)(const Context *rsc, const Script *, rs_script *obj);
    162     } script;
    163 
    164     struct {
    165         bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
    166         void (*destroy)(const Context *rsc, Allocation *alloc);
    167         uint32_t (*grallocBits)(const Context *rsc, Allocation *alloc);
    168 
    169         void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
    170                        bool zeroNew);
    171         void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
    172         void (*markDirty)(const Context *rsc, const Allocation *alloc);
    173 
    174         void (*setSurface)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
    175         void (*ioSend)(const Context *rsc, Allocation *alloc);
    176 
    177         /**
    178          * A new gralloc buffer is in use. The pointers and strides in
    179          * mHal.drvState.lod[0-2] will be updated with the new values.
    180          *
    181          * The new gralloc handle is provided in mHal.state.nativeBuffer
    182          *
    183          */
    184         void (*ioReceive)(const Context *rsc, Allocation *alloc);
    185 
    186         void (*data1D)(const Context *rsc, const Allocation *alloc,
    187                        uint32_t xoff, uint32_t lod, size_t count,
    188                        const void *data, size_t sizeBytes);
    189         void (*data2D)(const Context *rsc, const Allocation *alloc,
    190                        uint32_t xoff, uint32_t yoff, uint32_t lod,
    191                        RsAllocationCubemapFace face, uint32_t w, uint32_t h,
    192                        const void *data, size_t sizeBytes, size_t stride);
    193         void (*data3D)(const Context *rsc, const Allocation *alloc,
    194                        uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
    195                        uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes,
    196                        size_t stride);
    197 
    198         void (*read1D)(const Context *rsc, const Allocation *alloc,
    199                        uint32_t xoff, uint32_t lod, size_t count,
    200                        void *data, size_t sizeBytes);
    201         void (*read2D)(const Context *rsc, const Allocation *alloc,
    202                        uint32_t xoff, uint32_t yoff, uint32_t lod,
    203                        RsAllocationCubemapFace face, uint32_t w, uint32_t h,
    204                        void *data, size_t sizeBytes, size_t stride);
    205         void (*read3D)(const Context *rsc, const Allocation *alloc,
    206                        uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
    207                        uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes,
    208                        size_t stride);
    209 
    210         // Lock and unlock make a 1D region of memory available to the CPU
    211         // for direct access by pointer.  Once unlock is called control is
    212         // returned to the SOC driver.
    213         void * (*lock1D)(const Context *rsc, const Allocation *alloc);
    214         void (*unlock1D)(const Context *rsc, const Allocation *alloc);
    215 
    216         // Allocation to allocation copies
    217         void (*allocData1D)(const Context *rsc,
    218                             const Allocation *dstAlloc,
    219                             uint32_t dstXoff, uint32_t dstLod, size_t count,
    220                             const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
    221         void (*allocData2D)(const Context *rsc,
    222                             const Allocation *dstAlloc,
    223                             uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
    224                             RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
    225                             const Allocation *srcAlloc,
    226                             uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
    227                             RsAllocationCubemapFace srcFace);
    228         void (*allocData3D)(const Context *rsc,
    229                             const Allocation *dstAlloc,
    230                             uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
    231                             uint32_t dstLod,
    232                             uint32_t w, uint32_t h, uint32_t d,
    233                             const Allocation *srcAlloc,
    234                             uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
    235                             uint32_t srcLod);
    236 
    237         void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
    238                               const void *data, uint32_t elementOff, size_t sizeBytes);
    239         void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
    240                               const void *data, uint32_t elementOff, size_t sizeBytes);
    241 
    242         void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
    243 
    244         void (*updateCachedObject)(const Context *rsc, const Allocation *alloc, rs_allocation *obj);
    245     } allocation;
    246 
    247     struct {
    248         bool (*init)(const Context *rsc, const ProgramStore *ps);
    249         void (*setActive)(const Context *rsc, const ProgramStore *ps);
    250         void (*destroy)(const Context *rsc, const ProgramStore *ps);
    251     } store;
    252 
    253     struct {
    254         bool (*init)(const Context *rsc, const ProgramRaster *ps);
    255         void (*setActive)(const Context *rsc, const ProgramRaster *ps);
    256         void (*destroy)(const Context *rsc, const ProgramRaster *ps);
    257     } raster;
    258 
    259     struct {
    260         bool (*init)(const Context *rsc, const ProgramVertex *pv,
    261                      const char* shader, size_t shaderLen,
    262                      const char** textureNames, size_t textureNamesCount,
    263                      const size_t *textureNamesLength);
    264         void (*setActive)(const Context *rsc, const ProgramVertex *pv);
    265         void (*destroy)(const Context *rsc, const ProgramVertex *pv);
    266     } vertex;
    267 
    268     struct {
    269         bool (*init)(const Context *rsc, const ProgramFragment *pf,
    270                      const char* shader, size_t shaderLen,
    271                      const char** textureNames, size_t textureNamesCount,
    272                      const size_t *textureNamesLength);
    273         void (*setActive)(const Context *rsc, const ProgramFragment *pf);
    274         void (*destroy)(const Context *rsc, const ProgramFragment *pf);
    275     } fragment;
    276 
    277     struct {
    278         bool (*init)(const Context *rsc, const Mesh *m);
    279         void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
    280         void (*destroy)(const Context *rsc, const Mesh *m);
    281     } mesh;
    282 
    283     struct {
    284         bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
    285         bool (*initDynamic)(const Context *rsc, const Path *m);
    286         void (*draw)(const Context *rsc, const Path *m);
    287         void (*destroy)(const Context *rsc, const Path *m);
    288     } path;
    289 
    290     struct {
    291         bool (*init)(const Context *rsc, const Sampler *m);
    292         void (*destroy)(const Context *rsc, const Sampler *m);
    293         void (*updateCachedObject)(const Context *rsc, const Sampler *s, rs_sampler *obj);
    294     } sampler;
    295 
    296     struct {
    297         bool (*init)(const Context *rsc, const FBOCache *fb);
    298         void (*setActive)(const Context *rsc, const FBOCache *fb);
    299         void (*destroy)(const Context *rsc, const FBOCache *fb);
    300     } framebuffer;
    301 
    302     struct {
    303         bool (*init)(const Context *rsc, ScriptGroup *sg);
    304         void (*setInput)(const Context *rsc, const ScriptGroup *sg,
    305                          const ScriptKernelID *kid, Allocation *);
    306         void (*setOutput)(const Context *rsc, const ScriptGroup *sg,
    307                           const ScriptKernelID *kid, Allocation *);
    308         void (*execute)(const Context *rsc, const ScriptGroup *sg);
    309         void (*destroy)(const Context *rsc, const ScriptGroup *sg);
    310         void (*updateCachedObject)(const Context *rsc, const ScriptGroup *sg, rs_script_group *obj);
    311     } scriptgroup;
    312 
    313     struct {
    314         bool (*init)(const Context *rsc, const Type *m);
    315         void (*destroy)(const Context *rsc, const Type *m);
    316         void (*updateCachedObject)(const Context *rsc, const Type *s, rs_type *obj);
    317     } type;
    318 
    319     struct {
    320         bool (*init)(const Context *rsc, const Element *m);
    321         void (*destroy)(const Context *rsc, const Element *m);
    322         void (*updateCachedObject)(const Context *rsc, const Element *s, rs_element *obj);
    323     } element;
    324 
    325     void (*finish)(const Context *rsc);
    326 } RsdHalFunctions;
    327 
    328 
    329 }
    330 }
    331 
    332 #ifdef __cplusplus
    333 extern "C" {
    334 #endif
    335 
    336 bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor);
    337 
    338 #ifdef __cplusplus
    339 }
    340 #endif
    341 
    342 #endif
    343