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