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