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