blob: f3f7f31eeb402dde26cf44d59eccb8c4279169c1 [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.
Tim Murray84e3dea2013-09-09 16:12:51 -070083 RS_INIT_MAX = 4
84 };
85
Tim Murray75e877d2013-09-11 14:45:20 -070086 /**
87 * The RenderScript context. This class controls initialization, resource management, and teardown.
88 */
Tim Murray89daad62013-07-29 14:30:02 -070089 class RS : public android::RSC::LightRefBase<RS> {
Tim Murray84bf2b82012-10-31 16:03:16 -070090
91 public:
92 RS();
93 virtual ~RS();
94
Tim Murray75e877d2013-09-11 14:45:20 -070095 /**
96 * Initializes a RenderScript context. A context must be initialized before it can be used.
Tim Murraycaf41262013-12-13 12:54:37 -080097 * @param[in] name Directory name to be used by this context. This should be equivalent to
98 * Context.getCacheDir().
Tim Murray75e877d2013-09-11 14:45:20 -070099 * @param[in] flags Optional flags for this context.
100 * @return true on success
101 */
Miao Wangbc10dff2015-04-03 17:44:55 -0700102 bool init(const char * name, uint32_t flags = 0);
Tim Murray84bf2b82012-10-31 16:03:16 -0700103
Tim Murray75e877d2013-09-11 14:45:20 -0700104 /**
105 * Sets the error handler function for this context. This error handler is
106 * called whenever an error is set.
107 *
108 * @param[in] func Error handler function
109 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700110 void setErrorHandler(ErrorHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700111
112 /**
113 * Returns the current error handler function for this context.
114 *
115 * @return pointer to current error handler function or NULL if not set
116 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700117 ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
118
Tim Murray75e877d2013-09-11 14:45:20 -0700119 /**
120 * Sets the message handler function for this context. This message handler
121 * is called whenever a message is sent from a RenderScript kernel.
122 *
123 * @param[in] func Message handler function
124 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700125 void setMessageHandler(MessageHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700126
127 /**
128 * Returns the current message handler function for this context.
129 *
130 * @return pointer to current message handler function or NULL if not set
131 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700132 MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
133
Tim Murray75e877d2013-09-11 14:45:20 -0700134 /**
135 * Returns current status for the context.
136 *
137 * @return current error
138 */
Tim Murray10913a52013-08-20 17:19:47 -0700139 RSError getError();
Tim Murray84bf2b82012-10-31 16:03:16 -0700140
Tim Murray75e877d2013-09-11 14:45:20 -0700141 /**
142 * Waits for any currently running asynchronous operations to finish. This
143 * should only be used for performance testing and timing.
144 */
Tim Murraybaca6c32012-11-14 16:51:46 -0800145 void finish();
146
Tim Murray75e877d2013-09-11 14:45:20 -0700147 RsContext getContext() { return mContext; }
148 void throwError(RSError error, const char *errMsg);
149
Tim Murraya4230962013-07-17 16:50:10 -0700150 static dispatchTable* dispatch;
151
Tim Murray84bf2b82012-10-31 16:03:16 -0700152 private:
Tim Murray4a92d122013-07-22 10:56:18 -0700153 static bool usingNative;
Tim Murraya4230962013-07-17 16:50:10 -0700154 static bool initDispatch(int targetApi);
155
Miao Wangbc10dff2015-04-03 17:44:55 -0700156 bool init(const char * name, int targetApi, uint32_t flags);
Tim Murray84bf2b82012-10-31 16:03:16 -0700157 static void * threadProc(void *);
158
159 static bool gInitialized;
160 static pthread_mutex_t gInitMutex;
161
162 pthread_t mMessageThreadId;
163 pid_t mNativeMessageThreadId;
164 bool mMessageRun;
165
166 RsDevice mDev;
167 RsContext mContext;
Tim Murray21fa7a02013-08-15 16:25:03 -0700168 RSError mCurrentError;
Tim Murray84bf2b82012-10-31 16:03:16 -0700169
170 ErrorHandlerFunc_t mErrorFunc;
171 MessageHandlerFunc_t mMessageFunc;
Tim Murraya4230962013-07-17 16:50:10 -0700172 bool mInit;
Tim Murray84bf2b82012-10-31 16:03:16 -0700173
Miao Wangbc10dff2015-04-03 17:44:55 -0700174 char mCacheDir[PATH_MAX+1];
175 uint32_t mCacheDirLen;
Tim Murraycaf41262013-12-13 12:54:37 -0800176
Tim Murray84bf2b82012-10-31 16:03:16 -0700177 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700178 sp<const Element> U8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700179 sp<const Element> U8_2;
180 sp<const Element> U8_3;
181 sp<const Element> U8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700182 sp<const Element> I8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700183 sp<const Element> I8_2;
184 sp<const Element> I8_3;
185 sp<const Element> I8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700186 sp<const Element> U16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700187 sp<const Element> U16_2;
188 sp<const Element> U16_3;
189 sp<const Element> U16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700190 sp<const Element> I16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700191 sp<const Element> I16_2;
192 sp<const Element> I16_3;
193 sp<const Element> I16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700194 sp<const Element> U32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700195 sp<const Element> U32_2;
196 sp<const Element> U32_3;
197 sp<const Element> U32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700198 sp<const Element> I32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700199 sp<const Element> I32_2;
200 sp<const Element> I32_3;
201 sp<const Element> I32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700202 sp<const Element> U64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700203 sp<const Element> U64_2;
204 sp<const Element> U64_3;
205 sp<const Element> U64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700206 sp<const Element> I64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700207 sp<const Element> I64_2;
208 sp<const Element> I64_3;
209 sp<const Element> I64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700210 sp<const Element> F32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700211 sp<const Element> F32_2;
212 sp<const Element> F32_3;
213 sp<const Element> F32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700214 sp<const Element> F64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700215 sp<const Element> F64_2;
216 sp<const Element> F64_3;
217 sp<const Element> F64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700218 sp<const Element> BOOLEAN;
Tim Murray84bf2b82012-10-31 16:03:16 -0700219
Tim Murray89daad62013-07-29 14:30:02 -0700220 sp<const Element> ELEMENT;
221 sp<const Element> TYPE;
222 sp<const Element> ALLOCATION;
223 sp<const Element> SAMPLER;
224 sp<const Element> SCRIPT;
225 sp<const Element> MESH;
226 sp<const Element> PROGRAM_FRAGMENT;
227 sp<const Element> PROGRAM_VERTEX;
228 sp<const Element> PROGRAM_RASTER;
229 sp<const Element> PROGRAM_STORE;
Tim Murray84bf2b82012-10-31 16:03:16 -0700230
Tim Murray89daad62013-07-29 14:30:02 -0700231 sp<const Element> A_8;
232 sp<const Element> RGB_565;
233 sp<const Element> RGB_888;
234 sp<const Element> RGBA_5551;
235 sp<const Element> RGBA_4444;
236 sp<const Element> RGBA_8888;
Tim Murray84bf2b82012-10-31 16:03:16 -0700237
Tim Murrayeb4426d2013-08-27 15:30:16 -0700238 sp<const Element> YUV;
Tim Murray84bf2b82012-10-31 16:03:16 -0700239
Tim Murray89daad62013-07-29 14:30:02 -0700240 sp<const Element> MATRIX_4X4;
241 sp<const Element> MATRIX_3X3;
242 sp<const Element> MATRIX_2X2;
Tim Murray84bf2b82012-10-31 16:03:16 -0700243 } mElements;
244
Tim Murray729b6fe2013-07-23 16:20:42 -0700245 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700246 sp<const Sampler> CLAMP_NEAREST;
247 sp<const Sampler> CLAMP_LINEAR;
248 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
249 sp<const Sampler> WRAP_NEAREST;
250 sp<const Sampler> WRAP_LINEAR;
251 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
252 sp<const Sampler> MIRRORED_REPEAT_NEAREST;
253 sp<const Sampler> MIRRORED_REPEAT_LINEAR;
254 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Tim Murray729b6fe2013-07-23 16:20:42 -0700255 } mSamplers;
256 friend class Sampler;
257 friend class Element;
Tim Murraycaf41262013-12-13 12:54:37 -0800258 friend class ScriptC;
Tim Murray84bf2b82012-10-31 16:03:16 -0700259};
260
Tim Murray75e877d2013-09-11 14:45:20 -0700261 /**
262 * Base class for all RenderScript objects. Not for direct use by developers.
263 */
Tim Murray89daad62013-07-29 14:30:02 -0700264class BaseObj : public android::RSC::LightRefBase<BaseObj> {
265public:
266 void * getID() const;
267 virtual ~BaseObj();
268 virtual void updateFromNative();
269 virtual bool equals(sp<const BaseObj> obj);
270
Tim Murray84bf2b82012-10-31 16:03:16 -0700271protected:
272 void *mID;
Tim Murray35609072013-12-03 11:36:03 -0800273 RS* mRS;
Miao Wangbc10dff2015-04-03 17:44:55 -0700274 const char * mName;
Tim Murray84bf2b82012-10-31 16:03:16 -0700275
276 BaseObj(void *id, sp<RS> rs);
277 void checkValid();
278
279 static void * getObjID(sp<const BaseObj> o);
280
Tim Murray84bf2b82012-10-31 16:03:16 -0700281};
282
Tim Murray75e877d2013-09-11 14:45:20 -0700283 /**
284 * This class provides the primary method through which data is passed to and
285 * from RenderScript kernels. An Allocation provides the backing store for a
286 * given Type.
287 *
288 * An Allocation also contains a set of usage flags that denote how the
289 * Allocation could be used. For example, an Allocation may have usage flags
290 * specifying that it can be used from a script as well as input to a
291 * Sampler. A developer must synchronize across these different usages using
292 * syncAll(int) in order to ensure that different users of the Allocation have
293 * a consistent view of memory. For example, in the case where an Allocation is
294 * used as the output of one kernel and as Sampler input in a later kernel, a
295 * developer must call syncAll(RS_ALLOCATION_USAGE_SCRIPT) prior to launching the
296 * second kernel to ensure correctness.
297 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700298class Allocation : public BaseObj {
299protected:
Tim Murray89daad62013-07-29 14:30:02 -0700300 sp<const Type> mType;
Tim Murray84bf2b82012-10-31 16:03:16 -0700301 uint32_t mUsage;
Tim Murray89daad62013-07-29 14:30:02 -0700302 sp<Allocation> mAdaptedAllocation;
Tim Murray84bf2b82012-10-31 16:03:16 -0700303
304 bool mConstrainedLOD;
305 bool mConstrainedFace;
306 bool mConstrainedY;
307 bool mConstrainedZ;
308 bool mReadAllowed;
309 bool mWriteAllowed;
Miao Wange5428e62015-03-10 15:29:40 -0700310 bool mAutoPadding;
Tim Murray84bf2b82012-10-31 16:03:16 -0700311 uint32_t mSelectedY;
312 uint32_t mSelectedZ;
313 uint32_t mSelectedLOD;
314 RsAllocationCubemapFace mSelectedFace;
315
316 uint32_t mCurrentDimX;
317 uint32_t mCurrentDimY;
318 uint32_t mCurrentDimZ;
319 uint32_t mCurrentCount;
320
321 void * getIDSafe() const;
322 void updateCacheInfo(sp<const Type> t);
323
324 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
325
Miao Wange5428e62015-03-10 15:29:40 -0700326 void validateIsInt64();
Tim Murray84bf2b82012-10-31 16:03:16 -0700327 void validateIsInt32();
328 void validateIsInt16();
329 void validateIsInt8();
330 void validateIsFloat32();
Miao Wange5428e62015-03-10 15:29:40 -0700331 void validateIsFloat64();
Tim Murray84bf2b82012-10-31 16:03:16 -0700332 void validateIsObject();
333
334 virtual void updateFromNative();
335
336 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
Tim Murray9d24ae62013-08-30 12:17:14 -0700337 void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff,
338 uint32_t w, uint32_t h, uint32_t d);
Tim Murray84bf2b82012-10-31 16:03:16 -0700339
340public:
Tim Murray75e877d2013-09-11 14:45:20 -0700341
342 /**
343 * Return Type for the allocation.
344 * @return pointer to underlying Type
345 */
Stephen Hinesa180b7d2013-08-21 12:42:13 -0700346 sp<const Type> getType() const {
Tim Murray84bf2b82012-10-31 16:03:16 -0700347 return mType;
348 }
349
Tim Murray75e877d2013-09-11 14:45:20 -0700350 /**
Miao Wange5428e62015-03-10 15:29:40 -0700351 * Enable/Disable AutoPadding for Vec3 elements.
352 *
353 * @param useAutoPadding True: enable AutoPadding; flase: disable AutoPadding
354 *
355 */
356 void setAutoPadding(bool useAutoPadding) {
357 mAutoPadding = useAutoPadding;
358 }
359
360 /**
Tim Murray75e877d2013-09-11 14:45:20 -0700361 * Propagate changes from one usage of the Allocation to other usages of the Allocation.
362 * @param[in] srcLocation source location with changes to propagate elsewhere
363 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700364 void syncAll(RsAllocationUsageType srcLocation);
Miao Wang09d2dd22015-03-18 20:09:20 -0700365
366 /**
367 * Send a buffer to the output stream. The contents of the Allocation will
368 * be undefined after this operation. This operation is only valid if
369 * USAGE_IO_OUTPUT is set on the Allocation.
370 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700371 void ioSendOutput();
Miao Wang09d2dd22015-03-18 20:09:20 -0700372
373 /**
374 * Receive the latest input into the Allocation. This operation
375 * is only valid if USAGE_IO_INPUT is set on the Allocation.
376 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700377 void ioGetInput();
378
Miao Wang09d2dd22015-03-18 20:09:20 -0700379#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
380 /**
381 * Returns the handle to a raw buffer that is being managed by the screen
382 * compositor. This operation is only valid for Allocations with USAGE_IO_INPUT.
383 * @return Surface associated with allocation
384 */
385 sp<Surface> getSurface();
386
387 /**
388 * Associate a Surface with this Allocation. This
389 * operation is only valid for Allocations with USAGE_IO_OUTPUT.
390 * @param[in] s Surface to associate with allocation
391 */
392 void setSurface(sp<Surface> s);
393#endif
394
Tim Murray75e877d2013-09-11 14:45:20 -0700395 /**
396 * Generate a mipmap chain. This is only valid if the Type of the Allocation
397 * includes mipmaps. This function will generate a complete set of mipmaps
398 * from the top level LOD and place them into the script memory space. If
399 * the Allocation is also using other memory spaces, a call to
400 * syncAll(Allocation.USAGE_SCRIPT) is required.
401 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700402 void generateMipmaps();
Tim Murray509ea5c2012-11-13 11:56:40 -0800403
Tim Murray75e877d2013-09-11 14:45:20 -0700404 /**
405 * Copy an array into part of this Allocation.
406 * @param[in] off offset of first Element to be overwritten
407 * @param[in] count number of Elements to copy
408 * @param[in] data array from which to copy
409 */
Tim Murray0b93e302012-11-15 14:56:54 -0800410 void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
Tim Murray75e877d2013-09-11 14:45:20 -0700411
412 /**
413 * Copy part of an Allocation into part of this Allocation.
414 * @param[in] off offset of first Element to be overwritten
415 * @param[in] count number of Elements to copy
416 * @param[in] data Allocation from which to copy
417 * @param[in] dataOff offset of first Element in data to copy
418 */
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800419 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700420
Tim Murray75e877d2013-09-11 14:45:20 -0700421 /**
422 * Copy an array into part of this Allocation.
423 * @param[in] off offset of first Element to be overwritten
424 * @param[in] count number of Elements to copy
425 * @param[in] data array from which to copy
426 */
Tim Murray0b93e302012-11-15 14:56:54 -0800427 void copy1DRangeTo(uint32_t off, size_t count, void *data);
428
Tim Murray75e877d2013-09-11 14:45:20 -0700429 /**
430 * Copy entire array to an Allocation.
431 * @param[in] data array from which to copy
432 */
Tim Murray0b93e302012-11-15 14:56:54 -0800433 void copy1DFrom(const void* data);
Tim Murray75e877d2013-09-11 14:45:20 -0700434
435 /**
436 * Copy entire Allocation to an array.
437 * @param[in] data destination array
438 */
Tim Murray0b93e302012-11-15 14:56:54 -0800439 void copy1DTo(void* data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800440
Tim Murray75e877d2013-09-11 14:45:20 -0700441 /**
442 * Copy from an array into a rectangular region in this Allocation. The
443 * array is assumed to be tightly packed.
444 * @param[in] xoff X offset of region to update in this Allocation
445 * @param[in] yoff Y offset of region to update in this Allocation
446 * @param[in] w Width of region to update
447 * @param[in] h Height of region to update
448 * @param[in] data Array from which to copy
449 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700450 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800451 const void *data);
Tim Murray7b3e3092012-11-16 13:32:24 -0800452
Tim Murray75e877d2013-09-11 14:45:20 -0700453 /**
454 * Copy from this Allocation into a rectangular region in an array. The
455 * array is assumed to be tightly packed.
456 * @param[in] xoff X offset of region to copy from this Allocation
457 * @param[in] yoff Y offset of region to copy from this Allocation
458 * @param[in] w Width of region to update
459 * @param[in] h Height of region to update
460 * @param[in] data destination array
461 */
Tim Murray7b3e3092012-11-16 13:32:24 -0800462 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
463 void *data);
464
Tim Murray75e877d2013-09-11 14:45:20 -0700465 /**
466 * Copy from an Allocation into a rectangular region in this Allocation.
467 * @param[in] xoff X offset of region to update in this Allocation
468 * @param[in] yoff Y offset of region to update in this Allocation
469 * @param[in] w Width of region to update
470 * @param[in] h Height of region to update
471 * @param[in] data Allocation from which to copy
472 * @param[in] dataXoff X offset of region to copy from in data
473 * @param[in] dataYoff Y offset of region to copy from in data
474 */
Tim Murray0b93e302012-11-15 14:56:54 -0800475 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
476 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700477
Tim Murray75e877d2013-09-11 14:45:20 -0700478 /**
479 * Copy from a strided array into a rectangular region in this Allocation.
480 * @param[in] xoff X offset of region to update in this Allocation
481 * @param[in] yoff Y offset of region to update in this Allocation
482 * @param[in] w Width of region to update
483 * @param[in] h Height of region to update
484 * @param[in] data array from which to copy
485 * @param[in] stride stride of data in bytes
486 */
Tim Murray358747a2012-11-26 13:52:04 -0800487 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
488 const void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700489
490 /**
491 * Copy from a strided array into this Allocation.
492 * @param[in] data array from which to copy
493 * @param[in] stride stride of data in bytes
494 */
Tim Murray358747a2012-11-26 13:52:04 -0800495 void copy2DStridedFrom(const void *data, size_t stride);
496
Tim Murray75e877d2013-09-11 14:45:20 -0700497 /**
498 * Copy from a rectangular region in this Allocation into a strided array.
499 * @param[in] xoff X offset of region to update in this Allocation
500 * @param[in] yoff Y offset of region to update in this Allocation
501 * @param[in] w Width of region to update
502 * @param[in] h Height of region to update
503 * @param[in] data destination array
504 * @param[in] stride stride of data in bytes
505 */
Tim Murray358747a2012-11-26 13:52:04 -0800506 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
507 void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700508
509 /**
510 * Copy this Allocation into a strided array.
511 * @param[in] data destination array
512 * @param[in] stride stride of data in bytes
513 */
Tim Murray358747a2012-11-26 13:52:04 -0800514 void copy2DStridedTo(void *data, size_t stride);
515
Tim Murray75e877d2013-09-11 14:45:20 -0700516
517 /**
518 * Copy from an array into a 3D region in this Allocation. The
519 * array is assumed to be tightly packed.
520 * @param[in] xoff X offset of region to update in this Allocation
521 * @param[in] yoff Y offset of region to update in this Allocation
522 * @param[in] zoff Z offset of region to update in this Allocation
523 * @param[in] w Width of region to update
524 * @param[in] h Height of region to update
525 * @param[in] d Depth of region to update
526 * @param[in] data Array from which to copy
527 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700528 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
529 uint32_t h, uint32_t d, const void* data);
530
Tim Murray75e877d2013-09-11 14:45:20 -0700531 /**
532 * Copy from an Allocation into a 3D region in this Allocation.
533 * @param[in] xoff X offset of region to update in this Allocation
534 * @param[in] yoff Y offset of region to update in this Allocation
535 * @param[in] zoff Z offset of region to update in this Allocation
536 * @param[in] w Width of region to update
537 * @param[in] h Height of region to update
538 * @param[in] d Depth of region to update
539 * @param[in] data Allocation from which to copy
540 * @param[in] dataXoff X offset of region in data to copy from
541 * @param[in] dataYoff Y offset of region in data to copy from
542 * @param[in] dataZoff Z offset of region in data to copy from
543 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700544 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
545 uint32_t w, uint32_t h, uint32_t d,
546 sp<const Allocation> data,
547 uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700548
Tim Murray75e877d2013-09-11 14:45:20 -0700549 /**
Miao Wange5428e62015-03-10 15:29:40 -0700550 * Copy a 3D region in this Allocation into an array. The
551 * array is assumed to be tightly packed.
552 * @param[in] xoff X offset of region to update in this Allocation
553 * @param[in] yoff Y offset of region to update in this Allocation
554 * @param[in] zoff Z offset of region to update in this Allocation
555 * @param[in] w Width of region to update
556 * @param[in] h Height of region to update
557 * @param[in] d Depth of region to update
558 * @param[in] data Array from which to copy
559 */
560 void copy3DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
561 uint32_t h, uint32_t d, void* data);
562
563 /**
Tim Murray75e877d2013-09-11 14:45:20 -0700564 * Creates an Allocation for use by scripts with a given Type.
565 * @param[in] rs Context to which the Allocation will belong
566 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800567 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700568 * @param[in] usage usage for the Allocation
569 * @return new Allocation
570 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700571 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800572 RsAllocationMipmapControl mipmaps, uint32_t usage);
Tim Murray75e877d2013-09-11 14:45:20 -0700573
574 /**
575 * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use
576 * with RS_ALLOCATION_USAGE_SHARED.
577 * @param[in] rs Context to which the Allocation will belong
578 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800579 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700580 * @param[in] usage usage for the Allocation
581 * @param[in] pointer existing backing store to use for this Allocation if possible
582 * @return new Allocation
583 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700584 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800585 RsAllocationMipmapControl mipmaps, uint32_t usage, void * pointer);
Tim Murray84bf2b82012-10-31 16:03:16 -0700586
Tim Murray75e877d2013-09-11 14:45:20 -0700587 /**
588 * Creates an Allocation for use by scripts with a given Type with no mipmaps.
589 * @param[in] rs Context to which the Allocation will belong
590 * @param[in] type Type of the Allocation
591 * @param[in] usage usage for the Allocation
592 * @return new Allocation
593 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700594 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
595 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700596 /**
597 * Creates an Allocation with a specified number of given elements.
598 * @param[in] rs Context to which the Allocation will belong
599 * @param[in] e Element used in the Allocation
600 * @param[in] count Number of elements of the Allocation
601 * @param[in] usage usage for the Allocation
602 * @return new Allocation
603 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700604 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
605 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700606
607 /**
608 * Creates a 2D Allocation with a specified number of given elements.
609 * @param[in] rs Context to which the Allocation will belong
610 * @param[in] e Element used in the Allocation
611 * @param[in] x Width in Elements of the Allocation
612 * @param[in] y Height of the Allocation
613 * @param[in] usage usage for the Allocation
614 * @return new Allocation
615 */
Tim Murray684726c2012-11-14 11:57:42 -0800616 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
617 size_t x, size_t y,
618 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
619
Tim Murray84bf2b82012-10-31 16:03:16 -0700620
Jason Samsb8a94e22014-02-24 17:52:32 -0800621 /**
622 * Get the backing pointer for a USAGE_SHARED allocation.
623 * @param[in] stride optional parameter. when non-NULL, will contain
624 * stride in bytes of a 2D Allocation
625 * @return pointer to data
626 */
627 void * getPointer(size_t *stride = NULL);
Tim Murray84bf2b82012-10-31 16:03:16 -0700628};
629
Tim Murray75e877d2013-09-11 14:45:20 -0700630 /**
631 * An Element represents one item within an Allocation. An Element is roughly
632 * equivalent to a C type in a RenderScript kernel. Elements may be basic
633 * or complex. Some basic elements are:
634
635 * - A single float value (equivalent to a float in a kernel)
636 * - A four-element float vector (equivalent to a float4 in a kernel)
637 * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel)
638 * - A single signed 8-bit integer (equivalent to a char in a kernel)
639
640 * Basic Elements are comprised of a Element.DataType and a
641 * Element.DataKind. The DataType encodes C type information of an Element,
642 * while the DataKind encodes how that Element should be interpreted by a
643 * Sampler. Note that Allocation objects with DataKind USER cannot be used as
644 * input for a Sampler. In general, Allocation objects that are intended for
645 * use with a Sampler should use bitmap-derived Elements such as
646 * Element::RGBA_8888.
647 */
648
649
Tim Murray84bf2b82012-10-31 16:03:16 -0700650class Element : public BaseObj {
651public:
652 bool isComplex();
Tim Murray75e877d2013-09-11 14:45:20 -0700653
654 /**
655 * Elements could be simple, such as an int or a float, or a structure with
656 * multiple sub-elements, such as a collection of floats, float2,
657 * float4. This function returns zero for simple elements or the number of
658 * sub-elements otherwise.
659 * @return number of sub-elements
660 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700661 size_t getSubElementCount() {
Miao Wangbc10dff2015-04-03 17:44:55 -0700662 return mVisibleElementMapSize;
Tim Murray84bf2b82012-10-31 16:03:16 -0700663 }
664
Tim Murray75e877d2013-09-11 14:45:20 -0700665 /**
666 * For complex Elements, this returns the sub-element at a given index.
667 * @param[in] index index of sub-element
668 * @return sub-element
669 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700670 sp<const Element> getSubElement(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700671
672 /**
673 * For complex Elements, this returns the name of the sub-element at a given
674 * index.
675 * @param[in] index index of sub-element
676 * @return name of sub-element
677 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700678 const char * getSubElementName(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700679
680 /**
681 * For complex Elements, this returns the size of the sub-element at a given
682 * index.
683 * @param[in] index index of sub-element
684 * @return size of sub-element
685 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700686 size_t getSubElementArraySize(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700687
688 /**
689 * Returns the location of a sub-element within a complex Element.
690 * @param[in] index index of sub-element
691 * @return offset in bytes
692 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700693 uint32_t getSubElementOffsetBytes(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700694
695 /**
696 * Returns the data type used for the Element.
697 * @return data type
698 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700699 RsDataType getDataType() const {
700 return mType;
701 }
702
Tim Murray75e877d2013-09-11 14:45:20 -0700703 /**
704 * Returns the data kind used for the Element.
705 * @return data kind
706 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700707 RsDataKind getDataKind() const {
708 return mKind;
709 }
710
Tim Murray75e877d2013-09-11 14:45:20 -0700711 /**
712 * Returns the size in bytes of the Element.
713 * @return size in bytes
714 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700715 size_t getSizeBytes() const {
716 return mSizeBytes;
717 }
718
Tim Murray75e877d2013-09-11 14:45:20 -0700719 /**
720 * Returns the number of vector components for this Element.
721 * @return number of vector components
722 */
Tim Murray10913a52013-08-20 17:19:47 -0700723 uint32_t getVectorSize() const {
724 return mVectorSize;
725 }
726
Tim Murray75e877d2013-09-11 14:45:20 -0700727 /**
728 * Utility function for returning an Element containing a single bool.
729 * @param[in] rs RenderScript context
730 * @return Element
731 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700732 static sp<const Element> BOOLEAN(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700733 /**
734 * Utility function for returning an Element containing a single unsigned char.
735 * @param[in] rs RenderScript context
736 * @return Element
737 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700738 static sp<const Element> U8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700739 /**
740 * Utility function for returning an Element containing a single signed char.
741 * @param[in] rs RenderScript context
742 * @return Element
743 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700744 static sp<const Element> I8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700745 /**
746 * Utility function for returning an Element containing a single unsigned short.
747 * @param[in] rs RenderScript context
748 * @return Element
749 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700750 static sp<const Element> U16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700751 /**
752 * Utility function for returning an Element containing a single signed short.
753 * @param[in] rs RenderScript context
754 * @return Element
755 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700756 static sp<const Element> I16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700757 /**
758 * Utility function for returning an Element containing a single unsigned int.
759 * @param[in] rs RenderScript context
760 * @return Element
761 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700762 static sp<const Element> U32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700763 /**
764 * Utility function for returning an Element containing a single signed int.
765 * @param[in] rs RenderScript context
766 * @return Element
767 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700768 static sp<const Element> I32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700769 /**
770 * Utility function for returning an Element containing a single unsigned long long.
771 * @param[in] rs RenderScript context
772 * @return Element
773 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700774 static sp<const Element> U64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700775 /**
776 * Utility function for returning an Element containing a single signed long long.
777 * @param[in] rs RenderScript context
778 * @return Element
779 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700780 static sp<const Element> I64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700781 /**
782 * Utility function for returning an Element containing a single float.
783 * @param[in] rs RenderScript context
784 * @return Element
785 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700786 static sp<const Element> F32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700787 /**
788 * Utility function for returning an Element containing a single double.
789 * @param[in] rs RenderScript context
790 * @return Element
791 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700792 static sp<const Element> F64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700793 /**
794 * Utility function for returning an Element containing a single Element.
795 * @param[in] rs RenderScript context
796 * @return Element
797 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700798 static sp<const Element> ELEMENT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700799 /**
800 * Utility function for returning an Element containing a single Type.
801 * @param[in] rs RenderScript context
802 * @return Element
803 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700804 static sp<const Element> TYPE(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700805 /**
806 * Utility function for returning an Element containing a single Allocation.
807 * @param[in] rs RenderScript context
808 * @return Element
809 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700810 static sp<const Element> ALLOCATION(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700811 /**
812 * Utility function for returning an Element containing a single Sampler.
813 * @param[in] rs RenderScript context
814 * @return Element
815 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700816 static sp<const Element> SAMPLER(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700817 /**
818 * Utility function for returning an Element containing a single Script.
819 * @param[in] rs RenderScript context
820 * @return Element
821 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700822 static sp<const Element> SCRIPT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700823 /**
824 * Utility function for returning an Element containing an ALPHA_8 pixel.
825 * @param[in] rs RenderScript context
826 * @return Element
827 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700828 static sp<const Element> A_8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700829 /**
830 * Utility function for returning an Element containing an RGB_565 pixel.
831 * @param[in] rs RenderScript context
832 * @return Element
833 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700834 static sp<const Element> RGB_565(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700835 /**
836 * Utility function for returning an Element containing an RGB_888 pixel.
837 * @param[in] rs RenderScript context
838 * @return Element
839 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700840 static sp<const Element> RGB_888(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700841 /**
842 * Utility function for returning an Element containing an RGBA_5551 pixel.
843 * @param[in] rs RenderScript context
844 * @return Element
845 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700846 static sp<const Element> RGBA_5551(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700847 /**
848 * Utility function for returning an Element containing an RGBA_4444 pixel.
849 * @param[in] rs RenderScript context
850 * @return Element
851 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700852 static sp<const Element> RGBA_4444(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700853 /**
854 * Utility function for returning an Element containing an RGBA_8888 pixel.
855 * @param[in] rs RenderScript context
856 * @return Element
857 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700858 static sp<const Element> RGBA_8888(sp<RS> rs);
859
Tim Murray75e877d2013-09-11 14:45:20 -0700860 /**
861 * Utility function for returning an Element containing a float2.
862 * @param[in] rs RenderScript context
863 * @return Element
864 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700865 static sp<const Element> F32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700866 /**
867 * Utility function for returning an Element containing a float3.
868 * @param[in] rs RenderScript context
869 * @return Element
870 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700871 static sp<const Element> F32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700872 /**
873 * Utility function for returning an Element containing a float4.
874 * @param[in] rs RenderScript context
875 * @return Element
876 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700877 static sp<const Element> F32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700878 /**
879 * Utility function for returning an Element containing a double2.
880 * @param[in] rs RenderScript context
881 * @return Element
882 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700883 static sp<const Element> F64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700884 /**
885 * Utility function for returning an Element containing a double3.
886 * @param[in] rs RenderScript context
887 * @return Element
888 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700889 static sp<const Element> F64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700890 /**
891 * Utility function for returning an Element containing a double4.
892 * @param[in] rs RenderScript context
893 * @return Element
894 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700895 static sp<const Element> F64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700896 /**
897 * Utility function for returning an Element containing a uchar2.
898 * @param[in] rs RenderScript context
899 * @return Element
900 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700901 static sp<const Element> U8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700902 /**
903 * Utility function for returning an Element containing a uchar3.
904 * @param[in] rs RenderScript context
905 * @return Element
906 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700907 static sp<const Element> U8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700908 /**
909 * Utility function for returning an Element containing a uchar4.
910 * @param[in] rs RenderScript context
911 * @return Element
912 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700913 static sp<const Element> U8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700914 /**
915 * Utility function for returning an Element containing a char2.
916 * @param[in] rs RenderScript context
917 * @return Element
918 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700919 static sp<const Element> I8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700920 /**
921 * Utility function for returning an Element containing a char3.
922 * @param[in] rs RenderScript context
923 * @return Element
924 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700925 static sp<const Element> I8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700926 /**
927 * Utility function for returning an Element containing a char4.
928 * @param[in] rs RenderScript context
929 * @return Element
930 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700931 static sp<const Element> I8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700932 /**
933 * Utility function for returning an Element containing a ushort2.
934 * @param[in] rs RenderScript context
935 * @return Element
936 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700937 static sp<const Element> U16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700938 /**
939 * Utility function for returning an Element containing a ushort3.
940 * @param[in] rs RenderScript context
941 * @return Element
942 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700943 static sp<const Element> U16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700944 /**
945 * Utility function for returning an Element containing a ushort4.
946 * @param[in] rs RenderScript context
947 * @return Element
948 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700949 static sp<const Element> U16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700950 /**
951 * Utility function for returning an Element containing a short2.
952 * @param[in] rs RenderScript context
953 * @return Element
954 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700955 static sp<const Element> I16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700956 /**
957 * Utility function for returning an Element containing a short3.
958 * @param[in] rs RenderScript context
959 * @return Element
960 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700961 static sp<const Element> I16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700962 /**
963 * Utility function for returning an Element containing a short4.
964 * @param[in] rs RenderScript context
965 * @return Element
966 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700967 static sp<const Element> I16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700968 /**
969 * Utility function for returning an Element containing a uint2.
970 * @param[in] rs RenderScript context
971 * @return Element
972 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700973 static sp<const Element> U32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700974 /**
975 * Utility function for returning an Element containing a uint3.
976 * @param[in] rs RenderScript context
977 * @return Element
978 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700979 static sp<const Element> U32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700980 /**
981 * Utility function for returning an Element containing a uint4.
982 * @param[in] rs RenderScript context
983 * @return Element
984 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700985 static sp<const Element> U32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700986 /**
987 * Utility function for returning an Element containing an int2.
988 * @param[in] rs RenderScript context
989 * @return Element
990 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700991 static sp<const Element> I32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700992 /**
993 * Utility function for returning an Element containing an int3.
994 * @param[in] rs RenderScript context
995 * @return Element
996 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700997 static sp<const Element> I32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700998 /**
999 * Utility function for returning an Element containing an int4.
1000 * @param[in] rs RenderScript context
1001 * @return Element
1002 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001003 static sp<const Element> I32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001004 /**
1005 * Utility function for returning an Element containing a ulong2.
1006 * @param[in] rs RenderScript context
1007 * @return Element
1008 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001009 static sp<const Element> U64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001010 /**
1011 * Utility function for returning an Element containing a ulong3.
1012 * @param[in] rs RenderScript context
1013 * @return Element
1014 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001015 static sp<const Element> U64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001016 /**
1017 * Utility function for returning an Element containing a ulong4.
1018 * @param[in] rs RenderScript context
1019 * @return Element
1020 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001021 static sp<const Element> U64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001022 /**
1023 * Utility function for returning an Element containing a long2.
1024 * @param[in] rs RenderScript context
1025 * @return Element
1026 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001027 static sp<const Element> I64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001028 /**
1029 * Utility function for returning an Element containing a long3.
1030 * @param[in] rs RenderScript context
1031 * @return Element
1032 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001033 static sp<const Element> I64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001034 /**
1035 * Utility function for returning an Element containing a long4.
1036 * @param[in] rs RenderScript context
1037 * @return Element
1038 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001039 static sp<const Element> I64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001040 /**
1041 * Utility function for returning an Element containing a YUV pixel.
1042 * @param[in] rs RenderScript context
1043 * @return Element
1044 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001045 static sp<const Element> YUV(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001046 /**
1047 * Utility function for returning an Element containing an rs_matrix_4x4.
1048 * @param[in] rs RenderScript context
1049 * @return Element
1050 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001051 static sp<const Element> MATRIX_4X4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001052 /**
1053 * Utility function for returning an Element containing an rs_matrix_3x3.
1054 * @param[in] rs RenderScript context
1055 * @return Element
1056 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001057 static sp<const Element> MATRIX_3X3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001058 /**
1059 * Utility function for returning an Element containing an rs_matrix_2x2.
1060 * @param[in] rs RenderScript context
1061 * @return Element
1062 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001063 static sp<const Element> MATRIX_2X2(sp<RS> rs);
1064
Tim Murray84bf2b82012-10-31 16:03:16 -07001065 void updateFromNative();
Tim Murray75e877d2013-09-11 14:45:20 -07001066
1067 /**
1068 * Create an Element with a given DataType.
1069 * @param[in] rs RenderScript context
1070 * @param[in] dt data type
1071 * @return Element
1072 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001073 static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
Tim Murray75e877d2013-09-11 14:45:20 -07001074 /**
1075 * Create a vector Element with the given DataType
1076 * @param[in] rs RenderScript
1077 * @param[in] dt DataType
1078 * @param[in] size vector size
1079 * @return Element
1080 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001081 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
Tim Murray75e877d2013-09-11 14:45:20 -07001082 /**
1083 * Create an Element with a given DataType and DataKind.
1084 * @param[in] rs RenderScript context
1085 * @param[in] dt DataType
1086 * @param[in] dk DataKind
1087 * @return Element
1088 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001089 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
Tim Murray75e877d2013-09-11 14:45:20 -07001090
1091 /**
1092 * Returns true if the Element can interoperate with this Element.
1093 * @param[in] e Element to compare
1094 * @return true if Elements can interoperate
1095 */
Tim Murray10913a52013-08-20 17:19:47 -07001096 bool isCompatible(sp<const Element>e) const;
Tim Murray84bf2b82012-10-31 16:03:16 -07001097
Tim Murray75e877d2013-09-11 14:45:20 -07001098 /**
1099 * Builder class for producing complex elements with matching field and name
1100 * pairs. The builder starts empty. The order in which elements are added is
1101 * retained for the layout in memory.
1102 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001103 class Builder {
1104 private:
Tim Murray35609072013-12-03 11:36:03 -08001105 RS* mRS;
Miao Wangbc10dff2015-04-03 17:44:55 -07001106 size_t mElementsCount;
1107 size_t mElementsVecSize;
1108 sp<const Element> * mElements;
1109 char ** mElementNames;
1110 size_t * mElementNameLengths;
1111 uint32_t * mArraySizes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001112 bool mSkipPadding;
1113
1114 public:
1115 Builder(sp<RS> rs);
1116 ~Builder();
Miao Wangbc10dff2015-04-03 17:44:55 -07001117 void add(sp<const Element> e, const char * name, uint32_t arraySize = 1);
Tim Murray84bf2b82012-10-31 16:03:16 -07001118 sp<const Element> create();
1119 };
1120
Stephen Hines7d1b7572013-08-22 01:24:06 -07001121protected:
1122 Element(void *id, sp<RS> rs,
Miao Wangbc10dff2015-04-03 17:44:55 -07001123 sp<const Element> * elements,
1124 size_t elementCount,
1125 const char ** elementNames,
1126 size_t * elementNameLengths,
1127 uint32_t * arraySizes);
Stephen Hines7d1b7572013-08-22 01:24:06 -07001128 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
1129 Element(sp<RS> rs);
1130 virtual ~Element();
1131
Tim Murray84bf2b82012-10-31 16:03:16 -07001132private:
1133 void updateVisibleSubElements();
1134
Miao Wangbc10dff2015-04-03 17:44:55 -07001135 size_t mElementsCount;
1136 size_t mVisibleElementMapSize;
1137
1138 sp<const Element> * mElements;
1139 char ** mElementNames;
1140 size_t * mElementNameLengths;
1141 uint32_t * mArraySizes;
1142 uint32_t * mVisibleElementMap;
1143 uint32_t * mOffsetInBytes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001144
1145 RsDataType mType;
1146 RsDataKind mKind;
1147 bool mNormalized;
1148 size_t mSizeBytes;
1149 size_t mVectorSize;
1150};
1151
Stephen Hines2c7206e2012-11-14 19:47:01 -08001152class FieldPacker {
1153protected:
1154 unsigned char* mData;
1155 size_t mPos;
1156 size_t mLen;
1157
1158public:
1159 FieldPacker(size_t len)
Tim Murray89daad62013-07-29 14:30:02 -07001160 : mPos(0), mLen(len) {
1161 mData = new unsigned char[len];
1162 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001163
1164 virtual ~FieldPacker() {
1165 delete [] mData;
1166 }
1167
1168 void align(size_t v) {
1169 if ((v & (v - 1)) != 0) {
Tim Murrayab716362013-08-12 12:37:18 -07001170 // ALOGE("Non-power-of-two alignment: %zu", v);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001171 return;
1172 }
1173
1174 while ((mPos & (v - 1)) != 0) {
1175 mData[mPos++] = 0;
1176 }
1177 }
1178
1179 void reset() {
1180 mPos = 0;
1181 }
1182
1183 void reset(size_t i) {
1184 if (i >= mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001185 // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001186 return;
1187 }
1188 mPos = i;
1189 }
1190
1191 void skip(size_t i) {
1192 size_t res = mPos + i;
1193 if (res > mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001194 // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001195 return;
1196 }
1197 mPos = res;
1198 }
1199
1200 void* getData() const {
1201 return mData;
1202 }
1203
1204 size_t getLength() const {
1205 return mLen;
1206 }
1207
1208 template <typename T>
Tim Murray89daad62013-07-29 14:30:02 -07001209 void add(T t) {
Stephen Hines2c7206e2012-11-14 19:47:01 -08001210 align(sizeof(t));
1211 if (mPos + sizeof(t) <= mLen) {
1212 memcpy(&mData[mPos], &t, sizeof(t));
1213 mPos += sizeof(t);
1214 }
1215 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001216
1217 /*
Tim Murray89daad62013-07-29 14:30:02 -07001218 void add(rs_matrix4x4 m) {
1219 for (size_t i = 0; i < 16; i++) {
1220 add(m.m[i]);
1221 }
1222 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001223
Tim Murray89daad62013-07-29 14:30:02 -07001224 void add(rs_matrix3x3 m) {
1225 for (size_t i = 0; i < 9; i++) {
1226 add(m.m[i]);
1227 }
1228 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001229
Tim Murray89daad62013-07-29 14:30:02 -07001230 void add(rs_matrix2x2 m) {
1231 for (size_t i = 0; i < 4; i++) {
1232 add(m.m[i]);
1233 }
1234 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001235 */
1236
Tim Murray89daad62013-07-29 14:30:02 -07001237 void add(sp<BaseObj> obj) {
Stephen Hines43514cd2012-11-16 14:33:47 -08001238 if (obj != NULL) {
1239 add((uint32_t) (uintptr_t) obj->getID());
1240 } else {
1241 add((uint32_t) 0);
1242 }
1243 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001244};
1245
Tim Murray75e877d2013-09-11 14:45:20 -07001246/**
1247 * A Type describes the Element and dimensions used for an Allocation or a
1248 * parallel operation.
1249 *
1250 * A Type always includes an Element and an X dimension. A Type may be
1251 * multidimensional, up to three dimensions. A nonzero value in the Y or Z
1252 * dimensions indicates that the dimension is present. Note that a Type with
1253 * only a given X dimension and a Type with the same X dimension but Y = 1 are
1254 * not equivalent.
1255 *
1256 * A Type also supports inclusion of level of detail (LOD) or cube map
1257 * faces. LOD and cube map faces are booleans to indicate present or not
1258 * present.
1259 *
1260 * A Type also supports YUV format information to support an Allocation in a YUV
1261 * format. The YUV formats supported are YV12 and NV21.
1262 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001263class Type : public BaseObj {
1264protected:
1265 friend class Allocation;
1266
1267 uint32_t mDimX;
1268 uint32_t mDimY;
1269 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001270 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001271 bool mDimMipmaps;
1272 bool mDimFaces;
1273 size_t mElementCount;
1274 sp<const Element> mElement;
1275
Stephen Hines7d1b7572013-08-22 01:24:06 -07001276 Type(void *id, sp<RS> rs);
1277
Tim Murray84bf2b82012-10-31 16:03:16 -07001278 void calcElementCount();
1279 virtual void updateFromNative();
1280
1281public:
1282
Tim Murray75e877d2013-09-11 14:45:20 -07001283 /**
1284 * Returns the YUV format.
1285 * @return YUV format of the Allocation
1286 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001287 RSYuvFormat getYuvFormat() const {
1288 return mYuvFormat;
1289 }
1290
Tim Murray75e877d2013-09-11 14:45:20 -07001291 /**
1292 * Returns the Element of the Allocation.
1293 * @return YUV format of the Allocation
1294 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001295 sp<const Element> getElement() const {
1296 return mElement;
1297 }
1298
Tim Murray75e877d2013-09-11 14:45:20 -07001299 /**
1300 * Returns the X dimension of the Allocation.
1301 * @return X dimension of the allocation
1302 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001303 uint32_t getX() const {
1304 return mDimX;
1305 }
1306
Tim Murray75e877d2013-09-11 14:45:20 -07001307 /**
1308 * Returns the Y dimension of the Allocation.
1309 * @return Y dimension of the allocation
1310 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001311 uint32_t getY() const {
1312 return mDimY;
1313 }
1314
Tim Murray75e877d2013-09-11 14:45:20 -07001315 /**
1316 * Returns the Z dimension of the Allocation.
1317 * @return Z dimension of the allocation
1318 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001319 uint32_t getZ() const {
1320 return mDimZ;
1321 }
1322
Tim Murray75e877d2013-09-11 14:45:20 -07001323 /**
1324 * Returns true if the Allocation has mipmaps.
1325 * @return true if the Allocation has mipmaps
1326 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001327 bool hasMipmaps() const {
1328 return mDimMipmaps;
1329 }
1330
Tim Murray75e877d2013-09-11 14:45:20 -07001331 /**
1332 * Returns true if the Allocation is a cube map
1333 * @return true if the Allocation is a cube map
1334 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001335 bool hasFaces() const {
1336 return mDimFaces;
1337 }
1338
Tim Murray75e877d2013-09-11 14:45:20 -07001339 /**
1340 * Returns number of accessible Elements in the Allocation
1341 * @return number of accessible Elements in the Allocation
1342 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001343 size_t getCount() const {
1344 return mElementCount;
1345 }
1346
Tim Murray75e877d2013-09-11 14:45:20 -07001347 /**
1348 * Returns size in bytes of all Elements in the Allocation
1349 * @return size in bytes of all Elements in the Allocation
1350 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001351 size_t getSizeBytes() const {
1352 return mElementCount * mElement->getSizeBytes();
1353 }
1354
Tim Murray75e877d2013-09-11 14:45:20 -07001355 /**
1356 * Creates a new Type with the given Element and dimensions.
1357 * @param[in] rs RenderScript context
1358 * @param[in] e Element
1359 * @param[in] dimX X dimension
1360 * @param[in] dimY Y dimension
1361 * @param[in] dimZ Z dimension
1362 * @return new Type
1363 */
Tim Murray96267c22013-02-12 11:25:12 -08001364 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 -07001365
1366 class Builder {
1367 protected:
Tim Murray35609072013-12-03 11:36:03 -08001368 RS* mRS;
Tim Murray84bf2b82012-10-31 16:03:16 -07001369 uint32_t mDimX;
1370 uint32_t mDimY;
1371 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001372 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001373 bool mDimMipmaps;
1374 bool mDimFaces;
1375 sp<const Element> mElement;
1376
1377 public:
1378 Builder(sp<RS> rs, sp<const Element> e);
1379
1380 void setX(uint32_t value);
Stephen Hines7d1b7572013-08-22 01:24:06 -07001381 void setY(uint32_t value);
Tim Murrayeb4426d2013-08-27 15:30:16 -07001382 void setZ(uint32_t value);
1383 void setYuvFormat(RSYuvFormat format);
Tim Murray84bf2b82012-10-31 16:03:16 -07001384 void setMipmaps(bool value);
1385 void setFaces(bool value);
1386 sp<const Type> create();
1387 };
1388
1389};
1390
Tim Murray75e877d2013-09-11 14:45:20 -07001391/**
1392 * The parent class for all executable Scripts. This should not be used by applications.
1393 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001394class Script : public BaseObj {
1395private:
1396
1397protected:
1398 Script(void *id, sp<RS> rs);
1399 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
1400 const void *v, size_t) const;
1401 void bindAllocation(sp<Allocation> va, uint32_t slot) const;
1402 void setVar(uint32_t index, const void *, size_t len) const;
1403 void setVar(uint32_t index, sp<const BaseObj> o) const;
1404 void invoke(uint32_t slot, const void *v, size_t len) const;
1405
1406
1407 void invoke(uint32_t slot) const {
1408 invoke(slot, NULL, 0);
1409 }
1410 void setVar(uint32_t index, float v) const {
1411 setVar(index, &v, sizeof(v));
1412 }
1413 void setVar(uint32_t index, double v) const {
1414 setVar(index, &v, sizeof(v));
1415 }
1416 void setVar(uint32_t index, int32_t v) const {
1417 setVar(index, &v, sizeof(v));
1418 }
Jon Parrb05c8502015-03-13 14:41:58 +00001419 void setVar(uint32_t index, uint32_t v) const {
1420 setVar(index, &v, sizeof(v));
1421 }
Tim Murray84bf2b82012-10-31 16:03:16 -07001422 void setVar(uint32_t index, int64_t v) const {
1423 setVar(index, &v, sizeof(v));
1424 }
1425 void setVar(uint32_t index, bool v) const {
1426 setVar(index, &v, sizeof(v));
1427 }
1428
1429public:
1430 class FieldBase {
1431 protected:
1432 sp<const Element> mElement;
1433 sp<Allocation> mAllocation;
1434
1435 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
1436
1437 public:
1438 sp<const Element> getElement() {
1439 return mElement;
1440 }
1441
1442 sp<const Type> getType() {
1443 return mAllocation->getType();
1444 }
1445
1446 sp<const Allocation> getAllocation() {
1447 return mAllocation;
1448 }
1449
1450 //void updateAllocation();
1451 };
1452};
1453
Tim Murray75e877d2013-09-11 14:45:20 -07001454/**
1455 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only.
1456 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001457class ScriptC : public Script {
1458protected:
1459 ScriptC(sp<RS> rs,
1460 const void *codeTxt, size_t codeLength,
1461 const char *cachedName, size_t cachedNameLength,
1462 const char *cacheDir, size_t cacheDirLength);
1463
1464};
1465
Tim Murray75e877d2013-09-11 14:45:20 -07001466/**
1467 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of
1468 * basic functions. This is not intended to be used directly.
1469 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001470class ScriptIntrinsic : public Script {
1471 protected:
Tim Murray10913a52013-08-20 17:19:47 -07001472 sp<const Element> mElement;
Tim Murray3cd44af2012-11-14 11:25:27 -08001473 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001474 virtual ~ScriptIntrinsic();
Tim Murray7f0d5682012-11-08 16:35:24 -08001475};
1476
Tim Murray75e877d2013-09-11 14:45:20 -07001477/**
1478 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming
1479 * r,g,b values are use as normalized x,y,z coordinates into a 3D
1480 * allocation. The 8 nearest values are sampled and linearly interpolated. The
1481 * result is placed in the output.
1482 */
Tim Murray89daad62013-07-29 14:30:02 -07001483class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001484 private:
Tim Murray89daad62013-07-29 14:30:02 -07001485 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001486 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001487 /**
1488 * Supported Element types are U8_4. Default lookup table is identity.
1489 * @param[in] rs RenderScript context
1490 * @param[in] e Element
1491 * @return new ScriptIntrinsic
1492 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001493 static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001494
1495 /**
1496 * Launch the intrinsic.
1497 * @param[in] ain input Allocation
1498 * @param[in] aout output Allocation
1499 */
Tim Murray89daad62013-07-29 14:30:02 -07001500 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001501
1502 /**
1503 * Sets the lookup table. The lookup table must use the same Element as the
1504 * intrinsic.
1505 * @param[in] lut new lookup table
1506 */
Tim Murray89daad62013-07-29 14:30:02 -07001507 void setLUT(sp<Allocation> lut);
1508};
1509
Tim Murray75e877d2013-09-11 14:45:20 -07001510/**
1511 * Intrinsic kernel for blending two Allocations.
1512 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001513class ScriptIntrinsicBlend : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001514 private:
Tim Murray89daad62013-07-29 14:30:02 -07001515 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001516 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001517 /**
1518 * Supported Element types are U8_4.
1519 * @param[in] rs RenderScript context
1520 * @param[in] e Element
1521 * @return new ScriptIntrinsicBlend
1522 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001523 static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001524 /**
1525 * sets dst = {0, 0, 0, 0}
1526 * @param[in] in input Allocation
1527 * @param[in] out output Allocation
1528 */
1529 void forEachClear(sp<Allocation> in, sp<Allocation> out);
1530 /**
1531 * Sets dst = src
1532 * @param[in] in input Allocation
1533 * @param[in] out output Allocation
1534 */
1535 void forEachSrc(sp<Allocation> in, sp<Allocation> out);
1536 /**
1537 * Sets dst = dst (NOP)
1538 * @param[in] in input Allocation
1539 * @param[in] out output Allocation
1540 */
1541 void forEachDst(sp<Allocation> in, sp<Allocation> out);
1542 /**
1543 * Sets dst = src + dst * (1.0 - src.a)
1544 * @param[in] in input Allocation
1545 * @param[in] out output Allocation
1546 */
1547 void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
1548 /**
1549 * Sets dst = dst + src * (1.0 - dst.a)
1550 * @param[in] in input Allocation
1551 * @param[in] out output Allocation
1552 */
1553 void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
1554 /**
1555 * Sets dst = src * dst.a
1556 * @param[in] in input Allocation
1557 * @param[in] out output Allocation
1558 */
1559 void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
1560 /**
1561 * Sets dst = dst * src.a
1562 * @param[in] in input Allocation
1563 * @param[in] out output Allocation
1564 */
1565 void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
1566 /**
1567 * Sets dst = src * (1.0 - dst.a)
1568 * @param[in] in input Allocation
1569 * @param[in] out output Allocation
1570 */
1571 void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
1572 /**
1573 * Sets dst = dst * (1.0 - src.a)
1574 * @param[in] in input Allocation
1575 * @param[in] out output Allocation
1576 */
1577 void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
1578 /**
1579 * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
1580 * @param[in] in input Allocation
1581 * @param[in] out output Allocation
1582 */
1583 void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
1584 /**
1585 * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
1586 * @param[in] in input Allocation
1587 * @param[in] out output Allocation
1588 */
1589 void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
1590 /**
1591 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
1592 * @param[in] in input Allocation
1593 * @param[in] out output Allocation
1594 */
1595 void forEachXor(sp<Allocation> in, sp<Allocation> out);
1596 /**
1597 * Sets dst = src * dst
1598 * @param[in] in input Allocation
1599 * @param[in] out output Allocation
1600 */
1601 void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
1602 /**
1603 * Sets dst = min(src + dst, 1.0)
1604 * @param[in] in input Allocation
1605 * @param[in] out output Allocation
1606 */
1607 void forEachAdd(sp<Allocation> in, sp<Allocation> out);
1608 /**
1609 * Sets dst = max(dst - src, 0.0)
1610 * @param[in] in input Allocation
1611 * @param[in] out output Allocation
1612 */
1613 void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
Tim Murray7f0d5682012-11-08 16:35:24 -08001614};
Tim Murray84bf2b82012-10-31 16:03:16 -07001615
Tim Murray75e877d2013-09-11 14:45:20 -07001616/**
1617 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified
1618 * radius to all elements of an Allocation.
1619 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001620class ScriptIntrinsicBlur : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001621 private:
Tim Murray89daad62013-07-29 14:30:02 -07001622 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001623 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001624 /**
1625 * Supported Element types are U8 and U8_4.
1626 * @param[in] rs RenderScript context
1627 * @param[in] e Element
1628 * @return new ScriptIntrinsicBlur
1629 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001630 static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001631 /**
1632 * Sets the input of the blur.
1633 * @param[in] in input Allocation
1634 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001635 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001636 /**
1637 * Runs the intrinsic.
1638 * @param[in] output Allocation
1639 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001640 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001641 /**
1642 * Sets the radius of the blur. The supported range is 0 < radius <= 25.
1643 * @param[in] radius radius of the blur
1644 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001645 void setRadius(float radius);
1646};
1647
Tim Murray75e877d2013-09-11 14:45:20 -07001648/**
1649 * Intrinsic for applying a color matrix to allocations. This has the
1650 * same effect as loading each element and converting it to a
1651 * F32_N, multiplying the result by the 4x4 color matrix
1652 * as performed by rsMatrixMultiply() and writing it to the output
1653 * after conversion back to U8_N or F32_N.
1654 */
Tim Murray89daad62013-07-29 14:30:02 -07001655class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001656 private:
Tim Murray89daad62013-07-29 14:30:02 -07001657 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001658 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001659 /**
1660 * Creates a new intrinsic.
1661 * @param[in] rs RenderScript context
1662 * @return new ScriptIntrinsicColorMatrix
1663 */
Tim Murrayaae73c92013-09-03 17:05:46 -07001664 static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001665 /**
1666 * Applies the color matrix. Supported types are U8 and F32 with
1667 * vector lengths between 1 and 4.
1668 * @param[in] in input Allocation
1669 * @param[out] out output Allocation
1670 */
Tim Murray89daad62013-07-29 14:30:02 -07001671 void forEach(sp<Allocation> in, sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001672 /**
1673 * Set the value to be added after the color matrix has been
1674 * applied. The default value is {0, 0, 0, 0}.
1675 * @param[in] add float[4] of values
1676 */
Tim Murray10913a52013-08-20 17:19:47 -07001677 void setAdd(float* add);
Tim Murray75e877d2013-09-11 14:45:20 -07001678
1679 /**
1680 * Set the color matrix which will be applied to each cell of the
1681 * image. The alpha channel will be copied.
1682 *
1683 * @param[in] m float[9] of values
1684 */
Tim Murray89daad62013-07-29 14:30:02 -07001685 void setColorMatrix3(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001686 /**
1687 * Set the color matrix which will be applied to each cell of the
1688 * image.
1689 *
1690 * @param[in] m float[16] of values
1691 */
Tim Murray89daad62013-07-29 14:30:02 -07001692 void setColorMatrix4(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001693 /**
1694 * Set a color matrix to convert from RGB to luminance. The alpha
1695 * channel will be a copy.
1696 */
Tim Murray89daad62013-07-29 14:30:02 -07001697 void setGreyscale();
Tim Murray75e877d2013-09-11 14:45:20 -07001698 /**
1699 * Set the matrix to convert from RGB to YUV with a direct copy of
1700 * the 4th channel.
1701 */
Tim Murray89daad62013-07-29 14:30:02 -07001702 void setRGBtoYUV();
Tim Murray75e877d2013-09-11 14:45:20 -07001703 /**
1704 * Set the matrix to convert from YUV to RGB with a direct copy of
1705 * the 4th channel.
1706 */
Tim Murray89daad62013-07-29 14:30:02 -07001707 void setYUVtoRGB();
1708};
1709
Tim Murray75e877d2013-09-11 14:45:20 -07001710/**
1711 * Intrinsic for applying a 3x3 convolve to an allocation.
1712 */
Tim Murray89daad62013-07-29 14:30:02 -07001713class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001714 private:
Tim Murray89daad62013-07-29 14:30:02 -07001715 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001716 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001717 /**
1718 * Supported types U8 and F32 with vector lengths between 1 and
1719 * 4. The default convolution kernel is the identity.
1720 * @param[in] rs RenderScript context
1721 * @param[in] e Element
1722 * @return new ScriptIntrinsicConvolve3x3
1723 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001724 static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001725 /**
1726 * Sets input for intrinsic.
1727 * @param[in] in input Allocation
1728 */
Tim Murray89daad62013-07-29 14:30:02 -07001729 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001730 /**
1731 * Launches the intrinsic.
1732 * @param[in] out output Allocation
1733 */
Tim Murray89daad62013-07-29 14:30:02 -07001734 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001735 /**
1736 * Sets convolution kernel.
1737 * @param[in] v float[9] of values
1738 */
Tim Murray89daad62013-07-29 14:30:02 -07001739 void setCoefficients(float* v);
1740};
1741
Tim Murray75e877d2013-09-11 14:45:20 -07001742/**
1743 * Intrinsic for applying a 5x5 convolve to an allocation.
1744 */
Tim Murray89daad62013-07-29 14:30:02 -07001745class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001746 private:
Tim Murray89daad62013-07-29 14:30:02 -07001747 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001748 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001749 /**
1750 * Supported types U8 and F32 with vector lengths between 1 and
1751 * 4. The default convolution kernel is the identity.
1752 * @param[in] rs RenderScript context
1753 * @param[in] e Element
1754 * @return new ScriptIntrinsicConvolve5x5
1755 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001756 static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001757 /**
1758 * Sets input for intrinsic.
1759 * @param[in] in input Allocation
1760 */
Tim Murray89daad62013-07-29 14:30:02 -07001761 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001762 /**
1763 * Launches the intrinsic.
1764 * @param[in] out output Allocation
1765 */
Tim Murray89daad62013-07-29 14:30:02 -07001766 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001767 /**
1768 * Sets convolution kernel.
1769 * @param[in] v float[25] of values
1770 */
Tim Murray89daad62013-07-29 14:30:02 -07001771 void setCoefficients(float* v);
1772};
1773
Tim Murray75e877d2013-09-11 14:45:20 -07001774/**
1775 * Intrinsic for computing a histogram.
1776 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001777class ScriptIntrinsicHistogram : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001778 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001779 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
Tim Murray10913a52013-08-20 17:19:47 -07001780 sp<Allocation> mOut;
Tim Murray21fa7a02013-08-15 16:25:03 -07001781 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001782 /**
1783 * Create an intrinsic for calculating the histogram of an uchar
1784 * or uchar4 image.
1785 *
1786 * Supported elements types are U8_4, U8_3, U8_2, and U8.
1787 *
1788 * @param[in] rs The RenderScript context
1789 * @param[in] e Element type for inputs
1790 *
1791 * @return ScriptIntrinsicHistogram
1792 */
Jon Parrb05c8502015-03-13 14:41:58 +00001793 static sp<ScriptIntrinsicHistogram> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001794 /**
1795 * Set the output of the histogram. 32 bit integer types are
1796 * supported.
1797 *
1798 * @param[in] aout The output allocation
1799 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001800 void setOutput(sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001801 /**
1802 * Set the coefficients used for the dot product calculation. The
1803 * default is {0.299f, 0.587f, 0.114f, 0.f}.
1804 *
1805 * Coefficients must be >= 0 and sum to 1.0 or less.
1806 *
1807 * @param[in] r Red coefficient
1808 * @param[in] g Green coefficient
1809 * @param[in] b Blue coefficient
1810 * @param[in] a Alpha coefficient
1811 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001812 void setDotCoefficients(float r, float g, float b, float a);
Tim Murray75e877d2013-09-11 14:45:20 -07001813 /**
1814 * Process an input buffer and place the histogram into the output
1815 * allocation. The output allocation may be a narrower vector size
1816 * than the input. In this case the vector size of the output is
1817 * used to determine how many of the input channels are used in
1818 * the computation. This is useful if you have an RGBA input
1819 * buffer but only want the histogram for RGB.
1820 *
1821 * 1D and 2D input allocations are supported.
1822 *
1823 * @param[in] ain The input image
1824 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001825 void forEach(sp<Allocation> ain);
Tim Murray75e877d2013-09-11 14:45:20 -07001826 /**
1827 * Process an input buffer and place the histogram into the output
1828 * allocation. The dot product of the input channel and the
1829 * coefficients from 'setDotCoefficients' are used to calculate
1830 * the output values.
1831 *
1832 * 1D and 2D input allocations are supported.
1833 *
1834 * @param ain The input image
1835 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001836 void forEach_dot(sp<Allocation> ain);
1837};
1838
Tim Murray75e877d2013-09-11 14:45:20 -07001839/**
1840 * Intrinsic for applying a per-channel lookup table. Each channel of
1841 * the input has an independant lookup table. The tables are 256
1842 * entries in size and can cover the full value range of U8_4.
1843 **/
Tim Murrayb27b1812013-08-05 14:00:40 -07001844class ScriptIntrinsicLUT : public ScriptIntrinsic {
1845 private:
1846 sp<Allocation> LUT;
1847 bool mDirty;
1848 unsigned char mCache[1024];
Tim Murray2acce992013-08-28 14:23:31 -07001849 void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray21fa7a02013-08-15 16:25:03 -07001850 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001851
Tim Murray89daad62013-07-29 14:30:02 -07001852 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001853 /**
1854 * Supported elements types are U8_4.
1855 *
1856 * The defaults tables are identity.
1857 *
1858 * @param[in] rs The RenderScript context
1859 * @param[in] e Element type for intputs and outputs
1860 *
1861 * @return ScriptIntrinsicLUT
1862 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001863 static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001864 /**
1865 * Invoke the kernel and apply the lookup to each cell of ain and
1866 * copy to aout.
1867 *
1868 * @param[in] ain Input allocation
1869 * @param[in] aout Output allocation
1870 */
Tim Murray89daad62013-07-29 14:30:02 -07001871 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001872 /**
1873 * Sets entries in LUT for the red channel.
1874 * @param[in] base base of region to update
1875 * @param[in] length length of region to update
1876 * @param[in] lutValues LUT values to use
1877 */
Tim Murray2acce992013-08-28 14:23:31 -07001878 void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001879 /**
1880 * Sets entries in LUT for the green channel.
1881 * @param[in] base base of region to update
1882 * @param[in] length length of region to update
1883 * @param[in] lutValues LUT values to use
1884 */
Tim Murray2acce992013-08-28 14:23:31 -07001885 void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001886 /**
1887 * Sets entries in LUT for the blue channel.
1888 * @param[in] base base of region to update
1889 * @param[in] length length of region to update
1890 * @param[in] lutValues LUT values to use
1891 */
Tim Murray2acce992013-08-28 14:23:31 -07001892 void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001893 /**
1894 * Sets entries in LUT for the alpha channel.
1895 * @param[in] base base of region to update
1896 * @param[in] length length of region to update
1897 * @param[in] lutValues LUT values to use
1898 */
Tim Murray2acce992013-08-28 14:23:31 -07001899 void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murrayb27b1812013-08-05 14:00:40 -07001900 virtual ~ScriptIntrinsicLUT();
1901};
1902
Tim Murray75e877d2013-09-11 14:45:20 -07001903/**
Miao Wange5428e62015-03-10 15:29:40 -07001904 * Intrinsic for performing a resize of a 2D allocation.
1905 */
1906class ScriptIntrinsicResize : public ScriptIntrinsic {
1907 private:
1908 sp<Allocation> mInput;
1909 ScriptIntrinsicResize(sp<RS> rs, sp<const Element> e);
1910 public:
1911 /**
1912 * Supported Element types are U8_4. Default lookup table is identity.
1913 * @param[in] rs RenderScript context
1914 * @param[in] e Element
1915 * @return new ScriptIntrinsic
1916 */
1917 static sp<ScriptIntrinsicResize> create(sp<RS> rs);
1918
1919 /**
1920 * Resize copy the input allocation to the output specified. The
1921 * Allocation is rescaled if necessary using bi-cubic
1922 * interpolation.
1923 * @param[in] ain input Allocation
1924 * @param[in] aout output Allocation
1925 */
1926 void forEach_bicubic(sp<Allocation> aout);
1927
1928 /**
1929 * Set the input of the resize.
1930 * @param[in] lut new lookup table
1931 */
1932 void setInput(sp<Allocation> ain);
1933};
1934
1935/**
Tim Murray75e877d2013-09-11 14:45:20 -07001936 * Intrinsic for converting an Android YUV buffer to RGB.
1937 *
1938 * The input allocation should be supplied in a supported YUV format
1939 * as a YUV element Allocation. The output is RGBA; the alpha channel
1940 * will be set to 255.
1941 */
Tim Murray89daad62013-07-29 14:30:02 -07001942class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001943 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001944 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001945 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001946 /**
1947 * Create an intrinsic for converting YUV to RGB.
1948 *
1949 * Supported elements types are U8_4.
1950 *
1951 * @param[in] rs The RenderScript context
1952 * @param[in] e Element type for output
1953 *
1954 * @return ScriptIntrinsicYuvToRGB
1955 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001956 static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001957 /**
1958 * Set the input YUV allocation.
1959 *
1960 * @param[in] ain The input allocation.
1961 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001962 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001963
1964 /**
1965 * Convert the image to RGB.
1966 *
1967 * @param[in] aout Output allocation. Must match creation element
1968 * type.
1969 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001970 void forEach(sp<Allocation> out);
Tim Murray89daad62013-07-29 14:30:02 -07001971
1972};
Tim Murrayb27b1812013-08-05 14:00:40 -07001973
Tim Murray75e877d2013-09-11 14:45:20 -07001974/**
1975 * Sampler object that defines how Allocations can be read as textures
1976 * within a kernel. Samplers are used in conjunction with the rsSample
1977 * runtime function to return values from normalized coordinates.
1978 *
1979 * Any Allocation used with a Sampler must have been created with
1980 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an
1981 * Allocation that was not created with
1982 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined.
1983 **/
Tim Murray729b6fe2013-07-23 16:20:42 -07001984 class Sampler : public BaseObj {
1985 private:
1986 Sampler(sp<RS> rs, void* id);
Miao Wange5428e62015-03-10 15:29:40 -07001987 Sampler(sp<RS> rs, void* id, RsSamplerValue min, RsSamplerValue mag,
1988 RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
Tim Murray729b6fe2013-07-23 16:20:42 -07001989 RsSamplerValue mMin;
1990 RsSamplerValue mMag;
1991 RsSamplerValue mWrapS;
1992 RsSamplerValue mWrapT;
Tim Murray729b6fe2013-07-23 16:20:42 -07001993 float mAniso;
1994
1995 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001996 /**
1997 * Creates a non-standard Sampler.
1998 * @param[in] rs RenderScript context
1999 * @param[in] min minification
2000 * @param[in] mag magnification
2001 * @param[in] wrapS S wrapping mode
2002 * @param[in] wrapT T wrapping mode
2003 * @param[in] anisotropy anisotropy setting
2004 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002005 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
2006
Tim Murray75e877d2013-09-11 14:45:20 -07002007 /**
2008 * @return minification setting for the sampler
2009 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002010 RsSamplerValue getMinification();
Tim Murray75e877d2013-09-11 14:45:20 -07002011 /**
2012 * @return magnification setting for the sampler
2013 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002014 RsSamplerValue getMagnification();
Tim Murray75e877d2013-09-11 14:45:20 -07002015 /**
2016 * @return S wrapping mode for the sampler
2017 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002018 RsSamplerValue getWrapS();
Tim Murray75e877d2013-09-11 14:45:20 -07002019 /**
2020 * @return T wrapping mode for the sampler
2021 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002022 RsSamplerValue getWrapT();
Tim Murray75e877d2013-09-11 14:45:20 -07002023 /**
2024 * @return anisotropy setting for the sampler
2025 */
Tim Murray729b6fe2013-07-23 16:20:42 -07002026 float getAnisotropy();
2027
Tim Murray75e877d2013-09-11 14:45:20 -07002028 /**
2029 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2030 * clamp.
2031 *
2032 * @param rs Context to which the sampler will belong.
2033 *
2034 * @return Sampler
2035 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002036 static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002037 /**
2038 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2039 * clamp.
2040 *
2041 * @param rs Context to which the sampler will belong.
2042 *
2043 * @return Sampler
2044 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002045 static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002046 /**
2047 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2048 * wrap modes set to clamp.
2049 *
2050 * @param rs Context to which the sampler will belong.
2051 *
2052 * @return Sampler
2053 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002054 static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002055 /**
2056 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2057 * wrap.
2058 *
2059 * @param rs Context to which the sampler will belong.
2060 *
2061 * @return Sampler
2062 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002063 static sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002064 /**
2065 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2066 * wrap.
2067 *
2068 * @param rs Context to which the sampler will belong.
2069 *
2070 * @return Sampler
2071 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002072 static sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002073 /**
2074 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2075 * wrap modes set to wrap.
2076 *
2077 * @param rs Context to which the sampler will belong.
2078 *
2079 * @return Sampler
2080 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002081 static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002082 /**
2083 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2084 * mirrored repeat.
2085 *
2086 * @param rs Context to which the sampler will belong.
2087 *
2088 * @return Sampler
2089 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002090 static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002091 /**
2092 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2093 * mirrored repeat.
2094 *
2095 * @param rs Context to which the sampler will belong.
2096 *
2097 * @return Sampler
2098 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002099 static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002100 /**
2101 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2102 * mirrored repeat.
2103 *
2104 * @param rs Context to which the sampler will belong.
2105 *
2106 * @return Sampler
2107 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002108 static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray729b6fe2013-07-23 16:20:42 -07002109
2110};
2111
Stephen Hinesd10412f2013-08-29 18:27:21 -07002112class Byte2 {
2113 public:
2114 int8_t x, y;
2115
2116 Byte2(int8_t initX, int8_t initY)
2117 : x(initX), y(initY) {}
2118 Byte2() : x(0), y(0) {}
2119};
2120
2121class Byte3 {
2122 public:
2123 int8_t x, y, z;
2124
2125 Byte3(int8_t initX, int8_t initY, int8_t initZ)
2126 : x(initX), y(initY), z(initZ) {}
2127 Byte3() : x(0), y(0), z(0) {}
2128};
2129
2130class Byte4 {
2131 public:
2132 int8_t x, y, z, w;
2133
2134 Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
2135 : x(initX), y(initY), z(initZ), w(initW) {}
2136 Byte4() : x(0), y(0), z(0), w(0) {}
2137};
2138
2139class UByte2 {
2140 public:
2141 uint8_t x, y;
2142
2143 UByte2(uint8_t initX, uint8_t initY)
2144 : x(initX), y(initY) {}
2145 UByte2() : x(0), y(0) {}
2146};
2147
2148class UByte3 {
2149 public:
2150 uint8_t x, y, z;
2151
2152 UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
2153 : x(initX), y(initY), z(initZ) {}
2154 UByte3() : x(0), y(0), z(0) {}
2155};
2156
2157class UByte4 {
2158 public:
2159 uint8_t x, y, z, w;
2160
2161 UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
2162 : x(initX), y(initY), z(initZ), w(initW) {}
2163 UByte4() : x(0), y(0), z(0), w(0) {}
2164};
2165
2166class Short2 {
2167 public:
2168 short x, y;
2169
2170 Short2(short initX, short initY)
2171 : x(initX), y(initY) {}
2172 Short2() : x(0), y(0) {}
2173};
2174
2175class Short3 {
2176 public:
2177 short x, y, z;
2178
2179 Short3(short initX, short initY, short initZ)
2180 : x(initX), y(initY), z(initZ) {}
2181 Short3() : x(0), y(0), z(0) {}
2182};
2183
2184class Short4 {
2185 public:
2186 short x, y, z, w;
2187
2188 Short4(short initX, short initY, short initZ, short initW)
2189 : x(initX), y(initY), z(initZ), w(initW) {}
2190 Short4() : x(0), y(0), z(0), w(0) {}
2191};
2192
2193class UShort2 {
2194 public:
2195 uint16_t x, y;
2196
2197 UShort2(uint16_t initX, uint16_t initY)
2198 : x(initX), y(initY) {}
2199 UShort2() : x(0), y(0) {}
2200};
2201
2202class UShort3 {
2203 public:
2204 uint16_t x, y, z;
2205
2206 UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
2207 : x(initX), y(initY), z(initZ) {}
2208 UShort3() : x(0), y(0), z(0) {}
2209};
2210
2211class UShort4 {
2212 public:
2213 uint16_t x, y, z, w;
2214
2215 UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
2216 : x(initX), y(initY), z(initZ), w(initW) {}
2217 UShort4() : x(0), y(0), z(0), w(0) {}
2218};
2219
2220class Int2 {
2221 public:
2222 int x, y;
2223
2224 Int2(int initX, int initY)
2225 : x(initX), y(initY) {}
2226 Int2() : x(0), y(0) {}
2227};
2228
2229class Int3 {
2230 public:
2231 int x, y, z;
2232
2233 Int3(int initX, int initY, int initZ)
2234 : x(initX), y(initY), z(initZ) {}
2235 Int3() : x(0), y(0), z(0) {}
2236};
2237
2238class Int4 {
2239 public:
2240 int x, y, z, w;
2241
2242 Int4(int initX, int initY, int initZ, int initW)
2243 : x(initX), y(initY), z(initZ), w(initW) {}
2244 Int4() : x(0), y(0), z(0), w(0) {}
2245};
2246
2247class UInt2 {
2248 public:
2249 uint32_t x, y;
2250
2251 UInt2(uint32_t initX, uint32_t initY)
2252 : x(initX), y(initY) {}
2253 UInt2() : x(0), y(0) {}
2254};
2255
2256class UInt3 {
2257 public:
2258 uint32_t x, y, z;
2259
2260 UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
2261 : x(initX), y(initY), z(initZ) {}
2262 UInt3() : x(0), y(0), z(0) {}
2263};
2264
2265class UInt4 {
2266 public:
2267 uint32_t x, y, z, w;
2268
2269 UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
2270 : x(initX), y(initY), z(initZ), w(initW) {}
2271 UInt4() : x(0), y(0), z(0), w(0) {}
2272};
2273
2274class Long2 {
2275 public:
2276 int64_t x, y;
2277
2278 Long2(int64_t initX, int64_t initY)
2279 : x(initX), y(initY) {}
2280 Long2() : x(0), y(0) {}
2281};
2282
2283class Long3 {
2284 public:
2285 int64_t x, y, z;
2286
2287 Long3(int64_t initX, int64_t initY, int64_t initZ)
2288 : x(initX), y(initY), z(initZ) {}
2289 Long3() : x(0), y(0), z(0) {}
2290};
2291
2292class Long4 {
2293 public:
2294 int64_t x, y, z, w;
2295
2296 Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
2297 : x(initX), y(initY), z(initZ), w(initW) {}
2298 Long4() : x(0), y(0), z(0), w(0) {}
2299};
2300
2301class ULong2 {
2302 public:
2303 uint64_t x, y;
2304
2305 ULong2(uint64_t initX, uint64_t initY)
2306 : x(initX), y(initY) {}
2307 ULong2() : x(0), y(0) {}
2308};
2309
2310class ULong3 {
2311 public:
2312 uint64_t x, y, z;
2313
2314 ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
2315 : x(initX), y(initY), z(initZ) {}
2316 ULong3() : x(0), y(0), z(0) {}
2317};
2318
2319class ULong4 {
2320 public:
2321 uint64_t x, y, z, w;
2322
2323 ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
2324 : x(initX), y(initY), z(initZ), w(initW) {}
2325 ULong4() : x(0), y(0), z(0), w(0) {}
2326};
2327
2328class Float2 {
2329 public:
2330 float x, y;
2331
2332 Float2(float initX, float initY)
2333 : x(initX), y(initY) {}
2334 Float2() : x(0), y(0) {}
2335};
2336
2337class Float3 {
2338 public:
2339 float x, y, z;
2340
2341 Float3(float initX, float initY, float initZ)
2342 : x(initX), y(initY), z(initZ) {}
2343 Float3() : x(0.f), y(0.f), z(0.f) {}
2344};
2345
2346class Float4 {
2347 public:
2348 float x, y, z, w;
2349
2350 Float4(float initX, float initY, float initZ, float initW)
2351 : x(initX), y(initY), z(initZ), w(initW) {}
2352 Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
2353};
2354
2355class Double2 {
2356 public:
2357 double x, y;
2358
2359 Double2(double initX, double initY)
2360 : x(initX), y(initY) {}
2361 Double2() : x(0), y(0) {}
2362};
2363
2364class Double3 {
2365 public:
2366 double x, y, z;
2367
2368 Double3(double initX, double initY, double initZ)
2369 : x(initX), y(initY), z(initZ) {}
2370 Double3() : x(0), y(0), z(0) {}
2371};
2372
2373class Double4 {
2374 public:
2375 double x, y, z, w;
2376
2377 Double4(double initX, double initY, double initZ, double initW)
2378 : x(initX), y(initY), z(initZ), w(initW) {}
2379 Double4() : x(0), y(0), z(0), w(0) {}
2380};
2381
Tim Murray84bf2b82012-10-31 16:03:16 -07002382}
Tim Murray7f0d5682012-11-08 16:35:24 -08002383
Tim Murray84bf2b82012-10-31 16:03:16 -07002384}
2385
2386#endif