Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) 2009 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 18 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 19 | #include "rsContext.h" |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 20 | #else |
| 21 | #include "rsContextHostStub.h" |
| 22 | #endif |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 23 | |
| 24 | using namespace android; |
| 25 | using namespace android::renderscript; |
| 26 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 27 | Adapter1D::Adapter1D(Context *rsc) : ObjectBase(rsc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | reset(); |
| 29 | } |
| 30 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 31 | Adapter1D::Adapter1D(Context *rsc, Allocation *a) : ObjectBase(rsc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | reset(); |
| 33 | setAllocation(a); |
| 34 | } |
| 35 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 36 | void Adapter1D::reset() { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 37 | mY = 0; |
| 38 | mZ = 0; |
| 39 | mLOD = 0; |
| 40 | mFace = 0; |
| 41 | } |
| 42 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 43 | void * Adapter1D::getElement(uint32_t x) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 44 | rsAssert(mAllocation.get()); |
| 45 | rsAssert(mAllocation->getPtr()); |
| 46 | rsAssert(mAllocation->getType()); |
| 47 | uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr()); |
| 48 | ptr += mAllocation->getType()->getLODOffset(mLOD, x, mY); |
| 49 | return ptr; |
| 50 | } |
| 51 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 52 | void Adapter1D::subData(uint32_t xoff, uint32_t count, const void *data) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 53 | if (mAllocation.get() && mAllocation.get()->getType()) { |
| 54 | void *ptr = getElement(xoff); |
| 55 | count *= mAllocation.get()->getType()->getElementSizeBytes(); |
| 56 | memcpy(ptr, data, count); |
| 57 | } |
| 58 | } |
| 59 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 60 | void Adapter1D::data(const void *data) { |
Jason Sams | d3c8de2 | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 61 | memcpy(getElement(0), |
| 62 | data, |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 63 | mAllocation.get()->getType()->getSizeBytes()); |
| 64 | } |
| 65 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 66 | void Adapter1D::serialize(OStream *stream) const { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 69 | Adapter1D *Adapter1D::createFromStream(Context *rsc, IStream *stream) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 70 | return NULL; |
| 71 | } |
| 72 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 73 | namespace android { |
| 74 | namespace renderscript { |
| 75 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 76 | RsAdapter1D rsi_Adapter1DCreate(Context *rsc) { |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 77 | Adapter1D *a = new Adapter1D(rsc); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 78 | a->incUserRef(); |
Jason Sams | d3c8de2 | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 79 | return a; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 82 | void rsi_Adapter1DBindAllocation(Context *rsc, RsAdapter1D va, RsAllocation valloc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 83 | Adapter1D * a = static_cast<Adapter1D *>(va); |
| 84 | Allocation * alloc = static_cast<Allocation *>(valloc); |
| 85 | a->setAllocation(alloc); |
| 86 | } |
| 87 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 88 | void rsi_Adapter1DSetConstraint(Context *rsc, RsAdapter1D va, RsDimension dim, uint32_t value) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 89 | Adapter1D * a = static_cast<Adapter1D *>(va); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 90 | switch (dim) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 91 | case RS_DIMENSION_X: |
| 92 | rsAssert(!"Cannot contrain X in an 1D adapter"); |
| 93 | return; |
| 94 | case RS_DIMENSION_Y: |
| 95 | a->setY(value); |
| 96 | break; |
| 97 | case RS_DIMENSION_Z: |
| 98 | a->setZ(value); |
| 99 | break; |
| 100 | case RS_DIMENSION_LOD: |
| 101 | a->setLOD(value); |
| 102 | break; |
| 103 | case RS_DIMENSION_FACE: |
| 104 | a->setFace(value); |
| 105 | break; |
| 106 | default: |
| 107 | rsAssert(!"Unimplemented constraint"); |
| 108 | return; |
| 109 | } |
| 110 | } |
| 111 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 112 | void rsi_Adapter1DSubData(Context *rsc, RsAdapter1D va, uint32_t xoff, uint32_t count, const void *data) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 113 | Adapter1D * a = static_cast<Adapter1D *>(va); |
| 114 | a->subData(xoff, count, data); |
| 115 | } |
| 116 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 117 | void rsi_Adapter1DData(Context *rsc, RsAdapter1D va, const void *data) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 118 | Adapter1D * a = static_cast<Adapter1D *>(va); |
| 119 | a->data(data); |
| 120 | } |
| 121 | |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | ////////////////////////// |
| 126 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 127 | Adapter2D::Adapter2D(Context *rsc) : ObjectBase(rsc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 128 | reset(); |
| 129 | } |
| 130 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 131 | Adapter2D::Adapter2D(Context *rsc, Allocation *a) : ObjectBase(rsc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 132 | reset(); |
| 133 | setAllocation(a); |
| 134 | } |
| 135 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 136 | void Adapter2D::reset() { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 137 | mZ = 0; |
| 138 | mLOD = 0; |
| 139 | mFace = 0; |
| 140 | } |
| 141 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 142 | void * Adapter2D::getElement(uint32_t x, uint32_t y) const { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 143 | rsAssert(mAllocation.get()); |
| 144 | rsAssert(mAllocation->getPtr()); |
| 145 | rsAssert(mAllocation->getType()); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 146 | if (mFace != 0 && !mAllocation->getType()->getDimFaces()) { |
| 147 | LOGE("Adapter wants cubemap face, but allocation has none"); |
| 148 | return NULL; |
| 149 | } |
| 150 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 151 | uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr()); |
| 152 | ptr += mAllocation->getType()->getLODOffset(mLOD, x, y); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 153 | |
| 154 | if (mFace != 0) { |
| 155 | uint32_t totalSizeBytes = mAllocation->getType()->getSizeBytes(); |
| 156 | uint32_t faceOffset = totalSizeBytes / 6; |
| 157 | ptr += faceOffset * mFace; |
| 158 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 159 | return ptr; |
| 160 | } |
| 161 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 162 | void Adapter2D::subData(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 163 | rsAssert(mAllocation.get()); |
| 164 | rsAssert(mAllocation->getPtr()); |
| 165 | rsAssert(mAllocation->getType()); |
| 166 | |
| 167 | uint32_t eSize = mAllocation.get()->getType()->getElementSizeBytes(); |
| 168 | uint32_t lineSize = eSize * w; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 169 | |
| 170 | const uint8_t *src = static_cast<const uint8_t *>(data); |
| 171 | for (uint32_t line=yoff; line < (yoff+h); line++) { |
| 172 | memcpy(getElement(xoff, line), src, lineSize); |
| 173 | src += lineSize; |
| 174 | } |
| 175 | } |
| 176 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 177 | void Adapter2D::data(const void *data) { |
Jason Sams | d3c8de2 | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 178 | memcpy(getElement(0,0), |
| 179 | data, |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 180 | mAllocation.get()->getType()->getSizeBytes()); |
| 181 | } |
| 182 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 183 | void Adapter2D::serialize(OStream *stream) const { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 186 | Adapter2D *Adapter2D::createFromStream(Context *rsc, IStream *stream) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 187 | return NULL; |
| 188 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 189 | |
| 190 | |
| 191 | namespace android { |
| 192 | namespace renderscript { |
| 193 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 194 | RsAdapter2D rsi_Adapter2DCreate(Context *rsc) { |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 195 | Adapter2D *a = new Adapter2D(rsc); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 196 | a->incUserRef(); |
Jason Sams | d3c8de2 | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 197 | return a; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 200 | void rsi_Adapter2DBindAllocation(Context *rsc, RsAdapter2D va, RsAllocation valloc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 201 | Adapter2D * a = static_cast<Adapter2D *>(va); |
| 202 | Allocation * alloc = static_cast<Allocation *>(valloc); |
| 203 | a->setAllocation(alloc); |
| 204 | } |
| 205 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 206 | void rsi_Adapter2DSetConstraint(Context *rsc, RsAdapter2D va, RsDimension dim, uint32_t value) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 207 | Adapter2D * a = static_cast<Adapter2D *>(va); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 208 | switch (dim) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 209 | case RS_DIMENSION_X: |
| 210 | rsAssert(!"Cannot contrain X in an 2D adapter"); |
| 211 | return; |
| 212 | case RS_DIMENSION_Y: |
| 213 | rsAssert(!"Cannot contrain Y in an 2D adapter"); |
| 214 | break; |
| 215 | case RS_DIMENSION_Z: |
| 216 | a->setZ(value); |
| 217 | break; |
| 218 | case RS_DIMENSION_LOD: |
| 219 | a->setLOD(value); |
| 220 | break; |
| 221 | case RS_DIMENSION_FACE: |
| 222 | a->setFace(value); |
| 223 | break; |
| 224 | default: |
| 225 | rsAssert(!"Unimplemented constraint"); |
| 226 | return; |
| 227 | } |
| 228 | } |
| 229 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 230 | void rsi_Adapter2DData(Context *rsc, RsAdapter2D va, const void *data) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 231 | Adapter2D * a = static_cast<Adapter2D *>(va); |
| 232 | a->data(data); |
| 233 | } |
| 234 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 235 | void rsi_Adapter2DSubData(Context *rsc, RsAdapter2D va, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 236 | Adapter2D * a = static_cast<Adapter2D *>(va); |
| 237 | a->subData(xoff, yoff, w, h, data); |
| 238 | } |
| 239 | |
| 240 | } |
| 241 | } |