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