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