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