blob: 1efd128cb12d3a6aad970997a214b91a332ff7ff [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#include "rsDispatch.h"
23
Tim Murray89daad62013-07-29 14:30:02 -070024#include <vector>
Tim Murrayab716362013-08-12 12:37:18 -070025#include <string>
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
Tim Murray84bf2b82012-10-31 16:03:16 -070033namespace android {
Tim Murray9eb7f4b2012-11-16 14:02:18 -080034namespace RSC {
Tim Murray84bf2b82012-10-31 16:03:16 -070035
36typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText);
37typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen);
38
39class RS;
40class BaseObj;
41class Element;
42class Type;
43class Allocation;
44class Script;
45class ScriptC;
Tim Murray729b6fe2013-07-23 16:20:42 -070046class Sampler;
Tim Murray84bf2b82012-10-31 16:03:16 -070047
Tim Murray75e877d2013-09-11 14:45:20 -070048/**
49 * Possible error codes used by RenderScript. Once a status other than RS_SUCCESS
50 * is returned, the RenderScript context is considered dead and cannot perform any
51 * additional work.
52 */
Tim Murray21fa7a02013-08-15 16:25:03 -070053 enum RSError {
Tim Murray75e877d2013-09-11 14:45:20 -070054 RS_SUCCESS = 0, ///< No error
55 RS_ERROR_INVALID_PARAMETER = 1, ///< An invalid parameter was passed to a function
56 RS_ERROR_RUNTIME_ERROR = 2, ///< The RenderScript driver returned an error; this is
57 ///< often indicative of a kernel that crashed
58 RS_ERROR_INVALID_ELEMENT = 3, ///< An invalid Element was passed to a function
Tim Murray21fa7a02013-08-15 16:25:03 -070059 RS_ERROR_MAX = 9999
60
61 };
62
Tim Murray75e877d2013-09-11 14:45:20 -070063 /**
64 * YUV formats supported by the RenderScript API.
65 */
Tim Murrayeb4426d2013-08-27 15:30:16 -070066 enum RSYuvFormat {
Tim Murray75e877d2013-09-11 14:45:20 -070067 RS_YUV_NONE = 0, ///< No YUV data
68 RS_YUV_YV12 = 1, ///< YUV data in YV12 format
69 RS_YUV_NV21 = 2, ///< YUV data in NV21 format
Tim Murrayeb4426d2013-08-27 15:30:16 -070070 RS_YUV_MAX = 3
71 };
72
Tim Murray75e877d2013-09-11 14:45:20 -070073 /**
74 * Flags that can control RenderScript behavior on a per-context level.
75 */
Tim Murray84e3dea2013-09-09 16:12:51 -070076 enum RSInitFlags {
Tim Murray75e877d2013-09-11 14:45:20 -070077 RS_INIT_SYNCHRONOUS = 1, ///< All RenderScript calls will be synchronous. May reduce latency.
78 RS_INIT_LOW_LATENCY = 2, ///< Prefer low latency devices over potentially higher throughput devices.
Tim Murray84e3dea2013-09-09 16:12:51 -070079 RS_INIT_MAX = 4
80 };
81
Tim Murray75e877d2013-09-11 14:45:20 -070082 /**
83 * The RenderScript context. This class controls initialization, resource management, and teardown.
84 */
Tim Murray89daad62013-07-29 14:30:02 -070085 class RS : public android::RSC::LightRefBase<RS> {
Tim Murray84bf2b82012-10-31 16:03:16 -070086
87 public:
88 RS();
89 virtual ~RS();
90
Tim Murray75e877d2013-09-11 14:45:20 -070091 /**
92 * Initializes a RenderScript context. A context must be initialized before it can be used.
93 * @param[in] flags Optional flags for this context.
94 * @return true on success
95 */
Tim Murray4c4bec12013-09-09 17:21:36 -070096 bool init(uint32_t flags = 0);
Tim Murray84bf2b82012-10-31 16:03:16 -070097
Tim Murray75e877d2013-09-11 14:45:20 -070098 /**
99 * Sets the error handler function for this context. This error handler is
100 * called whenever an error is set.
101 *
102 * @param[in] func Error handler function
103 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700104 void setErrorHandler(ErrorHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700105
106 /**
107 * Returns the current error handler function for this context.
108 *
109 * @return pointer to current error handler function or NULL if not set
110 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700111 ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
112
Tim Murray75e877d2013-09-11 14:45:20 -0700113 /**
114 * Sets the message handler function for this context. This message handler
115 * is called whenever a message is sent from a RenderScript kernel.
116 *
117 * @param[in] func Message handler function
118 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700119 void setMessageHandler(MessageHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700120
121 /**
122 * Returns the current message handler function for this context.
123 *
124 * @return pointer to current message handler function or NULL if not set
125 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700126 MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
127
Tim Murray75e877d2013-09-11 14:45:20 -0700128 /**
129 * Returns current status for the context.
130 *
131 * @return current error
132 */
Tim Murray10913a52013-08-20 17:19:47 -0700133 RSError getError();
Tim Murray84bf2b82012-10-31 16:03:16 -0700134
Tim Murray75e877d2013-09-11 14:45:20 -0700135 /**
136 * Waits for any currently running asynchronous operations to finish. This
137 * should only be used for performance testing and timing.
138 */
Tim Murraybaca6c32012-11-14 16:51:46 -0800139 void finish();
140
Tim Murray75e877d2013-09-11 14:45:20 -0700141 RsContext getContext() { return mContext; }
142 void throwError(RSError error, const char *errMsg);
143
Tim Murraya4230962013-07-17 16:50:10 -0700144 static dispatchTable* dispatch;
145
Tim Murray84bf2b82012-10-31 16:03:16 -0700146 private:
Tim Murray4a92d122013-07-22 10:56:18 -0700147 static bool usingNative;
Tim Murraya4230962013-07-17 16:50:10 -0700148 static bool initDispatch(int targetApi);
149
Tim Murray84e3dea2013-09-09 16:12:51 -0700150 bool init(int targetApi, uint32_t flags);
Tim Murray84bf2b82012-10-31 16:03:16 -0700151 static void * threadProc(void *);
152
153 static bool gInitialized;
154 static pthread_mutex_t gInitMutex;
155
156 pthread_t mMessageThreadId;
157 pid_t mNativeMessageThreadId;
158 bool mMessageRun;
159
160 RsDevice mDev;
161 RsContext mContext;
Tim Murray21fa7a02013-08-15 16:25:03 -0700162 RSError mCurrentError;
Tim Murray84bf2b82012-10-31 16:03:16 -0700163
164 ErrorHandlerFunc_t mErrorFunc;
165 MessageHandlerFunc_t mMessageFunc;
Tim Murraya4230962013-07-17 16:50:10 -0700166 bool mInit;
Tim Murray84bf2b82012-10-31 16:03:16 -0700167
168 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700169 sp<const Element> U8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700170 sp<const Element> U8_2;
171 sp<const Element> U8_3;
172 sp<const Element> U8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700173 sp<const Element> I8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700174 sp<const Element> I8_2;
175 sp<const Element> I8_3;
176 sp<const Element> I8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700177 sp<const Element> U16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700178 sp<const Element> U16_2;
179 sp<const Element> U16_3;
180 sp<const Element> U16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700181 sp<const Element> I16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700182 sp<const Element> I16_2;
183 sp<const Element> I16_3;
184 sp<const Element> I16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700185 sp<const Element> U32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700186 sp<const Element> U32_2;
187 sp<const Element> U32_3;
188 sp<const Element> U32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700189 sp<const Element> I32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700190 sp<const Element> I32_2;
191 sp<const Element> I32_3;
192 sp<const Element> I32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700193 sp<const Element> U64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700194 sp<const Element> U64_2;
195 sp<const Element> U64_3;
196 sp<const Element> U64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700197 sp<const Element> I64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700198 sp<const Element> I64_2;
199 sp<const Element> I64_3;
200 sp<const Element> I64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700201 sp<const Element> F32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700202 sp<const Element> F32_2;
203 sp<const Element> F32_3;
204 sp<const Element> F32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700205 sp<const Element> F64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700206 sp<const Element> F64_2;
207 sp<const Element> F64_3;
208 sp<const Element> F64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700209 sp<const Element> BOOLEAN;
Tim Murray84bf2b82012-10-31 16:03:16 -0700210
Tim Murray89daad62013-07-29 14:30:02 -0700211 sp<const Element> ELEMENT;
212 sp<const Element> TYPE;
213 sp<const Element> ALLOCATION;
214 sp<const Element> SAMPLER;
215 sp<const Element> SCRIPT;
216 sp<const Element> MESH;
217 sp<const Element> PROGRAM_FRAGMENT;
218 sp<const Element> PROGRAM_VERTEX;
219 sp<const Element> PROGRAM_RASTER;
220 sp<const Element> PROGRAM_STORE;
Tim Murray84bf2b82012-10-31 16:03:16 -0700221
Tim Murray89daad62013-07-29 14:30:02 -0700222 sp<const Element> A_8;
223 sp<const Element> RGB_565;
224 sp<const Element> RGB_888;
225 sp<const Element> RGBA_5551;
226 sp<const Element> RGBA_4444;
227 sp<const Element> RGBA_8888;
Tim Murray84bf2b82012-10-31 16:03:16 -0700228
Tim Murrayeb4426d2013-08-27 15:30:16 -0700229 sp<const Element> YUV;
Tim Murray84bf2b82012-10-31 16:03:16 -0700230
Tim Murray89daad62013-07-29 14:30:02 -0700231 sp<const Element> MATRIX_4X4;
232 sp<const Element> MATRIX_3X3;
233 sp<const Element> MATRIX_2X2;
Tim Murray84bf2b82012-10-31 16:03:16 -0700234 } mElements;
235
Tim Murray729b6fe2013-07-23 16:20:42 -0700236 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700237 sp<const Sampler> CLAMP_NEAREST;
238 sp<const Sampler> CLAMP_LINEAR;
239 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
240 sp<const Sampler> WRAP_NEAREST;
241 sp<const Sampler> WRAP_LINEAR;
242 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
243 sp<const Sampler> MIRRORED_REPEAT_NEAREST;
244 sp<const Sampler> MIRRORED_REPEAT_LINEAR;
245 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Tim Murray729b6fe2013-07-23 16:20:42 -0700246 } mSamplers;
247 friend class Sampler;
248 friend class Element;
Tim Murray84bf2b82012-10-31 16:03:16 -0700249};
250
Tim Murray75e877d2013-09-11 14:45:20 -0700251 /**
252 * Base class for all RenderScript objects. Not for direct use by developers.
253 */
Tim Murray89daad62013-07-29 14:30:02 -0700254class BaseObj : public android::RSC::LightRefBase<BaseObj> {
255public:
256 void * getID() const;
257 virtual ~BaseObj();
258 virtual void updateFromNative();
259 virtual bool equals(sp<const BaseObj> obj);
260
Tim Murray84bf2b82012-10-31 16:03:16 -0700261protected:
262 void *mID;
263 sp<RS> mRS;
Tim Murrayab716362013-08-12 12:37:18 -0700264 std::string mName;
Tim Murray84bf2b82012-10-31 16:03:16 -0700265
266 BaseObj(void *id, sp<RS> rs);
267 void checkValid();
268
269 static void * getObjID(sp<const BaseObj> o);
270
Tim Murray84bf2b82012-10-31 16:03:16 -0700271};
272
Tim Murray75e877d2013-09-11 14:45:20 -0700273 /**
274 * This class provides the primary method through which data is passed to and
275 * from RenderScript kernels. An Allocation provides the backing store for a
276 * given Type.
277 *
278 * An Allocation also contains a set of usage flags that denote how the
279 * Allocation could be used. For example, an Allocation may have usage flags
280 * specifying that it can be used from a script as well as input to a
281 * Sampler. A developer must synchronize across these different usages using
282 * syncAll(int) in order to ensure that different users of the Allocation have
283 * a consistent view of memory. For example, in the case where an Allocation is
284 * used as the output of one kernel and as Sampler input in a later kernel, a
285 * developer must call syncAll(RS_ALLOCATION_USAGE_SCRIPT) prior to launching the
286 * second kernel to ensure correctness.
287 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700288class Allocation : public BaseObj {
289protected:
Tim Murray89daad62013-07-29 14:30:02 -0700290 sp<const Type> mType;
Tim Murray84bf2b82012-10-31 16:03:16 -0700291 uint32_t mUsage;
Tim Murray89daad62013-07-29 14:30:02 -0700292 sp<Allocation> mAdaptedAllocation;
Tim Murray84bf2b82012-10-31 16:03:16 -0700293
294 bool mConstrainedLOD;
295 bool mConstrainedFace;
296 bool mConstrainedY;
297 bool mConstrainedZ;
298 bool mReadAllowed;
299 bool mWriteAllowed;
300 uint32_t mSelectedY;
301 uint32_t mSelectedZ;
302 uint32_t mSelectedLOD;
303 RsAllocationCubemapFace mSelectedFace;
304
305 uint32_t mCurrentDimX;
306 uint32_t mCurrentDimY;
307 uint32_t mCurrentDimZ;
308 uint32_t mCurrentCount;
309
310 void * getIDSafe() const;
311 void updateCacheInfo(sp<const Type> t);
312
313 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
314
315 void validateIsInt32();
316 void validateIsInt16();
317 void validateIsInt8();
318 void validateIsFloat32();
319 void validateIsObject();
320
321 virtual void updateFromNative();
322
323 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
Tim Murray9d24ae62013-08-30 12:17:14 -0700324 void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff,
325 uint32_t w, uint32_t h, uint32_t d);
Tim Murray84bf2b82012-10-31 16:03:16 -0700326
327public:
Tim Murray75e877d2013-09-11 14:45:20 -0700328
329 /**
330 * Return Type for the allocation.
331 * @return pointer to underlying Type
332 */
Stephen Hinesa180b7d2013-08-21 12:42:13 -0700333 sp<const Type> getType() const {
Tim Murray84bf2b82012-10-31 16:03:16 -0700334 return mType;
335 }
336
Tim Murray75e877d2013-09-11 14:45:20 -0700337 /**
338 * Propagate changes from one usage of the Allocation to other usages of the Allocation.
339 * @param[in] srcLocation source location with changes to propagate elsewhere
340 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700341 void syncAll(RsAllocationUsageType srcLocation);
342 void ioSendOutput();
343 void ioGetInput();
344
Tim Murray75e877d2013-09-11 14:45:20 -0700345 /**
346 * Generate a mipmap chain. This is only valid if the Type of the Allocation
347 * includes mipmaps. This function will generate a complete set of mipmaps
348 * from the top level LOD and place them into the script memory space. If
349 * the Allocation is also using other memory spaces, a call to
350 * syncAll(Allocation.USAGE_SCRIPT) is required.
351 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700352 void generateMipmaps();
Tim Murray509ea5c2012-11-13 11:56:40 -0800353
Tim Murray75e877d2013-09-11 14:45:20 -0700354 /**
355 * Copy an array into part of this Allocation.
356 * @param[in] off offset of first Element to be overwritten
357 * @param[in] count number of Elements to copy
358 * @param[in] data array from which to copy
359 */
Tim Murray0b93e302012-11-15 14:56:54 -0800360 void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
Tim Murray75e877d2013-09-11 14:45:20 -0700361
362 /**
363 * Copy part of an Allocation 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 Allocation from which to copy
367 * @param[in] dataOff offset of first Element in data to copy
368 */
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800369 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700370
Tim Murray75e877d2013-09-11 14:45:20 -0700371 /**
372 * Copy an array into part of this Allocation.
373 * @param[in] off offset of first Element to be overwritten
374 * @param[in] count number of Elements to copy
375 * @param[in] data array from which to copy
376 */
Tim Murray0b93e302012-11-15 14:56:54 -0800377 void copy1DRangeTo(uint32_t off, size_t count, void *data);
378
Tim Murray75e877d2013-09-11 14:45:20 -0700379 /**
380 * Copy entire array to an Allocation.
381 * @param[in] data array from which to copy
382 */
Tim Murray0b93e302012-11-15 14:56:54 -0800383 void copy1DFrom(const void* data);
Tim Murray75e877d2013-09-11 14:45:20 -0700384
385 /**
386 * Copy entire Allocation to an array.
387 * @param[in] data destination array
388 */
Tim Murray0b93e302012-11-15 14:56:54 -0800389 void copy1DTo(void* data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800390
Tim Murray75e877d2013-09-11 14:45:20 -0700391 /**
392 * Copy from an array into a rectangular region in this Allocation. The
393 * array is assumed to be tightly packed.
394 * @param[in] xoff X offset of region to update in this Allocation
395 * @param[in] yoff Y offset of region to update in this Allocation
396 * @param[in] w Width of region to update
397 * @param[in] h Height of region to update
398 * @param[in] data Array from which to copy
399 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700400 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800401 const void *data);
Tim Murray7b3e3092012-11-16 13:32:24 -0800402
Tim Murray75e877d2013-09-11 14:45:20 -0700403 /**
404 * Copy from this Allocation into a rectangular region in an array. The
405 * array is assumed to be tightly packed.
406 * @param[in] xoff X offset of region to copy from this Allocation
407 * @param[in] yoff Y offset of region to copy from this Allocation
408 * @param[in] w Width of region to update
409 * @param[in] h Height of region to update
410 * @param[in] data destination array
411 */
Tim Murray7b3e3092012-11-16 13:32:24 -0800412 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
413 void *data);
414
Tim Murray75e877d2013-09-11 14:45:20 -0700415 /**
416 * Copy from an Allocation into a rectangular region in this Allocation.
417 * @param[in] xoff X offset of region to update in this Allocation
418 * @param[in] yoff Y offset of region to update in this Allocation
419 * @param[in] w Width of region to update
420 * @param[in] h Height of region to update
421 * @param[in] data Allocation from which to copy
422 * @param[in] dataXoff X offset of region to copy from in data
423 * @param[in] dataYoff Y offset of region to copy from in data
424 */
Tim Murray0b93e302012-11-15 14:56:54 -0800425 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
426 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700427
Tim Murray75e877d2013-09-11 14:45:20 -0700428 /**
429 * Copy from a strided array into a rectangular region in this Allocation.
430 * @param[in] xoff X offset of region to update in this Allocation
431 * @param[in] yoff Y offset of region to update in this Allocation
432 * @param[in] w Width of region to update
433 * @param[in] h Height of region to update
434 * @param[in] data array from which to copy
435 * @param[in] stride stride of data in bytes
436 */
Tim Murray358747a2012-11-26 13:52:04 -0800437 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
438 const void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700439
440 /**
441 * Copy from a strided array into this Allocation.
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(const void *data, size_t stride);
446
Tim Murray75e877d2013-09-11 14:45:20 -0700447 /**
448 * Copy from a rectangular region in this Allocation into a strided array.
449 * @param[in] xoff X offset of region to update in this Allocation
450 * @param[in] yoff Y offset of region to update in this Allocation
451 * @param[in] w Width of region to update
452 * @param[in] h Height of region to update
453 * @param[in] data destination array
454 * @param[in] stride stride of data in bytes
455 */
Tim Murray358747a2012-11-26 13:52:04 -0800456 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
457 void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700458
459 /**
460 * Copy this Allocation into a strided array.
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(void *data, size_t stride);
465
Tim Murray75e877d2013-09-11 14:45:20 -0700466
467 /**
468 * Copy from an array into a 3D region in this Allocation. The
469 * array is assumed to be tightly packed.
470 * @param[in] xoff X offset of region to update in this Allocation
471 * @param[in] yoff Y offset of region to update in this Allocation
472 * @param[in] zoff Z offset of region to update in this Allocation
473 * @param[in] w Width of region to update
474 * @param[in] h Height of region to update
475 * @param[in] d Depth of region to update
476 * @param[in] data Array from which to copy
477 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700478 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
479 uint32_t h, uint32_t d, const void* data);
480
Tim Murray75e877d2013-09-11 14:45:20 -0700481 /**
482 * Copy from an Allocation into a 3D region in this Allocation.
483 * @param[in] xoff X offset of region to update in this Allocation
484 * @param[in] yoff Y offset of region to update in this Allocation
485 * @param[in] zoff Z offset of region to update in this Allocation
486 * @param[in] w Width of region to update
487 * @param[in] h Height of region to update
488 * @param[in] d Depth of region to update
489 * @param[in] data Allocation from which to copy
490 * @param[in] dataXoff X offset of region in data to copy from
491 * @param[in] dataYoff Y offset of region in data to copy from
492 * @param[in] dataZoff Z offset of region in data to copy from
493 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700494 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
495 uint32_t w, uint32_t h, uint32_t d,
496 sp<const Allocation> data,
497 uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700498
Tim Murray75e877d2013-09-11 14:45:20 -0700499 /**
500 * Creates an Allocation for use by scripts with a given Type.
501 * @param[in] rs Context to which the Allocation will belong
502 * @param[in] type Type of the Allocation
503 * @param[in] mips desired mipmap behavior for the Allocation
504 * @param[in] usage usage for the Allocation
505 * @return new Allocation
506 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700507 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
508 RsAllocationMipmapControl mips, uint32_t usage);
Tim Murray75e877d2013-09-11 14:45:20 -0700509
510 /**
511 * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use
512 * with RS_ALLOCATION_USAGE_SHARED.
513 * @param[in] rs Context to which the Allocation will belong
514 * @param[in] type Type of the Allocation
515 * @param[in] mips desired mipmap behavior for the Allocation
516 * @param[in] usage usage for the Allocation
517 * @param[in] pointer existing backing store to use for this Allocation if possible
518 * @return new Allocation
519 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700520 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
521 RsAllocationMipmapControl mips, uint32_t usage, void * pointer);
522
Tim Murray75e877d2013-09-11 14:45:20 -0700523 /**
524 * Creates an Allocation for use by scripts with a given Type with no mipmaps.
525 * @param[in] rs Context to which the Allocation will belong
526 * @param[in] type Type of the Allocation
527 * @param[in] usage usage for the Allocation
528 * @return new Allocation
529 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700530 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
531 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700532 /**
533 * Creates an Allocation with a specified number of given elements.
534 * @param[in] rs Context to which the Allocation will belong
535 * @param[in] e Element used in the Allocation
536 * @param[in] count Number of elements of the Allocation
537 * @param[in] usage usage for the Allocation
538 * @return new Allocation
539 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700540 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
541 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700542
543 /**
544 * Creates a 2D Allocation with a specified number of given elements.
545 * @param[in] rs Context to which the Allocation will belong
546 * @param[in] e Element used in the Allocation
547 * @param[in] x Width in Elements of the Allocation
548 * @param[in] y Height of the Allocation
549 * @param[in] usage usage for the Allocation
550 * @return new Allocation
551 */
Tim Murray684726c2012-11-14 11:57:42 -0800552 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
553 size_t x, size_t y,
554 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
555
Tim Murray84bf2b82012-10-31 16:03:16 -0700556
557};
558
Tim Murray75e877d2013-09-11 14:45:20 -0700559 /**
560 * An Element represents one item within an Allocation. An Element is roughly
561 * equivalent to a C type in a RenderScript kernel. Elements may be basic
562 * or complex. Some basic elements are:
563
564 * - A single float value (equivalent to a float in a kernel)
565 * - A four-element float vector (equivalent to a float4 in a kernel)
566 * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel)
567 * - A single signed 8-bit integer (equivalent to a char in a kernel)
568
569 * Basic Elements are comprised of a Element.DataType and a
570 * Element.DataKind. The DataType encodes C type information of an Element,
571 * while the DataKind encodes how that Element should be interpreted by a
572 * Sampler. Note that Allocation objects with DataKind USER cannot be used as
573 * input for a Sampler. In general, Allocation objects that are intended for
574 * use with a Sampler should use bitmap-derived Elements such as
575 * Element::RGBA_8888.
576 */
577
578
Tim Murray84bf2b82012-10-31 16:03:16 -0700579class Element : public BaseObj {
580public:
581 bool isComplex();
Tim Murray75e877d2013-09-11 14:45:20 -0700582
583 /**
584 * Elements could be simple, such as an int or a float, or a structure with
585 * multiple sub-elements, such as a collection of floats, float2,
586 * float4. This function returns zero for simple elements or the number of
587 * sub-elements otherwise.
588 * @return number of sub-elements
589 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700590 size_t getSubElementCount() {
591 return mVisibleElementMap.size();
592 }
593
Tim Murray75e877d2013-09-11 14:45:20 -0700594 /**
595 * For complex Elements, this returns the sub-element at a given index.
596 * @param[in] index index of sub-element
597 * @return sub-element
598 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700599 sp<const Element> getSubElement(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700600
601 /**
602 * For complex Elements, this returns the name of the sub-element at a given
603 * index.
604 * @param[in] index index of sub-element
605 * @return name of sub-element
606 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700607 const char * getSubElementName(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700608
609 /**
610 * For complex Elements, this returns the size of the sub-element at a given
611 * index.
612 * @param[in] index index of sub-element
613 * @return size of sub-element
614 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700615 size_t getSubElementArraySize(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700616
617 /**
618 * Returns the location of a sub-element within a complex Element.
619 * @param[in] index index of sub-element
620 * @return offset in bytes
621 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700622 uint32_t getSubElementOffsetBytes(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700623
624 /**
625 * Returns the data type used for the Element.
626 * @return data type
627 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700628 RsDataType getDataType() const {
629 return mType;
630 }
631
Tim Murray75e877d2013-09-11 14:45:20 -0700632 /**
633 * Returns the data kind used for the Element.
634 * @return data kind
635 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700636 RsDataKind getDataKind() const {
637 return mKind;
638 }
639
Tim Murray75e877d2013-09-11 14:45:20 -0700640 /**
641 * Returns the size in bytes of the Element.
642 * @return size in bytes
643 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700644 size_t getSizeBytes() const {
645 return mSizeBytes;
646 }
647
Tim Murray75e877d2013-09-11 14:45:20 -0700648 /**
649 * Returns the number of vector components for this Element.
650 * @return number of vector components
651 */
Tim Murray10913a52013-08-20 17:19:47 -0700652 uint32_t getVectorSize() const {
653 return mVectorSize;
654 }
655
Tim Murray75e877d2013-09-11 14:45:20 -0700656 /**
657 * Utility function for returning an Element containing a single bool.
658 * @param[in] rs RenderScript context
659 * @return Element
660 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700661 static sp<const Element> BOOLEAN(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700662 /**
663 * Utility function for returning an Element containing a single unsigned char.
664 * @param[in] rs RenderScript context
665 * @return Element
666 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700667 static sp<const Element> U8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700668 /**
669 * Utility function for returning an Element containing a single signed char.
670 * @param[in] rs RenderScript context
671 * @return Element
672 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700673 static sp<const Element> I8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700674 /**
675 * Utility function for returning an Element containing a single unsigned short.
676 * @param[in] rs RenderScript context
677 * @return Element
678 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700679 static sp<const Element> U16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700680 /**
681 * Utility function for returning an Element containing a single signed short.
682 * @param[in] rs RenderScript context
683 * @return Element
684 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700685 static sp<const Element> I16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700686 /**
687 * Utility function for returning an Element containing a single unsigned int.
688 * @param[in] rs RenderScript context
689 * @return Element
690 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700691 static sp<const Element> U32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700692 /**
693 * Utility function for returning an Element containing a single signed int.
694 * @param[in] rs RenderScript context
695 * @return Element
696 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700697 static sp<const Element> I32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700698 /**
699 * Utility function for returning an Element containing a single unsigned long long.
700 * @param[in] rs RenderScript context
701 * @return Element
702 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700703 static sp<const Element> U64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700704 /**
705 * Utility function for returning an Element containing a single signed long long.
706 * @param[in] rs RenderScript context
707 * @return Element
708 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700709 static sp<const Element> I64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700710 /**
711 * Utility function for returning an Element containing a single float.
712 * @param[in] rs RenderScript context
713 * @return Element
714 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700715 static sp<const Element> F32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700716 /**
717 * Utility function for returning an Element containing a single double.
718 * @param[in] rs RenderScript context
719 * @return Element
720 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700721 static sp<const Element> F64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700722 /**
723 * Utility function for returning an Element containing a single Element.
724 * @param[in] rs RenderScript context
725 * @return Element
726 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700727 static sp<const Element> ELEMENT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700728 /**
729 * Utility function for returning an Element containing a single Type.
730 * @param[in] rs RenderScript context
731 * @return Element
732 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700733 static sp<const Element> TYPE(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700734 /**
735 * Utility function for returning an Element containing a single Allocation.
736 * @param[in] rs RenderScript context
737 * @return Element
738 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700739 static sp<const Element> ALLOCATION(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700740 /**
741 * Utility function for returning an Element containing a single Sampler.
742 * @param[in] rs RenderScript context
743 * @return Element
744 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700745 static sp<const Element> SAMPLER(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700746 /**
747 * Utility function for returning an Element containing a single Script.
748 * @param[in] rs RenderScript context
749 * @return Element
750 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700751 static sp<const Element> SCRIPT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700752 /**
753 * Utility function for returning an Element containing an ALPHA_8 pixel.
754 * @param[in] rs RenderScript context
755 * @return Element
756 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700757 static sp<const Element> A_8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700758 /**
759 * Utility function for returning an Element containing an RGB_565 pixel.
760 * @param[in] rs RenderScript context
761 * @return Element
762 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700763 static sp<const Element> RGB_565(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700764 /**
765 * Utility function for returning an Element containing an RGB_888 pixel.
766 * @param[in] rs RenderScript context
767 * @return Element
768 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700769 static sp<const Element> RGB_888(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700770 /**
771 * Utility function for returning an Element containing an RGBA_5551 pixel.
772 * @param[in] rs RenderScript context
773 * @return Element
774 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700775 static sp<const Element> RGBA_5551(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700776 /**
777 * Utility function for returning an Element containing an RGBA_4444 pixel.
778 * @param[in] rs RenderScript context
779 * @return Element
780 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700781 static sp<const Element> RGBA_4444(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700782 /**
783 * Utility function for returning an Element containing an RGBA_8888 pixel.
784 * @param[in] rs RenderScript context
785 * @return Element
786 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700787 static sp<const Element> RGBA_8888(sp<RS> rs);
788
Tim Murray75e877d2013-09-11 14:45:20 -0700789 /**
790 * Utility function for returning an Element containing a float2.
791 * @param[in] rs RenderScript context
792 * @return Element
793 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700794 static sp<const Element> F32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700795 /**
796 * Utility function for returning an Element containing a float3.
797 * @param[in] rs RenderScript context
798 * @return Element
799 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700800 static sp<const Element> F32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700801 /**
802 * Utility function for returning an Element containing a float4.
803 * @param[in] rs RenderScript context
804 * @return Element
805 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700806 static sp<const Element> F32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700807 /**
808 * Utility function for returning an Element containing a double2.
809 * @param[in] rs RenderScript context
810 * @return Element
811 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700812 static sp<const Element> F64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700813 /**
814 * Utility function for returning an Element containing a double3.
815 * @param[in] rs RenderScript context
816 * @return Element
817 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700818 static sp<const Element> F64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700819 /**
820 * Utility function for returning an Element containing a double4.
821 * @param[in] rs RenderScript context
822 * @return Element
823 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700824 static sp<const Element> F64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700825 /**
826 * Utility function for returning an Element containing a uchar2.
827 * @param[in] rs RenderScript context
828 * @return Element
829 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700830 static sp<const Element> U8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700831 /**
832 * Utility function for returning an Element containing a uchar3.
833 * @param[in] rs RenderScript context
834 * @return Element
835 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700836 static sp<const Element> U8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700837 /**
838 * Utility function for returning an Element containing a uchar4.
839 * @param[in] rs RenderScript context
840 * @return Element
841 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700842 static sp<const Element> U8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700843 /**
844 * Utility function for returning an Element containing a char2.
845 * @param[in] rs RenderScript context
846 * @return Element
847 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700848 static sp<const Element> I8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700849 /**
850 * Utility function for returning an Element containing a char3.
851 * @param[in] rs RenderScript context
852 * @return Element
853 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700854 static sp<const Element> I8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700855 /**
856 * Utility function for returning an Element containing a char4.
857 * @param[in] rs RenderScript context
858 * @return Element
859 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700860 static sp<const Element> I8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700861 /**
862 * Utility function for returning an Element containing a ushort2.
863 * @param[in] rs RenderScript context
864 * @return Element
865 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700866 static sp<const Element> U16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700867 /**
868 * Utility function for returning an Element containing a ushort3.
869 * @param[in] rs RenderScript context
870 * @return Element
871 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700872 static sp<const Element> U16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700873 /**
874 * Utility function for returning an Element containing a ushort4.
875 * @param[in] rs RenderScript context
876 * @return Element
877 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700878 static sp<const Element> U16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700879 /**
880 * Utility function for returning an Element containing a short2.
881 * @param[in] rs RenderScript context
882 * @return Element
883 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700884 static sp<const Element> I16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700885 /**
886 * Utility function for returning an Element containing a short3.
887 * @param[in] rs RenderScript context
888 * @return Element
889 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700890 static sp<const Element> I16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700891 /**
892 * Utility function for returning an Element containing a short4.
893 * @param[in] rs RenderScript context
894 * @return Element
895 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700896 static sp<const Element> I16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700897 /**
898 * Utility function for returning an Element containing a uint2.
899 * @param[in] rs RenderScript context
900 * @return Element
901 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700902 static sp<const Element> U32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700903 /**
904 * Utility function for returning an Element containing a uint3.
905 * @param[in] rs RenderScript context
906 * @return Element
907 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700908 static sp<const Element> U32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700909 /**
910 * Utility function for returning an Element containing a uint4.
911 * @param[in] rs RenderScript context
912 * @return Element
913 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700914 static sp<const Element> U32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700915 /**
916 * Utility function for returning an Element containing an int2.
917 * @param[in] rs RenderScript context
918 * @return Element
919 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700920 static sp<const Element> I32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700921 /**
922 * Utility function for returning an Element containing an int3.
923 * @param[in] rs RenderScript context
924 * @return Element
925 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700926 static sp<const Element> I32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700927 /**
928 * Utility function for returning an Element containing an int4.
929 * @param[in] rs RenderScript context
930 * @return Element
931 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700932 static sp<const Element> I32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700933 /**
934 * Utility function for returning an Element containing a ulong2.
935 * @param[in] rs RenderScript context
936 * @return Element
937 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700938 static sp<const Element> U64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700939 /**
940 * Utility function for returning an Element containing a ulong3.
941 * @param[in] rs RenderScript context
942 * @return Element
943 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700944 static sp<const Element> U64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700945 /**
946 * Utility function for returning an Element containing a ulong4.
947 * @param[in] rs RenderScript context
948 * @return Element
949 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700950 static sp<const Element> U64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700951 /**
952 * Utility function for returning an Element containing a long2.
953 * @param[in] rs RenderScript context
954 * @return Element
955 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700956 static sp<const Element> I64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700957 /**
958 * Utility function for returning an Element containing a long3.
959 * @param[in] rs RenderScript context
960 * @return Element
961 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700962 static sp<const Element> I64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700963 /**
964 * Utility function for returning an Element containing a long4.
965 * @param[in] rs RenderScript context
966 * @return Element
967 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700968 static sp<const Element> I64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700969 /**
970 * Utility function for returning an Element containing a YUV pixel.
971 * @param[in] rs RenderScript context
972 * @return Element
973 */
Tim Murrayeb4426d2013-08-27 15:30:16 -0700974 static sp<const Element> YUV(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700975 /**
976 * Utility function for returning an Element containing an rs_matrix_4x4.
977 * @param[in] rs RenderScript context
978 * @return Element
979 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700980 static sp<const Element> MATRIX_4X4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700981 /**
982 * Utility function for returning an Element containing an rs_matrix_3x3.
983 * @param[in] rs RenderScript context
984 * @return Element
985 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700986 static sp<const Element> MATRIX_3X3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700987 /**
988 * Utility function for returning an Element containing an rs_matrix_2x2.
989 * @param[in] rs RenderScript context
990 * @return Element
991 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700992 static sp<const Element> MATRIX_2X2(sp<RS> rs);
993
Tim Murray84bf2b82012-10-31 16:03:16 -0700994 void updateFromNative();
Tim Murray75e877d2013-09-11 14:45:20 -0700995
996 /**
997 * Create an Element with a given DataType.
998 * @param[in] rs RenderScript context
999 * @param[in] dt data type
1000 * @return Element
1001 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001002 static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
Tim Murray75e877d2013-09-11 14:45:20 -07001003 /**
1004 * Create a vector Element with the given DataType
1005 * @param[in] rs RenderScript
1006 * @param[in] dt DataType
1007 * @param[in] size vector size
1008 * @return Element
1009 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001010 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
Tim Murray75e877d2013-09-11 14:45:20 -07001011 /**
1012 * Create an Element with a given DataType and DataKind.
1013 * @param[in] rs RenderScript context
1014 * @param[in] dt DataType
1015 * @param[in] dk DataKind
1016 * @return Element
1017 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001018 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
Tim Murray75e877d2013-09-11 14:45:20 -07001019
1020 /**
1021 * Returns true if the Element can interoperate with this Element.
1022 * @param[in] e Element to compare
1023 * @return true if Elements can interoperate
1024 */
Tim Murray10913a52013-08-20 17:19:47 -07001025 bool isCompatible(sp<const Element>e) const;
Tim Murray84bf2b82012-10-31 16:03:16 -07001026
Tim Murray75e877d2013-09-11 14:45:20 -07001027 /**
1028 * Builder class for producing complex elements with matching field and name
1029 * pairs. The builder starts empty. The order in which elements are added is
1030 * retained for the layout in memory.
1031 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001032 class Builder {
1033 private:
1034 sp<RS> mRS;
Tim Murray89daad62013-07-29 14:30:02 -07001035 std::vector<sp<Element> > mElements;
Tim Murrayab716362013-08-12 12:37:18 -07001036 std::vector<std::string> mElementNames;
Tim Murray89daad62013-07-29 14:30:02 -07001037 std::vector<uint32_t> mArraySizes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001038 bool mSkipPadding;
1039
1040 public:
1041 Builder(sp<RS> rs);
1042 ~Builder();
Tim Murrayab716362013-08-12 12:37:18 -07001043 void add(sp<Element> e, std::string &name, uint32_t arraySize = 1);
Tim Murray84bf2b82012-10-31 16:03:16 -07001044 sp<const Element> create();
1045 };
1046
Stephen Hines7d1b7572013-08-22 01:24:06 -07001047protected:
1048 Element(void *id, sp<RS> rs,
1049 std::vector<sp<Element> > &elements,
1050 std::vector<std::string> &elementNames,
1051 std::vector<uint32_t> &arraySizes);
1052 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
1053 Element(sp<RS> rs);
1054 virtual ~Element();
1055
Tim Murray84bf2b82012-10-31 16:03:16 -07001056private:
1057 void updateVisibleSubElements();
1058
Tim Murray89daad62013-07-29 14:30:02 -07001059 std::vector<sp<Element> > mElements;
Tim Murrayab716362013-08-12 12:37:18 -07001060 std::vector<std::string> mElementNames;
Tim Murray89daad62013-07-29 14:30:02 -07001061 std::vector<uint32_t> mArraySizes;
1062 std::vector<uint32_t> mVisibleElementMap;
1063 std::vector<uint32_t> mOffsetInBytes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001064
1065 RsDataType mType;
1066 RsDataKind mKind;
1067 bool mNormalized;
1068 size_t mSizeBytes;
1069 size_t mVectorSize;
1070};
1071
Stephen Hines2c7206e2012-11-14 19:47:01 -08001072class FieldPacker {
1073protected:
1074 unsigned char* mData;
1075 size_t mPos;
1076 size_t mLen;
1077
1078public:
1079 FieldPacker(size_t len)
Tim Murray89daad62013-07-29 14:30:02 -07001080 : mPos(0), mLen(len) {
1081 mData = new unsigned char[len];
1082 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001083
1084 virtual ~FieldPacker() {
1085 delete [] mData;
1086 }
1087
1088 void align(size_t v) {
1089 if ((v & (v - 1)) != 0) {
Tim Murrayab716362013-08-12 12:37:18 -07001090 // ALOGE("Non-power-of-two alignment: %zu", v);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001091 return;
1092 }
1093
1094 while ((mPos & (v - 1)) != 0) {
1095 mData[mPos++] = 0;
1096 }
1097 }
1098
1099 void reset() {
1100 mPos = 0;
1101 }
1102
1103 void reset(size_t i) {
1104 if (i >= mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001105 // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001106 return;
1107 }
1108 mPos = i;
1109 }
1110
1111 void skip(size_t i) {
1112 size_t res = mPos + i;
1113 if (res > mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001114 // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001115 return;
1116 }
1117 mPos = res;
1118 }
1119
1120 void* getData() const {
1121 return mData;
1122 }
1123
1124 size_t getLength() const {
1125 return mLen;
1126 }
1127
1128 template <typename T>
Tim Murray89daad62013-07-29 14:30:02 -07001129 void add(T t) {
Stephen Hines2c7206e2012-11-14 19:47:01 -08001130 align(sizeof(t));
1131 if (mPos + sizeof(t) <= mLen) {
1132 memcpy(&mData[mPos], &t, sizeof(t));
1133 mPos += sizeof(t);
1134 }
1135 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001136
1137 /*
Tim Murray89daad62013-07-29 14:30:02 -07001138 void add(rs_matrix4x4 m) {
1139 for (size_t i = 0; i < 16; i++) {
1140 add(m.m[i]);
1141 }
1142 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001143
Tim Murray89daad62013-07-29 14:30:02 -07001144 void add(rs_matrix3x3 m) {
1145 for (size_t i = 0; i < 9; i++) {
1146 add(m.m[i]);
1147 }
1148 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001149
Tim Murray89daad62013-07-29 14:30:02 -07001150 void add(rs_matrix2x2 m) {
1151 for (size_t i = 0; i < 4; i++) {
1152 add(m.m[i]);
1153 }
1154 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001155 */
1156
Tim Murray89daad62013-07-29 14:30:02 -07001157 void add(sp<BaseObj> obj) {
Stephen Hines43514cd2012-11-16 14:33:47 -08001158 if (obj != NULL) {
1159 add((uint32_t) (uintptr_t) obj->getID());
1160 } else {
1161 add((uint32_t) 0);
1162 }
1163 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001164};
1165
Tim Murray75e877d2013-09-11 14:45:20 -07001166/**
1167 * A Type describes the Element and dimensions used for an Allocation or a
1168 * parallel operation.
1169 *
1170 * A Type always includes an Element and an X dimension. A Type may be
1171 * multidimensional, up to three dimensions. A nonzero value in the Y or Z
1172 * dimensions indicates that the dimension is present. Note that a Type with
1173 * only a given X dimension and a Type with the same X dimension but Y = 1 are
1174 * not equivalent.
1175 *
1176 * A Type also supports inclusion of level of detail (LOD) or cube map
1177 * faces. LOD and cube map faces are booleans to indicate present or not
1178 * present.
1179 *
1180 * A Type also supports YUV format information to support an Allocation in a YUV
1181 * format. The YUV formats supported are YV12 and NV21.
1182 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001183class Type : public BaseObj {
1184protected:
1185 friend class Allocation;
1186
1187 uint32_t mDimX;
1188 uint32_t mDimY;
1189 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001190 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001191 bool mDimMipmaps;
1192 bool mDimFaces;
1193 size_t mElementCount;
1194 sp<const Element> mElement;
1195
Stephen Hines7d1b7572013-08-22 01:24:06 -07001196 Type(void *id, sp<RS> rs);
1197
Tim Murray84bf2b82012-10-31 16:03:16 -07001198 void calcElementCount();
1199 virtual void updateFromNative();
1200
1201public:
1202
Tim Murray75e877d2013-09-11 14:45:20 -07001203 /**
1204 * Returns the YUV format.
1205 * @return YUV format of the Allocation
1206 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001207 RSYuvFormat getYuvFormat() const {
1208 return mYuvFormat;
1209 }
1210
Tim Murray75e877d2013-09-11 14:45:20 -07001211 /**
1212 * Returns the Element of the Allocation.
1213 * @return YUV format of the Allocation
1214 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001215 sp<const Element> getElement() const {
1216 return mElement;
1217 }
1218
Tim Murray75e877d2013-09-11 14:45:20 -07001219 /**
1220 * Returns the X dimension of the Allocation.
1221 * @return X dimension of the allocation
1222 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001223 uint32_t getX() const {
1224 return mDimX;
1225 }
1226
Tim Murray75e877d2013-09-11 14:45:20 -07001227 /**
1228 * Returns the Y dimension of the Allocation.
1229 * @return Y dimension of the allocation
1230 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001231 uint32_t getY() const {
1232 return mDimY;
1233 }
1234
Tim Murray75e877d2013-09-11 14:45:20 -07001235 /**
1236 * Returns the Z dimension of the Allocation.
1237 * @return Z dimension of the allocation
1238 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001239 uint32_t getZ() const {
1240 return mDimZ;
1241 }
1242
Tim Murray75e877d2013-09-11 14:45:20 -07001243 /**
1244 * Returns true if the Allocation has mipmaps.
1245 * @return true if the Allocation has mipmaps
1246 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001247 bool hasMipmaps() const {
1248 return mDimMipmaps;
1249 }
1250
Tim Murray75e877d2013-09-11 14:45:20 -07001251 /**
1252 * Returns true if the Allocation is a cube map
1253 * @return true if the Allocation is a cube map
1254 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001255 bool hasFaces() const {
1256 return mDimFaces;
1257 }
1258
Tim Murray75e877d2013-09-11 14:45:20 -07001259 /**
1260 * Returns number of accessible Elements in the Allocation
1261 * @return number of accessible Elements in the Allocation
1262 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001263 size_t getCount() const {
1264 return mElementCount;
1265 }
1266
Tim Murray75e877d2013-09-11 14:45:20 -07001267 /**
1268 * Returns size in bytes of all Elements in the Allocation
1269 * @return size in bytes of all Elements in the Allocation
1270 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001271 size_t getSizeBytes() const {
1272 return mElementCount * mElement->getSizeBytes();
1273 }
1274
Tim Murray75e877d2013-09-11 14:45:20 -07001275 /**
1276 * Creates a new Type with the given Element and dimensions.
1277 * @param[in] rs RenderScript context
1278 * @param[in] e Element
1279 * @param[in] dimX X dimension
1280 * @param[in] dimY Y dimension
1281 * @param[in] dimZ Z dimension
1282 * @return new Type
1283 */
Tim Murray96267c22013-02-12 11:25:12 -08001284 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 -07001285
1286 class Builder {
1287 protected:
1288 sp<RS> mRS;
1289 uint32_t mDimX;
1290 uint32_t mDimY;
1291 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001292 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001293 bool mDimMipmaps;
1294 bool mDimFaces;
1295 sp<const Element> mElement;
1296
1297 public:
1298 Builder(sp<RS> rs, sp<const Element> e);
1299
1300 void setX(uint32_t value);
Stephen Hines7d1b7572013-08-22 01:24:06 -07001301 void setY(uint32_t value);
Tim Murrayeb4426d2013-08-27 15:30:16 -07001302 void setZ(uint32_t value);
1303 void setYuvFormat(RSYuvFormat format);
Tim Murray84bf2b82012-10-31 16:03:16 -07001304 void setMipmaps(bool value);
1305 void setFaces(bool value);
1306 sp<const Type> create();
1307 };
1308
1309};
1310
Tim Murray75e877d2013-09-11 14:45:20 -07001311/**
1312 * The parent class for all executable Scripts. This should not be used by applications.
1313 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001314class Script : public BaseObj {
1315private:
1316
1317protected:
1318 Script(void *id, sp<RS> rs);
1319 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
1320 const void *v, size_t) const;
1321 void bindAllocation(sp<Allocation> va, uint32_t slot) const;
1322 void setVar(uint32_t index, const void *, size_t len) const;
1323 void setVar(uint32_t index, sp<const BaseObj> o) const;
1324 void invoke(uint32_t slot, const void *v, size_t len) const;
1325
1326
1327 void invoke(uint32_t slot) const {
1328 invoke(slot, NULL, 0);
1329 }
1330 void setVar(uint32_t index, float v) const {
1331 setVar(index, &v, sizeof(v));
1332 }
1333 void setVar(uint32_t index, double v) const {
1334 setVar(index, &v, sizeof(v));
1335 }
1336 void setVar(uint32_t index, int32_t v) const {
1337 setVar(index, &v, sizeof(v));
1338 }
1339 void setVar(uint32_t index, int64_t v) const {
1340 setVar(index, &v, sizeof(v));
1341 }
1342 void setVar(uint32_t index, bool v) const {
1343 setVar(index, &v, sizeof(v));
1344 }
1345
1346public:
1347 class FieldBase {
1348 protected:
1349 sp<const Element> mElement;
1350 sp<Allocation> mAllocation;
1351
1352 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
1353
1354 public:
1355 sp<const Element> getElement() {
1356 return mElement;
1357 }
1358
1359 sp<const Type> getType() {
1360 return mAllocation->getType();
1361 }
1362
1363 sp<const Allocation> getAllocation() {
1364 return mAllocation;
1365 }
1366
1367 //void updateAllocation();
1368 };
1369};
1370
Tim Murray75e877d2013-09-11 14:45:20 -07001371/**
1372 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only.
1373 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001374class ScriptC : public Script {
1375protected:
1376 ScriptC(sp<RS> rs,
1377 const void *codeTxt, size_t codeLength,
1378 const char *cachedName, size_t cachedNameLength,
1379 const char *cacheDir, size_t cacheDirLength);
1380
1381};
1382
Tim Murray75e877d2013-09-11 14:45:20 -07001383/**
1384 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of
1385 * basic functions. This is not intended to be used directly.
1386 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001387class ScriptIntrinsic : public Script {
1388 protected:
Tim Murray10913a52013-08-20 17:19:47 -07001389 sp<const Element> mElement;
Tim Murray3cd44af2012-11-14 11:25:27 -08001390 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001391 virtual ~ScriptIntrinsic();
Tim Murray7f0d5682012-11-08 16:35:24 -08001392};
1393
Tim Murray75e877d2013-09-11 14:45:20 -07001394/**
1395 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming
1396 * r,g,b values are use as normalized x,y,z coordinates into a 3D
1397 * allocation. The 8 nearest values are sampled and linearly interpolated. The
1398 * result is placed in the output.
1399 */
Tim Murray89daad62013-07-29 14:30:02 -07001400class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001401 private:
Tim Murray89daad62013-07-29 14:30:02 -07001402 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001403 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001404 /**
1405 * Supported Element types are U8_4. Default lookup table is identity.
1406 * @param[in] rs RenderScript context
1407 * @param[in] e Element
1408 * @return new ScriptIntrinsic
1409 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001410 static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001411
1412 /**
1413 * Launch the intrinsic.
1414 * @param[in] ain input Allocation
1415 * @param[in] aout output Allocation
1416 */
Tim Murray89daad62013-07-29 14:30:02 -07001417 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001418
1419 /**
1420 * Sets the lookup table. The lookup table must use the same Element as the
1421 * intrinsic.
1422 * @param[in] lut new lookup table
1423 */
Tim Murray89daad62013-07-29 14:30:02 -07001424 void setLUT(sp<Allocation> lut);
1425};
1426
Tim Murray75e877d2013-09-11 14:45:20 -07001427/**
1428 * Intrinsic kernel for blending two Allocations.
1429 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001430class ScriptIntrinsicBlend : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001431 private:
Tim Murray89daad62013-07-29 14:30:02 -07001432 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001433 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001434 /**
1435 * Supported Element types are U8_4.
1436 * @param[in] rs RenderScript context
1437 * @param[in] e Element
1438 * @return new ScriptIntrinsicBlend
1439 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001440 static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001441 /**
1442 * sets dst = {0, 0, 0, 0}
1443 * @param[in] in input Allocation
1444 * @param[in] out output Allocation
1445 */
1446 void forEachClear(sp<Allocation> in, sp<Allocation> out);
1447 /**
1448 * Sets dst = src
1449 * @param[in] in input Allocation
1450 * @param[in] out output Allocation
1451 */
1452 void forEachSrc(sp<Allocation> in, sp<Allocation> out);
1453 /**
1454 * Sets dst = dst (NOP)
1455 * @param[in] in input Allocation
1456 * @param[in] out output Allocation
1457 */
1458 void forEachDst(sp<Allocation> in, sp<Allocation> out);
1459 /**
1460 * Sets dst = src + dst * (1.0 - src.a)
1461 * @param[in] in input Allocation
1462 * @param[in] out output Allocation
1463 */
1464 void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
1465 /**
1466 * Sets dst = dst + src * (1.0 - dst.a)
1467 * @param[in] in input Allocation
1468 * @param[in] out output Allocation
1469 */
1470 void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
1471 /**
1472 * Sets dst = src * dst.a
1473 * @param[in] in input Allocation
1474 * @param[in] out output Allocation
1475 */
1476 void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
1477 /**
1478 * Sets dst = dst * src.a
1479 * @param[in] in input Allocation
1480 * @param[in] out output Allocation
1481 */
1482 void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
1483 /**
1484 * Sets dst = src * (1.0 - dst.a)
1485 * @param[in] in input Allocation
1486 * @param[in] out output Allocation
1487 */
1488 void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
1489 /**
1490 * Sets dst = dst * (1.0 - src.a)
1491 * @param[in] in input Allocation
1492 * @param[in] out output Allocation
1493 */
1494 void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
1495 /**
1496 * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
1497 * @param[in] in input Allocation
1498 * @param[in] out output Allocation
1499 */
1500 void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
1501 /**
1502 * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
1503 * @param[in] in input Allocation
1504 * @param[in] out output Allocation
1505 */
1506 void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
1507 /**
1508 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
1509 * @param[in] in input Allocation
1510 * @param[in] out output Allocation
1511 */
1512 void forEachXor(sp<Allocation> in, sp<Allocation> out);
1513 /**
1514 * Sets dst = src * dst
1515 * @param[in] in input Allocation
1516 * @param[in] out output Allocation
1517 */
1518 void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
1519 /**
1520 * Sets dst = min(src + dst, 1.0)
1521 * @param[in] in input Allocation
1522 * @param[in] out output Allocation
1523 */
1524 void forEachAdd(sp<Allocation> in, sp<Allocation> out);
1525 /**
1526 * Sets dst = max(dst - src, 0.0)
1527 * @param[in] in input Allocation
1528 * @param[in] out output Allocation
1529 */
1530 void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
Tim Murray7f0d5682012-11-08 16:35:24 -08001531};
Tim Murray84bf2b82012-10-31 16:03:16 -07001532
Tim Murray75e877d2013-09-11 14:45:20 -07001533/**
1534 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified
1535 * radius to all elements of an Allocation.
1536 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001537class ScriptIntrinsicBlur : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001538 private:
Tim Murray89daad62013-07-29 14:30:02 -07001539 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001540 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001541 /**
1542 * Supported Element types are U8 and U8_4.
1543 * @param[in] rs RenderScript context
1544 * @param[in] e Element
1545 * @return new ScriptIntrinsicBlur
1546 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001547 static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001548 /**
1549 * Sets the input of the blur.
1550 * @param[in] in input Allocation
1551 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001552 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001553 /**
1554 * Runs the intrinsic.
1555 * @param[in] output Allocation
1556 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001557 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001558 /**
1559 * Sets the radius of the blur. The supported range is 0 < radius <= 25.
1560 * @param[in] radius radius of the blur
1561 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001562 void setRadius(float radius);
1563};
1564
Tim Murray75e877d2013-09-11 14:45:20 -07001565/**
1566 * Intrinsic for applying a color matrix to allocations. This has the
1567 * same effect as loading each element and converting it to a
1568 * F32_N, multiplying the result by the 4x4 color matrix
1569 * as performed by rsMatrixMultiply() and writing it to the output
1570 * after conversion back to U8_N or F32_N.
1571 */
Tim Murray89daad62013-07-29 14:30:02 -07001572class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001573 private:
Tim Murray89daad62013-07-29 14:30:02 -07001574 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001575 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001576 /**
1577 * Creates a new intrinsic.
1578 * @param[in] rs RenderScript context
1579 * @return new ScriptIntrinsicColorMatrix
1580 */
Tim Murrayaae73c92013-09-03 17:05:46 -07001581 static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001582 /**
1583 * Applies the color matrix. Supported types are U8 and F32 with
1584 * vector lengths between 1 and 4.
1585 * @param[in] in input Allocation
1586 * @param[out] out output Allocation
1587 */
Tim Murray89daad62013-07-29 14:30:02 -07001588 void forEach(sp<Allocation> in, sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001589 /**
1590 * Set the value to be added after the color matrix has been
1591 * applied. The default value is {0, 0, 0, 0}.
1592 * @param[in] add float[4] of values
1593 */
Tim Murray10913a52013-08-20 17:19:47 -07001594 void setAdd(float* add);
Tim Murray75e877d2013-09-11 14:45:20 -07001595
1596 /**
1597 * Set the color matrix which will be applied to each cell of the
1598 * image. The alpha channel will be copied.
1599 *
1600 * @param[in] m float[9] of values
1601 */
Tim Murray89daad62013-07-29 14:30:02 -07001602 void setColorMatrix3(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001603 /**
1604 * Set the color matrix which will be applied to each cell of the
1605 * image.
1606 *
1607 * @param[in] m float[16] of values
1608 */
Tim Murray89daad62013-07-29 14:30:02 -07001609 void setColorMatrix4(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001610 /**
1611 * Set a color matrix to convert from RGB to luminance. The alpha
1612 * channel will be a copy.
1613 */
Tim Murray89daad62013-07-29 14:30:02 -07001614 void setGreyscale();
Tim Murray75e877d2013-09-11 14:45:20 -07001615 /**
1616 * Set the matrix to convert from RGB to YUV with a direct copy of
1617 * the 4th channel.
1618 */
Tim Murray89daad62013-07-29 14:30:02 -07001619 void setRGBtoYUV();
Tim Murray75e877d2013-09-11 14:45:20 -07001620 /**
1621 * Set the matrix to convert from YUV to RGB with a direct copy of
1622 * the 4th channel.
1623 */
Tim Murray89daad62013-07-29 14:30:02 -07001624 void setYUVtoRGB();
1625};
1626
Tim Murray75e877d2013-09-11 14:45:20 -07001627/**
1628 * Intrinsic for applying a 3x3 convolve to an allocation.
1629 */
Tim Murray89daad62013-07-29 14:30:02 -07001630class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001631 private:
Tim Murray89daad62013-07-29 14:30:02 -07001632 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001633 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001634 /**
1635 * Supported types U8 and F32 with vector lengths between 1 and
1636 * 4. The default convolution kernel is the identity.
1637 * @param[in] rs RenderScript context
1638 * @param[in] e Element
1639 * @return new ScriptIntrinsicConvolve3x3
1640 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001641 static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001642 /**
1643 * Sets input for intrinsic.
1644 * @param[in] in input Allocation
1645 */
Tim Murray89daad62013-07-29 14:30:02 -07001646 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001647 /**
1648 * Launches the intrinsic.
1649 * @param[in] out output Allocation
1650 */
Tim Murray89daad62013-07-29 14:30:02 -07001651 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001652 /**
1653 * Sets convolution kernel.
1654 * @param[in] v float[9] of values
1655 */
Tim Murray89daad62013-07-29 14:30:02 -07001656 void setCoefficients(float* v);
1657};
1658
Tim Murray75e877d2013-09-11 14:45:20 -07001659/**
1660 * Intrinsic for applying a 5x5 convolve to an allocation.
1661 */
Tim Murray89daad62013-07-29 14:30:02 -07001662class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001663 private:
Tim Murray89daad62013-07-29 14:30:02 -07001664 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001665 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001666 /**
1667 * Supported types U8 and F32 with vector lengths between 1 and
1668 * 4. The default convolution kernel is the identity.
1669 * @param[in] rs RenderScript context
1670 * @param[in] e Element
1671 * @return new ScriptIntrinsicConvolve5x5
1672 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001673 static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001674 /**
1675 * Sets input for intrinsic.
1676 * @param[in] in input Allocation
1677 */
Tim Murray89daad62013-07-29 14:30:02 -07001678 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001679 /**
1680 * Launches the intrinsic.
1681 * @param[in] out output Allocation
1682 */
Tim Murray89daad62013-07-29 14:30:02 -07001683 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001684 /**
1685 * Sets convolution kernel.
1686 * @param[in] v float[25] of values
1687 */
Tim Murray89daad62013-07-29 14:30:02 -07001688 void setCoefficients(float* v);
1689};
1690
Tim Murray75e877d2013-09-11 14:45:20 -07001691/**
1692 * Intrinsic for computing a histogram.
1693 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001694class ScriptIntrinsicHistogram : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001695 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001696 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
Tim Murray10913a52013-08-20 17:19:47 -07001697 sp<Allocation> mOut;
Tim Murray21fa7a02013-08-15 16:25:03 -07001698 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001699 /**
1700 * Create an intrinsic for calculating the histogram of an uchar
1701 * or uchar4 image.
1702 *
1703 * Supported elements types are U8_4, U8_3, U8_2, and U8.
1704 *
1705 * @param[in] rs The RenderScript context
1706 * @param[in] e Element type for inputs
1707 *
1708 * @return ScriptIntrinsicHistogram
1709 */
Tim Murray10913a52013-08-20 17:19:47 -07001710 static sp<ScriptIntrinsicHistogram> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001711 /**
1712 * Set the output of the histogram. 32 bit integer types are
1713 * supported.
1714 *
1715 * @param[in] aout The output allocation
1716 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001717 void setOutput(sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001718 /**
1719 * Set the coefficients used for the dot product calculation. The
1720 * default is {0.299f, 0.587f, 0.114f, 0.f}.
1721 *
1722 * Coefficients must be >= 0 and sum to 1.0 or less.
1723 *
1724 * @param[in] r Red coefficient
1725 * @param[in] g Green coefficient
1726 * @param[in] b Blue coefficient
1727 * @param[in] a Alpha coefficient
1728 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001729 void setDotCoefficients(float r, float g, float b, float a);
Tim Murray75e877d2013-09-11 14:45:20 -07001730 /**
1731 * Process an input buffer and place the histogram into the output
1732 * allocation. The output allocation may be a narrower vector size
1733 * than the input. In this case the vector size of the output is
1734 * used to determine how many of the input channels are used in
1735 * the computation. This is useful if you have an RGBA input
1736 * buffer but only want the histogram for RGB.
1737 *
1738 * 1D and 2D input allocations are supported.
1739 *
1740 * @param[in] ain The input image
1741 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001742 void forEach(sp<Allocation> ain);
Tim Murray75e877d2013-09-11 14:45:20 -07001743 /**
1744 * Process an input buffer and place the histogram into the output
1745 * allocation. The dot product of the input channel and the
1746 * coefficients from 'setDotCoefficients' are used to calculate
1747 * the output values.
1748 *
1749 * 1D and 2D input allocations are supported.
1750 *
1751 * @param ain The input image
1752 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001753 void forEach_dot(sp<Allocation> ain);
1754};
1755
Tim Murray75e877d2013-09-11 14:45:20 -07001756/**
1757 * Intrinsic for applying a per-channel lookup table. Each channel of
1758 * the input has an independant lookup table. The tables are 256
1759 * entries in size and can cover the full value range of U8_4.
1760 **/
Tim Murrayb27b1812013-08-05 14:00:40 -07001761class ScriptIntrinsicLUT : public ScriptIntrinsic {
1762 private:
1763 sp<Allocation> LUT;
1764 bool mDirty;
1765 unsigned char mCache[1024];
Tim Murray2acce992013-08-28 14:23:31 -07001766 void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray21fa7a02013-08-15 16:25:03 -07001767 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001768
Tim Murray89daad62013-07-29 14:30:02 -07001769 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001770 /**
1771 * Supported elements types are U8_4.
1772 *
1773 * The defaults tables are identity.
1774 *
1775 * @param[in] rs The RenderScript context
1776 * @param[in] e Element type for intputs and outputs
1777 *
1778 * @return ScriptIntrinsicLUT
1779 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001780 static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001781 /**
1782 * Invoke the kernel and apply the lookup to each cell of ain and
1783 * copy to aout.
1784 *
1785 * @param[in] ain Input allocation
1786 * @param[in] aout Output allocation
1787 */
Tim Murray89daad62013-07-29 14:30:02 -07001788 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001789 /**
1790 * Sets entries in LUT for the red channel.
1791 * @param[in] base base of region to update
1792 * @param[in] length length of region to update
1793 * @param[in] lutValues LUT values to use
1794 */
Tim Murray2acce992013-08-28 14:23:31 -07001795 void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001796 /**
1797 * Sets entries in LUT for the green channel.
1798 * @param[in] base base of region to update
1799 * @param[in] length length of region to update
1800 * @param[in] lutValues LUT values to use
1801 */
Tim Murray2acce992013-08-28 14:23:31 -07001802 void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001803 /**
1804 * Sets entries in LUT for the blue channel.
1805 * @param[in] base base of region to update
1806 * @param[in] length length of region to update
1807 * @param[in] lutValues LUT values to use
1808 */
Tim Murray2acce992013-08-28 14:23:31 -07001809 void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001810 /**
1811 * Sets entries in LUT for the alpha channel.
1812 * @param[in] base base of region to update
1813 * @param[in] length length of region to update
1814 * @param[in] lutValues LUT values to use
1815 */
Tim Murray2acce992013-08-28 14:23:31 -07001816 void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murrayb27b1812013-08-05 14:00:40 -07001817 virtual ~ScriptIntrinsicLUT();
1818};
1819
Tim Murray75e877d2013-09-11 14:45:20 -07001820/**
1821 * Intrinsic for converting an Android YUV buffer to RGB.
1822 *
1823 * The input allocation should be supplied in a supported YUV format
1824 * as a YUV element Allocation. The output is RGBA; the alpha channel
1825 * will be set to 255.
1826 */
Tim Murray89daad62013-07-29 14:30:02 -07001827class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001828 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001829 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001830 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001831 /**
1832 * Create an intrinsic for converting YUV to RGB.
1833 *
1834 * Supported elements types are U8_4.
1835 *
1836 * @param[in] rs The RenderScript context
1837 * @param[in] e Element type for output
1838 *
1839 * @return ScriptIntrinsicYuvToRGB
1840 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001841 static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001842 /**
1843 * Set the input YUV allocation.
1844 *
1845 * @param[in] ain The input allocation.
1846 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001847 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001848
1849 /**
1850 * Convert the image to RGB.
1851 *
1852 * @param[in] aout Output allocation. Must match creation element
1853 * type.
1854 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001855 void forEach(sp<Allocation> out);
Tim Murray89daad62013-07-29 14:30:02 -07001856
1857};
Tim Murrayb27b1812013-08-05 14:00:40 -07001858
Tim Murray75e877d2013-09-11 14:45:20 -07001859/**
1860 * Sampler object that defines how Allocations can be read as textures
1861 * within a kernel. Samplers are used in conjunction with the rsSample
1862 * runtime function to return values from normalized coordinates.
1863 *
1864 * Any Allocation used with a Sampler must have been created with
1865 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an
1866 * Allocation that was not created with
1867 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined.
1868 **/
Tim Murray729b6fe2013-07-23 16:20:42 -07001869 class Sampler : public BaseObj {
1870 private:
1871 Sampler(sp<RS> rs, void* id);
1872 RsSamplerValue mMin;
1873 RsSamplerValue mMag;
1874 RsSamplerValue mWrapS;
1875 RsSamplerValue mWrapT;
1876 RsSamplerValue mWrapR;
1877 float mAniso;
1878
1879 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001880 /**
1881 * Creates a non-standard Sampler.
1882 * @param[in] rs RenderScript context
1883 * @param[in] min minification
1884 * @param[in] mag magnification
1885 * @param[in] wrapS S wrapping mode
1886 * @param[in] wrapT T wrapping mode
1887 * @param[in] anisotropy anisotropy setting
1888 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001889 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
1890
Tim Murray75e877d2013-09-11 14:45:20 -07001891 /**
1892 * @return minification setting for the sampler
1893 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001894 RsSamplerValue getMinification();
Tim Murray75e877d2013-09-11 14:45:20 -07001895 /**
1896 * @return magnification setting for the sampler
1897 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001898 RsSamplerValue getMagnification();
Tim Murray75e877d2013-09-11 14:45:20 -07001899 /**
1900 * @return S wrapping mode for the sampler
1901 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001902 RsSamplerValue getWrapS();
Tim Murray75e877d2013-09-11 14:45:20 -07001903 /**
1904 * @return T wrapping mode for the sampler
1905 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001906 RsSamplerValue getWrapT();
Tim Murray75e877d2013-09-11 14:45:20 -07001907 /**
1908 * @return anisotropy setting for the sampler
1909 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001910 float getAnisotropy();
1911
Tim Murray75e877d2013-09-11 14:45:20 -07001912 /**
1913 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1914 * clamp.
1915 *
1916 * @param rs Context to which the sampler will belong.
1917 *
1918 * @return Sampler
1919 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001920 sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001921 /**
1922 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1923 * clamp.
1924 *
1925 * @param rs Context to which the sampler will belong.
1926 *
1927 * @return Sampler
1928 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001929 sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001930 /**
1931 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
1932 * wrap modes set to clamp.
1933 *
1934 * @param rs Context to which the sampler will belong.
1935 *
1936 * @return Sampler
1937 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001938 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001939 /**
1940 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1941 * wrap.
1942 *
1943 * @param rs Context to which the sampler will belong.
1944 *
1945 * @return Sampler
1946 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001947 sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001948 /**
1949 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1950 * wrap.
1951 *
1952 * @param rs Context to which the sampler will belong.
1953 *
1954 * @return Sampler
1955 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001956 sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001957 /**
1958 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
1959 * wrap modes set to wrap.
1960 *
1961 * @param rs Context to which the sampler will belong.
1962 *
1963 * @return Sampler
1964 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001965 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001966 /**
1967 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1968 * mirrored repeat.
1969 *
1970 * @param rs Context to which the sampler will belong.
1971 *
1972 * @return Sampler
1973 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001974 sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001975 /**
1976 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1977 * mirrored repeat.
1978 *
1979 * @param rs Context to which the sampler will belong.
1980 *
1981 * @return Sampler
1982 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001983 sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001984 /**
1985 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1986 * mirrored repeat.
1987 *
1988 * @param rs Context to which the sampler will belong.
1989 *
1990 * @return Sampler
1991 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001992 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
1993
1994};
1995
Stephen Hinesd10412f2013-08-29 18:27:21 -07001996class Byte2 {
1997 public:
1998 int8_t x, y;
1999
2000 Byte2(int8_t initX, int8_t initY)
2001 : x(initX), y(initY) {}
2002 Byte2() : x(0), y(0) {}
2003};
2004
2005class Byte3 {
2006 public:
2007 int8_t x, y, z;
2008
2009 Byte3(int8_t initX, int8_t initY, int8_t initZ)
2010 : x(initX), y(initY), z(initZ) {}
2011 Byte3() : x(0), y(0), z(0) {}
2012};
2013
2014class Byte4 {
2015 public:
2016 int8_t x, y, z, w;
2017
2018 Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
2019 : x(initX), y(initY), z(initZ), w(initW) {}
2020 Byte4() : x(0), y(0), z(0), w(0) {}
2021};
2022
2023class UByte2 {
2024 public:
2025 uint8_t x, y;
2026
2027 UByte2(uint8_t initX, uint8_t initY)
2028 : x(initX), y(initY) {}
2029 UByte2() : x(0), y(0) {}
2030};
2031
2032class UByte3 {
2033 public:
2034 uint8_t x, y, z;
2035
2036 UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
2037 : x(initX), y(initY), z(initZ) {}
2038 UByte3() : x(0), y(0), z(0) {}
2039};
2040
2041class UByte4 {
2042 public:
2043 uint8_t x, y, z, w;
2044
2045 UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
2046 : x(initX), y(initY), z(initZ), w(initW) {}
2047 UByte4() : x(0), y(0), z(0), w(0) {}
2048};
2049
2050class Short2 {
2051 public:
2052 short x, y;
2053
2054 Short2(short initX, short initY)
2055 : x(initX), y(initY) {}
2056 Short2() : x(0), y(0) {}
2057};
2058
2059class Short3 {
2060 public:
2061 short x, y, z;
2062
2063 Short3(short initX, short initY, short initZ)
2064 : x(initX), y(initY), z(initZ) {}
2065 Short3() : x(0), y(0), z(0) {}
2066};
2067
2068class Short4 {
2069 public:
2070 short x, y, z, w;
2071
2072 Short4(short initX, short initY, short initZ, short initW)
2073 : x(initX), y(initY), z(initZ), w(initW) {}
2074 Short4() : x(0), y(0), z(0), w(0) {}
2075};
2076
2077class UShort2 {
2078 public:
2079 uint16_t x, y;
2080
2081 UShort2(uint16_t initX, uint16_t initY)
2082 : x(initX), y(initY) {}
2083 UShort2() : x(0), y(0) {}
2084};
2085
2086class UShort3 {
2087 public:
2088 uint16_t x, y, z;
2089
2090 UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
2091 : x(initX), y(initY), z(initZ) {}
2092 UShort3() : x(0), y(0), z(0) {}
2093};
2094
2095class UShort4 {
2096 public:
2097 uint16_t x, y, z, w;
2098
2099 UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
2100 : x(initX), y(initY), z(initZ), w(initW) {}
2101 UShort4() : x(0), y(0), z(0), w(0) {}
2102};
2103
2104class Int2 {
2105 public:
2106 int x, y;
2107
2108 Int2(int initX, int initY)
2109 : x(initX), y(initY) {}
2110 Int2() : x(0), y(0) {}
2111};
2112
2113class Int3 {
2114 public:
2115 int x, y, z;
2116
2117 Int3(int initX, int initY, int initZ)
2118 : x(initX), y(initY), z(initZ) {}
2119 Int3() : x(0), y(0), z(0) {}
2120};
2121
2122class Int4 {
2123 public:
2124 int x, y, z, w;
2125
2126 Int4(int initX, int initY, int initZ, int initW)
2127 : x(initX), y(initY), z(initZ), w(initW) {}
2128 Int4() : x(0), y(0), z(0), w(0) {}
2129};
2130
2131class UInt2 {
2132 public:
2133 uint32_t x, y;
2134
2135 UInt2(uint32_t initX, uint32_t initY)
2136 : x(initX), y(initY) {}
2137 UInt2() : x(0), y(0) {}
2138};
2139
2140class UInt3 {
2141 public:
2142 uint32_t x, y, z;
2143
2144 UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
2145 : x(initX), y(initY), z(initZ) {}
2146 UInt3() : x(0), y(0), z(0) {}
2147};
2148
2149class UInt4 {
2150 public:
2151 uint32_t x, y, z, w;
2152
2153 UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
2154 : x(initX), y(initY), z(initZ), w(initW) {}
2155 UInt4() : x(0), y(0), z(0), w(0) {}
2156};
2157
2158class Long2 {
2159 public:
2160 int64_t x, y;
2161
2162 Long2(int64_t initX, int64_t initY)
2163 : x(initX), y(initY) {}
2164 Long2() : x(0), y(0) {}
2165};
2166
2167class Long3 {
2168 public:
2169 int64_t x, y, z;
2170
2171 Long3(int64_t initX, int64_t initY, int64_t initZ)
2172 : x(initX), y(initY), z(initZ) {}
2173 Long3() : x(0), y(0), z(0) {}
2174};
2175
2176class Long4 {
2177 public:
2178 int64_t x, y, z, w;
2179
2180 Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
2181 : x(initX), y(initY), z(initZ), w(initW) {}
2182 Long4() : x(0), y(0), z(0), w(0) {}
2183};
2184
2185class ULong2 {
2186 public:
2187 uint64_t x, y;
2188
2189 ULong2(uint64_t initX, uint64_t initY)
2190 : x(initX), y(initY) {}
2191 ULong2() : x(0), y(0) {}
2192};
2193
2194class ULong3 {
2195 public:
2196 uint64_t x, y, z;
2197
2198 ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
2199 : x(initX), y(initY), z(initZ) {}
2200 ULong3() : x(0), y(0), z(0) {}
2201};
2202
2203class ULong4 {
2204 public:
2205 uint64_t x, y, z, w;
2206
2207 ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
2208 : x(initX), y(initY), z(initZ), w(initW) {}
2209 ULong4() : x(0), y(0), z(0), w(0) {}
2210};
2211
2212class Float2 {
2213 public:
2214 float x, y;
2215
2216 Float2(float initX, float initY)
2217 : x(initX), y(initY) {}
2218 Float2() : x(0), y(0) {}
2219};
2220
2221class Float3 {
2222 public:
2223 float x, y, z;
2224
2225 Float3(float initX, float initY, float initZ)
2226 : x(initX), y(initY), z(initZ) {}
2227 Float3() : x(0.f), y(0.f), z(0.f) {}
2228};
2229
2230class Float4 {
2231 public:
2232 float x, y, z, w;
2233
2234 Float4(float initX, float initY, float initZ, float initW)
2235 : x(initX), y(initY), z(initZ), w(initW) {}
2236 Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
2237};
2238
2239class Double2 {
2240 public:
2241 double x, y;
2242
2243 Double2(double initX, double initY)
2244 : x(initX), y(initY) {}
2245 Double2() : x(0), y(0) {}
2246};
2247
2248class Double3 {
2249 public:
2250 double x, y, z;
2251
2252 Double3(double initX, double initY, double initZ)
2253 : x(initX), y(initY), z(initZ) {}
2254 Double3() : x(0), y(0), z(0) {}
2255};
2256
2257class Double4 {
2258 public:
2259 double x, y, z, w;
2260
2261 Double4(double initX, double initY, double initZ, double initW)
2262 : x(initX), y(initY), z(initZ), w(initW) {}
2263 Double4() : x(0), y(0), z(0), w(0) {}
2264};
2265
Tim Murray84bf2b82012-10-31 16:03:16 -07002266}
Tim Murray7f0d5682012-11-08 16:35:24 -08002267
Tim Murray84bf2b82012-10-31 16:03:16 -07002268}
2269
2270#endif