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 "../cpu_ref/rsd_cpu.h" 25 26 #ifndef RS_SERVER 27 #include <GLES/gl.h> 28 #include <GLES2/gl2.h> 29 #endif 30 31 #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) 32 #include "gui/GLConsumer.h" 33 #endif 34 35 class RsdFrameBufferObj; 36 struct ANativeWindow; 37 struct ANativeWindowBuffer; 38 struct ANativeWindow_Buffer; 39 40 struct DrvAllocation { 41 // Is this a legal structure to be used as a texture source. 42 // Initially this will require 1D or 2D and color data 43 uint32_t textureID; 44 45 // Is this a legal structure to be used as a vertex source. 46 // Initially this will require 1D and x(yzw). Additional per element data 47 // is allowed. 48 uint32_t bufferID; 49 50 // Is this a legal structure to be used as an FBO render target 51 uint32_t renderTargetID; 52 53 #ifndef RS_COMPATIBILITY_LIB 54 GLenum glTarget; 55 GLenum glType; 56 GLenum glFormat; 57 58 ANativeWindowBuffer *wndBuffer; 59 android::GLConsumer *surfaceTexture; 60 #else 61 int glTarget; 62 int glType; 63 int glFormat; 64 65 ANativeWindow_Buffer *wndBuffer; 66 #endif 67 68 bool useUserProvidedPtr; 69 bool uploadDeferred; 70 71 RsdFrameBufferObj * readBackFBO; 72 ANativeWindow *wnd; 73 ANativeWindow *wndSurface; 74 }; 75 76 #ifndef RS_COMPATIBILITY_LIB 77 GLenum rsdTypeToGLType(RsDataType t); 78 GLenum rsdKindToGLFormat(RsDataKind k); 79 #endif 80 81 82 uint32_t rsdAllocationGrallocBits(const android::renderscript::Context *rsc, 83 android::renderscript::Allocation *alloc); 84 bool rsdAllocationInit(const android::renderscript::Context *rsc, 85 android::renderscript::Allocation *alloc, 86 bool forceZero); 87 #ifdef RS_COMPATIBILITY_LIB 88 bool rsdAllocationInitStrided(const android::renderscript::Context *rsc, 89 android::renderscript::Allocation *alloc, 90 bool forceZero, size_t requiredAlignment); 91 #endif 92 bool rsdAllocationAdapterInit(const android::renderscript::Context *rsc, 93 android::renderscript::Allocation *alloc); 94 void rsdAllocationDestroy(const android::renderscript::Context *rsc, 95 android::renderscript::Allocation *alloc); 96 97 void rsdAllocationResize(const android::renderscript::Context *rsc, 98 const android::renderscript::Allocation *alloc, 99 const android::renderscript::Type *newType, bool zeroNew); 100 void rsdAllocationSyncAll(const android::renderscript::Context *rsc, 101 const android::renderscript::Allocation *alloc, 102 RsAllocationUsageType src); 103 void rsdAllocationMarkDirty(const android::renderscript::Context *rsc, 104 const android::renderscript::Allocation *alloc); 105 void rsdAllocationSetSurface(const android::renderscript::Context *rsc, 106 android::renderscript::Allocation *alloc, ANativeWindow *nw); 107 void rsdAllocationIoSend(const android::renderscript::Context *rsc, 108 android::renderscript::Allocation *alloc); 109 void rsdAllocationIoReceive(const android::renderscript::Context *rsc, 110 android::renderscript::Allocation *alloc); 111 112 void rsdAllocationData1D(const android::renderscript::Context *rsc, 113 const android::renderscript::Allocation *alloc, 114 uint32_t xoff, uint32_t lod, size_t count, 115 const void *data, size_t sizeBytes); 116 void rsdAllocationData2D(const android::renderscript::Context *rsc, 117 const android::renderscript::Allocation *alloc, 118 uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, 119 uint32_t w, uint32_t h, 120 const void *data, size_t sizeBytes, size_t stride); 121 void rsdAllocationData3D(const android::renderscript::Context *rsc, 122 const android::renderscript::Allocation *alloc, 123 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, 124 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, 125 size_t stride); 126 127 void rsdAllocationRead1D(const android::renderscript::Context *rsc, 128 const android::renderscript::Allocation *alloc, 129 uint32_t xoff, uint32_t lod, size_t count, 130 void *data, size_t sizeBytes); 131 void rsdAllocationRead2D(const android::renderscript::Context *rsc, 132 const android::renderscript::Allocation *alloc, 133 uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, 134 uint32_t w, uint32_t h, 135 void *data, size_t sizeBytes, size_t stride); 136 void rsdAllocationRead3D(const android::renderscript::Context *rsc, 137 const android::renderscript::Allocation *alloc, 138 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, 139 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, 140 size_t stride); 141 142 void * rsdAllocationLock1D(const android::renderscript::Context *rsc, 143 const android::renderscript::Allocation *alloc); 144 void rsdAllocationUnlock1D(const android::renderscript::Context *rsc, 145 const android::renderscript::Allocation *alloc); 146 147 148 void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc, 149 const android::renderscript::Allocation *dstAlloc, 150 uint32_t dstXoff, uint32_t dstLod, size_t count, 151 const android::renderscript::Allocation *srcAlloc, 152 uint32_t srcXoff, uint32_t srcLod); 153 void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc, 154 const android::renderscript::Allocation *dstAlloc, 155 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod, 156 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h, 157 const android::renderscript::Allocation *srcAlloc, 158 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod, 159 RsAllocationCubemapFace srcFace); 160 void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc, 161 const android::renderscript::Allocation *dstAlloc, 162 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, 163 uint32_t dstLod, 164 uint32_t w, uint32_t h, uint32_t d, 165 const android::renderscript::Allocation *srcAlloc, 166 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, 167 uint32_t srcLod); 168 169 void rsdAllocationElementData(const android::renderscript::Context *rsc, 170 const android::renderscript::Allocation *alloc, 171 uint32_t x, uint32_t y, uint32_t z, 172 const void *data, uint32_t elementOff, size_t sizeBytes); 173 174 void rsdAllocationElementRead(const android::renderscript::Context *rsc, 175 const android::renderscript::Allocation *alloc, 176 uint32_t x, uint32_t y, uint32_t z, 177 void *data, uint32_t elementOff, size_t sizeBytes); 178 179 void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc, 180 const android::renderscript::Allocation *alloc); 181 182 void rsdAllocationUpdateCachedObject(const android::renderscript::Context *rsc, 183 const android::renderscript::Allocation *alloc, 184 android::renderscript::rs_allocation *obj); 185 186 void rsdAllocationAdapterOffset(const android::renderscript::Context *rsc, 187 const android::renderscript::Allocation *alloc); 188 189 190 #endif 191