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