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