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