blob: d834ef5169aeb4922b68dcfbe2e62fbe4b60e4c9 [file] [log] [blame]
Tim Murray84bf2b82012-10-31 16:03:16 -07001/*
Tim Murray89daad62013-07-29 14:30:02 -07002 * Copyright (C) 2013 The Android Open Source Project
Tim Murray84bf2b82012-10-31 16:03:16 -07003 *
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 Murray89daad62013-07-29 14:30:02 -070020#include "rsDefines.h"
Tim Murray89daad62013-07-29 14:30:02 -070021#include "util/RefBase.h"
Tim Murraya4230962013-07-17 16:50:10 -070022
Tim Murray8c24cd62014-04-10 18:04:39 -070023#include <pthread.h>
Tim Murray89daad62013-07-29 14:30:02 -070024
Miao Wang09d2dd22015-03-18 20:09:20 -070025
Tim Murray75e877d2013-09-11 14:45:20 -070026/**
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 Murray96267c22013-02-12 11:25:12 -080030#define RS_CPU_ALLOCATION_ALIGNMENT 16
31
Jason Sams66f0a162014-11-11 13:46:38 -080032struct dispatchTable;
33
Tim Murray84bf2b82012-10-31 16:03:16 -070034namespace android {
Miao Wang09d2dd22015-03-18 20:09:20 -070035class Surface;
36
Tim Murray9eb7f4b2012-11-16 14:02:18 -080037namespace RSC {
Tim Murray84bf2b82012-10-31 16:03:16 -070038
Jason Sams66f0a162014-11-11 13:46:38 -080039
Tim Murray84bf2b82012-10-31 16:03:16 -070040typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText);
41typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen);
42
43class RS;
44class BaseObj;
45class Element;
46class Type;
47class Allocation;
48class Script;
49class ScriptC;
Tim Murray729b6fe2013-07-23 16:20:42 -070050class Sampler;
Tim Murray84bf2b82012-10-31 16:03:16 -070051
Tim Murray75e877d2013-09-11 14:45:20 -070052/**
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 Murray21fa7a02013-08-15 16:25:03 -070057 enum RSError {
Tim Murray75e877d2013-09-11 14:45:20 -070058 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 Murray21fa7a02013-08-15 16:25:03 -070063 RS_ERROR_MAX = 9999
64
65 };
66
Tim Murray75e877d2013-09-11 14:45:20 -070067 /**
68 * YUV formats supported by the RenderScript API.
69 */
Tim Murrayeb4426d2013-08-27 15:30:16 -070070 enum RSYuvFormat {
Tim Murray75e877d2013-09-11 14:45:20 -070071 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 Murrayeb4426d2013-08-27 15:30:16 -070074 RS_YUV_MAX = 3
75 };
76
Tim Murray75e877d2013-09-11 14:45:20 -070077 /**
78 * Flags that can control RenderScript behavior on a per-context level.
79 */
Tim Murray84e3dea2013-09-09 16:12:51 -070080 enum RSInitFlags {
Tim Murray75e877d2013-09-11 14:45:20 -070081 RS_INIT_SYNCHRONOUS = 1, ///< All RenderScript calls will be synchronous. May reduce latency.
82 RS_INIT_LOW_LATENCY = 2, ///< Prefer low latency devices over potentially higher throughput devices.
Stephen McGroartyd5164d52015-05-08 15:31:49 +010083 // Bitflag 4 is reserved for the context flag low power
84 RS_INIT_WAIT_FOR_ATTACH = 8, ///< Kernel execution will hold to give time for a debugger to be attached
verena beckhamf5029802015-05-22 16:51:42 +010085 RS_INIT_OPT_LEVEL_0 = 16, ///< Use the -O0 option to set the optimization level to zero when calling the bcc compiler.
86 RS_INIT_MAX = 32
Tim Murray84e3dea2013-09-09 16:12:51 -070087 };
88
Tim Murray75e877d2013-09-11 14:45:20 -070089 /**
90 * The RenderScript context. This class controls initialization, resource management, and teardown.
91 */
Tim Murray89daad62013-07-29 14:30:02 -070092 class RS : public android::RSC::LightRefBase<RS> {
Tim Murray84bf2b82012-10-31 16:03:16 -070093
94 public:
95 RS();
96 virtual ~RS();
97
Tim Murray75e877d2013-09-11 14:45:20 -070098 /**
99 * Initializes a RenderScript context. A context must be initialized before it can be used.
Tim Murraycaf41262013-12-13 12:54:37 -0800100 * @param[in] name Directory name to be used by this context. This should be equivalent to
101 * Context.getCacheDir().
Tim Murray75e877d2013-09-11 14:45:20 -0700102 * @param[in] flags Optional flags for this context.
103 * @return true on success
104 */
Miao Wangbc10dff2015-04-03 17:44:55 -0700105 bool init(const char * name, uint32_t flags = 0);
Tim Murray84bf2b82012-10-31 16:03:16 -0700106
Tim Murray75e877d2013-09-11 14:45:20 -0700107 /**
108 * Sets the error handler function for this context. This error handler is
109 * called whenever an error is set.
110 *
111 * @param[in] func Error handler function
112 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700113 void setErrorHandler(ErrorHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700114
115 /**
116 * Returns the current error handler function for this context.
117 *
118 * @return pointer to current error handler function or NULL if not set
119 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700120 ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
121
Tim Murray75e877d2013-09-11 14:45:20 -0700122 /**
123 * Sets the message handler function for this context. This message handler
124 * is called whenever a message is sent from a RenderScript kernel.
125 *
126 * @param[in] func Message handler function
127 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700128 void setMessageHandler(MessageHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700129
130 /**
131 * Returns the current message handler function for this context.
132 *
133 * @return pointer to current message handler function or NULL if not set
134 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700135 MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
136
Tim Murray75e877d2013-09-11 14:45:20 -0700137 /**
138 * Returns current status for the context.
139 *
140 * @return current error
141 */
Tim Murray10913a52013-08-20 17:19:47 -0700142 RSError getError();
Tim Murray84bf2b82012-10-31 16:03:16 -0700143
Tim Murray75e877d2013-09-11 14:45:20 -0700144 /**
145 * Waits for any currently running asynchronous operations to finish. This
146 * should only be used for performance testing and timing.
147 */
Tim Murraybaca6c32012-11-14 16:51:46 -0800148 void finish();
149
Tim Murray75e877d2013-09-11 14:45:20 -0700150 RsContext getContext() { return mContext; }
151 void throwError(RSError error, const char *errMsg);
152
Tim Murraya4230962013-07-17 16:50:10 -0700153 static dispatchTable* dispatch;
154
Tim Murray84bf2b82012-10-31 16:03:16 -0700155 private:
Tim Murray4a92d122013-07-22 10:56:18 -0700156 static bool usingNative;
Tim Murraya4230962013-07-17 16:50:10 -0700157 static bool initDispatch(int targetApi);
158
Miao Wangbc10dff2015-04-03 17:44:55 -0700159 bool init(const char * name, int targetApi, uint32_t flags);
Tim Murray84bf2b82012-10-31 16:03:16 -0700160 static void * threadProc(void *);
161
162 static bool gInitialized;
163 static pthread_mutex_t gInitMutex;
164
165 pthread_t mMessageThreadId;
166 pid_t mNativeMessageThreadId;
167 bool mMessageRun;
168
169 RsDevice mDev;
170 RsContext mContext;
Tim Murray21fa7a02013-08-15 16:25:03 -0700171 RSError mCurrentError;
Tim Murray84bf2b82012-10-31 16:03:16 -0700172
173 ErrorHandlerFunc_t mErrorFunc;
174 MessageHandlerFunc_t mMessageFunc;
Tim Murraya4230962013-07-17 16:50:10 -0700175 bool mInit;
Tim Murray84bf2b82012-10-31 16:03:16 -0700176
Miao Wangbc10dff2015-04-03 17:44:55 -0700177 char mCacheDir[PATH_MAX+1];
178 uint32_t mCacheDirLen;
Tim Murraycaf41262013-12-13 12:54:37 -0800179
Tim Murray84bf2b82012-10-31 16:03:16 -0700180 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700181 sp<const Element> U8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700182 sp<const Element> U8_2;
183 sp<const Element> U8_3;
184 sp<const Element> U8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700185 sp<const Element> I8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700186 sp<const Element> I8_2;
187 sp<const Element> I8_3;
188 sp<const Element> I8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700189 sp<const Element> U16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700190 sp<const Element> U16_2;
191 sp<const Element> U16_3;
192 sp<const Element> U16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700193 sp<const Element> I16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700194 sp<const Element> I16_2;
195 sp<const Element> I16_3;
196 sp<const Element> I16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700197 sp<const Element> U32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700198 sp<const Element> U32_2;
199 sp<const Element> U32_3;
200 sp<const Element> U32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700201 sp<const Element> I32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700202 sp<const Element> I32_2;
203 sp<const Element> I32_3;
204 sp<const Element> I32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700205 sp<const Element> U64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700206 sp<const Element> U64_2;
207 sp<const Element> U64_3;
208 sp<const Element> U64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700209 sp<const Element> I64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700210 sp<const Element> I64_2;
211 sp<const Element> I64_3;
212 sp<const Element> I64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700213 sp<const Element> F32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700214 sp<const Element> F32_2;
215 sp<const Element> F32_3;
216 sp<const Element> F32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700217 sp<const Element> F64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700218 sp<const Element> F64_2;
219 sp<const Element> F64_3;
220 sp<const Element> F64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700221 sp<const Element> BOOLEAN;
Tim Murray84bf2b82012-10-31 16:03:16 -0700222
Tim Murray89daad62013-07-29 14:30:02 -0700223 sp<const Element> ELEMENT;
224 sp<const Element> TYPE;
225 sp<const Element> ALLOCATION;
226 sp<const Element> SAMPLER;
227 sp<const Element> SCRIPT;
228 sp<const Element> MESH;
229 sp<const Element> PROGRAM_FRAGMENT;
230 sp<const Element> PROGRAM_VERTEX;
231 sp<const Element> PROGRAM_RASTER;
232 sp<const Element> PROGRAM_STORE;
Tim Murray84bf2b82012-10-31 16:03:16 -0700233
Tim Murray89daad62013-07-29 14:30:02 -0700234 sp<const Element> A_8;
235 sp<const Element> RGB_565;
236 sp<const Element> RGB_888;
237 sp<const Element> RGBA_5551;
238 sp<const Element> RGBA_4444;
239 sp<const Element> RGBA_8888;
Tim Murray84bf2b82012-10-31 16:03:16 -0700240
Tim Murrayeb4426d2013-08-27 15:30:16 -0700241 sp<const Element> YUV;
Tim Murray84bf2b82012-10-31 16:03:16 -0700242
Tim Murray89daad62013-07-29 14:30:02 -0700243 sp<const Element> MATRIX_4X4;
244 sp<const Element> MATRIX_3X3;
245 sp<const Element> MATRIX_2X2;
Tim Murray84bf2b82012-10-31 16:03:16 -0700246 } mElements;
247
Tim Murray729b6fe2013-07-23 16:20:42 -0700248 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700249 sp<const Sampler> CLAMP_NEAREST;
250 sp<const Sampler> CLAMP_LINEAR;
251 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
252 sp<const Sampler> WRAP_NEAREST;
253 sp<const Sampler> WRAP_LINEAR;
254 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
255 sp<const Sampler> MIRRORED_REPEAT_NEAREST;
256 sp<const Sampler> MIRRORED_REPEAT_LINEAR;
257 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Tim Murray729b6fe2013-07-23 16:20:42 -0700258 } mSamplers;
259 friend class Sampler;
260 friend class Element;
Tim Murraycaf41262013-12-13 12:54:37 -0800261 friend class ScriptC;
Tim Murray84bf2b82012-10-31 16:03:16 -0700262};
263
Tim Murray75e877d2013-09-11 14:45:20 -0700264 /**
265 * Base class for all RenderScript objects. Not for direct use by developers.
266 */
Tim Murray89daad62013-07-29 14:30:02 -0700267class BaseObj : public android::RSC::LightRefBase<BaseObj> {
268public:
269 void * getID() const;
270 virtual ~BaseObj();
271 virtual void updateFromNative();
272 virtual bool equals(sp<const BaseObj> obj);
273
Tim Murray84bf2b82012-10-31 16:03:16 -0700274protected:
275 void *mID;
Tim Murray35609072013-12-03 11:36:03 -0800276 RS* mRS;
Miao Wangbc10dff2015-04-03 17:44:55 -0700277 const char * mName;
Tim Murray84bf2b82012-10-31 16:03:16 -0700278
279 BaseObj(void *id, sp<RS> rs);
280 void checkValid();
281
282 static void * getObjID(sp<const BaseObj> o);
283
Tim Murray84bf2b82012-10-31 16:03:16 -0700284};
285
Tim Murray75e877d2013-09-11 14:45:20 -0700286 /**
287 * This class provides the primary method through which data is passed to and
288 * from RenderScript kernels. An Allocation provides the backing store for a
289 * given Type.
290 *
291 * An Allocation also contains a set of usage flags that denote how the
292 * Allocation could be used. For example, an Allocation may have usage flags
293 * specifying that it can be used from a script as well as input to a
294 * Sampler. A developer must synchronize across these different usages using
295 * syncAll(int) in order to ensure that different users of the Allocation have
296 * a consistent view of memory. For example, in the case where an Allocation is
297 * used as the output of one kernel and as Sampler input in a later kernel, a
298 * developer must call syncAll(RS_ALLOCATION_USAGE_SCRIPT) prior to launching the
299 * second kernel to ensure correctness.
300 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700301class Allocation : public BaseObj {
302protected:
Tim Murray89daad62013-07-29 14:30:02 -0700303 sp<const Type> mType;
Tim Murray84bf2b82012-10-31 16:03:16 -0700304 uint32_t mUsage;
Tim Murray89daad62013-07-29 14:30:02 -0700305 sp<Allocation> mAdaptedAllocation;
Tim Murray84bf2b82012-10-31 16:03:16 -0700306
307 bool mConstrainedLOD;
308 bool mConstrainedFace;
309 bool mConstrainedY;
310 bool mConstrainedZ;
311 bool mReadAllowed;
312 bool mWriteAllowed;
Miao Wange5428e62015-03-10 15:29:40 -0700313 bool mAutoPadding;
Tim Murray84bf2b82012-10-31 16:03:16 -0700314 uint32_t mSelectedY;
315 uint32_t mSelectedZ;
316 uint32_t mSelectedLOD;
317 RsAllocationCubemapFace mSelectedFace;
318
319 uint32_t mCurrentDimX;
320 uint32_t mCurrentDimY;
321 uint32_t mCurrentDimZ;
322 uint32_t mCurrentCount;
323
324 void * getIDSafe() const;
325 void updateCacheInfo(sp<const Type> t);
326
327 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
328
Miao Wange5428e62015-03-10 15:29:40 -0700329 void validateIsInt64();
Tim Murray84bf2b82012-10-31 16:03:16 -0700330 void validateIsInt32();
331 void validateIsInt16();
332 void validateIsInt8();
333 void validateIsFloat32();
Miao Wange5428e62015-03-10 15:29:40 -0700334 void validateIsFloat64();
Tim Murray84bf2b82012-10-31 16:03:16 -0700335 void validateIsObject();
336
337 virtual void updateFromNative();
338
339 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
Tim Murray9d24ae62013-08-30 12:17:14 -0700340 void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff,
341 uint32_t w, uint32_t h, uint32_t d);
Tim Murray84bf2b82012-10-31 16:03:16 -0700342
343public:
Tim Murray75e877d2013-09-11 14:45:20 -0700344
345 /**
346 * Return Type for the allocation.
347 * @return pointer to underlying Type
348 */
Stephen Hinesa180b7d2013-08-21 12:42:13 -0700349 sp<const Type> getType() const {
Tim Murray84bf2b82012-10-31 16:03:16 -0700350 return mType;
351 }
352
Tim Murray75e877d2013-09-11 14:45:20 -0700353 /**
Miao Wange5428e62015-03-10 15:29:40 -0700354 * Enable/Disable AutoPadding for Vec3 elements.
355 *
356 * @param useAutoPadding True: enable AutoPadding; flase: disable AutoPadding
357 *
358 */
359 void setAutoPadding(bool useAutoPadding) {
360 mAutoPadding = useAutoPadding;
361 }
362
363 /**
Tim Murray75e877d2013-09-11 14:45:20 -0700364 * Propagate changes from one usage of the Allocation to other usages of the Allocation.
365 * @param[in] srcLocation source location with changes to propagate elsewhere
366 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700367 void syncAll(RsAllocationUsageType srcLocation);
Miao Wang09d2dd22015-03-18 20:09:20 -0700368
369 /**
370 * Send a buffer to the output stream. The contents of the Allocation will
371 * be undefined after this operation. This operation is only valid if
372 * USAGE_IO_OUTPUT is set on the Allocation.
373 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700374 void ioSendOutput();
Miao Wang09d2dd22015-03-18 20:09:20 -0700375
376 /**
377 * Receive the latest input into the Allocation. This operation
378 * is only valid if USAGE_IO_INPUT is set on the Allocation.
379 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700380 void ioGetInput();
381
Miao Wang09d2dd22015-03-18 20:09:20 -0700382#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
383 /**
384 * Returns the handle to a raw buffer that is being managed by the screen
385 * compositor. This operation is only valid for Allocations with USAGE_IO_INPUT.
386 * @return Surface associated with allocation
387 */
388 sp<Surface> getSurface();
389
390 /**
391 * Associate a Surface with this Allocation. This
392 * operation is only valid for Allocations with USAGE_IO_OUTPUT.
393 * @param[in] s Surface to associate with allocation
394 */
395 void setSurface(sp<Surface> s);
396#endif
397
Tim Murray75e877d2013-09-11 14:45:20 -0700398 /**
399 * Generate a mipmap chain. This is only valid if the Type of the Allocation
400 * includes mipmaps. This function will generate a complete set of mipmaps
401 * from the top level LOD and place them into the script memory space. If
402 * the Allocation is also using other memory spaces, a call to
403 * syncAll(Allocation.USAGE_SCRIPT) is required.
404 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700405 void generateMipmaps();
Tim Murray509ea5c2012-11-13 11:56:40 -0800406
Tim Murray75e877d2013-09-11 14:45:20 -0700407 /**
408 * Copy an array into part of this Allocation.
409 * @param[in] off offset of first Element to be overwritten
410 * @param[in] count number of Elements to copy
411 * @param[in] data array from which to copy
412 */
Tim Murray0b93e302012-11-15 14:56:54 -0800413 void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
Tim Murray75e877d2013-09-11 14:45:20 -0700414
415 /**
416 * Copy part of an Allocation into part of this Allocation.
417 * @param[in] off offset of first Element to be overwritten
418 * @param[in] count number of Elements to copy
419 * @param[in] data Allocation from which to copy
420 * @param[in] dataOff offset of first Element in data to copy
421 */
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800422 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700423
Tim Murray75e877d2013-09-11 14:45:20 -0700424 /**
425 * Copy an array into part of this Allocation.
426 * @param[in] off offset of first Element to be overwritten
427 * @param[in] count number of Elements to copy
428 * @param[in] data array from which to copy
429 */
Tim Murray0b93e302012-11-15 14:56:54 -0800430 void copy1DRangeTo(uint32_t off, size_t count, void *data);
431
Tim Murray75e877d2013-09-11 14:45:20 -0700432 /**
433 * Copy entire array to an Allocation.
434 * @param[in] data array from which to copy
435 */
Tim Murray0b93e302012-11-15 14:56:54 -0800436 void copy1DFrom(const void* data);
Tim Murray75e877d2013-09-11 14:45:20 -0700437
438 /**
439 * Copy entire Allocation to an array.
440 * @param[in] data destination array
441 */
Tim Murray0b93e302012-11-15 14:56:54 -0800442 void copy1DTo(void* data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800443
Tim Murray75e877d2013-09-11 14:45:20 -0700444 /**
445 * Copy from an array into a rectangular region in this Allocation. The
446 * array is assumed to be tightly packed.
447 * @param[in] xoff X offset of region to update in this Allocation
448 * @param[in] yoff Y offset of region to update in this Allocation
449 * @param[in] w Width of region to update
450 * @param[in] h Height of region to update
451 * @param[in] data Array from which to copy
452 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700453 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800454 const void *data);
Tim Murray7b3e3092012-11-16 13:32:24 -0800455
Tim Murray75e877d2013-09-11 14:45:20 -0700456 /**
457 * Copy from this Allocation into a rectangular region in an array. The
458 * array is assumed to be tightly packed.
459 * @param[in] xoff X offset of region to copy from this Allocation
460 * @param[in] yoff Y offset of region to copy from this Allocation
461 * @param[in] w Width of region to update
462 * @param[in] h Height of region to update
463 * @param[in] data destination array
464 */
Tim Murray7b3e3092012-11-16 13:32:24 -0800465 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
466 void *data);
467
Tim Murray75e877d2013-09-11 14:45:20 -0700468 /**
469 * Copy from an Allocation into a rectangular region in this Allocation.
470 * @param[in] xoff X offset of region to update in this Allocation
471 * @param[in] yoff Y offset of region to update in this Allocation
472 * @param[in] w Width of region to update
473 * @param[in] h Height of region to update
474 * @param[in] data Allocation from which to copy
475 * @param[in] dataXoff X offset of region to copy from in data
476 * @param[in] dataYoff Y offset of region to copy from in data
477 */
Tim Murray0b93e302012-11-15 14:56:54 -0800478 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
479 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700480
Tim Murray75e877d2013-09-11 14:45:20 -0700481 /**
482 * Copy from a strided array into a rectangular region in this Allocation.
483 * @param[in] xoff X offset of region to update in this Allocation
484 * @param[in] yoff Y offset of region to update in this Allocation
485 * @param[in] w Width of region to update
486 * @param[in] h Height of region to update
487 * @param[in] data array from which to copy
488 * @param[in] stride stride of data in bytes
489 */
Tim Murray358747a2012-11-26 13:52:04 -0800490 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
491 const void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700492
493 /**
494 * Copy from a strided array into this Allocation.
495 * @param[in] data array from which to copy
496 * @param[in] stride stride of data in bytes
497 */
Tim Murray358747a2012-11-26 13:52:04 -0800498 void copy2DStridedFrom(const void *data, size_t stride);
499
Tim Murray75e877d2013-09-11 14:45:20 -0700500 /**
501 * Copy from a rectangular region in this Allocation into a strided array.
502 * @param[in] xoff X offset of region to update in this Allocation
503 * @param[in] yoff Y offset of region to update in this Allocation
504 * @param[in] w Width of region to update
505 * @param[in] h Height of region to update
506 * @param[in] data destination array
507 * @param[in] stride stride of data in bytes
508 */
Tim Murray358747a2012-11-26 13:52:04 -0800509 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
510 void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700511
512 /**
513 * Copy this Allocation into a strided array.
514 * @param[in] data destination array
515 * @param[in] stride stride of data in bytes
516 */
Tim Murray358747a2012-11-26 13:52:04 -0800517 void copy2DStridedTo(void *data, size_t stride);
518
Tim Murray75e877d2013-09-11 14:45:20 -0700519
520 /**
521 * Copy from an array into a 3D region in this Allocation. The
522 * array is assumed to be tightly packed.
523 * @param[in] xoff X offset of region to update in this Allocation
524 * @param[in] yoff Y offset of region to update in this Allocation
525 * @param[in] zoff Z offset of region to update in this Allocation
526 * @param[in] w Width of region to update
527 * @param[in] h Height of region to update
528 * @param[in] d Depth of region to update
529 * @param[in] data Array from which to copy
530 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700531 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
532 uint32_t h, uint32_t d, const void* data);
533
Tim Murray75e877d2013-09-11 14:45:20 -0700534 /**
535 * Copy from an Allocation into a 3D region in this Allocation.
536 * @param[in] xoff X offset of region to update in this Allocation
537 * @param[in] yoff Y offset of region to update in this Allocation
538 * @param[in] zoff Z offset of region to update in this Allocation
539 * @param[in] w Width of region to update
540 * @param[in] h Height of region to update
541 * @param[in] d Depth of region to update
542 * @param[in] data Allocation from which to copy
543 * @param[in] dataXoff X offset of region in data to copy from
544 * @param[in] dataYoff Y offset of region in data to copy from
545 * @param[in] dataZoff Z offset of region in data to copy from
546 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700547 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
548 uint32_t w, uint32_t h, uint32_t d,
549 sp<const Allocation> data,
550 uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700551
Tim Murray75e877d2013-09-11 14:45:20 -0700552 /**
Miao Wange5428e62015-03-10 15:29:40 -0700553 * Copy a 3D region in this Allocation into an array. The
554 * array is assumed to be tightly packed.
555 * @param[in] xoff X offset of region to update in this Allocation
556 * @param[in] yoff Y offset of region to update in this Allocation
557 * @param[in] zoff Z offset of region to update in this Allocation
558 * @param[in] w Width of region to update
559 * @param[in] h Height of region to update
560 * @param[in] d Depth of region to update
561 * @param[in] data Array from which to copy
562 */
563 void copy3DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
564 uint32_t h, uint32_t d, void* data);
565
566 /**
Tim Murray75e877d2013-09-11 14:45:20 -0700567 * Creates an Allocation for use by scripts with a given Type.
568 * @param[in] rs Context to which the Allocation will belong
569 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800570 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700571 * @param[in] usage usage for the Allocation
572 * @return new Allocation
573 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700574 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800575 RsAllocationMipmapControl mipmaps, uint32_t usage);
Tim Murray75e877d2013-09-11 14:45:20 -0700576
577 /**
578 * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use
579 * with RS_ALLOCATION_USAGE_SHARED.
580 * @param[in] rs Context to which the Allocation will belong
581 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800582 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700583 * @param[in] usage usage for the Allocation
584 * @param[in] pointer existing backing store to use for this Allocation if possible
585 * @return new Allocation
586 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700587 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800588 RsAllocationMipmapControl mipmaps, uint32_t usage, void * pointer);
Tim Murray84bf2b82012-10-31 16:03:16 -0700589
Tim Murray75e877d2013-09-11 14:45:20 -0700590 /**
591 * Creates an Allocation for use by scripts with a given Type with no mipmaps.
592 * @param[in] rs Context to which the Allocation will belong
593 * @param[in] type Type of the Allocation
594 * @param[in] usage usage for the Allocation
595 * @return new Allocation
596 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700597 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
598 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700599 /**
600 * Creates an Allocation with a specified number of given elements.
601 * @param[in] rs Context to which the Allocation will belong
602 * @param[in] e Element used in the Allocation
603 * @param[in] count Number of elements of the Allocation
604 * @param[in] usage usage for the Allocation
605 * @return new Allocation
606 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700607 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
608 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700609
610 /**
611 * Creates a 2D Allocation with a specified number of given elements.
612 * @param[in] rs Context to which the Allocation will belong
613 * @param[in] e Element used in the Allocation
614 * @param[in] x Width in Elements of the Allocation
615 * @param[in] y Height of the Allocation
616 * @param[in] usage usage for the Allocation
617 * @return new Allocation
618 */
Tim Murray684726c2012-11-14 11:57:42 -0800619 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
620 size_t x, size_t y,
621 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
622
Tim Murray84bf2b82012-10-31 16:03:16 -0700623
Jason Samsb8a94e22014-02-24 17:52:32 -0800624 /**
625 * Get the backing pointer for a USAGE_SHARED allocation.
626 * @param[in] stride optional parameter. when non-NULL, will contain
627 * stride in bytes of a 2D Allocation
628 * @return pointer to data
629 */
630 void * getPointer(size_t *stride = NULL);
Tim Murray84bf2b82012-10-31 16:03:16 -0700631};
632
Tim Murray75e877d2013-09-11 14:45:20 -0700633 /**
634 * An Element represents one item within an Allocation. An Element is roughly
635 * equivalent to a C type in a RenderScript kernel. Elements may be basic
636 * or complex. Some basic elements are:
637
638 * - A single float value (equivalent to a float in a kernel)
639 * - A four-element float vector (equivalent to a float4 in a kernel)
640 * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel)
641 * - A single signed 8-bit integer (equivalent to a char in a kernel)
642
643 * Basic Elements are comprised of a Element.DataType and a
644 * Element.DataKind. The DataType encodes C type information of an Element,
645 * while the DataKind encodes how that Element should be interpreted by a
646 * Sampler. Note that Allocation objects with DataKind USER cannot be used as
647 * input for a Sampler. In general, Allocation objects that are intended for
648 * use with a Sampler should use bitmap-derived Elements such as
649 * Element::RGBA_8888.
650 */
651
652
Tim Murray84bf2b82012-10-31 16:03:16 -0700653class Element : public BaseObj {
654public:
655 bool isComplex();
Tim Murray75e877d2013-09-11 14:45:20 -0700656
657 /**
658 * Elements could be simple, such as an int or a float, or a structure with
659 * multiple sub-elements, such as a collection of floats, float2,
660 * float4. This function returns zero for simple elements or the number of
661 * sub-elements otherwise.
662 * @return number of sub-elements
663 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700664 size_t getSubElementCount() {
Miao Wangbc10dff2015-04-03 17:44:55 -0700665 return mVisibleElementMapSize;
Tim Murray84bf2b82012-10-31 16:03:16 -0700666 }
667
Tim Murray75e877d2013-09-11 14:45:20 -0700668 /**
669 * For complex Elements, this returns the sub-element at a given index.
670 * @param[in] index index of sub-element
671 * @return sub-element
672 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700673 sp<const Element> getSubElement(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700674
675 /**
676 * For complex Elements, this returns the name of the sub-element at a given
677 * index.
678 * @param[in] index index of sub-element
679 * @return name of sub-element
680 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700681 const char * getSubElementName(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700682
683 /**
684 * For complex Elements, this returns the size of the sub-element at a given
685 * index.
686 * @param[in] index index of sub-element
687 * @return size of sub-element
688 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700689 size_t getSubElementArraySize(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700690
691 /**
692 * Returns the location of a sub-element within a complex Element.
693 * @param[in] index index of sub-element
694 * @return offset in bytes
695 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700696 uint32_t getSubElementOffsetBytes(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700697
698 /**
699 * Returns the data type used for the Element.
700 * @return data type
701 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700702 RsDataType getDataType() const {
703 return mType;
704 }
705
Tim Murray75e877d2013-09-11 14:45:20 -0700706 /**
707 * Returns the data kind used for the Element.
708 * @return data kind
709 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700710 RsDataKind getDataKind() const {
711 return mKind;
712 }
713
Tim Murray75e877d2013-09-11 14:45:20 -0700714 /**
715 * Returns the size in bytes of the Element.
716 * @return size in bytes
717 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700718 size_t getSizeBytes() const {
719 return mSizeBytes;
720 }
721
Tim Murray75e877d2013-09-11 14:45:20 -0700722 /**
723 * Returns the number of vector components for this Element.
724 * @return number of vector components
725 */
Tim Murray10913a52013-08-20 17:19:47 -0700726 uint32_t getVectorSize() const {
727 return mVectorSize;
728 }
729
Tim Murray75e877d2013-09-11 14:45:20 -0700730 /**
731 * Utility function for returning an Element containing a single bool.
732 * @param[in] rs RenderScript context
733 * @return Element
734 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700735 static sp<const Element> BOOLEAN(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700736 /**
737 * Utility function for returning an Element containing a single unsigned char.
738 * @param[in] rs RenderScript context
739 * @return Element
740 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700741 static sp<const Element> U8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700742 /**
743 * Utility function for returning an Element containing a single signed char.
744 * @param[in] rs RenderScript context
745 * @return Element
746 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700747 static sp<const Element> I8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700748 /**
749 * Utility function for returning an Element containing a single unsigned short.
750 * @param[in] rs RenderScript context
751 * @return Element
752 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700753 static sp<const Element> U16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700754 /**
755 * Utility function for returning an Element containing a single signed short.
756 * @param[in] rs RenderScript context
757 * @return Element
758 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700759 static sp<const Element> I16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700760 /**
761 * Utility function for returning an Element containing a single unsigned int.
762 * @param[in] rs RenderScript context
763 * @return Element
764 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700765 static sp<const Element> U32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700766 /**
767 * Utility function for returning an Element containing a single signed int.
768 * @param[in] rs RenderScript context
769 * @return Element
770 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700771 static sp<const Element> I32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700772 /**
773 * Utility function for returning an Element containing a single unsigned long long.
774 * @param[in] rs RenderScript context
775 * @return Element
776 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700777 static sp<const Element> U64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700778 /**
779 * Utility function for returning an Element containing a single signed long long.
780 * @param[in] rs RenderScript context
781 * @return Element
782 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700783 static sp<const Element> I64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700784 /**
785 * Utility function for returning an Element containing a single float.
786 * @param[in] rs RenderScript context
787 * @return Element
788 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700789 static sp<const Element> F32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700790 /**
791 * Utility function for returning an Element containing a single double.
792 * @param[in] rs RenderScript context
793 * @return Element
794 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700795 static sp<const Element> F64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700796 /**
797 * Utility function for returning an Element containing a single Element.
798 * @param[in] rs RenderScript context
799 * @return Element
800 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700801 static sp<const Element> ELEMENT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700802 /**
803 * Utility function for returning an Element containing a single Type.
804 * @param[in] rs RenderScript context
805 * @return Element
806 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700807 static sp<const Element> TYPE(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700808 /**
809 * Utility function for returning an Element containing a single Allocation.
810 * @param[in] rs RenderScript context
811 * @return Element
812 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700813 static sp<const Element> ALLOCATION(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700814 /**
815 * Utility function for returning an Element containing a single Sampler.
816 * @param[in] rs RenderScript context
817 * @return Element
818 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700819 static sp<const Element> SAMPLER(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700820 /**
821 * Utility function for returning an Element containing a single Script.
822 * @param[in] rs RenderScript context
823 * @return Element
824 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700825 static sp<const Element> SCRIPT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700826 /**
827 * Utility function for returning an Element containing an ALPHA_8 pixel.
828 * @param[in] rs RenderScript context
829 * @return Element
830 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700831 static sp<const Element> A_8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700832 /**
833 * Utility function for returning an Element containing an RGB_565 pixel.
834 * @param[in] rs RenderScript context
835 * @return Element
836 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700837 static sp<const Element> RGB_565(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700838 /**
839 * Utility function for returning an Element containing an RGB_888 pixel.
840 * @param[in] rs RenderScript context
841 * @return Element
842 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700843 static sp<const Element> RGB_888(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700844 /**
845 * Utility function for returning an Element containing an RGBA_5551 pixel.
846 * @param[in] rs RenderScript context
847 * @return Element
848 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700849 static sp<const Element> RGBA_5551(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700850 /**
851 * Utility function for returning an Element containing an RGBA_4444 pixel.
852 * @param[in] rs RenderScript context
853 * @return Element
854 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700855 static sp<const Element> RGBA_4444(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700856 /**
857 * Utility function for returning an Element containing an RGBA_8888 pixel.
858 * @param[in] rs RenderScript context
859 * @return Element
860 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700861 static sp<const Element> RGBA_8888(sp<RS> rs);
862
Tim Murray75e877d2013-09-11 14:45:20 -0700863 /**
864 * Utility function for returning an Element containing a float2.
865 * @param[in] rs RenderScript context
866 * @return Element
867 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700868 static sp<const Element> F32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700869 /**
870 * Utility function for returning an Element containing a float3.
871 * @param[in] rs RenderScript context
872 * @return Element
873 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700874 static sp<const Element> F32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700875 /**
876 * Utility function for returning an Element containing a float4.
877 * @param[in] rs RenderScript context
878 * @return Element
879 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700880 static sp<const Element> F32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700881 /**
882 * Utility function for returning an Element containing a double2.
883 * @param[in] rs RenderScript context
884 * @return Element
885 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700886 static sp<const Element> F64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700887 /**
888 * Utility function for returning an Element containing a double3.
889 * @param[in] rs RenderScript context
890 * @return Element
891 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700892 static sp<const Element> F64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700893 /**
894 * Utility function for returning an Element containing a double4.
895 * @param[in] rs RenderScript context
896 * @return Element
897 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700898 static sp<const Element> F64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700899 /**
900 * Utility function for returning an Element containing a uchar2.
901 * @param[in] rs RenderScript context
902 * @return Element
903 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700904 static sp<const Element> U8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700905 /**
906 * Utility function for returning an Element containing a uchar3.
907 * @param[in] rs RenderScript context
908 * @return Element
909 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700910 static sp<const Element> U8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700911 /**
912 * Utility function for returning an Element containing a uchar4.
913 * @param[in] rs RenderScript context
914 * @return Element
915 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700916 static sp<const Element> U8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700917 /**
918 * Utility function for returning an Element containing a char2.
919 * @param[in] rs RenderScript context
920 * @return Element
921 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700922 static sp<const Element> I8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700923 /**
924 * Utility function for returning an Element containing a char3.
925 * @param[in] rs RenderScript context
926 * @return Element
927 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700928 static sp<const Element> I8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700929 /**
930 * Utility function for returning an Element containing a char4.
931 * @param[in] rs RenderScript context
932 * @return Element
933 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700934 static sp<const Element> I8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700935 /**
936 * Utility function for returning an Element containing a ushort2.
937 * @param[in] rs RenderScript context
938 * @return Element
939 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700940 static sp<const Element> U16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700941 /**
942 * Utility function for returning an Element containing a ushort3.
943 * @param[in] rs RenderScript context
944 * @return Element
945 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700946 static sp<const Element> U16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700947 /**
948 * Utility function for returning an Element containing a ushort4.
949 * @param[in] rs RenderScript context
950 * @return Element
951 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700952 static sp<const Element> U16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700953 /**
954 * Utility function for returning an Element containing a short2.
955 * @param[in] rs RenderScript context
956 * @return Element
957 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700958 static sp<const Element> I16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700959 /**
960 * Utility function for returning an Element containing a short3.
961 * @param[in] rs RenderScript context
962 * @return Element
963 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700964 static sp<const Element> I16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700965 /**
966 * Utility function for returning an Element containing a short4.
967 * @param[in] rs RenderScript context
968 * @return Element
969 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700970 static sp<const Element> I16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700971 /**
972 * Utility function for returning an Element containing a uint2.
973 * @param[in] rs RenderScript context
974 * @return Element
975 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700976 static sp<const Element> U32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700977 /**
978 * Utility function for returning an Element containing a uint3.
979 * @param[in] rs RenderScript context
980 * @return Element
981 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700982 static sp<const Element> U32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700983 /**
984 * Utility function for returning an Element containing a uint4.
985 * @param[in] rs RenderScript context
986 * @return Element
987 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700988 static sp<const Element> U32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700989 /**
990 * Utility function for returning an Element containing an int2.
991 * @param[in] rs RenderScript context
992 * @return Element
993 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700994 static sp<const Element> I32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700995 /**
996 * Utility function for returning an Element containing an int3.
997 * @param[in] rs RenderScript context
998 * @return Element
999 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001000 static sp<const Element> I32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001001 /**
1002 * Utility function for returning an Element containing an int4.
1003 * @param[in] rs RenderScript context
1004 * @return Element
1005 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001006 static sp<const Element> I32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001007 /**
1008 * Utility function for returning an Element containing a ulong2.
1009 * @param[in] rs RenderScript context
1010 * @return Element
1011 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001012 static sp<const Element> U64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001013 /**
1014 * Utility function for returning an Element containing a ulong3.
1015 * @param[in] rs RenderScript context
1016 * @return Element
1017 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001018 static sp<const Element> U64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001019 /**
1020 * Utility function for returning an Element containing a ulong4.
1021 * @param[in] rs RenderScript context
1022 * @return Element
1023 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001024 static sp<const Element> U64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001025 /**
1026 * Utility function for returning an Element containing a long2.
1027 * @param[in] rs RenderScript context
1028 * @return Element
1029 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001030 static sp<const Element> I64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001031 /**
1032 * Utility function for returning an Element containing a long3.
1033 * @param[in] rs RenderScript context
1034 * @return Element
1035 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001036 static sp<const Element> I64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001037 /**
1038 * Utility function for returning an Element containing a long4.
1039 * @param[in] rs RenderScript context
1040 * @return Element
1041 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001042 static sp<const Element> I64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001043 /**
1044 * Utility function for returning an Element containing a YUV pixel.
1045 * @param[in] rs RenderScript context
1046 * @return Element
1047 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001048 static sp<const Element> YUV(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001049 /**
1050 * Utility function for returning an Element containing an rs_matrix_4x4.
1051 * @param[in] rs RenderScript context
1052 * @return Element
1053 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001054 static sp<const Element> MATRIX_4X4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001055 /**
1056 * Utility function for returning an Element containing an rs_matrix_3x3.
1057 * @param[in] rs RenderScript context
1058 * @return Element
1059 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001060 static sp<const Element> MATRIX_3X3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001061 /**
1062 * Utility function for returning an Element containing an rs_matrix_2x2.
1063 * @param[in] rs RenderScript context
1064 * @return Element
1065 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001066 static sp<const Element> MATRIX_2X2(sp<RS> rs);
1067
Tim Murray84bf2b82012-10-31 16:03:16 -07001068 void updateFromNative();
Tim Murray75e877d2013-09-11 14:45:20 -07001069
1070 /**
1071 * Create an Element with a given DataType.
1072 * @param[in] rs RenderScript context
1073 * @param[in] dt data type
1074 * @return Element
1075 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001076 static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
Tim Murray75e877d2013-09-11 14:45:20 -07001077 /**
1078 * Create a vector Element with the given DataType
1079 * @param[in] rs RenderScript
1080 * @param[in] dt DataType
1081 * @param[in] size vector size
1082 * @return Element
1083 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001084 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
Tim Murray75e877d2013-09-11 14:45:20 -07001085 /**
1086 * Create an Element with a given DataType and DataKind.
1087 * @param[in] rs RenderScript context
1088 * @param[in] dt DataType
1089 * @param[in] dk DataKind
1090 * @return Element
1091 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001092 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
Tim Murray75e877d2013-09-11 14:45:20 -07001093
1094 /**
1095 * Returns true if the Element can interoperate with this Element.
1096 * @param[in] e Element to compare
1097 * @return true if Elements can interoperate
1098 */
Tim Murray10913a52013-08-20 17:19:47 -07001099 bool isCompatible(sp<const Element>e) const;
Tim Murray84bf2b82012-10-31 16:03:16 -07001100
Tim Murray75e877d2013-09-11 14:45:20 -07001101 /**
1102 * Builder class for producing complex elements with matching field and name
1103 * pairs. The builder starts empty. The order in which elements are added is
1104 * retained for the layout in memory.
1105 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001106 class Builder {
1107 private:
Tim Murray35609072013-12-03 11:36:03 -08001108 RS* mRS;
Miao Wangbc10dff2015-04-03 17:44:55 -07001109 size_t mElementsCount;
1110 size_t mElementsVecSize;
1111 sp<const Element> * mElements;
1112 char ** mElementNames;
1113 size_t * mElementNameLengths;
1114 uint32_t * mArraySizes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001115 bool mSkipPadding;
1116
1117 public:
1118 Builder(sp<RS> rs);
1119 ~Builder();
Miao Wangbc10dff2015-04-03 17:44:55 -07001120 void add(sp<const Element> e, const char * name, uint32_t arraySize = 1);
Tim Murray84bf2b82012-10-31 16:03:16 -07001121 sp<const Element> create();
1122 };
1123
Stephen Hines7d1b7572013-08-22 01:24:06 -07001124protected:
1125 Element(void *id, sp<RS> rs,
Miao Wangbc10dff2015-04-03 17:44:55 -07001126 sp<const Element> * elements,
1127 size_t elementCount,
1128 const char ** elementNames,
1129 size_t * elementNameLengths,
1130 uint32_t * arraySizes);
Stephen Hines7d1b7572013-08-22 01:24:06 -07001131 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
1132 Element(sp<RS> rs);
1133 virtual ~Element();
1134
Tim Murray84bf2b82012-10-31 16:03:16 -07001135private:
1136 void updateVisibleSubElements();
1137
Miao Wangbc10dff2015-04-03 17:44:55 -07001138 size_t mElementsCount;
1139 size_t mVisibleElementMapSize;
1140
1141 sp<const Element> * mElements;
1142 char ** mElementNames;
1143 size_t * mElementNameLengths;
1144 uint32_t * mArraySizes;
1145 uint32_t * mVisibleElementMap;
1146 uint32_t * mOffsetInBytes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001147
1148 RsDataType mType;
1149 RsDataKind mKind;
1150 bool mNormalized;
1151 size_t mSizeBytes;
1152 size_t mVectorSize;
1153};
1154
Stephen Hines2c7206e2012-11-14 19:47:01 -08001155class FieldPacker {
1156protected:
1157 unsigned char* mData;
1158 size_t mPos;
1159 size_t mLen;
1160
1161public:
1162 FieldPacker(size_t len)
Tim Murray89daad62013-07-29 14:30:02 -07001163 : mPos(0), mLen(len) {
1164 mData = new unsigned char[len];
1165 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001166
1167 virtual ~FieldPacker() {
1168 delete [] mData;
1169 }
1170
1171 void align(size_t v) {
1172 if ((v & (v - 1)) != 0) {
Tim Murrayab716362013-08-12 12:37:18 -07001173 // ALOGE("Non-power-of-two alignment: %zu", v);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001174 return;
1175 }
1176
1177 while ((mPos & (v - 1)) != 0) {
1178 mData[mPos++] = 0;
1179 }
1180 }
1181
1182 void reset() {
1183 mPos = 0;
1184 }
1185
1186 void reset(size_t i) {
1187 if (i >= mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001188 // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001189 return;
1190 }
1191 mPos = i;
1192 }
1193
1194 void skip(size_t i) {
1195 size_t res = mPos + i;
1196 if (res > mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001197 // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001198 return;
1199 }
1200 mPos = res;
1201 }
1202
1203 void* getData() const {
1204 return mData;
1205 }
1206
1207 size_t getLength() const {
1208 return mLen;
1209 }
1210
1211 template <typename T>
Tim Murray89daad62013-07-29 14:30:02 -07001212 void add(T t) {
Stephen Hines2c7206e2012-11-14 19:47:01 -08001213 align(sizeof(t));
1214 if (mPos + sizeof(t) <= mLen) {
1215 memcpy(&mData[mPos], &t, sizeof(t));
1216 mPos += sizeof(t);
1217 }
1218 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001219
1220 /*
Tim Murray89daad62013-07-29 14:30:02 -07001221 void add(rs_matrix4x4 m) {
1222 for (size_t i = 0; i < 16; i++) {
1223 add(m.m[i]);
1224 }
1225 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001226
Tim Murray89daad62013-07-29 14:30:02 -07001227 void add(rs_matrix3x3 m) {
1228 for (size_t i = 0; i < 9; i++) {
1229 add(m.m[i]);
1230 }
1231 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001232
Tim Murray89daad62013-07-29 14:30:02 -07001233 void add(rs_matrix2x2 m) {
1234 for (size_t i = 0; i < 4; i++) {
1235 add(m.m[i]);
1236 }
1237 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001238 */
1239
Tim Murray89daad62013-07-29 14:30:02 -07001240 void add(sp<BaseObj> obj) {
Stephen Hines43514cd2012-11-16 14:33:47 -08001241 if (obj != NULL) {
1242 add((uint32_t) (uintptr_t) obj->getID());
1243 } else {
1244 add((uint32_t) 0);
1245 }
1246 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001247};
1248
Tim Murray75e877d2013-09-11 14:45:20 -07001249/**
1250 * A Type describes the Element and dimensions used for an Allocation or a
1251 * parallel operation.
1252 *
1253 * A Type always includes an Element and an X dimension. A Type may be
1254 * multidimensional, up to three dimensions. A nonzero value in the Y or Z
1255 * dimensions indicates that the dimension is present. Note that a Type with
1256 * only a given X dimension and a Type with the same X dimension but Y = 1 are
1257 * not equivalent.
1258 *
1259 * A Type also supports inclusion of level of detail (LOD) or cube map
1260 * faces. LOD and cube map faces are booleans to indicate present or not
1261 * present.
1262 *
1263 * A Type also supports YUV format information to support an Allocation in a YUV
1264 * format. The YUV formats supported are YV12 and NV21.
1265 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001266class Type : public BaseObj {
1267protected:
1268 friend class Allocation;
1269
1270 uint32_t mDimX;
1271 uint32_t mDimY;
1272 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001273 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001274 bool mDimMipmaps;
1275 bool mDimFaces;
1276 size_t mElementCount;
1277 sp<const Element> mElement;
1278
Stephen Hines7d1b7572013-08-22 01:24:06 -07001279 Type(void *id, sp<RS> rs);
1280
Tim Murray84bf2b82012-10-31 16:03:16 -07001281 void calcElementCount();
1282 virtual void updateFromNative();
1283
1284public:
1285
Tim Murray75e877d2013-09-11 14:45:20 -07001286 /**
1287 * Returns the YUV format.
1288 * @return YUV format of the Allocation
1289 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001290 RSYuvFormat getYuvFormat() const {
1291 return mYuvFormat;
1292 }
1293
Tim Murray75e877d2013-09-11 14:45:20 -07001294 /**
1295 * Returns the Element of the Allocation.
1296 * @return YUV format of the Allocation
1297 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001298 sp<const Element> getElement() const {
1299 return mElement;
1300 }
1301
Tim Murray75e877d2013-09-11 14:45:20 -07001302 /**
1303 * Returns the X dimension of the Allocation.
1304 * @return X dimension of the allocation
1305 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001306 uint32_t getX() const {
1307 return mDimX;
1308 }
1309
Tim Murray75e877d2013-09-11 14:45:20 -07001310 /**
1311 * Returns the Y dimension of the Allocation.
1312 * @return Y dimension of the allocation
1313 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001314 uint32_t getY() const {
1315 return mDimY;
1316 }
1317
Tim Murray75e877d2013-09-11 14:45:20 -07001318 /**
1319 * Returns the Z dimension of the Allocation.
1320 * @return Z dimension of the allocation
1321 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001322 uint32_t getZ() const {
1323 return mDimZ;
1324 }
1325
Tim Murray75e877d2013-09-11 14:45:20 -07001326 /**
1327 * Returns true if the Allocation has mipmaps.
1328 * @return true if the Allocation has mipmaps
1329 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001330 bool hasMipmaps() const {
1331 return mDimMipmaps;
1332 }
1333
Tim Murray75e877d2013-09-11 14:45:20 -07001334 /**
1335 * Returns true if the Allocation is a cube map
1336 * @return true if the Allocation is a cube map
1337 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001338 bool hasFaces() const {
1339 return mDimFaces;
1340 }
1341
Tim Murray75e877d2013-09-11 14:45:20 -07001342 /**
1343 * Returns number of accessible Elements in the Allocation
1344 * @return number of accessible Elements in the Allocation
1345 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001346 size_t getCount() const {
1347 return mElementCount;
1348 }
1349
Tim Murray75e877d2013-09-11 14:45:20 -07001350 /**
1351 * Returns size in bytes of all Elements in the Allocation
1352 * @return size in bytes of all Elements in the Allocation
1353 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001354 size_t getSizeBytes() const {
1355 return mElementCount * mElement->getSizeBytes();
1356 }
1357
Tim Murray75e877d2013-09-11 14:45:20 -07001358 /**
1359 * Creates a new Type with the given Element and dimensions.
1360 * @param[in] rs RenderScript context
1361 * @param[in] e Element
1362 * @param[in] dimX X dimension
1363 * @param[in] dimY Y dimension
1364 * @param[in] dimZ Z dimension
1365 * @return new Type
1366 */
Tim Murray96267c22013-02-12 11:25:12 -08001367 static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ);
Tim Murray84bf2b82012-10-31 16:03:16 -07001368
1369 class Builder {
1370 protected:
Tim Murray35609072013-12-03 11:36:03 -08001371 RS* mRS;
Tim Murray84bf2b82012-10-31 16:03:16 -07001372 uint32_t mDimX;
1373 uint32_t mDimY;
1374 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001375 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001376 bool mDimMipmaps;
1377 bool mDimFaces;
1378 sp<const Element> mElement;
1379
1380 public:
1381 Builder(sp<RS> rs, sp<const Element> e);
1382
1383 void setX(uint32_t value);
Stephen Hines7d1b7572013-08-22 01:24:06 -07001384 void setY(uint32_t value);
Tim Murrayeb4426d2013-08-27 15:30:16 -07001385 void setZ(uint32_t value);
1386 void setYuvFormat(RSYuvFormat format);
Tim Murray84bf2b82012-10-31 16:03:16 -07001387 void setMipmaps(bool value);
1388 void setFaces(bool value);
1389 sp<const Type> create();
1390 };
1391
1392};
1393
Tim Murray75e877d2013-09-11 14:45:20 -07001394/**
1395 * The parent class for all executable Scripts. This should not be used by applications.
1396 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001397class Script : public BaseObj {
1398private:
1399
1400protected:
1401 Script(void *id, sp<RS> rs);
1402 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
1403 const void *v, size_t) const;
1404 void bindAllocation(sp<Allocation> va, uint32_t slot) const;
1405 void setVar(uint32_t index, const void *, size_t len) const;
1406 void setVar(uint32_t index, sp<const BaseObj> o) const;
1407 void invoke(uint32_t slot, const void *v, size_t len) const;
1408
1409
1410 void invoke(uint32_t slot) const {
1411 invoke(slot, NULL, 0);
1412 }
1413 void setVar(uint32_t index, float v) const {
1414 setVar(index, &v, sizeof(v));
1415 }
1416 void setVar(uint32_t index, double v) const {
1417 setVar(index, &v, sizeof(v));
1418 }
1419 void setVar(uint32_t index, int32_t v) const {
1420 setVar(index, &v, sizeof(v));
1421 }
Jon Parrb05c8502015-03-13 14:41:58 +00001422 void setVar(uint32_t index, uint32_t v) const {
1423 setVar(index, &v, sizeof(v));
1424 }
Tim Murray84bf2b82012-10-31 16:03:16 -07001425 void setVar(uint32_t index, int64_t v) const {
1426 setVar(index, &v, sizeof(v));
1427 }
1428 void setVar(uint32_t index, bool v) const {
1429 setVar(index, &v, sizeof(v));
1430 }
1431
1432public:
1433 class FieldBase {
1434 protected:
1435 sp<const Element> mElement;
1436 sp<Allocation> mAllocation;
1437
1438 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
1439
1440 public:
1441 sp<const Element> getElement() {
1442 return mElement;
1443 }
1444
1445 sp<const Type> getType() {
1446 return mAllocation->getType();
1447 }
1448
1449 sp<const Allocation> getAllocation() {
1450 return mAllocation;
1451 }
1452
1453 //void updateAllocation();
1454 };
1455};
1456
Tim Murray75e877d2013-09-11 14:45:20 -07001457/**
1458 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only.
1459 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001460class ScriptC : public Script {
1461protected:
1462 ScriptC(sp<RS> rs,
1463 const void *codeTxt, size_t codeLength,
1464 const char *cachedName, size_t cachedNameLength,
1465 const char *cacheDir, size_t cacheDirLength);
1466
1467};
1468
Tim Murray75e877d2013-09-11 14:45:20 -07001469/**
1470 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of
1471 * basic functions. This is not intended to be used directly.
1472 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001473class ScriptIntrinsic : public Script {
1474 protected:
Tim Murray10913a52013-08-20 17:19:47 -07001475 sp<const Element> mElement;
Tim Murray3cd44af2012-11-14 11:25:27 -08001476 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001477 virtual ~ScriptIntrinsic();
Tim Murray7f0d5682012-11-08 16:35:24 -08001478};
1479
Tim Murray75e877d2013-09-11 14:45:20 -07001480/**
1481 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming
1482 * r,g,b values are use as normalized x,y,z coordinates into a 3D
1483 * allocation. The 8 nearest values are sampled and linearly interpolated. The
1484 * result is placed in the output.
1485 */
Tim Murray89daad62013-07-29 14:30:02 -07001486class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001487 private:
Tim Murray89daad62013-07-29 14:30:02 -07001488 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001489 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001490 /**
1491 * Supported Element types are U8_4. Default lookup table is identity.
1492 * @param[in] rs RenderScript context
1493 * @param[in] e Element
1494 * @return new ScriptIntrinsic
1495 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001496 static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001497
1498 /**
1499 * Launch the intrinsic.
1500 * @param[in] ain input Allocation
1501 * @param[in] aout output Allocation
1502 */
Tim Murray89daad62013-07-29 14:30:02 -07001503 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001504
1505 /**
1506 * Sets the lookup table. The lookup table must use the same Element as the
1507 * intrinsic.
1508 * @param[in] lut new lookup table
1509 */
Tim Murray89daad62013-07-29 14:30:02 -07001510 void setLUT(sp<Allocation> lut);
1511};
1512
Tim Murray75e877d2013-09-11 14:45:20 -07001513/**
1514 * Intrinsic kernel for blending two Allocations.
1515 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001516class ScriptIntrinsicBlend : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001517 private:
Tim Murray89daad62013-07-29 14:30:02 -07001518 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001519 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001520 /**
1521 * Supported Element types are U8_4.
1522 * @param[in] rs RenderScript context
1523 * @param[in] e Element
1524 * @return new ScriptIntrinsicBlend
1525 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001526 static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001527 /**
1528 * sets dst = {0, 0, 0, 0}
1529 * @param[in] in input Allocation
1530 * @param[in] out output Allocation
1531 */
1532 void forEachClear(sp<Allocation> in, sp<Allocation> out);
1533 /**
1534 * Sets dst = src
1535 * @param[in] in input Allocation
1536 * @param[in] out output Allocation
1537 */
1538 void forEachSrc(sp<Allocation> in, sp<Allocation> out);
1539 /**
1540 * Sets dst = dst (NOP)
1541 * @param[in] in input Allocation
1542 * @param[in] out output Allocation
1543 */
1544 void forEachDst(sp<Allocation> in, sp<Allocation> out);
1545 /**
1546 * Sets dst = src + dst * (1.0 - src.a)
1547 * @param[in] in input Allocation
1548 * @param[in] out output Allocation
1549 */
1550 void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
1551 /**
1552 * Sets dst = dst + src * (1.0 - dst.a)
1553 * @param[in] in input Allocation
1554 * @param[in] out output Allocation
1555 */
1556 void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
1557 /**
1558 * Sets dst = src * dst.a
1559 * @param[in] in input Allocation
1560 * @param[in] out output Allocation
1561 */
1562 void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
1563 /**
1564 * Sets dst = dst * src.a
1565 * @param[in] in input Allocation
1566 * @param[in] out output Allocation
1567 */
1568 void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
1569 /**
1570 * Sets dst = src * (1.0 - dst.a)
1571 * @param[in] in input Allocation
1572 * @param[in] out output Allocation
1573 */
1574 void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
1575 /**
1576 * Sets dst = dst * (1.0 - src.a)
1577 * @param[in] in input Allocation
1578 * @param[in] out output Allocation
1579 */
1580 void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
1581 /**
1582 * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
1583 * @param[in] in input Allocation
1584 * @param[in] out output Allocation
1585 */
1586 void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
1587 /**
1588 * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
1589 * @param[in] in input Allocation
1590 * @param[in] out output Allocation
1591 */
1592 void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
1593 /**
1594 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
1595 * @param[in] in input Allocation
1596 * @param[in] out output Allocation
1597 */
1598 void forEachXor(sp<Allocation> in, sp<Allocation> out);
1599 /**
1600 * Sets dst = src * dst
1601 * @param[in] in input Allocation
1602 * @param[in] out output Allocation
1603 */
1604 void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
1605 /**
1606 * Sets dst = min(src + dst, 1.0)
1607 * @param[in] in input Allocation
1608 * @param[in] out output Allocation
1609 */
1610 void forEachAdd(sp<Allocation> in, sp<Allocation> out);
1611 /**
1612 * Sets dst = max(dst - src, 0.0)
1613 * @param[in] in input Allocation
1614 * @param[in] out output Allocation
1615 */
1616 void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
Tim Murray7f0d5682012-11-08 16:35:24 -08001617};
Tim Murray84bf2b82012-10-31 16:03:16 -07001618
Tim Murray75e877d2013-09-11 14:45:20 -07001619/**
1620 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified
1621 * radius to all elements of an Allocation.
1622 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001623class ScriptIntrinsicBlur : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001624 private:
Tim Murray89daad62013-07-29 14:30:02 -07001625 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001626 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001627 /**
1628 * Supported Element types are U8 and U8_4.
1629 * @param[in] rs RenderScript context
1630 * @param[in] e Element
1631 * @return new ScriptIntrinsicBlur
1632 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001633 static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001634 /**
1635 * Sets the input of the blur.
1636 * @param[in] in input Allocation
1637 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001638 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001639 /**
1640 * Runs the intrinsic.
1641 * @param[in] output Allocation
1642 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001643 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001644 /**
1645 * Sets the radius of the blur. The supported range is 0 < radius <= 25.
1646 * @param[in] radius radius of the blur
1647 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001648 void setRadius(float radius);
1649};
1650
Tim Murray75e877d2013-09-11 14:45:20 -07001651/**
1652 * Intrinsic for applying a color matrix to allocations. This has the
1653 * same effect as loading each element and converting it to a
1654 * F32_N, multiplying the result by the 4x4 color matrix
1655 * as performed by rsMatrixMultiply() and writing it to the output
1656 * after conversion back to U8_N or F32_N.
1657 */
Tim Murray89daad62013-07-29 14:30:02 -07001658class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001659 private:
Tim Murray89daad62013-07-29 14:30:02 -07001660 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001661 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001662 /**
1663 * Creates a new intrinsic.
1664 * @param[in] rs RenderScript context
1665 * @return new ScriptIntrinsicColorMatrix
1666 */
Tim Murrayaae73c92013-09-03 17:05:46 -07001667 static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001668 /**
1669 * Applies the color matrix. Supported types are U8 and F32 with
1670 * vector lengths between 1 and 4.
1671 * @param[in] in input Allocation
1672 * @param[out] out output Allocation
1673 */
Tim Murray89daad62013-07-29 14:30:02 -07001674 void forEach(sp<Allocation> in, sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001675 /**
1676 * Set the value to be added after the color matrix has been
1677 * applied. The default value is {0, 0, 0, 0}.
1678 * @param[in] add float[4] of values
1679 */
Tim Murray10913a52013-08-20 17:19:47 -07001680 void setAdd(float* add);
Tim Murray75e877d2013-09-11 14:45:20 -07001681
1682 /**
1683 * Set the color matrix which will be applied to each cell of the
1684 * image. The alpha channel will be copied.
1685 *
1686 * @param[in] m float[9] of values
1687 */
Tim Murray89daad62013-07-29 14:30:02 -07001688 void setColorMatrix3(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001689 /**
1690 * Set the color matrix which will be applied to each cell of the
1691 * image.
1692 *
1693 * @param[in] m float[16] of values
1694 */
Tim Murray89daad62013-07-29 14:30:02 -07001695 void setColorMatrix4(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001696 /**
1697 * Set a color matrix to convert from RGB to luminance. The alpha
1698 * channel will be a copy.
1699 */
Tim Murray89daad62013-07-29 14:30:02 -07001700 void setGreyscale();
Tim Murray75e877d2013-09-11 14:45:20 -07001701 /**
1702 * Set the matrix to convert from RGB to YUV with a direct copy of
1703 * the 4th channel.
1704 */
Tim Murray89daad62013-07-29 14:30:02 -07001705 void setRGBtoYUV();
Tim Murray75e877d2013-09-11 14:45:20 -07001706 /**
1707 * Set the matrix to convert from YUV to RGB with a direct copy of
1708 * the 4th channel.
1709 */
Tim Murray89daad62013-07-29 14:30:02 -07001710 void setYUVtoRGB();
1711};
1712
Tim Murray75e877d2013-09-11 14:45:20 -07001713/**
1714 * Intrinsic for applying a 3x3 convolve to an allocation.
1715 */
Tim Murray89daad62013-07-29 14:30:02 -07001716class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001717 private:
Tim Murray89daad62013-07-29 14:30:02 -07001718 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001719 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001720 /**
1721 * Supported types U8 and F32 with vector lengths between 1 and
1722 * 4. The default convolution kernel is the identity.
1723 * @param[in] rs RenderScript context
1724 * @param[in] e Element
1725 * @return new ScriptIntrinsicConvolve3x3
1726 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001727 static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001728 /**
1729 * Sets input for intrinsic.
1730 * @param[in] in input Allocation
1731 */
Tim Murray89daad62013-07-29 14:30:02 -07001732 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001733 /**
1734 * Launches the intrinsic.
1735 * @param[in] out output Allocation
1736 */
Tim Murray89daad62013-07-29 14:30:02 -07001737 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001738 /**
1739 * Sets convolution kernel.
1740 * @param[in] v float[9] of values
1741 */
Tim Murray89daad62013-07-29 14:30:02 -07001742 void setCoefficients(float* v);
1743};
1744
Tim Murray75e877d2013-09-11 14:45:20 -07001745/**
1746 * Intrinsic for applying a 5x5 convolve to an allocation.
1747 */
Tim Murray89daad62013-07-29 14:30:02 -07001748class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001749 private:
Tim Murray89daad62013-07-29 14:30:02 -07001750 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001751 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001752 /**
1753 * Supported types U8 and F32 with vector lengths between 1 and
1754 * 4. The default convolution kernel is the identity.
1755 * @param[in] rs RenderScript context
1756 * @param[in] e Element
1757 * @return new ScriptIntrinsicConvolve5x5
1758 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001759 static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001760 /**
1761 * Sets input for intrinsic.
1762 * @param[in] in input Allocation
1763 */
Tim Murray89daad62013-07-29 14:30:02 -07001764 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001765 /**
1766 * Launches the intrinsic.
1767 * @param[in] out output Allocation
1768 */
Tim Murray89daad62013-07-29 14:30:02 -07001769 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001770 /**
1771 * Sets convolution kernel.
1772 * @param[in] v float[25] of values
1773 */
Tim Murray89daad62013-07-29 14:30:02 -07001774 void setCoefficients(float* v);
1775};
1776
Tim Murray75e877d2013-09-11 14:45:20 -07001777/**
1778 * Intrinsic for computing a histogram.
1779 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001780class ScriptIntrinsicHistogram : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001781 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001782 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
Tim Murray10913a52013-08-20 17:19:47 -07001783 sp<Allocation> mOut;
Tim Murray21fa7a02013-08-15 16:25:03 -07001784 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001785 /**
1786 * Create an intrinsic for calculating the histogram of an uchar
1787 * or uchar4 image.
1788 *
1789 * Supported elements types are U8_4, U8_3, U8_2, and U8.
1790 *
1791 * @param[in] rs The RenderScript context
1792 * @param[in] e Element type for inputs
1793 *
1794 * @return ScriptIntrinsicHistogram
1795 */
Jon Parrb05c8502015-03-13 14:41:58 +00001796 static sp<ScriptIntrinsicHistogram> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001797 /**
1798 * Set the output of the histogram. 32 bit integer types are
1799 * supported.
1800 *
1801 * @param[in] aout The output allocation
1802 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001803 void setOutput(sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001804 /**
1805 * Set the coefficients used for the dot product calculation. The
1806 * default is {0.299f, 0.587f, 0.114f, 0.f}.
1807 *
1808 * Coefficients must be >= 0 and sum to 1.0 or less.
1809 *
1810 * @param[in] r Red coefficient
1811 * @param[in] g Green coefficient
1812 * @param[in] b Blue coefficient
1813 * @param[in] a Alpha coefficient
1814 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001815 void setDotCoefficients(float r, float g, float b, float a);
Tim Murray75e877d2013-09-11 14:45:20 -07001816 /**
1817 * Process an input buffer and place the histogram into the output
1818 * allocation. The output allocation may be a narrower vector size
1819 * than the input. In this case the vector size of the output is
1820 * used to determine how many of the input channels are used in
1821 * the computation. This is useful if you have an RGBA input
1822 * buffer but only want the histogram for RGB.
1823 *
1824 * 1D and 2D input allocations are supported.
1825 *
1826 * @param[in] ain The input image
1827 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001828 void forEach(sp<Allocation> ain);
Tim Murray75e877d2013-09-11 14:45:20 -07001829 /**
1830 * Process an input buffer and place the histogram into the output
1831 * allocation. The dot product of the input channel and the
1832 * coefficients from 'setDotCoefficients' are used to calculate
1833 * the output values.
1834 *
1835 * 1D and 2D input allocations are supported.
1836 *
1837 * @param ain The input image
1838 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001839 void forEach_dot(sp<Allocation> ain);
1840};
1841
Tim Murray75e877d2013-09-11 14:45:20 -07001842/**
1843 * Intrinsic for applying a per-channel lookup table. Each channel of
1844 * the input has an independant lookup table. The tables are 256
1845 * entries in size and can cover the full value range of U8_4.
1846 **/
Tim Murrayb27b1812013-08-05 14:00:40 -07001847class ScriptIntrinsicLUT : public ScriptIntrinsic {
1848 private:
1849 sp<Allocation> LUT;
1850 bool mDirty;
1851 unsigned char mCache[1024];
Tim Murray2acce992013-08-28 14:23:31 -07001852 void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray21fa7a02013-08-15 16:25:03 -07001853 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001854
Tim Murray89daad62013-07-29 14:30:02 -07001855 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001856 /**
1857 * Supported elements types are U8_4.
1858 *
1859 * The defaults tables are identity.
1860 *
1861 * @param[in] rs The RenderScript context
1862 * @param[in] e Element type for intputs and outputs
1863 *
1864 * @return ScriptIntrinsicLUT
1865 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001866 static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001867 /**
1868 * Invoke the kernel and apply the lookup to each cell of ain and
1869 * copy to aout.
1870 *
1871 * @param[in] ain Input allocation
1872 * @param[in] aout Output allocation
1873 */
Tim Murray89daad62013-07-29 14:30:02 -07001874 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001875 /**
1876 * Sets entries in LUT for the red channel.
1877 * @param[in] base base of region to update
1878 * @param[in] length length of region to update
1879 * @param[in] lutValues LUT values to use
1880 */
Tim Murray2acce992013-08-28 14:23:31 -07001881 void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001882 /**
1883 * Sets entries in LUT for the green channel.
1884 * @param[in] base base of region to update
1885 * @param[in] length length of region to update
1886 * @param[in] lutValues LUT values to use
1887 */
Tim Murray2acce992013-08-28 14:23:31 -07001888 void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001889 /**
1890 * Sets entries in LUT for the blue channel.
1891 * @param[in] base base of region to update
1892 * @param[in] length length of region to update
1893 * @param[in] lutValues LUT values to use
1894 */
Tim Murray2acce992013-08-28 14:23:31 -07001895 void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001896 /**
1897 * Sets entries in LUT for the alpha channel.
1898 * @param[in] base base of region to update
1899 * @param[in] length length of region to update
1900 * @param[in] lutValues LUT values to use
1901 */
Tim Murray2acce992013-08-28 14:23:31 -07001902 void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murrayb27b1812013-08-05 14:00:40 -07001903 virtual ~ScriptIntrinsicLUT();
1904};
1905
Tim Murray75e877d2013-09-11 14:45:20 -07001906/**
Miao Wange5428e62015-03-10 15:29:40 -07001907 * Intrinsic for performing a resize of a 2D allocation.
1908 */
1909class ScriptIntrinsicResize : public ScriptIntrinsic {
1910 private:
1911 sp<Allocation> mInput;
1912 ScriptIntrinsicResize(sp<RS> rs, sp<const Element> e);
1913 public:
1914 /**
1915 * Supported Element types are U8_4. Default lookup table is identity.
1916 * @param[in] rs RenderScript context
1917 * @param[in] e Element
1918 * @return new ScriptIntrinsic
1919 */
1920 static sp<ScriptIntrinsicResize> create(sp<RS> rs);
1921
1922 /**
1923 * Resize copy the input allocation to the output specified. The
1924 * Allocation is rescaled if necessary using bi-cubic
1925 * interpolation.
1926 * @param[in] ain input Allocation
1927 * @param[in] aout output Allocation
1928 */
1929 void forEach_bicubic(sp<Allocation> aout);
1930
1931 /**
1932 * Set the input of the resize.
1933 * @param[in] lut new lookup table
1934 */
1935 void setInput(sp<Allocation> ain);
1936};
1937
1938/**
Tim Murray75e877d2013-09-11 14:45:20 -07001939 * Intrinsic for converting an Android YUV buffer to RGB.
1940 *
1941 * The input allocation should be supplied in a supported YUV format
1942 * as a YUV element Allocation. The output is RGBA; the alpha channel
1943 * will be set to 255.
1944 */
Tim Murray89daad62013-07-29 14:30:02 -07001945class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001946 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001947 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001948 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001949 /**
1950 * Create an intrinsic for converting YUV to RGB.
1951 *
1952 * Supported elements types are U8_4.
1953 *
1954 * @param[in] rs The RenderScript context
1955 * @param[in] e Element type for output
1956 *
1957 * @return ScriptIntrinsicYuvToRGB
1958 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001959 static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001960 /**
1961 * Set the input YUV allocation.
1962 *
1963 * @param[in] ain The input allocation.
1964 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001965 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001966
1967 /**
1968 * Convert the image to RGB.
1969 *
1970 * @param[in] aout Output allocation. Must match creation element
1971 * type.
1972 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001973 void forEach(sp<Allocation> out);
Tim Murray89daad62013-07-29 14:30:02 -07001974
1975};
Tim Murrayb27b1812013-08-05 14:00:40 -07001976
Tim Murray75e877d2013-09-11 14:45:20 -07001977/**
1978 * Sampler object that defines how Allocations can be read as textures
1979 * within a kernel. Samplers are used in conjunction with the rsSample
1980 * runtime function to return values from normalized coordinates.
1981 *
1982 * Any Allocation used with a Sampler must have been created with
1983 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an
1984 * Allocation that was not created with
1985 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined.
1986 **/
Tim Murray729b6fe2013-07-23 16:20:42 -07001987 class Sampler : public BaseObj {
1988 private:
1989 Sampler(sp<RS> rs, void* id);
Miao Wange5428e62015-03-10 15:29:40 -07001990 Sampler(sp<RS> rs, void* id, RsSamplerValue min, RsSamplerValue mag,
1991 RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
Tim Murray729b6fe2013-07-23 16:20:42 -07001992 RsSamplerValue mMin;
1993 RsSamplerValue mMag;
1994 RsSamplerValue mWrapS;
1995 RsSamplerValue mWrapT;
Tim Murray729b6fe2013-07-23 16:20:42 -07001996 float mAniso;
1997
1998 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001999 /**
2000 * Creates a non-standard Sampler.
2001 * @param[in] rs RenderScript context
2002 * @param[in] min minification
2003 * @param[in] mag magnification
2004 * @param[in] wrapS S wrapping mode
2005 * @param[in] wrapT T wrapping mode
2006 * @param[in] anisotropy anisotropy setting
2007 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002008 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
2009
Tim Murray75e877d2013-09-11 14:45:20 -07002010 /**
2011 * @return minification setting for the sampler
2012 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002013 RsSamplerValue getMinification();
Tim Murray75e877d2013-09-11 14:45:20 -07002014 /**
2015 * @return magnification setting for the sampler
2016 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002017 RsSamplerValue getMagnification();
Tim Murray75e877d2013-09-11 14:45:20 -07002018 /**
2019 * @return S wrapping mode for the sampler
2020 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002021 RsSamplerValue getWrapS();
Tim Murray75e877d2013-09-11 14:45:20 -07002022 /**
2023 * @return T wrapping mode for the sampler
2024 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002025 RsSamplerValue getWrapT();
Tim Murray75e877d2013-09-11 14:45:20 -07002026 /**
2027 * @return anisotropy setting for the sampler
2028 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002029 float getAnisotropy();
2030
Tim Murray75e877d2013-09-11 14:45:20 -07002031 /**
2032 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2033 * clamp.
2034 *
2035 * @param rs Context to which the sampler will belong.
2036 *
2037 * @return Sampler
2038 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002039 static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002040 /**
2041 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2042 * clamp.
2043 *
2044 * @param rs Context to which the sampler will belong.
2045 *
2046 * @return Sampler
2047 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002048 static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002049 /**
2050 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2051 * wrap modes set to clamp.
2052 *
2053 * @param rs Context to which the sampler will belong.
2054 *
2055 * @return Sampler
2056 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002057 static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002058 /**
2059 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2060 * wrap.
2061 *
2062 * @param rs Context to which the sampler will belong.
2063 *
2064 * @return Sampler
2065 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002066 static sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002067 /**
2068 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2069 * wrap.
2070 *
2071 * @param rs Context to which the sampler will belong.
2072 *
2073 * @return Sampler
2074 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002075 static sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002076 /**
2077 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2078 * wrap modes set to wrap.
2079 *
2080 * @param rs Context to which the sampler will belong.
2081 *
2082 * @return Sampler
2083 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002084 static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002085 /**
2086 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2087 * mirrored repeat.
2088 *
2089 * @param rs Context to which the sampler will belong.
2090 *
2091 * @return Sampler
2092 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002093 static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002094 /**
2095 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2096 * mirrored repeat.
2097 *
2098 * @param rs Context to which the sampler will belong.
2099 *
2100 * @return Sampler
2101 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002102 static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002103 /**
2104 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2105 * mirrored repeat.
2106 *
2107 * @param rs Context to which the sampler will belong.
2108 *
2109 * @return Sampler
2110 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002111 static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray729b6fe2013-07-23 16:20:42 -07002112
2113};
2114
Stephen Hinesd10412f2013-08-29 18:27:21 -07002115class Byte2 {
2116 public:
2117 int8_t x, y;
2118
2119 Byte2(int8_t initX, int8_t initY)
2120 : x(initX), y(initY) {}
2121 Byte2() : x(0), y(0) {}
2122};
2123
2124class Byte3 {
2125 public:
2126 int8_t x, y, z;
2127
2128 Byte3(int8_t initX, int8_t initY, int8_t initZ)
2129 : x(initX), y(initY), z(initZ) {}
2130 Byte3() : x(0), y(0), z(0) {}
2131};
2132
2133class Byte4 {
2134 public:
2135 int8_t x, y, z, w;
2136
2137 Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
2138 : x(initX), y(initY), z(initZ), w(initW) {}
2139 Byte4() : x(0), y(0), z(0), w(0) {}
2140};
2141
2142class UByte2 {
2143 public:
2144 uint8_t x, y;
2145
2146 UByte2(uint8_t initX, uint8_t initY)
2147 : x(initX), y(initY) {}
2148 UByte2() : x(0), y(0) {}
2149};
2150
2151class UByte3 {
2152 public:
2153 uint8_t x, y, z;
2154
2155 UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
2156 : x(initX), y(initY), z(initZ) {}
2157 UByte3() : x(0), y(0), z(0) {}
2158};
2159
2160class UByte4 {
2161 public:
2162 uint8_t x, y, z, w;
2163
2164 UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
2165 : x(initX), y(initY), z(initZ), w(initW) {}
2166 UByte4() : x(0), y(0), z(0), w(0) {}
2167};
2168
2169class Short2 {
2170 public:
2171 short x, y;
2172
2173 Short2(short initX, short initY)
2174 : x(initX), y(initY) {}
2175 Short2() : x(0), y(0) {}
2176};
2177
2178class Short3 {
2179 public:
2180 short x, y, z;
2181
2182 Short3(short initX, short initY, short initZ)
2183 : x(initX), y(initY), z(initZ) {}
2184 Short3() : x(0), y(0), z(0) {}
2185};
2186
2187class Short4 {
2188 public:
2189 short x, y, z, w;
2190
2191 Short4(short initX, short initY, short initZ, short initW)
2192 : x(initX), y(initY), z(initZ), w(initW) {}
2193 Short4() : x(0), y(0), z(0), w(0) {}
2194};
2195
2196class UShort2 {
2197 public:
2198 uint16_t x, y;
2199
2200 UShort2(uint16_t initX, uint16_t initY)
2201 : x(initX), y(initY) {}
2202 UShort2() : x(0), y(0) {}
2203};
2204
2205class UShort3 {
2206 public:
2207 uint16_t x, y, z;
2208
2209 UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
2210 : x(initX), y(initY), z(initZ) {}
2211 UShort3() : x(0), y(0), z(0) {}
2212};
2213
2214class UShort4 {
2215 public:
2216 uint16_t x, y, z, w;
2217
2218 UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
2219 : x(initX), y(initY), z(initZ), w(initW) {}
2220 UShort4() : x(0), y(0), z(0), w(0) {}
2221};
2222
2223class Int2 {
2224 public:
2225 int x, y;
2226
2227 Int2(int initX, int initY)
2228 : x(initX), y(initY) {}
2229 Int2() : x(0), y(0) {}
2230};
2231
2232class Int3 {
2233 public:
2234 int x, y, z;
2235
2236 Int3(int initX, int initY, int initZ)
2237 : x(initX), y(initY), z(initZ) {}
2238 Int3() : x(0), y(0), z(0) {}
2239};
2240
2241class Int4 {
2242 public:
2243 int x, y, z, w;
2244
2245 Int4(int initX, int initY, int initZ, int initW)
2246 : x(initX), y(initY), z(initZ), w(initW) {}
2247 Int4() : x(0), y(0), z(0), w(0) {}
2248};
2249
2250class UInt2 {
2251 public:
2252 uint32_t x, y;
2253
2254 UInt2(uint32_t initX, uint32_t initY)
2255 : x(initX), y(initY) {}
2256 UInt2() : x(0), y(0) {}
2257};
2258
2259class UInt3 {
2260 public:
2261 uint32_t x, y, z;
2262
2263 UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
2264 : x(initX), y(initY), z(initZ) {}
2265 UInt3() : x(0), y(0), z(0) {}
2266};
2267
2268class UInt4 {
2269 public:
2270 uint32_t x, y, z, w;
2271
2272 UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
2273 : x(initX), y(initY), z(initZ), w(initW) {}
2274 UInt4() : x(0), y(0), z(0), w(0) {}
2275};
2276
2277class Long2 {
2278 public:
2279 int64_t x, y;
2280
2281 Long2(int64_t initX, int64_t initY)
2282 : x(initX), y(initY) {}
2283 Long2() : x(0), y(0) {}
2284};
2285
2286class Long3 {
2287 public:
2288 int64_t x, y, z;
2289
2290 Long3(int64_t initX, int64_t initY, int64_t initZ)
2291 : x(initX), y(initY), z(initZ) {}
2292 Long3() : x(0), y(0), z(0) {}
2293};
2294
2295class Long4 {
2296 public:
2297 int64_t x, y, z, w;
2298
2299 Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
2300 : x(initX), y(initY), z(initZ), w(initW) {}
2301 Long4() : x(0), y(0), z(0), w(0) {}
2302};
2303
2304class ULong2 {
2305 public:
2306 uint64_t x, y;
2307
2308 ULong2(uint64_t initX, uint64_t initY)
2309 : x(initX), y(initY) {}
2310 ULong2() : x(0), y(0) {}
2311};
2312
2313class ULong3 {
2314 public:
2315 uint64_t x, y, z;
2316
2317 ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
2318 : x(initX), y(initY), z(initZ) {}
2319 ULong3() : x(0), y(0), z(0) {}
2320};
2321
2322class ULong4 {
2323 public:
2324 uint64_t x, y, z, w;
2325
2326 ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
2327 : x(initX), y(initY), z(initZ), w(initW) {}
2328 ULong4() : x(0), y(0), z(0), w(0) {}
2329};
2330
2331class Float2 {
2332 public:
2333 float x, y;
2334
2335 Float2(float initX, float initY)
2336 : x(initX), y(initY) {}
2337 Float2() : x(0), y(0) {}
2338};
2339
2340class Float3 {
2341 public:
2342 float x, y, z;
2343
2344 Float3(float initX, float initY, float initZ)
2345 : x(initX), y(initY), z(initZ) {}
2346 Float3() : x(0.f), y(0.f), z(0.f) {}
2347};
2348
2349class Float4 {
2350 public:
2351 float x, y, z, w;
2352
2353 Float4(float initX, float initY, float initZ, float initW)
2354 : x(initX), y(initY), z(initZ), w(initW) {}
2355 Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
2356};
2357
2358class Double2 {
2359 public:
2360 double x, y;
2361
2362 Double2(double initX, double initY)
2363 : x(initX), y(initY) {}
2364 Double2() : x(0), y(0) {}
2365};
2366
2367class Double3 {
2368 public:
2369 double x, y, z;
2370
2371 Double3(double initX, double initY, double initZ)
2372 : x(initX), y(initY), z(initZ) {}
2373 Double3() : x(0), y(0), z(0) {}
2374};
2375
2376class Double4 {
2377 public:
2378 double x, y, z, w;
2379
2380 Double4(double initX, double initY, double initZ, double initW)
2381 : x(initX), y(initY), z(initZ), w(initW) {}
2382 Double4() : x(0), y(0), z(0), w(0) {}
2383};
2384
Tim Murray84bf2b82012-10-31 16:03:16 -07002385}
Tim Murray7f0d5682012-11-08 16:35:24 -08002386
Tim Murray84bf2b82012-10-31 16:03:16 -07002387}
2388
2389#endif