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