blob: 12dc18619ff167ab2bd26abec3d242b08d6e2350 [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 Murray8c24cd62014-04-10 18:04:39 -070026#include <pthread.h>
Tim Murray89daad62013-07-29 14:30:02 -070027
Tim Murray75e877d2013-09-11 14:45:20 -070028/**
29 * Every row in an RS allocation is guaranteed to be aligned by this amount, and
30 * every row in a user-backed allocation must be aligned by this amount.
31 */
Tim Murray96267c22013-02-12 11:25:12 -080032#define RS_CPU_ALLOCATION_ALIGNMENT 16
33
Tim Murray84bf2b82012-10-31 16:03:16 -070034namespace android {
Tim Murray9eb7f4b2012-11-16 14:02:18 -080035namespace RSC {
Tim Murray84bf2b82012-10-31 16:03:16 -070036
37typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText);
38typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen);
39
40class RS;
41class BaseObj;
42class Element;
43class Type;
44class Allocation;
45class Script;
46class ScriptC;
Tim Murray729b6fe2013-07-23 16:20:42 -070047class Sampler;
Tim Murray84bf2b82012-10-31 16:03:16 -070048
Tim Murray75e877d2013-09-11 14:45:20 -070049/**
50 * Possible error codes used by RenderScript. Once a status other than RS_SUCCESS
51 * is returned, the RenderScript context is considered dead and cannot perform any
52 * additional work.
53 */
Tim Murray21fa7a02013-08-15 16:25:03 -070054 enum RSError {
Tim Murray75e877d2013-09-11 14:45:20 -070055 RS_SUCCESS = 0, ///< No error
56 RS_ERROR_INVALID_PARAMETER = 1, ///< An invalid parameter was passed to a function
57 RS_ERROR_RUNTIME_ERROR = 2, ///< The RenderScript driver returned an error; this is
58 ///< often indicative of a kernel that crashed
59 RS_ERROR_INVALID_ELEMENT = 3, ///< An invalid Element was passed to a function
Tim Murray21fa7a02013-08-15 16:25:03 -070060 RS_ERROR_MAX = 9999
61
62 };
63
Tim Murray75e877d2013-09-11 14:45:20 -070064 /**
65 * YUV formats supported by the RenderScript API.
66 */
Tim Murrayeb4426d2013-08-27 15:30:16 -070067 enum RSYuvFormat {
Tim Murray75e877d2013-09-11 14:45:20 -070068 RS_YUV_NONE = 0, ///< No YUV data
69 RS_YUV_YV12 = 1, ///< YUV data in YV12 format
70 RS_YUV_NV21 = 2, ///< YUV data in NV21 format
Tim Murrayeb4426d2013-08-27 15:30:16 -070071 RS_YUV_MAX = 3
72 };
73
Tim Murray75e877d2013-09-11 14:45:20 -070074 /**
75 * Flags that can control RenderScript behavior on a per-context level.
76 */
Tim Murray84e3dea2013-09-09 16:12:51 -070077 enum RSInitFlags {
Tim Murray75e877d2013-09-11 14:45:20 -070078 RS_INIT_SYNCHRONOUS = 1, ///< All RenderScript calls will be synchronous. May reduce latency.
79 RS_INIT_LOW_LATENCY = 2, ///< Prefer low latency devices over potentially higher throughput devices.
Tim Murray84e3dea2013-09-09 16:12:51 -070080 RS_INIT_MAX = 4
81 };
82
Tim Murray75e877d2013-09-11 14:45:20 -070083 /**
84 * The RenderScript context. This class controls initialization, resource management, and teardown.
85 */
Tim Murray89daad62013-07-29 14:30:02 -070086 class RS : public android::RSC::LightRefBase<RS> {
Tim Murray84bf2b82012-10-31 16:03:16 -070087
88 public:
89 RS();
90 virtual ~RS();
91
Tim Murray75e877d2013-09-11 14:45:20 -070092 /**
93 * Initializes a RenderScript context. A context must be initialized before it can be used.
Tim Murraycaf41262013-12-13 12:54:37 -080094 * @param[in] name Directory name to be used by this context. This should be equivalent to
95 * Context.getCacheDir().
Tim Murray75e877d2013-09-11 14:45:20 -070096 * @param[in] flags Optional flags for this context.
97 * @return true on success
98 */
Tim Murraycaf41262013-12-13 12:54:37 -080099 bool init(std::string name, uint32_t flags = 0);
Tim Murray84bf2b82012-10-31 16:03:16 -0700100
Tim Murray75e877d2013-09-11 14:45:20 -0700101 /**
102 * Sets the error handler function for this context. This error handler is
103 * called whenever an error is set.
104 *
105 * @param[in] func Error handler function
106 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700107 void setErrorHandler(ErrorHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700108
109 /**
110 * Returns the current error handler function for this context.
111 *
112 * @return pointer to current error handler function or NULL if not set
113 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700114 ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
115
Tim Murray75e877d2013-09-11 14:45:20 -0700116 /**
117 * Sets the message handler function for this context. This message handler
118 * is called whenever a message is sent from a RenderScript kernel.
119 *
120 * @param[in] func Message handler function
121 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700122 void setMessageHandler(MessageHandlerFunc_t func);
Tim Murray75e877d2013-09-11 14:45:20 -0700123
124 /**
125 * Returns the current message handler function for this context.
126 *
127 * @return pointer to current message handler function or NULL if not set
128 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700129 MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
130
Tim Murray75e877d2013-09-11 14:45:20 -0700131 /**
132 * Returns current status for the context.
133 *
134 * @return current error
135 */
Tim Murray10913a52013-08-20 17:19:47 -0700136 RSError getError();
Tim Murray84bf2b82012-10-31 16:03:16 -0700137
Tim Murray75e877d2013-09-11 14:45:20 -0700138 /**
139 * Waits for any currently running asynchronous operations to finish. This
140 * should only be used for performance testing and timing.
141 */
Tim Murraybaca6c32012-11-14 16:51:46 -0800142 void finish();
143
Tim Murray75e877d2013-09-11 14:45:20 -0700144 RsContext getContext() { return mContext; }
145 void throwError(RSError error, const char *errMsg);
146
Tim Murraya4230962013-07-17 16:50:10 -0700147 static dispatchTable* dispatch;
148
Tim Murray84bf2b82012-10-31 16:03:16 -0700149 private:
Tim Murray4a92d122013-07-22 10:56:18 -0700150 static bool usingNative;
Tim Murraya4230962013-07-17 16:50:10 -0700151 static bool initDispatch(int targetApi);
152
Tim Murraycaf41262013-12-13 12:54:37 -0800153 bool init(std::string &name, int targetApi, uint32_t flags);
Tim Murray84bf2b82012-10-31 16:03:16 -0700154 static void * threadProc(void *);
155
156 static bool gInitialized;
157 static pthread_mutex_t gInitMutex;
158
159 pthread_t mMessageThreadId;
160 pid_t mNativeMessageThreadId;
161 bool mMessageRun;
162
163 RsDevice mDev;
164 RsContext mContext;
Tim Murray21fa7a02013-08-15 16:25:03 -0700165 RSError mCurrentError;
Tim Murray84bf2b82012-10-31 16:03:16 -0700166
167 ErrorHandlerFunc_t mErrorFunc;
168 MessageHandlerFunc_t mMessageFunc;
Tim Murraya4230962013-07-17 16:50:10 -0700169 bool mInit;
Tim Murray84bf2b82012-10-31 16:03:16 -0700170
Tim Murraycaf41262013-12-13 12:54:37 -0800171 std::string mCacheDir;
172
Tim Murray84bf2b82012-10-31 16:03:16 -0700173 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700174 sp<const Element> U8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700175 sp<const Element> U8_2;
176 sp<const Element> U8_3;
177 sp<const Element> U8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700178 sp<const Element> I8;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700179 sp<const Element> I8_2;
180 sp<const Element> I8_3;
181 sp<const Element> I8_4;
Tim Murray89daad62013-07-29 14:30:02 -0700182 sp<const Element> U16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700183 sp<const Element> U16_2;
184 sp<const Element> U16_3;
185 sp<const Element> U16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700186 sp<const Element> I16;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700187 sp<const Element> I16_2;
188 sp<const Element> I16_3;
189 sp<const Element> I16_4;
Tim Murray89daad62013-07-29 14:30:02 -0700190 sp<const Element> U32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700191 sp<const Element> U32_2;
192 sp<const Element> U32_3;
193 sp<const Element> U32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700194 sp<const Element> I32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700195 sp<const Element> I32_2;
196 sp<const Element> I32_3;
197 sp<const Element> I32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700198 sp<const Element> U64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700199 sp<const Element> U64_2;
200 sp<const Element> U64_3;
201 sp<const Element> U64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700202 sp<const Element> I64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700203 sp<const Element> I64_2;
204 sp<const Element> I64_3;
205 sp<const Element> I64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700206 sp<const Element> F32;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700207 sp<const Element> F32_2;
208 sp<const Element> F32_3;
209 sp<const Element> F32_4;
Tim Murray89daad62013-07-29 14:30:02 -0700210 sp<const Element> F64;
Tim Murrayeb4426d2013-08-27 15:30:16 -0700211 sp<const Element> F64_2;
212 sp<const Element> F64_3;
213 sp<const Element> F64_4;
Tim Murray89daad62013-07-29 14:30:02 -0700214 sp<const Element> BOOLEAN;
Tim Murray84bf2b82012-10-31 16:03:16 -0700215
Tim Murray89daad62013-07-29 14:30:02 -0700216 sp<const Element> ELEMENT;
217 sp<const Element> TYPE;
218 sp<const Element> ALLOCATION;
219 sp<const Element> SAMPLER;
220 sp<const Element> SCRIPT;
221 sp<const Element> MESH;
222 sp<const Element> PROGRAM_FRAGMENT;
223 sp<const Element> PROGRAM_VERTEX;
224 sp<const Element> PROGRAM_RASTER;
225 sp<const Element> PROGRAM_STORE;
Tim Murray84bf2b82012-10-31 16:03:16 -0700226
Tim Murray89daad62013-07-29 14:30:02 -0700227 sp<const Element> A_8;
228 sp<const Element> RGB_565;
229 sp<const Element> RGB_888;
230 sp<const Element> RGBA_5551;
231 sp<const Element> RGBA_4444;
232 sp<const Element> RGBA_8888;
Tim Murray84bf2b82012-10-31 16:03:16 -0700233
Tim Murrayeb4426d2013-08-27 15:30:16 -0700234 sp<const Element> YUV;
Tim Murray84bf2b82012-10-31 16:03:16 -0700235
Tim Murray89daad62013-07-29 14:30:02 -0700236 sp<const Element> MATRIX_4X4;
237 sp<const Element> MATRIX_3X3;
238 sp<const Element> MATRIX_2X2;
Tim Murray84bf2b82012-10-31 16:03:16 -0700239 } mElements;
240
Tim Murray729b6fe2013-07-23 16:20:42 -0700241 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700242 sp<const Sampler> CLAMP_NEAREST;
243 sp<const Sampler> CLAMP_LINEAR;
244 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
245 sp<const Sampler> WRAP_NEAREST;
246 sp<const Sampler> WRAP_LINEAR;
247 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
248 sp<const Sampler> MIRRORED_REPEAT_NEAREST;
249 sp<const Sampler> MIRRORED_REPEAT_LINEAR;
250 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Tim Murray729b6fe2013-07-23 16:20:42 -0700251 } mSamplers;
252 friend class Sampler;
253 friend class Element;
Tim Murraycaf41262013-12-13 12:54:37 -0800254 friend class ScriptC;
Tim Murray84bf2b82012-10-31 16:03:16 -0700255};
256
Tim Murray75e877d2013-09-11 14:45:20 -0700257 /**
258 * Base class for all RenderScript objects. Not for direct use by developers.
259 */
Tim Murray89daad62013-07-29 14:30:02 -0700260class BaseObj : public android::RSC::LightRefBase<BaseObj> {
261public:
262 void * getID() const;
263 virtual ~BaseObj();
264 virtual void updateFromNative();
265 virtual bool equals(sp<const BaseObj> obj);
266
Tim Murray84bf2b82012-10-31 16:03:16 -0700267protected:
268 void *mID;
Tim Murray35609072013-12-03 11:36:03 -0800269 RS* mRS;
Tim Murrayab716362013-08-12 12:37:18 -0700270 std::string mName;
Tim Murray84bf2b82012-10-31 16:03:16 -0700271
272 BaseObj(void *id, sp<RS> rs);
273 void checkValid();
274
275 static void * getObjID(sp<const BaseObj> o);
276
Tim Murray84bf2b82012-10-31 16:03:16 -0700277};
278
Tim Murray75e877d2013-09-11 14:45:20 -0700279 /**
280 * This class provides the primary method through which data is passed to and
281 * from RenderScript kernels. An Allocation provides the backing store for a
282 * given Type.
283 *
284 * An Allocation also contains a set of usage flags that denote how the
285 * Allocation could be used. For example, an Allocation may have usage flags
286 * specifying that it can be used from a script as well as input to a
287 * Sampler. A developer must synchronize across these different usages using
288 * syncAll(int) in order to ensure that different users of the Allocation have
289 * a consistent view of memory. For example, in the case where an Allocation is
290 * used as the output of one kernel and as Sampler input in a later kernel, a
291 * developer must call syncAll(RS_ALLOCATION_USAGE_SCRIPT) prior to launching the
292 * second kernel to ensure correctness.
293 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700294class Allocation : public BaseObj {
295protected:
Tim Murray89daad62013-07-29 14:30:02 -0700296 sp<const Type> mType;
Tim Murray84bf2b82012-10-31 16:03:16 -0700297 uint32_t mUsage;
Tim Murray89daad62013-07-29 14:30:02 -0700298 sp<Allocation> mAdaptedAllocation;
Tim Murray84bf2b82012-10-31 16:03:16 -0700299
300 bool mConstrainedLOD;
301 bool mConstrainedFace;
302 bool mConstrainedY;
303 bool mConstrainedZ;
304 bool mReadAllowed;
305 bool mWriteAllowed;
306 uint32_t mSelectedY;
307 uint32_t mSelectedZ;
308 uint32_t mSelectedLOD;
309 RsAllocationCubemapFace mSelectedFace;
310
311 uint32_t mCurrentDimX;
312 uint32_t mCurrentDimY;
313 uint32_t mCurrentDimZ;
314 uint32_t mCurrentCount;
315
316 void * getIDSafe() const;
317 void updateCacheInfo(sp<const Type> t);
318
319 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
320
321 void validateIsInt32();
322 void validateIsInt16();
323 void validateIsInt8();
324 void validateIsFloat32();
325 void validateIsObject();
326
327 virtual void updateFromNative();
328
329 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
Tim Murray9d24ae62013-08-30 12:17:14 -0700330 void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff,
331 uint32_t w, uint32_t h, uint32_t d);
Tim Murray84bf2b82012-10-31 16:03:16 -0700332
333public:
Tim Murray75e877d2013-09-11 14:45:20 -0700334
335 /**
336 * Return Type for the allocation.
337 * @return pointer to underlying Type
338 */
Stephen Hinesa180b7d2013-08-21 12:42:13 -0700339 sp<const Type> getType() const {
Tim Murray84bf2b82012-10-31 16:03:16 -0700340 return mType;
341 }
342
Tim Murray75e877d2013-09-11 14:45:20 -0700343 /**
344 * Propagate changes from one usage of the Allocation to other usages of the Allocation.
345 * @param[in] srcLocation source location with changes to propagate elsewhere
346 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700347 void syncAll(RsAllocationUsageType srcLocation);
348 void ioSendOutput();
349 void ioGetInput();
350
Tim Murray75e877d2013-09-11 14:45:20 -0700351 /**
352 * Generate a mipmap chain. This is only valid if the Type of the Allocation
353 * includes mipmaps. This function will generate a complete set of mipmaps
354 * from the top level LOD and place them into the script memory space. If
355 * the Allocation is also using other memory spaces, a call to
356 * syncAll(Allocation.USAGE_SCRIPT) is required.
357 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700358 void generateMipmaps();
Tim Murray509ea5c2012-11-13 11:56:40 -0800359
Tim Murray75e877d2013-09-11 14:45:20 -0700360 /**
361 * Copy an array into part of this Allocation.
362 * @param[in] off offset of first Element to be overwritten
363 * @param[in] count number of Elements to copy
364 * @param[in] data array from which to copy
365 */
Tim Murray0b93e302012-11-15 14:56:54 -0800366 void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
Tim Murray75e877d2013-09-11 14:45:20 -0700367
368 /**
369 * Copy part of an Allocation into part of this Allocation.
370 * @param[in] off offset of first Element to be overwritten
371 * @param[in] count number of Elements to copy
372 * @param[in] data Allocation from which to copy
373 * @param[in] dataOff offset of first Element in data to copy
374 */
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800375 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700376
Tim Murray75e877d2013-09-11 14:45:20 -0700377 /**
378 * Copy an array into part of this Allocation.
379 * @param[in] off offset of first Element to be overwritten
380 * @param[in] count number of Elements to copy
381 * @param[in] data array from which to copy
382 */
Tim Murray0b93e302012-11-15 14:56:54 -0800383 void copy1DRangeTo(uint32_t off, size_t count, void *data);
384
Tim Murray75e877d2013-09-11 14:45:20 -0700385 /**
386 * Copy entire array to an Allocation.
387 * @param[in] data array from which to copy
388 */
Tim Murray0b93e302012-11-15 14:56:54 -0800389 void copy1DFrom(const void* data);
Tim Murray75e877d2013-09-11 14:45:20 -0700390
391 /**
392 * Copy entire Allocation to an array.
393 * @param[in] data destination array
394 */
Tim Murray0b93e302012-11-15 14:56:54 -0800395 void copy1DTo(void* data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800396
Tim Murray75e877d2013-09-11 14:45:20 -0700397 /**
398 * Copy from an array into a rectangular region in this Allocation. The
399 * array is assumed to be tightly packed.
400 * @param[in] xoff X offset of region to update in this Allocation
401 * @param[in] yoff Y offset of region to update in this Allocation
402 * @param[in] w Width of region to update
403 * @param[in] h Height of region to update
404 * @param[in] data Array from which to copy
405 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700406 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800407 const void *data);
Tim Murray7b3e3092012-11-16 13:32:24 -0800408
Tim Murray75e877d2013-09-11 14:45:20 -0700409 /**
410 * Copy from this Allocation into a rectangular region in an array. The
411 * array is assumed to be tightly packed.
412 * @param[in] xoff X offset of region to copy from this Allocation
413 * @param[in] yoff Y offset of region to copy from this Allocation
414 * @param[in] w Width of region to update
415 * @param[in] h Height of region to update
416 * @param[in] data destination array
417 */
Tim Murray7b3e3092012-11-16 13:32:24 -0800418 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
419 void *data);
420
Tim Murray75e877d2013-09-11 14:45:20 -0700421 /**
422 * Copy from an Allocation into a rectangular region in this Allocation.
423 * @param[in] xoff X offset of region to update in this Allocation
424 * @param[in] yoff Y offset of region to update in this Allocation
425 * @param[in] w Width of region to update
426 * @param[in] h Height of region to update
427 * @param[in] data Allocation from which to copy
428 * @param[in] dataXoff X offset of region to copy from in data
429 * @param[in] dataYoff Y offset of region to copy from in data
430 */
Tim Murray0b93e302012-11-15 14:56:54 -0800431 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
432 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700433
Tim Murray75e877d2013-09-11 14:45:20 -0700434 /**
435 * Copy from a strided array into a rectangular region in this Allocation.
436 * @param[in] xoff X offset of region to update in this Allocation
437 * @param[in] yoff Y offset of region to update in this Allocation
438 * @param[in] w Width of region to update
439 * @param[in] h Height of region to update
440 * @param[in] data array from which to copy
441 * @param[in] stride stride of data in bytes
442 */
Tim Murray358747a2012-11-26 13:52:04 -0800443 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
444 const void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700445
446 /**
447 * Copy from a strided array into this Allocation.
448 * @param[in] data array from which to copy
449 * @param[in] stride stride of data in bytes
450 */
Tim Murray358747a2012-11-26 13:52:04 -0800451 void copy2DStridedFrom(const void *data, size_t stride);
452
Tim Murray75e877d2013-09-11 14:45:20 -0700453 /**
454 * Copy from a rectangular region in this Allocation into a strided array.
455 * @param[in] xoff X offset of region to update in this Allocation
456 * @param[in] yoff Y offset of region to update in this Allocation
457 * @param[in] w Width of region to update
458 * @param[in] h Height of region to update
459 * @param[in] data destination array
460 * @param[in] stride stride of data in bytes
461 */
Tim Murray358747a2012-11-26 13:52:04 -0800462 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
463 void *data, size_t stride);
Tim Murray75e877d2013-09-11 14:45:20 -0700464
465 /**
466 * Copy this Allocation into a strided array.
467 * @param[in] data destination array
468 * @param[in] stride stride of data in bytes
469 */
Tim Murray358747a2012-11-26 13:52:04 -0800470 void copy2DStridedTo(void *data, size_t stride);
471
Tim Murray75e877d2013-09-11 14:45:20 -0700472
473 /**
474 * Copy from an array into a 3D region in this Allocation. The
475 * array is assumed to be tightly packed.
476 * @param[in] xoff X offset of region to update in this Allocation
477 * @param[in] yoff Y offset of region to update in this Allocation
478 * @param[in] zoff Z offset of region to update in this Allocation
479 * @param[in] w Width of region to update
480 * @param[in] h Height of region to update
481 * @param[in] d Depth of region to update
482 * @param[in] data Array from which to copy
483 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700484 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
485 uint32_t h, uint32_t d, const void* data);
486
Tim Murray75e877d2013-09-11 14:45:20 -0700487 /**
488 * Copy from an Allocation into a 3D region in this Allocation.
489 * @param[in] xoff X offset of region to update in this Allocation
490 * @param[in] yoff Y offset of region to update in this Allocation
491 * @param[in] zoff Z offset of region to update in this Allocation
492 * @param[in] w Width of region to update
493 * @param[in] h Height of region to update
494 * @param[in] d Depth of region to update
495 * @param[in] data Allocation from which to copy
496 * @param[in] dataXoff X offset of region in data to copy from
497 * @param[in] dataYoff Y offset of region in data to copy from
498 * @param[in] dataZoff Z offset of region in data to copy from
499 */
Tim Murray9d24ae62013-08-30 12:17:14 -0700500 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
501 uint32_t w, uint32_t h, uint32_t d,
502 sp<const Allocation> data,
503 uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700504
Tim Murray75e877d2013-09-11 14:45:20 -0700505 /**
506 * Creates an Allocation for use by scripts with a given Type.
507 * @param[in] rs Context to which the Allocation will belong
508 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800509 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700510 * @param[in] usage usage for the Allocation
511 * @return new Allocation
512 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700513 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800514 RsAllocationMipmapControl mipmaps, uint32_t usage);
Tim Murray75e877d2013-09-11 14:45:20 -0700515
516 /**
517 * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use
518 * with RS_ALLOCATION_USAGE_SHARED.
519 * @param[in] rs Context to which the Allocation will belong
520 * @param[in] type Type of the Allocation
Stephen Hines8f615d62013-12-20 12:23:32 -0800521 * @param[in] mipmaps desired mipmap behavior for the Allocation
Tim Murray75e877d2013-09-11 14:45:20 -0700522 * @param[in] usage usage for the Allocation
523 * @param[in] pointer existing backing store to use for this Allocation if possible
524 * @return new Allocation
525 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700526 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
Stephen Hines8f615d62013-12-20 12:23:32 -0800527 RsAllocationMipmapControl mipmaps, uint32_t usage, void * pointer);
Tim Murray84bf2b82012-10-31 16:03:16 -0700528
Tim Murray75e877d2013-09-11 14:45:20 -0700529 /**
530 * Creates an Allocation for use by scripts with a given Type with no mipmaps.
531 * @param[in] rs Context to which the Allocation will belong
532 * @param[in] type Type of the Allocation
533 * @param[in] usage usage for the Allocation
534 * @return new Allocation
535 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700536 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
537 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700538 /**
539 * Creates an Allocation with a specified number of given elements.
540 * @param[in] rs Context to which the Allocation will belong
541 * @param[in] e Element used in the Allocation
542 * @param[in] count Number of elements of the Allocation
543 * @param[in] usage usage for the Allocation
544 * @return new Allocation
545 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700546 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
547 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray75e877d2013-09-11 14:45:20 -0700548
549 /**
550 * Creates a 2D Allocation with a specified number of given elements.
551 * @param[in] rs Context to which the Allocation will belong
552 * @param[in] e Element used in the Allocation
553 * @param[in] x Width in Elements of the Allocation
554 * @param[in] y Height of the Allocation
555 * @param[in] usage usage for the Allocation
556 * @return new Allocation
557 */
Tim Murray684726c2012-11-14 11:57:42 -0800558 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
559 size_t x, size_t y,
560 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
561
Tim Murray84bf2b82012-10-31 16:03:16 -0700562
Jason Samsb8a94e22014-02-24 17:52:32 -0800563 /**
564 * Get the backing pointer for a USAGE_SHARED allocation.
565 * @param[in] stride optional parameter. when non-NULL, will contain
566 * stride in bytes of a 2D Allocation
567 * @return pointer to data
568 */
569 void * getPointer(size_t *stride = NULL);
Tim Murray84bf2b82012-10-31 16:03:16 -0700570};
571
Tim Murray75e877d2013-09-11 14:45:20 -0700572 /**
573 * An Element represents one item within an Allocation. An Element is roughly
574 * equivalent to a C type in a RenderScript kernel. Elements may be basic
575 * or complex. Some basic elements are:
576
577 * - A single float value (equivalent to a float in a kernel)
578 * - A four-element float vector (equivalent to a float4 in a kernel)
579 * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel)
580 * - A single signed 8-bit integer (equivalent to a char in a kernel)
581
582 * Basic Elements are comprised of a Element.DataType and a
583 * Element.DataKind. The DataType encodes C type information of an Element,
584 * while the DataKind encodes how that Element should be interpreted by a
585 * Sampler. Note that Allocation objects with DataKind USER cannot be used as
586 * input for a Sampler. In general, Allocation objects that are intended for
587 * use with a Sampler should use bitmap-derived Elements such as
588 * Element::RGBA_8888.
589 */
590
591
Tim Murray84bf2b82012-10-31 16:03:16 -0700592class Element : public BaseObj {
593public:
594 bool isComplex();
Tim Murray75e877d2013-09-11 14:45:20 -0700595
596 /**
597 * Elements could be simple, such as an int or a float, or a structure with
598 * multiple sub-elements, such as a collection of floats, float2,
599 * float4. This function returns zero for simple elements or the number of
600 * sub-elements otherwise.
601 * @return number of sub-elements
602 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700603 size_t getSubElementCount() {
604 return mVisibleElementMap.size();
605 }
606
Tim Murray75e877d2013-09-11 14:45:20 -0700607 /**
608 * For complex Elements, this returns the sub-element at a given index.
609 * @param[in] index index of sub-element
610 * @return sub-element
611 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700612 sp<const Element> getSubElement(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700613
614 /**
615 * For complex Elements, this returns the name of the sub-element at a given
616 * index.
617 * @param[in] index index of sub-element
618 * @return name of sub-element
619 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700620 const char * getSubElementName(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700621
622 /**
623 * For complex Elements, this returns the size of the sub-element at a given
624 * index.
625 * @param[in] index index of sub-element
626 * @return size of sub-element
627 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700628 size_t getSubElementArraySize(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700629
630 /**
631 * Returns the location of a sub-element within a complex Element.
632 * @param[in] index index of sub-element
633 * @return offset in bytes
634 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700635 uint32_t getSubElementOffsetBytes(uint32_t index);
Tim Murray75e877d2013-09-11 14:45:20 -0700636
637 /**
638 * Returns the data type used for the Element.
639 * @return data type
640 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700641 RsDataType getDataType() const {
642 return mType;
643 }
644
Tim Murray75e877d2013-09-11 14:45:20 -0700645 /**
646 * Returns the data kind used for the Element.
647 * @return data kind
648 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700649 RsDataKind getDataKind() const {
650 return mKind;
651 }
652
Tim Murray75e877d2013-09-11 14:45:20 -0700653 /**
654 * Returns the size in bytes of the Element.
655 * @return size in bytes
656 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700657 size_t getSizeBytes() const {
658 return mSizeBytes;
659 }
660
Tim Murray75e877d2013-09-11 14:45:20 -0700661 /**
662 * Returns the number of vector components for this Element.
663 * @return number of vector components
664 */
Tim Murray10913a52013-08-20 17:19:47 -0700665 uint32_t getVectorSize() const {
666 return mVectorSize;
667 }
668
Tim Murray75e877d2013-09-11 14:45:20 -0700669 /**
670 * Utility function for returning an Element containing a single bool.
671 * @param[in] rs RenderScript context
672 * @return Element
673 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700674 static sp<const Element> BOOLEAN(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700675 /**
676 * Utility function for returning an Element containing a single unsigned char.
677 * @param[in] rs RenderScript context
678 * @return Element
679 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700680 static sp<const Element> U8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700681 /**
682 * Utility function for returning an Element containing a single signed char.
683 * @param[in] rs RenderScript context
684 * @return Element
685 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700686 static sp<const Element> I8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700687 /**
688 * Utility function for returning an Element containing a single unsigned short.
689 * @param[in] rs RenderScript context
690 * @return Element
691 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700692 static sp<const Element> U16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700693 /**
694 * Utility function for returning an Element containing a single signed short.
695 * @param[in] rs RenderScript context
696 * @return Element
697 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700698 static sp<const Element> I16(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700699 /**
700 * Utility function for returning an Element containing a single unsigned int.
701 * @param[in] rs RenderScript context
702 * @return Element
703 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700704 static sp<const Element> U32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700705 /**
706 * Utility function for returning an Element containing a single signed int.
707 * @param[in] rs RenderScript context
708 * @return Element
709 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700710 static sp<const Element> I32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700711 /**
712 * Utility function for returning an Element containing a single unsigned long long.
713 * @param[in] rs RenderScript context
714 * @return Element
715 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700716 static sp<const Element> U64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700717 /**
718 * Utility function for returning an Element containing a single signed long long.
719 * @param[in] rs RenderScript context
720 * @return Element
721 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700722 static sp<const Element> I64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700723 /**
724 * Utility function for returning an Element containing a single float.
725 * @param[in] rs RenderScript context
726 * @return Element
727 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700728 static sp<const Element> F32(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700729 /**
730 * Utility function for returning an Element containing a single double.
731 * @param[in] rs RenderScript context
732 * @return Element
733 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700734 static sp<const Element> F64(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700735 /**
736 * Utility function for returning an Element containing a single Element.
737 * @param[in] rs RenderScript context
738 * @return Element
739 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700740 static sp<const Element> ELEMENT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700741 /**
742 * Utility function for returning an Element containing a single Type.
743 * @param[in] rs RenderScript context
744 * @return Element
745 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700746 static sp<const Element> TYPE(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700747 /**
748 * Utility function for returning an Element containing a single Allocation.
749 * @param[in] rs RenderScript context
750 * @return Element
751 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700752 static sp<const Element> ALLOCATION(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700753 /**
754 * Utility function for returning an Element containing a single Sampler.
755 * @param[in] rs RenderScript context
756 * @return Element
757 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700758 static sp<const Element> SAMPLER(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700759 /**
760 * Utility function for returning an Element containing a single Script.
761 * @param[in] rs RenderScript context
762 * @return Element
763 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700764 static sp<const Element> SCRIPT(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700765 /**
766 * Utility function for returning an Element containing an ALPHA_8 pixel.
767 * @param[in] rs RenderScript context
768 * @return Element
769 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700770 static sp<const Element> A_8(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700771 /**
772 * Utility function for returning an Element containing an RGB_565 pixel.
773 * @param[in] rs RenderScript context
774 * @return Element
775 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700776 static sp<const Element> RGB_565(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700777 /**
778 * Utility function for returning an Element containing an RGB_888 pixel.
779 * @param[in] rs RenderScript context
780 * @return Element
781 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700782 static sp<const Element> RGB_888(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700783 /**
784 * Utility function for returning an Element containing an RGBA_5551 pixel.
785 * @param[in] rs RenderScript context
786 * @return Element
787 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700788 static sp<const Element> RGBA_5551(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700789 /**
790 * Utility function for returning an Element containing an RGBA_4444 pixel.
791 * @param[in] rs RenderScript context
792 * @return Element
793 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700794 static sp<const Element> RGBA_4444(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700795 /**
796 * Utility function for returning an Element containing an RGBA_8888 pixel.
797 * @param[in] rs RenderScript context
798 * @return Element
799 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700800 static sp<const Element> RGBA_8888(sp<RS> rs);
801
Tim Murray75e877d2013-09-11 14:45:20 -0700802 /**
803 * Utility function for returning an Element containing a float2.
804 * @param[in] rs RenderScript context
805 * @return Element
806 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700807 static sp<const Element> F32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700808 /**
809 * Utility function for returning an Element containing a float3.
810 * @param[in] rs RenderScript context
811 * @return Element
812 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700813 static sp<const Element> F32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700814 /**
815 * Utility function for returning an Element containing a float4.
816 * @param[in] rs RenderScript context
817 * @return Element
818 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700819 static sp<const Element> F32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700820 /**
821 * Utility function for returning an Element containing a double2.
822 * @param[in] rs RenderScript context
823 * @return Element
824 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700825 static sp<const Element> F64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700826 /**
827 * Utility function for returning an Element containing a double3.
828 * @param[in] rs RenderScript context
829 * @return Element
830 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700831 static sp<const Element> F64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700832 /**
833 * Utility function for returning an Element containing a double4.
834 * @param[in] rs RenderScript context
835 * @return Element
836 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700837 static sp<const Element> F64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700838 /**
839 * Utility function for returning an Element containing a uchar2.
840 * @param[in] rs RenderScript context
841 * @return Element
842 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700843 static sp<const Element> U8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700844 /**
845 * Utility function for returning an Element containing a uchar3.
846 * @param[in] rs RenderScript context
847 * @return Element
848 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700849 static sp<const Element> U8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700850 /**
851 * Utility function for returning an Element containing a uchar4.
852 * @param[in] rs RenderScript context
853 * @return Element
854 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700855 static sp<const Element> U8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700856 /**
857 * Utility function for returning an Element containing a char2.
858 * @param[in] rs RenderScript context
859 * @return Element
860 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700861 static sp<const Element> I8_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700862 /**
863 * Utility function for returning an Element containing a char3.
864 * @param[in] rs RenderScript context
865 * @return Element
866 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700867 static sp<const Element> I8_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700868 /**
869 * Utility function for returning an Element containing a char4.
870 * @param[in] rs RenderScript context
871 * @return Element
872 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700873 static sp<const Element> I8_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700874 /**
875 * Utility function for returning an Element containing a ushort2.
876 * @param[in] rs RenderScript context
877 * @return Element
878 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700879 static sp<const Element> U16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700880 /**
881 * Utility function for returning an Element containing a ushort3.
882 * @param[in] rs RenderScript context
883 * @return Element
884 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700885 static sp<const Element> U16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700886 /**
887 * Utility function for returning an Element containing a ushort4.
888 * @param[in] rs RenderScript context
889 * @return Element
890 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700891 static sp<const Element> U16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700892 /**
893 * Utility function for returning an Element containing a short2.
894 * @param[in] rs RenderScript context
895 * @return Element
896 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700897 static sp<const Element> I16_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700898 /**
899 * Utility function for returning an Element containing a short3.
900 * @param[in] rs RenderScript context
901 * @return Element
902 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700903 static sp<const Element> I16_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700904 /**
905 * Utility function for returning an Element containing a short4.
906 * @param[in] rs RenderScript context
907 * @return Element
908 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700909 static sp<const Element> I16_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700910 /**
911 * Utility function for returning an Element containing a uint2.
912 * @param[in] rs RenderScript context
913 * @return Element
914 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700915 static sp<const Element> U32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700916 /**
917 * Utility function for returning an Element containing a uint3.
918 * @param[in] rs RenderScript context
919 * @return Element
920 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700921 static sp<const Element> U32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700922 /**
923 * Utility function for returning an Element containing a uint4.
924 * @param[in] rs RenderScript context
925 * @return Element
926 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700927 static sp<const Element> U32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700928 /**
929 * Utility function for returning an Element containing an int2.
930 * @param[in] rs RenderScript context
931 * @return Element
932 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700933 static sp<const Element> I32_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700934 /**
935 * Utility function for returning an Element containing an int3.
936 * @param[in] rs RenderScript context
937 * @return Element
938 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700939 static sp<const Element> I32_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700940 /**
941 * Utility function for returning an Element containing an int4.
942 * @param[in] rs RenderScript context
943 * @return Element
944 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700945 static sp<const Element> I32_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700946 /**
947 * Utility function for returning an Element containing a ulong2.
948 * @param[in] rs RenderScript context
949 * @return Element
950 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700951 static sp<const Element> U64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700952 /**
953 * Utility function for returning an Element containing a ulong3.
954 * @param[in] rs RenderScript context
955 * @return Element
956 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700957 static sp<const Element> U64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700958 /**
959 * Utility function for returning an Element containing a ulong4.
960 * @param[in] rs RenderScript context
961 * @return Element
962 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700963 static sp<const Element> U64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700964 /**
965 * Utility function for returning an Element containing a long2.
966 * @param[in] rs RenderScript context
967 * @return Element
968 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700969 static sp<const Element> I64_2(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700970 /**
971 * Utility function for returning an Element containing a long3.
972 * @param[in] rs RenderScript context
973 * @return Element
974 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700975 static sp<const Element> I64_3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700976 /**
977 * Utility function for returning an Element containing a long4.
978 * @param[in] rs RenderScript context
979 * @return Element
980 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700981 static sp<const Element> I64_4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700982 /**
983 * Utility function for returning an Element containing a YUV pixel.
984 * @param[in] rs RenderScript context
985 * @return Element
986 */
Tim Murrayeb4426d2013-08-27 15:30:16 -0700987 static sp<const Element> YUV(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700988 /**
989 * Utility function for returning an Element containing an rs_matrix_4x4.
990 * @param[in] rs RenderScript context
991 * @return Element
992 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700993 static sp<const Element> MATRIX_4X4(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -0700994 /**
995 * Utility function for returning an Element containing an rs_matrix_3x3.
996 * @param[in] rs RenderScript context
997 * @return Element
998 */
Tim Murray84bf2b82012-10-31 16:03:16 -0700999 static sp<const Element> MATRIX_3X3(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001000 /**
1001 * Utility function for returning an Element containing an rs_matrix_2x2.
1002 * @param[in] rs RenderScript context
1003 * @return Element
1004 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001005 static sp<const Element> MATRIX_2X2(sp<RS> rs);
1006
Tim Murray84bf2b82012-10-31 16:03:16 -07001007 void updateFromNative();
Tim Murray75e877d2013-09-11 14:45:20 -07001008
1009 /**
1010 * Create an Element with a given DataType.
1011 * @param[in] rs RenderScript context
1012 * @param[in] dt data type
1013 * @return Element
1014 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001015 static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
Tim Murray75e877d2013-09-11 14:45:20 -07001016 /**
1017 * Create a vector Element with the given DataType
1018 * @param[in] rs RenderScript
1019 * @param[in] dt DataType
1020 * @param[in] size vector size
1021 * @return Element
1022 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001023 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
Tim Murray75e877d2013-09-11 14:45:20 -07001024 /**
1025 * Create an Element with a given DataType and DataKind.
1026 * @param[in] rs RenderScript context
1027 * @param[in] dt DataType
1028 * @param[in] dk DataKind
1029 * @return Element
1030 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001031 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
Tim Murray75e877d2013-09-11 14:45:20 -07001032
1033 /**
1034 * Returns true if the Element can interoperate with this Element.
1035 * @param[in] e Element to compare
1036 * @return true if Elements can interoperate
1037 */
Tim Murray10913a52013-08-20 17:19:47 -07001038 bool isCompatible(sp<const Element>e) const;
Tim Murray84bf2b82012-10-31 16:03:16 -07001039
Tim Murray75e877d2013-09-11 14:45:20 -07001040 /**
1041 * Builder class for producing complex elements with matching field and name
1042 * pairs. The builder starts empty. The order in which elements are added is
1043 * retained for the layout in memory.
1044 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001045 class Builder {
1046 private:
Tim Murray35609072013-12-03 11:36:03 -08001047 RS* mRS;
Tim Murray89daad62013-07-29 14:30:02 -07001048 std::vector<sp<Element> > mElements;
Tim Murrayab716362013-08-12 12:37:18 -07001049 std::vector<std::string> mElementNames;
Tim Murray89daad62013-07-29 14:30:02 -07001050 std::vector<uint32_t> mArraySizes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001051 bool mSkipPadding;
1052
1053 public:
1054 Builder(sp<RS> rs);
1055 ~Builder();
Tim Murrayab716362013-08-12 12:37:18 -07001056 void add(sp<Element> e, std::string &name, uint32_t arraySize = 1);
Tim Murray84bf2b82012-10-31 16:03:16 -07001057 sp<const Element> create();
1058 };
1059
Stephen Hines7d1b7572013-08-22 01:24:06 -07001060protected:
1061 Element(void *id, sp<RS> rs,
1062 std::vector<sp<Element> > &elements,
1063 std::vector<std::string> &elementNames,
1064 std::vector<uint32_t> &arraySizes);
1065 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
1066 Element(sp<RS> rs);
1067 virtual ~Element();
1068
Tim Murray84bf2b82012-10-31 16:03:16 -07001069private:
1070 void updateVisibleSubElements();
1071
Tim Murray89daad62013-07-29 14:30:02 -07001072 std::vector<sp<Element> > mElements;
Tim Murrayab716362013-08-12 12:37:18 -07001073 std::vector<std::string> mElementNames;
Tim Murray89daad62013-07-29 14:30:02 -07001074 std::vector<uint32_t> mArraySizes;
1075 std::vector<uint32_t> mVisibleElementMap;
1076 std::vector<uint32_t> mOffsetInBytes;
Tim Murray84bf2b82012-10-31 16:03:16 -07001077
1078 RsDataType mType;
1079 RsDataKind mKind;
1080 bool mNormalized;
1081 size_t mSizeBytes;
1082 size_t mVectorSize;
1083};
1084
Stephen Hines2c7206e2012-11-14 19:47:01 -08001085class FieldPacker {
1086protected:
1087 unsigned char* mData;
1088 size_t mPos;
1089 size_t mLen;
1090
1091public:
1092 FieldPacker(size_t len)
Tim Murray89daad62013-07-29 14:30:02 -07001093 : mPos(0), mLen(len) {
1094 mData = new unsigned char[len];
1095 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001096
1097 virtual ~FieldPacker() {
1098 delete [] mData;
1099 }
1100
1101 void align(size_t v) {
1102 if ((v & (v - 1)) != 0) {
Tim Murrayab716362013-08-12 12:37:18 -07001103 // ALOGE("Non-power-of-two alignment: %zu", v);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001104 return;
1105 }
1106
1107 while ((mPos & (v - 1)) != 0) {
1108 mData[mPos++] = 0;
1109 }
1110 }
1111
1112 void reset() {
1113 mPos = 0;
1114 }
1115
1116 void reset(size_t i) {
1117 if (i >= mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001118 // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001119 return;
1120 }
1121 mPos = i;
1122 }
1123
1124 void skip(size_t i) {
1125 size_t res = mPos + i;
1126 if (res > mLen) {
Tim Murrayab716362013-08-12 12:37:18 -07001127 // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -08001128 return;
1129 }
1130 mPos = res;
1131 }
1132
1133 void* getData() const {
1134 return mData;
1135 }
1136
1137 size_t getLength() const {
1138 return mLen;
1139 }
1140
1141 template <typename T>
Tim Murray89daad62013-07-29 14:30:02 -07001142 void add(T t) {
Stephen Hines2c7206e2012-11-14 19:47:01 -08001143 align(sizeof(t));
1144 if (mPos + sizeof(t) <= mLen) {
1145 memcpy(&mData[mPos], &t, sizeof(t));
1146 mPos += sizeof(t);
1147 }
1148 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001149
1150 /*
Tim Murray89daad62013-07-29 14:30:02 -07001151 void add(rs_matrix4x4 m) {
1152 for (size_t i = 0; i < 16; i++) {
1153 add(m.m[i]);
1154 }
1155 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001156
Tim Murray89daad62013-07-29 14:30:02 -07001157 void add(rs_matrix3x3 m) {
1158 for (size_t i = 0; i < 9; i++) {
1159 add(m.m[i]);
1160 }
1161 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001162
Tim Murray89daad62013-07-29 14:30:02 -07001163 void add(rs_matrix2x2 m) {
1164 for (size_t i = 0; i < 4; i++) {
1165 add(m.m[i]);
1166 }
1167 }
Stephen Hines43514cd2012-11-16 14:33:47 -08001168 */
1169
Tim Murray89daad62013-07-29 14:30:02 -07001170 void add(sp<BaseObj> obj) {
Stephen Hines43514cd2012-11-16 14:33:47 -08001171 if (obj != NULL) {
1172 add((uint32_t) (uintptr_t) obj->getID());
1173 } else {
1174 add((uint32_t) 0);
1175 }
1176 }
Stephen Hines2c7206e2012-11-14 19:47:01 -08001177};
1178
Tim Murray75e877d2013-09-11 14:45:20 -07001179/**
1180 * A Type describes the Element and dimensions used for an Allocation or a
1181 * parallel operation.
1182 *
1183 * A Type always includes an Element and an X dimension. A Type may be
1184 * multidimensional, up to three dimensions. A nonzero value in the Y or Z
1185 * dimensions indicates that the dimension is present. Note that a Type with
1186 * only a given X dimension and a Type with the same X dimension but Y = 1 are
1187 * not equivalent.
1188 *
1189 * A Type also supports inclusion of level of detail (LOD) or cube map
1190 * faces. LOD and cube map faces are booleans to indicate present or not
1191 * present.
1192 *
1193 * A Type also supports YUV format information to support an Allocation in a YUV
1194 * format. The YUV formats supported are YV12 and NV21.
1195 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001196class Type : public BaseObj {
1197protected:
1198 friend class Allocation;
1199
1200 uint32_t mDimX;
1201 uint32_t mDimY;
1202 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001203 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001204 bool mDimMipmaps;
1205 bool mDimFaces;
1206 size_t mElementCount;
1207 sp<const Element> mElement;
1208
Stephen Hines7d1b7572013-08-22 01:24:06 -07001209 Type(void *id, sp<RS> rs);
1210
Tim Murray84bf2b82012-10-31 16:03:16 -07001211 void calcElementCount();
1212 virtual void updateFromNative();
1213
1214public:
1215
Tim Murray75e877d2013-09-11 14:45:20 -07001216 /**
1217 * Returns the YUV format.
1218 * @return YUV format of the Allocation
1219 */
Tim Murrayeb4426d2013-08-27 15:30:16 -07001220 RSYuvFormat getYuvFormat() const {
1221 return mYuvFormat;
1222 }
1223
Tim Murray75e877d2013-09-11 14:45:20 -07001224 /**
1225 * Returns the Element of the Allocation.
1226 * @return YUV format of the Allocation
1227 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001228 sp<const Element> getElement() const {
1229 return mElement;
1230 }
1231
Tim Murray75e877d2013-09-11 14:45:20 -07001232 /**
1233 * Returns the X dimension of the Allocation.
1234 * @return X dimension of the allocation
1235 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001236 uint32_t getX() const {
1237 return mDimX;
1238 }
1239
Tim Murray75e877d2013-09-11 14:45:20 -07001240 /**
1241 * Returns the Y dimension of the Allocation.
1242 * @return Y dimension of the allocation
1243 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001244 uint32_t getY() const {
1245 return mDimY;
1246 }
1247
Tim Murray75e877d2013-09-11 14:45:20 -07001248 /**
1249 * Returns the Z dimension of the Allocation.
1250 * @return Z dimension of the allocation
1251 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001252 uint32_t getZ() const {
1253 return mDimZ;
1254 }
1255
Tim Murray75e877d2013-09-11 14:45:20 -07001256 /**
1257 * Returns true if the Allocation has mipmaps.
1258 * @return true if the Allocation has mipmaps
1259 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001260 bool hasMipmaps() const {
1261 return mDimMipmaps;
1262 }
1263
Tim Murray75e877d2013-09-11 14:45:20 -07001264 /**
1265 * Returns true if the Allocation is a cube map
1266 * @return true if the Allocation is a cube map
1267 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001268 bool hasFaces() const {
1269 return mDimFaces;
1270 }
1271
Tim Murray75e877d2013-09-11 14:45:20 -07001272 /**
1273 * Returns number of accessible Elements in the Allocation
1274 * @return number of accessible Elements in the Allocation
1275 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001276 size_t getCount() const {
1277 return mElementCount;
1278 }
1279
Tim Murray75e877d2013-09-11 14:45:20 -07001280 /**
1281 * Returns size in bytes of all Elements in the Allocation
1282 * @return size in bytes of all Elements in the Allocation
1283 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001284 size_t getSizeBytes() const {
1285 return mElementCount * mElement->getSizeBytes();
1286 }
1287
Tim Murray75e877d2013-09-11 14:45:20 -07001288 /**
1289 * Creates a new Type with the given Element and dimensions.
1290 * @param[in] rs RenderScript context
1291 * @param[in] e Element
1292 * @param[in] dimX X dimension
1293 * @param[in] dimY Y dimension
1294 * @param[in] dimZ Z dimension
1295 * @return new Type
1296 */
Tim Murray96267c22013-02-12 11:25:12 -08001297 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 -07001298
1299 class Builder {
1300 protected:
Tim Murray35609072013-12-03 11:36:03 -08001301 RS* mRS;
Tim Murray84bf2b82012-10-31 16:03:16 -07001302 uint32_t mDimX;
1303 uint32_t mDimY;
1304 uint32_t mDimZ;
Tim Murrayeb4426d2013-08-27 15:30:16 -07001305 RSYuvFormat mYuvFormat;
Tim Murray84bf2b82012-10-31 16:03:16 -07001306 bool mDimMipmaps;
1307 bool mDimFaces;
1308 sp<const Element> mElement;
1309
1310 public:
1311 Builder(sp<RS> rs, sp<const Element> e);
1312
1313 void setX(uint32_t value);
Stephen Hines7d1b7572013-08-22 01:24:06 -07001314 void setY(uint32_t value);
Tim Murrayeb4426d2013-08-27 15:30:16 -07001315 void setZ(uint32_t value);
1316 void setYuvFormat(RSYuvFormat format);
Tim Murray84bf2b82012-10-31 16:03:16 -07001317 void setMipmaps(bool value);
1318 void setFaces(bool value);
1319 sp<const Type> create();
1320 };
1321
1322};
1323
Tim Murray75e877d2013-09-11 14:45:20 -07001324/**
1325 * The parent class for all executable Scripts. This should not be used by applications.
1326 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001327class Script : public BaseObj {
1328private:
1329
1330protected:
1331 Script(void *id, sp<RS> rs);
1332 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
1333 const void *v, size_t) const;
1334 void bindAllocation(sp<Allocation> va, uint32_t slot) const;
1335 void setVar(uint32_t index, const void *, size_t len) const;
1336 void setVar(uint32_t index, sp<const BaseObj> o) const;
1337 void invoke(uint32_t slot, const void *v, size_t len) const;
1338
1339
1340 void invoke(uint32_t slot) const {
1341 invoke(slot, NULL, 0);
1342 }
1343 void setVar(uint32_t index, float v) const {
1344 setVar(index, &v, sizeof(v));
1345 }
1346 void setVar(uint32_t index, double v) const {
1347 setVar(index, &v, sizeof(v));
1348 }
1349 void setVar(uint32_t index, int32_t v) const {
1350 setVar(index, &v, sizeof(v));
1351 }
1352 void setVar(uint32_t index, int64_t v) const {
1353 setVar(index, &v, sizeof(v));
1354 }
1355 void setVar(uint32_t index, bool v) const {
1356 setVar(index, &v, sizeof(v));
1357 }
1358
1359public:
1360 class FieldBase {
1361 protected:
1362 sp<const Element> mElement;
1363 sp<Allocation> mAllocation;
1364
1365 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
1366
1367 public:
1368 sp<const Element> getElement() {
1369 return mElement;
1370 }
1371
1372 sp<const Type> getType() {
1373 return mAllocation->getType();
1374 }
1375
1376 sp<const Allocation> getAllocation() {
1377 return mAllocation;
1378 }
1379
1380 //void updateAllocation();
1381 };
1382};
1383
Tim Murray75e877d2013-09-11 14:45:20 -07001384/**
1385 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only.
1386 */
Tim Murray84bf2b82012-10-31 16:03:16 -07001387class ScriptC : public Script {
1388protected:
1389 ScriptC(sp<RS> rs,
1390 const void *codeTxt, size_t codeLength,
1391 const char *cachedName, size_t cachedNameLength,
1392 const char *cacheDir, size_t cacheDirLength);
1393
1394};
1395
Tim Murray75e877d2013-09-11 14:45:20 -07001396/**
1397 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of
1398 * basic functions. This is not intended to be used directly.
1399 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001400class ScriptIntrinsic : public Script {
1401 protected:
Tim Murray10913a52013-08-20 17:19:47 -07001402 sp<const Element> mElement;
Tim Murray3cd44af2012-11-14 11:25:27 -08001403 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001404 virtual ~ScriptIntrinsic();
Tim Murray7f0d5682012-11-08 16:35:24 -08001405};
1406
Tim Murray75e877d2013-09-11 14:45:20 -07001407/**
1408 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming
1409 * r,g,b values are use as normalized x,y,z coordinates into a 3D
1410 * allocation. The 8 nearest values are sampled and linearly interpolated. The
1411 * result is placed in the output.
1412 */
Tim Murray89daad62013-07-29 14:30:02 -07001413class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001414 private:
Tim Murray89daad62013-07-29 14:30:02 -07001415 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001416 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001417 /**
1418 * Supported Element types are U8_4. Default lookup table is identity.
1419 * @param[in] rs RenderScript context
1420 * @param[in] e Element
1421 * @return new ScriptIntrinsic
1422 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001423 static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001424
1425 /**
1426 * Launch the intrinsic.
1427 * @param[in] ain input Allocation
1428 * @param[in] aout output Allocation
1429 */
Tim Murray89daad62013-07-29 14:30:02 -07001430 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001431
1432 /**
1433 * Sets the lookup table. The lookup table must use the same Element as the
1434 * intrinsic.
1435 * @param[in] lut new lookup table
1436 */
Tim Murray89daad62013-07-29 14:30:02 -07001437 void setLUT(sp<Allocation> lut);
1438};
1439
Tim Murray75e877d2013-09-11 14:45:20 -07001440/**
1441 * Intrinsic kernel for blending two Allocations.
1442 */
Tim Murray7f0d5682012-11-08 16:35:24 -08001443class ScriptIntrinsicBlend : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001444 private:
Tim Murray89daad62013-07-29 14:30:02 -07001445 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001446 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001447 /**
1448 * Supported Element types are U8_4.
1449 * @param[in] rs RenderScript context
1450 * @param[in] e Element
1451 * @return new ScriptIntrinsicBlend
1452 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001453 static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001454 /**
1455 * sets dst = {0, 0, 0, 0}
1456 * @param[in] in input Allocation
1457 * @param[in] out output Allocation
1458 */
1459 void forEachClear(sp<Allocation> in, sp<Allocation> out);
1460 /**
1461 * Sets dst = src
1462 * @param[in] in input Allocation
1463 * @param[in] out output Allocation
1464 */
1465 void forEachSrc(sp<Allocation> in, sp<Allocation> out);
1466 /**
1467 * Sets dst = dst (NOP)
1468 * @param[in] in input Allocation
1469 * @param[in] out output Allocation
1470 */
1471 void forEachDst(sp<Allocation> in, sp<Allocation> out);
1472 /**
1473 * Sets dst = src + dst * (1.0 - src.a)
1474 * @param[in] in input Allocation
1475 * @param[in] out output Allocation
1476 */
1477 void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
1478 /**
1479 * Sets dst = dst + src * (1.0 - dst.a)
1480 * @param[in] in input Allocation
1481 * @param[in] out output Allocation
1482 */
1483 void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
1484 /**
1485 * Sets dst = src * dst.a
1486 * @param[in] in input Allocation
1487 * @param[in] out output Allocation
1488 */
1489 void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
1490 /**
1491 * Sets dst = dst * src.a
1492 * @param[in] in input Allocation
1493 * @param[in] out output Allocation
1494 */
1495 void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
1496 /**
1497 * Sets dst = src * (1.0 - dst.a)
1498 * @param[in] in input Allocation
1499 * @param[in] out output Allocation
1500 */
1501 void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
1502 /**
1503 * Sets dst = dst * (1.0 - src.a)
1504 * @param[in] in input Allocation
1505 * @param[in] out output Allocation
1506 */
1507 void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
1508 /**
1509 * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
1510 * @param[in] in input Allocation
1511 * @param[in] out output Allocation
1512 */
1513 void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
1514 /**
1515 * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
1516 * @param[in] in input Allocation
1517 * @param[in] out output Allocation
1518 */
1519 void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
1520 /**
1521 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
1522 * @param[in] in input Allocation
1523 * @param[in] out output Allocation
1524 */
1525 void forEachXor(sp<Allocation> in, sp<Allocation> out);
1526 /**
1527 * Sets dst = src * dst
1528 * @param[in] in input Allocation
1529 * @param[in] out output Allocation
1530 */
1531 void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
1532 /**
1533 * Sets dst = min(src + dst, 1.0)
1534 * @param[in] in input Allocation
1535 * @param[in] out output Allocation
1536 */
1537 void forEachAdd(sp<Allocation> in, sp<Allocation> out);
1538 /**
1539 * Sets dst = max(dst - src, 0.0)
1540 * @param[in] in input Allocation
1541 * @param[in] out output Allocation
1542 */
1543 void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
Tim Murray7f0d5682012-11-08 16:35:24 -08001544};
Tim Murray84bf2b82012-10-31 16:03:16 -07001545
Tim Murray75e877d2013-09-11 14:45:20 -07001546/**
1547 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified
1548 * radius to all elements of an Allocation.
1549 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001550class ScriptIntrinsicBlur : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001551 private:
Tim Murray89daad62013-07-29 14:30:02 -07001552 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001553 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001554 /**
1555 * Supported Element types are U8 and U8_4.
1556 * @param[in] rs RenderScript context
1557 * @param[in] e Element
1558 * @return new ScriptIntrinsicBlur
1559 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001560 static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001561 /**
1562 * Sets the input of the blur.
1563 * @param[in] in input Allocation
1564 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001565 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001566 /**
1567 * Runs the intrinsic.
1568 * @param[in] output Allocation
1569 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001570 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001571 /**
1572 * Sets the radius of the blur. The supported range is 0 < radius <= 25.
1573 * @param[in] radius radius of the blur
1574 */
Tim Murray8f1e60c2012-11-13 12:25:11 -08001575 void setRadius(float radius);
1576};
1577
Tim Murray75e877d2013-09-11 14:45:20 -07001578/**
1579 * Intrinsic for applying a color matrix to allocations. This has the
1580 * same effect as loading each element and converting it to a
1581 * F32_N, multiplying the result by the 4x4 color matrix
1582 * as performed by rsMatrixMultiply() and writing it to the output
1583 * after conversion back to U8_N or F32_N.
1584 */
Tim Murray89daad62013-07-29 14:30:02 -07001585class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001586 private:
Tim Murray89daad62013-07-29 14:30:02 -07001587 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001588 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001589 /**
1590 * Creates a new intrinsic.
1591 * @param[in] rs RenderScript context
1592 * @return new ScriptIntrinsicColorMatrix
1593 */
Tim Murrayaae73c92013-09-03 17:05:46 -07001594 static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001595 /**
1596 * Applies the color matrix. Supported types are U8 and F32 with
1597 * vector lengths between 1 and 4.
1598 * @param[in] in input Allocation
1599 * @param[out] out output Allocation
1600 */
Tim Murray89daad62013-07-29 14:30:02 -07001601 void forEach(sp<Allocation> in, sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001602 /**
1603 * Set the value to be added after the color matrix has been
1604 * applied. The default value is {0, 0, 0, 0}.
1605 * @param[in] add float[4] of values
1606 */
Tim Murray10913a52013-08-20 17:19:47 -07001607 void setAdd(float* add);
Tim Murray75e877d2013-09-11 14:45:20 -07001608
1609 /**
1610 * Set the color matrix which will be applied to each cell of the
1611 * image. The alpha channel will be copied.
1612 *
1613 * @param[in] m float[9] of values
1614 */
Tim Murray89daad62013-07-29 14:30:02 -07001615 void setColorMatrix3(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001616 /**
1617 * Set the color matrix which will be applied to each cell of the
1618 * image.
1619 *
1620 * @param[in] m float[16] of values
1621 */
Tim Murray89daad62013-07-29 14:30:02 -07001622 void setColorMatrix4(float* m);
Tim Murray75e877d2013-09-11 14:45:20 -07001623 /**
1624 * Set a color matrix to convert from RGB to luminance. The alpha
1625 * channel will be a copy.
1626 */
Tim Murray89daad62013-07-29 14:30:02 -07001627 void setGreyscale();
Tim Murray75e877d2013-09-11 14:45:20 -07001628 /**
1629 * Set the matrix to convert from RGB to YUV with a direct copy of
1630 * the 4th channel.
1631 */
Tim Murray89daad62013-07-29 14:30:02 -07001632 void setRGBtoYUV();
Tim Murray75e877d2013-09-11 14:45:20 -07001633 /**
1634 * Set the matrix to convert from YUV to RGB with a direct copy of
1635 * the 4th channel.
1636 */
Tim Murray89daad62013-07-29 14:30:02 -07001637 void setYUVtoRGB();
1638};
1639
Tim Murray75e877d2013-09-11 14:45:20 -07001640/**
1641 * Intrinsic for applying a 3x3 convolve to an allocation.
1642 */
Tim Murray89daad62013-07-29 14:30:02 -07001643class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001644 private:
Tim Murray89daad62013-07-29 14:30:02 -07001645 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001646 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001647 /**
1648 * Supported types U8 and F32 with vector lengths between 1 and
1649 * 4. The default convolution kernel is the identity.
1650 * @param[in] rs RenderScript context
1651 * @param[in] e Element
1652 * @return new ScriptIntrinsicConvolve3x3
1653 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001654 static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001655 /**
1656 * Sets input for intrinsic.
1657 * @param[in] in input Allocation
1658 */
Tim Murray89daad62013-07-29 14:30:02 -07001659 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001660 /**
1661 * Launches the intrinsic.
1662 * @param[in] out output Allocation
1663 */
Tim Murray89daad62013-07-29 14:30:02 -07001664 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001665 /**
1666 * Sets convolution kernel.
1667 * @param[in] v float[9] of values
1668 */
Tim Murray89daad62013-07-29 14:30:02 -07001669 void setCoefficients(float* v);
1670};
1671
Tim Murray75e877d2013-09-11 14:45:20 -07001672/**
1673 * Intrinsic for applying a 5x5 convolve to an allocation.
1674 */
Tim Murray89daad62013-07-29 14:30:02 -07001675class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001676 private:
Tim Murray89daad62013-07-29 14:30:02 -07001677 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001678 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001679 /**
1680 * Supported types U8 and F32 with vector lengths between 1 and
1681 * 4. The default convolution kernel is the identity.
1682 * @param[in] rs RenderScript context
1683 * @param[in] e Element
1684 * @return new ScriptIntrinsicConvolve5x5
1685 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001686 static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001687 /**
1688 * Sets input for intrinsic.
1689 * @param[in] in input Allocation
1690 */
Tim Murray89daad62013-07-29 14:30:02 -07001691 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001692 /**
1693 * Launches the intrinsic.
1694 * @param[in] out output Allocation
1695 */
Tim Murray89daad62013-07-29 14:30:02 -07001696 void forEach(sp<Allocation> out);
Tim Murray75e877d2013-09-11 14:45:20 -07001697 /**
1698 * Sets convolution kernel.
1699 * @param[in] v float[25] of values
1700 */
Tim Murray89daad62013-07-29 14:30:02 -07001701 void setCoefficients(float* v);
1702};
1703
Tim Murray75e877d2013-09-11 14:45:20 -07001704/**
1705 * Intrinsic for computing a histogram.
1706 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001707class ScriptIntrinsicHistogram : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001708 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001709 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
Tim Murray10913a52013-08-20 17:19:47 -07001710 sp<Allocation> mOut;
Tim Murray21fa7a02013-08-15 16:25:03 -07001711 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001712 /**
1713 * Create an intrinsic for calculating the histogram of an uchar
1714 * or uchar4 image.
1715 *
1716 * Supported elements types are U8_4, U8_3, U8_2, and U8.
1717 *
1718 * @param[in] rs The RenderScript context
1719 * @param[in] e Element type for inputs
1720 *
1721 * @return ScriptIntrinsicHistogram
1722 */
Tim Murray10913a52013-08-20 17:19:47 -07001723 static sp<ScriptIntrinsicHistogram> create(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001724 /**
1725 * Set the output of the histogram. 32 bit integer types are
1726 * supported.
1727 *
1728 * @param[in] aout The output allocation
1729 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001730 void setOutput(sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001731 /**
1732 * Set the coefficients used for the dot product calculation. The
1733 * default is {0.299f, 0.587f, 0.114f, 0.f}.
1734 *
1735 * Coefficients must be >= 0 and sum to 1.0 or less.
1736 *
1737 * @param[in] r Red coefficient
1738 * @param[in] g Green coefficient
1739 * @param[in] b Blue coefficient
1740 * @param[in] a Alpha coefficient
1741 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001742 void setDotCoefficients(float r, float g, float b, float a);
Tim Murray75e877d2013-09-11 14:45:20 -07001743 /**
1744 * Process an input buffer and place the histogram into the output
1745 * allocation. The output allocation may be a narrower vector size
1746 * than the input. In this case the vector size of the output is
1747 * used to determine how many of the input channels are used in
1748 * the computation. This is useful if you have an RGBA input
1749 * buffer but only want the histogram for RGB.
1750 *
1751 * 1D and 2D input allocations are supported.
1752 *
1753 * @param[in] ain The input image
1754 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001755 void forEach(sp<Allocation> ain);
Tim Murray75e877d2013-09-11 14:45:20 -07001756 /**
1757 * Process an input buffer and place the histogram into the output
1758 * allocation. The dot product of the input channel and the
1759 * coefficients from 'setDotCoefficients' are used to calculate
1760 * the output values.
1761 *
1762 * 1D and 2D input allocations are supported.
1763 *
1764 * @param ain The input image
1765 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001766 void forEach_dot(sp<Allocation> ain);
1767};
1768
Tim Murray75e877d2013-09-11 14:45:20 -07001769/**
1770 * Intrinsic for applying a per-channel lookup table. Each channel of
1771 * the input has an independant lookup table. The tables are 256
1772 * entries in size and can cover the full value range of U8_4.
1773 **/
Tim Murrayb27b1812013-08-05 14:00:40 -07001774class ScriptIntrinsicLUT : public ScriptIntrinsic {
1775 private:
1776 sp<Allocation> LUT;
1777 bool mDirty;
1778 unsigned char mCache[1024];
Tim Murray2acce992013-08-28 14:23:31 -07001779 void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray21fa7a02013-08-15 16:25:03 -07001780 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -07001781
Tim Murray89daad62013-07-29 14:30:02 -07001782 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001783 /**
1784 * Supported elements types are U8_4.
1785 *
1786 * The defaults tables are identity.
1787 *
1788 * @param[in] rs The RenderScript context
1789 * @param[in] e Element type for intputs and outputs
1790 *
1791 * @return ScriptIntrinsicLUT
1792 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001793 static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001794 /**
1795 * Invoke the kernel and apply the lookup to each cell of ain and
1796 * copy to aout.
1797 *
1798 * @param[in] ain Input allocation
1799 * @param[in] aout Output allocation
1800 */
Tim Murray89daad62013-07-29 14:30:02 -07001801 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murray75e877d2013-09-11 14:45:20 -07001802 /**
1803 * Sets entries in LUT for the red channel.
1804 * @param[in] base base of region to update
1805 * @param[in] length length of region to update
1806 * @param[in] lutValues LUT values to use
1807 */
Tim Murray2acce992013-08-28 14:23:31 -07001808 void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001809 /**
1810 * Sets entries in LUT for the green channel.
1811 * @param[in] base base of region to update
1812 * @param[in] length length of region to update
1813 * @param[in] lutValues LUT values to use
1814 */
Tim Murray2acce992013-08-28 14:23:31 -07001815 void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001816 /**
1817 * Sets entries in LUT for the blue channel.
1818 * @param[in] base base of region to update
1819 * @param[in] length length of region to update
1820 * @param[in] lutValues LUT values to use
1821 */
Tim Murray2acce992013-08-28 14:23:31 -07001822 void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murray75e877d2013-09-11 14:45:20 -07001823 /**
1824 * Sets entries in LUT for the alpha channel.
1825 * @param[in] base base of region to update
1826 * @param[in] length length of region to update
1827 * @param[in] lutValues LUT values to use
1828 */
Tim Murray2acce992013-08-28 14:23:31 -07001829 void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
Tim Murrayb27b1812013-08-05 14:00:40 -07001830 virtual ~ScriptIntrinsicLUT();
1831};
1832
Tim Murray75e877d2013-09-11 14:45:20 -07001833/**
1834 * Intrinsic for converting an Android YUV buffer to RGB.
1835 *
1836 * The input allocation should be supplied in a supported YUV format
1837 * as a YUV element Allocation. The output is RGBA; the alpha channel
1838 * will be set to 255.
1839 */
Tim Murray89daad62013-07-29 14:30:02 -07001840class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
Tim Murray21fa7a02013-08-15 16:25:03 -07001841 private:
Tim Murrayb27b1812013-08-05 14:00:40 -07001842 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
Tim Murray21fa7a02013-08-15 16:25:03 -07001843 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001844 /**
1845 * Create an intrinsic for converting YUV to RGB.
1846 *
1847 * Supported elements types are U8_4.
1848 *
1849 * @param[in] rs The RenderScript context
1850 * @param[in] e Element type for output
1851 *
1852 * @return ScriptIntrinsicYuvToRGB
1853 */
Tim Murray21fa7a02013-08-15 16:25:03 -07001854 static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
Tim Murray75e877d2013-09-11 14:45:20 -07001855 /**
1856 * Set the input YUV allocation.
1857 *
1858 * @param[in] ain The input allocation.
1859 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001860 void setInput(sp<Allocation> in);
Tim Murray75e877d2013-09-11 14:45:20 -07001861
1862 /**
1863 * Convert the image to RGB.
1864 *
1865 * @param[in] aout Output allocation. Must match creation element
1866 * type.
1867 */
Tim Murrayb27b1812013-08-05 14:00:40 -07001868 void forEach(sp<Allocation> out);
Tim Murray89daad62013-07-29 14:30:02 -07001869
1870};
Tim Murrayb27b1812013-08-05 14:00:40 -07001871
Tim Murray75e877d2013-09-11 14:45:20 -07001872/**
1873 * Sampler object that defines how Allocations can be read as textures
1874 * within a kernel. Samplers are used in conjunction with the rsSample
1875 * runtime function to return values from normalized coordinates.
1876 *
1877 * Any Allocation used with a Sampler must have been created with
1878 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an
1879 * Allocation that was not created with
1880 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined.
1881 **/
Tim Murray729b6fe2013-07-23 16:20:42 -07001882 class Sampler : public BaseObj {
1883 private:
1884 Sampler(sp<RS> rs, void* id);
1885 RsSamplerValue mMin;
1886 RsSamplerValue mMag;
1887 RsSamplerValue mWrapS;
1888 RsSamplerValue mWrapT;
1889 RsSamplerValue mWrapR;
1890 float mAniso;
1891
1892 public:
Tim Murray75e877d2013-09-11 14:45:20 -07001893 /**
1894 * Creates a non-standard Sampler.
1895 * @param[in] rs RenderScript context
1896 * @param[in] min minification
1897 * @param[in] mag magnification
1898 * @param[in] wrapS S wrapping mode
1899 * @param[in] wrapT T wrapping mode
1900 * @param[in] anisotropy anisotropy setting
1901 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001902 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
1903
Tim Murray75e877d2013-09-11 14:45:20 -07001904 /**
1905 * @return minification setting for the sampler
1906 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001907 RsSamplerValue getMinification();
Tim Murray75e877d2013-09-11 14:45:20 -07001908 /**
1909 * @return magnification setting for the sampler
1910 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001911 RsSamplerValue getMagnification();
Tim Murray75e877d2013-09-11 14:45:20 -07001912 /**
1913 * @return S wrapping mode for the sampler
1914 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001915 RsSamplerValue getWrapS();
Tim Murray75e877d2013-09-11 14:45:20 -07001916 /**
1917 * @return T wrapping mode for the sampler
1918 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001919 RsSamplerValue getWrapT();
Tim Murray75e877d2013-09-11 14:45:20 -07001920 /**
1921 * @return anisotropy setting for the sampler
1922 */
Tim Murray729b6fe2013-07-23 16:20:42 -07001923 float getAnisotropy();
1924
Tim Murray75e877d2013-09-11 14:45:20 -07001925 /**
1926 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1927 * clamp.
1928 *
1929 * @param rs Context to which the sampler will belong.
1930 *
1931 * @return Sampler
1932 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001933 static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001934 /**
1935 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1936 * clamp.
1937 *
1938 * @param rs Context to which the sampler will belong.
1939 *
1940 * @return Sampler
1941 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001942 static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001943 /**
1944 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
1945 * wrap modes set to clamp.
1946 *
1947 * @param rs Context to which the sampler will belong.
1948 *
1949 * @return Sampler
1950 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001951 static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001952 /**
1953 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1954 * wrap.
1955 *
1956 * @param rs Context to which the sampler will belong.
1957 *
1958 * @return Sampler
1959 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001960 static sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001961 /**
1962 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1963 * wrap.
1964 *
1965 * @param rs Context to which the sampler will belong.
1966 *
1967 * @return Sampler
1968 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001969 static sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001970 /**
1971 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
1972 * wrap modes set to wrap.
1973 *
1974 * @param rs Context to which the sampler will belong.
1975 *
1976 * @return Sampler
1977 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001978 static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001979 /**
1980 * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1981 * mirrored repeat.
1982 *
1983 * @param rs Context to which the sampler will belong.
1984 *
1985 * @return Sampler
1986 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001987 static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001988 /**
1989 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1990 * mirrored repeat.
1991 *
1992 * @param rs Context to which the sampler will belong.
1993 *
1994 * @return Sampler
1995 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08001996 static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
Tim Murray75e877d2013-09-11 14:45:20 -07001997 /**
1998 * Retrieve a sampler with min and mag set to linear and wrap modes set to
1999 * mirrored repeat.
2000 *
2001 * @param rs Context to which the sampler will belong.
2002 *
2003 * @return Sampler
2004 */
Stephen Hines8a588bd2013-11-26 15:38:31 -08002005 static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
Tim Murray729b6fe2013-07-23 16:20:42 -07002006
2007};
2008
Stephen Hinesd10412f2013-08-29 18:27:21 -07002009class Byte2 {
2010 public:
2011 int8_t x, y;
2012
2013 Byte2(int8_t initX, int8_t initY)
2014 : x(initX), y(initY) {}
2015 Byte2() : x(0), y(0) {}
2016};
2017
2018class Byte3 {
2019 public:
2020 int8_t x, y, z;
2021
2022 Byte3(int8_t initX, int8_t initY, int8_t initZ)
2023 : x(initX), y(initY), z(initZ) {}
2024 Byte3() : x(0), y(0), z(0) {}
2025};
2026
2027class Byte4 {
2028 public:
2029 int8_t x, y, z, w;
2030
2031 Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
2032 : x(initX), y(initY), z(initZ), w(initW) {}
2033 Byte4() : x(0), y(0), z(0), w(0) {}
2034};
2035
2036class UByte2 {
2037 public:
2038 uint8_t x, y;
2039
2040 UByte2(uint8_t initX, uint8_t initY)
2041 : x(initX), y(initY) {}
2042 UByte2() : x(0), y(0) {}
2043};
2044
2045class UByte3 {
2046 public:
2047 uint8_t x, y, z;
2048
2049 UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
2050 : x(initX), y(initY), z(initZ) {}
2051 UByte3() : x(0), y(0), z(0) {}
2052};
2053
2054class UByte4 {
2055 public:
2056 uint8_t x, y, z, w;
2057
2058 UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
2059 : x(initX), y(initY), z(initZ), w(initW) {}
2060 UByte4() : x(0), y(0), z(0), w(0) {}
2061};
2062
2063class Short2 {
2064 public:
2065 short x, y;
2066
2067 Short2(short initX, short initY)
2068 : x(initX), y(initY) {}
2069 Short2() : x(0), y(0) {}
2070};
2071
2072class Short3 {
2073 public:
2074 short x, y, z;
2075
2076 Short3(short initX, short initY, short initZ)
2077 : x(initX), y(initY), z(initZ) {}
2078 Short3() : x(0), y(0), z(0) {}
2079};
2080
2081class Short4 {
2082 public:
2083 short x, y, z, w;
2084
2085 Short4(short initX, short initY, short initZ, short initW)
2086 : x(initX), y(initY), z(initZ), w(initW) {}
2087 Short4() : x(0), y(0), z(0), w(0) {}
2088};
2089
2090class UShort2 {
2091 public:
2092 uint16_t x, y;
2093
2094 UShort2(uint16_t initX, uint16_t initY)
2095 : x(initX), y(initY) {}
2096 UShort2() : x(0), y(0) {}
2097};
2098
2099class UShort3 {
2100 public:
2101 uint16_t x, y, z;
2102
2103 UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
2104 : x(initX), y(initY), z(initZ) {}
2105 UShort3() : x(0), y(0), z(0) {}
2106};
2107
2108class UShort4 {
2109 public:
2110 uint16_t x, y, z, w;
2111
2112 UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
2113 : x(initX), y(initY), z(initZ), w(initW) {}
2114 UShort4() : x(0), y(0), z(0), w(0) {}
2115};
2116
2117class Int2 {
2118 public:
2119 int x, y;
2120
2121 Int2(int initX, int initY)
2122 : x(initX), y(initY) {}
2123 Int2() : x(0), y(0) {}
2124};
2125
2126class Int3 {
2127 public:
2128 int x, y, z;
2129
2130 Int3(int initX, int initY, int initZ)
2131 : x(initX), y(initY), z(initZ) {}
2132 Int3() : x(0), y(0), z(0) {}
2133};
2134
2135class Int4 {
2136 public:
2137 int x, y, z, w;
2138
2139 Int4(int initX, int initY, int initZ, int initW)
2140 : x(initX), y(initY), z(initZ), w(initW) {}
2141 Int4() : x(0), y(0), z(0), w(0) {}
2142};
2143
2144class UInt2 {
2145 public:
2146 uint32_t x, y;
2147
2148 UInt2(uint32_t initX, uint32_t initY)
2149 : x(initX), y(initY) {}
2150 UInt2() : x(0), y(0) {}
2151};
2152
2153class UInt3 {
2154 public:
2155 uint32_t x, y, z;
2156
2157 UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
2158 : x(initX), y(initY), z(initZ) {}
2159 UInt3() : x(0), y(0), z(0) {}
2160};
2161
2162class UInt4 {
2163 public:
2164 uint32_t x, y, z, w;
2165
2166 UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
2167 : x(initX), y(initY), z(initZ), w(initW) {}
2168 UInt4() : x(0), y(0), z(0), w(0) {}
2169};
2170
2171class Long2 {
2172 public:
2173 int64_t x, y;
2174
2175 Long2(int64_t initX, int64_t initY)
2176 : x(initX), y(initY) {}
2177 Long2() : x(0), y(0) {}
2178};
2179
2180class Long3 {
2181 public:
2182 int64_t x, y, z;
2183
2184 Long3(int64_t initX, int64_t initY, int64_t initZ)
2185 : x(initX), y(initY), z(initZ) {}
2186 Long3() : x(0), y(0), z(0) {}
2187};
2188
2189class Long4 {
2190 public:
2191 int64_t x, y, z, w;
2192
2193 Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
2194 : x(initX), y(initY), z(initZ), w(initW) {}
2195 Long4() : x(0), y(0), z(0), w(0) {}
2196};
2197
2198class ULong2 {
2199 public:
2200 uint64_t x, y;
2201
2202 ULong2(uint64_t initX, uint64_t initY)
2203 : x(initX), y(initY) {}
2204 ULong2() : x(0), y(0) {}
2205};
2206
2207class ULong3 {
2208 public:
2209 uint64_t x, y, z;
2210
2211 ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
2212 : x(initX), y(initY), z(initZ) {}
2213 ULong3() : x(0), y(0), z(0) {}
2214};
2215
2216class ULong4 {
2217 public:
2218 uint64_t x, y, z, w;
2219
2220 ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
2221 : x(initX), y(initY), z(initZ), w(initW) {}
2222 ULong4() : x(0), y(0), z(0), w(0) {}
2223};
2224
2225class Float2 {
2226 public:
2227 float x, y;
2228
2229 Float2(float initX, float initY)
2230 : x(initX), y(initY) {}
2231 Float2() : x(0), y(0) {}
2232};
2233
2234class Float3 {
2235 public:
2236 float x, y, z;
2237
2238 Float3(float initX, float initY, float initZ)
2239 : x(initX), y(initY), z(initZ) {}
2240 Float3() : x(0.f), y(0.f), z(0.f) {}
2241};
2242
2243class Float4 {
2244 public:
2245 float x, y, z, w;
2246
2247 Float4(float initX, float initY, float initZ, float initW)
2248 : x(initX), y(initY), z(initZ), w(initW) {}
2249 Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
2250};
2251
2252class Double2 {
2253 public:
2254 double x, y;
2255
2256 Double2(double initX, double initY)
2257 : x(initX), y(initY) {}
2258 Double2() : x(0), y(0) {}
2259};
2260
2261class Double3 {
2262 public:
2263 double x, y, z;
2264
2265 Double3(double initX, double initY, double initZ)
2266 : x(initX), y(initY), z(initZ) {}
2267 Double3() : x(0), y(0), z(0) {}
2268};
2269
2270class Double4 {
2271 public:
2272 double x, y, z, w;
2273
2274 Double4(double initX, double initY, double initZ, double initW)
2275 : x(initX), y(initY), z(initZ), w(initW) {}
2276 Double4() : x(0), y(0), z(0), w(0) {}
2277};
2278
Tim Murray84bf2b82012-10-31 16:03:16 -07002279}
Tim Murray7f0d5682012-11-08 16:35:24 -08002280
Tim Murray84bf2b82012-10-31 16:03:16 -07002281}
2282
2283#endif