blob: fd531f16703143aaad47c79acce640ffdf995620 [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;
Matt Wala394e9a62015-08-03 11:35:55 -07001404 void reduce(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
1405 const RsScriptCall *sc) const;
Tim Murray84bf2b82012-10-31 16:03:16 -07001406 void bindAllocation(sp<Allocation> va, uint32_t slot) const;
1407 void setVar(uint32_t index, const void *, size_t len) const;
1408 void setVar(uint32_t index, sp<const BaseObj> o) const;
1409 void invoke(uint32_t slot, const void *v, size_t len) const;
1410
1411
1412 void invoke(uint32_t slot) const {
1413 invoke(slot, NULL, 0);
1414 }
1415 void setVar(uint32_t index, float v) const {
1416 setVar(index, &v, sizeof(v));
1417 }
1418 void setVar(uint32_t index, double v) const {
1419 setVar(index, &v, sizeof(v));
1420 }
1421 void setVar(uint32_t index, int32_t v) const {
1422 setVar(index, &v, sizeof(v));
1423 }
Jon Parrb05c8502015-03-13 14:41:58 +00001424 void setVar(uint32_t index, uint32_t v) const {
1425 setVar(index, &v, sizeof(v));
1426 }
Tim Murray84bf2b82012-10-31 16:03:16 -07001427 void setVar(uint32_t index, int64_t v) const {
1428 setVar(index, &v, sizeof(v));
1429 }
1430 void setVar(uint32_t index, bool v) const {
1431 setVar(index, &v, sizeof(v));
1432 }
1433
1434public:
1435 class FieldBase {
1436 protected:
1437 sp<const Element> mElement;
1438 sp<Allocation> mAllocation;
1439
1440 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
1441
1442 public:
1443 sp<const Element> getElement() {
1444 return mElement;
1445 }
1446
1447 sp<const Type> getType() {
1448 return mAllocation->getType();
1449 }
1450
1451 sp<const Allocation> getAllocation() {
1452 return mAllocation;
1453 }
1454
1455 //void updateAllocation();
1456 };
1457};
1458
Tim Murray75e877d2013-09-11 14:45:20 -07001459/**
1460 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only.
1461 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001462class ScriptC : public Script {
1463protected:
1464 ScriptC(sp<RS> rs,
1465 const void *codeTxt, size_t codeLength,
1466 const char *cachedName, size_t cachedNameLength,
1467 const char *cacheDir, size_t cacheDirLength);
1468
1469};
1470
Tim Murray75e877d2013-09-11 14:45:20 -07001471/**
1472 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of
1473 * basic functions. This is not intended to be used directly.
1474 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001475class ScriptIntrinsic : public Script {
1476 protected:
Tim Murray10913a52013-08-20 17:19:47 -07001477 sp<const Element> mElement;
Tim Murray3cd44af2012-11-14 11:25:27 -08001478 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001479 virtual ~ScriptIntrinsic();
Tim Murray7f0d5682012-11-08 16:35:24 -08001480};
1481
Tim Murray75e877d2013-09-11 14:45:20 -07001482/**
1483 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming
1484 * r,g,b values are use as normalized x,y,z coordinates into a 3D
1485 * allocation. The 8 nearest values are sampled and linearly interpolated. The
1486 * result is placed in the output.
1487 */
Tim Murray89daad62013-07-29 14:30:02 -07001488class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001489 private:
Tim Murray89daad62013-07-29 14:30:02 -07001490 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001491 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001492 /**
1493 * Supported Element types are U8_4. Default lookup table is identity.
1494 * @param[in] rs RenderScript context
1495 * @param[in] e Element
1496 * @return new ScriptIntrinsic
1497 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001498 static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001499
1500 /**
1501 * Launch the intrinsic.
1502 * @param[in] ain input Allocation
1503 * @param[in] aout output Allocation
1504 */
Tim Murray89daad62013-07-29 14:30:02 -07001505 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001506
1507 /**
1508 * Sets the lookup table. The lookup table must use the same Element as the
1509 * intrinsic.
1510 * @param[in] lut new lookup table
1511 */
Tim Murray89daad62013-07-29 14:30:02 -07001512 void setLUT(sp<Allocation> lut);
1513};
1514
Tim Murray75e877d2013-09-11 14:45:20 -07001515/**
1516 * Intrinsic kernel for blending two Allocations.
1517 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001518class ScriptIntrinsicBlend : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001519 private:
Tim Murray89daad62013-07-29 14:30:02 -07001520 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001521 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001522 /**
1523 * Supported Element types are U8_4.
1524 * @param[in] rs RenderScript context
1525 * @param[in] e Element
1526 * @return new ScriptIntrinsicBlend
1527 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001528 static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001529 /**
1530 * sets dst = {0, 0, 0, 0}
1531 * @param[in] in input Allocation
1532 * @param[in] out output Allocation
1533 */
1534 void forEachClear(sp<Allocation> in, sp<Allocation> out);
1535 /**
1536 * Sets dst = src
1537 * @param[in] in input Allocation
1538 * @param[in] out output Allocation
1539 */
1540 void forEachSrc(sp<Allocation> in, sp<Allocation> out);
1541 /**
1542 * Sets dst = dst (NOP)
1543 * @param[in] in input Allocation
1544 * @param[in] out output Allocation
1545 */
1546 void forEachDst(sp<Allocation> in, sp<Allocation> out);
1547 /**
1548 * Sets dst = src + dst * (1.0 - src.a)
1549 * @param[in] in input Allocation
1550 * @param[in] out output Allocation
1551 */
1552 void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
1553 /**
1554 * Sets dst = dst + src * (1.0 - dst.a)
1555 * @param[in] in input Allocation
1556 * @param[in] out output Allocation
1557 */
1558 void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
1559 /**
1560 * Sets dst = src * dst.a
1561 * @param[in] in input Allocation
1562 * @param[in] out output Allocation
1563 */
1564 void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
1565 /**
1566 * Sets dst = dst * src.a
1567 * @param[in] in input Allocation
1568 * @param[in] out output Allocation
1569 */
1570 void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
1571 /**
1572 * Sets dst = src * (1.0 - dst.a)
1573 * @param[in] in input Allocation
1574 * @param[in] out output Allocation
1575 */
1576 void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
1577 /**
1578 * Sets dst = dst * (1.0 - src.a)
1579 * @param[in] in input Allocation
1580 * @param[in] out output Allocation
1581 */
1582 void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
1583 /**
1584 * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
1585 * @param[in] in input Allocation
1586 * @param[in] out output Allocation
1587 */
1588 void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
1589 /**
1590 * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
1591 * @param[in] in input Allocation
1592 * @param[in] out output Allocation
1593 */
1594 void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
1595 /**
1596 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
1597 * @param[in] in input Allocation
1598 * @param[in] out output Allocation
1599 */
1600 void forEachXor(sp<Allocation> in, sp<Allocation> out);
1601 /**
1602 * Sets dst = src * dst
1603 * @param[in] in input Allocation
1604 * @param[in] out output Allocation
1605 */
1606 void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
1607 /**
1608 * Sets dst = min(src + dst, 1.0)
1609 * @param[in] in input Allocation
1610 * @param[in] out output Allocation
1611 */
1612 void forEachAdd(sp<Allocation> in, sp<Allocation> out);
1613 /**
1614 * Sets dst = max(dst - src, 0.0)
1615 * @param[in] in input Allocation
1616 * @param[in] out output Allocation
1617 */
1618 void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
Tim Murray7f0d5682012-11-08 16:35:24 -08001619};
Tim Murray84bf2b82012-10-31 16:03:16 -07001620
Tim Murray75e877d2013-09-11 14:45:20 -07001621/**
1622 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified
1623 * radius to all elements of an Allocation.
1624 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001625class ScriptIntrinsicBlur : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001626 private:
Tim Murray89daad62013-07-29 14:30:02 -07001627 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001628 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001629 /**
1630 * Supported Element types are U8 and U8_4.
1631 * @param[in] rs RenderScript context
1632 * @param[in] e Element
1633 * @return new ScriptIntrinsicBlur
1634 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001635 static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001636 /**
1637 * Sets the input of the blur.
1638 * @param[in] in input Allocation
1639 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001640 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001641 /**
1642 * Runs the intrinsic.
1643 * @param[in] output Allocation
1644 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001645 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001646 /**
1647 * Sets the radius of the blur. The supported range is 0 < radius <= 25.
1648 * @param[in] radius radius of the blur
1649 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001650 void setRadius(float radius);
1651};
1652
Tim Murray75e877d2013-09-11 14:45:20 -07001653/**
1654 * Intrinsic for applying a color matrix to allocations. This has the
1655 * same effect as loading each element and converting it to a
1656 * F32_N, multiplying the result by the 4x4 color matrix
1657 * as performed by rsMatrixMultiply() and writing it to the output
1658 * after conversion back to U8_N or F32_N.
1659 */
Tim Murray89daad62013-07-29 14:30:02 -07001660class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001661 private:
Tim Murray89daad62013-07-29 14:30:02 -07001662 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001663 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001664 /**
1665 * Creates a new intrinsic.
1666 * @param[in] rs RenderScript context
1667 * @return new ScriptIntrinsicColorMatrix
1668 */
Tim Murrayaae73c92013-09-03 17:05:46 -07001669 static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001670 /**
1671 * Applies the color matrix. Supported types are U8 and F32 with
1672 * vector lengths between 1 and 4.
1673 * @param[in] in input Allocation
1674 * @param[out] out output Allocation
1675 */
Tim Murray89daad62013-07-29 14:30:02 -07001676 void forEach(sp<Allocation> in, sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001677 /**
1678 * Set the value to be added after the color matrix has been
1679 * applied. The default value is {0, 0, 0, 0}.
1680 * @param[in] add float[4] of values
1681 */
Tim Murray10913a52013-08-20 17:19:47 -07001682 void setAdd(float* add);
Tim Murray75e877d2013-09-11 14:45:20 -07001683
1684 /**
1685 * Set the color matrix which will be applied to each cell of the
1686 * image. The alpha channel will be copied.
1687 *
1688 * @param[in] m float[9] of values
1689 */
Tim Murray89daad62013-07-29 14:30:02 -07001690 void setColorMatrix3(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001691 /**
1692 * Set the color matrix which will be applied to each cell of the
1693 * image.
1694 *
1695 * @param[in] m float[16] of values
1696 */
Tim Murray89daad62013-07-29 14:30:02 -07001697 void setColorMatrix4(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001698 /**
1699 * Set a color matrix to convert from RGB to luminance. The alpha
1700 * channel will be a copy.
1701 */
Tim Murray89daad62013-07-29 14:30:02 -07001702 void setGreyscale();
Tim Murray75e877d2013-09-11 14:45:20 -07001703 /**
1704 * Set the matrix to convert from RGB to YUV with a direct copy of
1705 * the 4th channel.
1706 */
Tim Murray89daad62013-07-29 14:30:02 -07001707 void setRGBtoYUV();
Tim Murray75e877d2013-09-11 14:45:20 -07001708 /**
1709 * Set the matrix to convert from YUV to RGB with a direct copy of
1710 * the 4th channel.
1711 */
Tim Murray89daad62013-07-29 14:30:02 -07001712 void setYUVtoRGB();
1713};
1714
Tim Murray75e877d2013-09-11 14:45:20 -07001715/**
1716 * Intrinsic for applying a 3x3 convolve to an allocation.
1717 */
Tim Murray89daad62013-07-29 14:30:02 -07001718class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001719 private:
Tim Murray89daad62013-07-29 14:30:02 -07001720 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001721 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001722 /**
1723 * Supported types U8 and F32 with vector lengths between 1 and
1724 * 4. The default convolution kernel is the identity.
1725 * @param[in] rs RenderScript context
1726 * @param[in] e Element
1727 * @return new ScriptIntrinsicConvolve3x3
1728 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001729 static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001730 /**
1731 * Sets input for intrinsic.
1732 * @param[in] in input Allocation
1733 */
Tim Murray89daad62013-07-29 14:30:02 -07001734 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001735 /**
1736 * Launches the intrinsic.
1737 * @param[in] out output Allocation
1738 */
Tim Murray89daad62013-07-29 14:30:02 -07001739 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001740 /**
1741 * Sets convolution kernel.
1742 * @param[in] v float[9] of values
1743 */
Tim Murray89daad62013-07-29 14:30:02 -07001744 void setCoefficients(float* v);
1745};
1746
Tim Murray75e877d2013-09-11 14:45:20 -07001747/**
1748 * Intrinsic for applying a 5x5 convolve to an allocation.
1749 */
Tim Murray89daad62013-07-29 14:30:02 -07001750class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001751 private:
Tim Murray89daad62013-07-29 14:30:02 -07001752 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001753 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001754 /**
1755 * Supported types U8 and F32 with vector lengths between 1 and
1756 * 4. The default convolution kernel is the identity.
1757 * @param[in] rs RenderScript context
1758 * @param[in] e Element
1759 * @return new ScriptIntrinsicConvolve5x5
1760 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001761 static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001762 /**
1763 * Sets input for intrinsic.
1764 * @param[in] in input Allocation
1765 */
Tim Murray89daad62013-07-29 14:30:02 -07001766 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001767 /**
1768 * Launches the intrinsic.
1769 * @param[in] out output Allocation
1770 */
Tim Murray89daad62013-07-29 14:30:02 -07001771 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001772 /**
1773 * Sets convolution kernel.
1774 * @param[in] v float[25] of values
1775 */
Tim Murray89daad62013-07-29 14:30:02 -07001776 void setCoefficients(float* v);
1777};
1778
Tim Murray75e877d2013-09-11 14:45:20 -07001779/**
1780 * Intrinsic for computing a histogram.
1781 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001782class ScriptIntrinsicHistogram : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001783 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001784 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
Tim Murray10913a52013-08-20 17:19:47 -07001785 sp<Allocation> mOut;
Tim Murray21fa7a02013-08-15 16:25:03 -07001786 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001787 /**
1788 * Create an intrinsic for calculating the histogram of an uchar
1789 * or uchar4 image.
1790 *
1791 * Supported elements types are U8_4, U8_3, U8_2, and U8.
1792 *
1793 * @param[in] rs The RenderScript context
1794 * @param[in] e Element type for inputs
1795 *
1796 * @return ScriptIntrinsicHistogram
1797 */
Jon Parrb05c8502015-03-13 14:41:58 +00001798 static sp<ScriptIntrinsicHistogram> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001799 /**
1800 * Set the output of the histogram. 32 bit integer types are
1801 * supported.
1802 *
1803 * @param[in] aout The output allocation
1804 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001805 void setOutput(sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001806 /**
1807 * Set the coefficients used for the dot product calculation. The
1808 * default is {0.299f, 0.587f, 0.114f, 0.f}.
1809 *
1810 * Coefficients must be >= 0 and sum to 1.0 or less.
1811 *
1812 * @param[in] r Red coefficient
1813 * @param[in] g Green coefficient
1814 * @param[in] b Blue coefficient
1815 * @param[in] a Alpha coefficient
1816 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001817 void setDotCoefficients(float r, float g, float b, float a);
Tim Murray75e877d2013-09-11 14:45:20 -07001818 /**
1819 * Process an input buffer and place the histogram into the output
1820 * allocation. The output allocation may be a narrower vector size
1821 * than the input. In this case the vector size of the output is
1822 * used to determine how many of the input channels are used in
1823 * the computation. This is useful if you have an RGBA input
1824 * buffer but only want the histogram for RGB.
1825 *
1826 * 1D and 2D input allocations are supported.
1827 *
1828 * @param[in] ain The input image
1829 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001830 void forEach(sp<Allocation> ain);
Tim Murray75e877d2013-09-11 14:45:20 -07001831 /**
1832 * Process an input buffer and place the histogram into the output
1833 * allocation. The dot product of the input channel and the
1834 * coefficients from 'setDotCoefficients' are used to calculate
1835 * the output values.
1836 *
1837 * 1D and 2D input allocations are supported.
1838 *
1839 * @param ain The input image
1840 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001841 void forEach_dot(sp<Allocation> ain);
1842};
1843
Tim Murray75e877d2013-09-11 14:45:20 -07001844/**
1845 * Intrinsic for applying a per-channel lookup table. Each channel of
1846 * the input has an independant lookup table. The tables are 256
1847 * entries in size and can cover the full value range of U8_4.
1848 **/
Tim Murrayb27b1812013-08-05 14:00:40 -07001849class ScriptIntrinsicLUT : public ScriptIntrinsic {
1850 private:
1851 sp<Allocation> LUT;
1852 bool mDirty;
1853 unsigned char mCache[1024];
Tim Murray2acce992013-08-28 14:23:31 -07001854 void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray21fa7a02013-08-15 16:25:03 -07001855 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001856
Tim Murray89daad62013-07-29 14:30:02 -07001857 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001858 /**
1859 * Supported elements types are U8_4.
1860 *
1861 * The defaults tables are identity.
1862 *
1863 * @param[in] rs The RenderScript context
1864 * @param[in] e Element type for intputs and outputs
1865 *
1866 * @return ScriptIntrinsicLUT
1867 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001868 static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001869 /**
1870 * Invoke the kernel and apply the lookup to each cell of ain and
1871 * copy to aout.
1872 *
1873 * @param[in] ain Input allocation
1874 * @param[in] aout Output allocation
1875 */
Tim Murray89daad62013-07-29 14:30:02 -07001876 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001877 /**
1878 * Sets entries in LUT for the red channel.
1879 * @param[in] base base of region to update
1880 * @param[in] length length of region to update
1881 * @param[in] lutValues LUT values to use
1882 */
Tim Murray2acce992013-08-28 14:23:31 -07001883 void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001884 /**
1885 * Sets entries in LUT for the green channel.
1886 * @param[in] base base of region to update
1887 * @param[in] length length of region to update
1888 * @param[in] lutValues LUT values to use
1889 */
Tim Murray2acce992013-08-28 14:23:31 -07001890 void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001891 /**
1892 * Sets entries in LUT for the blue channel.
1893 * @param[in] base base of region to update
1894 * @param[in] length length of region to update
1895 * @param[in] lutValues LUT values to use
1896 */
Tim Murray2acce992013-08-28 14:23:31 -07001897 void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001898 /**
1899 * Sets entries in LUT for the alpha channel.
1900 * @param[in] base base of region to update
1901 * @param[in] length length of region to update
1902 * @param[in] lutValues LUT values to use
1903 */
Tim Murray2acce992013-08-28 14:23:31 -07001904 void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murrayb27b1812013-08-05 14:00:40 -07001905 virtual ~ScriptIntrinsicLUT();
1906};
1907
Tim Murray75e877d2013-09-11 14:45:20 -07001908/**
Miao Wange5428e62015-03-10 15:29:40 -07001909 * Intrinsic for performing a resize of a 2D allocation.
1910 */
1911class ScriptIntrinsicResize : public ScriptIntrinsic {
1912 private:
1913 sp<Allocation> mInput;
1914 ScriptIntrinsicResize(sp<RS> rs, sp<const Element> e);
1915 public:
1916 /**
1917 * Supported Element types are U8_4. Default lookup table is identity.
1918 * @param[in] rs RenderScript context
1919 * @param[in] e Element
1920 * @return new ScriptIntrinsic
1921 */
1922 static sp<ScriptIntrinsicResize> create(sp<RS> rs);
1923
1924 /**
1925 * Resize copy the input allocation to the output specified. The
1926 * Allocation is rescaled if necessary using bi-cubic
1927 * interpolation.
1928 * @param[in] ain input Allocation
1929 * @param[in] aout output Allocation
1930 */
1931 void forEach_bicubic(sp<Allocation> aout);
1932
1933 /**
1934 * Set the input of the resize.
1935 * @param[in] lut new lookup table
1936 */
1937 void setInput(sp<Allocation> ain);
1938};
1939
1940/**
Tim Murray75e877d2013-09-11 14:45:20 -07001941 * Intrinsic for converting an Android YUV buffer to RGB.
1942 *
1943 * The input allocation should be supplied in a supported YUV format
1944 * as a YUV element Allocation. The output is RGBA; the alpha channel
1945 * will be set to 255.
1946 */
Tim Murray89daad62013-07-29 14:30:02 -07001947class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001948 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001949 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001950 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001951 /**
1952 * Create an intrinsic for converting YUV to RGB.
1953 *
1954 * Supported elements types are U8_4.
1955 *
1956 * @param[in] rs The RenderScript context
1957 * @param[in] e Element type for output
1958 *
1959 * @return ScriptIntrinsicYuvToRGB
1960 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001961 static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001962 /**
1963 * Set the input YUV allocation.
1964 *
1965 * @param[in] ain The input allocation.
1966 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001967 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001968
1969 /**
1970 * Convert the image to RGB.
1971 *
1972 * @param[in] aout Output allocation. Must match creation element
1973 * type.
1974 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001975 void forEach(sp<Allocation> out);
Tim Murray89daad62013-07-29 14:30:02 -07001976
1977};
Tim Murrayb27b1812013-08-05 14:00:40 -07001978
Tim Murray75e877d2013-09-11 14:45:20 -07001979/**
1980 * Sampler object that defines how Allocations can be read as textures
1981 * within a kernel. Samplers are used in conjunction with the rsSample
1982 * runtime function to return values from normalized coordinates.
1983 *
1984 * Any Allocation used with a Sampler must have been created with
1985 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an
1986 * Allocation that was not created with
1987 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined.
1988 **/
Tim Murray729b6fe2013-07-23 16:20:42 -07001989 class Sampler : public BaseObj {
1990 private:
1991 Sampler(sp<RS> rs, void* id);
Miao Wange5428e62015-03-10 15:29:40 -07001992 Sampler(sp<RS> rs, void* id, RsSamplerValue min, RsSamplerValue mag,
1993 RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
Tim Murray729b6fe2013-07-23 16:20:42 -07001994 RsSamplerValue mMin;
1995 RsSamplerValue mMag;
1996 RsSamplerValue mWrapS;
1997 RsSamplerValue mWrapT;
Tim Murray729b6fe2013-07-23 16:20:42 -07001998 float mAniso;
1999
2000 public:
Tim Murray75e877d2013-09-11 14:45:20 -07002001 /**
2002 * Creates a non-standard Sampler.
2003 * @param[in] rs RenderScript context
2004 * @param[in] min minification
2005 * @param[in] mag magnification
2006 * @param[in] wrapS S wrapping mode
2007 * @param[in] wrapT T wrapping mode
2008 * @param[in] anisotropy anisotropy setting
2009 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002010 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
2011
Tim Murray75e877d2013-09-11 14:45:20 -07002012 /**
2013 * @return minification setting for the sampler
2014 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002015 RsSamplerValue getMinification();
Tim Murray75e877d2013-09-11 14:45:20 -07002016 /**
2017 * @return magnification setting for the sampler
2018 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002019 RsSamplerValue getMagnification();
Tim Murray75e877d2013-09-11 14:45:20 -07002020 /**
2021 * @return S wrapping mode for the sampler
2022 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002023 RsSamplerValue getWrapS();
Tim Murray75e877d2013-09-11 14:45:20 -07002024 /**
2025 * @return T wrapping mode for the sampler
2026 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002027 RsSamplerValue getWrapT();
Tim Murray75e877d2013-09-11 14:45:20 -07002028 /**
2029 * @return anisotropy setting for the sampler
2030 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002031 float getAnisotropy();
2032
Tim Murray75e877d2013-09-11 14:45:20 -07002033 /**
2034 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2035 * clamp.
2036 *
2037 * @param rs Context to which the sampler will belong.
2038 *
2039 * @return Sampler
2040 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002041 static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002042 /**
2043 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2044 * clamp.
2045 *
2046 * @param rs Context to which the sampler will belong.
2047 *
2048 * @return Sampler
2049 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002050 static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002051 /**
2052 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2053 * wrap modes set to clamp.
2054 *
2055 * @param rs Context to which the sampler will belong.
2056 *
2057 * @return Sampler
2058 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002059 static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002060 /**
2061 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2062 * wrap.
2063 *
2064 * @param rs Context to which the sampler will belong.
2065 *
2066 * @return Sampler
2067 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002068 static sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002069 /**
2070 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2071 * wrap.
2072 *
2073 * @param rs Context to which the sampler will belong.
2074 *
2075 * @return Sampler
2076 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002077 static sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002078 /**
2079 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2080 * wrap modes set to wrap.
2081 *
2082 * @param rs Context to which the sampler will belong.
2083 *
2084 * @return Sampler
2085 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002086 static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002087 /**
2088 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2089 * mirrored repeat.
2090 *
2091 * @param rs Context to which the sampler will belong.
2092 *
2093 * @return Sampler
2094 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002095 static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002096 /**
2097 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2098 * mirrored repeat.
2099 *
2100 * @param rs Context to which the sampler will belong.
2101 *
2102 * @return Sampler
2103 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002104 static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002105 /**
2106 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2107 * mirrored repeat.
2108 *
2109 * @param rs Context to which the sampler will belong.
2110 *
2111 * @return Sampler
2112 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002113 static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray729b6fe2013-07-23 16:20:42 -07002114
2115};
2116
Stephen Hinesd10412f2013-08-29 18:27:21 -07002117class Byte2 {
2118 public:
2119 int8_t x, y;
2120
2121 Byte2(int8_t initX, int8_t initY)
2122 : x(initX), y(initY) {}
2123 Byte2() : x(0), y(0) {}
2124};
2125
2126class Byte3 {
2127 public:
2128 int8_t x, y, z;
2129
2130 Byte3(int8_t initX, int8_t initY, int8_t initZ)
2131 : x(initX), y(initY), z(initZ) {}
2132 Byte3() : x(0), y(0), z(0) {}
2133};
2134
2135class Byte4 {
2136 public:
2137 int8_t x, y, z, w;
2138
2139 Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
2140 : x(initX), y(initY), z(initZ), w(initW) {}
2141 Byte4() : x(0), y(0), z(0), w(0) {}
2142};
2143
2144class UByte2 {
2145 public:
2146 uint8_t x, y;
2147
2148 UByte2(uint8_t initX, uint8_t initY)
2149 : x(initX), y(initY) {}
2150 UByte2() : x(0), y(0) {}
2151};
2152
2153class UByte3 {
2154 public:
2155 uint8_t x, y, z;
2156
2157 UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
2158 : x(initX), y(initY), z(initZ) {}
2159 UByte3() : x(0), y(0), z(0) {}
2160};
2161
2162class UByte4 {
2163 public:
2164 uint8_t x, y, z, w;
2165
2166 UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
2167 : x(initX), y(initY), z(initZ), w(initW) {}
2168 UByte4() : x(0), y(0), z(0), w(0) {}
2169};
2170
2171class Short2 {
2172 public:
2173 short x, y;
2174
2175 Short2(short initX, short initY)
2176 : x(initX), y(initY) {}
2177 Short2() : x(0), y(0) {}
2178};
2179
2180class Short3 {
2181 public:
2182 short x, y, z;
2183
2184 Short3(short initX, short initY, short initZ)
2185 : x(initX), y(initY), z(initZ) {}
2186 Short3() : x(0), y(0), z(0) {}
2187};
2188
2189class Short4 {
2190 public:
2191 short x, y, z, w;
2192
2193 Short4(short initX, short initY, short initZ, short initW)
2194 : x(initX), y(initY), z(initZ), w(initW) {}
2195 Short4() : x(0), y(0), z(0), w(0) {}
2196};
2197
2198class UShort2 {
2199 public:
2200 uint16_t x, y;
2201
2202 UShort2(uint16_t initX, uint16_t initY)
2203 : x(initX), y(initY) {}
2204 UShort2() : x(0), y(0) {}
2205};
2206
2207class UShort3 {
2208 public:
2209 uint16_t x, y, z;
2210
2211 UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
2212 : x(initX), y(initY), z(initZ) {}
2213 UShort3() : x(0), y(0), z(0) {}
2214};
2215
2216class UShort4 {
2217 public:
2218 uint16_t x, y, z, w;
2219
2220 UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
2221 : x(initX), y(initY), z(initZ), w(initW) {}
2222 UShort4() : x(0), y(0), z(0), w(0) {}
2223};
2224
2225class Int2 {
2226 public:
2227 int x, y;
2228
2229 Int2(int initX, int initY)
2230 : x(initX), y(initY) {}
2231 Int2() : x(0), y(0) {}
2232};
2233
2234class Int3 {
2235 public:
2236 int x, y, z;
2237
2238 Int3(int initX, int initY, int initZ)
2239 : x(initX), y(initY), z(initZ) {}
2240 Int3() : x(0), y(0), z(0) {}
2241};
2242
2243class Int4 {
2244 public:
2245 int x, y, z, w;
2246
2247 Int4(int initX, int initY, int initZ, int initW)
2248 : x(initX), y(initY), z(initZ), w(initW) {}
2249 Int4() : x(0), y(0), z(0), w(0) {}
2250};
2251
2252class UInt2 {
2253 public:
2254 uint32_t x, y;
2255
2256 UInt2(uint32_t initX, uint32_t initY)
2257 : x(initX), y(initY) {}
2258 UInt2() : x(0), y(0) {}
2259};
2260
2261class UInt3 {
2262 public:
2263 uint32_t x, y, z;
2264
2265 UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
2266 : x(initX), y(initY), z(initZ) {}
2267 UInt3() : x(0), y(0), z(0) {}
2268};
2269
2270class UInt4 {
2271 public:
2272 uint32_t x, y, z, w;
2273
2274 UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
2275 : x(initX), y(initY), z(initZ), w(initW) {}
2276 UInt4() : x(0), y(0), z(0), w(0) {}
2277};
2278
2279class Long2 {
2280 public:
2281 int64_t x, y;
2282
2283 Long2(int64_t initX, int64_t initY)
2284 : x(initX), y(initY) {}
2285 Long2() : x(0), y(0) {}
2286};
2287
2288class Long3 {
2289 public:
2290 int64_t x, y, z;
2291
2292 Long3(int64_t initX, int64_t initY, int64_t initZ)
2293 : x(initX), y(initY), z(initZ) {}
2294 Long3() : x(0), y(0), z(0) {}
2295};
2296
2297class Long4 {
2298 public:
2299 int64_t x, y, z, w;
2300
2301 Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
2302 : x(initX), y(initY), z(initZ), w(initW) {}
2303 Long4() : x(0), y(0), z(0), w(0) {}
2304};
2305
2306class ULong2 {
2307 public:
2308 uint64_t x, y;
2309
2310 ULong2(uint64_t initX, uint64_t initY)
2311 : x(initX), y(initY) {}
2312 ULong2() : x(0), y(0) {}
2313};
2314
2315class ULong3 {
2316 public:
2317 uint64_t x, y, z;
2318
2319 ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
2320 : x(initX), y(initY), z(initZ) {}
2321 ULong3() : x(0), y(0), z(0) {}
2322};
2323
2324class ULong4 {
2325 public:
2326 uint64_t x, y, z, w;
2327
2328 ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
2329 : x(initX), y(initY), z(initZ), w(initW) {}
2330 ULong4() : x(0), y(0), z(0), w(0) {}
2331};
2332
2333class Float2 {
2334 public:
2335 float x, y;
2336
2337 Float2(float initX, float initY)
2338 : x(initX), y(initY) {}
2339 Float2() : x(0), y(0) {}
2340};
2341
2342class Float3 {
2343 public:
2344 float x, y, z;
2345
2346 Float3(float initX, float initY, float initZ)
2347 : x(initX), y(initY), z(initZ) {}
2348 Float3() : x(0.f), y(0.f), z(0.f) {}
2349};
2350
2351class Float4 {
2352 public:
2353 float x, y, z, w;
2354
2355 Float4(float initX, float initY, float initZ, float initW)
2356 : x(initX), y(initY), z(initZ), w(initW) {}
2357 Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
2358};
2359
2360class Double2 {
2361 public:
2362 double x, y;
2363
2364 Double2(double initX, double initY)
2365 : x(initX), y(initY) {}
2366 Double2() : x(0), y(0) {}
2367};
2368
2369class Double3 {
2370 public:
2371 double x, y, z;
2372
2373 Double3(double initX, double initY, double initZ)
2374 : x(initX), y(initY), z(initZ) {}
2375 Double3() : x(0), y(0), z(0) {}
2376};
2377
2378class Double4 {
2379 public:
2380 double x, y, z, w;
2381
2382 Double4(double initX, double initY, double initZ, double initW)
2383 : x(initX), y(initY), z(initZ), w(initW) {}
2384 Double4() : x(0), y(0), z(0), w(0) {}
2385};
2386
Tim Murray84bf2b82012-10-31 16:03:16 -07002387}
Tim Murray7f0d5682012-11-08 16:35:24 -08002388
Tim Murray84bf2b82012-10-31 16:03:16 -07002389}
2390
2391#endif