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