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