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 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 26 | #include <GLES/gl.h> |
| 27 | #include <GLES2/gl2.h> |
| 28 | |
Stephen Hines | b0934b6 | 2013-07-03 17:27:38 -0700 | [diff] [blame] | 29 | |
Alex Sakhartchouk | a949524 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 30 | class RsdFrameBufferObj; |
Tim Murray | 3a25fdd | 2013-02-22 17:56:56 -0800 | [diff] [blame] | 31 | struct ANativeWindow; |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 32 | struct ANativeWindowBuffer; |
Miao Wang | 2bd78f2 | 2014-11-20 10:49:43 -0800 | [diff] [blame] | 33 | struct ANativeWindow_Buffer; |
Alex Sakhartchouk | a949524 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 34 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 35 | struct DrvAllocation { |
| 36 | // Is this a legal structure to be used as a texture source. |
| 37 | // Initially this will require 1D or 2D and color data |
| 38 | uint32_t textureID; |
| 39 | |
| 40 | // Is this a legal structure to be used as a vertex source. |
| 41 | // Initially this will require 1D and x(yzw). Additional per element data |
| 42 | // is allowed. |
| 43 | uint32_t bufferID; |
| 44 | |
| 45 | // Is this a legal structure to be used as an FBO render target |
| 46 | uint32_t renderTargetID; |
| 47 | |
Miao Wang | 59f6142 | 2017-03-14 14:23:52 -0700 | [diff] [blame] | 48 | #if !defined(RS_VENDOR_LIB) && !defined(RS_COMPATIBILITY_LIB) |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 49 | GLenum glTarget; |
Jason Sams | a614ae1 | 2011-05-26 17:05:51 -0700 | [diff] [blame] | 50 | GLenum glType; |
| 51 | GLenum glFormat; |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 52 | #else |
| 53 | int glTarget; |
| 54 | int glType; |
| 55 | int glFormat; |
Miao Wang | 5d955c9 | 2017-03-01 11:57:47 -0800 | [diff] [blame] | 56 | #endif |
Miao Wang | 2bd78f2 | 2014-11-20 10:49:43 -0800 | [diff] [blame] | 57 | |
Miao Wang | c3e5765 | 2017-03-24 11:45:47 -0700 | [diff] [blame] | 58 | #if !defined(RS_COMPATIBILITY_LIB) |
| 59 | ANativeWindowBuffer *wndBuffer; |
| 60 | #else |
Miao Wang | 2bd78f2 | 2014-11-20 10:49:43 -0800 | [diff] [blame] | 61 | ANativeWindow_Buffer *wndBuffer; |
Miao Wang | c3e5765 | 2017-03-24 11:45:47 -0700 | [diff] [blame] | 62 | #endif |
Jason Sams | a614ae1 | 2011-05-26 17:05:51 -0700 | [diff] [blame] | 63 | |
Tim Murray | c2cfe6a | 2013-02-14 16:21:33 -0800 | [diff] [blame] | 64 | bool useUserProvidedPtr; |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 65 | bool uploadDeferred; |
Alex Sakhartchouk | a949524 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 66 | |
Miao Wang | 59f6142 | 2017-03-14 14:23:52 -0700 | [diff] [blame] | 67 | #if !defined(RS_VENDOR_LIB) && !defined(RS_COMPATIBILITY_LIB) |
Alex Sakhartchouk | a949524 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 68 | RsdFrameBufferObj * readBackFBO; |
Miao Wang | 59f6142 | 2017-03-14 14:23:52 -0700 | [diff] [blame] | 69 | #endif |
Jason Sams | b322033 | 2012-04-02 14:41:54 -0700 | [diff] [blame] | 70 | ANativeWindow *wnd; |
Miao Wang | 2bd78f2 | 2014-11-20 10:49:43 -0800 | [diff] [blame] | 71 | ANativeWindow *wndSurface; |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 74 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | a614ae1 | 2011-05-26 17:05:51 -0700 | [diff] [blame] | 75 | GLenum rsdTypeToGLType(RsDataType t); |
| 76 | GLenum rsdKindToGLFormat(RsDataKind k); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 77 | #endif |
Jason Sams | a614ae1 | 2011-05-26 17:05:51 -0700 | [diff] [blame] | 78 | |
| 79 | |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 80 | uint32_t rsdAllocationGrallocBits(const android::renderscript::Context *rsc, |
| 81 | android::renderscript::Allocation *alloc); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 82 | bool rsdAllocationInit(const android::renderscript::Context *rsc, |
| 83 | android::renderscript::Allocation *alloc, |
| 84 | bool forceZero); |
Miao Wang | 47a5881 | 2015-07-23 21:59:16 -0700 | [diff] [blame] | 85 | #ifdef RS_COMPATIBILITY_LIB |
| 86 | bool rsdAllocationInitStrided(const android::renderscript::Context *rsc, |
| 87 | android::renderscript::Allocation *alloc, |
| 88 | bool forceZero, size_t requiredAlignment); |
| 89 | #endif |
Jason Sams | bc9dc27 | 2015-02-09 12:50:22 -0800 | [diff] [blame] | 90 | bool rsdAllocationAdapterInit(const android::renderscript::Context *rsc, |
| 91 | android::renderscript::Allocation *alloc); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 92 | void rsdAllocationDestroy(const android::renderscript::Context *rsc, |
| 93 | android::renderscript::Allocation *alloc); |
| 94 | |
| 95 | void rsdAllocationResize(const android::renderscript::Context *rsc, |
| 96 | const android::renderscript::Allocation *alloc, |
| 97 | const android::renderscript::Type *newType, bool zeroNew); |
| 98 | void rsdAllocationSyncAll(const android::renderscript::Context *rsc, |
| 99 | const android::renderscript::Allocation *alloc, |
| 100 | RsAllocationUsageType src); |
| 101 | void rsdAllocationMarkDirty(const android::renderscript::Context *rsc, |
| 102 | const android::renderscript::Allocation *alloc); |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 103 | void rsdAllocationSetSurface(const android::renderscript::Context *rsc, |
| 104 | android::renderscript::Allocation *alloc, ANativeWindow *nw); |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 105 | void rsdAllocationIoSend(const android::renderscript::Context *rsc, |
| 106 | android::renderscript::Allocation *alloc); |
| 107 | void rsdAllocationIoReceive(const android::renderscript::Context *rsc, |
| 108 | android::renderscript::Allocation *alloc); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 109 | |
| 110 | void rsdAllocationData1D(const android::renderscript::Context *rsc, |
| 111 | const android::renderscript::Allocation *alloc, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 112 | uint32_t xoff, uint32_t lod, size_t count, |
| 113 | const void *data, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 114 | void rsdAllocationData2D(const android::renderscript::Context *rsc, |
| 115 | const android::renderscript::Allocation *alloc, |
| 116 | uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, |
| 117 | uint32_t w, uint32_t h, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 118 | const void *data, size_t sizeBytes, size_t stride); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 119 | void rsdAllocationData3D(const android::renderscript::Context *rsc, |
| 120 | const android::renderscript::Allocation *alloc, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 121 | uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, |
| 122 | uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, |
| 123 | size_t stride); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 124 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 125 | void rsdAllocationRead1D(const android::renderscript::Context *rsc, |
| 126 | const android::renderscript::Allocation *alloc, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 127 | uint32_t xoff, uint32_t lod, size_t count, |
| 128 | void *data, size_t sizeBytes); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 129 | void rsdAllocationRead2D(const android::renderscript::Context *rsc, |
| 130 | const android::renderscript::Allocation *alloc, |
| 131 | uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, |
| 132 | uint32_t w, uint32_t h, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 133 | void *data, size_t sizeBytes, size_t stride); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 134 | void rsdAllocationRead3D(const android::renderscript::Context *rsc, |
| 135 | const android::renderscript::Allocation *alloc, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 136 | uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, |
| 137 | uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, |
| 138 | size_t stride); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 139 | |
| 140 | void * rsdAllocationLock1D(const android::renderscript::Context *rsc, |
| 141 | const android::renderscript::Allocation *alloc); |
| 142 | void rsdAllocationUnlock1D(const android::renderscript::Context *rsc, |
| 143 | const android::renderscript::Allocation *alloc); |
| 144 | |
| 145 | |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 146 | void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc, |
| 147 | const android::renderscript::Allocation *dstAlloc, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 148 | uint32_t dstXoff, uint32_t dstLod, size_t count, |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 149 | const android::renderscript::Allocation *srcAlloc, |
| 150 | uint32_t srcXoff, uint32_t srcLod); |
| 151 | void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc, |
| 152 | const android::renderscript::Allocation *dstAlloc, |
| 153 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod, |
| 154 | RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h, |
| 155 | const android::renderscript::Allocation *srcAlloc, |
| 156 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod, |
| 157 | RsAllocationCubemapFace srcFace); |
| 158 | void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc, |
| 159 | const android::renderscript::Allocation *dstAlloc, |
| 160 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 161 | uint32_t dstLod, |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 162 | uint32_t w, uint32_t h, uint32_t d, |
| 163 | const android::renderscript::Allocation *srcAlloc, |
| 164 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 165 | uint32_t srcLod); |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 166 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 167 | void rsdAllocationElementData(const android::renderscript::Context *rsc, |
| 168 | const android::renderscript::Allocation *alloc, |
| 169 | uint32_t x, uint32_t y, uint32_t z, |
| 170 | const void *data, uint32_t elementOff, size_t sizeBytes); |
| 171 | |
| 172 | void rsdAllocationElementRead(const android::renderscript::Context *rsc, |
| 173 | const android::renderscript::Allocation *alloc, |
| 174 | uint32_t x, uint32_t y, uint32_t z, |
| 175 | void *data, uint32_t elementOff, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 176 | |
Jason Sams | a6dd823 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 177 | void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc, |
| 178 | const android::renderscript::Allocation *alloc); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 179 | |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 180 | void rsdAllocationUpdateCachedObject(const android::renderscript::Context *rsc, |
| 181 | const android::renderscript::Allocation *alloc, |
| 182 | android::renderscript::rs_allocation *obj); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 183 | |
Jason Sams | bc9dc27 | 2015-02-09 12:50:22 -0800 | [diff] [blame] | 184 | void rsdAllocationAdapterOffset(const android::renderscript::Context *rsc, |
| 185 | const android::renderscript::Allocation *alloc); |
| 186 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 187 | |
| 188 | #endif |