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