Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 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> |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 22 | #include <rsAllocation.h> |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 23 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 24 | #include "../cpu_ref/rsd_cpu.h" |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 25 | |
| 26 | #ifndef RS_SERVER |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 27 | #include "gui/CpuConsumer.h" |
Tim Murray | 3a25fdd | 2013-02-22 17:56:56 -0800 | [diff] [blame] | 28 | #include "gui/GLConsumer.h" |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 29 | #include <GLES/gl.h> |
| 30 | #include <GLES2/gl2.h> |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 31 | #endif |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 32 | |
Alex Sakhartchouk | a949524 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 33 | class RsdFrameBufferObj; |
Tim Murray | 3a25fdd | 2013-02-22 17:56:56 -0800 | [diff] [blame] | 34 | struct ANativeWindow; |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 35 | struct ANativeWindowBuffer; |
Alex Sakhartchouk | a949524 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 36 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 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 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 50 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 4961cce | 2013-04-11 16:11:46 -0700 | [diff] [blame^] | 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 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 61 | GLenum glTarget; |
Jason Sams | a614ae1 | 2011-05-26 17:05:51 -0700 | [diff] [blame] | 62 | GLenum glType; |
| 63 | GLenum glFormat; |
Tim Murray | 3a25fdd | 2013-02-22 17:56:56 -0800 | [diff] [blame] | 64 | |
| 65 | ANativeWindow *wndSurface; |
| 66 | android::GLConsumer *surfaceTexture; |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 67 | #else |
| 68 | int glTarget; |
| 69 | int glType; |
| 70 | int glFormat; |
| 71 | #endif |
Jason Sams | a614ae1 | 2011-05-26 17:05:51 -0700 | [diff] [blame] | 72 | |
Tim Murray | c2cfe6a | 2013-02-14 16:21:33 -0800 | [diff] [blame] | 73 | bool useUserProvidedPtr; |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 74 | bool uploadDeferred; |
Alex Sakhartchouk | a949524 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 75 | |
| 76 | RsdFrameBufferObj * readBackFBO; |
Jason Sams | b322033 | 2012-04-02 14:41:54 -0700 | [diff] [blame] | 77 | ANativeWindow *wnd; |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 78 | ANativeWindowBuffer *wndBuffer; |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 79 | |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 80 | #ifndef RS_SERVER |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 81 | android::sp< android::CpuConsumer > cpuConsumer; |
| 82 | android::CpuConsumer::LockedBuffer lb; |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 83 | #endif |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 86 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | a614ae1 | 2011-05-26 17:05:51 -0700 | [diff] [blame] | 87 | GLenum rsdTypeToGLType(RsDataType t); |
| 88 | GLenum rsdKindToGLFormat(RsDataKind k); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 89 | #endif |
Jason Sams | a614ae1 | 2011-05-26 17:05:51 -0700 | [diff] [blame] | 90 | |
| 91 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 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); |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 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); |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 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); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 114 | |
| 115 | void rsdAllocationData1D(const android::renderscript::Context *rsc, |
| 116 | const android::renderscript::Allocation *alloc, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 117 | uint32_t xoff, uint32_t lod, size_t count, |
| 118 | const void *data, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 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, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 123 | const void *data, size_t sizeBytes, size_t stride); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 124 | void rsdAllocationData3D(const android::renderscript::Context *rsc, |
| 125 | const android::renderscript::Allocation *alloc, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 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); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 129 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 130 | void rsdAllocationRead1D(const android::renderscript::Context *rsc, |
| 131 | const android::renderscript::Allocation *alloc, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 132 | uint32_t xoff, uint32_t lod, size_t count, |
| 133 | void *data, size_t sizeBytes); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 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, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 138 | void *data, size_t sizeBytes, size_t stride); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 139 | void rsdAllocationRead3D(const android::renderscript::Context *rsc, |
| 140 | const android::renderscript::Allocation *alloc, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 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); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 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 | |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 151 | void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc, |
| 152 | const android::renderscript::Allocation *dstAlloc, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 153 | uint32_t dstXoff, uint32_t dstLod, size_t count, |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 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, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 166 | uint32_t dstLod, |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 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, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 170 | uint32_t srcLod); |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 171 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 172 | void rsdAllocationElementData1D(const android::renderscript::Context *rsc, |
| 173 | const android::renderscript::Allocation *alloc, |
| 174 | uint32_t x, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 175 | const void *data, uint32_t elementOff, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 176 | void rsdAllocationElementData2D(const android::renderscript::Context *rsc, |
| 177 | const android::renderscript::Allocation *alloc, |
| 178 | uint32_t x, uint32_t y, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 179 | const void *data, uint32_t elementOff, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 180 | |
Jason Sams | a6dd823 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 181 | void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc, |
| 182 | const android::renderscript::Allocation *alloc); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 183 | |
| 184 | |
| 185 | |
| 186 | #endif |