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