Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 ANDROID_RSCPPSTRUCTS_H |
| 18 | #define ANDROID_RSCPPSTRUCTS_H |
| 19 | |
Jason Sams | f9e077a | 2013-03-20 19:04:19 -0700 | [diff] [blame] | 20 | #include "rsCppUtils.h" |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 21 | #ifndef RS_SERVER |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 22 | #include "utils/RefBase.h" |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 23 | #else |
| 24 | #include "RefBase.h" |
| 25 | #endif |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 26 | |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 27 | #include "rsDispatch.h" |
| 28 | |
Tim Murray | 96267c2 | 2013-02-12 11:25:12 -0800 | [diff] [blame] | 29 | // Every row in an RS allocation is guaranteed to be aligned by this amount |
| 30 | // Every row in a user-backed allocation must be aligned by this amount |
| 31 | #define RS_CPU_ALLOCATION_ALIGNMENT 16 |
| 32 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 33 | namespace android { |
Tim Murray | 9eb7f4b | 2012-11-16 14:02:18 -0800 | [diff] [blame] | 34 | namespace RSC { |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 35 | |
| 36 | typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText); |
| 37 | typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen); |
| 38 | |
| 39 | class RS; |
| 40 | class BaseObj; |
| 41 | class Element; |
| 42 | class Type; |
| 43 | class Allocation; |
| 44 | class Script; |
| 45 | class ScriptC; |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 46 | class Sampler; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 47 | |
| 48 | class RS : public android::LightRefBase<RS> { |
| 49 | |
| 50 | public: |
| 51 | RS(); |
| 52 | virtual ~RS(); |
| 53 | |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 54 | bool init(bool forceCpu = false, bool synchronous = false); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 55 | |
| 56 | void setErrorHandler(ErrorHandlerFunc_t func); |
| 57 | ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; } |
| 58 | |
| 59 | void setMessageHandler(MessageHandlerFunc_t func); |
| 60 | MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; } |
| 61 | |
| 62 | void throwError(const char *err) const; |
| 63 | |
| 64 | RsContext getContext() { return mContext; } |
| 65 | |
Tim Murray | baca6c3 | 2012-11-14 16:51:46 -0800 | [diff] [blame] | 66 | void finish(); |
| 67 | |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 68 | static dispatchTable* dispatch; |
| 69 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 70 | private: |
Tim Murray | 4a92d12 | 2013-07-22 10:56:18 -0700 | [diff] [blame] | 71 | static bool usingNative; |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 72 | static bool initDispatch(int targetApi); |
| 73 | |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 74 | bool init(int targetApi, bool forceCpu, bool synchronous); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 75 | static void * threadProc(void *); |
| 76 | |
| 77 | static bool gInitialized; |
| 78 | static pthread_mutex_t gInitMutex; |
| 79 | |
| 80 | pthread_t mMessageThreadId; |
| 81 | pid_t mNativeMessageThreadId; |
| 82 | bool mMessageRun; |
| 83 | |
| 84 | RsDevice mDev; |
| 85 | RsContext mContext; |
| 86 | |
| 87 | ErrorHandlerFunc_t mErrorFunc; |
| 88 | MessageHandlerFunc_t mMessageFunc; |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 89 | bool mInit; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 90 | |
| 91 | struct { |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 92 | const Element *U8; |
| 93 | const Element *I8; |
| 94 | const Element *U16; |
| 95 | const Element *I16; |
| 96 | const Element *U32; |
| 97 | const Element *I32; |
| 98 | const Element *U64; |
| 99 | const Element *I64; |
| 100 | const Element *F32; |
| 101 | const Element *F64; |
| 102 | const Element *BOOLEAN; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 103 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 104 | const Element *ELEMENT; |
| 105 | const Element *TYPE; |
| 106 | const Element *ALLOCATION; |
| 107 | const Element *SAMPLER; |
| 108 | const Element *SCRIPT; |
| 109 | const Element *MESH; |
| 110 | const Element *PROGRAM_FRAGMENT; |
| 111 | const Element *PROGRAM_VERTEX; |
| 112 | const Element *PROGRAM_RASTER; |
| 113 | const Element *PROGRAM_STORE; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 114 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 115 | const Element *A_8; |
| 116 | const Element *RGB_565; |
| 117 | const Element *RGB_888; |
| 118 | const Element *RGBA_5551; |
| 119 | const Element *RGBA_4444; |
| 120 | const Element *RGBA_8888; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 121 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 122 | const Element *FLOAT_2; |
| 123 | const Element *FLOAT_3; |
| 124 | const Element *FLOAT_4; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 125 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 126 | const Element *DOUBLE_2; |
| 127 | const Element *DOUBLE_3; |
| 128 | const Element *DOUBLE_4; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 129 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 130 | const Element *UCHAR_2; |
| 131 | const Element *UCHAR_3; |
| 132 | const Element *UCHAR_4; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 133 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 134 | const Element *CHAR_2; |
| 135 | const Element *CHAR_3; |
| 136 | const Element *CHAR_4; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 137 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 138 | const Element *USHORT_2; |
| 139 | const Element *USHORT_3; |
| 140 | const Element *USHORT_4; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 141 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 142 | const Element *SHORT_2; |
| 143 | const Element *SHORT_3; |
| 144 | const Element *SHORT_4; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 145 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 146 | const Element *UINT_2; |
| 147 | const Element *UINT_3; |
| 148 | const Element *UINT_4; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 149 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 150 | const Element *INT_2; |
| 151 | const Element *INT_3; |
| 152 | const Element *INT_4; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 153 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 154 | const Element *ULONG_2; |
| 155 | const Element *ULONG_3; |
| 156 | const Element *ULONG_4; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 157 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 158 | const Element *LONG_2; |
| 159 | const Element *LONG_3; |
| 160 | const Element *LONG_4; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 161 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 162 | const Element *MATRIX_4X4; |
| 163 | const Element *MATRIX_3X3; |
| 164 | const Element *MATRIX_2X2; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 165 | } mElements; |
| 166 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 167 | struct { |
| 168 | const Sampler* CLAMP_NEAREST; |
| 169 | const Sampler* CLAMP_LINEAR; |
| 170 | const Sampler* CLAMP_LINEAR_MIP_LINEAR; |
| 171 | const Sampler* WRAP_NEAREST; |
| 172 | const Sampler* WRAP_LINEAR; |
| 173 | const Sampler* WRAP_LINEAR_MIP_LINEAR; |
| 174 | const Sampler* MIRRORED_REPEAT_NEAREST; |
| 175 | const Sampler* MIRRORED_REPEAT_LINEAR; |
| 176 | const Sampler* MIRRORED_REPEAT_LINEAR_MIP_LINEAR; |
| 177 | } mSamplers; |
| 178 | friend class Sampler; |
| 179 | friend class Element; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | class BaseObj : public android::LightRefBase<BaseObj> { |
| 183 | protected: |
| 184 | void *mID; |
| 185 | sp<RS> mRS; |
| 186 | String8 mName; |
| 187 | |
| 188 | BaseObj(void *id, sp<RS> rs); |
| 189 | void checkValid(); |
| 190 | |
| 191 | static void * getObjID(sp<const BaseObj> o); |
| 192 | |
| 193 | public: |
| 194 | |
| 195 | void * getID() const; |
| 196 | virtual ~BaseObj(); |
| 197 | virtual void updateFromNative(); |
| 198 | virtual bool equals(const BaseObj *obj); |
| 199 | }; |
| 200 | |
| 201 | |
| 202 | class Allocation : public BaseObj { |
| 203 | protected: |
| 204 | android::sp<const Type> mType; |
| 205 | uint32_t mUsage; |
| 206 | android::sp<Allocation> mAdaptedAllocation; |
| 207 | |
| 208 | bool mConstrainedLOD; |
| 209 | bool mConstrainedFace; |
| 210 | bool mConstrainedY; |
| 211 | bool mConstrainedZ; |
| 212 | bool mReadAllowed; |
| 213 | bool mWriteAllowed; |
| 214 | uint32_t mSelectedY; |
| 215 | uint32_t mSelectedZ; |
| 216 | uint32_t mSelectedLOD; |
| 217 | RsAllocationCubemapFace mSelectedFace; |
| 218 | |
| 219 | uint32_t mCurrentDimX; |
| 220 | uint32_t mCurrentDimY; |
| 221 | uint32_t mCurrentDimZ; |
| 222 | uint32_t mCurrentCount; |
| 223 | |
| 224 | void * getIDSafe() const; |
| 225 | void updateCacheInfo(sp<const Type> t); |
| 226 | |
| 227 | Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage); |
| 228 | |
| 229 | void validateIsInt32(); |
| 230 | void validateIsInt16(); |
| 231 | void validateIsInt8(); |
| 232 | void validateIsFloat32(); |
| 233 | void validateIsObject(); |
| 234 | |
| 235 | virtual void updateFromNative(); |
| 236 | |
| 237 | void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h); |
| 238 | |
| 239 | public: |
| 240 | android::sp<const Type> getType() { |
| 241 | return mType; |
| 242 | } |
| 243 | |
| 244 | void syncAll(RsAllocationUsageType srcLocation); |
| 245 | void ioSendOutput(); |
| 246 | void ioGetInput(); |
| 247 | |
| 248 | void generateMipmaps(); |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 249 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 250 | void copy1DRangeFrom(uint32_t off, size_t count, const void *data); |
Tim Murray | a4cbc2b | 2012-11-14 17:18:08 -0800 | [diff] [blame] | 251 | void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 252 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 253 | void copy1DRangeTo(uint32_t off, size_t count, void *data); |
| 254 | |
| 255 | void copy1DFrom(const void* data); |
| 256 | void copy1DTo(void* data); |
Tim Murray | a4cbc2b | 2012-11-14 17:18:08 -0800 | [diff] [blame] | 257 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 258 | void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 259 | const void *data); |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 260 | |
| 261 | void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 262 | void *data); |
| 263 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 264 | void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 265 | sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 266 | |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 267 | void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 268 | const void *data, size_t stride); |
| 269 | void copy2DStridedFrom(const void *data, size_t stride); |
| 270 | |
| 271 | void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 272 | void *data, size_t stride); |
| 273 | void copy2DStridedTo(void *data, size_t stride); |
| 274 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 275 | void resize(int dimX); |
| 276 | void resize(int dimX, int dimY); |
| 277 | |
| 278 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| 279 | RsAllocationMipmapControl mips, uint32_t usage); |
| 280 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| 281 | RsAllocationMipmapControl mips, uint32_t usage, void * pointer); |
| 282 | |
| 283 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| 284 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
| 285 | static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count, |
| 286 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 287 | static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e, |
| 288 | size_t x, size_t y, |
| 289 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
| 290 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 291 | |
| 292 | }; |
| 293 | |
| 294 | class Element : public BaseObj { |
| 295 | public: |
| 296 | bool isComplex(); |
| 297 | size_t getSubElementCount() { |
| 298 | return mVisibleElementMap.size(); |
| 299 | } |
| 300 | |
| 301 | sp<const Element> getSubElement(uint32_t index); |
| 302 | const char * getSubElementName(uint32_t index); |
| 303 | size_t getSubElementArraySize(uint32_t index); |
| 304 | uint32_t getSubElementOffsetBytes(uint32_t index); |
| 305 | RsDataType getDataType() const { |
| 306 | return mType; |
| 307 | } |
| 308 | |
| 309 | RsDataKind getDataKind() const { |
| 310 | return mKind; |
| 311 | } |
| 312 | |
| 313 | size_t getSizeBytes() const { |
| 314 | return mSizeBytes; |
| 315 | } |
| 316 | |
| 317 | static sp<const Element> BOOLEAN(sp<RS> rs); |
| 318 | static sp<const Element> U8(sp<RS> rs); |
| 319 | static sp<const Element> I8(sp<RS> rs); |
| 320 | static sp<const Element> U16(sp<RS> rs); |
| 321 | static sp<const Element> I16(sp<RS> rs); |
| 322 | static sp<const Element> U32(sp<RS> rs); |
| 323 | static sp<const Element> I32(sp<RS> rs); |
| 324 | static sp<const Element> U64(sp<RS> rs); |
| 325 | static sp<const Element> I64(sp<RS> rs); |
| 326 | static sp<const Element> F32(sp<RS> rs); |
| 327 | static sp<const Element> F64(sp<RS> rs); |
| 328 | static sp<const Element> ELEMENT(sp<RS> rs); |
| 329 | static sp<const Element> TYPE(sp<RS> rs); |
| 330 | static sp<const Element> ALLOCATION(sp<RS> rs); |
| 331 | static sp<const Element> SAMPLER(sp<RS> rs); |
| 332 | static sp<const Element> SCRIPT(sp<RS> rs); |
| 333 | static sp<const Element> MESH(sp<RS> rs); |
| 334 | static sp<const Element> PROGRAM_FRAGMENT(sp<RS> rs); |
| 335 | static sp<const Element> PROGRAM_VERTEX(sp<RS> rs); |
| 336 | static sp<const Element> PROGRAM_RASTER(sp<RS> rs); |
| 337 | static sp<const Element> PROGRAM_STORE(sp<RS> rs); |
| 338 | |
| 339 | static sp<const Element> A_8(sp<RS> rs); |
| 340 | static sp<const Element> RGB_565(sp<RS> rs); |
| 341 | static sp<const Element> RGB_888(sp<RS> rs); |
| 342 | static sp<const Element> RGBA_5551(sp<RS> rs); |
| 343 | static sp<const Element> RGBA_4444(sp<RS> rs); |
| 344 | static sp<const Element> RGBA_8888(sp<RS> rs); |
| 345 | |
| 346 | static sp<const Element> F32_2(sp<RS> rs); |
| 347 | static sp<const Element> F32_3(sp<RS> rs); |
| 348 | static sp<const Element> F32_4(sp<RS> rs); |
| 349 | static sp<const Element> F64_2(sp<RS> rs); |
| 350 | static sp<const Element> F64_3(sp<RS> rs); |
| 351 | static sp<const Element> F64_4(sp<RS> rs); |
| 352 | static sp<const Element> U8_2(sp<RS> rs); |
| 353 | static sp<const Element> U8_3(sp<RS> rs); |
| 354 | static sp<const Element> U8_4(sp<RS> rs); |
| 355 | static sp<const Element> I8_2(sp<RS> rs); |
| 356 | static sp<const Element> I8_3(sp<RS> rs); |
| 357 | static sp<const Element> I8_4(sp<RS> rs); |
| 358 | static sp<const Element> U16_2(sp<RS> rs); |
| 359 | static sp<const Element> U16_3(sp<RS> rs); |
| 360 | static sp<const Element> U16_4(sp<RS> rs); |
| 361 | static sp<const Element> I16_2(sp<RS> rs); |
| 362 | static sp<const Element> I16_3(sp<RS> rs); |
| 363 | static sp<const Element> I16_4(sp<RS> rs); |
| 364 | static sp<const Element> U32_2(sp<RS> rs); |
| 365 | static sp<const Element> U32_3(sp<RS> rs); |
| 366 | static sp<const Element> U32_4(sp<RS> rs); |
| 367 | static sp<const Element> I32_2(sp<RS> rs); |
| 368 | static sp<const Element> I32_3(sp<RS> rs); |
| 369 | static sp<const Element> I32_4(sp<RS> rs); |
| 370 | static sp<const Element> U64_2(sp<RS> rs); |
| 371 | static sp<const Element> U64_3(sp<RS> rs); |
| 372 | static sp<const Element> U64_4(sp<RS> rs); |
| 373 | static sp<const Element> I64_2(sp<RS> rs); |
| 374 | static sp<const Element> I64_3(sp<RS> rs); |
| 375 | static sp<const Element> I64_4(sp<RS> rs); |
| 376 | static sp<const Element> MATRIX_4X4(sp<RS> rs); |
| 377 | static sp<const Element> MATRIX_3X3(sp<RS> rs); |
| 378 | static sp<const Element> MATRIX_2X2(sp<RS> rs); |
| 379 | |
| 380 | Element(void *id, sp<RS> rs, |
| 381 | android::Vector<sp<Element> > &elements, |
| 382 | android::Vector<android::String8> &elementNames, |
| 383 | android::Vector<uint32_t> &arraySizes); |
| 384 | Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size); |
| 385 | Element(sp<RS> rs); |
| 386 | virtual ~Element(); |
| 387 | |
| 388 | void updateFromNative(); |
| 389 | static sp<const Element> createUser(sp<RS> rs, RsDataType dt); |
| 390 | static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size); |
| 391 | static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk); |
| 392 | bool isCompatible(sp<const Element>e); |
| 393 | |
| 394 | class Builder { |
| 395 | private: |
| 396 | sp<RS> mRS; |
| 397 | android::Vector<sp<Element> > mElements; |
| 398 | android::Vector<android::String8> mElementNames; |
| 399 | android::Vector<uint32_t> mArraySizes; |
| 400 | bool mSkipPadding; |
| 401 | |
| 402 | public: |
| 403 | Builder(sp<RS> rs); |
| 404 | ~Builder(); |
| 405 | void add(sp<Element>, android::String8 &name, uint32_t arraySize = 1); |
| 406 | sp<const Element> create(); |
| 407 | }; |
| 408 | |
| 409 | private: |
| 410 | void updateVisibleSubElements(); |
| 411 | |
| 412 | android::Vector<sp</*const*/ Element> > mElements; |
| 413 | android::Vector<android::String8> mElementNames; |
| 414 | android::Vector<uint32_t> mArraySizes; |
| 415 | android::Vector<uint32_t> mVisibleElementMap; |
| 416 | android::Vector<uint32_t> mOffsetInBytes; |
| 417 | |
| 418 | RsDataType mType; |
| 419 | RsDataKind mKind; |
| 420 | bool mNormalized; |
| 421 | size_t mSizeBytes; |
| 422 | size_t mVectorSize; |
| 423 | }; |
| 424 | |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 425 | class FieldPacker { |
| 426 | protected: |
| 427 | unsigned char* mData; |
| 428 | size_t mPos; |
| 429 | size_t mLen; |
| 430 | |
| 431 | public: |
| 432 | FieldPacker(size_t len) |
| 433 | : mPos(0), |
| 434 | mLen(len) { |
| 435 | mData = new unsigned char[len]; |
| 436 | } |
| 437 | |
| 438 | virtual ~FieldPacker() { |
| 439 | delete [] mData; |
| 440 | } |
| 441 | |
| 442 | void align(size_t v) { |
| 443 | if ((v & (v - 1)) != 0) { |
| 444 | ALOGE("Non-power-of-two alignment: %zu", v); |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | while ((mPos & (v - 1)) != 0) { |
| 449 | mData[mPos++] = 0; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | void reset() { |
| 454 | mPos = 0; |
| 455 | } |
| 456 | |
| 457 | void reset(size_t i) { |
| 458 | if (i >= mLen) { |
| 459 | ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen); |
| 460 | return; |
| 461 | } |
| 462 | mPos = i; |
| 463 | } |
| 464 | |
| 465 | void skip(size_t i) { |
| 466 | size_t res = mPos + i; |
| 467 | if (res > mLen) { |
| 468 | ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen); |
| 469 | return; |
| 470 | } |
| 471 | mPos = res; |
| 472 | } |
| 473 | |
| 474 | void* getData() const { |
| 475 | return mData; |
| 476 | } |
| 477 | |
| 478 | size_t getLength() const { |
| 479 | return mLen; |
| 480 | } |
| 481 | |
| 482 | template <typename T> |
| 483 | void add(T t) { |
| 484 | align(sizeof(t)); |
| 485 | if (mPos + sizeof(t) <= mLen) { |
| 486 | memcpy(&mData[mPos], &t, sizeof(t)); |
| 487 | mPos += sizeof(t); |
| 488 | } |
| 489 | } |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 490 | |
| 491 | /* |
| 492 | void add(rs_matrix4x4 m) { |
| 493 | for (size_t i = 0; i < 16; i++) { |
| 494 | add(m.m[i]); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | void add(rs_matrix3x3 m) { |
| 499 | for (size_t i = 0; i < 9; i++) { |
| 500 | add(m.m[i]); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | void add(rs_matrix2x2 m) { |
| 505 | for (size_t i = 0; i < 4; i++) { |
| 506 | add(m.m[i]); |
| 507 | } |
| 508 | } |
| 509 | */ |
| 510 | |
| 511 | void add(BaseObj* obj) { |
| 512 | if (obj != NULL) { |
| 513 | add((uint32_t) (uintptr_t) obj->getID()); |
| 514 | } else { |
| 515 | add((uint32_t) 0); |
| 516 | } |
| 517 | } |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 518 | }; |
| 519 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 520 | class Type : public BaseObj { |
| 521 | protected: |
| 522 | friend class Allocation; |
| 523 | |
| 524 | uint32_t mDimX; |
| 525 | uint32_t mDimY; |
| 526 | uint32_t mDimZ; |
| 527 | bool mDimMipmaps; |
| 528 | bool mDimFaces; |
| 529 | size_t mElementCount; |
| 530 | sp<const Element> mElement; |
| 531 | |
| 532 | void calcElementCount(); |
| 533 | virtual void updateFromNative(); |
| 534 | |
| 535 | public: |
| 536 | |
| 537 | sp<const Element> getElement() const { |
| 538 | return mElement; |
| 539 | } |
| 540 | |
| 541 | uint32_t getX() const { |
| 542 | return mDimX; |
| 543 | } |
| 544 | |
| 545 | uint32_t getY() const { |
| 546 | return mDimY; |
| 547 | } |
| 548 | |
| 549 | uint32_t getZ() const { |
| 550 | return mDimZ; |
| 551 | } |
| 552 | |
| 553 | bool hasMipmaps() const { |
| 554 | return mDimMipmaps; |
| 555 | } |
| 556 | |
| 557 | bool hasFaces() const { |
| 558 | return mDimFaces; |
| 559 | } |
| 560 | |
| 561 | size_t getCount() const { |
| 562 | return mElementCount; |
| 563 | } |
| 564 | |
| 565 | size_t getSizeBytes() const { |
| 566 | return mElementCount * mElement->getSizeBytes(); |
| 567 | } |
| 568 | |
| 569 | Type(void *id, sp<RS> rs); |
| 570 | |
Tim Murray | 96267c2 | 2013-02-12 11:25:12 -0800 | [diff] [blame] | 571 | static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 572 | |
| 573 | class Builder { |
| 574 | protected: |
| 575 | sp<RS> mRS; |
| 576 | uint32_t mDimX; |
| 577 | uint32_t mDimY; |
| 578 | uint32_t mDimZ; |
| 579 | bool mDimMipmaps; |
| 580 | bool mDimFaces; |
| 581 | sp<const Element> mElement; |
| 582 | |
| 583 | public: |
| 584 | Builder(sp<RS> rs, sp<const Element> e); |
| 585 | |
| 586 | void setX(uint32_t value); |
| 587 | void setY(int value); |
| 588 | void setMipmaps(bool value); |
| 589 | void setFaces(bool value); |
| 590 | sp<const Type> create(); |
| 591 | }; |
| 592 | |
| 593 | }; |
| 594 | |
| 595 | class Script : public BaseObj { |
| 596 | private: |
| 597 | |
| 598 | protected: |
| 599 | Script(void *id, sp<RS> rs); |
| 600 | void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out, |
| 601 | const void *v, size_t) const; |
| 602 | void bindAllocation(sp<Allocation> va, uint32_t slot) const; |
| 603 | void setVar(uint32_t index, const void *, size_t len) const; |
| 604 | void setVar(uint32_t index, sp<const BaseObj> o) const; |
| 605 | void invoke(uint32_t slot, const void *v, size_t len) const; |
| 606 | |
| 607 | |
| 608 | void invoke(uint32_t slot) const { |
| 609 | invoke(slot, NULL, 0); |
| 610 | } |
| 611 | void setVar(uint32_t index, float v) const { |
| 612 | setVar(index, &v, sizeof(v)); |
| 613 | } |
| 614 | void setVar(uint32_t index, double v) const { |
| 615 | setVar(index, &v, sizeof(v)); |
| 616 | } |
| 617 | void setVar(uint32_t index, int32_t v) const { |
| 618 | setVar(index, &v, sizeof(v)); |
| 619 | } |
| 620 | void setVar(uint32_t index, int64_t v) const { |
| 621 | setVar(index, &v, sizeof(v)); |
| 622 | } |
| 623 | void setVar(uint32_t index, bool v) const { |
| 624 | setVar(index, &v, sizeof(v)); |
| 625 | } |
| 626 | |
| 627 | public: |
| 628 | class FieldBase { |
| 629 | protected: |
| 630 | sp<const Element> mElement; |
| 631 | sp<Allocation> mAllocation; |
| 632 | |
| 633 | void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0); |
| 634 | |
| 635 | public: |
| 636 | sp<const Element> getElement() { |
| 637 | return mElement; |
| 638 | } |
| 639 | |
| 640 | sp<const Type> getType() { |
| 641 | return mAllocation->getType(); |
| 642 | } |
| 643 | |
| 644 | sp<const Allocation> getAllocation() { |
| 645 | return mAllocation; |
| 646 | } |
| 647 | |
| 648 | //void updateAllocation(); |
| 649 | }; |
| 650 | }; |
| 651 | |
| 652 | class ScriptC : public Script { |
| 653 | protected: |
| 654 | ScriptC(sp<RS> rs, |
| 655 | const void *codeTxt, size_t codeLength, |
| 656 | const char *cachedName, size_t cachedNameLength, |
| 657 | const char *cacheDir, size_t cacheDirLength); |
| 658 | |
| 659 | }; |
| 660 | |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 661 | class ScriptIntrinsic : public Script { |
| 662 | protected: |
Tim Murray | 3cd44af | 2012-11-14 11:25:27 -0800 | [diff] [blame] | 663 | ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e); |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 664 | }; |
| 665 | |
| 666 | class ScriptIntrinsicBlend : public ScriptIntrinsic { |
| 667 | public: |
Tim Murray | 3cd44af | 2012-11-14 11:25:27 -0800 | [diff] [blame] | 668 | ScriptIntrinsicBlend(sp<RS> rs, sp <const Element> e); |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 669 | void blendClear(sp<Allocation> in, sp<Allocation> out); |
| 670 | void blendSrc(sp<Allocation> in, sp<Allocation> out); |
| 671 | void blendDst(sp<Allocation> in, sp<Allocation> out); |
| 672 | void blendSrcOver(sp<Allocation> in, sp<Allocation> out); |
| 673 | void blendDstOver(sp<Allocation> in, sp<Allocation> out); |
| 674 | void blendSrcIn(sp<Allocation> in, sp<Allocation> out); |
| 675 | void blendDstIn(sp<Allocation> in, sp<Allocation> out); |
| 676 | void blendSrcOut(sp<Allocation> in, sp<Allocation> out); |
| 677 | void blendDstOut(sp<Allocation> in, sp<Allocation> out); |
| 678 | void blendSrcAtop(sp<Allocation> in, sp<Allocation> out); |
| 679 | void blendDstAtop(sp<Allocation> in, sp<Allocation> out); |
| 680 | void blendXor(sp<Allocation> in, sp<Allocation> out); |
| 681 | void blendMultiply(sp<Allocation> in, sp<Allocation> out); |
| 682 | void blendAdd(sp<Allocation> in, sp<Allocation> out); |
| 683 | void blendSubtract(sp<Allocation> in, sp<Allocation> out); |
| 684 | }; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 685 | |
Tim Murray | 8f1e60c | 2012-11-13 12:25:11 -0800 | [diff] [blame] | 686 | class ScriptIntrinsicBlur : public ScriptIntrinsic { |
| 687 | public: |
Tim Murray | 3cd44af | 2012-11-14 11:25:27 -0800 | [diff] [blame] | 688 | ScriptIntrinsicBlur(sp<RS> rs, sp <const Element> e); |
Tim Murray | 8f1e60c | 2012-11-13 12:25:11 -0800 | [diff] [blame] | 689 | void blur(sp<Allocation> in, sp<Allocation> out); |
| 690 | void setRadius(float radius); |
| 691 | }; |
| 692 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame^] | 693 | class Sampler : public BaseObj { |
| 694 | private: |
| 695 | Sampler(sp<RS> rs, void* id); |
| 696 | RsSamplerValue mMin; |
| 697 | RsSamplerValue mMag; |
| 698 | RsSamplerValue mWrapS; |
| 699 | RsSamplerValue mWrapT; |
| 700 | RsSamplerValue mWrapR; |
| 701 | float mAniso; |
| 702 | |
| 703 | public: |
| 704 | static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy); |
| 705 | |
| 706 | RsSamplerValue getMinification(); |
| 707 | RsSamplerValue getMagnification(); |
| 708 | RsSamplerValue getWrapS(); |
| 709 | RsSamplerValue getWrapT(); |
| 710 | float getAnisotropy(); |
| 711 | |
| 712 | sp<const Sampler> CLAMP_NEAREST(sp<RS> rs); |
| 713 | sp<const Sampler> CLAMP_LINEAR(sp<RS> rs); |
| 714 | sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs); |
| 715 | sp<const Sampler> WRAP_NEAREST(sp<RS> rs); |
| 716 | sp<const Sampler> WRAP_LINEAR(sp<RS> rs); |
| 717 | sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs); |
| 718 | sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs); |
| 719 | sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs); |
| 720 | sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs); |
| 721 | |
| 722 | }; |
| 723 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 724 | } |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 725 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | #endif |