Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Jason Sams | bc0ca6b | 2013-02-15 18:13:43 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | #include "rsContext.h" |
| 18 | |
Stephen Hines | 10f3170 | 2013-08-15 17:30:12 -0700 | [diff] [blame^] | 19 | #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) |
Jason Sams | bc0ca6b | 2013-02-15 18:13:43 -0800 | [diff] [blame] | 20 | #include "system/graphics.h" |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 21 | #endif |
Jason Sams | bc0ca6b | 2013-02-15 18:13:43 -0800 | [diff] [blame] | 22 | |
Stephen Hines | 10f3170 | 2013-08-15 17:30:12 -0700 | [diff] [blame^] | 23 | #ifdef RS_COMPATIBILITY_LIB |
| 24 | #include "rsCompatibilityLib.h" |
| 25 | #endif |
| 26 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 27 | using namespace android; |
| 28 | using namespace android::renderscript; |
| 29 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 30 | Type::Type(Context *rsc) : ObjectBase(rsc) { |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 31 | memset(&mHal, 0, sizeof(mHal)); |
| 32 | mDimLOD = false; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 35 | void Type::preDestroy() const { |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 36 | for (uint32_t ct = 0; ct < mRSC->mStateType.mTypes.size(); ct++) { |
| 37 | if (mRSC->mStateType.mTypes[ct] == this) { |
| 38 | mRSC->mStateType.mTypes.removeAt(ct); |
| 39 | break; |
| 40 | } |
| 41 | } |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 44 | Type::~Type() { |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 45 | clear(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 48 | void Type::clear() { |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 49 | if (mHal.state.lodCount) { |
| 50 | delete [] mHal.state.lodDimX; |
| 51 | delete [] mHal.state.lodDimY; |
| 52 | delete [] mHal.state.lodDimZ; |
Stephen Hines | 86087f2 | 2012-10-19 19:16:51 -0700 | [diff] [blame] | 53 | delete [] mHal.state.lodOffset; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 54 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 55 | mElement.clear(); |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 56 | memset(&mHal, 0, sizeof(mHal)); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 59 | TypeState::TypeState() { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 62 | TypeState::~TypeState() { |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 63 | rsAssert(!mTypes.size()); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Stephen Hines | 86087f2 | 2012-10-19 19:16:51 -0700 | [diff] [blame] | 66 | size_t Type::getOffsetForFace(uint32_t face) const { |
| 67 | rsAssert(mHal.state.faces); |
| 68 | return 0; |
| 69 | } |
| 70 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 71 | void Type::compute() { |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 72 | uint32_t oldLODCount = mHal.state.lodCount; |
| 73 | if (mDimLOD) { |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 74 | uint32_t l2x = rsFindHighBit(mHal.state.dimX) + 1; |
| 75 | uint32_t l2y = rsFindHighBit(mHal.state.dimY) + 1; |
| 76 | uint32_t l2z = rsFindHighBit(mHal.state.dimZ) + 1; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 77 | |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 78 | mHal.state.lodCount = rsMax(l2x, l2y); |
| 79 | mHal.state.lodCount = rsMax(mHal.state.lodCount, l2z); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 80 | } else { |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 81 | mHal.state.lodCount = 1; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 82 | } |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 83 | if (mHal.state.lodCount != oldLODCount) { |
| 84 | if (oldLODCount) { |
| 85 | delete [] mHal.state.lodDimX; |
| 86 | delete [] mHal.state.lodDimY; |
| 87 | delete [] mHal.state.lodDimZ; |
Stephen Hines | 86087f2 | 2012-10-19 19:16:51 -0700 | [diff] [blame] | 88 | delete [] mHal.state.lodOffset; |
Alex Sakhartchouk | 417e6a4 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 89 | } |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 90 | mHal.state.lodDimX = new uint32_t[mHal.state.lodCount]; |
| 91 | mHal.state.lodDimY = new uint32_t[mHal.state.lodCount]; |
| 92 | mHal.state.lodDimZ = new uint32_t[mHal.state.lodCount]; |
Stephen Hines | 86087f2 | 2012-10-19 19:16:51 -0700 | [diff] [blame] | 93 | mHal.state.lodOffset = new uint32_t[mHal.state.lodCount]; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 96 | uint32_t tx = mHal.state.dimX; |
| 97 | uint32_t ty = mHal.state.dimY; |
| 98 | uint32_t tz = mHal.state.dimZ; |
Stephen Hines | 86087f2 | 2012-10-19 19:16:51 -0700 | [diff] [blame] | 99 | size_t offset = 0; |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 100 | for (uint32_t lod=0; lod < mHal.state.lodCount; lod++) { |
| 101 | mHal.state.lodDimX[lod] = tx; |
| 102 | mHal.state.lodDimY[lod] = ty; |
| 103 | mHal.state.lodDimZ[lod] = tz; |
Stephen Hines | 86087f2 | 2012-10-19 19:16:51 -0700 | [diff] [blame] | 104 | mHal.state.lodOffset[lod] = offset; |
| 105 | offset += tx * rsMax(ty, 1u) * rsMax(tz, 1u) * mElement->getSizeBytes(); |
Jason Sams | 7c52898 | 2010-01-07 16:25:08 -0800 | [diff] [blame] | 106 | if (tx > 1) tx >>= 1; |
| 107 | if (ty > 1) ty >>= 1; |
| 108 | if (tz > 1) tz >>= 1; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 111 | // At this point the offset is the size of a mipmap chain; |
Stephen Hines | 86087f2 | 2012-10-19 19:16:51 -0700 | [diff] [blame] | 112 | mMipChainSizeBytes = offset; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 113 | |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 114 | if (mHal.state.faces) { |
Stephen Hines | 86087f2 | 2012-10-19 19:16:51 -0700 | [diff] [blame] | 115 | offset *= 6; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 116 | } |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 117 | #ifndef RS_SERVER |
Jason Sams | bc0ca6b | 2013-02-15 18:13:43 -0800 | [diff] [blame] | 118 | // YUV only supports basic 2d |
| 119 | // so we can stash the plane pointers in the mipmap levels. |
| 120 | if (mHal.state.dimYuv) { |
| 121 | switch(mHal.state.dimYuv) { |
| 122 | case HAL_PIXEL_FORMAT_YV12: |
| 123 | mHal.state.lodOffset[1] = offset; |
| 124 | mHal.state.lodDimX[1] = mHal.state.lodDimX[0] / 2; |
| 125 | mHal.state.lodDimY[1] = mHal.state.lodDimY[0] / 2; |
| 126 | offset += offset / 4; |
| 127 | mHal.state.lodOffset[2] = offset; |
| 128 | mHal.state.lodDimX[2] = mHal.state.lodDimX[0] / 2; |
| 129 | mHal.state.lodDimY[2] = mHal.state.lodDimY[0] / 2; |
| 130 | offset += offset / 4; |
| 131 | break; |
| 132 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: // NV21 |
| 133 | mHal.state.lodOffset[1] = offset; |
| 134 | mHal.state.lodDimX[1] = mHal.state.lodDimX[0]; |
| 135 | mHal.state.lodDimY[1] = mHal.state.lodDimY[0] / 2; |
| 136 | offset += offset / 2; |
| 137 | break; |
| 138 | default: |
| 139 | rsAssert(0); |
| 140 | } |
| 141 | } |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 142 | #endif |
Stephen Hines | 86087f2 | 2012-10-19 19:16:51 -0700 | [diff] [blame] | 143 | mTotalSizeBytes = offset; |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 144 | mHal.state.element = mElement.get(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Stephen Hines | 86087f2 | 2012-10-19 19:16:51 -0700 | [diff] [blame] | 147 | uint32_t Type::getLODOffset(uint32_t lod, uint32_t x) const { |
| 148 | uint32_t offset = mHal.state.lodOffset[lod]; |
| 149 | offset += x * mElement->getSizeBytes(); |
| 150 | return offset; |
| 151 | } |
| 152 | |
| 153 | uint32_t Type::getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const { |
| 154 | uint32_t offset = mHal.state.lodOffset[lod]; |
| 155 | offset += (x + y * mHal.state.lodDimX[lod]) * mElement->getSizeBytes(); |
| 156 | return offset; |
| 157 | } |
| 158 | |
| 159 | uint32_t Type::getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const { |
| 160 | uint32_t offset = mHal.state.lodOffset[lod]; |
| 161 | offset += (x + |
| 162 | y * mHal.state.lodDimX[lod] + |
| 163 | z * mHal.state.lodDimX[lod] * mHal.state.lodDimY[lod]) * mElement->getSizeBytes(); |
| 164 | return offset; |
| 165 | } |
| 166 | |
| 167 | uint32_t Type::getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face, |
| 168 | uint32_t x, uint32_t y) const { |
| 169 | uint32_t offset = mHal.state.lodOffset[lod]; |
| 170 | offset += (x + y * mHal.state.lodDimX[lod]) * mElement->getSizeBytes(); |
| 171 | |
| 172 | if (face != 0) { |
| 173 | uint32_t faceOffset = getSizeBytes() / 6; |
| 174 | offset += faceOffset * face; |
| 175 | } |
| 176 | return offset; |
| 177 | } |
| 178 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 179 | void Type::dumpLOGV(const char *prefix) const { |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 180 | char buf[1024]; |
| 181 | ObjectBase::dumpLOGV(prefix); |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 182 | ALOGV("%s Type: x=%u y=%u z=%u mip=%i face=%i", prefix, |
| 183 | mHal.state.dimX, |
| 184 | mHal.state.dimY, |
| 185 | mHal.state.dimZ, |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 186 | mHal.state.lodCount, |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 187 | mHal.state.faces); |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 188 | snprintf(buf, sizeof(buf), "%s element: ", prefix); |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 189 | mElement->dumpLOGV(buf); |
| 190 | } |
| 191 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 192 | void Type::serialize(Context *rsc, OStream *stream) const { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 193 | // Need to identify ourselves |
| 194 | stream->addU32((uint32_t)getClassId()); |
| 195 | |
| 196 | String8 name(getName()); |
| 197 | stream->addString(&name); |
| 198 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 199 | mElement->serialize(rsc, stream); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 200 | |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 201 | stream->addU32(mHal.state.dimX); |
| 202 | stream->addU32(mHal.state.dimY); |
| 203 | stream->addU32(mHal.state.dimZ); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 204 | |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 205 | stream->addU8((uint8_t)(mHal.state.lodCount ? 1 : 0)); |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 206 | stream->addU8((uint8_t)(mHal.state.faces ? 1 : 0)); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 209 | Type *Type::createFromStream(Context *rsc, IStream *stream) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 210 | // First make sure we are reading the correct object |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 211 | RsA3DClassID classID = (RsA3DClassID)stream->loadU32(); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 212 | if (classID != RS_A3D_CLASS_ID_TYPE) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 213 | ALOGE("type loading skipped due to invalid class id\n"); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 214 | return NULL; |
| 215 | } |
| 216 | |
| 217 | String8 name; |
| 218 | stream->loadString(&name); |
| 219 | |
| 220 | Element *elem = Element::createFromStream(rsc, stream); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 221 | if (!elem) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 222 | return NULL; |
| 223 | } |
| 224 | |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 225 | uint32_t x = stream->loadU32(); |
| 226 | uint32_t y = stream->loadU32(); |
| 227 | uint32_t z = stream->loadU32(); |
| 228 | uint8_t lod = stream->loadU8(); |
| 229 | uint8_t faces = stream->loadU8(); |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 230 | Type *type = Type::getType(rsc, elem, x, y, z, lod != 0, faces !=0, 0); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 231 | elem->decUserRef(); |
| 232 | return type; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 235 | bool Type::getIsNp2() const { |
Jason Sams | ef21edc | 2010-02-22 15:37:51 -0800 | [diff] [blame] | 236 | uint32_t x = getDimX(); |
| 237 | uint32_t y = getDimY(); |
| 238 | uint32_t z = getDimZ(); |
| 239 | |
| 240 | if (x && (x & (x-1))) { |
| 241 | return true; |
| 242 | } |
| 243 | if (y && (y & (y-1))) { |
| 244 | return true; |
| 245 | } |
| 246 | if (z && (z & (z-1))) { |
| 247 | return true; |
| 248 | } |
| 249 | return false; |
| 250 | } |
| 251 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 252 | ObjectBaseRef<Type> Type::getTypeRef(Context *rsc, const Element *e, |
| 253 | uint32_t dimX, uint32_t dimY, uint32_t dimZ, |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 254 | bool dimLOD, bool dimFaces, uint32_t dimYuv) { |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 255 | ObjectBaseRef<Type> returnRef; |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 256 | |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 257 | TypeState * stc = &rsc->mStateType; |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 258 | |
| 259 | ObjectBase::asyncLock(); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 260 | for (uint32_t ct=0; ct < stc->mTypes.size(); ct++) { |
| 261 | Type *t = stc->mTypes[ct]; |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 262 | if (t->getElement() != e) continue; |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 263 | if (t->getDimX() != dimX) continue; |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 264 | if (t->getDimY() != dimY) continue; |
| 265 | if (t->getDimZ() != dimZ) continue; |
| 266 | if (t->getDimLOD() != dimLOD) continue; |
| 267 | if (t->getDimFaces() != dimFaces) continue; |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 268 | if (t->getDimYuv() != dimYuv) continue; |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 269 | returnRef.set(t); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 270 | ObjectBase::asyncUnlock(); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 271 | return returnRef; |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 272 | } |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 273 | ObjectBase::asyncUnlock(); |
| 274 | |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 275 | |
| 276 | Type *nt = new Type(rsc); |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 277 | nt->mDimLOD = dimLOD; |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 278 | returnRef.set(nt); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 279 | nt->mElement.set(e); |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 280 | nt->mHal.state.dimX = dimX; |
| 281 | nt->mHal.state.dimY = dimY; |
| 282 | nt->mHal.state.dimZ = dimZ; |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 283 | nt->mHal.state.faces = dimFaces; |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 284 | nt->mHal.state.dimYuv = dimYuv; |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 285 | nt->compute(); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 286 | |
| 287 | ObjectBase::asyncLock(); |
| 288 | stc->mTypes.push(nt); |
| 289 | ObjectBase::asyncUnlock(); |
| 290 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 291 | return returnRef; |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 294 | ObjectBaseRef<Type> Type::cloneAndResize1D(Context *rsc, uint32_t dimX) const { |
| 295 | return getTypeRef(rsc, mElement.get(), dimX, |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 296 | getDimY(), getDimZ(), getDimLOD(), getDimFaces(), getDimYuv()); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 299 | ObjectBaseRef<Type> Type::cloneAndResize2D(Context *rsc, |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 300 | uint32_t dimX, |
| 301 | uint32_t dimY) const { |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 302 | return getTypeRef(rsc, mElement.get(), dimX, dimY, |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 303 | getDimZ(), getDimLOD(), getDimFaces(), getDimYuv()); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | |
Stephen Hines | 9f70a4e | 2012-04-02 20:18:48 -0700 | [diff] [blame] | 307 | void Type::incRefs(const void *ptr, size_t ct, size_t startOff) const { |
| 308 | const uint8_t *p = static_cast<const uint8_t *>(ptr); |
| 309 | const Element *e = mHal.state.element; |
| 310 | uint32_t stride = e->getSizeBytes(); |
| 311 | |
| 312 | p += stride * startOff; |
| 313 | while (ct > 0) { |
| 314 | e->incRefs(p); |
| 315 | ct--; |
| 316 | p += stride; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | |
| 321 | void Type::decRefs(const void *ptr, size_t ct, size_t startOff) const { |
| 322 | if (!mHal.state.element->getHasReferences()) { |
| 323 | return; |
| 324 | } |
| 325 | const uint8_t *p = static_cast<const uint8_t *>(ptr); |
| 326 | const Element *e = mHal.state.element; |
| 327 | uint32_t stride = e->getSizeBytes(); |
| 328 | |
| 329 | p += stride * startOff; |
| 330 | while (ct > 0) { |
| 331 | e->decRefs(p); |
| 332 | ct--; |
| 333 | p += stride; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 338 | ////////////////////////////////////////////////// |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 339 | // |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 340 | namespace android { |
| 341 | namespace renderscript { |
| 342 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 343 | RsType rsi_TypeCreate(Context *rsc, RsElement _e, uint32_t dimX, |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 344 | uint32_t dimY, uint32_t dimZ, bool mips, bool faces, uint32_t yuv) { |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 345 | Element *e = static_cast<Element *>(_e); |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 346 | |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 347 | return Type::getType(rsc, e, dimX, dimY, dimZ, mips, faces, yuv); |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 353 | void rsaTypeGetNativeData(RsContext con, RsType type, uintptr_t *typeData, uint32_t typeDataSize) { |
Alex Sakhartchouk | dc763f3 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 354 | rsAssert(typeDataSize == 6); |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 355 | // Pack the data in the follofing way mHal.state.dimX; mHal.state.dimY; mHal.state.dimZ; |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 356 | // mHal.state.lodCount; mHal.state.faces; mElement; into typeData |
Alex Sakhartchouk | dc763f3 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 357 | Type *t = static_cast<Type *>(type); |
| 358 | |
| 359 | (*typeData++) = t->getDimX(); |
| 360 | (*typeData++) = t->getDimY(); |
| 361 | (*typeData++) = t->getDimZ(); |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 362 | (*typeData++) = t->getDimLOD() ? 1 : 0; |
Alex Sakhartchouk | dc763f3 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 363 | (*typeData++) = t->getDimFaces() ? 1 : 0; |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 364 | (*typeData++) = (uintptr_t)t->getElement(); |
Alex Sakhartchouk | dc763f3 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 365 | t->getElement()->incUserRef(); |
| 366 | } |