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