blob: e7acbedc33ab43c58cbddce4be820f6949c31fb5 [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
85 RS_INIT_MAX = 16
Tim Murray84e3dea2013-09-09 16:12:51 -070086 };
87
Tim Murray75e877d2013-09-11 14:45:20 -070088 /**
89 * The RenderScript context. This class controls initialization, resource management, and teardown.
90 */
Tim Murray89daad62013-07-29 14:30:02 -070091 class RS : public android::RSC::LightRefBase<RS> {
Tim Murray84bf2b82012-10-31 16:03:16 -070092
93 public:
94 RS();
95 virtual ~RS();
96
Tim Murray75e877d2013-09-11 14:45:20 -070097 /**
98 * Initializes a RenderScript context. A context must be initialized before it can be used.
Tim Murraycaf41262013-12-13 12:54:37 -080099 * @param[in] name Directory name to be used by this context. This should be equivalent to
100 * Context.getCacheDir().
Tim Murray75e877d2013-09-11 14:45:20 -0700101 * @param[in] flags Optional flags for this context.
102 * @return true on success
103 */
Miao Wangbc10dff2015-04-03 17:44:55 -0700104 bool init(const char * name, uint32_t flags = 0);
Tim Murray84bf2b82012-10-31 16:03:16 -0700105
Tim Murray75e877d2013-09-11 14:45:20 -0700106 /**
107 * Sets the error handler function for this context. This error handler is
108 * called whenever an error is set.
109 *
110 * @param[in] func Error handler function
111 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700112 void setErrorHandler(ErrorHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700113
114 /**
115 * Returns the current error handler function for this context.
116 *
117 * @return pointer to current error handler function or NULL if not set
118 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700119 ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
120
Tim Murray75e877d2013-09-11 14:45:20 -0700121 /**
122 * Sets the message handler function for this context. This message handler
123 * is called whenever a message is sent from a RenderScript kernel.
124 *
125 * @param[in] func Message handler function
126 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700127 void setMessageHandler(MessageHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700128
129 /**
130 * Returns the current message handler function for this context.
131 *
132 * @return pointer to current message handler function or NULL if not set
133 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700134 MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
135
Tim Murray75e877d2013-09-11 14:45:20 -0700136 /**
137 * Returns current status for the context.
138 *
139 * @return current error
140 */
Tim Murray10913a52013-08-20 17:19:47 -0700141 RSError getError();
Tim Murray84bf2b82012-10-31 16:03:16 -0700142
Tim Murray75e877d2013-09-11 14:45:20 -0700143 /**
144 * Waits for any currently running asynchronous operations to finish. This
145 * should only be used for performance testing and timing.
146 */
Tim Murraybaca6c32012-11-14 16:51:46 -0800147 void finish();
148
Tim Murray75e877d2013-09-11 14:45:20 -0700149 RsContext getContext() { return mContext; }
150 void throwError(RSError error, const char *errMsg);
151
Tim Murraya4230962013-07-17 16:50:10 -0700152 static dispatchTable* dispatch;
153
Tim Murray84bf2b82012-10-31 16:03:16 -0700154 private:
Tim Murray4a92d122013-07-22 10:56:18 -0700155 static bool usingNative;
Tim Murraya4230962013-07-17 16:50:10 -0700156 static bool initDispatch(int targetApi);
157
Miao Wangbc10dff2015-04-03 17:44:55 -0700158 bool init(const char * name, int targetApi, uint32_t flags);
Tim Murray84bf2b82012-10-31 16:03:16 -0700159 static void * threadProc(void *);
160
161 static bool gInitialized;
162 static pthread_mutex_t gInitMutex;
163
164 pthread_t mMessageThreadId;
165 pid_t mNativeMessageThreadId;
166 bool mMessageRun;
167
168 RsDevice mDev;
169 RsContext mContext;
Tim Murray21fa7a02013-08-15 16:25:03 -0700170 RSError mCurrentError;
Tim Murray84bf2b82012-10-31 16:03:16 -0700171
172 ErrorHandlerFunc_t mErrorFunc;
173 MessageHandlerFunc_t mMessageFunc;
Tim Murraya4230962013-07-17 16:50:10 -0700174 bool mInit;
Tim Murray84bf2b82012-10-31 16:03:16 -0700175
Miao Wangbc10dff2015-04-03 17:44:55 -0700176 char mCacheDir[PATH_MAX+1];
177 uint32_t mCacheDirLen;
Tim Murraycaf41262013-12-13 12:54:37 -0800178
Tim Murray84bf2b82012-10-31 16:03:16 -0700179 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700180 sp<const Element> U8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700181 sp<const Element> U8_2;
182 sp<const Element> U8_3;
183 sp<const Element> U8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700184 sp<const Element> I8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700185 sp<const Element> I8_2;
186 sp<const Element> I8_3;
187 sp<const Element> I8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700188 sp<const Element> U16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700189 sp<const Element> U16_2;
190 sp<const Element> U16_3;
191 sp<const Element> U16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700192 sp<const Element> I16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700193 sp<const Element> I16_2;
194 sp<const Element> I16_3;
195 sp<const Element> I16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700196 sp<const Element> U32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700197 sp<const Element> U32_2;
198 sp<const Element> U32_3;
199 sp<const Element> U32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700200 sp<const Element> I32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700201 sp<const Element> I32_2;
202 sp<const Element> I32_3;
203 sp<const Element> I32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700204 sp<const Element> U64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700205 sp<const Element> U64_2;
206 sp<const Element> U64_3;
207 sp<const Element> U64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700208 sp<const Element> I64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700209 sp<const Element> I64_2;
210 sp<const Element> I64_3;
211 sp<const Element> I64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700212 sp<const Element> F32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700213 sp<const Element> F32_2;
214 sp<const Element> F32_3;
215 sp<const Element> F32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700216 sp<const Element> F64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700217 sp<const Element> F64_2;
218 sp<const Element> F64_3;
219 sp<const Element> F64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700220 sp<const Element> BOOLEAN;
Tim Murray84bf2b82012-10-31 16:03:16 -0700221
Tim Murray89daad62013-07-29 14:30:02 -0700222 sp<const Element> ELEMENT;
223 sp<const Element> TYPE;
224 sp<const Element> ALLOCATION;
225 sp<const Element> SAMPLER;
226 sp<const Element> SCRIPT;
227 sp<const Element> MESH;
228 sp<const Element> PROGRAM_FRAGMENT;
229 sp<const Element> PROGRAM_VERTEX;
230 sp<const Element> PROGRAM_RASTER;
231 sp<const Element> PROGRAM_STORE;
Tim Murray84bf2b82012-10-31 16:03:16 -0700232
Tim Murray89daad62013-07-29 14:30:02 -0700233 sp<const Element> A_8;
234 sp<const Element> RGB_565;
235 sp<const Element> RGB_888;
236 sp<const Element> RGBA_5551;
237 sp<const Element> RGBA_4444;
238 sp<const Element> RGBA_8888;
Tim Murray84bf2b82012-10-31 16:03:16 -0700239
Tim Murrayeb4426d2013-08-27 15:30:16 -0700240 sp<const Element> YUV;
Tim Murray84bf2b82012-10-31 16:03:16 -0700241
Tim Murray89daad62013-07-29 14:30:02 -0700242 sp<const Element> MATRIX_4X4;
243 sp<const Element> MATRIX_3X3;
244 sp<const Element> MATRIX_2X2;
Tim Murray84bf2b82012-10-31 16:03:16 -0700245 } mElements;
246
Tim Murray729b6fe2013-07-23 16:20:42 -0700247 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700248 sp<const Sampler> CLAMP_NEAREST;
249 sp<const Sampler> CLAMP_LINEAR;
250 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
251 sp<const Sampler> WRAP_NEAREST;
252 sp<const Sampler> WRAP_LINEAR;
253 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
254 sp<const Sampler> MIRRORED_REPEAT_NEAREST;
255 sp<const Sampler> MIRRORED_REPEAT_LINEAR;
256 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Tim Murray729b6fe2013-07-23 16:20:42 -0700257 } mSamplers;
258 friend class Sampler;
259 friend class Element;
Tim Murraycaf41262013-12-13 12:54:37 -0800260 friend class ScriptC;
Tim Murray84bf2b82012-10-31 16:03:16 -0700261};
262
Tim Murray75e877d2013-09-11 14:45:20 -0700263 /**
264 * Base class for all RenderScript objects. Not for direct use by developers.
265 */
Tim Murray89daad62013-07-29 14:30:02 -0700266class BaseObj : public android::RSC::LightRefBase<BaseObj> {
267public:
268 void * getID() const;
269 virtual ~BaseObj();
270 virtual void updateFromNative();
271 virtual bool equals(sp<const BaseObj> obj);
272
Tim Murray84bf2b82012-10-31 16:03:16 -0700273protected:
274 void *mID;
Tim Murray35609072013-12-03 11:36:03 -0800275 RS* mRS;
Miao Wangbc10dff2015-04-03 17:44:55 -0700276 const char * mName;
Tim Murray84bf2b82012-10-31 16:03:16 -0700277
278 BaseObj(void *id, sp<RS> rs);
279 void checkValid();
280
281 static void * getObjID(sp<const BaseObj> o);
282
Tim Murray84bf2b82012-10-31 16:03:16 -0700283};
284
Tim Murray75e877d2013-09-11 14:45:20 -0700285 /**
286 * This class provides the primary method through which data is passed to and
287 * from RenderScript kernels. An Allocation provides the backing store for a
288 * given Type.
289 *
290 * An Allocation also contains a set of usage flags that denote how the
291 * Allocation could be used. For example, an Allocation may have usage flags
292 * specifying that it can be used from a script as well as input to a
293 * Sampler. A developer must synchronize across these different usages using
294 * syncAll(int) in order to ensure that different users of the Allocation have
295 * a consistent view of memory. For example, in the case where an Allocation is
296 * used as the output of one kernel and as Sampler input in a later kernel, a
297 * developer must call syncAll(RS_ALLOCATION_USAGE_SCRIPT) prior to launching the
298 * second kernel to ensure correctness.
299 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700300class Allocation : public BaseObj {
301protected:
Tim Murray89daad62013-07-29 14:30:02 -0700302 sp<const Type> mType;
Tim Murray84bf2b82012-10-31 16:03:16 -0700303 uint32_t mUsage;
Tim Murray89daad62013-07-29 14:30:02 -0700304 sp<Allocation> mAdaptedAllocation;
Tim Murray84bf2b82012-10-31 16:03:16 -0700305
306 bool mConstrainedLOD;
307 bool mConstrainedFace;
308 bool mConstrainedY;
309 bool mConstrainedZ;
310 bool mReadAllowed;
311 bool mWriteAllowed;
Miao Wange5428e62015-03-10 15:29:40 -0700312 bool mAutoPadding;
Tim Murray84bf2b82012-10-31 16:03:16 -0700313 uint32_t mSelectedY;
314 uint32_t mSelectedZ;
315 uint32_t mSelectedLOD;
316 RsAllocationCubemapFace mSelectedFace;
317
318 uint32_t mCurrentDimX;
319 uint32_t mCurrentDimY;
320 uint32_t mCurrentDimZ;
321 uint32_t mCurrentCount;
322
323 void * getIDSafe() const;
324 void updateCacheInfo(sp<const Type> t);
325
326 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
327
Miao Wange5428e62015-03-10 15:29:40 -0700328 void validateIsInt64();
Tim Murray84bf2b82012-10-31 16:03:16 -0700329 void validateIsInt32();
330 void validateIsInt16();
331 void validateIsInt8();
332 void validateIsFloat32();
Miao Wange5428e62015-03-10 15:29:40 -0700333 void validateIsFloat64();
Tim Murray84bf2b82012-10-31 16:03:16 -0700334 void validateIsObject();
335
336 virtual void updateFromNative();
337
338 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
Tim Murray9d24ae62013-08-30 12:17:14 -0700339 void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff,
340 uint32_t w, uint32_t h, uint32_t d);
Tim Murray84bf2b82012-10-31 16:03:16 -0700341
342public:
Tim Murray75e877d2013-09-11 14:45:20 -0700343
344 /**
345 * Return Type for the allocation.
346 * @return pointer to underlying Type
347 */
Stephen Hinesa180b7d2013-08-21 12:42:13 -0700348 sp<const Type> getType() const {
Tim Murray84bf2b82012-10-31 16:03:16 -0700349 return mType;
350 }
351
Tim Murray75e877d2013-09-11 14:45:20 -0700352 /**
Miao Wange5428e62015-03-10 15:29:40 -0700353 * Enable/Disable AutoPadding for Vec3 elements.
354 *
355 * @param useAutoPadding True: enable AutoPadding; flase: disable AutoPadding
356 *
357 */
358 void setAutoPadding(bool useAutoPadding) {
359 mAutoPadding = useAutoPadding;
360 }
361
362 /**
Tim Murray75e877d2013-09-11 14:45:20 -0700363 * Propagate changes from one usage of the Allocation to other usages of the Allocation.
364 * @param[in] srcLocation source location with changes to propagate elsewhere
365 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700366 void syncAll(RsAllocationUsageType srcLocation);
Miao Wang09d2dd22015-03-18 20:09:20 -0700367
368 /**
369 * Send a buffer to the output stream. The contents of the Allocation will
370 * be undefined after this operation. This operation is only valid if
371 * USAGE_IO_OUTPUT is set on the Allocation.
372 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700373 void ioSendOutput();
Miao Wang09d2dd22015-03-18 20:09:20 -0700374
375 /**
376 * Receive the latest input into the Allocation. This operation
377 * is only valid if USAGE_IO_INPUT is set on the Allocation.
378 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700379 void ioGetInput();
380
Miao Wang09d2dd22015-03-18 20:09:20 -0700381#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
382 /**
383 * Returns the handle to a raw buffer that is being managed by the screen
384 * compositor. This operation is only valid for Allocations with USAGE_IO_INPUT.
385 * @return Surface associated with allocation
386 */
387 sp<Surface> getSurface();
388
389 /**
390 * Associate a Surface with this Allocation. This
391 * operation is only valid for Allocations with USAGE_IO_OUTPUT.
392 * @param[in] s Surface to associate with allocation
393 */
394 void setSurface(sp<Surface> s);
395#endif
396
Tim Murray75e877d2013-09-11 14:45:20 -0700397 /**
398 * Generate a mipmap chain. This is only valid if the Type of the Allocation
399 * includes mipmaps. This function will generate a complete set of mipmaps
400 * from the top level LOD and place them into the script memory space. If
401 * the Allocation is also using other memory spaces, a call to
402 * syncAll(Allocation.USAGE_SCRIPT) is required.
403 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700404 void generateMipmaps();
Tim Murray509ea5c2012-11-13 11:56:40 -0800405
Tim Murray75e877d2013-09-11 14:45:20 -0700406 /**
407 * Copy an array into part of this Allocation.
408 * @param[in] off offset of first Element to be overwritten
409 * @param[in] count number of Elements to copy
410 * @param[in] data array from which to copy
411 */
Tim Murray0b93e302012-11-15 14:56:54 -0800412 void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
Tim Murray75e877d2013-09-11 14:45:20 -0700413
414 /**
415 * Copy part of an Allocation into part of this Allocation.
416 * @param[in] off offset of first Element to be overwritten
417 * @param[in] count number of Elements to copy
418 * @param[in] data Allocation from which to copy
419 * @param[in] dataOff offset of first Element in data to copy
420 */
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800421 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700422
Tim Murray75e877d2013-09-11 14:45:20 -0700423 /**
424 * Copy an array into part of this Allocation.
425 * @param[in] off offset of first Element to be overwritten
426 * @param[in] count number of Elements to copy
427 * @param[in] data array from which to copy
428 */
Tim Murray0b93e302012-11-15 14:56:54 -0800429 void copy1DRangeTo(uint32_t off, size_t count, void *data);
430
Tim Murray75e877d2013-09-11 14:45:20 -0700431 /**
432 * Copy entire array to an Allocation.
433 * @param[in] data array from which to copy
434 */
Tim Murray0b93e302012-11-15 14:56:54 -0800435 void copy1DFrom(const void* data);
Tim Murray75e877d2013-09-11 14:45:20 -0700436
437 /**
438 * Copy entire Allocation to an array.
439 * @param[in] data destination array
440 */
Tim Murray0b93e302012-11-15 14:56:54 -0800441 void copy1DTo(void* data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800442
Tim Murray75e877d2013-09-11 14:45:20 -0700443 /**
444 * Copy from an array into a rectangular region in this Allocation. The
445 * array is assumed to be tightly packed.
446 * @param[in] xoff X offset of region to update in this Allocation
447 * @param[in] yoff Y offset of region to update in this Allocation
448 * @param[in] w Width of region to update
449 * @param[in] h Height of region to update
450 * @param[in] data Array from which to copy
451 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700452 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800453 const void *data);
Tim Murray7b3e3092012-11-16 13:32:24 -0800454
Tim Murray75e877d2013-09-11 14:45:20 -0700455 /**
456 * Copy from this Allocation into a rectangular region in an array. The
457 * array is assumed to be tightly packed.
458 * @param[in] xoff X offset of region to copy from this Allocation
459 * @param[in] yoff Y offset of region to copy from this Allocation
460 * @param[in] w Width of region to update
461 * @param[in] h Height of region to update
462 * @param[in] data destination array
463 */
Tim Murray7b3e3092012-11-16 13:32:24 -0800464 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
465 void *data);
466
Tim Murray75e877d2013-09-11 14:45:20 -0700467 /**
468 * Copy from an Allocation into a rectangular region in this Allocation.
469 * @param[in] xoff X offset of region to update in this Allocation
470 * @param[in] yoff Y offset of region to update in this Allocation
471 * @param[in] w Width of region to update
472 * @param[in] h Height of region to update
473 * @param[in] data Allocation from which to copy
474 * @param[in] dataXoff X offset of region to copy from in data
475 * @param[in] dataYoff Y offset of region to copy from in data
476 */
Tim Murray0b93e302012-11-15 14:56:54 -0800477 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
478 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700479
Tim Murray75e877d2013-09-11 14:45:20 -0700480 /**
481 * Copy from a strided array into a rectangular region in this Allocation.
482 * @param[in] xoff X offset of region to update in this Allocation
483 * @param[in] yoff Y offset of region to update in this Allocation
484 * @param[in] w Width of region to update
485 * @param[in] h Height of region to update
486 * @param[in] data array from which to copy
487 * @param[in] stride stride of data in bytes
488 */
Tim Murray358747a2012-11-26 13:52:04 -0800489 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
490 const void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700491
492 /**
493 * Copy from a strided array into this Allocation.
494 * @param[in] data array from which to copy
495 * @param[in] stride stride of data in bytes
496 */
Tim Murray358747a2012-11-26 13:52:04 -0800497 void copy2DStridedFrom(const void *data, size_t stride);
498
Tim Murray75e877d2013-09-11 14:45:20 -0700499 /**
500 * Copy from a rectangular region in this Allocation into a strided array.
501 * @param[in] xoff X offset of region to update in this Allocation
502 * @param[in] yoff Y offset of region to update in this Allocation
503 * @param[in] w Width of region to update
504 * @param[in] h Height of region to update
505 * @param[in] data destination array
506 * @param[in] stride stride of data in bytes
507 */
Tim Murray358747a2012-11-26 13:52:04 -0800508 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
509 void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700510
511 /**
512 * Copy this Allocation into a strided array.
513 * @param[in] data destination array
514 * @param[in] stride stride of data in bytes
515 */
Tim Murray358747a2012-11-26 13:52:04 -0800516 void copy2DStridedTo(void *data, size_t stride);
517
Tim Murray75e877d2013-09-11 14:45:20 -0700518
519 /**
520 * Copy from an array into a 3D region in this Allocation. The
521 * array is assumed to be tightly packed.
522 * @param[in] xoff X offset of region to update in this Allocation
523 * @param[in] yoff Y offset of region to update in this Allocation
524 * @param[in] zoff Z offset of region to update in this Allocation
525 * @param[in] w Width of region to update
526 * @param[in] h Height of region to update
527 * @param[in] d Depth of region to update
528 * @param[in] data Array from which to copy
529 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700530 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
531 uint32_t h, uint32_t d, const void* data);
532
Tim Murray75e877d2013-09-11 14:45:20 -0700533 /**
534 * Copy from an Allocation into a 3D region in this Allocation.
535 * @param[in] xoff X offset of region to update in this Allocation
536 * @param[in] yoff Y offset of region to update in this Allocation
537 * @param[in] zoff Z offset of region to update in this Allocation
538 * @param[in] w Width of region to update
539 * @param[in] h Height of region to update
540 * @param[in] d Depth of region to update
541 * @param[in] data Allocation from which to copy
542 * @param[in] dataXoff X offset of region in data to copy from
543 * @param[in] dataYoff Y offset of region in data to copy from
544 * @param[in] dataZoff Z offset of region in data to copy from
545 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700546 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
547 uint32_t w, uint32_t h, uint32_t d,
548 sp<const Allocation> data,
549 uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700550
Tim Murray75e877d2013-09-11 14:45:20 -0700551 /**
Miao Wange5428e62015-03-10 15:29:40 -0700552 * Copy a 3D region in this Allocation into an array. The
553 * array is assumed to be tightly packed.
554 * @param[in] xoff X offset of region to update in this Allocation
555 * @param[in] yoff Y offset of region to update in this Allocation
556 * @param[in] zoff Z offset of region to update in this Allocation
557 * @param[in] w Width of region to update
558 * @param[in] h Height of region to update
559 * @param[in] d Depth of region to update
560 * @param[in] data Array from which to copy
561 */
562 void copy3DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
563 uint32_t h, uint32_t d, void* data);
564
565 /**
Tim Murray75e877d2013-09-11 14:45:20 -0700566 * Creates an Allocation for use by scripts with a given Type.
567 * @param[in] rs Context to which the Allocation will belong
568 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800569 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700570 * @param[in] usage usage for the Allocation
571 * @return new Allocation
572 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700573 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800574 RsAllocationMipmapControl mipmaps, uint32_t usage);
Tim Murray75e877d2013-09-11 14:45:20 -0700575
576 /**
577 * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use
578 * with RS_ALLOCATION_USAGE_SHARED.
579 * @param[in] rs Context to which the Allocation will belong
580 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800581 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700582 * @param[in] usage usage for the Allocation
583 * @param[in] pointer existing backing store to use for this Allocation if possible
584 * @return new Allocation
585 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700586 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800587 RsAllocationMipmapControl mipmaps, uint32_t usage, void * pointer);
Tim Murray84bf2b82012-10-31 16:03:16 -0700588
Tim Murray75e877d2013-09-11 14:45:20 -0700589 /**
590 * Creates an Allocation for use by scripts with a given Type with no mipmaps.
591 * @param[in] rs Context to which the Allocation will belong
592 * @param[in] type Type of the Allocation
593 * @param[in] usage usage for the Allocation
594 * @return new Allocation
595 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700596 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
597 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700598 /**
599 * Creates an Allocation with a specified number of given elements.
600 * @param[in] rs Context to which the Allocation will belong
601 * @param[in] e Element used in the Allocation
602 * @param[in] count Number of elements of the Allocation
603 * @param[in] usage usage for the Allocation
604 * @return new Allocation
605 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700606 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
607 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700608
609 /**
610 * Creates a 2D Allocation with a specified number of given elements.
611 * @param[in] rs Context to which the Allocation will belong
612 * @param[in] e Element used in the Allocation
613 * @param[in] x Width in Elements of the Allocation
614 * @param[in] y Height of the Allocation
615 * @param[in] usage usage for the Allocation
616 * @return new Allocation
617 */
Tim Murray684726c2012-11-14 11:57:42 -0800618 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
619 size_t x, size_t y,
620 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
621
Tim Murray84bf2b82012-10-31 16:03:16 -0700622
Jason Samsb8a94e22014-02-24 17:52:32 -0800623 /**
624 * Get the backing pointer for a USAGE_SHARED allocation.
625 * @param[in] stride optional parameter. when non-NULL, will contain
626 * stride in bytes of a 2D Allocation
627 * @return pointer to data
628 */
629 void * getPointer(size_t *stride = NULL);
Tim Murray84bf2b82012-10-31 16:03:16 -0700630};
631
Tim Murray75e877d2013-09-11 14:45:20 -0700632 /**
633 * An Element represents one item within an Allocation. An Element is roughly
634 * equivalent to a C type in a RenderScript kernel. Elements may be basic
635 * or complex. Some basic elements are:
636
637 * - A single float value (equivalent to a float in a kernel)
638 * - A four-element float vector (equivalent to a float4 in a kernel)
639 * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel)
640 * - A single signed 8-bit integer (equivalent to a char in a kernel)
641
642 * Basic Elements are comprised of a Element.DataType and a
643 * Element.DataKind. The DataType encodes C type information of an Element,
644 * while the DataKind encodes how that Element should be interpreted by a
645 * Sampler. Note that Allocation objects with DataKind USER cannot be used as
646 * input for a Sampler. In general, Allocation objects that are intended for
647 * use with a Sampler should use bitmap-derived Elements such as
648 * Element::RGBA_8888.
649 */
650
651
Tim Murray84bf2b82012-10-31 16:03:16 -0700652class Element : public BaseObj {
653public:
654 bool isComplex();
Tim Murray75e877d2013-09-11 14:45:20 -0700655
656 /**
657 * Elements could be simple, such as an int or a float, or a structure with
658 * multiple sub-elements, such as a collection of floats, float2,
659 * float4. This function returns zero for simple elements or the number of
660 * sub-elements otherwise.
661 * @return number of sub-elements
662 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700663 size_t getSubElementCount() {
Miao Wangbc10dff2015-04-03 17:44:55 -0700664 return mVisibleElementMapSize;
Tim Murray84bf2b82012-10-31 16:03:16 -0700665 }
666
Tim Murray75e877d2013-09-11 14:45:20 -0700667 /**
668 * For complex Elements, this returns the sub-element at a given index.
669 * @param[in] index index of sub-element
670 * @return sub-element
671 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700672 sp<const Element> getSubElement(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700673
674 /**
675 * For complex Elements, this returns the name of the sub-element at a given
676 * index.
677 * @param[in] index index of sub-element
678 * @return name of sub-element
679 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700680 const char * getSubElementName(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700681
682 /**
683 * For complex Elements, this returns the size of the sub-element at a given
684 * index.
685 * @param[in] index index of sub-element
686 * @return size of sub-element
687 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700688 size_t getSubElementArraySize(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700689
690 /**
691 * Returns the location of a sub-element within a complex Element.
692 * @param[in] index index of sub-element
693 * @return offset in bytes
694 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700695 uint32_t getSubElementOffsetBytes(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700696
697 /**
698 * Returns the data type used for the Element.
699 * @return data type
700 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700701 RsDataType getDataType() const {
702 return mType;
703 }
704
Tim Murray75e877d2013-09-11 14:45:20 -0700705 /**
706 * Returns the data kind used for the Element.
707 * @return data kind
708 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700709 RsDataKind getDataKind() const {
710 return mKind;
711 }
712
Tim Murray75e877d2013-09-11 14:45:20 -0700713 /**
714 * Returns the size in bytes of the Element.
715 * @return size in bytes
716 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700717 size_t getSizeBytes() const {
718 return mSizeBytes;
719 }
720
Tim Murray75e877d2013-09-11 14:45:20 -0700721 /**
722 * Returns the number of vector components for this Element.
723 * @return number of vector components
724 */
Tim Murray10913a52013-08-20 17:19:47 -0700725 uint32_t getVectorSize() const {
726 return mVectorSize;
727 }
728
Tim Murray75e877d2013-09-11 14:45:20 -0700729 /**
730 * Utility function for returning an Element containing a single bool.
731 * @param[in] rs RenderScript context
732 * @return Element
733 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700734 static sp<const Element> BOOLEAN(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700735 /**
736 * Utility function for returning an Element containing a single unsigned char.
737 * @param[in] rs RenderScript context
738 * @return Element
739 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700740 static sp<const Element> U8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700741 /**
742 * Utility function for returning an Element containing a single signed char.
743 * @param[in] rs RenderScript context
744 * @return Element
745 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700746 static sp<const Element> I8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700747 /**
748 * Utility function for returning an Element containing a single unsigned short.
749 * @param[in] rs RenderScript context
750 * @return Element
751 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700752 static sp<const Element> U16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700753 /**
754 * Utility function for returning an Element containing a single signed short.
755 * @param[in] rs RenderScript context
756 * @return Element
757 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700758 static sp<const Element> I16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700759 /**
760 * Utility function for returning an Element containing a single unsigned int.
761 * @param[in] rs RenderScript context
762 * @return Element
763 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700764 static sp<const Element> U32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700765 /**
766 * Utility function for returning an Element containing a single signed int.
767 * @param[in] rs RenderScript context
768 * @return Element
769 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700770 static sp<const Element> I32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700771 /**
772 * Utility function for returning an Element containing a single unsigned long long.
773 * @param[in] rs RenderScript context
774 * @return Element
775 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700776 static sp<const Element> U64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700777 /**
778 * Utility function for returning an Element containing a single signed long long.
779 * @param[in] rs RenderScript context
780 * @return Element
781 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700782 static sp<const Element> I64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700783 /**
784 * Utility function for returning an Element containing a single float.
785 * @param[in] rs RenderScript context
786 * @return Element
787 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700788 static sp<const Element> F32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700789 /**
790 * Utility function for returning an Element containing a single double.
791 * @param[in] rs RenderScript context
792 * @return Element
793 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700794 static sp<const Element> F64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700795 /**
796 * Utility function for returning an Element containing a single Element.
797 * @param[in] rs RenderScript context
798 * @return Element
799 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700800 static sp<const Element> ELEMENT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700801 /**
802 * Utility function for returning an Element containing a single Type.
803 * @param[in] rs RenderScript context
804 * @return Element
805 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700806 static sp<const Element> TYPE(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700807 /**
808 * Utility function for returning an Element containing a single Allocation.
809 * @param[in] rs RenderScript context
810 * @return Element
811 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700812 static sp<const Element> ALLOCATION(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700813 /**
814 * Utility function for returning an Element containing a single Sampler.
815 * @param[in] rs RenderScript context
816 * @return Element
817 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700818 static sp<const Element> SAMPLER(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700819 /**
820 * Utility function for returning an Element containing a single Script.
821 * @param[in] rs RenderScript context
822 * @return Element
823 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700824 static sp<const Element> SCRIPT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700825 /**
826 * Utility function for returning an Element containing an ALPHA_8 pixel.
827 * @param[in] rs RenderScript context
828 * @return Element
829 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700830 static sp<const Element> A_8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700831 /**
832 * Utility function for returning an Element containing an RGB_565 pixel.
833 * @param[in] rs RenderScript context
834 * @return Element
835 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700836 static sp<const Element> RGB_565(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700837 /**
838 * Utility function for returning an Element containing an RGB_888 pixel.
839 * @param[in] rs RenderScript context
840 * @return Element
841 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700842 static sp<const Element> RGB_888(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700843 /**
844 * Utility function for returning an Element containing an RGBA_5551 pixel.
845 * @param[in] rs RenderScript context
846 * @return Element
847 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700848 static sp<const Element> RGBA_5551(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700849 /**
850 * Utility function for returning an Element containing an RGBA_4444 pixel.
851 * @param[in] rs RenderScript context
852 * @return Element
853 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700854 static sp<const Element> RGBA_4444(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700855 /**
856 * Utility function for returning an Element containing an RGBA_8888 pixel.
857 * @param[in] rs RenderScript context
858 * @return Element
859 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700860 static sp<const Element> RGBA_8888(sp<RS> rs);
861
Tim Murray75e877d2013-09-11 14:45:20 -0700862 /**
863 * Utility function for returning an Element containing a float2.
864 * @param[in] rs RenderScript context
865 * @return Element
866 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700867 static sp<const Element> F32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700868 /**
869 * Utility function for returning an Element containing a float3.
870 * @param[in] rs RenderScript context
871 * @return Element
872 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700873 static sp<const Element> F32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700874 /**
875 * Utility function for returning an Element containing a float4.
876 * @param[in] rs RenderScript context
877 * @return Element
878 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700879 static sp<const Element> F32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700880 /**
881 * Utility function for returning an Element containing a double2.
882 * @param[in] rs RenderScript context
883 * @return Element
884 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700885 static sp<const Element> F64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700886 /**
887 * Utility function for returning an Element containing a double3.
888 * @param[in] rs RenderScript context
889 * @return Element
890 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700891 static sp<const Element> F64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700892 /**
893 * Utility function for returning an Element containing a double4.
894 * @param[in] rs RenderScript context
895 * @return Element
896 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700897 static sp<const Element> F64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700898 /**
899 * Utility function for returning an Element containing a uchar2.
900 * @param[in] rs RenderScript context
901 * @return Element
902 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700903 static sp<const Element> U8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700904 /**
905 * Utility function for returning an Element containing a uchar3.
906 * @param[in] rs RenderScript context
907 * @return Element
908 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700909 static sp<const Element> U8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700910 /**
911 * Utility function for returning an Element containing a uchar4.
912 * @param[in] rs RenderScript context
913 * @return Element
914 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700915 static sp<const Element> U8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700916 /**
917 * Utility function for returning an Element containing a char2.
918 * @param[in] rs RenderScript context
919 * @return Element
920 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700921 static sp<const Element> I8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700922 /**
923 * Utility function for returning an Element containing a char3.
924 * @param[in] rs RenderScript context
925 * @return Element
926 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700927 static sp<const Element> I8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700928 /**
929 * Utility function for returning an Element containing a char4.
930 * @param[in] rs RenderScript context
931 * @return Element
932 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700933 static sp<const Element> I8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700934 /**
935 * Utility function for returning an Element containing a ushort2.
936 * @param[in] rs RenderScript context
937 * @return Element
938 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700939 static sp<const Element> U16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700940 /**
941 * Utility function for returning an Element containing a ushort3.
942 * @param[in] rs RenderScript context
943 * @return Element
944 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700945 static sp<const Element> U16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700946 /**
947 * Utility function for returning an Element containing a ushort4.
948 * @param[in] rs RenderScript context
949 * @return Element
950 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700951 static sp<const Element> U16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700952 /**
953 * Utility function for returning an Element containing a short2.
954 * @param[in] rs RenderScript context
955 * @return Element
956 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700957 static sp<const Element> I16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700958 /**
959 * Utility function for returning an Element containing a short3.
960 * @param[in] rs RenderScript context
961 * @return Element
962 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700963 static sp<const Element> I16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700964 /**
965 * Utility function for returning an Element containing a short4.
966 * @param[in] rs RenderScript context
967 * @return Element
968 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700969 static sp<const Element> I16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700970 /**
971 * Utility function for returning an Element containing a uint2.
972 * @param[in] rs RenderScript context
973 * @return Element
974 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700975 static sp<const Element> U32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700976 /**
977 * Utility function for returning an Element containing a uint3.
978 * @param[in] rs RenderScript context
979 * @return Element
980 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700981 static sp<const Element> U32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700982 /**
983 * Utility function for returning an Element containing a uint4.
984 * @param[in] rs RenderScript context
985 * @return Element
986 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700987 static sp<const Element> U32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700988 /**
989 * Utility function for returning an Element containing an int2.
990 * @param[in] rs RenderScript context
991 * @return Element
992 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700993 static sp<const Element> I32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700994 /**
995 * Utility function for returning an Element containing an int3.
996 * @param[in] rs RenderScript context
997 * @return Element
998 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700999 static sp<const Element> I32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001000 /**
1001 * Utility function for returning an Element containing an int4.
1002 * @param[in] rs RenderScript context
1003 * @return Element
1004 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001005 static sp<const Element> I32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001006 /**
1007 * Utility function for returning an Element containing a ulong2.
1008 * @param[in] rs RenderScript context
1009 * @return Element
1010 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001011 static sp<const Element> U64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001012 /**
1013 * Utility function for returning an Element containing a ulong3.
1014 * @param[in] rs RenderScript context
1015 * @return Element
1016 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001017 static sp<const Element> U64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001018 /**
1019 * Utility function for returning an Element containing a ulong4.
1020 * @param[in] rs RenderScript context
1021 * @return Element
1022 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001023 static sp<const Element> U64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001024 /**
1025 * Utility function for returning an Element containing a long2.
1026 * @param[in] rs RenderScript context
1027 * @return Element
1028 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001029 static sp<const Element> I64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001030 /**
1031 * Utility function for returning an Element containing a long3.
1032 * @param[in] rs RenderScript context
1033 * @return Element
1034 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001035 static sp<const Element> I64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001036 /**
1037 * Utility function for returning an Element containing a long4.
1038 * @param[in] rs RenderScript context
1039 * @return Element
1040 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001041 static sp<const Element> I64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001042 /**
1043 * Utility function for returning an Element containing a YUV pixel.
1044 * @param[in] rs RenderScript context
1045 * @return Element
1046 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001047 static sp<const Element> YUV(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001048 /**
1049 * Utility function for returning an Element containing an rs_matrix_4x4.
1050 * @param[in] rs RenderScript context
1051 * @return Element
1052 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001053 static sp<const Element> MATRIX_4X4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001054 /**
1055 * Utility function for returning an Element containing an rs_matrix_3x3.
1056 * @param[in] rs RenderScript context
1057 * @return Element
1058 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001059 static sp<const Element> MATRIX_3X3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001060 /**
1061 * Utility function for returning an Element containing an rs_matrix_2x2.
1062 * @param[in] rs RenderScript context
1063 * @return Element
1064 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001065 static sp<const Element> MATRIX_2X2(sp<RS> rs);
1066
Tim Murray84bf2b82012-10-31 16:03:16 -07001067 void updateFromNative();
Tim Murray75e877d2013-09-11 14:45:20 -07001068
1069 /**
1070 * Create an Element with a given DataType.
1071 * @param[in] rs RenderScript context
1072 * @param[in] dt data type
1073 * @return Element
1074 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001075 static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
Tim Murray75e877d2013-09-11 14:45:20 -07001076 /**
1077 * Create a vector Element with the given DataType
1078 * @param[in] rs RenderScript
1079 * @param[in] dt DataType
1080 * @param[in] size vector size
1081 * @return Element
1082 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001083 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
Tim Murray75e877d2013-09-11 14:45:20 -07001084 /**
1085 * Create an Element with a given DataType and DataKind.
1086 * @param[in] rs RenderScript context
1087 * @param[in] dt DataType
1088 * @param[in] dk DataKind
1089 * @return Element
1090 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001091 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
Tim Murray75e877d2013-09-11 14:45:20 -07001092
1093 /**
1094 * Returns true if the Element can interoperate with this Element.
1095 * @param[in] e Element to compare
1096 * @return true if Elements can interoperate
1097 */
Tim Murray10913a52013-08-20 17:19:47 -07001098 bool isCompatible(sp<const Element>e) const;
Tim Murray84bf2b82012-10-31 16:03:16 -07001099
Tim Murray75e877d2013-09-11 14:45:20 -07001100 /**
1101 * Builder class for producing complex elements with matching field and name
1102 * pairs. The builder starts empty. The order in which elements are added is
1103 * retained for the layout in memory.
1104 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001105 class Builder {
1106 private:
Tim Murray35609072013-12-03 11:36:03 -08001107 RS* mRS;
Miao Wangbc10dff2015-04-03 17:44:55 -07001108 size_t mElementsCount;
1109 size_t mElementsVecSize;
1110 sp<const Element> * mElements;
1111 char ** mElementNames;
1112 size_t * mElementNameLengths;
1113 uint32_t * mArraySizes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001114 bool mSkipPadding;
1115
1116 public:
1117 Builder(sp<RS> rs);
1118 ~Builder();
Miao Wangbc10dff2015-04-03 17:44:55 -07001119 void add(sp<const Element> e, const char * name, uint32_t arraySize = 1);
Tim Murray84bf2b82012-10-31 16:03:16 -07001120 sp<const Element> create();
1121 };
1122
Stephen Hines7d1b7572013-08-22 01:24:06 -07001123protected:
1124 Element(void *id, sp<RS> rs,
Miao Wangbc10dff2015-04-03 17:44:55 -07001125 sp<const Element> * elements,
1126 size_t elementCount,
1127 const char ** elementNames,
1128 size_t * elementNameLengths,
1129 uint32_t * arraySizes);
Stephen Hines7d1b7572013-08-22 01:24:06 -07001130 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
1131 Element(sp<RS> rs);
1132 virtual ~Element();
1133
Tim Murray84bf2b82012-10-31 16:03:16 -07001134private:
1135 void updateVisibleSubElements();
1136
Miao Wangbc10dff2015-04-03 17:44:55 -07001137 size_t mElementsCount;
1138 size_t mVisibleElementMapSize;
1139
1140 sp<const Element> * mElements;
1141 char ** mElementNames;
1142 size_t * mElementNameLengths;
1143 uint32_t * mArraySizes;
1144 uint32_t * mVisibleElementMap;
1145 uint32_t * mOffsetInBytes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001146
1147 RsDataType mType;
1148 RsDataKind mKind;
1149 bool mNormalized;
1150 size_t mSizeBytes;
1151 size_t mVectorSize;
1152};
1153
Stephen Hines2c7206e2012-11-14 19:47:01 -08001154class FieldPacker {
1155protected:
1156 unsigned char* mData;
1157 size_t mPos;
1158 size_t mLen;
1159
1160public:
1161 FieldPacker(size_t len)
Tim Murray89daad62013-07-29 14:30:02 -07001162 : mPos(0), mLen(len) {
1163 mData = new unsigned char[len];
1164 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001165
1166 virtual ~FieldPacker() {
1167 delete [] mData;
1168 }
1169
1170 void align(size_t v) {
1171 if ((v & (v - 1)) != 0) {
Tim Murrayab716362013-08-12 12:37:18 -07001172 // ALOGE("Non-power-of-two alignment: %zu", v);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001173 return;
1174 }
1175
1176 while ((mPos & (v - 1)) != 0) {
1177 mData[mPos++] = 0;
1178 }
1179 }
1180
1181 void reset() {
1182 mPos = 0;
1183 }
1184
1185 void reset(size_t i) {
1186 if (i >= mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001187 // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001188 return;
1189 }
1190 mPos = i;
1191 }
1192
1193 void skip(size_t i) {
1194 size_t res = mPos + i;
1195 if (res > mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001196 // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001197 return;
1198 }
1199 mPos = res;
1200 }
1201
1202 void* getData() const {
1203 return mData;
1204 }
1205
1206 size_t getLength() const {
1207 return mLen;
1208 }
1209
1210 template <typename T>
Tim Murray89daad62013-07-29 14:30:02 -07001211 void add(T t) {
Stephen Hines2c7206e2012-11-14 19:47:01 -08001212 align(sizeof(t));
1213 if (mPos + sizeof(t) <= mLen) {
1214 memcpy(&mData[mPos], &t, sizeof(t));
1215 mPos += sizeof(t);
1216 }
1217 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001218
1219 /*
Tim Murray89daad62013-07-29 14:30:02 -07001220 void add(rs_matrix4x4 m) {
1221 for (size_t i = 0; i < 16; i++) {
1222 add(m.m[i]);
1223 }
1224 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001225
Tim Murray89daad62013-07-29 14:30:02 -07001226 void add(rs_matrix3x3 m) {
1227 for (size_t i = 0; i < 9; i++) {
1228 add(m.m[i]);
1229 }
1230 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001231
Tim Murray89daad62013-07-29 14:30:02 -07001232 void add(rs_matrix2x2 m) {
1233 for (size_t i = 0; i < 4; i++) {
1234 add(m.m[i]);
1235 }
1236 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001237 */
1238
Tim Murray89daad62013-07-29 14:30:02 -07001239 void add(sp<BaseObj> obj) {
Stephen Hines43514cd2012-11-16 14:33:47 -08001240 if (obj != NULL) {
1241 add((uint32_t) (uintptr_t) obj->getID());
1242 } else {
1243 add((uint32_t) 0);
1244 }
1245 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001246};
1247
Tim Murray75e877d2013-09-11 14:45:20 -07001248/**
1249 * A Type describes the Element and dimensions used for an Allocation or a
1250 * parallel operation.
1251 *
1252 * A Type always includes an Element and an X dimension. A Type may be
1253 * multidimensional, up to three dimensions. A nonzero value in the Y or Z
1254 * dimensions indicates that the dimension is present. Note that a Type with
1255 * only a given X dimension and a Type with the same X dimension but Y = 1 are
1256 * not equivalent.
1257 *
1258 * A Type also supports inclusion of level of detail (LOD) or cube map
1259 * faces. LOD and cube map faces are booleans to indicate present or not
1260 * present.
1261 *
1262 * A Type also supports YUV format information to support an Allocation in a YUV
1263 * format. The YUV formats supported are YV12 and NV21.
1264 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001265class Type : public BaseObj {
1266protected:
1267 friend class Allocation;
1268
1269 uint32_t mDimX;
1270 uint32_t mDimY;
1271 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001272 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001273 bool mDimMipmaps;
1274 bool mDimFaces;
1275 size_t mElementCount;
1276 sp<const Element> mElement;
1277
Stephen Hines7d1b7572013-08-22 01:24:06 -07001278 Type(void *id, sp<RS> rs);
1279
Tim Murray84bf2b82012-10-31 16:03:16 -07001280 void calcElementCount();
1281 virtual void updateFromNative();
1282
1283public:
1284
Tim Murray75e877d2013-09-11 14:45:20 -07001285 /**
1286 * Returns the YUV format.
1287 * @return YUV format of the Allocation
1288 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001289 RSYuvFormat getYuvFormat() const {
1290 return mYuvFormat;
1291 }
1292
Tim Murray75e877d2013-09-11 14:45:20 -07001293 /**
1294 * Returns the Element of the Allocation.
1295 * @return YUV format of the Allocation
1296 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001297 sp<const Element> getElement() const {
1298 return mElement;
1299 }
1300
Tim Murray75e877d2013-09-11 14:45:20 -07001301 /**
1302 * Returns the X dimension of the Allocation.
1303 * @return X dimension of the allocation
1304 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001305 uint32_t getX() const {
1306 return mDimX;
1307 }
1308
Tim Murray75e877d2013-09-11 14:45:20 -07001309 /**
1310 * Returns the Y dimension of the Allocation.
1311 * @return Y dimension of the allocation
1312 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001313 uint32_t getY() const {
1314 return mDimY;
1315 }
1316
Tim Murray75e877d2013-09-11 14:45:20 -07001317 /**
1318 * Returns the Z dimension of the Allocation.
1319 * @return Z dimension of the allocation
1320 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001321 uint32_t getZ() const {
1322 return mDimZ;
1323 }
1324
Tim Murray75e877d2013-09-11 14:45:20 -07001325 /**
1326 * Returns true if the Allocation has mipmaps.
1327 * @return true if the Allocation has mipmaps
1328 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001329 bool hasMipmaps() const {
1330 return mDimMipmaps;
1331 }
1332
Tim Murray75e877d2013-09-11 14:45:20 -07001333 /**
1334 * Returns true if the Allocation is a cube map
1335 * @return true if the Allocation is a cube map
1336 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001337 bool hasFaces() const {
1338 return mDimFaces;
1339 }
1340
Tim Murray75e877d2013-09-11 14:45:20 -07001341 /**
1342 * Returns number of accessible Elements in the Allocation
1343 * @return number of accessible Elements in the Allocation
1344 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001345 size_t getCount() const {
1346 return mElementCount;
1347 }
1348
Tim Murray75e877d2013-09-11 14:45:20 -07001349 /**
1350 * Returns size in bytes of all Elements in the Allocation
1351 * @return size in bytes of all Elements in the Allocation
1352 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001353 size_t getSizeBytes() const {
1354 return mElementCount * mElement->getSizeBytes();
1355 }
1356
Tim Murray75e877d2013-09-11 14:45:20 -07001357 /**
1358 * Creates a new Type with the given Element and dimensions.
1359 * @param[in] rs RenderScript context
1360 * @param[in] e Element
1361 * @param[in] dimX X dimension
1362 * @param[in] dimY Y dimension
1363 * @param[in] dimZ Z dimension
1364 * @return new Type
1365 */
Tim Murray96267c22013-02-12 11:25:12 -08001366 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 -07001367
1368 class Builder {
1369 protected:
Tim Murray35609072013-12-03 11:36:03 -08001370 RS* mRS;
Tim Murray84bf2b82012-10-31 16:03:16 -07001371 uint32_t mDimX;
1372 uint32_t mDimY;
1373 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001374 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001375 bool mDimMipmaps;
1376 bool mDimFaces;
1377 sp<const Element> mElement;
1378
1379 public:
1380 Builder(sp<RS> rs, sp<const Element> e);
1381
1382 void setX(uint32_t value);
Stephen Hines7d1b7572013-08-22 01:24:06 -07001383 void setY(uint32_t value);
Tim Murrayeb4426d2013-08-27 15:30:16 -07001384 void setZ(uint32_t value);
1385 void setYuvFormat(RSYuvFormat format);
Tim Murray84bf2b82012-10-31 16:03:16 -07001386 void setMipmaps(bool value);
1387 void setFaces(bool value);
1388 sp<const Type> create();
1389 };
1390
1391};
1392
Tim Murray75e877d2013-09-11 14:45:20 -07001393/**
1394 * The parent class for all executable Scripts. This should not be used by applications.
1395 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001396class Script : public BaseObj {
1397private:
1398
1399protected:
1400 Script(void *id, sp<RS> rs);
1401 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
1402 const void *v, size_t) const;
1403 void bindAllocation(sp<Allocation> va, uint32_t slot) const;
1404 void setVar(uint32_t index, const void *, size_t len) const;
1405 void setVar(uint32_t index, sp<const BaseObj> o) const;
1406 void invoke(uint32_t slot, const void *v, size_t len) const;
1407
1408
1409 void invoke(uint32_t slot) const {
1410 invoke(slot, NULL, 0);
1411 }
1412 void setVar(uint32_t index, float v) const {
1413 setVar(index, &v, sizeof(v));
1414 }
1415 void setVar(uint32_t index, double v) const {
1416 setVar(index, &v, sizeof(v));
1417 }
1418 void setVar(uint32_t index, int32_t v) const {
1419 setVar(index, &v, sizeof(v));
1420 }
Jon Parrb05c8502015-03-13 14:41:58 +00001421 void setVar(uint32_t index, uint32_t v) const {
1422 setVar(index, &v, sizeof(v));
1423 }
Tim Murray84bf2b82012-10-31 16:03:16 -07001424 void setVar(uint32_t index, int64_t v) const {
1425 setVar(index, &v, sizeof(v));
1426 }
1427 void setVar(uint32_t index, bool v) const {
1428 setVar(index, &v, sizeof(v));
1429 }
1430
1431public:
1432 class FieldBase {
1433 protected:
1434 sp<const Element> mElement;
1435 sp<Allocation> mAllocation;
1436
1437 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
1438
1439 public:
1440 sp<const Element> getElement() {
1441 return mElement;
1442 }
1443
1444 sp<const Type> getType() {
1445 return mAllocation->getType();
1446 }
1447
1448 sp<const Allocation> getAllocation() {
1449 return mAllocation;
1450 }
1451
1452 //void updateAllocation();
1453 };
1454};
1455
Tim Murray75e877d2013-09-11 14:45:20 -07001456/**
1457 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only.
1458 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001459class ScriptC : public Script {
1460protected:
1461 ScriptC(sp<RS> rs,
1462 const void *codeTxt, size_t codeLength,
1463 const char *cachedName, size_t cachedNameLength,
1464 const char *cacheDir, size_t cacheDirLength);
1465
1466};
1467
Tim Murray75e877d2013-09-11 14:45:20 -07001468/**
1469 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of
1470 * basic functions. This is not intended to be used directly.
1471 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001472class ScriptIntrinsic : public Script {
1473 protected:
Tim Murray10913a52013-08-20 17:19:47 -07001474 sp<const Element> mElement;
Tim Murray3cd44af2012-11-14 11:25:27 -08001475 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001476 virtual ~ScriptIntrinsic();
Tim Murray7f0d5682012-11-08 16:35:24 -08001477};
1478
Tim Murray75e877d2013-09-11 14:45:20 -07001479/**
1480 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming
1481 * r,g,b values are use as normalized x,y,z coordinates into a 3D
1482 * allocation. The 8 nearest values are sampled and linearly interpolated. The
1483 * result is placed in the output.
1484 */
Tim Murray89daad62013-07-29 14:30:02 -07001485class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001486 private:
Tim Murray89daad62013-07-29 14:30:02 -07001487 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001488 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001489 /**
1490 * Supported Element types are U8_4. Default lookup table is identity.
1491 * @param[in] rs RenderScript context
1492 * @param[in] e Element
1493 * @return new ScriptIntrinsic
1494 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001495 static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001496
1497 /**
1498 * Launch the intrinsic.
1499 * @param[in] ain input Allocation
1500 * @param[in] aout output Allocation
1501 */
Tim Murray89daad62013-07-29 14:30:02 -07001502 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001503
1504 /**
1505 * Sets the lookup table. The lookup table must use the same Element as the
1506 * intrinsic.
1507 * @param[in] lut new lookup table
1508 */
Tim Murray89daad62013-07-29 14:30:02 -07001509 void setLUT(sp<Allocation> lut);
1510};
1511
Tim Murray75e877d2013-09-11 14:45:20 -07001512/**
1513 * Intrinsic kernel for blending two Allocations.
1514 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001515class ScriptIntrinsicBlend : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001516 private:
Tim Murray89daad62013-07-29 14:30:02 -07001517 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001518 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001519 /**
1520 * Supported Element types are U8_4.
1521 * @param[in] rs RenderScript context
1522 * @param[in] e Element
1523 * @return new ScriptIntrinsicBlend
1524 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001525 static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001526 /**
1527 * sets dst = {0, 0, 0, 0}
1528 * @param[in] in input Allocation
1529 * @param[in] out output Allocation
1530 */
1531 void forEachClear(sp<Allocation> in, sp<Allocation> out);
1532 /**
1533 * Sets dst = src
1534 * @param[in] in input Allocation
1535 * @param[in] out output Allocation
1536 */
1537 void forEachSrc(sp<Allocation> in, sp<Allocation> out);
1538 /**
1539 * Sets dst = dst (NOP)
1540 * @param[in] in input Allocation
1541 * @param[in] out output Allocation
1542 */
1543 void forEachDst(sp<Allocation> in, sp<Allocation> out);
1544 /**
1545 * Sets dst = src + dst * (1.0 - src.a)
1546 * @param[in] in input Allocation
1547 * @param[in] out output Allocation
1548 */
1549 void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
1550 /**
1551 * Sets dst = dst + src * (1.0 - dst.a)
1552 * @param[in] in input Allocation
1553 * @param[in] out output Allocation
1554 */
1555 void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
1556 /**
1557 * Sets dst = src * dst.a
1558 * @param[in] in input Allocation
1559 * @param[in] out output Allocation
1560 */
1561 void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
1562 /**
1563 * Sets dst = dst * src.a
1564 * @param[in] in input Allocation
1565 * @param[in] out output Allocation
1566 */
1567 void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
1568 /**
1569 * Sets dst = src * (1.0 - dst.a)
1570 * @param[in] in input Allocation
1571 * @param[in] out output Allocation
1572 */
1573 void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
1574 /**
1575 * Sets dst = dst * (1.0 - src.a)
1576 * @param[in] in input Allocation
1577 * @param[in] out output Allocation
1578 */
1579 void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
1580 /**
1581 * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
1582 * @param[in] in input Allocation
1583 * @param[in] out output Allocation
1584 */
1585 void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
1586 /**
1587 * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
1588 * @param[in] in input Allocation
1589 * @param[in] out output Allocation
1590 */
1591 void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
1592 /**
1593 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
1594 * @param[in] in input Allocation
1595 * @param[in] out output Allocation
1596 */
1597 void forEachXor(sp<Allocation> in, sp<Allocation> out);
1598 /**
1599 * Sets dst = src * dst
1600 * @param[in] in input Allocation
1601 * @param[in] out output Allocation
1602 */
1603 void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
1604 /**
1605 * Sets dst = min(src + dst, 1.0)
1606 * @param[in] in input Allocation
1607 * @param[in] out output Allocation
1608 */
1609 void forEachAdd(sp<Allocation> in, sp<Allocation> out);
1610 /**
1611 * Sets dst = max(dst - src, 0.0)
1612 * @param[in] in input Allocation
1613 * @param[in] out output Allocation
1614 */
1615 void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
Tim Murray7f0d5682012-11-08 16:35:24 -08001616};
Tim Murray84bf2b82012-10-31 16:03:16 -07001617
Tim Murray75e877d2013-09-11 14:45:20 -07001618/**
1619 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified
1620 * radius to all elements of an Allocation.
1621 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001622class ScriptIntrinsicBlur : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001623 private:
Tim Murray89daad62013-07-29 14:30:02 -07001624 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001625 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001626 /**
1627 * Supported Element types are U8 and U8_4.
1628 * @param[in] rs RenderScript context
1629 * @param[in] e Element
1630 * @return new ScriptIntrinsicBlur
1631 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001632 static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001633 /**
1634 * Sets the input of the blur.
1635 * @param[in] in input Allocation
1636 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001637 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001638 /**
1639 * Runs the intrinsic.
1640 * @param[in] output Allocation
1641 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001642 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001643 /**
1644 * Sets the radius of the blur. The supported range is 0 < radius <= 25.
1645 * @param[in] radius radius of the blur
1646 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001647 void setRadius(float radius);
1648};
1649
Tim Murray75e877d2013-09-11 14:45:20 -07001650/**
1651 * Intrinsic for applying a color matrix to allocations. This has the
1652 * same effect as loading each element and converting it to a
1653 * F32_N, multiplying the result by the 4x4 color matrix
1654 * as performed by rsMatrixMultiply() and writing it to the output
1655 * after conversion back to U8_N or F32_N.
1656 */
Tim Murray89daad62013-07-29 14:30:02 -07001657class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001658 private:
Tim Murray89daad62013-07-29 14:30:02 -07001659 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001660 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001661 /**
1662 * Creates a new intrinsic.
1663 * @param[in] rs RenderScript context
1664 * @return new ScriptIntrinsicColorMatrix
1665 */
Tim Murrayaae73c92013-09-03 17:05:46 -07001666 static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001667 /**
1668 * Applies the color matrix. Supported types are U8 and F32 with
1669 * vector lengths between 1 and 4.
1670 * @param[in] in input Allocation
1671 * @param[out] out output Allocation
1672 */
Tim Murray89daad62013-07-29 14:30:02 -07001673 void forEach(sp<Allocation> in, sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001674 /**
1675 * Set the value to be added after the color matrix has been
1676 * applied. The default value is {0, 0, 0, 0}.
1677 * @param[in] add float[4] of values
1678 */
Tim Murray10913a52013-08-20 17:19:47 -07001679 void setAdd(float* add);
Tim Murray75e877d2013-09-11 14:45:20 -07001680
1681 /**
1682 * Set the color matrix which will be applied to each cell of the
1683 * image. The alpha channel will be copied.
1684 *
1685 * @param[in] m float[9] of values
1686 */
Tim Murray89daad62013-07-29 14:30:02 -07001687 void setColorMatrix3(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001688 /**
1689 * Set the color matrix which will be applied to each cell of the
1690 * image.
1691 *
1692 * @param[in] m float[16] of values
1693 */
Tim Murray89daad62013-07-29 14:30:02 -07001694 void setColorMatrix4(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001695 /**
1696 * Set a color matrix to convert from RGB to luminance. The alpha
1697 * channel will be a copy.
1698 */
Tim Murray89daad62013-07-29 14:30:02 -07001699 void setGreyscale();
Tim Murray75e877d2013-09-11 14:45:20 -07001700 /**
1701 * Set the matrix to convert from RGB to YUV with a direct copy of
1702 * the 4th channel.
1703 */
Tim Murray89daad62013-07-29 14:30:02 -07001704 void setRGBtoYUV();
Tim Murray75e877d2013-09-11 14:45:20 -07001705 /**
1706 * Set the matrix to convert from YUV to RGB with a direct copy of
1707 * the 4th channel.
1708 */
Tim Murray89daad62013-07-29 14:30:02 -07001709 void setYUVtoRGB();
1710};
1711
Tim Murray75e877d2013-09-11 14:45:20 -07001712/**
1713 * Intrinsic for applying a 3x3 convolve to an allocation.
1714 */
Tim Murray89daad62013-07-29 14:30:02 -07001715class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001716 private:
Tim Murray89daad62013-07-29 14:30:02 -07001717 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001718 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001719 /**
1720 * Supported types U8 and F32 with vector lengths between 1 and
1721 * 4. The default convolution kernel is the identity.
1722 * @param[in] rs RenderScript context
1723 * @param[in] e Element
1724 * @return new ScriptIntrinsicConvolve3x3
1725 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001726 static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001727 /**
1728 * Sets input for intrinsic.
1729 * @param[in] in input Allocation
1730 */
Tim Murray89daad62013-07-29 14:30:02 -07001731 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001732 /**
1733 * Launches the intrinsic.
1734 * @param[in] out output Allocation
1735 */
Tim Murray89daad62013-07-29 14:30:02 -07001736 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001737 /**
1738 * Sets convolution kernel.
1739 * @param[in] v float[9] of values
1740 */
Tim Murray89daad62013-07-29 14:30:02 -07001741 void setCoefficients(float* v);
1742};
1743
Tim Murray75e877d2013-09-11 14:45:20 -07001744/**
1745 * Intrinsic for applying a 5x5 convolve to an allocation.
1746 */
Tim Murray89daad62013-07-29 14:30:02 -07001747class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001748 private:
Tim Murray89daad62013-07-29 14:30:02 -07001749 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001750 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001751 /**
1752 * Supported types U8 and F32 with vector lengths between 1 and
1753 * 4. The default convolution kernel is the identity.
1754 * @param[in] rs RenderScript context
1755 * @param[in] e Element
1756 * @return new ScriptIntrinsicConvolve5x5
1757 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001758 static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001759 /**
1760 * Sets input for intrinsic.
1761 * @param[in] in input Allocation
1762 */
Tim Murray89daad62013-07-29 14:30:02 -07001763 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001764 /**
1765 * Launches the intrinsic.
1766 * @param[in] out output Allocation
1767 */
Tim Murray89daad62013-07-29 14:30:02 -07001768 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001769 /**
1770 * Sets convolution kernel.
1771 * @param[in] v float[25] of values
1772 */
Tim Murray89daad62013-07-29 14:30:02 -07001773 void setCoefficients(float* v);
1774};
1775
Tim Murray75e877d2013-09-11 14:45:20 -07001776/**
1777 * Intrinsic for computing a histogram.
1778 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001779class ScriptIntrinsicHistogram : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001780 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001781 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
Tim Murray10913a52013-08-20 17:19:47 -07001782 sp<Allocation> mOut;
Tim Murray21fa7a02013-08-15 16:25:03 -07001783 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001784 /**
1785 * Create an intrinsic for calculating the histogram of an uchar
1786 * or uchar4 image.
1787 *
1788 * Supported elements types are U8_4, U8_3, U8_2, and U8.
1789 *
1790 * @param[in] rs The RenderScript context
1791 * @param[in] e Element type for inputs
1792 *
1793 * @return ScriptIntrinsicHistogram
1794 */
Jon Parrb05c8502015-03-13 14:41:58 +00001795 static sp<ScriptIntrinsicHistogram> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001796 /**
1797 * Set the output of the histogram. 32 bit integer types are
1798 * supported.
1799 *
1800 * @param[in] aout The output allocation
1801 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001802 void setOutput(sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001803 /**
1804 * Set the coefficients used for the dot product calculation. The
1805 * default is {0.299f, 0.587f, 0.114f, 0.f}.
1806 *
1807 * Coefficients must be >= 0 and sum to 1.0 or less.
1808 *
1809 * @param[in] r Red coefficient
1810 * @param[in] g Green coefficient
1811 * @param[in] b Blue coefficient
1812 * @param[in] a Alpha coefficient
1813 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001814 void setDotCoefficients(float r, float g, float b, float a);
Tim Murray75e877d2013-09-11 14:45:20 -07001815 /**
1816 * Process an input buffer and place the histogram into the output
1817 * allocation. The output allocation may be a narrower vector size
1818 * than the input. In this case the vector size of the output is
1819 * used to determine how many of the input channels are used in
1820 * the computation. This is useful if you have an RGBA input
1821 * buffer but only want the histogram for RGB.
1822 *
1823 * 1D and 2D input allocations are supported.
1824 *
1825 * @param[in] ain The input image
1826 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001827 void forEach(sp<Allocation> ain);
Tim Murray75e877d2013-09-11 14:45:20 -07001828 /**
1829 * Process an input buffer and place the histogram into the output
1830 * allocation. The dot product of the input channel and the
1831 * coefficients from 'setDotCoefficients' are used to calculate
1832 * the output values.
1833 *
1834 * 1D and 2D input allocations are supported.
1835 *
1836 * @param ain The input image
1837 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001838 void forEach_dot(sp<Allocation> ain);
1839};
1840
Tim Murray75e877d2013-09-11 14:45:20 -07001841/**
1842 * Intrinsic for applying a per-channel lookup table. Each channel of
1843 * the input has an independant lookup table. The tables are 256
1844 * entries in size and can cover the full value range of U8_4.
1845 **/
Tim Murrayb27b1812013-08-05 14:00:40 -07001846class ScriptIntrinsicLUT : public ScriptIntrinsic {
1847 private:
1848 sp<Allocation> LUT;
1849 bool mDirty;
1850 unsigned char mCache[1024];
Tim Murray2acce992013-08-28 14:23:31 -07001851 void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray21fa7a02013-08-15 16:25:03 -07001852 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001853
Tim Murray89daad62013-07-29 14:30:02 -07001854 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001855 /**
1856 * Supported elements types are U8_4.
1857 *
1858 * The defaults tables are identity.
1859 *
1860 * @param[in] rs The RenderScript context
1861 * @param[in] e Element type for intputs and outputs
1862 *
1863 * @return ScriptIntrinsicLUT
1864 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001865 static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001866 /**
1867 * Invoke the kernel and apply the lookup to each cell of ain and
1868 * copy to aout.
1869 *
1870 * @param[in] ain Input allocation
1871 * @param[in] aout Output allocation
1872 */
Tim Murray89daad62013-07-29 14:30:02 -07001873 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001874 /**
1875 * Sets entries in LUT for the red channel.
1876 * @param[in] base base of region to update
1877 * @param[in] length length of region to update
1878 * @param[in] lutValues LUT values to use
1879 */
Tim Murray2acce992013-08-28 14:23:31 -07001880 void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001881 /**
1882 * Sets entries in LUT for the green channel.
1883 * @param[in] base base of region to update
1884 * @param[in] length length of region to update
1885 * @param[in] lutValues LUT values to use
1886 */
Tim Murray2acce992013-08-28 14:23:31 -07001887 void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001888 /**
1889 * Sets entries in LUT for the blue channel.
1890 * @param[in] base base of region to update
1891 * @param[in] length length of region to update
1892 * @param[in] lutValues LUT values to use
1893 */
Tim Murray2acce992013-08-28 14:23:31 -07001894 void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001895 /**
1896 * Sets entries in LUT for the alpha channel.
1897 * @param[in] base base of region to update
1898 * @param[in] length length of region to update
1899 * @param[in] lutValues LUT values to use
1900 */
Tim Murray2acce992013-08-28 14:23:31 -07001901 void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murrayb27b1812013-08-05 14:00:40 -07001902 virtual ~ScriptIntrinsicLUT();
1903};
1904
Tim Murray75e877d2013-09-11 14:45:20 -07001905/**
Miao Wange5428e62015-03-10 15:29:40 -07001906 * Intrinsic for performing a resize of a 2D allocation.
1907 */
1908class ScriptIntrinsicResize : public ScriptIntrinsic {
1909 private:
1910 sp<Allocation> mInput;
1911 ScriptIntrinsicResize(sp<RS> rs, sp<const Element> e);
1912 public:
1913 /**
1914 * Supported Element types are U8_4. Default lookup table is identity.
1915 * @param[in] rs RenderScript context
1916 * @param[in] e Element
1917 * @return new ScriptIntrinsic
1918 */
1919 static sp<ScriptIntrinsicResize> create(sp<RS> rs);
1920
1921 /**
1922 * Resize copy the input allocation to the output specified. The
1923 * Allocation is rescaled if necessary using bi-cubic
1924 * interpolation.
1925 * @param[in] ain input Allocation
1926 * @param[in] aout output Allocation
1927 */
1928 void forEach_bicubic(sp<Allocation> aout);
1929
1930 /**
1931 * Set the input of the resize.
1932 * @param[in] lut new lookup table
1933 */
1934 void setInput(sp<Allocation> ain);
1935};
1936
1937/**
Tim Murray75e877d2013-09-11 14:45:20 -07001938 * Intrinsic for converting an Android YUV buffer to RGB.
1939 *
1940 * The input allocation should be supplied in a supported YUV format
1941 * as a YUV element Allocation. The output is RGBA; the alpha channel
1942 * will be set to 255.
1943 */
Tim Murray89daad62013-07-29 14:30:02 -07001944class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001945 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001946 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001947 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001948 /**
1949 * Create an intrinsic for converting YUV to RGB.
1950 *
1951 * Supported elements types are U8_4.
1952 *
1953 * @param[in] rs The RenderScript context
1954 * @param[in] e Element type for output
1955 *
1956 * @return ScriptIntrinsicYuvToRGB
1957 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001958 static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001959 /**
1960 * Set the input YUV allocation.
1961 *
1962 * @param[in] ain The input allocation.
1963 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001964 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001965
1966 /**
1967 * Convert the image to RGB.
1968 *
1969 * @param[in] aout Output allocation. Must match creation element
1970 * type.
1971 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001972 void forEach(sp<Allocation> out);
Tim Murray89daad62013-07-29 14:30:02 -07001973
1974};
Tim Murrayb27b1812013-08-05 14:00:40 -07001975
Tim Murray75e877d2013-09-11 14:45:20 -07001976/**
1977 * Sampler object that defines how Allocations can be read as textures
1978 * within a kernel. Samplers are used in conjunction with the rsSample
1979 * runtime function to return values from normalized coordinates.
1980 *
1981 * Any Allocation used with a Sampler must have been created with
1982 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an
1983 * Allocation that was not created with
1984 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined.
1985 **/
Tim Murray729b6fe2013-07-23 16:20:42 -07001986 class Sampler : public BaseObj {
1987 private:
1988 Sampler(sp<RS> rs, void* id);
Miao Wange5428e62015-03-10 15:29:40 -07001989 Sampler(sp<RS> rs, void* id, RsSamplerValue min, RsSamplerValue mag,
1990 RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
Tim Murray729b6fe2013-07-23 16:20:42 -07001991 RsSamplerValue mMin;
1992 RsSamplerValue mMag;
1993 RsSamplerValue mWrapS;
1994 RsSamplerValue mWrapT;
Tim Murray729b6fe2013-07-23 16:20:42 -07001995 float mAniso;
1996
1997 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001998 /**
1999 * Creates a non-standard Sampler.
2000 * @param[in] rs RenderScript context
2001 * @param[in] min minification
2002 * @param[in] mag magnification
2003 * @param[in] wrapS S wrapping mode
2004 * @param[in] wrapT T wrapping mode
2005 * @param[in] anisotropy anisotropy setting
2006 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002007 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
2008
Tim Murray75e877d2013-09-11 14:45:20 -07002009 /**
2010 * @return minification setting for the sampler
2011 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002012 RsSamplerValue getMinification();
Tim Murray75e877d2013-09-11 14:45:20 -07002013 /**
2014 * @return magnification setting for the sampler
2015 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002016 RsSamplerValue getMagnification();
Tim Murray75e877d2013-09-11 14:45:20 -07002017 /**
2018 * @return S wrapping mode for the sampler
2019 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002020 RsSamplerValue getWrapS();
Tim Murray75e877d2013-09-11 14:45:20 -07002021 /**
2022 * @return T wrapping mode for the sampler
2023 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002024 RsSamplerValue getWrapT();
Tim Murray75e877d2013-09-11 14:45:20 -07002025 /**
2026 * @return anisotropy setting for the sampler
2027 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002028 float getAnisotropy();
2029
Tim Murray75e877d2013-09-11 14:45:20 -07002030 /**
2031 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2032 * clamp.
2033 *
2034 * @param rs Context to which the sampler will belong.
2035 *
2036 * @return Sampler
2037 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002038 static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002039 /**
2040 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2041 * clamp.
2042 *
2043 * @param rs Context to which the sampler will belong.
2044 *
2045 * @return Sampler
2046 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002047 static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002048 /**
2049 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2050 * wrap modes set to clamp.
2051 *
2052 * @param rs Context to which the sampler will belong.
2053 *
2054 * @return Sampler
2055 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002056 static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002057 /**
2058 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2059 * wrap.
2060 *
2061 * @param rs Context to which the sampler will belong.
2062 *
2063 * @return Sampler
2064 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002065 static sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002066 /**
2067 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2068 * wrap.
2069 *
2070 * @param rs Context to which the sampler will belong.
2071 *
2072 * @return Sampler
2073 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002074 static sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002075 /**
2076 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2077 * wrap modes set to wrap.
2078 *
2079 * @param rs Context to which the sampler will belong.
2080 *
2081 * @return Sampler
2082 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002083 static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002084 /**
2085 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2086 * mirrored repeat.
2087 *
2088 * @param rs Context to which the sampler will belong.
2089 *
2090 * @return Sampler
2091 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002092 static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002093 /**
2094 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2095 * mirrored repeat.
2096 *
2097 * @param rs Context to which the sampler will belong.
2098 *
2099 * @return Sampler
2100 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002101 static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002102 /**
2103 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2104 * mirrored repeat.
2105 *
2106 * @param rs Context to which the sampler will belong.
2107 *
2108 * @return Sampler
2109 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002110 static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray729b6fe2013-07-23 16:20:42 -07002111
2112};
2113
Stephen Hinesd10412f2013-08-29 18:27:21 -07002114class Byte2 {
2115 public:
2116 int8_t x, y;
2117
2118 Byte2(int8_t initX, int8_t initY)
2119 : x(initX), y(initY) {}
2120 Byte2() : x(0), y(0) {}
2121};
2122
2123class Byte3 {
2124 public:
2125 int8_t x, y, z;
2126
2127 Byte3(int8_t initX, int8_t initY, int8_t initZ)
2128 : x(initX), y(initY), z(initZ) {}
2129 Byte3() : x(0), y(0), z(0) {}
2130};
2131
2132class Byte4 {
2133 public:
2134 int8_t x, y, z, w;
2135
2136 Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
2137 : x(initX), y(initY), z(initZ), w(initW) {}
2138 Byte4() : x(0), y(0), z(0), w(0) {}
2139};
2140
2141class UByte2 {
2142 public:
2143 uint8_t x, y;
2144
2145 UByte2(uint8_t initX, uint8_t initY)
2146 : x(initX), y(initY) {}
2147 UByte2() : x(0), y(0) {}
2148};
2149
2150class UByte3 {
2151 public:
2152 uint8_t x, y, z;
2153
2154 UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
2155 : x(initX), y(initY), z(initZ) {}
2156 UByte3() : x(0), y(0), z(0) {}
2157};
2158
2159class UByte4 {
2160 public:
2161 uint8_t x, y, z, w;
2162
2163 UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
2164 : x(initX), y(initY), z(initZ), w(initW) {}
2165 UByte4() : x(0), y(0), z(0), w(0) {}
2166};
2167
2168class Short2 {
2169 public:
2170 short x, y;
2171
2172 Short2(short initX, short initY)
2173 : x(initX), y(initY) {}
2174 Short2() : x(0), y(0) {}
2175};
2176
2177class Short3 {
2178 public:
2179 short x, y, z;
2180
2181 Short3(short initX, short initY, short initZ)
2182 : x(initX), y(initY), z(initZ) {}
2183 Short3() : x(0), y(0), z(0) {}
2184};
2185
2186class Short4 {
2187 public:
2188 short x, y, z, w;
2189
2190 Short4(short initX, short initY, short initZ, short initW)
2191 : x(initX), y(initY), z(initZ), w(initW) {}
2192 Short4() : x(0), y(0), z(0), w(0) {}
2193};
2194
2195class UShort2 {
2196 public:
2197 uint16_t x, y;
2198
2199 UShort2(uint16_t initX, uint16_t initY)
2200 : x(initX), y(initY) {}
2201 UShort2() : x(0), y(0) {}
2202};
2203
2204class UShort3 {
2205 public:
2206 uint16_t x, y, z;
2207
2208 UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
2209 : x(initX), y(initY), z(initZ) {}
2210 UShort3() : x(0), y(0), z(0) {}
2211};
2212
2213class UShort4 {
2214 public:
2215 uint16_t x, y, z, w;
2216
2217 UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
2218 : x(initX), y(initY), z(initZ), w(initW) {}
2219 UShort4() : x(0), y(0), z(0), w(0) {}
2220};
2221
2222class Int2 {
2223 public:
2224 int x, y;
2225
2226 Int2(int initX, int initY)
2227 : x(initX), y(initY) {}
2228 Int2() : x(0), y(0) {}
2229};
2230
2231class Int3 {
2232 public:
2233 int x, y, z;
2234
2235 Int3(int initX, int initY, int initZ)
2236 : x(initX), y(initY), z(initZ) {}
2237 Int3() : x(0), y(0), z(0) {}
2238};
2239
2240class Int4 {
2241 public:
2242 int x, y, z, w;
2243
2244 Int4(int initX, int initY, int initZ, int initW)
2245 : x(initX), y(initY), z(initZ), w(initW) {}
2246 Int4() : x(0), y(0), z(0), w(0) {}
2247};
2248
2249class UInt2 {
2250 public:
2251 uint32_t x, y;
2252
2253 UInt2(uint32_t initX, uint32_t initY)
2254 : x(initX), y(initY) {}
2255 UInt2() : x(0), y(0) {}
2256};
2257
2258class UInt3 {
2259 public:
2260 uint32_t x, y, z;
2261
2262 UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
2263 : x(initX), y(initY), z(initZ) {}
2264 UInt3() : x(0), y(0), z(0) {}
2265};
2266
2267class UInt4 {
2268 public:
2269 uint32_t x, y, z, w;
2270
2271 UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
2272 : x(initX), y(initY), z(initZ), w(initW) {}
2273 UInt4() : x(0), y(0), z(0), w(0) {}
2274};
2275
2276class Long2 {
2277 public:
2278 int64_t x, y;
2279
2280 Long2(int64_t initX, int64_t initY)
2281 : x(initX), y(initY) {}
2282 Long2() : x(0), y(0) {}
2283};
2284
2285class Long3 {
2286 public:
2287 int64_t x, y, z;
2288
2289 Long3(int64_t initX, int64_t initY, int64_t initZ)
2290 : x(initX), y(initY), z(initZ) {}
2291 Long3() : x(0), y(0), z(0) {}
2292};
2293
2294class Long4 {
2295 public:
2296 int64_t x, y, z, w;
2297
2298 Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
2299 : x(initX), y(initY), z(initZ), w(initW) {}
2300 Long4() : x(0), y(0), z(0), w(0) {}
2301};
2302
2303class ULong2 {
2304 public:
2305 uint64_t x, y;
2306
2307 ULong2(uint64_t initX, uint64_t initY)
2308 : x(initX), y(initY) {}
2309 ULong2() : x(0), y(0) {}
2310};
2311
2312class ULong3 {
2313 public:
2314 uint64_t x, y, z;
2315
2316 ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
2317 : x(initX), y(initY), z(initZ) {}
2318 ULong3() : x(0), y(0), z(0) {}
2319};
2320
2321class ULong4 {
2322 public:
2323 uint64_t x, y, z, w;
2324
2325 ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
2326 : x(initX), y(initY), z(initZ), w(initW) {}
2327 ULong4() : x(0), y(0), z(0), w(0) {}
2328};
2329
2330class Float2 {
2331 public:
2332 float x, y;
2333
2334 Float2(float initX, float initY)
2335 : x(initX), y(initY) {}
2336 Float2() : x(0), y(0) {}
2337};
2338
2339class Float3 {
2340 public:
2341 float x, y, z;
2342
2343 Float3(float initX, float initY, float initZ)
2344 : x(initX), y(initY), z(initZ) {}
2345 Float3() : x(0.f), y(0.f), z(0.f) {}
2346};
2347
2348class Float4 {
2349 public:
2350 float x, y, z, w;
2351
2352 Float4(float initX, float initY, float initZ, float initW)
2353 : x(initX), y(initY), z(initZ), w(initW) {}
2354 Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
2355};
2356
2357class Double2 {
2358 public:
2359 double x, y;
2360
2361 Double2(double initX, double initY)
2362 : x(initX), y(initY) {}
2363 Double2() : x(0), y(0) {}
2364};
2365
2366class Double3 {
2367 public:
2368 double x, y, z;
2369
2370 Double3(double initX, double initY, double initZ)
2371 : x(initX), y(initY), z(initZ) {}
2372 Double3() : x(0), y(0), z(0) {}
2373};
2374
2375class Double4 {
2376 public:
2377 double x, y, z, w;
2378
2379 Double4(double initX, double initY, double initZ, double initW)
2380 : x(initX), y(initY), z(initZ), w(initW) {}
2381 Double4() : x(0), y(0), z(0), w(0) {}
2382};
2383
Tim Murray84bf2b82012-10-31 16:03:16 -07002384}
Tim Murray7f0d5682012-11-08 16:35:24 -08002385
Tim Murray84bf2b82012-10-31 16:03:16 -07002386}
2387
2388#endif