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