| 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 | |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 23 | #include <vector> |
| Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 24 | #include <string> |
| Tim Murray | 8c24cd6 | 2014-04-10 18:04:39 -0700 | [diff] [blame] | 25 | #include <pthread.h> |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 26 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Every row in an RS allocation is guaranteed to be aligned by this amount, and |
| 29 | * every row in a user-backed allocation must be aligned by this amount. |
| 30 | */ |
| Tim Murray | 96267c2 | 2013-02-12 11:25:12 -0800 | [diff] [blame] | 31 | #define RS_CPU_ALLOCATION_ALIGNMENT 16 |
| 32 | |
| Jason Sams | 66f0a16 | 2014-11-11 13:46:38 -0800 | [diff] [blame] | 33 | struct dispatchTable; |
| 34 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 35 | namespace android { |
| Tim Murray | 9eb7f4b | 2012-11-16 14:02:18 -0800 | [diff] [blame] | 36 | namespace RSC { |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 37 | |
| Jason Sams | 66f0a16 | 2014-11-11 13:46:38 -0800 | [diff] [blame] | 38 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 39 | typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText); |
| 40 | typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen); |
| 41 | |
| 42 | class RS; |
| 43 | class BaseObj; |
| 44 | class Element; |
| 45 | class Type; |
| 46 | class Allocation; |
| 47 | class Script; |
| 48 | class ScriptC; |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 49 | class Sampler; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 50 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Possible error codes used by RenderScript. Once a status other than RS_SUCCESS |
| 53 | * is returned, the RenderScript context is considered dead and cannot perform any |
| 54 | * additional work. |
| 55 | */ |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 56 | enum RSError { |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 57 | RS_SUCCESS = 0, ///< No error |
| 58 | RS_ERROR_INVALID_PARAMETER = 1, ///< An invalid parameter was passed to a function |
| 59 | RS_ERROR_RUNTIME_ERROR = 2, ///< The RenderScript driver returned an error; this is |
| 60 | ///< often indicative of a kernel that crashed |
| 61 | RS_ERROR_INVALID_ELEMENT = 3, ///< An invalid Element was passed to a function |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 62 | RS_ERROR_MAX = 9999 |
| 63 | |
| 64 | }; |
| 65 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 66 | /** |
| 67 | * YUV formats supported by the RenderScript API. |
| 68 | */ |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 69 | enum RSYuvFormat { |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 70 | RS_YUV_NONE = 0, ///< No YUV data |
| 71 | RS_YUV_YV12 = 1, ///< YUV data in YV12 format |
| 72 | RS_YUV_NV21 = 2, ///< YUV data in NV21 format |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 73 | RS_YUV_MAX = 3 |
| 74 | }; |
| 75 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 76 | /** |
| 77 | * Flags that can control RenderScript behavior on a per-context level. |
| 78 | */ |
| Tim Murray | 84e3dea | 2013-09-09 16:12:51 -0700 | [diff] [blame] | 79 | enum RSInitFlags { |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 80 | RS_INIT_SYNCHRONOUS = 1, ///< All RenderScript calls will be synchronous. May reduce latency. |
| 81 | RS_INIT_LOW_LATENCY = 2, ///< Prefer low latency devices over potentially higher throughput devices. |
| Tim Murray | 84e3dea | 2013-09-09 16:12:51 -0700 | [diff] [blame] | 82 | RS_INIT_MAX = 4 |
| 83 | }; |
| 84 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 85 | /** |
| 86 | * The RenderScript context. This class controls initialization, resource management, and teardown. |
| 87 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 88 | class RS : public android::RSC::LightRefBase<RS> { |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 89 | |
| 90 | public: |
| 91 | RS(); |
| 92 | virtual ~RS(); |
| 93 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Initializes a RenderScript context. A context must be initialized before it can be used. |
| Tim Murray | caf4126 | 2013-12-13 12:54:37 -0800 | [diff] [blame] | 96 | * @param[in] name Directory name to be used by this context. This should be equivalent to |
| 97 | * Context.getCacheDir(). |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 98 | * @param[in] flags Optional flags for this context. |
| 99 | * @return true on success |
| 100 | */ |
| Tim Murray | caf4126 | 2013-12-13 12:54:37 -0800 | [diff] [blame] | 101 | bool init(std::string name, uint32_t flags = 0); |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 102 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 103 | /** |
| 104 | * Sets the error handler function for this context. This error handler is |
| 105 | * called whenever an error is set. |
| 106 | * |
| 107 | * @param[in] func Error handler function |
| 108 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 109 | void setErrorHandler(ErrorHandlerFunc_t func); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * Returns the current error handler function for this context. |
| 113 | * |
| 114 | * @return pointer to current error handler function or NULL if not set |
| 115 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 116 | ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; } |
| 117 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 118 | /** |
| 119 | * Sets the message handler function for this context. This message handler |
| 120 | * is called whenever a message is sent from a RenderScript kernel. |
| 121 | * |
| 122 | * @param[in] func Message handler function |
| 123 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 124 | void setMessageHandler(MessageHandlerFunc_t func); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * Returns the current message handler function for this context. |
| 128 | * |
| 129 | * @return pointer to current message handler function or NULL if not set |
| 130 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 131 | MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; } |
| 132 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 133 | /** |
| 134 | * Returns current status for the context. |
| 135 | * |
| 136 | * @return current error |
| 137 | */ |
| Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 138 | RSError getError(); |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 139 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Waits for any currently running asynchronous operations to finish. This |
| 142 | * should only be used for performance testing and timing. |
| 143 | */ |
| Tim Murray | baca6c3 | 2012-11-14 16:51:46 -0800 | [diff] [blame] | 144 | void finish(); |
| 145 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 146 | RsContext getContext() { return mContext; } |
| 147 | void throwError(RSError error, const char *errMsg); |
| 148 | |
| Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 149 | static dispatchTable* dispatch; |
| 150 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 151 | private: |
| Tim Murray | 4a92d12 | 2013-07-22 10:56:18 -0700 | [diff] [blame] | 152 | static bool usingNative; |
| Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 153 | static bool initDispatch(int targetApi); |
| 154 | |
| Tim Murray | caf4126 | 2013-12-13 12:54:37 -0800 | [diff] [blame] | 155 | bool init(std::string &name, int targetApi, uint32_t flags); |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 156 | static void * threadProc(void *); |
| 157 | |
| 158 | static bool gInitialized; |
| 159 | static pthread_mutex_t gInitMutex; |
| 160 | |
| 161 | pthread_t mMessageThreadId; |
| 162 | pid_t mNativeMessageThreadId; |
| 163 | bool mMessageRun; |
| 164 | |
| 165 | RsDevice mDev; |
| 166 | RsContext mContext; |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 167 | RSError mCurrentError; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 168 | |
| 169 | ErrorHandlerFunc_t mErrorFunc; |
| 170 | MessageHandlerFunc_t mMessageFunc; |
| Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 171 | bool mInit; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 172 | |
| Tim Murray | caf4126 | 2013-12-13 12:54:37 -0800 | [diff] [blame] | 173 | std::string mCacheDir; |
| 174 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 175 | struct { |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 176 | sp<const Element> U8; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 177 | sp<const Element> U8_2; |
| 178 | sp<const Element> U8_3; |
| 179 | sp<const Element> U8_4; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 180 | sp<const Element> I8; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 181 | sp<const Element> I8_2; |
| 182 | sp<const Element> I8_3; |
| 183 | sp<const Element> I8_4; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 184 | sp<const Element> U16; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 185 | sp<const Element> U16_2; |
| 186 | sp<const Element> U16_3; |
| 187 | sp<const Element> U16_4; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 188 | sp<const Element> I16; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 189 | sp<const Element> I16_2; |
| 190 | sp<const Element> I16_3; |
| 191 | sp<const Element> I16_4; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 192 | sp<const Element> U32; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 193 | sp<const Element> U32_2; |
| 194 | sp<const Element> U32_3; |
| 195 | sp<const Element> U32_4; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 196 | sp<const Element> I32; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 197 | sp<const Element> I32_2; |
| 198 | sp<const Element> I32_3; |
| 199 | sp<const Element> I32_4; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 200 | sp<const Element> U64; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 201 | sp<const Element> U64_2; |
| 202 | sp<const Element> U64_3; |
| 203 | sp<const Element> U64_4; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 204 | sp<const Element> I64; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 205 | sp<const Element> I64_2; |
| 206 | sp<const Element> I64_3; |
| 207 | sp<const Element> I64_4; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 208 | sp<const Element> F32; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 209 | sp<const Element> F32_2; |
| 210 | sp<const Element> F32_3; |
| 211 | sp<const Element> F32_4; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 212 | sp<const Element> F64; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 213 | sp<const Element> F64_2; |
| 214 | sp<const Element> F64_3; |
| 215 | sp<const Element> F64_4; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 216 | sp<const Element> BOOLEAN; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 217 | |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 218 | sp<const Element> ELEMENT; |
| 219 | sp<const Element> TYPE; |
| 220 | sp<const Element> ALLOCATION; |
| 221 | sp<const Element> SAMPLER; |
| 222 | sp<const Element> SCRIPT; |
| 223 | sp<const Element> MESH; |
| 224 | sp<const Element> PROGRAM_FRAGMENT; |
| 225 | sp<const Element> PROGRAM_VERTEX; |
| 226 | sp<const Element> PROGRAM_RASTER; |
| 227 | sp<const Element> PROGRAM_STORE; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 228 | |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 229 | sp<const Element> A_8; |
| 230 | sp<const Element> RGB_565; |
| 231 | sp<const Element> RGB_888; |
| 232 | sp<const Element> RGBA_5551; |
| 233 | sp<const Element> RGBA_4444; |
| 234 | sp<const Element> RGBA_8888; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 235 | |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 236 | sp<const Element> YUV; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 237 | |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 238 | sp<const Element> MATRIX_4X4; |
| 239 | sp<const Element> MATRIX_3X3; |
| 240 | sp<const Element> MATRIX_2X2; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 241 | } mElements; |
| 242 | |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 243 | struct { |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 244 | sp<const Sampler> CLAMP_NEAREST; |
| 245 | sp<const Sampler> CLAMP_LINEAR; |
| 246 | sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR; |
| 247 | sp<const Sampler> WRAP_NEAREST; |
| 248 | sp<const Sampler> WRAP_LINEAR; |
| 249 | sp<const Sampler> WRAP_LINEAR_MIP_LINEAR; |
| 250 | sp<const Sampler> MIRRORED_REPEAT_NEAREST; |
| 251 | sp<const Sampler> MIRRORED_REPEAT_LINEAR; |
| 252 | sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR; |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 253 | } mSamplers; |
| 254 | friend class Sampler; |
| 255 | friend class Element; |
| Tim Murray | caf4126 | 2013-12-13 12:54:37 -0800 | [diff] [blame] | 256 | friend class ScriptC; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 257 | }; |
| 258 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 259 | /** |
| 260 | * Base class for all RenderScript objects. Not for direct use by developers. |
| 261 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 262 | class BaseObj : public android::RSC::LightRefBase<BaseObj> { |
| 263 | public: |
| 264 | void * getID() const; |
| 265 | virtual ~BaseObj(); |
| 266 | virtual void updateFromNative(); |
| 267 | virtual bool equals(sp<const BaseObj> obj); |
| 268 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 269 | protected: |
| 270 | void *mID; |
| Tim Murray | 3560907 | 2013-12-03 11:36:03 -0800 | [diff] [blame] | 271 | RS* mRS; |
| Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 272 | std::string mName; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 273 | |
| 274 | BaseObj(void *id, sp<RS> rs); |
| 275 | void checkValid(); |
| 276 | |
| 277 | static void * getObjID(sp<const BaseObj> o); |
| 278 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 279 | }; |
| 280 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 281 | /** |
| 282 | * This class provides the primary method through which data is passed to and |
| 283 | * from RenderScript kernels. An Allocation provides the backing store for a |
| 284 | * given Type. |
| 285 | * |
| 286 | * An Allocation also contains a set of usage flags that denote how the |
| 287 | * Allocation could be used. For example, an Allocation may have usage flags |
| 288 | * specifying that it can be used from a script as well as input to a |
| 289 | * Sampler. A developer must synchronize across these different usages using |
| 290 | * syncAll(int) in order to ensure that different users of the Allocation have |
| 291 | * a consistent view of memory. For example, in the case where an Allocation is |
| 292 | * used as the output of one kernel and as Sampler input in a later kernel, a |
| 293 | * developer must call syncAll(RS_ALLOCATION_USAGE_SCRIPT) prior to launching the |
| 294 | * second kernel to ensure correctness. |
| 295 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 296 | class Allocation : public BaseObj { |
| 297 | protected: |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 298 | sp<const Type> mType; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 299 | uint32_t mUsage; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 300 | sp<Allocation> mAdaptedAllocation; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 301 | |
| 302 | bool mConstrainedLOD; |
| 303 | bool mConstrainedFace; |
| 304 | bool mConstrainedY; |
| 305 | bool mConstrainedZ; |
| 306 | bool mReadAllowed; |
| 307 | bool mWriteAllowed; |
| 308 | uint32_t mSelectedY; |
| 309 | uint32_t mSelectedZ; |
| 310 | uint32_t mSelectedLOD; |
| 311 | RsAllocationCubemapFace mSelectedFace; |
| 312 | |
| 313 | uint32_t mCurrentDimX; |
| 314 | uint32_t mCurrentDimY; |
| 315 | uint32_t mCurrentDimZ; |
| 316 | uint32_t mCurrentCount; |
| 317 | |
| 318 | void * getIDSafe() const; |
| 319 | void updateCacheInfo(sp<const Type> t); |
| 320 | |
| 321 | Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage); |
| 322 | |
| 323 | void validateIsInt32(); |
| 324 | void validateIsInt16(); |
| 325 | void validateIsInt8(); |
| 326 | void validateIsFloat32(); |
| 327 | void validateIsObject(); |
| 328 | |
| 329 | virtual void updateFromNative(); |
| 330 | |
| 331 | 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] | 332 | void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff, |
| 333 | uint32_t w, uint32_t h, uint32_t d); |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 334 | |
| 335 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 336 | |
| 337 | /** |
| 338 | * Return Type for the allocation. |
| 339 | * @return pointer to underlying Type |
| 340 | */ |
| Stephen Hines | a180b7d | 2013-08-21 12:42:13 -0700 | [diff] [blame] | 341 | sp<const Type> getType() const { |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 342 | return mType; |
| 343 | } |
| 344 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 345 | /** |
| 346 | * Propagate changes from one usage of the Allocation to other usages of the Allocation. |
| 347 | * @param[in] srcLocation source location with changes to propagate elsewhere |
| 348 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 349 | void syncAll(RsAllocationUsageType srcLocation); |
| 350 | void ioSendOutput(); |
| 351 | void ioGetInput(); |
| 352 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 353 | /** |
| 354 | * Generate a mipmap chain. This is only valid if the Type of the Allocation |
| 355 | * includes mipmaps. This function will generate a complete set of mipmaps |
| 356 | * from the top level LOD and place them into the script memory space. If |
| 357 | * the Allocation is also using other memory spaces, a call to |
| 358 | * syncAll(Allocation.USAGE_SCRIPT) is required. |
| 359 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 360 | void generateMipmaps(); |
| Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 361 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 362 | /** |
| 363 | * Copy an array into part of this Allocation. |
| 364 | * @param[in] off offset of first Element to be overwritten |
| 365 | * @param[in] count number of Elements to copy |
| 366 | * @param[in] data array from which to copy |
| 367 | */ |
| Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 368 | void copy1DRangeFrom(uint32_t off, size_t count, const void *data); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 369 | |
| 370 | /** |
| 371 | * Copy part of an Allocation into part of this Allocation. |
| 372 | * @param[in] off offset of first Element to be overwritten |
| 373 | * @param[in] count number of Elements to copy |
| 374 | * @param[in] data Allocation from which to copy |
| 375 | * @param[in] dataOff offset of first Element in data to copy |
| 376 | */ |
| Tim Murray | a4cbc2b | 2012-11-14 17:18:08 -0800 | [diff] [blame] | 377 | 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] | 378 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 379 | /** |
| 380 | * Copy an array into part of this Allocation. |
| 381 | * @param[in] off offset of first Element to be overwritten |
| 382 | * @param[in] count number of Elements to copy |
| 383 | * @param[in] data array from which to copy |
| 384 | */ |
| Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 385 | void copy1DRangeTo(uint32_t off, size_t count, void *data); |
| 386 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 387 | /** |
| 388 | * Copy entire array to an Allocation. |
| 389 | * @param[in] data array from which to copy |
| 390 | */ |
| Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 391 | void copy1DFrom(const void* data); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 392 | |
| 393 | /** |
| 394 | * Copy entire Allocation to an array. |
| 395 | * @param[in] data destination array |
| 396 | */ |
| Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 397 | void copy1DTo(void* data); |
| Tim Murray | a4cbc2b | 2012-11-14 17:18:08 -0800 | [diff] [blame] | 398 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 399 | /** |
| 400 | * Copy from an array into a rectangular region in this Allocation. The |
| 401 | * array is assumed to be tightly packed. |
| 402 | * @param[in] xoff X offset of region to update in this Allocation |
| 403 | * @param[in] yoff Y offset of region to update in this Allocation |
| 404 | * @param[in] w Width of region to update |
| 405 | * @param[in] h Height of region to update |
| 406 | * @param[in] data Array from which to copy |
| 407 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 408 | 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] | 409 | const void *data); |
| Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 410 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 411 | /** |
| 412 | * Copy from this Allocation into a rectangular region in an array. The |
| 413 | * array is assumed to be tightly packed. |
| 414 | * @param[in] xoff X offset of region to copy from this Allocation |
| 415 | * @param[in] yoff Y offset of region to copy from this Allocation |
| 416 | * @param[in] w Width of region to update |
| 417 | * @param[in] h Height of region to update |
| 418 | * @param[in] data destination array |
| 419 | */ |
| Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 420 | void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 421 | void *data); |
| 422 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 423 | /** |
| 424 | * Copy from an Allocation into a rectangular region in this Allocation. |
| 425 | * @param[in] xoff X offset of region to update in this Allocation |
| 426 | * @param[in] yoff Y offset of region to update in this Allocation |
| 427 | * @param[in] w Width of region to update |
| 428 | * @param[in] h Height of region to update |
| 429 | * @param[in] data Allocation from which to copy |
| 430 | * @param[in] dataXoff X offset of region to copy from in data |
| 431 | * @param[in] dataYoff Y offset of region to copy from in data |
| 432 | */ |
| Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 433 | void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 434 | sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff); |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 435 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 436 | /** |
| 437 | * Copy from a strided array into a rectangular region in this Allocation. |
| 438 | * @param[in] xoff X offset of region to update in this Allocation |
| 439 | * @param[in] yoff Y offset of region to update in this Allocation |
| 440 | * @param[in] w Width of region to update |
| 441 | * @param[in] h Height of region to update |
| 442 | * @param[in] data array from which to copy |
| 443 | * @param[in] stride stride of data in bytes |
| 444 | */ |
| Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 445 | void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 446 | const void *data, size_t stride); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 447 | |
| 448 | /** |
| 449 | * Copy from a strided array into this Allocation. |
| 450 | * @param[in] data array from which to copy |
| 451 | * @param[in] stride stride of data in bytes |
| 452 | */ |
| Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 453 | void copy2DStridedFrom(const void *data, size_t stride); |
| 454 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 455 | /** |
| 456 | * Copy from a rectangular region in this Allocation into a strided array. |
| 457 | * @param[in] xoff X offset of region to update in this Allocation |
| 458 | * @param[in] yoff Y offset of region to update in this Allocation |
| 459 | * @param[in] w Width of region to update |
| 460 | * @param[in] h Height of region to update |
| 461 | * @param[in] data destination array |
| 462 | * @param[in] stride stride of data in bytes |
| 463 | */ |
| Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 464 | void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 465 | void *data, size_t stride); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 466 | |
| 467 | /** |
| 468 | * Copy this Allocation into a strided array. |
| 469 | * @param[in] data destination array |
| 470 | * @param[in] stride stride of data in bytes |
| 471 | */ |
| Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 472 | void copy2DStridedTo(void *data, size_t stride); |
| 473 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 474 | |
| 475 | /** |
| 476 | * Copy from an array into a 3D region in this Allocation. The |
| 477 | * array is assumed to be tightly packed. |
| 478 | * @param[in] xoff X offset of region to update in this Allocation |
| 479 | * @param[in] yoff Y offset of region to update in this Allocation |
| 480 | * @param[in] zoff Z offset of region to update in this Allocation |
| 481 | * @param[in] w Width of region to update |
| 482 | * @param[in] h Height of region to update |
| 483 | * @param[in] d Depth of region to update |
| 484 | * @param[in] data Array from which to copy |
| 485 | */ |
| Tim Murray | 9d24ae6 | 2013-08-30 12:17:14 -0700 | [diff] [blame] | 486 | void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, |
| 487 | uint32_t h, uint32_t d, const void* data); |
| 488 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 489 | /** |
| 490 | * Copy from an Allocation into a 3D region in this Allocation. |
| 491 | * @param[in] xoff X offset of region to update in this Allocation |
| 492 | * @param[in] yoff Y offset of region to update in this Allocation |
| 493 | * @param[in] zoff Z offset of region to update in this Allocation |
| 494 | * @param[in] w Width of region to update |
| 495 | * @param[in] h Height of region to update |
| 496 | * @param[in] d Depth of region to update |
| 497 | * @param[in] data Allocation from which to copy |
| 498 | * @param[in] dataXoff X offset of region in data to copy from |
| 499 | * @param[in] dataYoff Y offset of region in data to copy from |
| 500 | * @param[in] dataZoff Z offset of region in data to copy from |
| 501 | */ |
| Tim Murray | 9d24ae6 | 2013-08-30 12:17:14 -0700 | [diff] [blame] | 502 | void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, |
| 503 | uint32_t w, uint32_t h, uint32_t d, |
| 504 | sp<const Allocation> data, |
| 505 | uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff); |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 506 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 507 | /** |
| 508 | * Creates an Allocation for use by scripts with a given Type. |
| 509 | * @param[in] rs Context to which the Allocation will belong |
| 510 | * @param[in] type Type of the Allocation |
| Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 511 | * @param[in] mipmaps desired mipmap behavior for the Allocation |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 512 | * @param[in] usage usage for the Allocation |
| 513 | * @return new Allocation |
| 514 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 515 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 516 | RsAllocationMipmapControl mipmaps, uint32_t usage); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 517 | |
| 518 | /** |
| 519 | * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use |
| 520 | * with RS_ALLOCATION_USAGE_SHARED. |
| 521 | * @param[in] rs Context to which the Allocation will belong |
| 522 | * @param[in] type Type of the Allocation |
| Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 523 | * @param[in] mipmaps desired mipmap behavior for the Allocation |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 524 | * @param[in] usage usage for the Allocation |
| 525 | * @param[in] pointer existing backing store to use for this Allocation if possible |
| 526 | * @return new Allocation |
| 527 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 528 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 529 | RsAllocationMipmapControl mipmaps, uint32_t usage, void * pointer); |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 530 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 531 | /** |
| 532 | * Creates an Allocation for use by scripts with a given Type with no mipmaps. |
| 533 | * @param[in] rs Context to which the Allocation will belong |
| 534 | * @param[in] type Type of the Allocation |
| 535 | * @param[in] usage usage for the Allocation |
| 536 | * @return new Allocation |
| 537 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 538 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| 539 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 540 | /** |
| 541 | * Creates an Allocation with a specified number of given elements. |
| 542 | * @param[in] rs Context to which the Allocation will belong |
| 543 | * @param[in] e Element used in the Allocation |
| 544 | * @param[in] count Number of elements of the Allocation |
| 545 | * @param[in] usage usage for the Allocation |
| 546 | * @return new Allocation |
| 547 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 548 | static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count, |
| 549 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 550 | |
| 551 | /** |
| 552 | * Creates a 2D Allocation with a specified number of given elements. |
| 553 | * @param[in] rs Context to which the Allocation will belong |
| 554 | * @param[in] e Element used in the Allocation |
| 555 | * @param[in] x Width in Elements of the Allocation |
| 556 | * @param[in] y Height of the Allocation |
| 557 | * @param[in] usage usage for the Allocation |
| 558 | * @return new Allocation |
| 559 | */ |
| Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 560 | static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e, |
| 561 | size_t x, size_t y, |
| 562 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
| 563 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 564 | |
| Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 565 | /** |
| 566 | * Get the backing pointer for a USAGE_SHARED allocation. |
| 567 | * @param[in] stride optional parameter. when non-NULL, will contain |
| 568 | * stride in bytes of a 2D Allocation |
| 569 | * @return pointer to data |
| 570 | */ |
| 571 | void * getPointer(size_t *stride = NULL); |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 572 | }; |
| 573 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 574 | /** |
| 575 | * An Element represents one item within an Allocation. An Element is roughly |
| 576 | * equivalent to a C type in a RenderScript kernel. Elements may be basic |
| 577 | * or complex. Some basic elements are: |
| 578 | |
| 579 | * - A single float value (equivalent to a float in a kernel) |
| 580 | * - A four-element float vector (equivalent to a float4 in a kernel) |
| 581 | * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel) |
| 582 | * - A single signed 8-bit integer (equivalent to a char in a kernel) |
| 583 | |
| 584 | * Basic Elements are comprised of a Element.DataType and a |
| 585 | * Element.DataKind. The DataType encodes C type information of an Element, |
| 586 | * while the DataKind encodes how that Element should be interpreted by a |
| 587 | * Sampler. Note that Allocation objects with DataKind USER cannot be used as |
| 588 | * input for a Sampler. In general, Allocation objects that are intended for |
| 589 | * use with a Sampler should use bitmap-derived Elements such as |
| 590 | * Element::RGBA_8888. |
| 591 | */ |
| 592 | |
| 593 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 594 | class Element : public BaseObj { |
| 595 | public: |
| 596 | bool isComplex(); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 597 | |
| 598 | /** |
| 599 | * Elements could be simple, such as an int or a float, or a structure with |
| 600 | * multiple sub-elements, such as a collection of floats, float2, |
| 601 | * float4. This function returns zero for simple elements or the number of |
| 602 | * sub-elements otherwise. |
| 603 | * @return number of sub-elements |
| 604 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 605 | size_t getSubElementCount() { |
| 606 | return mVisibleElementMap.size(); |
| 607 | } |
| 608 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 609 | /** |
| 610 | * For complex Elements, this returns the sub-element at a given index. |
| 611 | * @param[in] index index of sub-element |
| 612 | * @return sub-element |
| 613 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 614 | sp<const Element> getSubElement(uint32_t index); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 615 | |
| 616 | /** |
| 617 | * For complex Elements, this returns the name of the sub-element at a given |
| 618 | * index. |
| 619 | * @param[in] index index of sub-element |
| 620 | * @return name of sub-element |
| 621 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 622 | const char * getSubElementName(uint32_t index); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 623 | |
| 624 | /** |
| 625 | * For complex Elements, this returns the size of the sub-element at a given |
| 626 | * index. |
| 627 | * @param[in] index index of sub-element |
| 628 | * @return size of sub-element |
| 629 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 630 | size_t getSubElementArraySize(uint32_t index); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 631 | |
| 632 | /** |
| 633 | * Returns the location of a sub-element within a complex Element. |
| 634 | * @param[in] index index of sub-element |
| 635 | * @return offset in bytes |
| 636 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 637 | uint32_t getSubElementOffsetBytes(uint32_t index); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 638 | |
| 639 | /** |
| 640 | * Returns the data type used for the Element. |
| 641 | * @return data type |
| 642 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 643 | RsDataType getDataType() const { |
| 644 | return mType; |
| 645 | } |
| 646 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 647 | /** |
| 648 | * Returns the data kind used for the Element. |
| 649 | * @return data kind |
| 650 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 651 | RsDataKind getDataKind() const { |
| 652 | return mKind; |
| 653 | } |
| 654 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 655 | /** |
| 656 | * Returns the size in bytes of the Element. |
| 657 | * @return size in bytes |
| 658 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 659 | size_t getSizeBytes() const { |
| 660 | return mSizeBytes; |
| 661 | } |
| 662 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 663 | /** |
| 664 | * Returns the number of vector components for this Element. |
| 665 | * @return number of vector components |
| 666 | */ |
| Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 667 | uint32_t getVectorSize() const { |
| 668 | return mVectorSize; |
| 669 | } |
| 670 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 671 | /** |
| 672 | * Utility function for returning an Element containing a single bool. |
| 673 | * @param[in] rs RenderScript context |
| 674 | * @return Element |
| 675 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 676 | static sp<const Element> BOOLEAN(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 677 | /** |
| 678 | * Utility function for returning an Element containing a single unsigned char. |
| 679 | * @param[in] rs RenderScript context |
| 680 | * @return Element |
| 681 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 682 | static sp<const Element> U8(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 683 | /** |
| 684 | * Utility function for returning an Element containing a single signed char. |
| 685 | * @param[in] rs RenderScript context |
| 686 | * @return Element |
| 687 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 688 | static sp<const Element> I8(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 689 | /** |
| 690 | * Utility function for returning an Element containing a single unsigned short. |
| 691 | * @param[in] rs RenderScript context |
| 692 | * @return Element |
| 693 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 694 | static sp<const Element> U16(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 695 | /** |
| 696 | * Utility function for returning an Element containing a single signed short. |
| 697 | * @param[in] rs RenderScript context |
| 698 | * @return Element |
| 699 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 700 | static sp<const Element> I16(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 701 | /** |
| 702 | * Utility function for returning an Element containing a single unsigned int. |
| 703 | * @param[in] rs RenderScript context |
| 704 | * @return Element |
| 705 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 706 | static sp<const Element> U32(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 707 | /** |
| 708 | * Utility function for returning an Element containing a single signed int. |
| 709 | * @param[in] rs RenderScript context |
| 710 | * @return Element |
| 711 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 712 | static sp<const Element> I32(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 713 | /** |
| 714 | * Utility function for returning an Element containing a single unsigned long long. |
| 715 | * @param[in] rs RenderScript context |
| 716 | * @return Element |
| 717 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 718 | static sp<const Element> U64(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 719 | /** |
| 720 | * Utility function for returning an Element containing a single signed long long. |
| 721 | * @param[in] rs RenderScript context |
| 722 | * @return Element |
| 723 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 724 | static sp<const Element> I64(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 725 | /** |
| 726 | * Utility function for returning an Element containing a single float. |
| 727 | * @param[in] rs RenderScript context |
| 728 | * @return Element |
| 729 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 730 | static sp<const Element> F32(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 731 | /** |
| 732 | * Utility function for returning an Element containing a single double. |
| 733 | * @param[in] rs RenderScript context |
| 734 | * @return Element |
| 735 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 736 | static sp<const Element> F64(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 737 | /** |
| 738 | * Utility function for returning an Element containing a single Element. |
| 739 | * @param[in] rs RenderScript context |
| 740 | * @return Element |
| 741 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 742 | static sp<const Element> ELEMENT(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 743 | /** |
| 744 | * Utility function for returning an Element containing a single Type. |
| 745 | * @param[in] rs RenderScript context |
| 746 | * @return Element |
| 747 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 748 | static sp<const Element> TYPE(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 749 | /** |
| 750 | * Utility function for returning an Element containing a single Allocation. |
| 751 | * @param[in] rs RenderScript context |
| 752 | * @return Element |
| 753 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 754 | static sp<const Element> ALLOCATION(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 755 | /** |
| 756 | * Utility function for returning an Element containing a single Sampler. |
| 757 | * @param[in] rs RenderScript context |
| 758 | * @return Element |
| 759 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 760 | static sp<const Element> SAMPLER(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 761 | /** |
| 762 | * Utility function for returning an Element containing a single Script. |
| 763 | * @param[in] rs RenderScript context |
| 764 | * @return Element |
| 765 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 766 | static sp<const Element> SCRIPT(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 767 | /** |
| 768 | * Utility function for returning an Element containing an ALPHA_8 pixel. |
| 769 | * @param[in] rs RenderScript context |
| 770 | * @return Element |
| 771 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 772 | static sp<const Element> A_8(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 773 | /** |
| 774 | * Utility function for returning an Element containing an RGB_565 pixel. |
| 775 | * @param[in] rs RenderScript context |
| 776 | * @return Element |
| 777 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 778 | static sp<const Element> RGB_565(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 779 | /** |
| 780 | * Utility function for returning an Element containing an RGB_888 pixel. |
| 781 | * @param[in] rs RenderScript context |
| 782 | * @return Element |
| 783 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 784 | static sp<const Element> RGB_888(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 785 | /** |
| 786 | * Utility function for returning an Element containing an RGBA_5551 pixel. |
| 787 | * @param[in] rs RenderScript context |
| 788 | * @return Element |
| 789 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 790 | static sp<const Element> RGBA_5551(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 791 | /** |
| 792 | * Utility function for returning an Element containing an RGBA_4444 pixel. |
| 793 | * @param[in] rs RenderScript context |
| 794 | * @return Element |
| 795 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 796 | static sp<const Element> RGBA_4444(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 797 | /** |
| 798 | * Utility function for returning an Element containing an RGBA_8888 pixel. |
| 799 | * @param[in] rs RenderScript context |
| 800 | * @return Element |
| 801 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 802 | static sp<const Element> RGBA_8888(sp<RS> rs); |
| 803 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 804 | /** |
| 805 | * Utility function for returning an Element containing a float2. |
| 806 | * @param[in] rs RenderScript context |
| 807 | * @return Element |
| 808 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 809 | static sp<const Element> F32_2(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 810 | /** |
| 811 | * Utility function for returning an Element containing a float3. |
| 812 | * @param[in] rs RenderScript context |
| 813 | * @return Element |
| 814 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 815 | static sp<const Element> F32_3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 816 | /** |
| 817 | * Utility function for returning an Element containing a float4. |
| 818 | * @param[in] rs RenderScript context |
| 819 | * @return Element |
| 820 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 821 | static sp<const Element> F32_4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 822 | /** |
| 823 | * Utility function for returning an Element containing a double2. |
| 824 | * @param[in] rs RenderScript context |
| 825 | * @return Element |
| 826 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 827 | static sp<const Element> F64_2(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 828 | /** |
| 829 | * Utility function for returning an Element containing a double3. |
| 830 | * @param[in] rs RenderScript context |
| 831 | * @return Element |
| 832 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 833 | static sp<const Element> F64_3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 834 | /** |
| 835 | * Utility function for returning an Element containing a double4. |
| 836 | * @param[in] rs RenderScript context |
| 837 | * @return Element |
| 838 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 839 | static sp<const Element> F64_4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 840 | /** |
| 841 | * Utility function for returning an Element containing a uchar2. |
| 842 | * @param[in] rs RenderScript context |
| 843 | * @return Element |
| 844 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 845 | static sp<const Element> U8_2(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 846 | /** |
| 847 | * Utility function for returning an Element containing a uchar3. |
| 848 | * @param[in] rs RenderScript context |
| 849 | * @return Element |
| 850 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 851 | static sp<const Element> U8_3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 852 | /** |
| 853 | * Utility function for returning an Element containing a uchar4. |
| 854 | * @param[in] rs RenderScript context |
| 855 | * @return Element |
| 856 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 857 | static sp<const Element> U8_4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 858 | /** |
| 859 | * Utility function for returning an Element containing a char2. |
| 860 | * @param[in] rs RenderScript context |
| 861 | * @return Element |
| 862 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 863 | static sp<const Element> I8_2(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 864 | /** |
| 865 | * Utility function for returning an Element containing a char3. |
| 866 | * @param[in] rs RenderScript context |
| 867 | * @return Element |
| 868 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 869 | static sp<const Element> I8_3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 870 | /** |
| 871 | * Utility function for returning an Element containing a char4. |
| 872 | * @param[in] rs RenderScript context |
| 873 | * @return Element |
| 874 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 875 | static sp<const Element> I8_4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 876 | /** |
| 877 | * Utility function for returning an Element containing a ushort2. |
| 878 | * @param[in] rs RenderScript context |
| 879 | * @return Element |
| 880 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 881 | static sp<const Element> U16_2(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 882 | /** |
| 883 | * Utility function for returning an Element containing a ushort3. |
| 884 | * @param[in] rs RenderScript context |
| 885 | * @return Element |
| 886 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 887 | static sp<const Element> U16_3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 888 | /** |
| 889 | * Utility function for returning an Element containing a ushort4. |
| 890 | * @param[in] rs RenderScript context |
| 891 | * @return Element |
| 892 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 893 | static sp<const Element> U16_4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 894 | /** |
| 895 | * Utility function for returning an Element containing a short2. |
| 896 | * @param[in] rs RenderScript context |
| 897 | * @return Element |
| 898 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 899 | static sp<const Element> I16_2(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 900 | /** |
| 901 | * Utility function for returning an Element containing a short3. |
| 902 | * @param[in] rs RenderScript context |
| 903 | * @return Element |
| 904 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 905 | static sp<const Element> I16_3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 906 | /** |
| 907 | * Utility function for returning an Element containing a short4. |
| 908 | * @param[in] rs RenderScript context |
| 909 | * @return Element |
| 910 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 911 | static sp<const Element> I16_4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 912 | /** |
| 913 | * Utility function for returning an Element containing a uint2. |
| 914 | * @param[in] rs RenderScript context |
| 915 | * @return Element |
| 916 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 917 | static sp<const Element> U32_2(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 918 | /** |
| 919 | * Utility function for returning an Element containing a uint3. |
| 920 | * @param[in] rs RenderScript context |
| 921 | * @return Element |
| 922 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 923 | static sp<const Element> U32_3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 924 | /** |
| 925 | * Utility function for returning an Element containing a uint4. |
| 926 | * @param[in] rs RenderScript context |
| 927 | * @return Element |
| 928 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 929 | static sp<const Element> U32_4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 930 | /** |
| 931 | * Utility function for returning an Element containing an int2. |
| 932 | * @param[in] rs RenderScript context |
| 933 | * @return Element |
| 934 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 935 | static sp<const Element> I32_2(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 936 | /** |
| 937 | * Utility function for returning an Element containing an int3. |
| 938 | * @param[in] rs RenderScript context |
| 939 | * @return Element |
| 940 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 941 | static sp<const Element> I32_3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 942 | /** |
| 943 | * Utility function for returning an Element containing an int4. |
| 944 | * @param[in] rs RenderScript context |
| 945 | * @return Element |
| 946 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 947 | static sp<const Element> I32_4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 948 | /** |
| 949 | * Utility function for returning an Element containing a ulong2. |
| 950 | * @param[in] rs RenderScript context |
| 951 | * @return Element |
| 952 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 953 | static sp<const Element> U64_2(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 954 | /** |
| 955 | * Utility function for returning an Element containing a ulong3. |
| 956 | * @param[in] rs RenderScript context |
| 957 | * @return Element |
| 958 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 959 | static sp<const Element> U64_3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 960 | /** |
| 961 | * Utility function for returning an Element containing a ulong4. |
| 962 | * @param[in] rs RenderScript context |
| 963 | * @return Element |
| 964 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 965 | static sp<const Element> U64_4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 966 | /** |
| 967 | * Utility function for returning an Element containing a long2. |
| 968 | * @param[in] rs RenderScript context |
| 969 | * @return Element |
| 970 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 971 | static sp<const Element> I64_2(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 972 | /** |
| 973 | * Utility function for returning an Element containing a long3. |
| 974 | * @param[in] rs RenderScript context |
| 975 | * @return Element |
| 976 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 977 | static sp<const Element> I64_3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 978 | /** |
| 979 | * Utility function for returning an Element containing a long4. |
| 980 | * @param[in] rs RenderScript context |
| 981 | * @return Element |
| 982 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 983 | static sp<const Element> I64_4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 984 | /** |
| 985 | * Utility function for returning an Element containing a YUV pixel. |
| 986 | * @param[in] rs RenderScript context |
| 987 | * @return Element |
| 988 | */ |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 989 | static sp<const Element> YUV(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 990 | /** |
| 991 | * Utility function for returning an Element containing an rs_matrix_4x4. |
| 992 | * @param[in] rs RenderScript context |
| 993 | * @return Element |
| 994 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 995 | static sp<const Element> MATRIX_4X4(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 996 | /** |
| 997 | * Utility function for returning an Element containing an rs_matrix_3x3. |
| 998 | * @param[in] rs RenderScript context |
| 999 | * @return Element |
| 1000 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1001 | static sp<const Element> MATRIX_3X3(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1002 | /** |
| 1003 | * Utility function for returning an Element containing an rs_matrix_2x2. |
| 1004 | * @param[in] rs RenderScript context |
| 1005 | * @return Element |
| 1006 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1007 | static sp<const Element> MATRIX_2X2(sp<RS> rs); |
| 1008 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1009 | void updateFromNative(); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1010 | |
| 1011 | /** |
| 1012 | * Create an Element with a given DataType. |
| 1013 | * @param[in] rs RenderScript context |
| 1014 | * @param[in] dt data type |
| 1015 | * @return Element |
| 1016 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1017 | static sp<const Element> createUser(sp<RS> rs, RsDataType dt); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1018 | /** |
| 1019 | * Create a vector Element with the given DataType |
| 1020 | * @param[in] rs RenderScript |
| 1021 | * @param[in] dt DataType |
| 1022 | * @param[in] size vector size |
| 1023 | * @return Element |
| 1024 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1025 | static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1026 | /** |
| 1027 | * Create an Element with a given DataType and DataKind. |
| 1028 | * @param[in] rs RenderScript context |
| 1029 | * @param[in] dt DataType |
| 1030 | * @param[in] dk DataKind |
| 1031 | * @return Element |
| 1032 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1033 | static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1034 | |
| 1035 | /** |
| 1036 | * Returns true if the Element can interoperate with this Element. |
| 1037 | * @param[in] e Element to compare |
| 1038 | * @return true if Elements can interoperate |
| 1039 | */ |
| Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 1040 | bool isCompatible(sp<const Element>e) const; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1041 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1042 | /** |
| 1043 | * Builder class for producing complex elements with matching field and name |
| 1044 | * pairs. The builder starts empty. The order in which elements are added is |
| 1045 | * retained for the layout in memory. |
| 1046 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1047 | class Builder { |
| 1048 | private: |
| Tim Murray | 3560907 | 2013-12-03 11:36:03 -0800 | [diff] [blame] | 1049 | RS* mRS; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1050 | std::vector<sp<Element> > mElements; |
| Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 1051 | std::vector<std::string> mElementNames; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1052 | std::vector<uint32_t> mArraySizes; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1053 | bool mSkipPadding; |
| 1054 | |
| 1055 | public: |
| 1056 | Builder(sp<RS> rs); |
| 1057 | ~Builder(); |
| Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 1058 | void add(sp<Element> e, std::string &name, uint32_t arraySize = 1); |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1059 | sp<const Element> create(); |
| 1060 | }; |
| 1061 | |
| Stephen Hines | 7d1b757 | 2013-08-22 01:24:06 -0700 | [diff] [blame] | 1062 | protected: |
| 1063 | Element(void *id, sp<RS> rs, |
| 1064 | std::vector<sp<Element> > &elements, |
| 1065 | std::vector<std::string> &elementNames, |
| 1066 | std::vector<uint32_t> &arraySizes); |
| 1067 | Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size); |
| 1068 | Element(sp<RS> rs); |
| 1069 | virtual ~Element(); |
| 1070 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1071 | private: |
| 1072 | void updateVisibleSubElements(); |
| 1073 | |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1074 | std::vector<sp<Element> > mElements; |
| Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 1075 | std::vector<std::string> mElementNames; |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1076 | std::vector<uint32_t> mArraySizes; |
| 1077 | std::vector<uint32_t> mVisibleElementMap; |
| 1078 | std::vector<uint32_t> mOffsetInBytes; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1079 | |
| 1080 | RsDataType mType; |
| 1081 | RsDataKind mKind; |
| 1082 | bool mNormalized; |
| 1083 | size_t mSizeBytes; |
| 1084 | size_t mVectorSize; |
| 1085 | }; |
| 1086 | |
| Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 1087 | class FieldPacker { |
| 1088 | protected: |
| 1089 | unsigned char* mData; |
| 1090 | size_t mPos; |
| 1091 | size_t mLen; |
| 1092 | |
| 1093 | public: |
| 1094 | FieldPacker(size_t len) |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1095 | : mPos(0), mLen(len) { |
| 1096 | mData = new unsigned char[len]; |
| 1097 | } |
| Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 1098 | |
| 1099 | virtual ~FieldPacker() { |
| 1100 | delete [] mData; |
| 1101 | } |
| 1102 | |
| 1103 | void align(size_t v) { |
| 1104 | if ((v & (v - 1)) != 0) { |
| Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 1105 | // ALOGE("Non-power-of-two alignment: %zu", v); |
| Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 1106 | return; |
| 1107 | } |
| 1108 | |
| 1109 | while ((mPos & (v - 1)) != 0) { |
| 1110 | mData[mPos++] = 0; |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | void reset() { |
| 1115 | mPos = 0; |
| 1116 | } |
| 1117 | |
| 1118 | void reset(size_t i) { |
| 1119 | if (i >= mLen) { |
| Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 1120 | // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen); |
| Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 1121 | return; |
| 1122 | } |
| 1123 | mPos = i; |
| 1124 | } |
| 1125 | |
| 1126 | void skip(size_t i) { |
| 1127 | size_t res = mPos + i; |
| 1128 | if (res > mLen) { |
| Tim Murray | ab71636 | 2013-08-12 12:37:18 -0700 | [diff] [blame] | 1129 | // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen); |
| Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 1130 | return; |
| 1131 | } |
| 1132 | mPos = res; |
| 1133 | } |
| 1134 | |
| 1135 | void* getData() const { |
| 1136 | return mData; |
| 1137 | } |
| 1138 | |
| 1139 | size_t getLength() const { |
| 1140 | return mLen; |
| 1141 | } |
| 1142 | |
| 1143 | template <typename T> |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1144 | void add(T t) { |
| Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 1145 | align(sizeof(t)); |
| 1146 | if (mPos + sizeof(t) <= mLen) { |
| 1147 | memcpy(&mData[mPos], &t, sizeof(t)); |
| 1148 | mPos += sizeof(t); |
| 1149 | } |
| 1150 | } |
| Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 1151 | |
| 1152 | /* |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1153 | void add(rs_matrix4x4 m) { |
| 1154 | for (size_t i = 0; i < 16; i++) { |
| 1155 | add(m.m[i]); |
| 1156 | } |
| 1157 | } |
| Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 1158 | |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1159 | void add(rs_matrix3x3 m) { |
| 1160 | for (size_t i = 0; i < 9; i++) { |
| 1161 | add(m.m[i]); |
| 1162 | } |
| 1163 | } |
| Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 1164 | |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1165 | void add(rs_matrix2x2 m) { |
| 1166 | for (size_t i = 0; i < 4; i++) { |
| 1167 | add(m.m[i]); |
| 1168 | } |
| 1169 | } |
| Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 1170 | */ |
| 1171 | |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1172 | void add(sp<BaseObj> obj) { |
| Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 1173 | if (obj != NULL) { |
| 1174 | add((uint32_t) (uintptr_t) obj->getID()); |
| 1175 | } else { |
| 1176 | add((uint32_t) 0); |
| 1177 | } |
| 1178 | } |
| Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 1179 | }; |
| 1180 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1181 | /** |
| 1182 | * A Type describes the Element and dimensions used for an Allocation or a |
| 1183 | * parallel operation. |
| 1184 | * |
| 1185 | * A Type always includes an Element and an X dimension. A Type may be |
| 1186 | * multidimensional, up to three dimensions. A nonzero value in the Y or Z |
| 1187 | * dimensions indicates that the dimension is present. Note that a Type with |
| 1188 | * only a given X dimension and a Type with the same X dimension but Y = 1 are |
| 1189 | * not equivalent. |
| 1190 | * |
| 1191 | * A Type also supports inclusion of level of detail (LOD) or cube map |
| 1192 | * faces. LOD and cube map faces are booleans to indicate present or not |
| 1193 | * present. |
| 1194 | * |
| 1195 | * A Type also supports YUV format information to support an Allocation in a YUV |
| 1196 | * format. The YUV formats supported are YV12 and NV21. |
| 1197 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1198 | class Type : public BaseObj { |
| 1199 | protected: |
| 1200 | friend class Allocation; |
| 1201 | |
| 1202 | uint32_t mDimX; |
| 1203 | uint32_t mDimY; |
| 1204 | uint32_t mDimZ; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 1205 | RSYuvFormat mYuvFormat; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1206 | bool mDimMipmaps; |
| 1207 | bool mDimFaces; |
| 1208 | size_t mElementCount; |
| 1209 | sp<const Element> mElement; |
| 1210 | |
| Stephen Hines | 7d1b757 | 2013-08-22 01:24:06 -0700 | [diff] [blame] | 1211 | Type(void *id, sp<RS> rs); |
| 1212 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1213 | void calcElementCount(); |
| 1214 | virtual void updateFromNative(); |
| 1215 | |
| 1216 | public: |
| 1217 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1218 | /** |
| 1219 | * Returns the YUV format. |
| 1220 | * @return YUV format of the Allocation |
| 1221 | */ |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 1222 | RSYuvFormat getYuvFormat() const { |
| 1223 | return mYuvFormat; |
| 1224 | } |
| 1225 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1226 | /** |
| 1227 | * Returns the Element of the Allocation. |
| 1228 | * @return YUV format of the Allocation |
| 1229 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1230 | sp<const Element> getElement() const { |
| 1231 | return mElement; |
| 1232 | } |
| 1233 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1234 | /** |
| 1235 | * Returns the X dimension of the Allocation. |
| 1236 | * @return X dimension of the allocation |
| 1237 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1238 | uint32_t getX() const { |
| 1239 | return mDimX; |
| 1240 | } |
| 1241 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1242 | /** |
| 1243 | * Returns the Y dimension of the Allocation. |
| 1244 | * @return Y dimension of the allocation |
| 1245 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1246 | uint32_t getY() const { |
| 1247 | return mDimY; |
| 1248 | } |
| 1249 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1250 | /** |
| 1251 | * Returns the Z dimension of the Allocation. |
| 1252 | * @return Z dimension of the allocation |
| 1253 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1254 | uint32_t getZ() const { |
| 1255 | return mDimZ; |
| 1256 | } |
| 1257 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1258 | /** |
| 1259 | * Returns true if the Allocation has mipmaps. |
| 1260 | * @return true if the Allocation has mipmaps |
| 1261 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1262 | bool hasMipmaps() const { |
| 1263 | return mDimMipmaps; |
| 1264 | } |
| 1265 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1266 | /** |
| 1267 | * Returns true if the Allocation is a cube map |
| 1268 | * @return true if the Allocation is a cube map |
| 1269 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1270 | bool hasFaces() const { |
| 1271 | return mDimFaces; |
| 1272 | } |
| 1273 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1274 | /** |
| 1275 | * Returns number of accessible Elements in the Allocation |
| 1276 | * @return number of accessible Elements in the Allocation |
| 1277 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1278 | size_t getCount() const { |
| 1279 | return mElementCount; |
| 1280 | } |
| 1281 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1282 | /** |
| 1283 | * Returns size in bytes of all Elements in the Allocation |
| 1284 | * @return size in bytes of all Elements in the Allocation |
| 1285 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1286 | size_t getSizeBytes() const { |
| 1287 | return mElementCount * mElement->getSizeBytes(); |
| 1288 | } |
| 1289 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1290 | /** |
| 1291 | * Creates a new Type with the given Element and dimensions. |
| 1292 | * @param[in] rs RenderScript context |
| 1293 | * @param[in] e Element |
| 1294 | * @param[in] dimX X dimension |
| 1295 | * @param[in] dimY Y dimension |
| 1296 | * @param[in] dimZ Z dimension |
| 1297 | * @return new Type |
| 1298 | */ |
| Tim Murray | 96267c2 | 2013-02-12 11:25:12 -0800 | [diff] [blame] | 1299 | 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] | 1300 | |
| 1301 | class Builder { |
| 1302 | protected: |
| Tim Murray | 3560907 | 2013-12-03 11:36:03 -0800 | [diff] [blame] | 1303 | RS* mRS; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1304 | uint32_t mDimX; |
| 1305 | uint32_t mDimY; |
| 1306 | uint32_t mDimZ; |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 1307 | RSYuvFormat mYuvFormat; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1308 | bool mDimMipmaps; |
| 1309 | bool mDimFaces; |
| 1310 | sp<const Element> mElement; |
| 1311 | |
| 1312 | public: |
| 1313 | Builder(sp<RS> rs, sp<const Element> e); |
| 1314 | |
| 1315 | void setX(uint32_t value); |
| Stephen Hines | 7d1b757 | 2013-08-22 01:24:06 -0700 | [diff] [blame] | 1316 | void setY(uint32_t value); |
| Tim Murray | eb4426d | 2013-08-27 15:30:16 -0700 | [diff] [blame] | 1317 | void setZ(uint32_t value); |
| 1318 | void setYuvFormat(RSYuvFormat format); |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1319 | void setMipmaps(bool value); |
| 1320 | void setFaces(bool value); |
| 1321 | sp<const Type> create(); |
| 1322 | }; |
| 1323 | |
| 1324 | }; |
| 1325 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1326 | /** |
| 1327 | * The parent class for all executable Scripts. This should not be used by applications. |
| 1328 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1329 | class Script : public BaseObj { |
| 1330 | private: |
| 1331 | |
| 1332 | protected: |
| 1333 | Script(void *id, sp<RS> rs); |
| 1334 | void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out, |
| 1335 | const void *v, size_t) const; |
| 1336 | void bindAllocation(sp<Allocation> va, uint32_t slot) const; |
| 1337 | void setVar(uint32_t index, const void *, size_t len) const; |
| 1338 | void setVar(uint32_t index, sp<const BaseObj> o) const; |
| 1339 | void invoke(uint32_t slot, const void *v, size_t len) const; |
| 1340 | |
| 1341 | |
| 1342 | void invoke(uint32_t slot) const { |
| 1343 | invoke(slot, NULL, 0); |
| 1344 | } |
| 1345 | void setVar(uint32_t index, float v) const { |
| 1346 | setVar(index, &v, sizeof(v)); |
| 1347 | } |
| 1348 | void setVar(uint32_t index, double v) const { |
| 1349 | setVar(index, &v, sizeof(v)); |
| 1350 | } |
| 1351 | void setVar(uint32_t index, int32_t v) const { |
| 1352 | setVar(index, &v, sizeof(v)); |
| 1353 | } |
| 1354 | void setVar(uint32_t index, int64_t v) const { |
| 1355 | setVar(index, &v, sizeof(v)); |
| 1356 | } |
| 1357 | void setVar(uint32_t index, bool v) const { |
| 1358 | setVar(index, &v, sizeof(v)); |
| 1359 | } |
| 1360 | |
| 1361 | public: |
| 1362 | class FieldBase { |
| 1363 | protected: |
| 1364 | sp<const Element> mElement; |
| 1365 | sp<Allocation> mAllocation; |
| 1366 | |
| 1367 | void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0); |
| 1368 | |
| 1369 | public: |
| 1370 | sp<const Element> getElement() { |
| 1371 | return mElement; |
| 1372 | } |
| 1373 | |
| 1374 | sp<const Type> getType() { |
| 1375 | return mAllocation->getType(); |
| 1376 | } |
| 1377 | |
| 1378 | sp<const Allocation> getAllocation() { |
| 1379 | return mAllocation; |
| 1380 | } |
| 1381 | |
| 1382 | //void updateAllocation(); |
| 1383 | }; |
| 1384 | }; |
| 1385 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1386 | /** |
| 1387 | * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only. |
| 1388 | */ |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1389 | class ScriptC : public Script { |
| 1390 | protected: |
| 1391 | ScriptC(sp<RS> rs, |
| 1392 | const void *codeTxt, size_t codeLength, |
| 1393 | const char *cachedName, size_t cachedNameLength, |
| 1394 | const char *cacheDir, size_t cacheDirLength); |
| 1395 | |
| 1396 | }; |
| 1397 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1398 | /** |
| 1399 | * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of |
| 1400 | * basic functions. This is not intended to be used directly. |
| 1401 | */ |
| Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 1402 | class ScriptIntrinsic : public Script { |
| 1403 | protected: |
| Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 1404 | sp<const Element> mElement; |
| Tim Murray | 3cd44af | 2012-11-14 11:25:27 -0800 | [diff] [blame] | 1405 | ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e); |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1406 | virtual ~ScriptIntrinsic(); |
| Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 1407 | }; |
| 1408 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1409 | /** |
| 1410 | * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming |
| 1411 | * r,g,b values are use as normalized x,y,z coordinates into a 3D |
| 1412 | * allocation. The 8 nearest values are sampled and linearly interpolated. The |
| 1413 | * result is placed in the output. |
| 1414 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1415 | class ScriptIntrinsic3DLUT : public ScriptIntrinsic { |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1416 | private: |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1417 | ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1418 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1419 | /** |
| 1420 | * Supported Element types are U8_4. Default lookup table is identity. |
| 1421 | * @param[in] rs RenderScript context |
| 1422 | * @param[in] e Element |
| 1423 | * @return new ScriptIntrinsic |
| 1424 | */ |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1425 | static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1426 | |
| 1427 | /** |
| 1428 | * Launch the intrinsic. |
| 1429 | * @param[in] ain input Allocation |
| 1430 | * @param[in] aout output Allocation |
| 1431 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1432 | void forEach(sp<Allocation> ain, sp<Allocation> aout); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1433 | |
| 1434 | /** |
| 1435 | * Sets the lookup table. The lookup table must use the same Element as the |
| 1436 | * intrinsic. |
| 1437 | * @param[in] lut new lookup table |
| 1438 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1439 | void setLUT(sp<Allocation> lut); |
| 1440 | }; |
| 1441 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1442 | /** |
| 1443 | * Intrinsic kernel for blending two Allocations. |
| 1444 | */ |
| Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 1445 | class ScriptIntrinsicBlend : public ScriptIntrinsic { |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1446 | private: |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1447 | ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1448 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1449 | /** |
| 1450 | * Supported Element types are U8_4. |
| 1451 | * @param[in] rs RenderScript context |
| 1452 | * @param[in] e Element |
| 1453 | * @return new ScriptIntrinsicBlend |
| 1454 | */ |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1455 | static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1456 | /** |
| 1457 | * sets dst = {0, 0, 0, 0} |
| 1458 | * @param[in] in input Allocation |
| 1459 | * @param[in] out output Allocation |
| 1460 | */ |
| 1461 | void forEachClear(sp<Allocation> in, sp<Allocation> out); |
| 1462 | /** |
| 1463 | * Sets dst = src |
| 1464 | * @param[in] in input Allocation |
| 1465 | * @param[in] out output Allocation |
| 1466 | */ |
| 1467 | void forEachSrc(sp<Allocation> in, sp<Allocation> out); |
| 1468 | /** |
| 1469 | * Sets dst = dst (NOP) |
| 1470 | * @param[in] in input Allocation |
| 1471 | * @param[in] out output Allocation |
| 1472 | */ |
| 1473 | void forEachDst(sp<Allocation> in, sp<Allocation> out); |
| 1474 | /** |
| 1475 | * Sets dst = src + dst * (1.0 - src.a) |
| 1476 | * @param[in] in input Allocation |
| 1477 | * @param[in] out output Allocation |
| 1478 | */ |
| 1479 | void forEachSrcOver(sp<Allocation> in, sp<Allocation> out); |
| 1480 | /** |
| 1481 | * Sets dst = dst + src * (1.0 - dst.a) |
| 1482 | * @param[in] in input Allocation |
| 1483 | * @param[in] out output Allocation |
| 1484 | */ |
| 1485 | void forEachDstOver(sp<Allocation> in, sp<Allocation> out); |
| 1486 | /** |
| 1487 | * Sets dst = src * dst.a |
| 1488 | * @param[in] in input Allocation |
| 1489 | * @param[in] out output Allocation |
| 1490 | */ |
| 1491 | void forEachSrcIn(sp<Allocation> in, sp<Allocation> out); |
| 1492 | /** |
| 1493 | * Sets dst = dst * src.a |
| 1494 | * @param[in] in input Allocation |
| 1495 | * @param[in] out output Allocation |
| 1496 | */ |
| 1497 | void forEachDstIn(sp<Allocation> in, sp<Allocation> out); |
| 1498 | /** |
| 1499 | * Sets dst = src * (1.0 - dst.a) |
| 1500 | * @param[in] in input Allocation |
| 1501 | * @param[in] out output Allocation |
| 1502 | */ |
| 1503 | void forEachSrcOut(sp<Allocation> in, sp<Allocation> out); |
| 1504 | /** |
| 1505 | * Sets dst = dst * (1.0 - src.a) |
| 1506 | * @param[in] in input Allocation |
| 1507 | * @param[in] out output Allocation |
| 1508 | */ |
| 1509 | void forEachDstOut(sp<Allocation> in, sp<Allocation> out); |
| 1510 | /** |
| 1511 | * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb |
| 1512 | * @param[in] in input Allocation |
| 1513 | * @param[in] out output Allocation |
| 1514 | */ |
| 1515 | void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out); |
| 1516 | /** |
| 1517 | * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb |
| 1518 | * @param[in] in input Allocation |
| 1519 | * @param[in] out output Allocation |
| 1520 | */ |
| 1521 | void forEachDstAtop(sp<Allocation> in, sp<Allocation> out); |
| 1522 | /** |
| 1523 | * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a} |
| 1524 | * @param[in] in input Allocation |
| 1525 | * @param[in] out output Allocation |
| 1526 | */ |
| 1527 | void forEachXor(sp<Allocation> in, sp<Allocation> out); |
| 1528 | /** |
| 1529 | * Sets dst = src * dst |
| 1530 | * @param[in] in input Allocation |
| 1531 | * @param[in] out output Allocation |
| 1532 | */ |
| 1533 | void forEachMultiply(sp<Allocation> in, sp<Allocation> out); |
| 1534 | /** |
| 1535 | * Sets dst = min(src + dst, 1.0) |
| 1536 | * @param[in] in input Allocation |
| 1537 | * @param[in] out output Allocation |
| 1538 | */ |
| 1539 | void forEachAdd(sp<Allocation> in, sp<Allocation> out); |
| 1540 | /** |
| 1541 | * Sets dst = max(dst - src, 0.0) |
| 1542 | * @param[in] in input Allocation |
| 1543 | * @param[in] out output Allocation |
| 1544 | */ |
| 1545 | void forEachSubtract(sp<Allocation> in, sp<Allocation> out); |
| Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 1546 | }; |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1547 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1548 | /** |
| 1549 | * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified |
| 1550 | * radius to all elements of an Allocation. |
| 1551 | */ |
| Tim Murray | 8f1e60c | 2012-11-13 12:25:11 -0800 | [diff] [blame] | 1552 | class ScriptIntrinsicBlur : public ScriptIntrinsic { |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1553 | private: |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1554 | ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1555 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1556 | /** |
| 1557 | * Supported Element types are U8 and U8_4. |
| 1558 | * @param[in] rs RenderScript context |
| 1559 | * @param[in] e Element |
| 1560 | * @return new ScriptIntrinsicBlur |
| 1561 | */ |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1562 | static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1563 | /** |
| 1564 | * Sets the input of the blur. |
| 1565 | * @param[in] in input Allocation |
| 1566 | */ |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1567 | void setInput(sp<Allocation> in); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1568 | /** |
| 1569 | * Runs the intrinsic. |
| 1570 | * @param[in] output Allocation |
| 1571 | */ |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1572 | void forEach(sp<Allocation> out); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1573 | /** |
| 1574 | * Sets the radius of the blur. The supported range is 0 < radius <= 25. |
| 1575 | * @param[in] radius radius of the blur |
| 1576 | */ |
| Tim Murray | 8f1e60c | 2012-11-13 12:25:11 -0800 | [diff] [blame] | 1577 | void setRadius(float radius); |
| 1578 | }; |
| 1579 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1580 | /** |
| 1581 | * Intrinsic for applying a color matrix to allocations. This has the |
| 1582 | * same effect as loading each element and converting it to a |
| 1583 | * F32_N, multiplying the result by the 4x4 color matrix |
| 1584 | * as performed by rsMatrixMultiply() and writing it to the output |
| 1585 | * after conversion back to U8_N or F32_N. |
| 1586 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1587 | class ScriptIntrinsicColorMatrix : public ScriptIntrinsic { |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1588 | private: |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1589 | ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1590 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1591 | /** |
| 1592 | * Creates a new intrinsic. |
| 1593 | * @param[in] rs RenderScript context |
| 1594 | * @return new ScriptIntrinsicColorMatrix |
| 1595 | */ |
| Tim Murray | aae73c9 | 2013-09-03 17:05:46 -0700 | [diff] [blame] | 1596 | static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1597 | /** |
| 1598 | * Applies the color matrix. Supported types are U8 and F32 with |
| 1599 | * vector lengths between 1 and 4. |
| 1600 | * @param[in] in input Allocation |
| 1601 | * @param[out] out output Allocation |
| 1602 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1603 | void forEach(sp<Allocation> in, sp<Allocation> out); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1604 | /** |
| 1605 | * Set the value to be added after the color matrix has been |
| 1606 | * applied. The default value is {0, 0, 0, 0}. |
| 1607 | * @param[in] add float[4] of values |
| 1608 | */ |
| Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 1609 | void setAdd(float* add); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1610 | |
| 1611 | /** |
| 1612 | * Set the color matrix which will be applied to each cell of the |
| 1613 | * image. The alpha channel will be copied. |
| 1614 | * |
| 1615 | * @param[in] m float[9] of values |
| 1616 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1617 | void setColorMatrix3(float* m); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1618 | /** |
| 1619 | * Set the color matrix which will be applied to each cell of the |
| 1620 | * image. |
| 1621 | * |
| 1622 | * @param[in] m float[16] of values |
| 1623 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1624 | void setColorMatrix4(float* m); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1625 | /** |
| 1626 | * Set a color matrix to convert from RGB to luminance. The alpha |
| 1627 | * channel will be a copy. |
| 1628 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1629 | void setGreyscale(); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1630 | /** |
| 1631 | * Set the matrix to convert from RGB to YUV with a direct copy of |
| 1632 | * the 4th channel. |
| 1633 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1634 | void setRGBtoYUV(); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1635 | /** |
| 1636 | * Set the matrix to convert from YUV to RGB with a direct copy of |
| 1637 | * the 4th channel. |
| 1638 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1639 | void setYUVtoRGB(); |
| 1640 | }; |
| 1641 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1642 | /** |
| 1643 | * Intrinsic for applying a 3x3 convolve to an allocation. |
| 1644 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1645 | class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic { |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1646 | private: |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1647 | ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1648 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1649 | /** |
| 1650 | * Supported types U8 and F32 with vector lengths between 1 and |
| 1651 | * 4. The default convolution kernel is the identity. |
| 1652 | * @param[in] rs RenderScript context |
| 1653 | * @param[in] e Element |
| 1654 | * @return new ScriptIntrinsicConvolve3x3 |
| 1655 | */ |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1656 | static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1657 | /** |
| 1658 | * Sets input for intrinsic. |
| 1659 | * @param[in] in input Allocation |
| 1660 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1661 | void setInput(sp<Allocation> in); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1662 | /** |
| 1663 | * Launches the intrinsic. |
| 1664 | * @param[in] out output Allocation |
| 1665 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1666 | void forEach(sp<Allocation> out); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1667 | /** |
| 1668 | * Sets convolution kernel. |
| 1669 | * @param[in] v float[9] of values |
| 1670 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1671 | void setCoefficients(float* v); |
| 1672 | }; |
| 1673 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1674 | /** |
| 1675 | * Intrinsic for applying a 5x5 convolve to an allocation. |
| 1676 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1677 | class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic { |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1678 | private: |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1679 | ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1680 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1681 | /** |
| 1682 | * Supported types U8 and F32 with vector lengths between 1 and |
| 1683 | * 4. The default convolution kernel is the identity. |
| 1684 | * @param[in] rs RenderScript context |
| 1685 | * @param[in] e Element |
| 1686 | * @return new ScriptIntrinsicConvolve5x5 |
| 1687 | */ |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1688 | static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1689 | /** |
| 1690 | * Sets input for intrinsic. |
| 1691 | * @param[in] in input Allocation |
| 1692 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1693 | void setInput(sp<Allocation> in); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1694 | /** |
| 1695 | * Launches the intrinsic. |
| 1696 | * @param[in] out output Allocation |
| 1697 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1698 | void forEach(sp<Allocation> out); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1699 | /** |
| 1700 | * Sets convolution kernel. |
| 1701 | * @param[in] v float[25] of values |
| 1702 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1703 | void setCoefficients(float* v); |
| 1704 | }; |
| 1705 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1706 | /** |
| 1707 | * Intrinsic for computing a histogram. |
| 1708 | */ |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1709 | class ScriptIntrinsicHistogram : public ScriptIntrinsic { |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1710 | private: |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1711 | ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 1712 | sp<Allocation> mOut; |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1713 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1714 | /** |
| 1715 | * Create an intrinsic for calculating the histogram of an uchar |
| 1716 | * or uchar4 image. |
| 1717 | * |
| 1718 | * Supported elements types are U8_4, U8_3, U8_2, and U8. |
| 1719 | * |
| 1720 | * @param[in] rs The RenderScript context |
| 1721 | * @param[in] e Element type for inputs |
| 1722 | * |
| 1723 | * @return ScriptIntrinsicHistogram |
| 1724 | */ |
| Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 1725 | static sp<ScriptIntrinsicHistogram> create(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1726 | /** |
| 1727 | * Set the output of the histogram. 32 bit integer types are |
| 1728 | * supported. |
| 1729 | * |
| 1730 | * @param[in] aout The output allocation |
| 1731 | */ |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1732 | void setOutput(sp<Allocation> aout); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1733 | /** |
| 1734 | * Set the coefficients used for the dot product calculation. The |
| 1735 | * default is {0.299f, 0.587f, 0.114f, 0.f}. |
| 1736 | * |
| 1737 | * Coefficients must be >= 0 and sum to 1.0 or less. |
| 1738 | * |
| 1739 | * @param[in] r Red coefficient |
| 1740 | * @param[in] g Green coefficient |
| 1741 | * @param[in] b Blue coefficient |
| 1742 | * @param[in] a Alpha coefficient |
| 1743 | */ |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1744 | void setDotCoefficients(float r, float g, float b, float a); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1745 | /** |
| 1746 | * Process an input buffer and place the histogram into the output |
| 1747 | * allocation. The output allocation may be a narrower vector size |
| 1748 | * than the input. In this case the vector size of the output is |
| 1749 | * used to determine how many of the input channels are used in |
| 1750 | * the computation. This is useful if you have an RGBA input |
| 1751 | * buffer but only want the histogram for RGB. |
| 1752 | * |
| 1753 | * 1D and 2D input allocations are supported. |
| 1754 | * |
| 1755 | * @param[in] ain The input image |
| 1756 | */ |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1757 | void forEach(sp<Allocation> ain); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1758 | /** |
| 1759 | * Process an input buffer and place the histogram into the output |
| 1760 | * allocation. The dot product of the input channel and the |
| 1761 | * coefficients from 'setDotCoefficients' are used to calculate |
| 1762 | * the output values. |
| 1763 | * |
| 1764 | * 1D and 2D input allocations are supported. |
| 1765 | * |
| 1766 | * @param ain The input image |
| 1767 | */ |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1768 | void forEach_dot(sp<Allocation> ain); |
| 1769 | }; |
| 1770 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1771 | /** |
| 1772 | * Intrinsic for applying a per-channel lookup table. Each channel of |
| 1773 | * the input has an independant lookup table. The tables are 256 |
| 1774 | * entries in size and can cover the full value range of U8_4. |
| 1775 | **/ |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1776 | class ScriptIntrinsicLUT : public ScriptIntrinsic { |
| 1777 | private: |
| 1778 | sp<Allocation> LUT; |
| 1779 | bool mDirty; |
| 1780 | unsigned char mCache[1024]; |
| Tim Murray | 2acce99 | 2013-08-28 14:23:31 -0700 | [diff] [blame] | 1781 | 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] | 1782 | ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e); |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1783 | |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1784 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1785 | /** |
| 1786 | * Supported elements types are U8_4. |
| 1787 | * |
| 1788 | * The defaults tables are identity. |
| 1789 | * |
| 1790 | * @param[in] rs The RenderScript context |
| 1791 | * @param[in] e Element type for intputs and outputs |
| 1792 | * |
| 1793 | * @return ScriptIntrinsicLUT |
| 1794 | */ |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1795 | static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1796 | /** |
| 1797 | * Invoke the kernel and apply the lookup to each cell of ain and |
| 1798 | * copy to aout. |
| 1799 | * |
| 1800 | * @param[in] ain Input allocation |
| 1801 | * @param[in] aout Output allocation |
| 1802 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1803 | void forEach(sp<Allocation> ain, sp<Allocation> aout); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1804 | /** |
| 1805 | * Sets entries in LUT for the red channel. |
| 1806 | * @param[in] base base of region to update |
| 1807 | * @param[in] length length of region to update |
| 1808 | * @param[in] lutValues LUT values to use |
| 1809 | */ |
| Tim Murray | 2acce99 | 2013-08-28 14:23:31 -0700 | [diff] [blame] | 1810 | void setRed(unsigned char base, unsigned int length, unsigned char* lutValues); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1811 | /** |
| 1812 | * Sets entries in LUT for the green channel. |
| 1813 | * @param[in] base base of region to update |
| 1814 | * @param[in] length length of region to update |
| 1815 | * @param[in] lutValues LUT values to use |
| 1816 | */ |
| Tim Murray | 2acce99 | 2013-08-28 14:23:31 -0700 | [diff] [blame] | 1817 | void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1818 | /** |
| 1819 | * Sets entries in LUT for the blue channel. |
| 1820 | * @param[in] base base of region to update |
| 1821 | * @param[in] length length of region to update |
| 1822 | * @param[in] lutValues LUT values to use |
| 1823 | */ |
| Tim Murray | 2acce99 | 2013-08-28 14:23:31 -0700 | [diff] [blame] | 1824 | void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1825 | /** |
| 1826 | * Sets entries in LUT for the alpha channel. |
| 1827 | * @param[in] base base of region to update |
| 1828 | * @param[in] length length of region to update |
| 1829 | * @param[in] lutValues LUT values to use |
| 1830 | */ |
| Tim Murray | 2acce99 | 2013-08-28 14:23:31 -0700 | [diff] [blame] | 1831 | void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues); |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1832 | virtual ~ScriptIntrinsicLUT(); |
| 1833 | }; |
| 1834 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1835 | /** |
| 1836 | * Intrinsic for converting an Android YUV buffer to RGB. |
| 1837 | * |
| 1838 | * The input allocation should be supplied in a supported YUV format |
| 1839 | * as a YUV element Allocation. The output is RGBA; the alpha channel |
| 1840 | * will be set to 255. |
| 1841 | */ |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1842 | class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic { |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1843 | private: |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1844 | ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1845 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1846 | /** |
| 1847 | * Create an intrinsic for converting YUV to RGB. |
| 1848 | * |
| 1849 | * Supported elements types are U8_4. |
| 1850 | * |
| 1851 | * @param[in] rs The RenderScript context |
| 1852 | * @param[in] e Element type for output |
| 1853 | * |
| 1854 | * @return ScriptIntrinsicYuvToRGB |
| 1855 | */ |
| Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 1856 | static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1857 | /** |
| 1858 | * Set the input YUV allocation. |
| 1859 | * |
| 1860 | * @param[in] ain The input allocation. |
| 1861 | */ |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1862 | void setInput(sp<Allocation> in); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1863 | |
| 1864 | /** |
| 1865 | * Convert the image to RGB. |
| 1866 | * |
| 1867 | * @param[in] aout Output allocation. Must match creation element |
| 1868 | * type. |
| 1869 | */ |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1870 | void forEach(sp<Allocation> out); |
| Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 1871 | |
| 1872 | }; |
| Tim Murray | b27b181 | 2013-08-05 14:00:40 -0700 | [diff] [blame] | 1873 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1874 | /** |
| 1875 | * Sampler object that defines how Allocations can be read as textures |
| 1876 | * within a kernel. Samplers are used in conjunction with the rsSample |
| 1877 | * runtime function to return values from normalized coordinates. |
| 1878 | * |
| 1879 | * Any Allocation used with a Sampler must have been created with |
| 1880 | * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an |
| 1881 | * Allocation that was not created with |
| 1882 | * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined. |
| 1883 | **/ |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 1884 | class Sampler : public BaseObj { |
| 1885 | private: |
| 1886 | Sampler(sp<RS> rs, void* id); |
| 1887 | RsSamplerValue mMin; |
| 1888 | RsSamplerValue mMag; |
| 1889 | RsSamplerValue mWrapS; |
| 1890 | RsSamplerValue mWrapT; |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 1891 | float mAniso; |
| 1892 | |
| 1893 | public: |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1894 | /** |
| 1895 | * Creates a non-standard Sampler. |
| 1896 | * @param[in] rs RenderScript context |
| 1897 | * @param[in] min minification |
| 1898 | * @param[in] mag magnification |
| 1899 | * @param[in] wrapS S wrapping mode |
| 1900 | * @param[in] wrapT T wrapping mode |
| 1901 | * @param[in] anisotropy anisotropy setting |
| 1902 | */ |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 1903 | static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy); |
| 1904 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1905 | /** |
| 1906 | * @return minification setting for the sampler |
| 1907 | */ |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 1908 | RsSamplerValue getMinification(); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1909 | /** |
| 1910 | * @return magnification setting for the sampler |
| 1911 | */ |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 1912 | RsSamplerValue getMagnification(); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1913 | /** |
| 1914 | * @return S wrapping mode for the sampler |
| 1915 | */ |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 1916 | RsSamplerValue getWrapS(); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1917 | /** |
| 1918 | * @return T wrapping mode for the sampler |
| 1919 | */ |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 1920 | RsSamplerValue getWrapT(); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1921 | /** |
| 1922 | * @return anisotropy setting for the sampler |
| 1923 | */ |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 1924 | float getAnisotropy(); |
| 1925 | |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1926 | /** |
| 1927 | * Retrieve a sampler with min and mag set to nearest and wrap modes set to |
| 1928 | * clamp. |
| 1929 | * |
| 1930 | * @param rs Context to which the sampler will belong. |
| 1931 | * |
| 1932 | * @return Sampler |
| 1933 | */ |
| Stephen Hines | 8a588bd | 2013-11-26 15:38:31 -0800 | [diff] [blame] | 1934 | static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1935 | /** |
| 1936 | * Retrieve a sampler with min and mag set to linear and wrap modes set to |
| 1937 | * clamp. |
| 1938 | * |
| 1939 | * @param rs Context to which the sampler will belong. |
| 1940 | * |
| 1941 | * @return Sampler |
| 1942 | */ |
| Stephen Hines | 8a588bd | 2013-11-26 15:38:31 -0800 | [diff] [blame] | 1943 | static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1944 | /** |
| 1945 | * Retrieve a sampler with mag set to linear, min linear mipmap linear, and |
| 1946 | * wrap modes set to clamp. |
| 1947 | * |
| 1948 | * @param rs Context to which the sampler will belong. |
| 1949 | * |
| 1950 | * @return Sampler |
| 1951 | */ |
| Stephen Hines | 8a588bd | 2013-11-26 15:38:31 -0800 | [diff] [blame] | 1952 | static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1953 | /** |
| 1954 | * Retrieve a sampler with min and mag set to nearest and wrap modes set to |
| 1955 | * wrap. |
| 1956 | * |
| 1957 | * @param rs Context to which the sampler will belong. |
| 1958 | * |
| 1959 | * @return Sampler |
| 1960 | */ |
| Stephen Hines | 8a588bd | 2013-11-26 15:38:31 -0800 | [diff] [blame] | 1961 | static sp<const Sampler> WRAP_NEAREST(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1962 | /** |
| 1963 | * Retrieve a sampler with min and mag set to linear and wrap modes set to |
| 1964 | * wrap. |
| 1965 | * |
| 1966 | * @param rs Context to which the sampler will belong. |
| 1967 | * |
| 1968 | * @return Sampler |
| 1969 | */ |
| Stephen Hines | 8a588bd | 2013-11-26 15:38:31 -0800 | [diff] [blame] | 1970 | static sp<const Sampler> WRAP_LINEAR(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1971 | /** |
| 1972 | * Retrieve a sampler with mag set to linear, min linear mipmap linear, and |
| 1973 | * wrap modes set to wrap. |
| 1974 | * |
| 1975 | * @param rs Context to which the sampler will belong. |
| 1976 | * |
| 1977 | * @return Sampler |
| 1978 | */ |
| Stephen Hines | 8a588bd | 2013-11-26 15:38:31 -0800 | [diff] [blame] | 1979 | static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1980 | /** |
| 1981 | * Retrieve a sampler with min and mag set to nearest and wrap modes set to |
| 1982 | * mirrored repeat. |
| 1983 | * |
| 1984 | * @param rs Context to which the sampler will belong. |
| 1985 | * |
| 1986 | * @return Sampler |
| 1987 | */ |
| Stephen Hines | 8a588bd | 2013-11-26 15:38:31 -0800 | [diff] [blame] | 1988 | static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1989 | /** |
| 1990 | * Retrieve a sampler with min and mag set to linear and wrap modes set to |
| 1991 | * mirrored repeat. |
| 1992 | * |
| 1993 | * @param rs Context to which the sampler will belong. |
| 1994 | * |
| 1995 | * @return Sampler |
| 1996 | */ |
| Stephen Hines | 8a588bd | 2013-11-26 15:38:31 -0800 | [diff] [blame] | 1997 | static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs); |
| Tim Murray | 75e877d | 2013-09-11 14:45:20 -0700 | [diff] [blame] | 1998 | /** |
| 1999 | * Retrieve a sampler with min and mag set to linear and wrap modes set to |
| 2000 | * mirrored repeat. |
| 2001 | * |
| 2002 | * @param rs Context to which the sampler will belong. |
| 2003 | * |
| 2004 | * @return Sampler |
| 2005 | */ |
| Stephen Hines | 8a588bd | 2013-11-26 15:38:31 -0800 | [diff] [blame] | 2006 | static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs); |
| Tim Murray | 729b6fe | 2013-07-23 16:20:42 -0700 | [diff] [blame] | 2007 | |
| 2008 | }; |
| 2009 | |
| Stephen Hines | d10412f | 2013-08-29 18:27:21 -0700 | [diff] [blame] | 2010 | class Byte2 { |
| 2011 | public: |
| 2012 | int8_t x, y; |
| 2013 | |
| 2014 | Byte2(int8_t initX, int8_t initY) |
| 2015 | : x(initX), y(initY) {} |
| 2016 | Byte2() : x(0), y(0) {} |
| 2017 | }; |
| 2018 | |
| 2019 | class Byte3 { |
| 2020 | public: |
| 2021 | int8_t x, y, z; |
| 2022 | |
| 2023 | Byte3(int8_t initX, int8_t initY, int8_t initZ) |
| 2024 | : x(initX), y(initY), z(initZ) {} |
| 2025 | Byte3() : x(0), y(0), z(0) {} |
| 2026 | }; |
| 2027 | |
| 2028 | class Byte4 { |
| 2029 | public: |
| 2030 | int8_t x, y, z, w; |
| 2031 | |
| 2032 | Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW) |
| 2033 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 2034 | Byte4() : x(0), y(0), z(0), w(0) {} |
| 2035 | }; |
| 2036 | |
| 2037 | class UByte2 { |
| 2038 | public: |
| 2039 | uint8_t x, y; |
| 2040 | |
| 2041 | UByte2(uint8_t initX, uint8_t initY) |
| 2042 | : x(initX), y(initY) {} |
| 2043 | UByte2() : x(0), y(0) {} |
| 2044 | }; |
| 2045 | |
| 2046 | class UByte3 { |
| 2047 | public: |
| 2048 | uint8_t x, y, z; |
| 2049 | |
| 2050 | UByte3(uint8_t initX, uint8_t initY, uint8_t initZ) |
| 2051 | : x(initX), y(initY), z(initZ) {} |
| 2052 | UByte3() : x(0), y(0), z(0) {} |
| 2053 | }; |
| 2054 | |
| 2055 | class UByte4 { |
| 2056 | public: |
| 2057 | uint8_t x, y, z, w; |
| 2058 | |
| 2059 | UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW) |
| 2060 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 2061 | UByte4() : x(0), y(0), z(0), w(0) {} |
| 2062 | }; |
| 2063 | |
| 2064 | class Short2 { |
| 2065 | public: |
| 2066 | short x, y; |
| 2067 | |
| 2068 | Short2(short initX, short initY) |
| 2069 | : x(initX), y(initY) {} |
| 2070 | Short2() : x(0), y(0) {} |
| 2071 | }; |
| 2072 | |
| 2073 | class Short3 { |
| 2074 | public: |
| 2075 | short x, y, z; |
| 2076 | |
| 2077 | Short3(short initX, short initY, short initZ) |
| 2078 | : x(initX), y(initY), z(initZ) {} |
| 2079 | Short3() : x(0), y(0), z(0) {} |
| 2080 | }; |
| 2081 | |
| 2082 | class Short4 { |
| 2083 | public: |
| 2084 | short x, y, z, w; |
| 2085 | |
| 2086 | Short4(short initX, short initY, short initZ, short initW) |
| 2087 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 2088 | Short4() : x(0), y(0), z(0), w(0) {} |
| 2089 | }; |
| 2090 | |
| 2091 | class UShort2 { |
| 2092 | public: |
| 2093 | uint16_t x, y; |
| 2094 | |
| 2095 | UShort2(uint16_t initX, uint16_t initY) |
| 2096 | : x(initX), y(initY) {} |
| 2097 | UShort2() : x(0), y(0) {} |
| 2098 | }; |
| 2099 | |
| 2100 | class UShort3 { |
| 2101 | public: |
| 2102 | uint16_t x, y, z; |
| 2103 | |
| 2104 | UShort3(uint16_t initX, uint16_t initY, uint16_t initZ) |
| 2105 | : x(initX), y(initY), z(initZ) {} |
| 2106 | UShort3() : x(0), y(0), z(0) {} |
| 2107 | }; |
| 2108 | |
| 2109 | class UShort4 { |
| 2110 | public: |
| 2111 | uint16_t x, y, z, w; |
| 2112 | |
| 2113 | UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW) |
| 2114 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 2115 | UShort4() : x(0), y(0), z(0), w(0) {} |
| 2116 | }; |
| 2117 | |
| 2118 | class Int2 { |
| 2119 | public: |
| 2120 | int x, y; |
| 2121 | |
| 2122 | Int2(int initX, int initY) |
| 2123 | : x(initX), y(initY) {} |
| 2124 | Int2() : x(0), y(0) {} |
| 2125 | }; |
| 2126 | |
| 2127 | class Int3 { |
| 2128 | public: |
| 2129 | int x, y, z; |
| 2130 | |
| 2131 | Int3(int initX, int initY, int initZ) |
| 2132 | : x(initX), y(initY), z(initZ) {} |
| 2133 | Int3() : x(0), y(0), z(0) {} |
| 2134 | }; |
| 2135 | |
| 2136 | class Int4 { |
| 2137 | public: |
| 2138 | int x, y, z, w; |
| 2139 | |
| 2140 | Int4(int initX, int initY, int initZ, int initW) |
| 2141 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 2142 | Int4() : x(0), y(0), z(0), w(0) {} |
| 2143 | }; |
| 2144 | |
| 2145 | class UInt2 { |
| 2146 | public: |
| 2147 | uint32_t x, y; |
| 2148 | |
| 2149 | UInt2(uint32_t initX, uint32_t initY) |
| 2150 | : x(initX), y(initY) {} |
| 2151 | UInt2() : x(0), y(0) {} |
| 2152 | }; |
| 2153 | |
| 2154 | class UInt3 { |
| 2155 | public: |
| 2156 | uint32_t x, y, z; |
| 2157 | |
| 2158 | UInt3(uint32_t initX, uint32_t initY, uint32_t initZ) |
| 2159 | : x(initX), y(initY), z(initZ) {} |
| 2160 | UInt3() : x(0), y(0), z(0) {} |
| 2161 | }; |
| 2162 | |
| 2163 | class UInt4 { |
| 2164 | public: |
| 2165 | uint32_t x, y, z, w; |
| 2166 | |
| 2167 | UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW) |
| 2168 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 2169 | UInt4() : x(0), y(0), z(0), w(0) {} |
| 2170 | }; |
| 2171 | |
| 2172 | class Long2 { |
| 2173 | public: |
| 2174 | int64_t x, y; |
| 2175 | |
| 2176 | Long2(int64_t initX, int64_t initY) |
| 2177 | : x(initX), y(initY) {} |
| 2178 | Long2() : x(0), y(0) {} |
| 2179 | }; |
| 2180 | |
| 2181 | class Long3 { |
| 2182 | public: |
| 2183 | int64_t x, y, z; |
| 2184 | |
| 2185 | Long3(int64_t initX, int64_t initY, int64_t initZ) |
| 2186 | : x(initX), y(initY), z(initZ) {} |
| 2187 | Long3() : x(0), y(0), z(0) {} |
| 2188 | }; |
| 2189 | |
| 2190 | class Long4 { |
| 2191 | public: |
| 2192 | int64_t x, y, z, w; |
| 2193 | |
| 2194 | Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW) |
| 2195 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 2196 | Long4() : x(0), y(0), z(0), w(0) {} |
| 2197 | }; |
| 2198 | |
| 2199 | class ULong2 { |
| 2200 | public: |
| 2201 | uint64_t x, y; |
| 2202 | |
| 2203 | ULong2(uint64_t initX, uint64_t initY) |
| 2204 | : x(initX), y(initY) {} |
| 2205 | ULong2() : x(0), y(0) {} |
| 2206 | }; |
| 2207 | |
| 2208 | class ULong3 { |
| 2209 | public: |
| 2210 | uint64_t x, y, z; |
| 2211 | |
| 2212 | ULong3(uint64_t initX, uint64_t initY, uint64_t initZ) |
| 2213 | : x(initX), y(initY), z(initZ) {} |
| 2214 | ULong3() : x(0), y(0), z(0) {} |
| 2215 | }; |
| 2216 | |
| 2217 | class ULong4 { |
| 2218 | public: |
| 2219 | uint64_t x, y, z, w; |
| 2220 | |
| 2221 | ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW) |
| 2222 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 2223 | ULong4() : x(0), y(0), z(0), w(0) {} |
| 2224 | }; |
| 2225 | |
| 2226 | class Float2 { |
| 2227 | public: |
| 2228 | float x, y; |
| 2229 | |
| 2230 | Float2(float initX, float initY) |
| 2231 | : x(initX), y(initY) {} |
| 2232 | Float2() : x(0), y(0) {} |
| 2233 | }; |
| 2234 | |
| 2235 | class Float3 { |
| 2236 | public: |
| 2237 | float x, y, z; |
| 2238 | |
| 2239 | Float3(float initX, float initY, float initZ) |
| 2240 | : x(initX), y(initY), z(initZ) {} |
| 2241 | Float3() : x(0.f), y(0.f), z(0.f) {} |
| 2242 | }; |
| 2243 | |
| 2244 | class Float4 { |
| 2245 | public: |
| 2246 | float x, y, z, w; |
| 2247 | |
| 2248 | Float4(float initX, float initY, float initZ, float initW) |
| 2249 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 2250 | Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {} |
| 2251 | }; |
| 2252 | |
| 2253 | class Double2 { |
| 2254 | public: |
| 2255 | double x, y; |
| 2256 | |
| 2257 | Double2(double initX, double initY) |
| 2258 | : x(initX), y(initY) {} |
| 2259 | Double2() : x(0), y(0) {} |
| 2260 | }; |
| 2261 | |
| 2262 | class Double3 { |
| 2263 | public: |
| 2264 | double x, y, z; |
| 2265 | |
| 2266 | Double3(double initX, double initY, double initZ) |
| 2267 | : x(initX), y(initY), z(initZ) {} |
| 2268 | Double3() : x(0), y(0), z(0) {} |
| 2269 | }; |
| 2270 | |
| 2271 | class Double4 { |
| 2272 | public: |
| 2273 | double x, y, z, w; |
| 2274 | |
| 2275 | Double4(double initX, double initY, double initZ, double initW) |
| 2276 | : x(initX), y(initY), z(initZ), w(initW) {} |
| 2277 | Double4() : x(0), y(0), z(0), w(0) {} |
| 2278 | }; |
| 2279 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 2280 | } |
| Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 2281 | |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | #endif |