Jason Sams | d19f10d | 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 | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 18 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 19 | #include "rsContext.h" |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 20 | #else |
| 21 | #include "rsContextHostStub.h" |
| 22 | #endif |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 23 | |
| 24 | using namespace android; |
| 25 | using namespace android::renderscript; |
| 26 | |
| 27 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 28 | Adapter1D::Adapter1D(Context *rsc) : ObjectBase(rsc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 29 | { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 30 | mAllocFile = __FILE__; |
| 31 | mAllocLine = __LINE__; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | reset(); |
| 33 | } |
| 34 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 35 | Adapter1D::Adapter1D(Context *rsc, Allocation *a) : ObjectBase(rsc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 36 | { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 37 | mAllocFile = __FILE__; |
| 38 | mAllocLine = __LINE__; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 39 | reset(); |
| 40 | setAllocation(a); |
| 41 | } |
| 42 | |
| 43 | void Adapter1D::reset() |
| 44 | { |
| 45 | mY = 0; |
| 46 | mZ = 0; |
| 47 | mLOD = 0; |
| 48 | mFace = 0; |
| 49 | } |
| 50 | |
| 51 | void * Adapter1D::getElement(uint32_t x) |
| 52 | { |
| 53 | rsAssert(mAllocation.get()); |
| 54 | rsAssert(mAllocation->getPtr()); |
| 55 | rsAssert(mAllocation->getType()); |
| 56 | uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr()); |
| 57 | ptr += mAllocation->getType()->getLODOffset(mLOD, x, mY); |
| 58 | return ptr; |
| 59 | } |
| 60 | |
| 61 | void Adapter1D::subData(uint32_t xoff, uint32_t count, const void *data) |
| 62 | { |
| 63 | if (mAllocation.get() && mAllocation.get()->getType()) { |
| 64 | void *ptr = getElement(xoff); |
| 65 | count *= mAllocation.get()->getType()->getElementSizeBytes(); |
| 66 | memcpy(ptr, data, count); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void Adapter1D::data(const void *data) |
| 71 | { |
Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 72 | memcpy(getElement(0), |
| 73 | data, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 74 | mAllocation.get()->getType()->getSizeBytes()); |
| 75 | } |
| 76 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 77 | void Adapter1D::serialize(OStream *stream) const |
| 78 | { |
| 79 | |
| 80 | } |
| 81 | |
| 82 | Adapter1D *Adapter1D::createFromStream(Context *rsc, IStream *stream) |
| 83 | { |
| 84 | return NULL; |
| 85 | } |
| 86 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 87 | namespace android { |
| 88 | namespace renderscript { |
| 89 | |
| 90 | RsAdapter1D rsi_Adapter1DCreate(Context *rsc) |
| 91 | { |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 92 | Adapter1D *a = new Adapter1D(rsc); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 93 | a->incUserRef(); |
Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 94 | return a; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 97 | void rsi_Adapter1DBindAllocation(Context *rsc, RsAdapter1D va, RsAllocation valloc) |
| 98 | { |
| 99 | Adapter1D * a = static_cast<Adapter1D *>(va); |
| 100 | Allocation * alloc = static_cast<Allocation *>(valloc); |
| 101 | a->setAllocation(alloc); |
| 102 | } |
| 103 | |
| 104 | void rsi_Adapter1DSetConstraint(Context *rsc, RsAdapter1D va, RsDimension dim, uint32_t value) |
| 105 | { |
| 106 | Adapter1D * a = static_cast<Adapter1D *>(va); |
| 107 | switch(dim) { |
| 108 | case RS_DIMENSION_X: |
| 109 | rsAssert(!"Cannot contrain X in an 1D adapter"); |
| 110 | return; |
| 111 | case RS_DIMENSION_Y: |
| 112 | a->setY(value); |
| 113 | break; |
| 114 | case RS_DIMENSION_Z: |
| 115 | a->setZ(value); |
| 116 | break; |
| 117 | case RS_DIMENSION_LOD: |
| 118 | a->setLOD(value); |
| 119 | break; |
| 120 | case RS_DIMENSION_FACE: |
| 121 | a->setFace(value); |
| 122 | break; |
| 123 | default: |
| 124 | rsAssert(!"Unimplemented constraint"); |
| 125 | return; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | void rsi_Adapter1DSubData(Context *rsc, RsAdapter1D va, uint32_t xoff, uint32_t count, const void *data) |
| 130 | { |
| 131 | Adapter1D * a = static_cast<Adapter1D *>(va); |
| 132 | a->subData(xoff, count, data); |
| 133 | } |
| 134 | |
| 135 | void rsi_Adapter1DData(Context *rsc, RsAdapter1D va, const void *data) |
| 136 | { |
| 137 | Adapter1D * a = static_cast<Adapter1D *>(va); |
| 138 | a->data(data); |
| 139 | } |
| 140 | |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | ////////////////////////// |
| 145 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 146 | Adapter2D::Adapter2D(Context *rsc) : ObjectBase(rsc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 147 | { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 148 | mAllocFile = __FILE__; |
| 149 | mAllocLine = __LINE__; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 150 | reset(); |
| 151 | } |
| 152 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 153 | Adapter2D::Adapter2D(Context *rsc, Allocation *a) : ObjectBase(rsc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 154 | { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 155 | mAllocFile = __FILE__; |
| 156 | mAllocLine = __LINE__; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 157 | reset(); |
| 158 | setAllocation(a); |
| 159 | } |
| 160 | |
| 161 | void Adapter2D::reset() |
| 162 | { |
| 163 | mZ = 0; |
| 164 | mLOD = 0; |
| 165 | mFace = 0; |
| 166 | } |
| 167 | |
| 168 | void * Adapter2D::getElement(uint32_t x, uint32_t y) const |
| 169 | { |
| 170 | rsAssert(mAllocation.get()); |
| 171 | rsAssert(mAllocation->getPtr()); |
| 172 | rsAssert(mAllocation->getType()); |
| 173 | uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr()); |
| 174 | ptr += mAllocation->getType()->getLODOffset(mLOD, x, y); |
| 175 | return ptr; |
| 176 | } |
| 177 | |
| 178 | void Adapter2D::subData(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data) |
| 179 | { |
| 180 | rsAssert(mAllocation.get()); |
| 181 | rsAssert(mAllocation->getPtr()); |
| 182 | rsAssert(mAllocation->getType()); |
| 183 | |
| 184 | uint32_t eSize = mAllocation.get()->getType()->getElementSizeBytes(); |
| 185 | uint32_t lineSize = eSize * w; |
| 186 | uint32_t destW = getDimX(); |
| 187 | |
| 188 | const uint8_t *src = static_cast<const uint8_t *>(data); |
| 189 | for (uint32_t line=yoff; line < (yoff+h); line++) { |
| 190 | memcpy(getElement(xoff, line), src, lineSize); |
| 191 | src += lineSize; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | void Adapter2D::data(const void *data) |
| 196 | { |
Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 197 | memcpy(getElement(0,0), |
| 198 | data, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 199 | mAllocation.get()->getType()->getSizeBytes()); |
| 200 | } |
| 201 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 202 | void Adapter2D::serialize(OStream *stream) const |
| 203 | { |
| 204 | |
| 205 | } |
| 206 | |
| 207 | Adapter2D *Adapter2D::createFromStream(Context *rsc, IStream *stream) |
| 208 | { |
| 209 | return NULL; |
| 210 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 211 | |
| 212 | |
| 213 | namespace android { |
| 214 | namespace renderscript { |
| 215 | |
| 216 | RsAdapter2D rsi_Adapter2DCreate(Context *rsc) |
| 217 | { |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 218 | Adapter2D *a = new Adapter2D(rsc); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 219 | a->incUserRef(); |
Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 220 | return a; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 223 | void rsi_Adapter2DBindAllocation(Context *rsc, RsAdapter2D va, RsAllocation valloc) |
| 224 | { |
| 225 | Adapter2D * a = static_cast<Adapter2D *>(va); |
| 226 | Allocation * alloc = static_cast<Allocation *>(valloc); |
| 227 | a->setAllocation(alloc); |
| 228 | } |
| 229 | |
| 230 | void rsi_Adapter2DSetConstraint(Context *rsc, RsAdapter2D va, RsDimension dim, uint32_t value) |
| 231 | { |
| 232 | Adapter2D * a = static_cast<Adapter2D *>(va); |
| 233 | switch(dim) { |
| 234 | case RS_DIMENSION_X: |
| 235 | rsAssert(!"Cannot contrain X in an 2D adapter"); |
| 236 | return; |
| 237 | case RS_DIMENSION_Y: |
| 238 | rsAssert(!"Cannot contrain Y in an 2D adapter"); |
| 239 | break; |
| 240 | case RS_DIMENSION_Z: |
| 241 | a->setZ(value); |
| 242 | break; |
| 243 | case RS_DIMENSION_LOD: |
| 244 | a->setLOD(value); |
| 245 | break; |
| 246 | case RS_DIMENSION_FACE: |
| 247 | a->setFace(value); |
| 248 | break; |
| 249 | default: |
| 250 | rsAssert(!"Unimplemented constraint"); |
| 251 | return; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | void rsi_Adapter2DData(Context *rsc, RsAdapter2D va, const void *data) |
| 256 | { |
| 257 | Adapter2D * a = static_cast<Adapter2D *>(va); |
| 258 | a->data(data); |
| 259 | } |
| 260 | |
| 261 | void rsi_Adapter2DSubData(Context *rsc, RsAdapter2D va, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data) |
| 262 | { |
| 263 | Adapter2D * a = static_cast<Adapter2D *>(va); |
| 264 | a->subData(xoff, yoff, w, h, data); |
| 265 | } |
| 266 | |
| 267 | } |
| 268 | } |