blob: 26e195453a287f3f61c8fe338d783d4971a4db32 [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;
308 uint32_t mSelectedY;
309 uint32_t mSelectedZ;
310 uint32_t mSelectedLOD;
311 RsAllocationCubemapFace mSelectedFace;
312
313 uint32_t mCurrentDimX;
314 uint32_t mCurrentDimY;
315 uint32_t mCurrentDimZ;
316 uint32_t mCurrentCount;
317
318 void * getIDSafe() const;
319 void updateCacheInfo(sp<const Type> t);
320
321 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
322
323 void validateIsInt32();
324 void validateIsInt16();
325 void validateIsInt8();
326 void validateIsFloat32();
327 void validateIsObject();
328
329 virtual void updateFromNative();
330
331 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
Tim Murray9d24ae62013-08-30 12:17:14 -0700332 void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff,
333 uint32_t w, uint32_t h, uint32_t d);
Tim Murray84bf2b82012-10-31 16:03:16 -0700334
335public:
Tim Murray75e877d2013-09-11 14:45:20 -0700336
337 /**
338 * Return Type for the allocation.
339 * @return pointer to underlying Type
340 */
Stephen Hinesa180b7d2013-08-21 12:42:13 -0700341 sp<const Type> getType() const {
Tim Murray84bf2b82012-10-31 16:03:16 -0700342 return mType;
343 }
344
Tim Murray75e877d2013-09-11 14:45:20 -0700345 /**
346 * Propagate changes from one usage of the Allocation to other usages of the Allocation.
347 * @param[in] srcLocation source location with changes to propagate elsewhere
348 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700349 void syncAll(RsAllocationUsageType srcLocation);
350 void ioSendOutput();
351 void ioGetInput();
352
Tim Murray75e877d2013-09-11 14:45:20 -0700353 /**
354 * Generate a mipmap chain. This is only valid if the Type of the Allocation
355 * includes mipmaps. This function will generate a complete set of mipmaps
356 * from the top level LOD and place them into the script memory space. If
357 * the Allocation is also using other memory spaces, a call to
358 * syncAll(Allocation.USAGE_SCRIPT) is required.
359 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700360 void generateMipmaps();
Tim Murray509ea5c2012-11-13 11:56:40 -0800361
Tim Murray75e877d2013-09-11 14:45:20 -0700362 /**
363 * Copy an array into part of this Allocation.
364 * @param[in] off offset of first Element to be overwritten
365 * @param[in] count number of Elements to copy
366 * @param[in] data array from which to copy
367 */
Tim Murray0b93e302012-11-15 14:56:54 -0800368 void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
Tim Murray75e877d2013-09-11 14:45:20 -0700369
370 /**
371 * Copy part of an Allocation into part of this Allocation.
372 * @param[in] off offset of first Element to be overwritten
373 * @param[in] count number of Elements to copy
374 * @param[in] data Allocation from which to copy
375 * @param[in] dataOff offset of first Element in data to copy
376 */
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800377 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700378
Tim Murray75e877d2013-09-11 14:45:20 -0700379 /**
380 * Copy an array into part of this Allocation.
381 * @param[in] off offset of first Element to be overwritten
382 * @param[in] count number of Elements to copy
383 * @param[in] data array from which to copy
384 */
Tim Murray0b93e302012-11-15 14:56:54 -0800385 void copy1DRangeTo(uint32_t off, size_t count, void *data);
386
Tim Murray75e877d2013-09-11 14:45:20 -0700387 /**
388 * Copy entire array to an Allocation.
389 * @param[in] data array from which to copy
390 */
Tim Murray0b93e302012-11-15 14:56:54 -0800391 void copy1DFrom(const void* data);
Tim Murray75e877d2013-09-11 14:45:20 -0700392
393 /**
394 * Copy entire Allocation to an array.
395 * @param[in] data destination array
396 */
Tim Murray0b93e302012-11-15 14:56:54 -0800397 void copy1DTo(void* data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800398
Tim Murray75e877d2013-09-11 14:45:20 -0700399 /**
400 * Copy from an array into a rectangular region in this Allocation. The
401 * array is assumed to be tightly packed.
402 * @param[in] xoff X offset of region to update in this Allocation
403 * @param[in] yoff Y offset of region to update in this Allocation
404 * @param[in] w Width of region to update
405 * @param[in] h Height of region to update
406 * @param[in] data Array from which to copy
407 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700408 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800409 const void *data);
Tim Murray7b3e3092012-11-16 13:32:24 -0800410
Tim Murray75e877d2013-09-11 14:45:20 -0700411 /**
412 * Copy from this Allocation into a rectangular region in an array. The
413 * array is assumed to be tightly packed.
414 * @param[in] xoff X offset of region to copy from this Allocation
415 * @param[in] yoff Y offset of region to copy from this Allocation
416 * @param[in] w Width of region to update
417 * @param[in] h Height of region to update
418 * @param[in] data destination array
419 */
Tim Murray7b3e3092012-11-16 13:32:24 -0800420 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
421 void *data);
422
Tim Murray75e877d2013-09-11 14:45:20 -0700423 /**
424 * Copy from an Allocation into a rectangular region in this Allocation.
425 * @param[in] xoff X offset of region to update in this Allocation
426 * @param[in] yoff Y offset of region to update in this Allocation
427 * @param[in] w Width of region to update
428 * @param[in] h Height of region to update
429 * @param[in] data Allocation from which to copy
430 * @param[in] dataXoff X offset of region to copy from in data
431 * @param[in] dataYoff Y offset of region to copy from in data
432 */
Tim Murray0b93e302012-11-15 14:56:54 -0800433 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
434 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700435
Tim Murray75e877d2013-09-11 14:45:20 -0700436 /**
437 * Copy from a strided array 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 array from which to copy
443 * @param[in] stride stride of data in bytes
444 */
Tim Murray358747a2012-11-26 13:52:04 -0800445 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
446 const void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700447
448 /**
449 * Copy from a strided array into this Allocation.
450 * @param[in] data array from which to copy
451 * @param[in] stride stride of data in bytes
452 */
Tim Murray358747a2012-11-26 13:52:04 -0800453 void copy2DStridedFrom(const void *data, size_t stride);
454
Tim Murray75e877d2013-09-11 14:45:20 -0700455 /**
456 * Copy from a rectangular region in this Allocation into a strided array.
457 * @param[in] xoff X offset of region to update in this Allocation
458 * @param[in] yoff Y offset of region to update in this Allocation
459 * @param[in] w Width of region to update
460 * @param[in] h Height of region to update
461 * @param[in] data destination array
462 * @param[in] stride stride of data in bytes
463 */
Tim Murray358747a2012-11-26 13:52:04 -0800464 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
465 void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700466
467 /**
468 * Copy this Allocation into a strided array.
469 * @param[in] data destination array
470 * @param[in] stride stride of data in bytes
471 */
Tim Murray358747a2012-11-26 13:52:04 -0800472 void copy2DStridedTo(void *data, size_t stride);
473
Tim Murray75e877d2013-09-11 14:45:20 -0700474
475 /**
476 * Copy from an array into a 3D region in this Allocation. The
477 * array is assumed to be tightly packed.
478 * @param[in] xoff X offset of region to update in this Allocation
479 * @param[in] yoff Y offset of region to update in this Allocation
480 * @param[in] zoff Z offset of region to update in this Allocation
481 * @param[in] w Width of region to update
482 * @param[in] h Height of region to update
483 * @param[in] d Depth of region to update
484 * @param[in] data Array from which to copy
485 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700486 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
487 uint32_t h, uint32_t d, const void* data);
488
Tim Murray75e877d2013-09-11 14:45:20 -0700489 /**
490 * Copy from an Allocation into a 3D region in this Allocation.
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 Allocation from which to copy
498 * @param[in] dataXoff X offset of region in data to copy from
499 * @param[in] dataYoff Y offset of region in data to copy from
500 * @param[in] dataZoff Z offset of region in data to copy from
501 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700502 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
503 uint32_t w, uint32_t h, uint32_t d,
504 sp<const Allocation> data,
505 uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700506
Tim Murray75e877d2013-09-11 14:45:20 -0700507 /**
508 * Creates an Allocation for use by scripts with a given Type.
509 * @param[in] rs Context to which the Allocation will belong
510 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800511 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700512 * @param[in] usage usage for the Allocation
513 * @return new Allocation
514 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700515 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800516 RsAllocationMipmapControl mipmaps, uint32_t usage);
Tim Murray75e877d2013-09-11 14:45:20 -0700517
518 /**
519 * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use
520 * with RS_ALLOCATION_USAGE_SHARED.
521 * @param[in] rs Context to which the Allocation will belong
522 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800523 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700524 * @param[in] usage usage for the Allocation
525 * @param[in] pointer existing backing store to use for this Allocation if possible
526 * @return new Allocation
527 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700528 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800529 RsAllocationMipmapControl mipmaps, uint32_t usage, void * pointer);
Tim Murray84bf2b82012-10-31 16:03:16 -0700530
Tim Murray75e877d2013-09-11 14:45:20 -0700531 /**
532 * Creates an Allocation for use by scripts with a given Type with no mipmaps.
533 * @param[in] rs Context to which the Allocation will belong
534 * @param[in] type Type of the Allocation
535 * @param[in] usage usage for the Allocation
536 * @return new Allocation
537 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700538 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
539 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700540 /**
541 * Creates an Allocation with a specified number of given elements.
542 * @param[in] rs Context to which the Allocation will belong
543 * @param[in] e Element used in the Allocation
544 * @param[in] count Number of elements of the Allocation
545 * @param[in] usage usage for the Allocation
546 * @return new Allocation
547 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700548 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
549 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700550
551 /**
552 * Creates a 2D Allocation with a specified number of given elements.
553 * @param[in] rs Context to which the Allocation will belong
554 * @param[in] e Element used in the Allocation
555 * @param[in] x Width in Elements of the Allocation
556 * @param[in] y Height of the Allocation
557 * @param[in] usage usage for the Allocation
558 * @return new Allocation
559 */
Tim Murray684726c2012-11-14 11:57:42 -0800560 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
561 size_t x, size_t y,
562 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
563
Tim Murray84bf2b82012-10-31 16:03:16 -0700564
Jason Samsb8a94e22014-02-24 17:52:32 -0800565 /**
566 * Get the backing pointer for a USAGE_SHARED allocation.
567 * @param[in] stride optional parameter. when non-NULL, will contain
568 * stride in bytes of a 2D Allocation
569 * @return pointer to data
570 */
571 void * getPointer(size_t *stride = NULL);
Tim Murray84bf2b82012-10-31 16:03:16 -0700572};
573
Tim Murray75e877d2013-09-11 14:45:20 -0700574 /**
575 * An Element represents one item within an Allocation. An Element is roughly
576 * equivalent to a C type in a RenderScript kernel. Elements may be basic
577 * or complex. Some basic elements are:
578
579 * - A single float value (equivalent to a float in a kernel)
580 * - A four-element float vector (equivalent to a float4 in a kernel)
581 * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel)
582 * - A single signed 8-bit integer (equivalent to a char in a kernel)
583
584 * Basic Elements are comprised of a Element.DataType and a
585 * Element.DataKind. The DataType encodes C type information of an Element,
586 * while the DataKind encodes how that Element should be interpreted by a
587 * Sampler. Note that Allocation objects with DataKind USER cannot be used as
588 * input for a Sampler. In general, Allocation objects that are intended for
589 * use with a Sampler should use bitmap-derived Elements such as
590 * Element::RGBA_8888.
591 */
592
593
Tim Murray84bf2b82012-10-31 16:03:16 -0700594class Element : public BaseObj {
595public:
596 bool isComplex();
Tim Murray75e877d2013-09-11 14:45:20 -0700597
598 /**
599 * Elements could be simple, such as an int or a float, or a structure with
600 * multiple sub-elements, such as a collection of floats, float2,
601 * float4. This function returns zero for simple elements or the number of
602 * sub-elements otherwise.
603 * @return number of sub-elements
604 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700605 size_t getSubElementCount() {
606 return mVisibleElementMap.size();
607 }
608
Tim Murray75e877d2013-09-11 14:45:20 -0700609 /**
610 * For complex Elements, this returns the sub-element at a given index.
611 * @param[in] index index of sub-element
612 * @return sub-element
613 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700614 sp<const Element> getSubElement(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700615
616 /**
617 * For complex Elements, this returns the name of the sub-element at a given
618 * index.
619 * @param[in] index index of sub-element
620 * @return name of sub-element
621 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700622 const char * getSubElementName(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700623
624 /**
625 * For complex Elements, this returns the size of the sub-element at a given
626 * index.
627 * @param[in] index index of sub-element
628 * @return size of sub-element
629 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700630 size_t getSubElementArraySize(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700631
632 /**
633 * Returns the location of a sub-element within a complex Element.
634 * @param[in] index index of sub-element
635 * @return offset in bytes
636 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700637 uint32_t getSubElementOffsetBytes(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700638
639 /**
640 * Returns the data type used for the Element.
641 * @return data type
642 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700643 RsDataType getDataType() const {
644 return mType;
645 }
646
Tim Murray75e877d2013-09-11 14:45:20 -0700647 /**
648 * Returns the data kind used for the Element.
649 * @return data kind
650 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700651 RsDataKind getDataKind() const {
652 return mKind;
653 }
654
Tim Murray75e877d2013-09-11 14:45:20 -0700655 /**
656 * Returns the size in bytes of the Element.
657 * @return size in bytes
658 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700659 size_t getSizeBytes() const {
660 return mSizeBytes;
661 }
662
Tim Murray75e877d2013-09-11 14:45:20 -0700663 /**
664 * Returns the number of vector components for this Element.
665 * @return number of vector components
666 */
Tim Murray10913a52013-08-20 17:19:47 -0700667 uint32_t getVectorSize() const {
668 return mVectorSize;
669 }
670
Tim Murray75e877d2013-09-11 14:45:20 -0700671 /**
672 * Utility function for returning an Element containing a single bool.
673 * @param[in] rs RenderScript context
674 * @return Element
675 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700676 static sp<const Element> BOOLEAN(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700677 /**
678 * Utility function for returning an Element containing a single unsigned char.
679 * @param[in] rs RenderScript context
680 * @return Element
681 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700682 static sp<const Element> U8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700683 /**
684 * Utility function for returning an Element containing a single signed char.
685 * @param[in] rs RenderScript context
686 * @return Element
687 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700688 static sp<const Element> I8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700689 /**
690 * Utility function for returning an Element containing a single unsigned short.
691 * @param[in] rs RenderScript context
692 * @return Element
693 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700694 static sp<const Element> U16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700695 /**
696 * Utility function for returning an Element containing a single signed short.
697 * @param[in] rs RenderScript context
698 * @return Element
699 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700700 static sp<const Element> I16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700701 /**
702 * Utility function for returning an Element containing a single unsigned int.
703 * @param[in] rs RenderScript context
704 * @return Element
705 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700706 static sp<const Element> U32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700707 /**
708 * Utility function for returning an Element containing a single signed int.
709 * @param[in] rs RenderScript context
710 * @return Element
711 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700712 static sp<const Element> I32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700713 /**
714 * Utility function for returning an Element containing a single unsigned long long.
715 * @param[in] rs RenderScript context
716 * @return Element
717 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700718 static sp<const Element> U64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700719 /**
720 * Utility function for returning an Element containing a single signed long long.
721 * @param[in] rs RenderScript context
722 * @return Element
723 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700724 static sp<const Element> I64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700725 /**
726 * Utility function for returning an Element containing a single float.
727 * @param[in] rs RenderScript context
728 * @return Element
729 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700730 static sp<const Element> F32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700731 /**
732 * Utility function for returning an Element containing a single double.
733 * @param[in] rs RenderScript context
734 * @return Element
735 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700736 static sp<const Element> F64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700737 /**
738 * Utility function for returning an Element containing a single Element.
739 * @param[in] rs RenderScript context
740 * @return Element
741 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700742 static sp<const Element> ELEMENT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700743 /**
744 * Utility function for returning an Element containing a single Type.
745 * @param[in] rs RenderScript context
746 * @return Element
747 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700748 static sp<const Element> TYPE(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700749 /**
750 * Utility function for returning an Element containing a single Allocation.
751 * @param[in] rs RenderScript context
752 * @return Element
753 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700754 static sp<const Element> ALLOCATION(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700755 /**
756 * Utility function for returning an Element containing a single Sampler.
757 * @param[in] rs RenderScript context
758 * @return Element
759 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700760 static sp<const Element> SAMPLER(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700761 /**
762 * Utility function for returning an Element containing a single Script.
763 * @param[in] rs RenderScript context
764 * @return Element
765 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700766 static sp<const Element> SCRIPT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700767 /**
768 * Utility function for returning an Element containing an ALPHA_8 pixel.
769 * @param[in] rs RenderScript context
770 * @return Element
771 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700772 static sp<const Element> A_8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700773 /**
774 * Utility function for returning an Element containing an RGB_565 pixel.
775 * @param[in] rs RenderScript context
776 * @return Element
777 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700778 static sp<const Element> RGB_565(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700779 /**
780 * Utility function for returning an Element containing an RGB_888 pixel.
781 * @param[in] rs RenderScript context
782 * @return Element
783 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700784 static sp<const Element> RGB_888(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700785 /**
786 * Utility function for returning an Element containing an RGBA_5551 pixel.
787 * @param[in] rs RenderScript context
788 * @return Element
789 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700790 static sp<const Element> RGBA_5551(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700791 /**
792 * Utility function for returning an Element containing an RGBA_4444 pixel.
793 * @param[in] rs RenderScript context
794 * @return Element
795 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700796 static sp<const Element> RGBA_4444(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700797 /**
798 * Utility function for returning an Element containing an RGBA_8888 pixel.
799 * @param[in] rs RenderScript context
800 * @return Element
801 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700802 static sp<const Element> RGBA_8888(sp<RS> rs);
803
Tim Murray75e877d2013-09-11 14:45:20 -0700804 /**
805 * Utility function for returning an Element containing a float2.
806 * @param[in] rs RenderScript context
807 * @return Element
808 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700809 static sp<const Element> F32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700810 /**
811 * Utility function for returning an Element containing a float3.
812 * @param[in] rs RenderScript context
813 * @return Element
814 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700815 static sp<const Element> F32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700816 /**
817 * Utility function for returning an Element containing a float4.
818 * @param[in] rs RenderScript context
819 * @return Element
820 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700821 static sp<const Element> F32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700822 /**
823 * Utility function for returning an Element containing a double2.
824 * @param[in] rs RenderScript context
825 * @return Element
826 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700827 static sp<const Element> F64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700828 /**
829 * Utility function for returning an Element containing a double3.
830 * @param[in] rs RenderScript context
831 * @return Element
832 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700833 static sp<const Element> F64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700834 /**
835 * Utility function for returning an Element containing a double4.
836 * @param[in] rs RenderScript context
837 * @return Element
838 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700839 static sp<const Element> F64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700840 /**
841 * Utility function for returning an Element containing a uchar2.
842 * @param[in] rs RenderScript context
843 * @return Element
844 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700845 static sp<const Element> U8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700846 /**
847 * Utility function for returning an Element containing a uchar3.
848 * @param[in] rs RenderScript context
849 * @return Element
850 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700851 static sp<const Element> U8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700852 /**
853 * Utility function for returning an Element containing a uchar4.
854 * @param[in] rs RenderScript context
855 * @return Element
856 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700857 static sp<const Element> U8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700858 /**
859 * Utility function for returning an Element containing a char2.
860 * @param[in] rs RenderScript context
861 * @return Element
862 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700863 static sp<const Element> I8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700864 /**
865 * Utility function for returning an Element containing a char3.
866 * @param[in] rs RenderScript context
867 * @return Element
868 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700869 static sp<const Element> I8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700870 /**
871 * Utility function for returning an Element containing a char4.
872 * @param[in] rs RenderScript context
873 * @return Element
874 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700875 static sp<const Element> I8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700876 /**
877 * Utility function for returning an Element containing a ushort2.
878 * @param[in] rs RenderScript context
879 * @return Element
880 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700881 static sp<const Element> U16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700882 /**
883 * Utility function for returning an Element containing a ushort3.
884 * @param[in] rs RenderScript context
885 * @return Element
886 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700887 static sp<const Element> U16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700888 /**
889 * Utility function for returning an Element containing a ushort4.
890 * @param[in] rs RenderScript context
891 * @return Element
892 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700893 static sp<const Element> U16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700894 /**
895 * Utility function for returning an Element containing a short2.
896 * @param[in] rs RenderScript context
897 * @return Element
898 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700899 static sp<const Element> I16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700900 /**
901 * Utility function for returning an Element containing a short3.
902 * @param[in] rs RenderScript context
903 * @return Element
904 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700905 static sp<const Element> I16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700906 /**
907 * Utility function for returning an Element containing a short4.
908 * @param[in] rs RenderScript context
909 * @return Element
910 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700911 static sp<const Element> I16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700912 /**
913 * Utility function for returning an Element containing a uint2.
914 * @param[in] rs RenderScript context
915 * @return Element
916 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700917 static sp<const Element> U32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700918 /**
919 * Utility function for returning an Element containing a uint3.
920 * @param[in] rs RenderScript context
921 * @return Element
922 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700923 static sp<const Element> U32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700924 /**
925 * Utility function for returning an Element containing a uint4.
926 * @param[in] rs RenderScript context
927 * @return Element
928 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700929 static sp<const Element> U32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700930 /**
931 * Utility function for returning an Element containing an int2.
932 * @param[in] rs RenderScript context
933 * @return Element
934 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700935 static sp<const Element> I32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700936 /**
937 * Utility function for returning an Element containing an int3.
938 * @param[in] rs RenderScript context
939 * @return Element
940 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700941 static sp<const Element> I32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700942 /**
943 * Utility function for returning an Element containing an int4.
944 * @param[in] rs RenderScript context
945 * @return Element
946 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700947 static sp<const Element> I32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700948 /**
949 * Utility function for returning an Element containing a ulong2.
950 * @param[in] rs RenderScript context
951 * @return Element
952 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700953 static sp<const Element> U64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700954 /**
955 * Utility function for returning an Element containing a ulong3.
956 * @param[in] rs RenderScript context
957 * @return Element
958 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700959 static sp<const Element> U64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700960 /**
961 * Utility function for returning an Element containing a ulong4.
962 * @param[in] rs RenderScript context
963 * @return Element
964 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700965 static sp<const Element> U64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700966 /**
967 * Utility function for returning an Element containing a long2.
968 * @param[in] rs RenderScript context
969 * @return Element
970 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700971 static sp<const Element> I64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700972 /**
973 * Utility function for returning an Element containing a long3.
974 * @param[in] rs RenderScript context
975 * @return Element
976 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700977 static sp<const Element> I64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700978 /**
979 * Utility function for returning an Element containing a long4.
980 * @param[in] rs RenderScript context
981 * @return Element
982 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700983 static sp<const Element> I64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700984 /**
985 * Utility function for returning an Element containing a YUV pixel.
986 * @param[in] rs RenderScript context
987 * @return Element
988 */
Tim Murrayeb4426d2013-08-27 15:30:16 -0700989 static sp<const Element> YUV(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700990 /**
991 * Utility function for returning an Element containing an rs_matrix_4x4.
992 * @param[in] rs RenderScript context
993 * @return Element
994 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700995 static sp<const Element> MATRIX_4X4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700996 /**
997 * Utility function for returning an Element containing an rs_matrix_3x3.
998 * @param[in] rs RenderScript context
999 * @return Element
1000 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001001 static sp<const Element> MATRIX_3X3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001002 /**
1003 * Utility function for returning an Element containing an rs_matrix_2x2.
1004 * @param[in] rs RenderScript context
1005 * @return Element
1006 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001007 static sp<const Element> MATRIX_2X2(sp<RS> rs);
1008
Tim Murray84bf2b82012-10-31 16:03:16 -07001009 void updateFromNative();
Tim Murray75e877d2013-09-11 14:45:20 -07001010
1011 /**
1012 * Create an Element with a given DataType.
1013 * @param[in] rs RenderScript context
1014 * @param[in] dt data type
1015 * @return Element
1016 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001017 static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
Tim Murray75e877d2013-09-11 14:45:20 -07001018 /**
1019 * Create a vector Element with the given DataType
1020 * @param[in] rs RenderScript
1021 * @param[in] dt DataType
1022 * @param[in] size vector size
1023 * @return Element
1024 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001025 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
Tim Murray75e877d2013-09-11 14:45:20 -07001026 /**
1027 * Create an Element with a given DataType and DataKind.
1028 * @param[in] rs RenderScript context
1029 * @param[in] dt DataType
1030 * @param[in] dk DataKind
1031 * @return Element
1032 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001033 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
Tim Murray75e877d2013-09-11 14:45:20 -07001034
1035 /**
1036 * Returns true if the Element can interoperate with this Element.
1037 * @param[in] e Element to compare
1038 * @return true if Elements can interoperate
1039 */
Tim Murray10913a52013-08-20 17:19:47 -07001040 bool isCompatible(sp<const Element>e) const;
Tim Murray84bf2b82012-10-31 16:03:16 -07001041
Tim Murray75e877d2013-09-11 14:45:20 -07001042 /**
1043 * Builder class for producing complex elements with matching field and name
1044 * pairs. The builder starts empty. The order in which elements are added is
1045 * retained for the layout in memory.
1046 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001047 class Builder {
1048 private:
Tim Murray35609072013-12-03 11:36:03 -08001049 RS* mRS;
Tim Murray89daad62013-07-29 14:30:02 -07001050 std::vector<sp<Element> > mElements;
Tim Murrayab716362013-08-12 12:37:18 -07001051 std::vector<std::string> mElementNames;
Tim Murray89daad62013-07-29 14:30:02 -07001052 std::vector<uint32_t> mArraySizes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001053 bool mSkipPadding;
1054
1055 public:
1056 Builder(sp<RS> rs);
1057 ~Builder();
Tim Murrayab716362013-08-12 12:37:18 -07001058 void add(sp<Element> e, std::string &name, uint32_t arraySize = 1);
Tim Murray84bf2b82012-10-31 16:03:16 -07001059 sp<const Element> create();
1060 };
1061
Stephen Hines7d1b7572013-08-22 01:24:06 -07001062protected:
1063 Element(void *id, sp<RS> rs,
1064 std::vector<sp<Element> > &elements,
1065 std::vector<std::string> &elementNames,
1066 std::vector<uint32_t> &arraySizes);
1067 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
1068 Element(sp<RS> rs);
1069 virtual ~Element();
1070
Tim Murray84bf2b82012-10-31 16:03:16 -07001071private:
1072 void updateVisibleSubElements();
1073
Tim Murray89daad62013-07-29 14:30:02 -07001074 std::vector<sp<Element> > mElements;
Tim Murrayab716362013-08-12 12:37:18 -07001075 std::vector<std::string> mElementNames;
Tim Murray89daad62013-07-29 14:30:02 -07001076 std::vector<uint32_t> mArraySizes;
1077 std::vector<uint32_t> mVisibleElementMap;
1078 std::vector<uint32_t> mOffsetInBytes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001079
1080 RsDataType mType;
1081 RsDataKind mKind;
1082 bool mNormalized;
1083 size_t mSizeBytes;
1084 size_t mVectorSize;
1085};
1086
Stephen Hines2c7206e2012-11-14 19:47:01 -08001087class FieldPacker {
1088protected:
1089 unsigned char* mData;
1090 size_t mPos;
1091 size_t mLen;
1092
1093public:
1094 FieldPacker(size_t len)
Tim Murray89daad62013-07-29 14:30:02 -07001095 : mPos(0), mLen(len) {
1096 mData = new unsigned char[len];
1097 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001098
1099 virtual ~FieldPacker() {
1100 delete [] mData;
1101 }
1102
1103 void align(size_t v) {
1104 if ((v & (v - 1)) != 0) {
Tim Murrayab716362013-08-12 12:37:18 -07001105 // ALOGE("Non-power-of-two alignment: %zu", v);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001106 return;
1107 }
1108
1109 while ((mPos & (v - 1)) != 0) {
1110 mData[mPos++] = 0;
1111 }
1112 }
1113
1114 void reset() {
1115 mPos = 0;
1116 }
1117
1118 void reset(size_t i) {
1119 if (i >= mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001120 // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001121 return;
1122 }
1123 mPos = i;
1124 }
1125
1126 void skip(size_t i) {
1127 size_t res = mPos + i;
1128 if (res > mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001129 // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001130 return;
1131 }
1132 mPos = res;
1133 }
1134
1135 void* getData() const {
1136 return mData;
1137 }
1138
1139 size_t getLength() const {
1140 return mLen;
1141 }
1142
1143 template <typename T>
Tim Murray89daad62013-07-29 14:30:02 -07001144 void add(T t) {
Stephen Hines2c7206e2012-11-14 19:47:01 -08001145 align(sizeof(t));
1146 if (mPos + sizeof(t) <= mLen) {
1147 memcpy(&mData[mPos], &t, sizeof(t));
1148 mPos += sizeof(t);
1149 }
1150 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001151
1152 /*
Tim Murray89daad62013-07-29 14:30:02 -07001153 void add(rs_matrix4x4 m) {
1154 for (size_t i = 0; i < 16; i++) {
1155 add(m.m[i]);
1156 }
1157 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001158
Tim Murray89daad62013-07-29 14:30:02 -07001159 void add(rs_matrix3x3 m) {
1160 for (size_t i = 0; i < 9; i++) {
1161 add(m.m[i]);
1162 }
1163 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001164
Tim Murray89daad62013-07-29 14:30:02 -07001165 void add(rs_matrix2x2 m) {
1166 for (size_t i = 0; i < 4; i++) {
1167 add(m.m[i]);
1168 }
1169 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001170 */
1171
Tim Murray89daad62013-07-29 14:30:02 -07001172 void add(sp<BaseObj> obj) {
Stephen Hines43514cd2012-11-16 14:33:47 -08001173 if (obj != NULL) {
1174 add((uint32_t) (uintptr_t) obj->getID());
1175 } else {
1176 add((uint32_t) 0);
1177 }
1178 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001179};
1180
Tim Murray75e877d2013-09-11 14:45:20 -07001181/**
1182 * A Type describes the Element and dimensions used for an Allocation or a
1183 * parallel operation.
1184 *
1185 * A Type always includes an Element and an X dimension. A Type may be
1186 * multidimensional, up to three dimensions. A nonzero value in the Y or Z
1187 * dimensions indicates that the dimension is present. Note that a Type with
1188 * only a given X dimension and a Type with the same X dimension but Y = 1 are
1189 * not equivalent.
1190 *
1191 * A Type also supports inclusion of level of detail (LOD) or cube map
1192 * faces. LOD and cube map faces are booleans to indicate present or not
1193 * present.
1194 *
1195 * A Type also supports YUV format information to support an Allocation in a YUV
1196 * format. The YUV formats supported are YV12 and NV21.
1197 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001198class Type : public BaseObj {
1199protected:
1200 friend class Allocation;
1201
1202 uint32_t mDimX;
1203 uint32_t mDimY;
1204 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001205 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001206 bool mDimMipmaps;
1207 bool mDimFaces;
1208 size_t mElementCount;
1209 sp<const Element> mElement;
1210
Stephen Hines7d1b7572013-08-22 01:24:06 -07001211 Type(void *id, sp<RS> rs);
1212
Tim Murray84bf2b82012-10-31 16:03:16 -07001213 void calcElementCount();
1214 virtual void updateFromNative();
1215
1216public:
1217
Tim Murray75e877d2013-09-11 14:45:20 -07001218 /**
1219 * Returns the YUV format.
1220 * @return YUV format of the Allocation
1221 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001222 RSYuvFormat getYuvFormat() const {
1223 return mYuvFormat;
1224 }
1225
Tim Murray75e877d2013-09-11 14:45:20 -07001226 /**
1227 * Returns the Element of the Allocation.
1228 * @return YUV format of the Allocation
1229 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001230 sp<const Element> getElement() const {
1231 return mElement;
1232 }
1233
Tim Murray75e877d2013-09-11 14:45:20 -07001234 /**
1235 * Returns the X dimension of the Allocation.
1236 * @return X dimension of the allocation
1237 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001238 uint32_t getX() const {
1239 return mDimX;
1240 }
1241
Tim Murray75e877d2013-09-11 14:45:20 -07001242 /**
1243 * Returns the Y dimension of the Allocation.
1244 * @return Y dimension of the allocation
1245 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001246 uint32_t getY() const {
1247 return mDimY;
1248 }
1249
Tim Murray75e877d2013-09-11 14:45:20 -07001250 /**
1251 * Returns the Z dimension of the Allocation.
1252 * @return Z dimension of the allocation
1253 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001254 uint32_t getZ() const {
1255 return mDimZ;
1256 }
1257
Tim Murray75e877d2013-09-11 14:45:20 -07001258 /**
1259 * Returns true if the Allocation has mipmaps.
1260 * @return true if the Allocation has mipmaps
1261 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001262 bool hasMipmaps() const {
1263 return mDimMipmaps;
1264 }
1265
Tim Murray75e877d2013-09-11 14:45:20 -07001266 /**
1267 * Returns true if the Allocation is a cube map
1268 * @return true if the Allocation is a cube map
1269 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001270 bool hasFaces() const {
1271 return mDimFaces;
1272 }
1273
Tim Murray75e877d2013-09-11 14:45:20 -07001274 /**
1275 * Returns number of accessible Elements in the Allocation
1276 * @return number of accessible Elements in the Allocation
1277 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001278 size_t getCount() const {
1279 return mElementCount;
1280 }
1281
Tim Murray75e877d2013-09-11 14:45:20 -07001282 /**
1283 * Returns size in bytes of all Elements in the Allocation
1284 * @return size in bytes of all Elements in the Allocation
1285 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001286 size_t getSizeBytes() const {
1287 return mElementCount * mElement->getSizeBytes();
1288 }
1289
Tim Murray75e877d2013-09-11 14:45:20 -07001290 /**
1291 * Creates a new Type with the given Element and dimensions.
1292 * @param[in] rs RenderScript context
1293 * @param[in] e Element
1294 * @param[in] dimX X dimension
1295 * @param[in] dimY Y dimension
1296 * @param[in] dimZ Z dimension
1297 * @return new Type
1298 */
Tim Murray96267c22013-02-12 11:25:12 -08001299 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 -07001300
1301 class Builder {
1302 protected:
Tim Murray35609072013-12-03 11:36:03 -08001303 RS* mRS;
Tim Murray84bf2b82012-10-31 16:03:16 -07001304 uint32_t mDimX;
1305 uint32_t mDimY;
1306 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001307 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001308 bool mDimMipmaps;
1309 bool mDimFaces;
1310 sp<const Element> mElement;
1311
1312 public:
1313 Builder(sp<RS> rs, sp<const Element> e);
1314
1315 void setX(uint32_t value);
Stephen Hines7d1b7572013-08-22 01:24:06 -07001316 void setY(uint32_t value);
Tim Murrayeb4426d2013-08-27 15:30:16 -07001317 void setZ(uint32_t value);
1318 void setYuvFormat(RSYuvFormat format);
Tim Murray84bf2b82012-10-31 16:03:16 -07001319 void setMipmaps(bool value);
1320 void setFaces(bool value);
1321 sp<const Type> create();
1322 };
1323
1324};
1325
Tim Murray75e877d2013-09-11 14:45:20 -07001326/**
1327 * The parent class for all executable Scripts. This should not be used by applications.
1328 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001329class Script : public BaseObj {
1330private:
1331
1332protected:
1333 Script(void *id, sp<RS> rs);
1334 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
1335 const void *v, size_t) const;
1336 void bindAllocation(sp<Allocation> va, uint32_t slot) const;
1337 void setVar(uint32_t index, const void *, size_t len) const;
1338 void setVar(uint32_t index, sp<const BaseObj> o) const;
1339 void invoke(uint32_t slot, const void *v, size_t len) const;
1340
1341
1342 void invoke(uint32_t slot) const {
1343 invoke(slot, NULL, 0);
1344 }
1345 void setVar(uint32_t index, float v) const {
1346 setVar(index, &v, sizeof(v));
1347 }
1348 void setVar(uint32_t index, double v) const {
1349 setVar(index, &v, sizeof(v));
1350 }
1351 void setVar(uint32_t index, int32_t v) const {
1352 setVar(index, &v, sizeof(v));
1353 }
1354 void setVar(uint32_t index, int64_t v) const {
1355 setVar(index, &v, sizeof(v));
1356 }
1357 void setVar(uint32_t index, bool v) const {
1358 setVar(index, &v, sizeof(v));
1359 }
1360
1361public:
1362 class FieldBase {
1363 protected:
1364 sp<const Element> mElement;
1365 sp<Allocation> mAllocation;
1366
1367 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
1368
1369 public:
1370 sp<const Element> getElement() {
1371 return mElement;
1372 }
1373
1374 sp<const Type> getType() {
1375 return mAllocation->getType();
1376 }
1377
1378 sp<const Allocation> getAllocation() {
1379 return mAllocation;
1380 }
1381
1382 //void updateAllocation();
1383 };
1384};
1385
Tim Murray75e877d2013-09-11 14:45:20 -07001386/**
1387 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only.
1388 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001389class ScriptC : public Script {
1390protected:
1391 ScriptC(sp<RS> rs,
1392 const void *codeTxt, size_t codeLength,
1393 const char *cachedName, size_t cachedNameLength,
1394 const char *cacheDir, size_t cacheDirLength);
1395
1396};
1397
Tim Murray75e877d2013-09-11 14:45:20 -07001398/**
1399 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of
1400 * basic functions. This is not intended to be used directly.
1401 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001402class ScriptIntrinsic : public Script {
1403 protected:
Tim Murray10913a52013-08-20 17:19:47 -07001404 sp<const Element> mElement;
Tim Murray3cd44af2012-11-14 11:25:27 -08001405 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001406 virtual ~ScriptIntrinsic();
Tim Murray7f0d5682012-11-08 16:35:24 -08001407};
1408
Tim Murray75e877d2013-09-11 14:45:20 -07001409/**
1410 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming
1411 * r,g,b values are use as normalized x,y,z coordinates into a 3D
1412 * allocation. The 8 nearest values are sampled and linearly interpolated. The
1413 * result is placed in the output.
1414 */
Tim Murray89daad62013-07-29 14:30:02 -07001415class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001416 private:
Tim Murray89daad62013-07-29 14:30:02 -07001417 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001418 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001419 /**
1420 * Supported Element types are U8_4. Default lookup table is identity.
1421 * @param[in] rs RenderScript context
1422 * @param[in] e Element
1423 * @return new ScriptIntrinsic
1424 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001425 static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001426
1427 /**
1428 * Launch the intrinsic.
1429 * @param[in] ain input Allocation
1430 * @param[in] aout output Allocation
1431 */
Tim Murray89daad62013-07-29 14:30:02 -07001432 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001433
1434 /**
1435 * Sets the lookup table. The lookup table must use the same Element as the
1436 * intrinsic.
1437 * @param[in] lut new lookup table
1438 */
Tim Murray89daad62013-07-29 14:30:02 -07001439 void setLUT(sp<Allocation> lut);
1440};
1441
Tim Murray75e877d2013-09-11 14:45:20 -07001442/**
1443 * Intrinsic kernel for blending two Allocations.
1444 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001445class ScriptIntrinsicBlend : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001446 private:
Tim Murray89daad62013-07-29 14:30:02 -07001447 ScriptIntrinsicBlend(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.
1451 * @param[in] rs RenderScript context
1452 * @param[in] e Element
1453 * @return new ScriptIntrinsicBlend
1454 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001455 static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001456 /**
1457 * sets dst = {0, 0, 0, 0}
1458 * @param[in] in input Allocation
1459 * @param[in] out output Allocation
1460 */
1461 void forEachClear(sp<Allocation> in, sp<Allocation> out);
1462 /**
1463 * Sets dst = src
1464 * @param[in] in input Allocation
1465 * @param[in] out output Allocation
1466 */
1467 void forEachSrc(sp<Allocation> in, sp<Allocation> out);
1468 /**
1469 * Sets dst = dst (NOP)
1470 * @param[in] in input Allocation
1471 * @param[in] out output Allocation
1472 */
1473 void forEachDst(sp<Allocation> in, sp<Allocation> out);
1474 /**
1475 * Sets dst = src + dst * (1.0 - src.a)
1476 * @param[in] in input Allocation
1477 * @param[in] out output Allocation
1478 */
1479 void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
1480 /**
1481 * Sets dst = dst + src * (1.0 - dst.a)
1482 * @param[in] in input Allocation
1483 * @param[in] out output Allocation
1484 */
1485 void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
1486 /**
1487 * Sets dst = src * dst.a
1488 * @param[in] in input Allocation
1489 * @param[in] out output Allocation
1490 */
1491 void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
1492 /**
1493 * Sets dst = dst * src.a
1494 * @param[in] in input Allocation
1495 * @param[in] out output Allocation
1496 */
1497 void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
1498 /**
1499 * Sets dst = src * (1.0 - dst.a)
1500 * @param[in] in input Allocation
1501 * @param[in] out output Allocation
1502 */
1503 void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
1504 /**
1505 * Sets dst = dst * (1.0 - src.a)
1506 * @param[in] in input Allocation
1507 * @param[in] out output Allocation
1508 */
1509 void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
1510 /**
1511 * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
1512 * @param[in] in input Allocation
1513 * @param[in] out output Allocation
1514 */
1515 void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
1516 /**
1517 * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
1518 * @param[in] in input Allocation
1519 * @param[in] out output Allocation
1520 */
1521 void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
1522 /**
1523 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
1524 * @param[in] in input Allocation
1525 * @param[in] out output Allocation
1526 */
1527 void forEachXor(sp<Allocation> in, sp<Allocation> out);
1528 /**
1529 * Sets dst = src * dst
1530 * @param[in] in input Allocation
1531 * @param[in] out output Allocation
1532 */
1533 void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
1534 /**
1535 * Sets dst = min(src + dst, 1.0)
1536 * @param[in] in input Allocation
1537 * @param[in] out output Allocation
1538 */
1539 void forEachAdd(sp<Allocation> in, sp<Allocation> out);
1540 /**
1541 * Sets dst = max(dst - src, 0.0)
1542 * @param[in] in input Allocation
1543 * @param[in] out output Allocation
1544 */
1545 void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
Tim Murray7f0d5682012-11-08 16:35:24 -08001546};
Tim Murray84bf2b82012-10-31 16:03:16 -07001547
Tim Murray75e877d2013-09-11 14:45:20 -07001548/**
1549 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified
1550 * radius to all elements of an Allocation.
1551 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001552class ScriptIntrinsicBlur : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001553 private:
Tim Murray89daad62013-07-29 14:30:02 -07001554 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001555 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001556 /**
1557 * Supported Element types are U8 and U8_4.
1558 * @param[in] rs RenderScript context
1559 * @param[in] e Element
1560 * @return new ScriptIntrinsicBlur
1561 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001562 static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001563 /**
1564 * Sets the input of the blur.
1565 * @param[in] in input Allocation
1566 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001567 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001568 /**
1569 * Runs the intrinsic.
1570 * @param[in] output Allocation
1571 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001572 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001573 /**
1574 * Sets the radius of the blur. The supported range is 0 < radius <= 25.
1575 * @param[in] radius radius of the blur
1576 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001577 void setRadius(float radius);
1578};
1579
Tim Murray75e877d2013-09-11 14:45:20 -07001580/**
1581 * Intrinsic for applying a color matrix to allocations. This has the
1582 * same effect as loading each element and converting it to a
1583 * F32_N, multiplying the result by the 4x4 color matrix
1584 * as performed by rsMatrixMultiply() and writing it to the output
1585 * after conversion back to U8_N or F32_N.
1586 */
Tim Murray89daad62013-07-29 14:30:02 -07001587class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001588 private:
Tim Murray89daad62013-07-29 14:30:02 -07001589 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001590 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001591 /**
1592 * Creates a new intrinsic.
1593 * @param[in] rs RenderScript context
1594 * @return new ScriptIntrinsicColorMatrix
1595 */
Tim Murrayaae73c92013-09-03 17:05:46 -07001596 static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001597 /**
1598 * Applies the color matrix. Supported types are U8 and F32 with
1599 * vector lengths between 1 and 4.
1600 * @param[in] in input Allocation
1601 * @param[out] out output Allocation
1602 */
Tim Murray89daad62013-07-29 14:30:02 -07001603 void forEach(sp<Allocation> in, sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001604 /**
1605 * Set the value to be added after the color matrix has been
1606 * applied. The default value is {0, 0, 0, 0}.
1607 * @param[in] add float[4] of values
1608 */
Tim Murray10913a52013-08-20 17:19:47 -07001609 void setAdd(float* add);
Tim Murray75e877d2013-09-11 14:45:20 -07001610
1611 /**
1612 * Set the color matrix which will be applied to each cell of the
1613 * image. The alpha channel will be copied.
1614 *
1615 * @param[in] m float[9] of values
1616 */
Tim Murray89daad62013-07-29 14:30:02 -07001617 void setColorMatrix3(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001618 /**
1619 * Set the color matrix which will be applied to each cell of the
1620 * image.
1621 *
1622 * @param[in] m float[16] of values
1623 */
Tim Murray89daad62013-07-29 14:30:02 -07001624 void setColorMatrix4(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001625 /**
1626 * Set a color matrix to convert from RGB to luminance. The alpha
1627 * channel will be a copy.
1628 */
Tim Murray89daad62013-07-29 14:30:02 -07001629 void setGreyscale();
Tim Murray75e877d2013-09-11 14:45:20 -07001630 /**
1631 * Set the matrix to convert from RGB to YUV with a direct copy of
1632 * the 4th channel.
1633 */
Tim Murray89daad62013-07-29 14:30:02 -07001634 void setRGBtoYUV();
Tim Murray75e877d2013-09-11 14:45:20 -07001635 /**
1636 * Set the matrix to convert from YUV to RGB with a direct copy of
1637 * the 4th channel.
1638 */
Tim Murray89daad62013-07-29 14:30:02 -07001639 void setYUVtoRGB();
1640};
1641
Tim Murray75e877d2013-09-11 14:45:20 -07001642/**
1643 * Intrinsic for applying a 3x3 convolve to an allocation.
1644 */
Tim Murray89daad62013-07-29 14:30:02 -07001645class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001646 private:
Tim Murray89daad62013-07-29 14:30:02 -07001647 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001648 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001649 /**
1650 * Supported types U8 and F32 with vector lengths between 1 and
1651 * 4. The default convolution kernel is the identity.
1652 * @param[in] rs RenderScript context
1653 * @param[in] e Element
1654 * @return new ScriptIntrinsicConvolve3x3
1655 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001656 static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001657 /**
1658 * Sets input for intrinsic.
1659 * @param[in] in input Allocation
1660 */
Tim Murray89daad62013-07-29 14:30:02 -07001661 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001662 /**
1663 * Launches the intrinsic.
1664 * @param[in] out output Allocation
1665 */
Tim Murray89daad62013-07-29 14:30:02 -07001666 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001667 /**
1668 * Sets convolution kernel.
1669 * @param[in] v float[9] of values
1670 */
Tim Murray89daad62013-07-29 14:30:02 -07001671 void setCoefficients(float* v);
1672};
1673
Tim Murray75e877d2013-09-11 14:45:20 -07001674/**
1675 * Intrinsic for applying a 5x5 convolve to an allocation.
1676 */
Tim Murray89daad62013-07-29 14:30:02 -07001677class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001678 private:
Tim Murray89daad62013-07-29 14:30:02 -07001679 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001680 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001681 /**
1682 * Supported types U8 and F32 with vector lengths between 1 and
1683 * 4. The default convolution kernel is the identity.
1684 * @param[in] rs RenderScript context
1685 * @param[in] e Element
1686 * @return new ScriptIntrinsicConvolve5x5
1687 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001688 static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001689 /**
1690 * Sets input for intrinsic.
1691 * @param[in] in input Allocation
1692 */
Tim Murray89daad62013-07-29 14:30:02 -07001693 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001694 /**
1695 * Launches the intrinsic.
1696 * @param[in] out output Allocation
1697 */
Tim Murray89daad62013-07-29 14:30:02 -07001698 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001699 /**
1700 * Sets convolution kernel.
1701 * @param[in] v float[25] of values
1702 */
Tim Murray89daad62013-07-29 14:30:02 -07001703 void setCoefficients(float* v);
1704};
1705
Tim Murray75e877d2013-09-11 14:45:20 -07001706/**
1707 * Intrinsic for computing a histogram.
1708 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001709class ScriptIntrinsicHistogram : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001710 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001711 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
Tim Murray10913a52013-08-20 17:19:47 -07001712 sp<Allocation> mOut;
Tim Murray21fa7a02013-08-15 16:25:03 -07001713 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001714 /**
1715 * Create an intrinsic for calculating the histogram of an uchar
1716 * or uchar4 image.
1717 *
1718 * Supported elements types are U8_4, U8_3, U8_2, and U8.
1719 *
1720 * @param[in] rs The RenderScript context
1721 * @param[in] e Element type for inputs
1722 *
1723 * @return ScriptIntrinsicHistogram
1724 */
Tim Murray10913a52013-08-20 17:19:47 -07001725 static sp<ScriptIntrinsicHistogram> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001726 /**
1727 * Set the output of the histogram. 32 bit integer types are
1728 * supported.
1729 *
1730 * @param[in] aout The output allocation
1731 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001732 void setOutput(sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001733 /**
1734 * Set the coefficients used for the dot product calculation. The
1735 * default is {0.299f, 0.587f, 0.114f, 0.f}.
1736 *
1737 * Coefficients must be >= 0 and sum to 1.0 or less.
1738 *
1739 * @param[in] r Red coefficient
1740 * @param[in] g Green coefficient
1741 * @param[in] b Blue coefficient
1742 * @param[in] a Alpha coefficient
1743 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001744 void setDotCoefficients(float r, float g, float b, float a);
Tim Murray75e877d2013-09-11 14:45:20 -07001745 /**
1746 * Process an input buffer and place the histogram into the output
1747 * allocation. The output allocation may be a narrower vector size
1748 * than the input. In this case the vector size of the output is
1749 * used to determine how many of the input channels are used in
1750 * the computation. This is useful if you have an RGBA input
1751 * buffer but only want the histogram for RGB.
1752 *
1753 * 1D and 2D input allocations are supported.
1754 *
1755 * @param[in] ain The input image
1756 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001757 void forEach(sp<Allocation> ain);
Tim Murray75e877d2013-09-11 14:45:20 -07001758 /**
1759 * Process an input buffer and place the histogram into the output
1760 * allocation. The dot product of the input channel and the
1761 * coefficients from 'setDotCoefficients' are used to calculate
1762 * the output values.
1763 *
1764 * 1D and 2D input allocations are supported.
1765 *
1766 * @param ain The input image
1767 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001768 void forEach_dot(sp<Allocation> ain);
1769};
1770
Tim Murray75e877d2013-09-11 14:45:20 -07001771/**
1772 * Intrinsic for applying a per-channel lookup table. Each channel of
1773 * the input has an independant lookup table. The tables are 256
1774 * entries in size and can cover the full value range of U8_4.
1775 **/
Tim Murrayb27b1812013-08-05 14:00:40 -07001776class ScriptIntrinsicLUT : public ScriptIntrinsic {
1777 private:
1778 sp<Allocation> LUT;
1779 bool mDirty;
1780 unsigned char mCache[1024];
Tim Murray2acce992013-08-28 14:23:31 -07001781 void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray21fa7a02013-08-15 16:25:03 -07001782 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001783
Tim Murray89daad62013-07-29 14:30:02 -07001784 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001785 /**
1786 * Supported elements types are U8_4.
1787 *
1788 * The defaults tables are identity.
1789 *
1790 * @param[in] rs The RenderScript context
1791 * @param[in] e Element type for intputs and outputs
1792 *
1793 * @return ScriptIntrinsicLUT
1794 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001795 static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001796 /**
1797 * Invoke the kernel and apply the lookup to each cell of ain and
1798 * copy to aout.
1799 *
1800 * @param[in] ain Input allocation
1801 * @param[in] aout Output allocation
1802 */
Tim Murray89daad62013-07-29 14:30:02 -07001803 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001804 /**
1805 * Sets entries in LUT for the red channel.
1806 * @param[in] base base of region to update
1807 * @param[in] length length of region to update
1808 * @param[in] lutValues LUT values to use
1809 */
Tim Murray2acce992013-08-28 14:23:31 -07001810 void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001811 /**
1812 * Sets entries in LUT for the green channel.
1813 * @param[in] base base of region to update
1814 * @param[in] length length of region to update
1815 * @param[in] lutValues LUT values to use
1816 */
Tim Murray2acce992013-08-28 14:23:31 -07001817 void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001818 /**
1819 * Sets entries in LUT for the blue channel.
1820 * @param[in] base base of region to update
1821 * @param[in] length length of region to update
1822 * @param[in] lutValues LUT values to use
1823 */
Tim Murray2acce992013-08-28 14:23:31 -07001824 void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001825 /**
1826 * Sets entries in LUT for the alpha channel.
1827 * @param[in] base base of region to update
1828 * @param[in] length length of region to update
1829 * @param[in] lutValues LUT values to use
1830 */
Tim Murray2acce992013-08-28 14:23:31 -07001831 void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murrayb27b1812013-08-05 14:00:40 -07001832 virtual ~ScriptIntrinsicLUT();
1833};
1834
Tim Murray75e877d2013-09-11 14:45:20 -07001835/**
1836 * Intrinsic for converting an Android YUV buffer to RGB.
1837 *
1838 * The input allocation should be supplied in a supported YUV format
1839 * as a YUV element Allocation. The output is RGBA; the alpha channel
1840 * will be set to 255.
1841 */
Tim Murray89daad62013-07-29 14:30:02 -07001842class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001843 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001844 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001845 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001846 /**
1847 * Create an intrinsic for converting YUV to RGB.
1848 *
1849 * Supported elements types are U8_4.
1850 *
1851 * @param[in] rs The RenderScript context
1852 * @param[in] e Element type for output
1853 *
1854 * @return ScriptIntrinsicYuvToRGB
1855 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001856 static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001857 /**
1858 * Set the input YUV allocation.
1859 *
1860 * @param[in] ain The input allocation.
1861 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001862 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001863
1864 /**
1865 * Convert the image to RGB.
1866 *
1867 * @param[in] aout Output allocation. Must match creation element
1868 * type.
1869 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001870 void forEach(sp<Allocation> out);
Tim Murray89daad62013-07-29 14:30:02 -07001871
1872};
Tim Murrayb27b1812013-08-05 14:00:40 -07001873
Tim Murray75e877d2013-09-11 14:45:20 -07001874/**
1875 * Sampler object that defines how Allocations can be read as textures
1876 * within a kernel. Samplers are used in conjunction with the rsSample
1877 * runtime function to return values from normalized coordinates.
1878 *
1879 * Any Allocation used with a Sampler must have been created with
1880 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an
1881 * Allocation that was not created with
1882 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined.
1883 **/
Tim Murray729b6fe2013-07-23 16:20:42 -07001884 class Sampler : public BaseObj {
1885 private:
1886 Sampler(sp<RS> rs, void* id);
1887 RsSamplerValue mMin;
1888 RsSamplerValue mMag;
1889 RsSamplerValue mWrapS;
1890 RsSamplerValue mWrapT;
Tim Murray729b6fe2013-07-23 16:20:42 -07001891 float mAniso;
1892
1893 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001894 /**
1895 * Creates a non-standard Sampler.
1896 * @param[in] rs RenderScript context
1897 * @param[in] min minification
1898 * @param[in] mag magnification
1899 * @param[in] wrapS S wrapping mode
1900 * @param[in] wrapT T wrapping mode
1901 * @param[in] anisotropy anisotropy setting
1902 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001903 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
1904
Tim Murray75e877d2013-09-11 14:45:20 -07001905 /**
1906 * @return minification setting for the sampler
1907 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001908 RsSamplerValue getMinification();
Tim Murray75e877d2013-09-11 14:45:20 -07001909 /**
1910 * @return magnification setting for the sampler
1911 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001912 RsSamplerValue getMagnification();
Tim Murray75e877d2013-09-11 14:45:20 -07001913 /**
1914 * @return S wrapping mode for the sampler
1915 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001916 RsSamplerValue getWrapS();
Tim Murray75e877d2013-09-11 14:45:20 -07001917 /**
1918 * @return T wrapping mode for the sampler
1919 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001920 RsSamplerValue getWrapT();
Tim Murray75e877d2013-09-11 14:45:20 -07001921 /**
1922 * @return anisotropy setting for the sampler
1923 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001924 float getAnisotropy();
1925
Tim Murray75e877d2013-09-11 14:45:20 -07001926 /**
1927 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1928 * clamp.
1929 *
1930 * @param rs Context to which the sampler will belong.
1931 *
1932 * @return Sampler
1933 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001934 static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001935 /**
1936 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1937 * clamp.
1938 *
1939 * @param rs Context to which the sampler will belong.
1940 *
1941 * @return Sampler
1942 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001943 static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001944 /**
1945 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
1946 * wrap modes set to clamp.
1947 *
1948 * @param rs Context to which the sampler will belong.
1949 *
1950 * @return Sampler
1951 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001952 static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001953 /**
1954 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1955 * wrap.
1956 *
1957 * @param rs Context to which the sampler will belong.
1958 *
1959 * @return Sampler
1960 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001961 static sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001962 /**
1963 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1964 * wrap.
1965 *
1966 * @param rs Context to which the sampler will belong.
1967 *
1968 * @return Sampler
1969 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001970 static sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001971 /**
1972 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
1973 * wrap modes set to wrap.
1974 *
1975 * @param rs Context to which the sampler will belong.
1976 *
1977 * @return Sampler
1978 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001979 static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001980 /**
1981 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1982 * mirrored repeat.
1983 *
1984 * @param rs Context to which the sampler will belong.
1985 *
1986 * @return Sampler
1987 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001988 static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001989 /**
1990 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1991 * mirrored repeat.
1992 *
1993 * @param rs Context to which the sampler will belong.
1994 *
1995 * @return Sampler
1996 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001997 static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001998 /**
1999 * Retrieve a sampler with min and mag set to linear and wrap modes set to
2000 * mirrored repeat.
2001 *
2002 * @param rs Context to which the sampler will belong.
2003 *
2004 * @return Sampler
2005 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002006 static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray729b6fe2013-07-23 16:20:42 -07002007
2008};
2009
Stephen Hinesd10412f2013-08-29 18:27:21 -07002010class Byte2 {
2011 public:
2012 int8_t x, y;
2013
2014 Byte2(int8_t initX, int8_t initY)
2015 : x(initX), y(initY) {}
2016 Byte2() : x(0), y(0) {}
2017};
2018
2019class Byte3 {
2020 public:
2021 int8_t x, y, z;
2022
2023 Byte3(int8_t initX, int8_t initY, int8_t initZ)
2024 : x(initX), y(initY), z(initZ) {}
2025 Byte3() : x(0), y(0), z(0) {}
2026};
2027
2028class Byte4 {
2029 public:
2030 int8_t x, y, z, w;
2031
2032 Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
2033 : x(initX), y(initY), z(initZ), w(initW) {}
2034 Byte4() : x(0), y(0), z(0), w(0) {}
2035};
2036
2037class UByte2 {
2038 public:
2039 uint8_t x, y;
2040
2041 UByte2(uint8_t initX, uint8_t initY)
2042 : x(initX), y(initY) {}
2043 UByte2() : x(0), y(0) {}
2044};
2045
2046class UByte3 {
2047 public:
2048 uint8_t x, y, z;
2049
2050 UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
2051 : x(initX), y(initY), z(initZ) {}
2052 UByte3() : x(0), y(0), z(0) {}
2053};
2054
2055class UByte4 {
2056 public:
2057 uint8_t x, y, z, w;
2058
2059 UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
2060 : x(initX), y(initY), z(initZ), w(initW) {}
2061 UByte4() : x(0), y(0), z(0), w(0) {}
2062};
2063
2064class Short2 {
2065 public:
2066 short x, y;
2067
2068 Short2(short initX, short initY)
2069 : x(initX), y(initY) {}
2070 Short2() : x(0), y(0) {}
2071};
2072
2073class Short3 {
2074 public:
2075 short x, y, z;
2076
2077 Short3(short initX, short initY, short initZ)
2078 : x(initX), y(initY), z(initZ) {}
2079 Short3() : x(0), y(0), z(0) {}
2080};
2081
2082class Short4 {
2083 public:
2084 short x, y, z, w;
2085
2086 Short4(short initX, short initY, short initZ, short initW)
2087 : x(initX), y(initY), z(initZ), w(initW) {}
2088 Short4() : x(0), y(0), z(0), w(0) {}
2089};
2090
2091class UShort2 {
2092 public:
2093 uint16_t x, y;
2094
2095 UShort2(uint16_t initX, uint16_t initY)
2096 : x(initX), y(initY) {}
2097 UShort2() : x(0), y(0) {}
2098};
2099
2100class UShort3 {
2101 public:
2102 uint16_t x, y, z;
2103
2104 UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
2105 : x(initX), y(initY), z(initZ) {}
2106 UShort3() : x(0), y(0), z(0) {}
2107};
2108
2109class UShort4 {
2110 public:
2111 uint16_t x, y, z, w;
2112
2113 UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
2114 : x(initX), y(initY), z(initZ), w(initW) {}
2115 UShort4() : x(0), y(0), z(0), w(0) {}
2116};
2117
2118class Int2 {
2119 public:
2120 int x, y;
2121
2122 Int2(int initX, int initY)
2123 : x(initX), y(initY) {}
2124 Int2() : x(0), y(0) {}
2125};
2126
2127class Int3 {
2128 public:
2129 int x, y, z;
2130
2131 Int3(int initX, int initY, int initZ)
2132 : x(initX), y(initY), z(initZ) {}
2133 Int3() : x(0), y(0), z(0) {}
2134};
2135
2136class Int4 {
2137 public:
2138 int x, y, z, w;
2139
2140 Int4(int initX, int initY, int initZ, int initW)
2141 : x(initX), y(initY), z(initZ), w(initW) {}
2142 Int4() : x(0), y(0), z(0), w(0) {}
2143};
2144
2145class UInt2 {
2146 public:
2147 uint32_t x, y;
2148
2149 UInt2(uint32_t initX, uint32_t initY)
2150 : x(initX), y(initY) {}
2151 UInt2() : x(0), y(0) {}
2152};
2153
2154class UInt3 {
2155 public:
2156 uint32_t x, y, z;
2157
2158 UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
2159 : x(initX), y(initY), z(initZ) {}
2160 UInt3() : x(0), y(0), z(0) {}
2161};
2162
2163class UInt4 {
2164 public:
2165 uint32_t x, y, z, w;
2166
2167 UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
2168 : x(initX), y(initY), z(initZ), w(initW) {}
2169 UInt4() : x(0), y(0), z(0), w(0) {}
2170};
2171
2172class Long2 {
2173 public:
2174 int64_t x, y;
2175
2176 Long2(int64_t initX, int64_t initY)
2177 : x(initX), y(initY) {}
2178 Long2() : x(0), y(0) {}
2179};
2180
2181class Long3 {
2182 public:
2183 int64_t x, y, z;
2184
2185 Long3(int64_t initX, int64_t initY, int64_t initZ)
2186 : x(initX), y(initY), z(initZ) {}
2187 Long3() : x(0), y(0), z(0) {}
2188};
2189
2190class Long4 {
2191 public:
2192 int64_t x, y, z, w;
2193
2194 Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
2195 : x(initX), y(initY), z(initZ), w(initW) {}
2196 Long4() : x(0), y(0), z(0), w(0) {}
2197};
2198
2199class ULong2 {
2200 public:
2201 uint64_t x, y;
2202
2203 ULong2(uint64_t initX, uint64_t initY)
2204 : x(initX), y(initY) {}
2205 ULong2() : x(0), y(0) {}
2206};
2207
2208class ULong3 {
2209 public:
2210 uint64_t x, y, z;
2211
2212 ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
2213 : x(initX), y(initY), z(initZ) {}
2214 ULong3() : x(0), y(0), z(0) {}
2215};
2216
2217class ULong4 {
2218 public:
2219 uint64_t x, y, z, w;
2220
2221 ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
2222 : x(initX), y(initY), z(initZ), w(initW) {}
2223 ULong4() : x(0), y(0), z(0), w(0) {}
2224};
2225
2226class Float2 {
2227 public:
2228 float x, y;
2229
2230 Float2(float initX, float initY)
2231 : x(initX), y(initY) {}
2232 Float2() : x(0), y(0) {}
2233};
2234
2235class Float3 {
2236 public:
2237 float x, y, z;
2238
2239 Float3(float initX, float initY, float initZ)
2240 : x(initX), y(initY), z(initZ) {}
2241 Float3() : x(0.f), y(0.f), z(0.f) {}
2242};
2243
2244class Float4 {
2245 public:
2246 float x, y, z, w;
2247
2248 Float4(float initX, float initY, float initZ, float initW)
2249 : x(initX), y(initY), z(initZ), w(initW) {}
2250 Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
2251};
2252
2253class Double2 {
2254 public:
2255 double x, y;
2256
2257 Double2(double initX, double initY)
2258 : x(initX), y(initY) {}
2259 Double2() : x(0), y(0) {}
2260};
2261
2262class Double3 {
2263 public:
2264 double x, y, z;
2265
2266 Double3(double initX, double initY, double initZ)
2267 : x(initX), y(initY), z(initZ) {}
2268 Double3() : x(0), y(0), z(0) {}
2269};
2270
2271class Double4 {
2272 public:
2273 double x, y, z, w;
2274
2275 Double4(double initX, double initY, double initZ, double initW)
2276 : x(initX), y(initY), z(initZ), w(initW) {}
2277 Double4() : x(0), y(0), z(0), w(0) {}
2278};
2279
Tim Murray84bf2b82012-10-31 16:03:16 -07002280}
Tim Murray7f0d5682012-11-08 16:35:24 -08002281
Tim Murray84bf2b82012-10-31 16:03:16 -07002282}
2283
2284#endif