Home | History | Annotate | Download | only in driver
      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 RSD_ALLOCATION_H
     18 #define RSD_ALLOCATION_H
     19 
     20 #include <rs_hal.h>
     21 #include <rsRuntime.h>
     22 #include <rsAllocation.h>
     23 
     24 #include <GLES/gl.h>
     25 #include <GLES2/gl2.h>
     26 
     27 class RsdFrameBufferObj;
     28 struct ANativeWindowBuffer;
     29 
     30 struct DrvAllocation {
     31     // Is this a legal structure to be used as a texture source.
     32     // Initially this will require 1D or 2D and color data
     33     uint32_t textureID;
     34 
     35     // Is this a legal structure to be used as a vertex source.
     36     // Initially this will require 1D and x(yzw).  Additional per element data
     37     // is allowed.
     38     uint32_t bufferID;
     39 
     40     // Is this a legal structure to be used as an FBO render target
     41     uint32_t renderTargetID;
     42 
     43     GLenum glTarget;
     44     GLenum glType;
     45     GLenum glFormat;
     46 
     47     bool uploadDeferred;
     48 
     49     RsdFrameBufferObj * readBackFBO;
     50     ANativeWindow *wnd;
     51     ANativeWindowBuffer *wndBuffer;
     52 
     53     struct LodState {
     54         void * mallocPtr;
     55         size_t stride;
     56         uint32_t dimX;
     57         uint32_t dimY;
     58         uint32_t dimZ;
     59     } lod[android::renderscript::Allocation::MAX_LOD];
     60     size_t faceOffset;
     61     uint32_t lodCount;
     62     uint32_t faceCount;
     63 
     64 
     65 };
     66 
     67 GLenum rsdTypeToGLType(RsDataType t);
     68 GLenum rsdKindToGLFormat(RsDataKind k);
     69 
     70 
     71 bool rsdAllocationInit(const android::renderscript::Context *rsc,
     72                        android::renderscript::Allocation *alloc,
     73                        bool forceZero);
     74 void rsdAllocationDestroy(const android::renderscript::Context *rsc,
     75                           android::renderscript::Allocation *alloc);
     76 
     77 void rsdAllocationResize(const android::renderscript::Context *rsc,
     78                          const android::renderscript::Allocation *alloc,
     79                          const android::renderscript::Type *newType, bool zeroNew);
     80 void rsdAllocationSyncAll(const android::renderscript::Context *rsc,
     81                           const android::renderscript::Allocation *alloc,
     82                           RsAllocationUsageType src);
     83 void rsdAllocationMarkDirty(const android::renderscript::Context *rsc,
     84                             const android::renderscript::Allocation *alloc);
     85 int32_t rsdAllocationInitSurfaceTexture(const android::renderscript::Context *rsc,
     86                                         const android::renderscript::Allocation *alloc);
     87 void rsdAllocationSetSurfaceTexture(const android::renderscript::Context *rsc,
     88                                     android::renderscript::Allocation *alloc, ANativeWindow *nw);
     89 void rsdAllocationIoSend(const android::renderscript::Context *rsc,
     90                          android::renderscript::Allocation *alloc);
     91 void rsdAllocationIoReceive(const android::renderscript::Context *rsc,
     92                             android::renderscript::Allocation *alloc);
     93 
     94 void rsdAllocationData1D(const android::renderscript::Context *rsc,
     95                          const android::renderscript::Allocation *alloc,
     96                          uint32_t xoff, uint32_t lod, uint32_t count,
     97                          const void *data, uint32_t sizeBytes);
     98 void rsdAllocationData2D(const android::renderscript::Context *rsc,
     99                          const android::renderscript::Allocation *alloc,
    100                          uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
    101                          uint32_t w, uint32_t h,
    102                          const void *data, uint32_t sizeBytes);
    103 void rsdAllocationData3D(const android::renderscript::Context *rsc,
    104                          const android::renderscript::Allocation *alloc,
    105                          uint32_t xoff, uint32_t yoff, uint32_t zoff,
    106                          uint32_t lod, RsAllocationCubemapFace face,
    107                          uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
    108 
    109 void rsdAllocationRead1D(const android::renderscript::Context *rsc,
    110                          const android::renderscript::Allocation *alloc,
    111                          uint32_t xoff, uint32_t lod, uint32_t count,
    112                          void *data, uint32_t sizeBytes);
    113 void rsdAllocationRead2D(const android::renderscript::Context *rsc,
    114                          const android::renderscript::Allocation *alloc,
    115                          uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
    116                          uint32_t w, uint32_t h,
    117                          void *data, uint32_t sizeBytes);
    118 void rsdAllocationRead3D(const android::renderscript::Context *rsc,
    119                          const android::renderscript::Allocation *alloc,
    120                          uint32_t xoff, uint32_t yoff, uint32_t zoff,
    121                          uint32_t lod, RsAllocationCubemapFace face,
    122                          uint32_t w, uint32_t h, uint32_t d, void *data, uint32_t sizeBytes);
    123 
    124 void * rsdAllocationLock1D(const android::renderscript::Context *rsc,
    125                           const android::renderscript::Allocation *alloc);
    126 void rsdAllocationUnlock1D(const android::renderscript::Context *rsc,
    127                           const android::renderscript::Allocation *alloc);
    128 
    129 
    130 void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
    131                                const android::renderscript::Allocation *dstAlloc,
    132                                uint32_t dstXoff, uint32_t dstLod, uint32_t count,
    133                                const android::renderscript::Allocation *srcAlloc,
    134                                uint32_t srcXoff, uint32_t srcLod);
    135 void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc,
    136                                const android::renderscript::Allocation *dstAlloc,
    137                                uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
    138                                RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
    139                                const android::renderscript::Allocation *srcAlloc,
    140                                uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
    141                                RsAllocationCubemapFace srcFace);
    142 void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc,
    143                                const android::renderscript::Allocation *dstAlloc,
    144                                uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
    145                                uint32_t dstLod, RsAllocationCubemapFace dstFace,
    146                                uint32_t w, uint32_t h, uint32_t d,
    147                                const android::renderscript::Allocation *srcAlloc,
    148                                uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
    149                                uint32_t srcLod, RsAllocationCubemapFace srcFace);
    150 
    151 void rsdAllocationElementData1D(const android::renderscript::Context *rsc,
    152                                 const android::renderscript::Allocation *alloc,
    153                                 uint32_t x,
    154                                 const void *data, uint32_t elementOff, uint32_t sizeBytes);
    155 void rsdAllocationElementData2D(const android::renderscript::Context *rsc,
    156                                 const android::renderscript::Allocation *alloc,
    157                                 uint32_t x, uint32_t y,
    158                                 const void *data, uint32_t elementOff, uint32_t sizeBytes);
    159 
    160 void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc,
    161                                   const android::renderscript::Allocation *alloc);
    162 
    163 
    164 
    165 #endif
    166