blob: 14166f02165b94b078b656351b8dda4243a700d6 [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 Murray89daad62013-07-29 14:30:02 -070023#include <vector>
Tim Murrayab716362013-08-12 12:37:18 -070024#include <string>
Tim Murray8c24cd62014-04-10 18:04:39 -070025#include <pthread.h>
Tim Murray89daad62013-07-29 14:30:02 -070026
Tim Murray75e877d2013-09-11 14:45:20 -070027/**
28 * Every row in an RS allocation is guaranteed to be aligned by this amount, and
29 * every row in a user-backed allocation must be aligned by this amount.
30 */
Tim Murray96267c22013-02-12 11:25:12 -080031#define RS_CPU_ALLOCATION_ALIGNMENT 16
32
Jason Sams66f0a162014-11-11 13:46:38 -080033struct dispatchTable;
34
Tim Murray84bf2b82012-10-31 16:03:16 -070035namespace android {
Tim Murray9eb7f4b2012-11-16 14:02:18 -080036namespace RSC {
Tim Murray84bf2b82012-10-31 16:03:16 -070037
Jason Sams66f0a162014-11-11 13:46:38 -080038
Tim Murray84bf2b82012-10-31 16:03:16 -070039typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText);
40typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen);
41
42class RS;
43class BaseObj;
44class Element;
45class Type;
46class Allocation;
47class Script;
48class ScriptC;
Tim Murray729b6fe2013-07-23 16:20:42 -070049class Sampler;
Tim Murray84bf2b82012-10-31 16:03:16 -070050
Tim Murray75e877d2013-09-11 14:45:20 -070051/**
52 * Possible error codes used by RenderScript. Once a status other than RS_SUCCESS
53 * is returned, the RenderScript context is considered dead and cannot perform any
54 * additional work.
55 */
Tim Murray21fa7a02013-08-15 16:25:03 -070056 enum RSError {
Tim Murray75e877d2013-09-11 14:45:20 -070057 RS_SUCCESS = 0, ///< No error
58 RS_ERROR_INVALID_PARAMETER = 1, ///< An invalid parameter was passed to a function
59 RS_ERROR_RUNTIME_ERROR = 2, ///< The RenderScript driver returned an error; this is
60 ///< often indicative of a kernel that crashed
61 RS_ERROR_INVALID_ELEMENT = 3, ///< An invalid Element was passed to a function
Tim Murray21fa7a02013-08-15 16:25:03 -070062 RS_ERROR_MAX = 9999
63
64 };
65
Tim Murray75e877d2013-09-11 14:45:20 -070066 /**
67 * YUV formats supported by the RenderScript API.
68 */
Tim Murrayeb4426d2013-08-27 15:30:16 -070069 enum RSYuvFormat {
Tim Murray75e877d2013-09-11 14:45:20 -070070 RS_YUV_NONE = 0, ///< No YUV data
71 RS_YUV_YV12 = 1, ///< YUV data in YV12 format
72 RS_YUV_NV21 = 2, ///< YUV data in NV21 format
Tim Murrayeb4426d2013-08-27 15:30:16 -070073 RS_YUV_MAX = 3
74 };
75
Tim Murray75e877d2013-09-11 14:45:20 -070076 /**
77 * Flags that can control RenderScript behavior on a per-context level.
78 */
Tim Murray84e3dea2013-09-09 16:12:51 -070079 enum RSInitFlags {
Tim Murray75e877d2013-09-11 14:45:20 -070080 RS_INIT_SYNCHRONOUS = 1, ///< All RenderScript calls will be synchronous. May reduce latency.
81 RS_INIT_LOW_LATENCY = 2, ///< Prefer low latency devices over potentially higher throughput devices.
Tim Murray84e3dea2013-09-09 16:12:51 -070082 RS_INIT_MAX = 4
83 };
84
Tim Murray75e877d2013-09-11 14:45:20 -070085 /**
86 * The RenderScript context. This class controls initialization, resource management, and teardown.
87 */
Tim Murray89daad62013-07-29 14:30:02 -070088 class RS : public android::RSC::LightRefBase<RS> {
Tim Murray84bf2b82012-10-31 16:03:16 -070089
90 public:
91 RS();
92 virtual ~RS();
93
Tim Murray75e877d2013-09-11 14:45:20 -070094 /**
95 * Initializes a RenderScript context. A context must be initialized before it can be used.
Tim Murraycaf41262013-12-13 12:54:37 -080096 * @param[in] name Directory name to be used by this context. This should be equivalent to
97 * Context.getCacheDir().
Tim Murray75e877d2013-09-11 14:45:20 -070098 * @param[in] flags Optional flags for this context.
99 * @return true on success
100 */
Tim Murraycaf41262013-12-13 12:54:37 -0800101 bool init(std::string name, uint32_t flags = 0);
Tim Murray84bf2b82012-10-31 16:03:16 -0700102
Tim Murray75e877d2013-09-11 14:45:20 -0700103 /**
104 * Sets the error handler function for this context. This error handler is
105 * called whenever an error is set.
106 *
107 * @param[in] func Error handler function
108 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700109 void setErrorHandler(ErrorHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700110
111 /**
112 * Returns the current error handler function for this context.
113 *
114 * @return pointer to current error handler function or NULL if not set
115 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700116 ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
117
Tim Murray75e877d2013-09-11 14:45:20 -0700118 /**
119 * Sets the message handler function for this context. This message handler
120 * is called whenever a message is sent from a RenderScript kernel.
121 *
122 * @param[in] func Message handler function
123 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700124 void setMessageHandler(MessageHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700125
126 /**
127 * Returns the current message handler function for this context.
128 *
129 * @return pointer to current message handler function or NULL if not set
130 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700131 MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
132
Tim Murray75e877d2013-09-11 14:45:20 -0700133 /**
134 * Returns current status for the context.
135 *
136 * @return current error
137 */
Tim Murray10913a52013-08-20 17:19:47 -0700138 RSError getError();
Tim Murray84bf2b82012-10-31 16:03:16 -0700139
Tim Murray75e877d2013-09-11 14:45:20 -0700140 /**
141 * Waits for any currently running asynchronous operations to finish. This
142 * should only be used for performance testing and timing.
143 */
Tim Murraybaca6c32012-11-14 16:51:46 -0800144 void finish();
145
Tim Murray75e877d2013-09-11 14:45:20 -0700146 RsContext getContext() { return mContext; }
147 void throwError(RSError error, const char *errMsg);
148
Tim Murraya4230962013-07-17 16:50:10 -0700149 static dispatchTable* dispatch;
150
Tim Murray84bf2b82012-10-31 16:03:16 -0700151 private:
Tim Murray4a92d122013-07-22 10:56:18 -0700152 static bool usingNative;
Tim Murraya4230962013-07-17 16:50:10 -0700153 static bool initDispatch(int targetApi);
154
Tim Murraycaf41262013-12-13 12:54:37 -0800155 bool init(std::string &name, int targetApi, uint32_t flags);
Tim Murray84bf2b82012-10-31 16:03:16 -0700156 static void * threadProc(void *);
157
158 static bool gInitialized;
159 static pthread_mutex_t gInitMutex;
160
161 pthread_t mMessageThreadId;
162 pid_t mNativeMessageThreadId;
163 bool mMessageRun;
164
165 RsDevice mDev;
166 RsContext mContext;
Tim Murray21fa7a02013-08-15 16:25:03 -0700167 RSError mCurrentError;
Tim Murray84bf2b82012-10-31 16:03:16 -0700168
169 ErrorHandlerFunc_t mErrorFunc;
170 MessageHandlerFunc_t mMessageFunc;
Tim Murraya4230962013-07-17 16:50:10 -0700171 bool mInit;
Tim Murray84bf2b82012-10-31 16:03:16 -0700172
Tim Murraycaf41262013-12-13 12:54:37 -0800173 std::string mCacheDir;
174
Tim Murray84bf2b82012-10-31 16:03:16 -0700175 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700176 sp<const Element> U8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700177 sp<const Element> U8_2;
178 sp<const Element> U8_3;
179 sp<const Element> U8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700180 sp<const Element> I8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700181 sp<const Element> I8_2;
182 sp<const Element> I8_3;
183 sp<const Element> I8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700184 sp<const Element> U16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700185 sp<const Element> U16_2;
186 sp<const Element> U16_3;
187 sp<const Element> U16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700188 sp<const Element> I16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700189 sp<const Element> I16_2;
190 sp<const Element> I16_3;
191 sp<const Element> I16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700192 sp<const Element> U32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700193 sp<const Element> U32_2;
194 sp<const Element> U32_3;
195 sp<const Element> U32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700196 sp<const Element> I32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700197 sp<const Element> I32_2;
198 sp<const Element> I32_3;
199 sp<const Element> I32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700200 sp<const Element> U64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700201 sp<const Element> U64_2;
202 sp<const Element> U64_3;
203 sp<const Element> U64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700204 sp<const Element> I64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700205 sp<const Element> I64_2;
206 sp<const Element> I64_3;
207 sp<const Element> I64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700208 sp<const Element> F32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700209 sp<const Element> F32_2;
210 sp<const Element> F32_3;
211 sp<const Element> F32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700212 sp<const Element> F64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700213 sp<const Element> F64_2;
214 sp<const Element> F64_3;
215 sp<const Element> F64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700216 sp<const Element> BOOLEAN;
Tim Murray84bf2b82012-10-31 16:03:16 -0700217
Tim Murray89daad62013-07-29 14:30:02 -0700218 sp<const Element> ELEMENT;
219 sp<const Element> TYPE;
220 sp<const Element> ALLOCATION;
221 sp<const Element> SAMPLER;
222 sp<const Element> SCRIPT;
223 sp<const Element> MESH;
224 sp<const Element> PROGRAM_FRAGMENT;
225 sp<const Element> PROGRAM_VERTEX;
226 sp<const Element> PROGRAM_RASTER;
227 sp<const Element> PROGRAM_STORE;
Tim Murray84bf2b82012-10-31 16:03:16 -0700228
Tim Murray89daad62013-07-29 14:30:02 -0700229 sp<const Element> A_8;
230 sp<const Element> RGB_565;
231 sp<const Element> RGB_888;
232 sp<const Element> RGBA_5551;
233 sp<const Element> RGBA_4444;
234 sp<const Element> RGBA_8888;
Tim Murray84bf2b82012-10-31 16:03:16 -0700235
Tim Murrayeb4426d2013-08-27 15:30:16 -0700236 sp<const Element> YUV;
Tim Murray84bf2b82012-10-31 16:03:16 -0700237
Tim Murray89daad62013-07-29 14:30:02 -0700238 sp<const Element> MATRIX_4X4;
239 sp<const Element> MATRIX_3X3;
240 sp<const Element> MATRIX_2X2;
Tim Murray84bf2b82012-10-31 16:03:16 -0700241 } mElements;
242
Tim Murray729b6fe2013-07-23 16:20:42 -0700243 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700244 sp<const Sampler> CLAMP_NEAREST;
245 sp<const Sampler> CLAMP_LINEAR;
246 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
247 sp<const Sampler> WRAP_NEAREST;
248 sp<const Sampler> WRAP_LINEAR;
249 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
250 sp<const Sampler> MIRRORED_REPEAT_NEAREST;
251 sp<const Sampler> MIRRORED_REPEAT_LINEAR;
252 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Tim Murray729b6fe2013-07-23 16:20:42 -0700253 } mSamplers;
254 friend class Sampler;
255 friend class Element;
Tim Murraycaf41262013-12-13 12:54:37 -0800256 friend class ScriptC;
Tim Murray84bf2b82012-10-31 16:03:16 -0700257};
258
Tim Murray75e877d2013-09-11 14:45:20 -0700259 /**
260 * Base class for all RenderScript objects. Not for direct use by developers.
261 */
Tim Murray89daad62013-07-29 14:30:02 -0700262class BaseObj : public android::RSC::LightRefBase<BaseObj> {
263public:
264 void * getID() const;
265 virtual ~BaseObj();
266 virtual void updateFromNative();
267 virtual bool equals(sp<const BaseObj> obj);
268
Tim Murray84bf2b82012-10-31 16:03:16 -0700269protected:
270 void *mID;
Tim Murray35609072013-12-03 11:36:03 -0800271 RS* mRS;
Tim Murrayab716362013-08-12 12:37:18 -0700272 std::string mName;
Tim Murray84bf2b82012-10-31 16:03:16 -0700273
274 BaseObj(void *id, sp<RS> rs);
275 void checkValid();
276
277 static void * getObjID(sp<const BaseObj> o);
278
Tim Murray84bf2b82012-10-31 16:03:16 -0700279};
280
Tim Murray75e877d2013-09-11 14:45:20 -0700281 /**
282 * This class provides the primary method through which data is passed to and
283 * from RenderScript kernels. An Allocation provides the backing store for a
284 * given Type.
285 *
286 * An Allocation also contains a set of usage flags that denote how the
287 * Allocation could be used. For example, an Allocation may have usage flags
288 * specifying that it can be used from a script as well as input to a
289 * Sampler. A developer must synchronize across these different usages using
290 * syncAll(int) in order to ensure that different users of the Allocation have
291 * a consistent view of memory. For example, in the case where an Allocation is
292 * used as the output of one kernel and as Sampler input in a later kernel, a
293 * developer must call syncAll(RS_ALLOCATION_USAGE_SCRIPT) prior to launching the
294 * second kernel to ensure correctness.
295 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700296class Allocation : public BaseObj {
297protected:
Tim Murray89daad62013-07-29 14:30:02 -0700298 sp<const Type> mType;
Tim Murray84bf2b82012-10-31 16:03:16 -0700299 uint32_t mUsage;
Tim Murray89daad62013-07-29 14:30:02 -0700300 sp<Allocation> mAdaptedAllocation;
Tim Murray84bf2b82012-10-31 16:03:16 -0700301
302 bool mConstrainedLOD;
303 bool mConstrainedFace;
304 bool mConstrainedY;
305 bool mConstrainedZ;
306 bool mReadAllowed;
307 bool mWriteAllowed;
Miao Wange5428e62015-03-10 15:29:40 -0700308 bool mAutoPadding;
Tim Murray84bf2b82012-10-31 16:03:16 -0700309 uint32_t mSelectedY;
310 uint32_t mSelectedZ;
311 uint32_t mSelectedLOD;
312 RsAllocationCubemapFace mSelectedFace;
313
314 uint32_t mCurrentDimX;
315 uint32_t mCurrentDimY;
316 uint32_t mCurrentDimZ;
317 uint32_t mCurrentCount;
318
319 void * getIDSafe() const;
320 void updateCacheInfo(sp<const Type> t);
321
322 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
323
Miao Wange5428e62015-03-10 15:29:40 -0700324 void validateIsInt64();
Tim Murray84bf2b82012-10-31 16:03:16 -0700325 void validateIsInt32();
326 void validateIsInt16();
327 void validateIsInt8();
328 void validateIsFloat32();
Miao Wange5428e62015-03-10 15:29:40 -0700329 void validateIsFloat64();
Tim Murray84bf2b82012-10-31 16:03:16 -0700330 void validateIsObject();
331
332 virtual void updateFromNative();
333
334 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
Tim Murray9d24ae62013-08-30 12:17:14 -0700335 void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff,
336 uint32_t w, uint32_t h, uint32_t d);
Tim Murray84bf2b82012-10-31 16:03:16 -0700337
338public:
Tim Murray75e877d2013-09-11 14:45:20 -0700339
340 /**
341 * Return Type for the allocation.
342 * @return pointer to underlying Type
343 */
Stephen Hinesa180b7d2013-08-21 12:42:13 -0700344 sp<const Type> getType() const {
Tim Murray84bf2b82012-10-31 16:03:16 -0700345 return mType;
346 }
347
Tim Murray75e877d2013-09-11 14:45:20 -0700348 /**
Miao Wange5428e62015-03-10 15:29:40 -0700349 * Enable/Disable AutoPadding for Vec3 elements.
350 *
351 * @param useAutoPadding True: enable AutoPadding; flase: disable AutoPadding
352 *
353 */
354 void setAutoPadding(bool useAutoPadding) {
355 mAutoPadding = useAutoPadding;
356 }
357
358 /**
Tim Murray75e877d2013-09-11 14:45:20 -0700359 * Propagate changes from one usage of the Allocation to other usages of the Allocation.
360 * @param[in] srcLocation source location with changes to propagate elsewhere
361 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700362 void syncAll(RsAllocationUsageType srcLocation);
363 void ioSendOutput();
364 void ioGetInput();
365
Tim Murray75e877d2013-09-11 14:45:20 -0700366 /**
367 * Generate a mipmap chain. This is only valid if the Type of the Allocation
368 * includes mipmaps. This function will generate a complete set of mipmaps
369 * from the top level LOD and place them into the script memory space. If
370 * the Allocation is also using other memory spaces, a call to
371 * syncAll(Allocation.USAGE_SCRIPT) is required.
372 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700373 void generateMipmaps();
Tim Murray509ea5c2012-11-13 11:56:40 -0800374
Tim Murray75e877d2013-09-11 14:45:20 -0700375 /**
376 * Copy an array into part of this Allocation.
377 * @param[in] off offset of first Element to be overwritten
378 * @param[in] count number of Elements to copy
379 * @param[in] data array from which to copy
380 */
Tim Murray0b93e302012-11-15 14:56:54 -0800381 void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
Tim Murray75e877d2013-09-11 14:45:20 -0700382
383 /**
384 * Copy part of an Allocation into part of this Allocation.
385 * @param[in] off offset of first Element to be overwritten
386 * @param[in] count number of Elements to copy
387 * @param[in] data Allocation from which to copy
388 * @param[in] dataOff offset of first Element in data to copy
389 */
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800390 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700391
Tim Murray75e877d2013-09-11 14:45:20 -0700392 /**
393 * Copy an array into part of this Allocation.
394 * @param[in] off offset of first Element to be overwritten
395 * @param[in] count number of Elements to copy
396 * @param[in] data array from which to copy
397 */
Tim Murray0b93e302012-11-15 14:56:54 -0800398 void copy1DRangeTo(uint32_t off, size_t count, void *data);
399
Tim Murray75e877d2013-09-11 14:45:20 -0700400 /**
401 * Copy entire array to an Allocation.
402 * @param[in] data array from which to copy
403 */
Tim Murray0b93e302012-11-15 14:56:54 -0800404 void copy1DFrom(const void* data);
Tim Murray75e877d2013-09-11 14:45:20 -0700405
406 /**
407 * Copy entire Allocation to an array.
408 * @param[in] data destination array
409 */
Tim Murray0b93e302012-11-15 14:56:54 -0800410 void copy1DTo(void* data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800411
Tim Murray75e877d2013-09-11 14:45:20 -0700412 /**
413 * Copy from an array into a rectangular region in this Allocation. The
414 * array is assumed to be tightly packed.
415 * @param[in] xoff X offset of region to update in this Allocation
416 * @param[in] yoff Y offset of region to update in this Allocation
417 * @param[in] w Width of region to update
418 * @param[in] h Height of region to update
419 * @param[in] data Array from which to copy
420 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700421 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800422 const void *data);
Tim Murray7b3e3092012-11-16 13:32:24 -0800423
Tim Murray75e877d2013-09-11 14:45:20 -0700424 /**
425 * Copy from this Allocation into a rectangular region in an array. The
426 * array is assumed to be tightly packed.
427 * @param[in] xoff X offset of region to copy from this Allocation
428 * @param[in] yoff Y offset of region to copy from this Allocation
429 * @param[in] w Width of region to update
430 * @param[in] h Height of region to update
431 * @param[in] data destination array
432 */
Tim Murray7b3e3092012-11-16 13:32:24 -0800433 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
434 void *data);
435
Tim Murray75e877d2013-09-11 14:45:20 -0700436 /**
437 * Copy from an Allocation into a rectangular region in this Allocation.
438 * @param[in] xoff X offset of region to update in this Allocation
439 * @param[in] yoff Y offset of region to update in this Allocation
440 * @param[in] w Width of region to update
441 * @param[in] h Height of region to update
442 * @param[in] data Allocation from which to copy
443 * @param[in] dataXoff X offset of region to copy from in data
444 * @param[in] dataYoff Y offset of region to copy from in data
445 */
Tim Murray0b93e302012-11-15 14:56:54 -0800446 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
447 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700448
Tim Murray75e877d2013-09-11 14:45:20 -0700449 /**
450 * Copy from a strided array into a rectangular region in this Allocation.
451 * @param[in] xoff X offset of region to update in this Allocation
452 * @param[in] yoff Y offset of region to update in this Allocation
453 * @param[in] w Width of region to update
454 * @param[in] h Height of region to update
455 * @param[in] data array from which to copy
456 * @param[in] stride stride of data in bytes
457 */
Tim Murray358747a2012-11-26 13:52:04 -0800458 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
459 const void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700460
461 /**
462 * Copy from a strided array into this Allocation.
463 * @param[in] data array from which to copy
464 * @param[in] stride stride of data in bytes
465 */
Tim Murray358747a2012-11-26 13:52:04 -0800466 void copy2DStridedFrom(const void *data, size_t stride);
467
Tim Murray75e877d2013-09-11 14:45:20 -0700468 /**
469 * Copy from a rectangular region in this Allocation into a strided array.
470 * @param[in] xoff X offset of region to update in this Allocation
471 * @param[in] yoff Y offset of region to update in this Allocation
472 * @param[in] w Width of region to update
473 * @param[in] h Height of region to update
474 * @param[in] data destination array
475 * @param[in] stride stride of data in bytes
476 */
Tim Murray358747a2012-11-26 13:52:04 -0800477 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
478 void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700479
480 /**
481 * Copy this Allocation into a strided array.
482 * @param[in] data destination array
483 * @param[in] stride stride of data in bytes
484 */
Tim Murray358747a2012-11-26 13:52:04 -0800485 void copy2DStridedTo(void *data, size_t stride);
486
Tim Murray75e877d2013-09-11 14:45:20 -0700487
488 /**
489 * Copy from an array into a 3D region in this Allocation. The
490 * array is assumed to be tightly packed.
491 * @param[in] xoff X offset of region to update in this Allocation
492 * @param[in] yoff Y offset of region to update in this Allocation
493 * @param[in] zoff Z offset of region to update in this Allocation
494 * @param[in] w Width of region to update
495 * @param[in] h Height of region to update
496 * @param[in] d Depth of region to update
497 * @param[in] data Array from which to copy
498 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700499 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
500 uint32_t h, uint32_t d, const void* data);
501
Tim Murray75e877d2013-09-11 14:45:20 -0700502 /**
503 * Copy from an Allocation into a 3D region in this Allocation.
504 * @param[in] xoff X offset of region to update in this Allocation
505 * @param[in] yoff Y offset of region to update in this Allocation
506 * @param[in] zoff Z offset of region to update in this Allocation
507 * @param[in] w Width of region to update
508 * @param[in] h Height of region to update
509 * @param[in] d Depth of region to update
510 * @param[in] data Allocation from which to copy
511 * @param[in] dataXoff X offset of region in data to copy from
512 * @param[in] dataYoff Y offset of region in data to copy from
513 * @param[in] dataZoff Z offset of region in data to copy from
514 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700515 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
516 uint32_t w, uint32_t h, uint32_t d,
517 sp<const Allocation> data,
518 uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700519
Tim Murray75e877d2013-09-11 14:45:20 -0700520 /**
Miao Wange5428e62015-03-10 15:29:40 -0700521 * Copy a 3D region in this Allocation into an array. The
522 * array is assumed to be tightly packed.
523 * @param[in] xoff X offset of region to update in this Allocation
524 * @param[in] yoff Y offset of region to update in this Allocation
525 * @param[in] zoff Z offset of region to update in this Allocation
526 * @param[in] w Width of region to update
527 * @param[in] h Height of region to update
528 * @param[in] d Depth of region to update
529 * @param[in] data Array from which to copy
530 */
531 void copy3DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
532 uint32_t h, uint32_t d, void* data);
533
534 /**
Tim Murray75e877d2013-09-11 14:45:20 -0700535 * Creates an Allocation for use by scripts with a given Type.
536 * @param[in] rs Context to which the Allocation will belong
537 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800538 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700539 * @param[in] usage usage for the Allocation
540 * @return new Allocation
541 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700542 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800543 RsAllocationMipmapControl mipmaps, uint32_t usage);
Tim Murray75e877d2013-09-11 14:45:20 -0700544
545 /**
546 * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use
547 * with RS_ALLOCATION_USAGE_SHARED.
548 * @param[in] rs Context to which the Allocation will belong
549 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800550 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700551 * @param[in] usage usage for the Allocation
552 * @param[in] pointer existing backing store to use for this Allocation if possible
553 * @return new Allocation
554 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700555 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800556 RsAllocationMipmapControl mipmaps, uint32_t usage, void * pointer);
Tim Murray84bf2b82012-10-31 16:03:16 -0700557
Tim Murray75e877d2013-09-11 14:45:20 -0700558 /**
559 * Creates an Allocation for use by scripts with a given Type with no mipmaps.
560 * @param[in] rs Context to which the Allocation will belong
561 * @param[in] type Type of the Allocation
562 * @param[in] usage usage for the Allocation
563 * @return new Allocation
564 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700565 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
566 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700567 /**
568 * Creates an Allocation with a specified number of given elements.
569 * @param[in] rs Context to which the Allocation will belong
570 * @param[in] e Element used in the Allocation
571 * @param[in] count Number of elements of the Allocation
572 * @param[in] usage usage for the Allocation
573 * @return new Allocation
574 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700575 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
576 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700577
578 /**
579 * Creates a 2D Allocation with a specified number of given elements.
580 * @param[in] rs Context to which the Allocation will belong
581 * @param[in] e Element used in the Allocation
582 * @param[in] x Width in Elements of the Allocation
583 * @param[in] y Height of the Allocation
584 * @param[in] usage usage for the Allocation
585 * @return new Allocation
586 */
Tim Murray684726c2012-11-14 11:57:42 -0800587 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
588 size_t x, size_t y,
589 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
590
Tim Murray84bf2b82012-10-31 16:03:16 -0700591
Jason Samsb8a94e22014-02-24 17:52:32 -0800592 /**
593 * Get the backing pointer for a USAGE_SHARED allocation.
594 * @param[in] stride optional parameter. when non-NULL, will contain
595 * stride in bytes of a 2D Allocation
596 * @return pointer to data
597 */
598 void * getPointer(size_t *stride = NULL);
Tim Murray84bf2b82012-10-31 16:03:16 -0700599};
600
Tim Murray75e877d2013-09-11 14:45:20 -0700601 /**
602 * An Element represents one item within an Allocation. An Element is roughly
603 * equivalent to a C type in a RenderScript kernel. Elements may be basic
604 * or complex. Some basic elements are:
605
606 * - A single float value (equivalent to a float in a kernel)
607 * - A four-element float vector (equivalent to a float4 in a kernel)
608 * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel)
609 * - A single signed 8-bit integer (equivalent to a char in a kernel)
610
611 * Basic Elements are comprised of a Element.DataType and a
612 * Element.DataKind. The DataType encodes C type information of an Element,
613 * while the DataKind encodes how that Element should be interpreted by a
614 * Sampler. Note that Allocation objects with DataKind USER cannot be used as
615 * input for a Sampler. In general, Allocation objects that are intended for
616 * use with a Sampler should use bitmap-derived Elements such as
617 * Element::RGBA_8888.
618 */
619
620
Tim Murray84bf2b82012-10-31 16:03:16 -0700621class Element : public BaseObj {
622public:
623 bool isComplex();
Tim Murray75e877d2013-09-11 14:45:20 -0700624
625 /**
626 * Elements could be simple, such as an int or a float, or a structure with
627 * multiple sub-elements, such as a collection of floats, float2,
628 * float4. This function returns zero for simple elements or the number of
629 * sub-elements otherwise.
630 * @return number of sub-elements
631 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700632 size_t getSubElementCount() {
633 return mVisibleElementMap.size();
634 }
635
Tim Murray75e877d2013-09-11 14:45:20 -0700636 /**
637 * For complex Elements, this returns the sub-element at a given index.
638 * @param[in] index index of sub-element
639 * @return sub-element
640 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700641 sp<const Element> getSubElement(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700642
643 /**
644 * For complex Elements, this returns the name of the sub-element at a given
645 * index.
646 * @param[in] index index of sub-element
647 * @return name of sub-element
648 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700649 const char * getSubElementName(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700650
651 /**
652 * For complex Elements, this returns the size of the sub-element at a given
653 * index.
654 * @param[in] index index of sub-element
655 * @return size of sub-element
656 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700657 size_t getSubElementArraySize(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700658
659 /**
660 * Returns the location of a sub-element within a complex Element.
661 * @param[in] index index of sub-element
662 * @return offset in bytes
663 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700664 uint32_t getSubElementOffsetBytes(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700665
666 /**
667 * Returns the data type used for the Element.
668 * @return data type
669 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700670 RsDataType getDataType() const {
671 return mType;
672 }
673
Tim Murray75e877d2013-09-11 14:45:20 -0700674 /**
675 * Returns the data kind used for the Element.
676 * @return data kind
677 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700678 RsDataKind getDataKind() const {
679 return mKind;
680 }
681
Tim Murray75e877d2013-09-11 14:45:20 -0700682 /**
683 * Returns the size in bytes of the Element.
684 * @return size in bytes
685 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700686 size_t getSizeBytes() const {
687 return mSizeBytes;
688 }
689
Tim Murray75e877d2013-09-11 14:45:20 -0700690 /**
691 * Returns the number of vector components for this Element.
692 * @return number of vector components
693 */
Tim Murray10913a52013-08-20 17:19:47 -0700694 uint32_t getVectorSize() const {
695 return mVectorSize;
696 }
697
Tim Murray75e877d2013-09-11 14:45:20 -0700698 /**
699 * Utility function for returning an Element containing a single bool.
700 * @param[in] rs RenderScript context
701 * @return Element
702 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700703 static sp<const Element> BOOLEAN(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700704 /**
705 * Utility function for returning an Element containing a single unsigned char.
706 * @param[in] rs RenderScript context
707 * @return Element
708 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700709 static sp<const Element> U8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700710 /**
711 * Utility function for returning an Element containing a single signed char.
712 * @param[in] rs RenderScript context
713 * @return Element
714 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700715 static sp<const Element> I8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700716 /**
717 * Utility function for returning an Element containing a single unsigned short.
718 * @param[in] rs RenderScript context
719 * @return Element
720 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700721 static sp<const Element> U16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700722 /**
723 * Utility function for returning an Element containing a single signed short.
724 * @param[in] rs RenderScript context
725 * @return Element
726 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700727 static sp<const Element> I16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700728 /**
729 * Utility function for returning an Element containing a single unsigned int.
730 * @param[in] rs RenderScript context
731 * @return Element
732 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700733 static sp<const Element> U32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700734 /**
735 * Utility function for returning an Element containing a single signed int.
736 * @param[in] rs RenderScript context
737 * @return Element
738 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700739 static sp<const Element> I32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700740 /**
741 * Utility function for returning an Element containing a single unsigned long long.
742 * @param[in] rs RenderScript context
743 * @return Element
744 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700745 static sp<const Element> U64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700746 /**
747 * Utility function for returning an Element containing a single signed long long.
748 * @param[in] rs RenderScript context
749 * @return Element
750 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700751 static sp<const Element> I64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700752 /**
753 * Utility function for returning an Element containing a single float.
754 * @param[in] rs RenderScript context
755 * @return Element
756 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700757 static sp<const Element> F32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700758 /**
759 * Utility function for returning an Element containing a single double.
760 * @param[in] rs RenderScript context
761 * @return Element
762 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700763 static sp<const Element> F64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700764 /**
765 * Utility function for returning an Element containing a single Element.
766 * @param[in] rs RenderScript context
767 * @return Element
768 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700769 static sp<const Element> ELEMENT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700770 /**
771 * Utility function for returning an Element containing a single Type.
772 * @param[in] rs RenderScript context
773 * @return Element
774 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700775 static sp<const Element> TYPE(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700776 /**
777 * Utility function for returning an Element containing a single Allocation.
778 * @param[in] rs RenderScript context
779 * @return Element
780 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700781 static sp<const Element> ALLOCATION(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700782 /**
783 * Utility function for returning an Element containing a single Sampler.
784 * @param[in] rs RenderScript context
785 * @return Element
786 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700787 static sp<const Element> SAMPLER(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700788 /**
789 * Utility function for returning an Element containing a single Script.
790 * @param[in] rs RenderScript context
791 * @return Element
792 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700793 static sp<const Element> SCRIPT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700794 /**
795 * Utility function for returning an Element containing an ALPHA_8 pixel.
796 * @param[in] rs RenderScript context
797 * @return Element
798 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700799 static sp<const Element> A_8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700800 /**
801 * Utility function for returning an Element containing an RGB_565 pixel.
802 * @param[in] rs RenderScript context
803 * @return Element
804 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700805 static sp<const Element> RGB_565(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700806 /**
807 * Utility function for returning an Element containing an RGB_888 pixel.
808 * @param[in] rs RenderScript context
809 * @return Element
810 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700811 static sp<const Element> RGB_888(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700812 /**
813 * Utility function for returning an Element containing an RGBA_5551 pixel.
814 * @param[in] rs RenderScript context
815 * @return Element
816 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700817 static sp<const Element> RGBA_5551(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700818 /**
819 * Utility function for returning an Element containing an RGBA_4444 pixel.
820 * @param[in] rs RenderScript context
821 * @return Element
822 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700823 static sp<const Element> RGBA_4444(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700824 /**
825 * Utility function for returning an Element containing an RGBA_8888 pixel.
826 * @param[in] rs RenderScript context
827 * @return Element
828 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700829 static sp<const Element> RGBA_8888(sp<RS> rs);
830
Tim Murray75e877d2013-09-11 14:45:20 -0700831 /**
832 * Utility function for returning an Element containing a float2.
833 * @param[in] rs RenderScript context
834 * @return Element
835 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700836 static sp<const Element> F32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700837 /**
838 * Utility function for returning an Element containing a float3.
839 * @param[in] rs RenderScript context
840 * @return Element
841 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700842 static sp<const Element> F32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700843 /**
844 * Utility function for returning an Element containing a float4.
845 * @param[in] rs RenderScript context
846 * @return Element
847 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700848 static sp<const Element> F32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700849 /**
850 * Utility function for returning an Element containing a double2.
851 * @param[in] rs RenderScript context
852 * @return Element
853 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700854 static sp<const Element> F64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700855 /**
856 * Utility function for returning an Element containing a double3.
857 * @param[in] rs RenderScript context
858 * @return Element
859 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700860 static sp<const Element> F64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700861 /**
862 * Utility function for returning an Element containing a double4.
863 * @param[in] rs RenderScript context
864 * @return Element
865 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700866 static sp<const Element> F64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700867 /**
868 * Utility function for returning an Element containing a uchar2.
869 * @param[in] rs RenderScript context
870 * @return Element
871 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700872 static sp<const Element> U8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700873 /**
874 * Utility function for returning an Element containing a uchar3.
875 * @param[in] rs RenderScript context
876 * @return Element
877 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700878 static sp<const Element> U8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700879 /**
880 * Utility function for returning an Element containing a uchar4.
881 * @param[in] rs RenderScript context
882 * @return Element
883 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700884 static sp<const Element> U8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700885 /**
886 * Utility function for returning an Element containing a char2.
887 * @param[in] rs RenderScript context
888 * @return Element
889 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700890 static sp<const Element> I8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700891 /**
892 * Utility function for returning an Element containing a char3.
893 * @param[in] rs RenderScript context
894 * @return Element
895 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700896 static sp<const Element> I8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700897 /**
898 * Utility function for returning an Element containing a char4.
899 * @param[in] rs RenderScript context
900 * @return Element
901 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700902 static sp<const Element> I8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700903 /**
904 * Utility function for returning an Element containing a ushort2.
905 * @param[in] rs RenderScript context
906 * @return Element
907 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700908 static sp<const Element> U16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700909 /**
910 * Utility function for returning an Element containing a ushort3.
911 * @param[in] rs RenderScript context
912 * @return Element
913 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700914 static sp<const Element> U16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700915 /**
916 * Utility function for returning an Element containing a ushort4.
917 * @param[in] rs RenderScript context
918 * @return Element
919 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700920 static sp<const Element> U16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700921 /**
922 * Utility function for returning an Element containing a short2.
923 * @param[in] rs RenderScript context
924 * @return Element
925 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700926 static sp<const Element> I16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700927 /**
928 * Utility function for returning an Element containing a short3.
929 * @param[in] rs RenderScript context
930 * @return Element
931 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700932 static sp<const Element> I16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700933 /**
934 * Utility function for returning an Element containing a short4.
935 * @param[in] rs RenderScript context
936 * @return Element
937 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700938 static sp<const Element> I16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700939 /**
940 * Utility function for returning an Element containing a uint2.
941 * @param[in] rs RenderScript context
942 * @return Element
943 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700944 static sp<const Element> U32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700945 /**
946 * Utility function for returning an Element containing a uint3.
947 * @param[in] rs RenderScript context
948 * @return Element
949 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700950 static sp<const Element> U32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700951 /**
952 * Utility function for returning an Element containing a uint4.
953 * @param[in] rs RenderScript context
954 * @return Element
955 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700956 static sp<const Element> U32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700957 /**
958 * Utility function for returning an Element containing an int2.
959 * @param[in] rs RenderScript context
960 * @return Element
961 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700962 static sp<const Element> I32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700963 /**
964 * Utility function for returning an Element containing an int3.
965 * @param[in] rs RenderScript context
966 * @return Element
967 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700968 static sp<const Element> I32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700969 /**
970 * Utility function for returning an Element containing an int4.
971 * @param[in] rs RenderScript context
972 * @return Element
973 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700974 static sp<const Element> I32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700975 /**
976 * Utility function for returning an Element containing a ulong2.
977 * @param[in] rs RenderScript context
978 * @return Element
979 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700980 static sp<const Element> U64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700981 /**
982 * Utility function for returning an Element containing a ulong3.
983 * @param[in] rs RenderScript context
984 * @return Element
985 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700986 static sp<const Element> U64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700987 /**
988 * Utility function for returning an Element containing a ulong4.
989 * @param[in] rs RenderScript context
990 * @return Element
991 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700992 static sp<const Element> U64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700993 /**
994 * Utility function for returning an Element containing a long2.
995 * @param[in] rs RenderScript context
996 * @return Element
997 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700998 static sp<const Element> I64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700999 /**
1000 * Utility function for returning an Element containing a long3.
1001 * @param[in] rs RenderScript context
1002 * @return Element
1003 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001004 static sp<const Element> I64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001005 /**
1006 * Utility function for returning an Element containing a long4.
1007 * @param[in] rs RenderScript context
1008 * @return Element
1009 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001010 static sp<const Element> I64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001011 /**
1012 * Utility function for returning an Element containing a YUV pixel.
1013 * @param[in] rs RenderScript context
1014 * @return Element
1015 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001016 static sp<const Element> YUV(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001017 /**
1018 * Utility function for returning an Element containing an rs_matrix_4x4.
1019 * @param[in] rs RenderScript context
1020 * @return Element
1021 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001022 static sp<const Element> MATRIX_4X4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001023 /**
1024 * Utility function for returning an Element containing an rs_matrix_3x3.
1025 * @param[in] rs RenderScript context
1026 * @return Element
1027 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001028 static sp<const Element> MATRIX_3X3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001029 /**
1030 * Utility function for returning an Element containing an rs_matrix_2x2.
1031 * @param[in] rs RenderScript context
1032 * @return Element
1033 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001034 static sp<const Element> MATRIX_2X2(sp<RS> rs);
1035
Tim Murray84bf2b82012-10-31 16:03:16 -07001036 void updateFromNative();
Tim Murray75e877d2013-09-11 14:45:20 -07001037
1038 /**
1039 * Create an Element with a given DataType.
1040 * @param[in] rs RenderScript context
1041 * @param[in] dt data type
1042 * @return Element
1043 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001044 static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
Tim Murray75e877d2013-09-11 14:45:20 -07001045 /**
1046 * Create a vector Element with the given DataType
1047 * @param[in] rs RenderScript
1048 * @param[in] dt DataType
1049 * @param[in] size vector size
1050 * @return Element
1051 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001052 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
Tim Murray75e877d2013-09-11 14:45:20 -07001053 /**
1054 * Create an Element with a given DataType and DataKind.
1055 * @param[in] rs RenderScript context
1056 * @param[in] dt DataType
1057 * @param[in] dk DataKind
1058 * @return Element
1059 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001060 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
Tim Murray75e877d2013-09-11 14:45:20 -07001061
1062 /**
1063 * Returns true if the Element can interoperate with this Element.
1064 * @param[in] e Element to compare
1065 * @return true if Elements can interoperate
1066 */
Tim Murray10913a52013-08-20 17:19:47 -07001067 bool isCompatible(sp<const Element>e) const;
Tim Murray84bf2b82012-10-31 16:03:16 -07001068
Tim Murray75e877d2013-09-11 14:45:20 -07001069 /**
1070 * Builder class for producing complex elements with matching field and name
1071 * pairs. The builder starts empty. The order in which elements are added is
1072 * retained for the layout in memory.
1073 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001074 class Builder {
1075 private:
Tim Murray35609072013-12-03 11:36:03 -08001076 RS* mRS;
Tim Murray89daad62013-07-29 14:30:02 -07001077 std::vector<sp<Element> > mElements;
Tim Murrayab716362013-08-12 12:37:18 -07001078 std::vector<std::string> mElementNames;
Tim Murray89daad62013-07-29 14:30:02 -07001079 std::vector<uint32_t> mArraySizes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001080 bool mSkipPadding;
1081
1082 public:
1083 Builder(sp<RS> rs);
1084 ~Builder();
Tim Murrayab716362013-08-12 12:37:18 -07001085 void add(sp<Element> e, std::string &name, uint32_t arraySize = 1);
Tim Murray84bf2b82012-10-31 16:03:16 -07001086 sp<const Element> create();
1087 };
1088
Stephen Hines7d1b7572013-08-22 01:24:06 -07001089protected:
1090 Element(void *id, sp<RS> rs,
1091 std::vector<sp<Element> > &elements,
1092 std::vector<std::string> &elementNames,
1093 std::vector<uint32_t> &arraySizes);
1094 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
1095 Element(sp<RS> rs);
1096 virtual ~Element();
1097
Tim Murray84bf2b82012-10-31 16:03:16 -07001098private:
1099 void updateVisibleSubElements();
1100
Tim Murray89daad62013-07-29 14:30:02 -07001101 std::vector<sp<Element> > mElements;
Tim Murrayab716362013-08-12 12:37:18 -07001102 std::vector<std::string> mElementNames;
Tim Murray89daad62013-07-29 14:30:02 -07001103 std::vector<uint32_t> mArraySizes;
1104 std::vector<uint32_t> mVisibleElementMap;
1105 std::vector<uint32_t> mOffsetInBytes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001106
1107 RsDataType mType;
1108 RsDataKind mKind;
1109 bool mNormalized;
1110 size_t mSizeBytes;
1111 size_t mVectorSize;
1112};
1113
Stephen Hines2c7206e2012-11-14 19:47:01 -08001114class FieldPacker {
1115protected:
1116 unsigned char* mData;
1117 size_t mPos;
1118 size_t mLen;
1119
1120public:
1121 FieldPacker(size_t len)
Tim Murray89daad62013-07-29 14:30:02 -07001122 : mPos(0), mLen(len) {
1123 mData = new unsigned char[len];
1124 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001125
1126 virtual ~FieldPacker() {
1127 delete [] mData;
1128 }
1129
1130 void align(size_t v) {
1131 if ((v & (v - 1)) != 0) {
Tim Murrayab716362013-08-12 12:37:18 -07001132 // ALOGE("Non-power-of-two alignment: %zu", v);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001133 return;
1134 }
1135
1136 while ((mPos & (v - 1)) != 0) {
1137 mData[mPos++] = 0;
1138 }
1139 }
1140
1141 void reset() {
1142 mPos = 0;
1143 }
1144
1145 void reset(size_t i) {
1146 if (i >= mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001147 // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001148 return;
1149 }
1150 mPos = i;
1151 }
1152
1153 void skip(size_t i) {
1154 size_t res = mPos + i;
1155 if (res > mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001156 // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001157 return;
1158 }
1159 mPos = res;
1160 }
1161
1162 void* getData() const {
1163 return mData;
1164 }
1165
1166 size_t getLength() const {
1167 return mLen;
1168 }
1169
1170 template <typename T>
Tim Murray89daad62013-07-29 14:30:02 -07001171 void add(T t) {
Stephen Hines2c7206e2012-11-14 19:47:01 -08001172 align(sizeof(t));
1173 if (mPos + sizeof(t) <= mLen) {
1174 memcpy(&mData[mPos], &t, sizeof(t));
1175 mPos += sizeof(t);
1176 }
1177 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001178
1179 /*
Tim Murray89daad62013-07-29 14:30:02 -07001180 void add(rs_matrix4x4 m) {
1181 for (size_t i = 0; i < 16; i++) {
1182 add(m.m[i]);
1183 }
1184 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001185
Tim Murray89daad62013-07-29 14:30:02 -07001186 void add(rs_matrix3x3 m) {
1187 for (size_t i = 0; i < 9; i++) {
1188 add(m.m[i]);
1189 }
1190 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001191
Tim Murray89daad62013-07-29 14:30:02 -07001192 void add(rs_matrix2x2 m) {
1193 for (size_t i = 0; i < 4; i++) {
1194 add(m.m[i]);
1195 }
1196 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001197 */
1198
Tim Murray89daad62013-07-29 14:30:02 -07001199 void add(sp<BaseObj> obj) {
Stephen Hines43514cd2012-11-16 14:33:47 -08001200 if (obj != NULL) {
1201 add((uint32_t) (uintptr_t) obj->getID());
1202 } else {
1203 add((uint32_t) 0);
1204 }
1205 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001206};
1207
Tim Murray75e877d2013-09-11 14:45:20 -07001208/**
1209 * A Type describes the Element and dimensions used for an Allocation or a
1210 * parallel operation.
1211 *
1212 * A Type always includes an Element and an X dimension. A Type may be
1213 * multidimensional, up to three dimensions. A nonzero value in the Y or Z
1214 * dimensions indicates that the dimension is present. Note that a Type with
1215 * only a given X dimension and a Type with the same X dimension but Y = 1 are
1216 * not equivalent.
1217 *
1218 * A Type also supports inclusion of level of detail (LOD) or cube map
1219 * faces. LOD and cube map faces are booleans to indicate present or not
1220 * present.
1221 *
1222 * A Type also supports YUV format information to support an Allocation in a YUV
1223 * format. The YUV formats supported are YV12 and NV21.
1224 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001225class Type : public BaseObj {
1226protected:
1227 friend class Allocation;
1228
1229 uint32_t mDimX;
1230 uint32_t mDimY;
1231 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001232 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001233 bool mDimMipmaps;
1234 bool mDimFaces;
1235 size_t mElementCount;
1236 sp<const Element> mElement;
1237
Stephen Hines7d1b7572013-08-22 01:24:06 -07001238 Type(void *id, sp<RS> rs);
1239
Tim Murray84bf2b82012-10-31 16:03:16 -07001240 void calcElementCount();
1241 virtual void updateFromNative();
1242
1243public:
1244
Tim Murray75e877d2013-09-11 14:45:20 -07001245 /**
1246 * Returns the YUV format.
1247 * @return YUV format of the Allocation
1248 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001249 RSYuvFormat getYuvFormat() const {
1250 return mYuvFormat;
1251 }
1252
Tim Murray75e877d2013-09-11 14:45:20 -07001253 /**
1254 * Returns the Element of the Allocation.
1255 * @return YUV format of the Allocation
1256 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001257 sp<const Element> getElement() const {
1258 return mElement;
1259 }
1260
Tim Murray75e877d2013-09-11 14:45:20 -07001261 /**
1262 * Returns the X dimension of the Allocation.
1263 * @return X dimension of the allocation
1264 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001265 uint32_t getX() const {
1266 return mDimX;
1267 }
1268
Tim Murray75e877d2013-09-11 14:45:20 -07001269 /**
1270 * Returns the Y dimension of the Allocation.
1271 * @return Y dimension of the allocation
1272 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001273 uint32_t getY() const {
1274 return mDimY;
1275 }
1276
Tim Murray75e877d2013-09-11 14:45:20 -07001277 /**
1278 * Returns the Z dimension of the Allocation.
1279 * @return Z dimension of the allocation
1280 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001281 uint32_t getZ() const {
1282 return mDimZ;
1283 }
1284
Tim Murray75e877d2013-09-11 14:45:20 -07001285 /**
1286 * Returns true if the Allocation has mipmaps.
1287 * @return true if the Allocation has mipmaps
1288 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001289 bool hasMipmaps() const {
1290 return mDimMipmaps;
1291 }
1292
Tim Murray75e877d2013-09-11 14:45:20 -07001293 /**
1294 * Returns true if the Allocation is a cube map
1295 * @return true if the Allocation is a cube map
1296 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001297 bool hasFaces() const {
1298 return mDimFaces;
1299 }
1300
Tim Murray75e877d2013-09-11 14:45:20 -07001301 /**
1302 * Returns number of accessible Elements in the Allocation
1303 * @return number of accessible Elements in the Allocation
1304 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001305 size_t getCount() const {
1306 return mElementCount;
1307 }
1308
Tim Murray75e877d2013-09-11 14:45:20 -07001309 /**
1310 * Returns size in bytes of all Elements in the Allocation
1311 * @return size in bytes of all Elements in the Allocation
1312 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001313 size_t getSizeBytes() const {
1314 return mElementCount * mElement->getSizeBytes();
1315 }
1316
Tim Murray75e877d2013-09-11 14:45:20 -07001317 /**
1318 * Creates a new Type with the given Element and dimensions.
1319 * @param[in] rs RenderScript context
1320 * @param[in] e Element
1321 * @param[in] dimX X dimension
1322 * @param[in] dimY Y dimension
1323 * @param[in] dimZ Z dimension
1324 * @return new Type
1325 */
Tim Murray96267c22013-02-12 11:25:12 -08001326 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 -07001327
1328 class Builder {
1329 protected:
Tim Murray35609072013-12-03 11:36:03 -08001330 RS* mRS;
Tim Murray84bf2b82012-10-31 16:03:16 -07001331 uint32_t mDimX;
1332 uint32_t mDimY;
1333 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001334 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001335 bool mDimMipmaps;
1336 bool mDimFaces;
1337 sp<const Element> mElement;
1338
1339 public:
1340 Builder(sp<RS> rs, sp<const Element> e);
1341
1342 void setX(uint32_t value);
Stephen Hines7d1b7572013-08-22 01:24:06 -07001343 void setY(uint32_t value);
Tim Murrayeb4426d2013-08-27 15:30:16 -07001344 void setZ(uint32_t value);
1345 void setYuvFormat(RSYuvFormat format);
Tim Murray84bf2b82012-10-31 16:03:16 -07001346 void setMipmaps(bool value);
1347 void setFaces(bool value);
1348 sp<const Type> create();
1349 };
1350
1351};
1352
Tim Murray75e877d2013-09-11 14:45:20 -07001353/**
1354 * The parent class for all executable Scripts. This should not be used by applications.
1355 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001356class Script : public BaseObj {
1357private:
1358
1359protected:
1360 Script(void *id, sp<RS> rs);
1361 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
1362 const void *v, size_t) const;
1363 void bindAllocation(sp<Allocation> va, uint32_t slot) const;
1364 void setVar(uint32_t index, const void *, size_t len) const;
1365 void setVar(uint32_t index, sp<const BaseObj> o) const;
1366 void invoke(uint32_t slot, const void *v, size_t len) const;
1367
1368
1369 void invoke(uint32_t slot) const {
1370 invoke(slot, NULL, 0);
1371 }
1372 void setVar(uint32_t index, float v) const {
1373 setVar(index, &v, sizeof(v));
1374 }
1375 void setVar(uint32_t index, double v) const {
1376 setVar(index, &v, sizeof(v));
1377 }
1378 void setVar(uint32_t index, int32_t v) const {
1379 setVar(index, &v, sizeof(v));
1380 }
Jon Parrb05c8502015-03-13 14:41:58 +00001381 void setVar(uint32_t index, uint32_t v) const {
1382 setVar(index, &v, sizeof(v));
1383 }
Tim Murray84bf2b82012-10-31 16:03:16 -07001384 void setVar(uint32_t index, int64_t v) const {
1385 setVar(index, &v, sizeof(v));
1386 }
1387 void setVar(uint32_t index, bool v) const {
1388 setVar(index, &v, sizeof(v));
1389 }
1390
1391public:
1392 class FieldBase {
1393 protected:
1394 sp<const Element> mElement;
1395 sp<Allocation> mAllocation;
1396
1397 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
1398
1399 public:
1400 sp<const Element> getElement() {
1401 return mElement;
1402 }
1403
1404 sp<const Type> getType() {
1405 return mAllocation->getType();
1406 }
1407
1408 sp<const Allocation> getAllocation() {
1409 return mAllocation;
1410 }
1411
1412 //void updateAllocation();
1413 };
1414};
1415
Tim Murray75e877d2013-09-11 14:45:20 -07001416/**
1417 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only.
1418 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001419class ScriptC : public Script {
1420protected:
1421 ScriptC(sp<RS> rs,
1422 const void *codeTxt, size_t codeLength,
1423 const char *cachedName, size_t cachedNameLength,
1424 const char *cacheDir, size_t cacheDirLength);
1425
1426};
1427
Tim Murray75e877d2013-09-11 14:45:20 -07001428/**
1429 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of
1430 * basic functions. This is not intended to be used directly.
1431 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001432class ScriptIntrinsic : public Script {
1433 protected:
Tim Murray10913a52013-08-20 17:19:47 -07001434 sp<const Element> mElement;
Tim Murray3cd44af2012-11-14 11:25:27 -08001435 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001436 virtual ~ScriptIntrinsic();
Tim Murray7f0d5682012-11-08 16:35:24 -08001437};
1438
Tim Murray75e877d2013-09-11 14:45:20 -07001439/**
1440 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming
1441 * r,g,b values are use as normalized x,y,z coordinates into a 3D
1442 * allocation. The 8 nearest values are sampled and linearly interpolated. The
1443 * result is placed in the output.
1444 */
Tim Murray89daad62013-07-29 14:30:02 -07001445class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001446 private:
Tim Murray89daad62013-07-29 14:30:02 -07001447 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001448 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001449 /**
1450 * Supported Element types are U8_4. Default lookup table is identity.
1451 * @param[in] rs RenderScript context
1452 * @param[in] e Element
1453 * @return new ScriptIntrinsic
1454 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001455 static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001456
1457 /**
1458 * Launch the intrinsic.
1459 * @param[in] ain input Allocation
1460 * @param[in] aout output Allocation
1461 */
Tim Murray89daad62013-07-29 14:30:02 -07001462 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001463
1464 /**
1465 * Sets the lookup table. The lookup table must use the same Element as the
1466 * intrinsic.
1467 * @param[in] lut new lookup table
1468 */
Tim Murray89daad62013-07-29 14:30:02 -07001469 void setLUT(sp<Allocation> lut);
1470};
1471
Tim Murray75e877d2013-09-11 14:45:20 -07001472/**
1473 * Intrinsic kernel for blending two Allocations.
1474 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001475class ScriptIntrinsicBlend : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001476 private:
Tim Murray89daad62013-07-29 14:30:02 -07001477 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001478 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001479 /**
1480 * Supported Element types are U8_4.
1481 * @param[in] rs RenderScript context
1482 * @param[in] e Element
1483 * @return new ScriptIntrinsicBlend
1484 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001485 static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001486 /**
1487 * sets dst = {0, 0, 0, 0}
1488 * @param[in] in input Allocation
1489 * @param[in] out output Allocation
1490 */
1491 void forEachClear(sp<Allocation> in, sp<Allocation> out);
1492 /**
1493 * Sets dst = src
1494 * @param[in] in input Allocation
1495 * @param[in] out output Allocation
1496 */
1497 void forEachSrc(sp<Allocation> in, sp<Allocation> out);
1498 /**
1499 * Sets dst = dst (NOP)
1500 * @param[in] in input Allocation
1501 * @param[in] out output Allocation
1502 */
1503 void forEachDst(sp<Allocation> in, sp<Allocation> out);
1504 /**
1505 * Sets dst = src + dst * (1.0 - src.a)
1506 * @param[in] in input Allocation
1507 * @param[in] out output Allocation
1508 */
1509 void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
1510 /**
1511 * Sets dst = dst + src * (1.0 - dst.a)
1512 * @param[in] in input Allocation
1513 * @param[in] out output Allocation
1514 */
1515 void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
1516 /**
1517 * Sets dst = src * dst.a
1518 * @param[in] in input Allocation
1519 * @param[in] out output Allocation
1520 */
1521 void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
1522 /**
1523 * Sets dst = dst * src.a
1524 * @param[in] in input Allocation
1525 * @param[in] out output Allocation
1526 */
1527 void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
1528 /**
1529 * Sets dst = src * (1.0 - dst.a)
1530 * @param[in] in input Allocation
1531 * @param[in] out output Allocation
1532 */
1533 void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
1534 /**
1535 * Sets dst = dst * (1.0 - src.a)
1536 * @param[in] in input Allocation
1537 * @param[in] out output Allocation
1538 */
1539 void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
1540 /**
1541 * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
1542 * @param[in] in input Allocation
1543 * @param[in] out output Allocation
1544 */
1545 void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
1546 /**
1547 * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
1548 * @param[in] in input Allocation
1549 * @param[in] out output Allocation
1550 */
1551 void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
1552 /**
1553 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
1554 * @param[in] in input Allocation
1555 * @param[in] out output Allocation
1556 */
1557 void forEachXor(sp<Allocation> in, sp<Allocation> out);
1558 /**
1559 * Sets dst = src * dst
1560 * @param[in] in input Allocation
1561 * @param[in] out output Allocation
1562 */
1563 void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
1564 /**
1565 * Sets dst = min(src + dst, 1.0)
1566 * @param[in] in input Allocation
1567 * @param[in] out output Allocation
1568 */
1569 void forEachAdd(sp<Allocation> in, sp<Allocation> out);
1570 /**
1571 * Sets dst = max(dst - src, 0.0)
1572 * @param[in] in input Allocation
1573 * @param[in] out output Allocation
1574 */
1575 void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
Tim Murray7f0d5682012-11-08 16:35:24 -08001576};
Tim Murray84bf2b82012-10-31 16:03:16 -07001577
Tim Murray75e877d2013-09-11 14:45:20 -07001578/**
1579 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified
1580 * radius to all elements of an Allocation.
1581 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001582class ScriptIntrinsicBlur : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001583 private:
Tim Murray89daad62013-07-29 14:30:02 -07001584 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001585 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001586 /**
1587 * Supported Element types are U8 and U8_4.
1588 * @param[in] rs RenderScript context
1589 * @param[in] e Element
1590 * @return new ScriptIntrinsicBlur
1591 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001592 static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001593 /**
1594 * Sets the input of the blur.
1595 * @param[in] in input Allocation
1596 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001597 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001598 /**
1599 * Runs the intrinsic.
1600 * @param[in] output Allocation
1601 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001602 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001603 /**
1604 * Sets the radius of the blur. The supported range is 0 < radius <= 25.
1605 * @param[in] radius radius of the blur
1606 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001607 void setRadius(float radius);
1608};
1609
Tim Murray75e877d2013-09-11 14:45:20 -07001610/**
1611 * Intrinsic for applying a color matrix to allocations. This has the
1612 * same effect as loading each element and converting it to a
1613 * F32_N, multiplying the result by the 4x4 color matrix
1614 * as performed by rsMatrixMultiply() and writing it to the output
1615 * after conversion back to U8_N or F32_N.
1616 */
Tim Murray89daad62013-07-29 14:30:02 -07001617class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001618 private:
Tim Murray89daad62013-07-29 14:30:02 -07001619 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001620 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001621 /**
1622 * Creates a new intrinsic.
1623 * @param[in] rs RenderScript context
1624 * @return new ScriptIntrinsicColorMatrix
1625 */
Tim Murrayaae73c92013-09-03 17:05:46 -07001626 static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001627 /**
1628 * Applies the color matrix. Supported types are U8 and F32 with
1629 * vector lengths between 1 and 4.
1630 * @param[in] in input Allocation
1631 * @param[out] out output Allocation
1632 */
Tim Murray89daad62013-07-29 14:30:02 -07001633 void forEach(sp<Allocation> in, sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001634 /**
1635 * Set the value to be added after the color matrix has been
1636 * applied. The default value is {0, 0, 0, 0}.
1637 * @param[in] add float[4] of values
1638 */
Tim Murray10913a52013-08-20 17:19:47 -07001639 void setAdd(float* add);
Tim Murray75e877d2013-09-11 14:45:20 -07001640
1641 /**
1642 * Set the color matrix which will be applied to each cell of the
1643 * image. The alpha channel will be copied.
1644 *
1645 * @param[in] m float[9] of values
1646 */
Tim Murray89daad62013-07-29 14:30:02 -07001647 void setColorMatrix3(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001648 /**
1649 * Set the color matrix which will be applied to each cell of the
1650 * image.
1651 *
1652 * @param[in] m float[16] of values
1653 */
Tim Murray89daad62013-07-29 14:30:02 -07001654 void setColorMatrix4(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001655 /**
1656 * Set a color matrix to convert from RGB to luminance. The alpha
1657 * channel will be a copy.
1658 */
Tim Murray89daad62013-07-29 14:30:02 -07001659 void setGreyscale();
Tim Murray75e877d2013-09-11 14:45:20 -07001660 /**
1661 * Set the matrix to convert from RGB to YUV with a direct copy of
1662 * the 4th channel.
1663 */
Tim Murray89daad62013-07-29 14:30:02 -07001664 void setRGBtoYUV();
Tim Murray75e877d2013-09-11 14:45:20 -07001665 /**
1666 * Set the matrix to convert from YUV to RGB with a direct copy of
1667 * the 4th channel.
1668 */
Tim Murray89daad62013-07-29 14:30:02 -07001669 void setYUVtoRGB();
1670};
1671
Tim Murray75e877d2013-09-11 14:45:20 -07001672/**
1673 * Intrinsic for applying a 3x3 convolve to an allocation.
1674 */
Tim Murray89daad62013-07-29 14:30:02 -07001675class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001676 private:
Tim Murray89daad62013-07-29 14:30:02 -07001677 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001678 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001679 /**
1680 * Supported types U8 and F32 with vector lengths between 1 and
1681 * 4. The default convolution kernel is the identity.
1682 * @param[in] rs RenderScript context
1683 * @param[in] e Element
1684 * @return new ScriptIntrinsicConvolve3x3
1685 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001686 static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001687 /**
1688 * Sets input for intrinsic.
1689 * @param[in] in input Allocation
1690 */
Tim Murray89daad62013-07-29 14:30:02 -07001691 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001692 /**
1693 * Launches the intrinsic.
1694 * @param[in] out output Allocation
1695 */
Tim Murray89daad62013-07-29 14:30:02 -07001696 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001697 /**
1698 * Sets convolution kernel.
1699 * @param[in] v float[9] of values
1700 */
Tim Murray89daad62013-07-29 14:30:02 -07001701 void setCoefficients(float* v);
1702};
1703
Tim Murray75e877d2013-09-11 14:45:20 -07001704/**
1705 * Intrinsic for applying a 5x5 convolve to an allocation.
1706 */
Tim Murray89daad62013-07-29 14:30:02 -07001707class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001708 private:
Tim Murray89daad62013-07-29 14:30:02 -07001709 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001710 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001711 /**
1712 * Supported types U8 and F32 with vector lengths between 1 and
1713 * 4. The default convolution kernel is the identity.
1714 * @param[in] rs RenderScript context
1715 * @param[in] e Element
1716 * @return new ScriptIntrinsicConvolve5x5
1717 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001718 static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001719 /**
1720 * Sets input for intrinsic.
1721 * @param[in] in input Allocation
1722 */
Tim Murray89daad62013-07-29 14:30:02 -07001723 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001724 /**
1725 * Launches the intrinsic.
1726 * @param[in] out output Allocation
1727 */
Tim Murray89daad62013-07-29 14:30:02 -07001728 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001729 /**
1730 * Sets convolution kernel.
1731 * @param[in] v float[25] of values
1732 */
Tim Murray89daad62013-07-29 14:30:02 -07001733 void setCoefficients(float* v);
1734};
1735
Tim Murray75e877d2013-09-11 14:45:20 -07001736/**
1737 * Intrinsic for computing a histogram.
1738 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001739class ScriptIntrinsicHistogram : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001740 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001741 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
Tim Murray10913a52013-08-20 17:19:47 -07001742 sp<Allocation> mOut;
Tim Murray21fa7a02013-08-15 16:25:03 -07001743 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001744 /**
1745 * Create an intrinsic for calculating the histogram of an uchar
1746 * or uchar4 image.
1747 *
1748 * Supported elements types are U8_4, U8_3, U8_2, and U8.
1749 *
1750 * @param[in] rs The RenderScript context
1751 * @param[in] e Element type for inputs
1752 *
1753 * @return ScriptIntrinsicHistogram
1754 */
Jon Parrb05c8502015-03-13 14:41:58 +00001755 static sp<ScriptIntrinsicHistogram> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001756 /**
1757 * Set the output of the histogram. 32 bit integer types are
1758 * supported.
1759 *
1760 * @param[in] aout The output allocation
1761 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001762 void setOutput(sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001763 /**
1764 * Set the coefficients used for the dot product calculation. The
1765 * default is {0.299f, 0.587f, 0.114f, 0.f}.
1766 *
1767 * Coefficients must be >= 0 and sum to 1.0 or less.
1768 *
1769 * @param[in] r Red coefficient
1770 * @param[in] g Green coefficient
1771 * @param[in] b Blue coefficient
1772 * @param[in] a Alpha coefficient
1773 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001774 void setDotCoefficients(float r, float g, float b, float a);
Tim Murray75e877d2013-09-11 14:45:20 -07001775 /**
1776 * Process an input buffer and place the histogram into the output
1777 * allocation. The output allocation may be a narrower vector size
1778 * than the input. In this case the vector size of the output is
1779 * used to determine how many of the input channels are used in
1780 * the computation. This is useful if you have an RGBA input
1781 * buffer but only want the histogram for RGB.
1782 *
1783 * 1D and 2D input allocations are supported.
1784 *
1785 * @param[in] ain The input image
1786 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001787 void forEach(sp<Allocation> ain);
Tim Murray75e877d2013-09-11 14:45:20 -07001788 /**
1789 * Process an input buffer and place the histogram into the output
1790 * allocation. The dot product of the input channel and the
1791 * coefficients from 'setDotCoefficients' are used to calculate
1792 * the output values.
1793 *
1794 * 1D and 2D input allocations are supported.
1795 *
1796 * @param ain The input image
1797 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001798 void forEach_dot(sp<Allocation> ain);
1799};
1800
Tim Murray75e877d2013-09-11 14:45:20 -07001801/**
1802 * Intrinsic for applying a per-channel lookup table. Each channel of
1803 * the input has an independant lookup table. The tables are 256
1804 * entries in size and can cover the full value range of U8_4.
1805 **/
Tim Murrayb27b1812013-08-05 14:00:40 -07001806class ScriptIntrinsicLUT : public ScriptIntrinsic {
1807 private:
1808 sp<Allocation> LUT;
1809 bool mDirty;
1810 unsigned char mCache[1024];
Tim Murray2acce992013-08-28 14:23:31 -07001811 void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray21fa7a02013-08-15 16:25:03 -07001812 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001813
Tim Murray89daad62013-07-29 14:30:02 -07001814 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001815 /**
1816 * Supported elements types are U8_4.
1817 *
1818 * The defaults tables are identity.
1819 *
1820 * @param[in] rs The RenderScript context
1821 * @param[in] e Element type for intputs and outputs
1822 *
1823 * @return ScriptIntrinsicLUT
1824 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001825 static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001826 /**
1827 * Invoke the kernel and apply the lookup to each cell of ain and
1828 * copy to aout.
1829 *
1830 * @param[in] ain Input allocation
1831 * @param[in] aout Output allocation
1832 */
Tim Murray89daad62013-07-29 14:30:02 -07001833 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001834 /**
1835 * Sets entries in LUT for the red channel.
1836 * @param[in] base base of region to update
1837 * @param[in] length length of region to update
1838 * @param[in] lutValues LUT values to use
1839 */
Tim Murray2acce992013-08-28 14:23:31 -07001840 void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001841 /**
1842 * Sets entries in LUT for the green channel.
1843 * @param[in] base base of region to update
1844 * @param[in] length length of region to update
1845 * @param[in] lutValues LUT values to use
1846 */
Tim Murray2acce992013-08-28 14:23:31 -07001847 void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001848 /**
1849 * Sets entries in LUT for the blue channel.
1850 * @param[in] base base of region to update
1851 * @param[in] length length of region to update
1852 * @param[in] lutValues LUT values to use
1853 */
Tim Murray2acce992013-08-28 14:23:31 -07001854 void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001855 /**
1856 * Sets entries in LUT for the alpha channel.
1857 * @param[in] base base of region to update
1858 * @param[in] length length of region to update
1859 * @param[in] lutValues LUT values to use
1860 */
Tim Murray2acce992013-08-28 14:23:31 -07001861 void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murrayb27b1812013-08-05 14:00:40 -07001862 virtual ~ScriptIntrinsicLUT();
1863};
1864
Tim Murray75e877d2013-09-11 14:45:20 -07001865/**
Miao Wange5428e62015-03-10 15:29:40 -07001866 * Intrinsic for performing a resize of a 2D allocation.
1867 */
1868class ScriptIntrinsicResize : public ScriptIntrinsic {
1869 private:
1870 sp<Allocation> mInput;
1871 ScriptIntrinsicResize(sp<RS> rs, sp<const Element> e);
1872 public:
1873 /**
1874 * Supported Element types are U8_4. Default lookup table is identity.
1875 * @param[in] rs RenderScript context
1876 * @param[in] e Element
1877 * @return new ScriptIntrinsic
1878 */
1879 static sp<ScriptIntrinsicResize> create(sp<RS> rs);
1880
1881 /**
1882 * Resize copy the input allocation to the output specified. The
1883 * Allocation is rescaled if necessary using bi-cubic
1884 * interpolation.
1885 * @param[in] ain input Allocation
1886 * @param[in] aout output Allocation
1887 */
1888 void forEach_bicubic(sp<Allocation> aout);
1889
1890 /**
1891 * Set the input of the resize.
1892 * @param[in] lut new lookup table
1893 */
1894 void setInput(sp<Allocation> ain);
1895};
1896
1897/**
Tim Murray75e877d2013-09-11 14:45:20 -07001898 * Intrinsic for converting an Android YUV buffer to RGB.
1899 *
1900 * The input allocation should be supplied in a supported YUV format
1901 * as a YUV element Allocation. The output is RGBA; the alpha channel
1902 * will be set to 255.
1903 */
Tim Murray89daad62013-07-29 14:30:02 -07001904class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001905 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001906 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001907 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001908 /**
1909 * Create an intrinsic for converting YUV to RGB.
1910 *
1911 * Supported elements types are U8_4.
1912 *
1913 * @param[in] rs The RenderScript context
1914 * @param[in] e Element type for output
1915 *
1916 * @return ScriptIntrinsicYuvToRGB
1917 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001918 static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001919 /**
1920 * Set the input YUV allocation.
1921 *
1922 * @param[in] ain The input allocation.
1923 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001924 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001925
1926 /**
1927 * Convert the image to RGB.
1928 *
1929 * @param[in] aout Output allocation. Must match creation element
1930 * type.
1931 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001932 void forEach(sp<Allocation> out);
Tim Murray89daad62013-07-29 14:30:02 -07001933
1934};
Tim Murrayb27b1812013-08-05 14:00:40 -07001935
Tim Murray75e877d2013-09-11 14:45:20 -07001936/**
1937 * Sampler object that defines how Allocations can be read as textures
1938 * within a kernel. Samplers are used in conjunction with the rsSample
1939 * runtime function to return values from normalized coordinates.
1940 *
1941 * Any Allocation used with a Sampler must have been created with
1942 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an
1943 * Allocation that was not created with
1944 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined.
1945 **/
Tim Murray729b6fe2013-07-23 16:20:42 -07001946 class Sampler : public BaseObj {
1947 private:
1948 Sampler(sp<RS> rs, void* id);
Miao Wange5428e62015-03-10 15:29:40 -07001949 Sampler(sp<RS> rs, void* id, RsSamplerValue min, RsSamplerValue mag,
1950 RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
Tim Murray729b6fe2013-07-23 16:20:42 -07001951 RsSamplerValue mMin;
1952 RsSamplerValue mMag;
1953 RsSamplerValue mWrapS;
1954 RsSamplerValue mWrapT;
Tim Murray729b6fe2013-07-23 16:20:42 -07001955 float mAniso;
1956
1957 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001958 /**
1959 * Creates a non-standard Sampler.
1960 * @param[in] rs RenderScript context
1961 * @param[in] min minification
1962 * @param[in] mag magnification
1963 * @param[in] wrapS S wrapping mode
1964 * @param[in] wrapT T wrapping mode
1965 * @param[in] anisotropy anisotropy setting
1966 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001967 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
1968
Tim Murray75e877d2013-09-11 14:45:20 -07001969 /**
1970 * @return minification setting for the sampler
1971 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001972 RsSamplerValue getMinification();
Tim Murray75e877d2013-09-11 14:45:20 -07001973 /**
1974 * @return magnification setting for the sampler
1975 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001976 RsSamplerValue getMagnification();
Tim Murray75e877d2013-09-11 14:45:20 -07001977 /**
1978 * @return S wrapping mode for the sampler
1979 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001980 RsSamplerValue getWrapS();
Tim Murray75e877d2013-09-11 14:45:20 -07001981 /**
1982 * @return T wrapping mode for the sampler
1983 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001984 RsSamplerValue getWrapT();
Tim Murray75e877d2013-09-11 14:45:20 -07001985 /**
1986 * @return anisotropy setting for the sampler
1987 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001988 float getAnisotropy();
1989
Tim Murray75e877d2013-09-11 14:45:20 -07001990 /**
1991 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1992 * clamp.
1993 *
1994 * @param rs Context to which the sampler will belong.
1995 *
1996 * @return Sampler
1997 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001998 static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001999 /**
2000 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2001 * clamp.
2002 *
2003 * @param rs Context to which the sampler will belong.
2004 *
2005 * @return Sampler
2006 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002007 static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002008 /**
2009 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2010 * wrap modes set to clamp.
2011 *
2012 * @param rs Context to which the sampler will belong.
2013 *
2014 * @return Sampler
2015 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002016 static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002017 /**
2018 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2019 * wrap.
2020 *
2021 * @param rs Context to which the sampler will belong.
2022 *
2023 * @return Sampler
2024 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002025 static sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002026 /**
2027 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2028 * wrap.
2029 *
2030 * @param rs Context to which the sampler will belong.
2031 *
2032 * @return Sampler
2033 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002034 static sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002035 /**
2036 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2037 * wrap modes set to wrap.
2038 *
2039 * @param rs Context to which the sampler will belong.
2040 *
2041 * @return Sampler
2042 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002043 static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002044 /**
2045 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2046 * mirrored repeat.
2047 *
2048 * @param rs Context to which the sampler will belong.
2049 *
2050 * @return Sampler
2051 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002052 static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002053 /**
2054 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2055 * mirrored repeat.
2056 *
2057 * @param rs Context to which the sampler will belong.
2058 *
2059 * @return Sampler
2060 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002061 static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07002062 /**
2063 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2064 * mirrored repeat.
2065 *
2066 * @param rs Context to which the sampler will belong.
2067 *
2068 * @return Sampler
2069 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002070 static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray729b6fe2013-07-23 16:20:42 -07002071
2072};
2073
Stephen Hinesd10412f2013-08-29 18:27:21 -07002074class Byte2 {
2075 public:
2076 int8_t x, y;
2077
2078 Byte2(int8_t initX, int8_t initY)
2079 : x(initX), y(initY) {}
2080 Byte2() : x(0), y(0) {}
2081};
2082
2083class Byte3 {
2084 public:
2085 int8_t x, y, z;
2086
2087 Byte3(int8_t initX, int8_t initY, int8_t initZ)
2088 : x(initX), y(initY), z(initZ) {}
2089 Byte3() : x(0), y(0), z(0) {}
2090};
2091
2092class Byte4 {
2093 public:
2094 int8_t x, y, z, w;
2095
2096 Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
2097 : x(initX), y(initY), z(initZ), w(initW) {}
2098 Byte4() : x(0), y(0), z(0), w(0) {}
2099};
2100
2101class UByte2 {
2102 public:
2103 uint8_t x, y;
2104
2105 UByte2(uint8_t initX, uint8_t initY)
2106 : x(initX), y(initY) {}
2107 UByte2() : x(0), y(0) {}
2108};
2109
2110class UByte3 {
2111 public:
2112 uint8_t x, y, z;
2113
2114 UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
2115 : x(initX), y(initY), z(initZ) {}
2116 UByte3() : x(0), y(0), z(0) {}
2117};
2118
2119class UByte4 {
2120 public:
2121 uint8_t x, y, z, w;
2122
2123 UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
2124 : x(initX), y(initY), z(initZ), w(initW) {}
2125 UByte4() : x(0), y(0), z(0), w(0) {}
2126};
2127
2128class Short2 {
2129 public:
2130 short x, y;
2131
2132 Short2(short initX, short initY)
2133 : x(initX), y(initY) {}
2134 Short2() : x(0), y(0) {}
2135};
2136
2137class Short3 {
2138 public:
2139 short x, y, z;
2140
2141 Short3(short initX, short initY, short initZ)
2142 : x(initX), y(initY), z(initZ) {}
2143 Short3() : x(0), y(0), z(0) {}
2144};
2145
2146class Short4 {
2147 public:
2148 short x, y, z, w;
2149
2150 Short4(short initX, short initY, short initZ, short initW)
2151 : x(initX), y(initY), z(initZ), w(initW) {}
2152 Short4() : x(0), y(0), z(0), w(0) {}
2153};
2154
2155class UShort2 {
2156 public:
2157 uint16_t x, y;
2158
2159 UShort2(uint16_t initX, uint16_t initY)
2160 : x(initX), y(initY) {}
2161 UShort2() : x(0), y(0) {}
2162};
2163
2164class UShort3 {
2165 public:
2166 uint16_t x, y, z;
2167
2168 UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
2169 : x(initX), y(initY), z(initZ) {}
2170 UShort3() : x(0), y(0), z(0) {}
2171};
2172
2173class UShort4 {
2174 public:
2175 uint16_t x, y, z, w;
2176
2177 UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
2178 : x(initX), y(initY), z(initZ), w(initW) {}
2179 UShort4() : x(0), y(0), z(0), w(0) {}
2180};
2181
2182class Int2 {
2183 public:
2184 int x, y;
2185
2186 Int2(int initX, int initY)
2187 : x(initX), y(initY) {}
2188 Int2() : x(0), y(0) {}
2189};
2190
2191class Int3 {
2192 public:
2193 int x, y, z;
2194
2195 Int3(int initX, int initY, int initZ)
2196 : x(initX), y(initY), z(initZ) {}
2197 Int3() : x(0), y(0), z(0) {}
2198};
2199
2200class Int4 {
2201 public:
2202 int x, y, z, w;
2203
2204 Int4(int initX, int initY, int initZ, int initW)
2205 : x(initX), y(initY), z(initZ), w(initW) {}
2206 Int4() : x(0), y(0), z(0), w(0) {}
2207};
2208
2209class UInt2 {
2210 public:
2211 uint32_t x, y;
2212
2213 UInt2(uint32_t initX, uint32_t initY)
2214 : x(initX), y(initY) {}
2215 UInt2() : x(0), y(0) {}
2216};
2217
2218class UInt3 {
2219 public:
2220 uint32_t x, y, z;
2221
2222 UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
2223 : x(initX), y(initY), z(initZ) {}
2224 UInt3() : x(0), y(0), z(0) {}
2225};
2226
2227class UInt4 {
2228 public:
2229 uint32_t x, y, z, w;
2230
2231 UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
2232 : x(initX), y(initY), z(initZ), w(initW) {}
2233 UInt4() : x(0), y(0), z(0), w(0) {}
2234};
2235
2236class Long2 {
2237 public:
2238 int64_t x, y;
2239
2240 Long2(int64_t initX, int64_t initY)
2241 : x(initX), y(initY) {}
2242 Long2() : x(0), y(0) {}
2243};
2244
2245class Long3 {
2246 public:
2247 int64_t x, y, z;
2248
2249 Long3(int64_t initX, int64_t initY, int64_t initZ)
2250 : x(initX), y(initY), z(initZ) {}
2251 Long3() : x(0), y(0), z(0) {}
2252};
2253
2254class Long4 {
2255 public:
2256 int64_t x, y, z, w;
2257
2258 Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
2259 : x(initX), y(initY), z(initZ), w(initW) {}
2260 Long4() : x(0), y(0), z(0), w(0) {}
2261};
2262
2263class ULong2 {
2264 public:
2265 uint64_t x, y;
2266
2267 ULong2(uint64_t initX, uint64_t initY)
2268 : x(initX), y(initY) {}
2269 ULong2() : x(0), y(0) {}
2270};
2271
2272class ULong3 {
2273 public:
2274 uint64_t x, y, z;
2275
2276 ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
2277 : x(initX), y(initY), z(initZ) {}
2278 ULong3() : x(0), y(0), z(0) {}
2279};
2280
2281class ULong4 {
2282 public:
2283 uint64_t x, y, z, w;
2284
2285 ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
2286 : x(initX), y(initY), z(initZ), w(initW) {}
2287 ULong4() : x(0), y(0), z(0), w(0) {}
2288};
2289
2290class Float2 {
2291 public:
2292 float x, y;
2293
2294 Float2(float initX, float initY)
2295 : x(initX), y(initY) {}
2296 Float2() : x(0), y(0) {}
2297};
2298
2299class Float3 {
2300 public:
2301 float x, y, z;
2302
2303 Float3(float initX, float initY, float initZ)
2304 : x(initX), y(initY), z(initZ) {}
2305 Float3() : x(0.f), y(0.f), z(0.f) {}
2306};
2307
2308class Float4 {
2309 public:
2310 float x, y, z, w;
2311
2312 Float4(float initX, float initY, float initZ, float initW)
2313 : x(initX), y(initY), z(initZ), w(initW) {}
2314 Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
2315};
2316
2317class Double2 {
2318 public:
2319 double x, y;
2320
2321 Double2(double initX, double initY)
2322 : x(initX), y(initY) {}
2323 Double2() : x(0), y(0) {}
2324};
2325
2326class Double3 {
2327 public:
2328 double x, y, z;
2329
2330 Double3(double initX, double initY, double initZ)
2331 : x(initX), y(initY), z(initZ) {}
2332 Double3() : x(0), y(0), z(0) {}
2333};
2334
2335class Double4 {
2336 public:
2337 double x, y, z, w;
2338
2339 Double4(double initX, double initY, double initZ, double initW)
2340 : x(initX), y(initY), z(initZ), w(initW) {}
2341 Double4() : x(0), y(0), z(0), w(0) {}
2342};
2343
Tim Murray84bf2b82012-10-31 16:03:16 -07002344}
Tim Murray7f0d5682012-11-08 16:35:24 -08002345
Tim Murray84bf2b82012-10-31 16:03:16 -07002346}
2347
2348#endif