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" |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 21 | #include "util/RefBase.h" |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 22 | #include "rsDispatch.h" |
| 23 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 24 | #include <vector> |
Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 25 | #include <string> |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 26 | |
Tim Murray | 96267c2 | 2013-02-12 11:25:12 -0800 | [diff] [blame] | 27 | // Every row in an RS allocation is guaranteed to be aligned by this amount |
| 28 | // Every row in a user-backed allocation must be aligned by this amount |
| 29 | #define RS_CPU_ALLOCATION_ALIGNMENT 16 |
| 30 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 31 | namespace android { |
Tim Murray | 9eb7f4b | 2012-11-16 14:02:18 -0800 | [diff] [blame] | 32 | namespace RSC { |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 33 | |
| 34 | typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText); |
| 35 | typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen); |
| 36 | |
| 37 | class RS; |
| 38 | class BaseObj; |
| 39 | class Element; |
| 40 | class Type; |
| 41 | class Allocation; |
| 42 | class Script; |
| 43 | class ScriptC; |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 44 | class Sampler; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 45 | |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 46 | enum RSError { |
| 47 | RS_SUCCESS = 0, |
| 48 | RS_ERROR_INVALID_PARAMETER = 1, |
| 49 | RS_ERROR_RUNTIME_ERROR = 2, |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 50 | RS_ERROR_INVALID_ELEMENT = 3, |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 51 | RS_ERROR_MAX = 9999 |
| 52 | |
| 53 | }; |
| 54 | |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 55 | enum RSYuvFormat { |
| 56 | RS_YUV_NONE = 0, |
| 57 | RS_YUV_YV12 = 1, |
| 58 | RS_YUV_NV21 = 2, |
| 59 | RS_YUV_MAX = 3 |
| 60 | }; |
| 61 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 62 | class RS : public android::RSC::LightRefBase<RS> { |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 63 | |
| 64 | public: |
| 65 | RS(); |
| 66 | virtual ~RS(); |
| 67 | |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 68 | bool init(bool forceCpu = false, bool synchronous = false); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 69 | |
| 70 | void setErrorHandler(ErrorHandlerFunc_t func); |
| 71 | ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; } |
| 72 | |
| 73 | void setMessageHandler(MessageHandlerFunc_t func); |
| 74 | MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; } |
| 75 | |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 76 | void throwError(RSError error, const char *errMsg); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 77 | RSError getError(); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 78 | |
| 79 | RsContext getContext() { return mContext; } |
| 80 | |
Tim Murray | baca6c3 | 2012-11-14 16:51:46 -0800 | [diff] [blame] | 81 | void finish(); |
| 82 | |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 83 | static dispatchTable* dispatch; |
| 84 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 85 | private: |
Tim Murray | 4a92d12 | 2013-07-22 10:56:18 -0700 | [diff] [blame] | 86 | static bool usingNative; |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 87 | static bool initDispatch(int targetApi); |
| 88 | |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 89 | bool init(int targetApi, bool forceCpu, bool synchronous); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 90 | static void * threadProc(void *); |
| 91 | |
| 92 | static bool gInitialized; |
| 93 | static pthread_mutex_t gInitMutex; |
| 94 | |
| 95 | pthread_t mMessageThreadId; |
| 96 | pid_t mNativeMessageThreadId; |
| 97 | bool mMessageRun; |
| 98 | |
| 99 | RsDevice mDev; |
| 100 | RsContext mContext; |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 101 | RSError mCurrentError; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 102 | |
| 103 | ErrorHandlerFunc_t mErrorFunc; |
| 104 | MessageHandlerFunc_t mMessageFunc; |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 105 | bool mInit; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 106 | |
| 107 | struct { |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 108 | sp<const Element> U8; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 109 | sp<const Element> U8_2; |
| 110 | sp<const Element> U8_3; |
| 111 | sp<const Element> U8_4; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 112 | sp<const Element> I8; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 113 | sp<const Element> I8_2; |
| 114 | sp<const Element> I8_3; |
| 115 | sp<const Element> I8_4; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 116 | sp<const Element> U16; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 117 | sp<const Element> U16_2; |
| 118 | sp<const Element> U16_3; |
| 119 | sp<const Element> U16_4; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 120 | sp<const Element> I16; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 121 | sp<const Element> I16_2; |
| 122 | sp<const Element> I16_3; |
| 123 | sp<const Element> I16_4; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 124 | sp<const Element> U32; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 125 | sp<const Element> U32_2; |
| 126 | sp<const Element> U32_3; |
| 127 | sp<const Element> U32_4; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 128 | sp<const Element> I32; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 129 | sp<const Element> I32_2; |
| 130 | sp<const Element> I32_3; |
| 131 | sp<const Element> I32_4; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 132 | sp<const Element> U64; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 133 | sp<const Element> U64_2; |
| 134 | sp<const Element> U64_3; |
| 135 | sp<const Element> U64_4; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 136 | sp<const Element> I64; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 137 | sp<const Element> I64_2; |
| 138 | sp<const Element> I64_3; |
| 139 | sp<const Element> I64_4; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 140 | sp<const Element> F32; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 141 | sp<const Element> F32_2; |
| 142 | sp<const Element> F32_3; |
| 143 | sp<const Element> F32_4; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 144 | sp<const Element> F64; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 145 | sp<const Element> F64_2; |
| 146 | sp<const Element> F64_3; |
| 147 | sp<const Element> F64_4; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 148 | sp<const Element> BOOLEAN; |
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> ELEMENT; |
| 151 | sp<const Element> TYPE; |
| 152 | sp<const Element> ALLOCATION; |
| 153 | sp<const Element> SAMPLER; |
| 154 | sp<const Element> SCRIPT; |
| 155 | sp<const Element> MESH; |
| 156 | sp<const Element> PROGRAM_FRAGMENT; |
| 157 | sp<const Element> PROGRAM_VERTEX; |
| 158 | sp<const Element> PROGRAM_RASTER; |
| 159 | sp<const Element> PROGRAM_STORE; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 160 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 161 | sp<const Element> A_8; |
| 162 | sp<const Element> RGB_565; |
| 163 | sp<const Element> RGB_888; |
| 164 | sp<const Element> RGBA_5551; |
| 165 | sp<const Element> RGBA_4444; |
| 166 | sp<const Element> RGBA_8888; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 167 | |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 168 | sp<const Element> YUV; |
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); |
Tim Murray | 9d24ae6 | 2013-08-30 12:17:14 -0700 | [diff] [blame] | 246 | void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff, |
| 247 | uint32_t w, uint32_t h, uint32_t d); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 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 | 9d24ae6 | 2013-08-30 12:17:14 -0700 | [diff] [blame] | 285 | void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, |
| 286 | uint32_t h, uint32_t d, const void* data); |
| 287 | |
| 288 | void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, |
| 289 | uint32_t w, uint32_t h, uint32_t d, |
| 290 | sp<const Allocation> data, |
| 291 | uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 292 | |
| 293 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| 294 | RsAllocationMipmapControl mips, uint32_t usage); |
| 295 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| 296 | RsAllocationMipmapControl mips, uint32_t usage, void * pointer); |
| 297 | |
| 298 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| 299 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
| 300 | static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count, |
| 301 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 302 | static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e, |
| 303 | size_t x, size_t y, |
| 304 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
| 305 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 306 | |
| 307 | }; |
| 308 | |
| 309 | class Element : public BaseObj { |
| 310 | public: |
| 311 | bool isComplex(); |
| 312 | size_t getSubElementCount() { |
| 313 | return mVisibleElementMap.size(); |
| 314 | } |
| 315 | |
| 316 | sp<const Element> getSubElement(uint32_t index); |
| 317 | const char * getSubElementName(uint32_t index); |
| 318 | size_t getSubElementArraySize(uint32_t index); |
| 319 | uint32_t getSubElementOffsetBytes(uint32_t index); |
| 320 | RsDataType getDataType() const { |
| 321 | return mType; |
| 322 | } |
| 323 | |
| 324 | RsDataKind getDataKind() const { |
| 325 | return mKind; |
| 326 | } |
| 327 | |
| 328 | size_t getSizeBytes() const { |
| 329 | return mSizeBytes; |
| 330 | } |
| 331 | |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 332 | uint32_t getVectorSize() const { |
| 333 | return mVectorSize; |
| 334 | } |
| 335 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 336 | static sp<const Element> BOOLEAN(sp<RS> rs); |
| 337 | static sp<const Element> U8(sp<RS> rs); |
| 338 | static sp<const Element> I8(sp<RS> rs); |
| 339 | static sp<const Element> U16(sp<RS> rs); |
| 340 | static sp<const Element> I16(sp<RS> rs); |
| 341 | static sp<const Element> U32(sp<RS> rs); |
| 342 | static sp<const Element> I32(sp<RS> rs); |
| 343 | static sp<const Element> U64(sp<RS> rs); |
| 344 | static sp<const Element> I64(sp<RS> rs); |
| 345 | static sp<const Element> F32(sp<RS> rs); |
| 346 | static sp<const Element> F64(sp<RS> rs); |
| 347 | static sp<const Element> ELEMENT(sp<RS> rs); |
| 348 | static sp<const Element> TYPE(sp<RS> rs); |
| 349 | static sp<const Element> ALLOCATION(sp<RS> rs); |
| 350 | static sp<const Element> SAMPLER(sp<RS> rs); |
| 351 | static sp<const Element> SCRIPT(sp<RS> rs); |
| 352 | static sp<const Element> MESH(sp<RS> rs); |
| 353 | static sp<const Element> PROGRAM_FRAGMENT(sp<RS> rs); |
| 354 | static sp<const Element> PROGRAM_VERTEX(sp<RS> rs); |
| 355 | static sp<const Element> PROGRAM_RASTER(sp<RS> rs); |
| 356 | static sp<const Element> PROGRAM_STORE(sp<RS> rs); |
| 357 | |
| 358 | static sp<const Element> A_8(sp<RS> rs); |
| 359 | static sp<const Element> RGB_565(sp<RS> rs); |
| 360 | static sp<const Element> RGB_888(sp<RS> rs); |
| 361 | static sp<const Element> RGBA_5551(sp<RS> rs); |
| 362 | static sp<const Element> RGBA_4444(sp<RS> rs); |
| 363 | static sp<const Element> RGBA_8888(sp<RS> rs); |
| 364 | |
| 365 | static sp<const Element> F32_2(sp<RS> rs); |
| 366 | static sp<const Element> F32_3(sp<RS> rs); |
| 367 | static sp<const Element> F32_4(sp<RS> rs); |
| 368 | static sp<const Element> F64_2(sp<RS> rs); |
| 369 | static sp<const Element> F64_3(sp<RS> rs); |
| 370 | static sp<const Element> F64_4(sp<RS> rs); |
| 371 | static sp<const Element> U8_2(sp<RS> rs); |
| 372 | static sp<const Element> U8_3(sp<RS> rs); |
| 373 | static sp<const Element> U8_4(sp<RS> rs); |
| 374 | static sp<const Element> I8_2(sp<RS> rs); |
| 375 | static sp<const Element> I8_3(sp<RS> rs); |
| 376 | static sp<const Element> I8_4(sp<RS> rs); |
| 377 | static sp<const Element> U16_2(sp<RS> rs); |
| 378 | static sp<const Element> U16_3(sp<RS> rs); |
| 379 | static sp<const Element> U16_4(sp<RS> rs); |
| 380 | static sp<const Element> I16_2(sp<RS> rs); |
| 381 | static sp<const Element> I16_3(sp<RS> rs); |
| 382 | static sp<const Element> I16_4(sp<RS> rs); |
| 383 | static sp<const Element> U32_2(sp<RS> rs); |
| 384 | static sp<const Element> U32_3(sp<RS> rs); |
| 385 | static sp<const Element> U32_4(sp<RS> rs); |
| 386 | static sp<const Element> I32_2(sp<RS> rs); |
| 387 | static sp<const Element> I32_3(sp<RS> rs); |
| 388 | static sp<const Element> I32_4(sp<RS> rs); |
| 389 | static sp<const Element> U64_2(sp<RS> rs); |
| 390 | static sp<const Element> U64_3(sp<RS> rs); |
| 391 | static sp<const Element> U64_4(sp<RS> rs); |
| 392 | static sp<const Element> I64_2(sp<RS> rs); |
| 393 | static sp<const Element> I64_3(sp<RS> rs); |
| 394 | static sp<const Element> I64_4(sp<RS> rs); |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 395 | static sp<const Element> YUV(sp<RS> rs); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 396 | static sp<const Element> MATRIX_4X4(sp<RS> rs); |
| 397 | static sp<const Element> MATRIX_3X3(sp<RS> rs); |
| 398 | static sp<const Element> MATRIX_2X2(sp<RS> rs); |
| 399 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 400 | void updateFromNative(); |
| 401 | static sp<const Element> createUser(sp<RS> rs, RsDataType dt); |
| 402 | static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size); |
| 403 | static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 404 | bool isCompatible(sp<const Element>e) const; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 405 | |
| 406 | class Builder { |
| 407 | private: |
| 408 | sp<RS> mRS; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 409 | std::vector<sp<Element> > mElements; |
Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 410 | std::vector<std::string> mElementNames; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 411 | std::vector<uint32_t> mArraySizes; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 412 | bool mSkipPadding; |
| 413 | |
| 414 | public: |
| 415 | Builder(sp<RS> rs); |
| 416 | ~Builder(); |
Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 417 | void add(sp<Element> e, std::string &name, uint32_t arraySize = 1); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 418 | sp<const Element> create(); |
| 419 | }; |
| 420 | |
Stephen Hines | 7d1b757 | 2013-08-22 01:24:06 -0700 | [diff] [blame] | 421 | protected: |
| 422 | Element(void *id, sp<RS> rs, |
| 423 | std::vector<sp<Element> > &elements, |
| 424 | std::vector<std::string> &elementNames, |
| 425 | std::vector<uint32_t> &arraySizes); |
| 426 | Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size); |
| 427 | Element(sp<RS> rs); |
| 428 | virtual ~Element(); |
| 429 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 430 | private: |
| 431 | void updateVisibleSubElements(); |
| 432 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 433 | std::vector<sp<Element> > mElements; |
Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 434 | std::vector<std::string> mElementNames; |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 435 | std::vector<uint32_t> mArraySizes; |
| 436 | std::vector<uint32_t> mVisibleElementMap; |
| 437 | std::vector<uint32_t> mOffsetInBytes; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 438 | |
| 439 | RsDataType mType; |
| 440 | RsDataKind mKind; |
| 441 | bool mNormalized; |
| 442 | size_t mSizeBytes; |
| 443 | size_t mVectorSize; |
| 444 | }; |
| 445 | |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 446 | class FieldPacker { |
| 447 | protected: |
| 448 | unsigned char* mData; |
| 449 | size_t mPos; |
| 450 | size_t mLen; |
| 451 | |
| 452 | public: |
| 453 | FieldPacker(size_t len) |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 454 | : mPos(0), mLen(len) { |
| 455 | mData = new unsigned char[len]; |
| 456 | } |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 457 | |
| 458 | virtual ~FieldPacker() { |
| 459 | delete [] mData; |
| 460 | } |
| 461 | |
| 462 | void align(size_t v) { |
| 463 | if ((v & (v - 1)) != 0) { |
Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 464 | // ALOGE("Non-power-of-two alignment: %zu", v); |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 465 | return; |
| 466 | } |
| 467 | |
| 468 | while ((mPos & (v - 1)) != 0) { |
| 469 | mData[mPos++] = 0; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | void reset() { |
| 474 | mPos = 0; |
| 475 | } |
| 476 | |
| 477 | void reset(size_t i) { |
| 478 | if (i >= mLen) { |
Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 479 | // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen); |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 480 | return; |
| 481 | } |
| 482 | mPos = i; |
| 483 | } |
| 484 | |
| 485 | void skip(size_t i) { |
| 486 | size_t res = mPos + i; |
| 487 | if (res > mLen) { |
Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 488 | // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen); |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 489 | return; |
| 490 | } |
| 491 | mPos = res; |
| 492 | } |
| 493 | |
| 494 | void* getData() const { |
| 495 | return mData; |
| 496 | } |
| 497 | |
| 498 | size_t getLength() const { |
| 499 | return mLen; |
| 500 | } |
| 501 | |
| 502 | template <typename T> |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 503 | void add(T t) { |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 504 | align(sizeof(t)); |
| 505 | if (mPos + sizeof(t) <= mLen) { |
| 506 | memcpy(&mData[mPos], &t, sizeof(t)); |
| 507 | mPos += sizeof(t); |
| 508 | } |
| 509 | } |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 510 | |
| 511 | /* |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 512 | void add(rs_matrix4x4 m) { |
| 513 | for (size_t i = 0; i < 16; 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_matrix3x3 m) { |
| 519 | for (size_t i = 0; i < 9; i++) { |
| 520 | add(m.m[i]); |
| 521 | } |
| 522 | } |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 523 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 524 | void add(rs_matrix2x2 m) { |
| 525 | for (size_t i = 0; i < 4; i++) { |
| 526 | add(m.m[i]); |
| 527 | } |
| 528 | } |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 529 | */ |
| 530 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 531 | void add(sp<BaseObj> obj) { |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 532 | if (obj != NULL) { |
| 533 | add((uint32_t) (uintptr_t) obj->getID()); |
| 534 | } else { |
| 535 | add((uint32_t) 0); |
| 536 | } |
| 537 | } |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 538 | }; |
| 539 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 540 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 541 | class Type : public BaseObj { |
| 542 | protected: |
| 543 | friend class Allocation; |
| 544 | |
| 545 | uint32_t mDimX; |
| 546 | uint32_t mDimY; |
| 547 | uint32_t mDimZ; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 548 | RSYuvFormat mYuvFormat; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 549 | bool mDimMipmaps; |
| 550 | bool mDimFaces; |
| 551 | size_t mElementCount; |
| 552 | sp<const Element> mElement; |
| 553 | |
Stephen Hines | 7d1b757 | 2013-08-22 01:24:06 -0700 | [diff] [blame] | 554 | Type(void *id, sp<RS> rs); |
| 555 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 556 | void calcElementCount(); |
| 557 | virtual void updateFromNative(); |
| 558 | |
| 559 | public: |
| 560 | |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 561 | RSYuvFormat getYuvFormat() const { |
| 562 | return mYuvFormat; |
| 563 | } |
| 564 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 565 | sp<const Element> getElement() const { |
| 566 | return mElement; |
| 567 | } |
| 568 | |
| 569 | uint32_t getX() const { |
| 570 | return mDimX; |
| 571 | } |
| 572 | |
| 573 | uint32_t getY() const { |
| 574 | return mDimY; |
| 575 | } |
| 576 | |
| 577 | uint32_t getZ() const { |
| 578 | return mDimZ; |
| 579 | } |
| 580 | |
| 581 | bool hasMipmaps() const { |
| 582 | return mDimMipmaps; |
| 583 | } |
| 584 | |
| 585 | bool hasFaces() const { |
| 586 | return mDimFaces; |
| 587 | } |
| 588 | |
| 589 | size_t getCount() const { |
| 590 | return mElementCount; |
| 591 | } |
| 592 | |
| 593 | size_t getSizeBytes() const { |
| 594 | return mElementCount * mElement->getSizeBytes(); |
| 595 | } |
| 596 | |
Tim Murray | 96267c2 | 2013-02-12 11:25:12 -0800 | [diff] [blame] | 597 | 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] | 598 | |
| 599 | class Builder { |
| 600 | protected: |
| 601 | sp<RS> mRS; |
| 602 | uint32_t mDimX; |
| 603 | uint32_t mDimY; |
| 604 | uint32_t mDimZ; |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 605 | RSYuvFormat mYuvFormat; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 606 | bool mDimMipmaps; |
| 607 | bool mDimFaces; |
| 608 | sp<const Element> mElement; |
| 609 | |
| 610 | public: |
| 611 | Builder(sp<RS> rs, sp<const Element> e); |
| 612 | |
| 613 | void setX(uint32_t value); |
Stephen Hines | 7d1b757 | 2013-08-22 01:24:06 -0700 | [diff] [blame] | 614 | void setY(uint32_t value); |
Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 615 | void setZ(uint32_t value); |
| 616 | void setYuvFormat(RSYuvFormat format); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 617 | void setMipmaps(bool value); |
| 618 | void setFaces(bool value); |
| 619 | sp<const Type> create(); |
| 620 | }; |
| 621 | |
| 622 | }; |
| 623 | |
| 624 | class Script : public BaseObj { |
| 625 | private: |
| 626 | |
| 627 | protected: |
| 628 | Script(void *id, sp<RS> rs); |
| 629 | void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out, |
| 630 | const void *v, size_t) const; |
| 631 | void bindAllocation(sp<Allocation> va, uint32_t slot) const; |
| 632 | void setVar(uint32_t index, const void *, size_t len) const; |
| 633 | void setVar(uint32_t index, sp<const BaseObj> o) const; |
| 634 | void invoke(uint32_t slot, const void *v, size_t len) const; |
| 635 | |
| 636 | |
| 637 | void invoke(uint32_t slot) const { |
| 638 | invoke(slot, NULL, 0); |
| 639 | } |
| 640 | void setVar(uint32_t index, float v) const { |
| 641 | setVar(index, &v, sizeof(v)); |
| 642 | } |
| 643 | void setVar(uint32_t index, double v) const { |
| 644 | setVar(index, &v, sizeof(v)); |
| 645 | } |
| 646 | void setVar(uint32_t index, int32_t v) const { |
| 647 | setVar(index, &v, sizeof(v)); |
| 648 | } |
| 649 | void setVar(uint32_t index, int64_t v) const { |
| 650 | setVar(index, &v, sizeof(v)); |
| 651 | } |
| 652 | void setVar(uint32_t index, bool v) const { |
| 653 | setVar(index, &v, sizeof(v)); |
| 654 | } |
| 655 | |
| 656 | public: |
| 657 | class FieldBase { |
| 658 | protected: |
| 659 | sp<const Element> mElement; |
| 660 | sp<Allocation> mAllocation; |
| 661 | |
| 662 | void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0); |
| 663 | |
| 664 | public: |
| 665 | sp<const Element> getElement() { |
| 666 | return mElement; |
| 667 | } |
| 668 | |
| 669 | sp<const Type> getType() { |
| 670 | return mAllocation->getType(); |
| 671 | } |
| 672 | |
| 673 | sp<const Allocation> getAllocation() { |
| 674 | return mAllocation; |
| 675 | } |
| 676 | |
| 677 | //void updateAllocation(); |
| 678 | }; |
| 679 | }; |
| 680 | |
| 681 | class ScriptC : public Script { |
| 682 | protected: |
| 683 | ScriptC(sp<RS> rs, |
| 684 | const void *codeTxt, size_t codeLength, |
| 685 | const char *cachedName, size_t cachedNameLength, |
| 686 | const char *cacheDir, size_t cacheDirLength); |
| 687 | |
| 688 | }; |
| 689 | |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 690 | class ScriptIntrinsic : public Script { |
| 691 | protected: |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 692 | sp<const Element> mElement; |
Tim Murray | 3cd44af | 2012-11-14 11:25:27 -0800 | [diff] [blame] | 693 | ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e); |
Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 694 | virtual ~ScriptIntrinsic(); |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 695 | }; |
| 696 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 697 | class ScriptIntrinsic3DLUT : public ScriptIntrinsic { |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 698 | private: |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 699 | ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e); |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 700 | public: |
| 701 | static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e); |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 702 | void forEach(sp<Allocation> ain, sp<Allocation> aout); |
| 703 | void setLUT(sp<Allocation> lut); |
| 704 | }; |
| 705 | |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 706 | class ScriptIntrinsicBlend : public ScriptIntrinsic { |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 707 | private: |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 708 | ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e); |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 709 | public: |
| 710 | static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e); |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 711 | void blendClear(sp<Allocation> in, sp<Allocation> out); |
| 712 | void blendSrc(sp<Allocation> in, sp<Allocation> out); |
| 713 | void blendDst(sp<Allocation> in, sp<Allocation> out); |
| 714 | void blendSrcOver(sp<Allocation> in, sp<Allocation> out); |
| 715 | void blendDstOver(sp<Allocation> in, sp<Allocation> out); |
| 716 | void blendSrcIn(sp<Allocation> in, sp<Allocation> out); |
| 717 | void blendDstIn(sp<Allocation> in, sp<Allocation> out); |
| 718 | void blendSrcOut(sp<Allocation> in, sp<Allocation> out); |
| 719 | void blendDstOut(sp<Allocation> in, sp<Allocation> out); |
| 720 | void blendSrcAtop(sp<Allocation> in, sp<Allocation> out); |
| 721 | void blendDstAtop(sp<Allocation> in, sp<Allocation> out); |
| 722 | void blendXor(sp<Allocation> in, sp<Allocation> out); |
| 723 | void blendMultiply(sp<Allocation> in, sp<Allocation> out); |
| 724 | void blendAdd(sp<Allocation> in, sp<Allocation> out); |
| 725 | void blendSubtract(sp<Allocation> in, sp<Allocation> out); |
| 726 | }; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 727 | |
Tim Murray | 8f1e60c | 2012-11-13 12:25:11 -0800 | [diff] [blame] | 728 | class ScriptIntrinsicBlur : public ScriptIntrinsic { |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 729 | private: |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 730 | ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e); |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 731 | public: |
| 732 | static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e); |
| 733 | void setInput(sp<Allocation> in); |
| 734 | void forEach(sp<Allocation> out); |
Tim Murray | 8f1e60c | 2012-11-13 12:25:11 -0800 | [diff] [blame] | 735 | void setRadius(float radius); |
| 736 | }; |
| 737 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 738 | class ScriptIntrinsicColorMatrix : 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 | ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e); |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 741 | public: |
Tim Murray | aae73c9 | 2013-09-03 17:05:46 -0700 | [diff] [blame] | 742 | static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs); |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 743 | void forEach(sp<Allocation> in, sp<Allocation> out); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 744 | void setAdd(float* add); |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 745 | void setColorMatrix3(float* m); |
| 746 | void setColorMatrix4(float* m); |
| 747 | void setGreyscale(); |
| 748 | void setRGBtoYUV(); |
| 749 | void setYUVtoRGB(); |
| 750 | }; |
| 751 | |
| 752 | class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic { |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 753 | private: |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 754 | ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e); |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 755 | public: |
| 756 | static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e); |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 757 | void setInput(sp<Allocation> in); |
| 758 | void forEach(sp<Allocation> out); |
| 759 | void setCoefficients(float* v); |
| 760 | }; |
| 761 | |
| 762 | class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic { |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 763 | private: |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 764 | ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e); |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 765 | public: |
| 766 | static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e); |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 767 | void setInput(sp<Allocation> in); |
| 768 | void forEach(sp<Allocation> out); |
| 769 | void setCoefficients(float* v); |
| 770 | }; |
| 771 | |
Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 772 | class ScriptIntrinsicHistogram : public ScriptIntrinsic { |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 773 | private: |
Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 774 | ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 775 | sp<Allocation> mOut; |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 776 | public: |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 777 | static sp<ScriptIntrinsicHistogram> create(sp<RS> rs); |
Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 778 | void setOutput(sp<Allocation> aout); |
| 779 | void setDotCoefficients(float r, float g, float b, float a); |
| 780 | void forEach(sp<Allocation> ain); |
| 781 | void forEach_dot(sp<Allocation> ain); |
| 782 | }; |
| 783 | |
| 784 | class ScriptIntrinsicLUT : public ScriptIntrinsic { |
| 785 | private: |
| 786 | sp<Allocation> LUT; |
| 787 | bool mDirty; |
| 788 | unsigned char mCache[1024]; |
Tim Murray | 2acce99 | 2013-08-28 14:23:31 -0700 | [diff] [blame] | 789 | 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] | 790 | ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e); |
Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 791 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 792 | public: |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 793 | static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e); |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 794 | void forEach(sp<Allocation> ain, sp<Allocation> aout); |
Tim Murray | 2acce99 | 2013-08-28 14:23:31 -0700 | [diff] [blame] | 795 | void setRed(unsigned char base, unsigned int length, unsigned char* lutValues); |
| 796 | void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues); |
| 797 | void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues); |
| 798 | void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues); |
Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 799 | virtual ~ScriptIntrinsicLUT(); |
| 800 | }; |
| 801 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 802 | class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic { |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 803 | private: |
Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 804 | ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e); |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 805 | public: |
| 806 | static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e); |
Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 807 | void setInput(sp<Allocation> in); |
| 808 | void forEach(sp<Allocation> out); |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 809 | |
| 810 | }; |
Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 811 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 812 | |
Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 813 | class Sampler : public BaseObj { |
| 814 | private: |
| 815 | Sampler(sp<RS> rs, void* id); |
| 816 | RsSamplerValue mMin; |
| 817 | RsSamplerValue mMag; |
| 818 | RsSamplerValue mWrapS; |
| 819 | RsSamplerValue mWrapT; |
| 820 | RsSamplerValue mWrapR; |
| 821 | float mAniso; |
| 822 | |
| 823 | public: |
| 824 | static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy); |
| 825 | |
| 826 | RsSamplerValue getMinification(); |
| 827 | RsSamplerValue getMagnification(); |
| 828 | RsSamplerValue getWrapS(); |
| 829 | RsSamplerValue getWrapT(); |
| 830 | float getAnisotropy(); |
| 831 | |
| 832 | sp<const Sampler> CLAMP_NEAREST(sp<RS> rs); |
| 833 | sp<const Sampler> CLAMP_LINEAR(sp<RS> rs); |
| 834 | sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs); |
| 835 | sp<const Sampler> WRAP_NEAREST(sp<RS> rs); |
| 836 | sp<const Sampler> WRAP_LINEAR(sp<RS> rs); |
| 837 | sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs); |
| 838 | sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs); |
| 839 | sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs); |
| 840 | sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs); |
| 841 | |
| 842 | }; |
| 843 | |
Stephen Hines | d10412f | 2013-08-29 18:27:21 -0700 | [diff] [blame] | 844 | class Byte2 { |
| 845 | public: |
| 846 | int8_t x, y; |
| 847 | |
| 848 | Byte2(int8_t initX, int8_t initY) |
| 849 | : x(initX), y(initY) {} |
| 850 | Byte2() : x(0), y(0) {} |
| 851 | }; |
| 852 | |
| 853 | class Byte3 { |
| 854 | public: |
| 855 | int8_t x, y, z; |
| 856 | |
| 857 | Byte3(int8_t initX, int8_t initY, int8_t initZ) |
| 858 | : x(initX), y(initY), z(initZ) {} |
| 859 | Byte3() : x(0), y(0), z(0) {} |
| 860 | }; |
| 861 | |
| 862 | class Byte4 { |
| 863 | public: |
| 864 | int8_t x, y, z, w; |
| 865 | |
| 866 | Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW) |
| 867 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 868 | Byte4() : x(0), y(0), z(0), w(0) {} |
| 869 | }; |
| 870 | |
| 871 | class UByte2 { |
| 872 | public: |
| 873 | uint8_t x, y; |
| 874 | |
| 875 | UByte2(uint8_t initX, uint8_t initY) |
| 876 | : x(initX), y(initY) {} |
| 877 | UByte2() : x(0), y(0) {} |
| 878 | }; |
| 879 | |
| 880 | class UByte3 { |
| 881 | public: |
| 882 | uint8_t x, y, z; |
| 883 | |
| 884 | UByte3(uint8_t initX, uint8_t initY, uint8_t initZ) |
| 885 | : x(initX), y(initY), z(initZ) {} |
| 886 | UByte3() : x(0), y(0), z(0) {} |
| 887 | }; |
| 888 | |
| 889 | class UByte4 { |
| 890 | public: |
| 891 | uint8_t x, y, z, w; |
| 892 | |
| 893 | UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW) |
| 894 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 895 | UByte4() : x(0), y(0), z(0), w(0) {} |
| 896 | }; |
| 897 | |
| 898 | class Short2 { |
| 899 | public: |
| 900 | short x, y; |
| 901 | |
| 902 | Short2(short initX, short initY) |
| 903 | : x(initX), y(initY) {} |
| 904 | Short2() : x(0), y(0) {} |
| 905 | }; |
| 906 | |
| 907 | class Short3 { |
| 908 | public: |
| 909 | short x, y, z; |
| 910 | |
| 911 | Short3(short initX, short initY, short initZ) |
| 912 | : x(initX), y(initY), z(initZ) {} |
| 913 | Short3() : x(0), y(0), z(0) {} |
| 914 | }; |
| 915 | |
| 916 | class Short4 { |
| 917 | public: |
| 918 | short x, y, z, w; |
| 919 | |
| 920 | Short4(short initX, short initY, short initZ, short initW) |
| 921 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 922 | Short4() : x(0), y(0), z(0), w(0) {} |
| 923 | }; |
| 924 | |
| 925 | class UShort2 { |
| 926 | public: |
| 927 | uint16_t x, y; |
| 928 | |
| 929 | UShort2(uint16_t initX, uint16_t initY) |
| 930 | : x(initX), y(initY) {} |
| 931 | UShort2() : x(0), y(0) {} |
| 932 | }; |
| 933 | |
| 934 | class UShort3 { |
| 935 | public: |
| 936 | uint16_t x, y, z; |
| 937 | |
| 938 | UShort3(uint16_t initX, uint16_t initY, uint16_t initZ) |
| 939 | : x(initX), y(initY), z(initZ) {} |
| 940 | UShort3() : x(0), y(0), z(0) {} |
| 941 | }; |
| 942 | |
| 943 | class UShort4 { |
| 944 | public: |
| 945 | uint16_t x, y, z, w; |
| 946 | |
| 947 | UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW) |
| 948 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 949 | UShort4() : x(0), y(0), z(0), w(0) {} |
| 950 | }; |
| 951 | |
| 952 | class Int2 { |
| 953 | public: |
| 954 | int x, y; |
| 955 | |
| 956 | Int2(int initX, int initY) |
| 957 | : x(initX), y(initY) {} |
| 958 | Int2() : x(0), y(0) {} |
| 959 | }; |
| 960 | |
| 961 | class Int3 { |
| 962 | public: |
| 963 | int x, y, z; |
| 964 | |
| 965 | Int3(int initX, int initY, int initZ) |
| 966 | : x(initX), y(initY), z(initZ) {} |
| 967 | Int3() : x(0), y(0), z(0) {} |
| 968 | }; |
| 969 | |
| 970 | class Int4 { |
| 971 | public: |
| 972 | int x, y, z, w; |
| 973 | |
| 974 | Int4(int initX, int initY, int initZ, int initW) |
| 975 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 976 | Int4() : x(0), y(0), z(0), w(0) {} |
| 977 | }; |
| 978 | |
| 979 | class UInt2 { |
| 980 | public: |
| 981 | uint32_t x, y; |
| 982 | |
| 983 | UInt2(uint32_t initX, uint32_t initY) |
| 984 | : x(initX), y(initY) {} |
| 985 | UInt2() : x(0), y(0) {} |
| 986 | }; |
| 987 | |
| 988 | class UInt3 { |
| 989 | public: |
| 990 | uint32_t x, y, z; |
| 991 | |
| 992 | UInt3(uint32_t initX, uint32_t initY, uint32_t initZ) |
| 993 | : x(initX), y(initY), z(initZ) {} |
| 994 | UInt3() : x(0), y(0), z(0) {} |
| 995 | }; |
| 996 | |
| 997 | class UInt4 { |
| 998 | public: |
| 999 | uint32_t x, y, z, w; |
| 1000 | |
| 1001 | UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW) |
| 1002 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 1003 | UInt4() : x(0), y(0), z(0), w(0) {} |
| 1004 | }; |
| 1005 | |
| 1006 | class Long2 { |
| 1007 | public: |
| 1008 | int64_t x, y; |
| 1009 | |
| 1010 | Long2(int64_t initX, int64_t initY) |
| 1011 | : x(initX), y(initY) {} |
| 1012 | Long2() : x(0), y(0) {} |
| 1013 | }; |
| 1014 | |
| 1015 | class Long3 { |
| 1016 | public: |
| 1017 | int64_t x, y, z; |
| 1018 | |
| 1019 | Long3(int64_t initX, int64_t initY, int64_t initZ) |
| 1020 | : x(initX), y(initY), z(initZ) {} |
| 1021 | Long3() : x(0), y(0), z(0) {} |
| 1022 | }; |
| 1023 | |
| 1024 | class Long4 { |
| 1025 | public: |
| 1026 | int64_t x, y, z, w; |
| 1027 | |
| 1028 | Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW) |
| 1029 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 1030 | Long4() : x(0), y(0), z(0), w(0) {} |
| 1031 | }; |
| 1032 | |
| 1033 | class ULong2 { |
| 1034 | public: |
| 1035 | uint64_t x, y; |
| 1036 | |
| 1037 | ULong2(uint64_t initX, uint64_t initY) |
| 1038 | : x(initX), y(initY) {} |
| 1039 | ULong2() : x(0), y(0) {} |
| 1040 | }; |
| 1041 | |
| 1042 | class ULong3 { |
| 1043 | public: |
| 1044 | uint64_t x, y, z; |
| 1045 | |
| 1046 | ULong3(uint64_t initX, uint64_t initY, uint64_t initZ) |
| 1047 | : x(initX), y(initY), z(initZ) {} |
| 1048 | ULong3() : x(0), y(0), z(0) {} |
| 1049 | }; |
| 1050 | |
| 1051 | class ULong4 { |
| 1052 | public: |
| 1053 | uint64_t x, y, z, w; |
| 1054 | |
| 1055 | ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW) |
| 1056 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 1057 | ULong4() : x(0), y(0), z(0), w(0) {} |
| 1058 | }; |
| 1059 | |
| 1060 | class Float2 { |
| 1061 | public: |
| 1062 | float x, y; |
| 1063 | |
| 1064 | Float2(float initX, float initY) |
| 1065 | : x(initX), y(initY) {} |
| 1066 | Float2() : x(0), y(0) {} |
| 1067 | }; |
| 1068 | |
| 1069 | class Float3 { |
| 1070 | public: |
| 1071 | float x, y, z; |
| 1072 | |
| 1073 | Float3(float initX, float initY, float initZ) |
| 1074 | : x(initX), y(initY), z(initZ) {} |
| 1075 | Float3() : x(0.f), y(0.f), z(0.f) {} |
| 1076 | }; |
| 1077 | |
| 1078 | class Float4 { |
| 1079 | public: |
| 1080 | float x, y, z, w; |
| 1081 | |
| 1082 | Float4(float initX, float initY, float initZ, float initW) |
| 1083 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 1084 | Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {} |
| 1085 | }; |
| 1086 | |
| 1087 | class Double2 { |
| 1088 | public: |
| 1089 | double x, y; |
| 1090 | |
| 1091 | Double2(double initX, double initY) |
| 1092 | : x(initX), y(initY) {} |
| 1093 | Double2() : x(0), y(0) {} |
| 1094 | }; |
| 1095 | |
| 1096 | class Double3 { |
| 1097 | public: |
| 1098 | double x, y, z; |
| 1099 | |
| 1100 | Double3(double initX, double initY, double initZ) |
| 1101 | : x(initX), y(initY), z(initZ) {} |
| 1102 | Double3() : x(0), y(0), z(0) {} |
| 1103 | }; |
| 1104 | |
| 1105 | class Double4 { |
| 1106 | public: |
| 1107 | double x, y, z, w; |
| 1108 | |
| 1109 | Double4(double initX, double initY, double initZ, double initW) |
| 1110 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 1111 | Double4() : x(0), y(0), z(0), w(0) {} |
| 1112 | }; |
| 1113 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1114 | } |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 1115 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | #endif |