rsCppStructs.h revision d5164d537c84867880694327727b5f22b0a3ccbd
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
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
20#include "rsDefines.h"
21#include "util/RefBase.h"
22
23#include <pthread.h>
24
25
26/**
27 * Every row in an RS allocation is guaranteed to be aligned by this amount, and
28 * every row in a user-backed allocation must be aligned by this amount.
29 */
30#define RS_CPU_ALLOCATION_ALIGNMENT 16
31
32struct dispatchTable;
33
34namespace android {
35class Surface;
36
37namespace RSC {
38
39
40typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText);
41typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen);
42
43class RS;
44class BaseObj;
45class Element;
46class Type;
47class Allocation;
48class Script;
49class ScriptC;
50class Sampler;
51
52/**
53 * Possible error codes used by RenderScript. Once a status other than RS_SUCCESS
54 * is returned, the RenderScript context is considered dead and cannot perform any
55 * additional work.
56 */
57 enum RSError {
58     RS_SUCCESS = 0,                 ///< No error
59     RS_ERROR_INVALID_PARAMETER = 1, ///< An invalid parameter was passed to a function
60     RS_ERROR_RUNTIME_ERROR = 2,     ///< The RenderScript driver returned an error; this is
61                                     ///< often indicative of a kernel that crashed
62     RS_ERROR_INVALID_ELEMENT = 3,   ///< An invalid Element was passed to a function
63     RS_ERROR_MAX = 9999
64
65 };
66
67 /**
68  * YUV formats supported by the RenderScript API.
69  */
70 enum RSYuvFormat {
71     RS_YUV_NONE = 0, ///< No YUV data
72     RS_YUV_YV12 = 1, ///< YUV data in YV12 format
73     RS_YUV_NV21 = 2, ///< YUV data in NV21 format
74     RS_YUV_MAX = 3
75 };
76
77 /**
78  * Flags that can control RenderScript behavior on a per-context level.
79  */
80 enum RSInitFlags {
81     RS_INIT_SYNCHRONOUS = 1, ///< All RenderScript calls will be synchronous. May reduce latency.
82     RS_INIT_LOW_LATENCY = 2, ///< Prefer low latency devices over potentially higher throughput devices.
83     // Bitflag 4 is reserved for the context flag low power
84     RS_INIT_WAIT_FOR_ATTACH = 8,   ///< Kernel execution will hold to give time for a debugger to be attached
85     RS_INIT_MAX = 16
86 };
87
88 /**
89  * The RenderScript context. This class controls initialization, resource management, and teardown.
90  */
91 class RS : public android::RSC::LightRefBase<RS> {
92
93 public:
94    RS();
95    virtual ~RS();
96
97    /**
98     * Initializes a RenderScript context. A context must be initialized before it can be used.
99     * @param[in] name Directory name to be used by this context. This should be equivalent to
100     * Context.getCacheDir().
101     * @param[in] flags Optional flags for this context.
102     * @return true on success
103     */
104    bool init(const char * name, uint32_t flags = 0);
105
106    /**
107     * Sets the error handler function for this context. This error handler is
108     * called whenever an error is set.
109     *
110     * @param[in] func Error handler function
111     */
112    void setErrorHandler(ErrorHandlerFunc_t func);
113
114    /**
115     * Returns the current error handler function for this context.
116     *
117     * @return pointer to current error handler function or NULL if not set
118     */
119    ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
120
121    /**
122     * Sets the message handler function for this context. This message handler
123     * is called whenever a message is sent from a RenderScript kernel.
124     *
125     *  @param[in] func Message handler function
126     */
127    void setMessageHandler(MessageHandlerFunc_t func);
128
129    /**
130     * Returns the current message handler function for this context.
131     *
132     * @return pointer to current message handler function or NULL if not set
133     */
134    MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
135
136    /**
137     * Returns current status for the context.
138     *
139     * @return current error
140     */
141    RSError getError();
142
143    /**
144     * Waits for any currently running asynchronous operations to finish. This
145     * should only be used for performance testing and timing.
146     */
147    void finish();
148
149    RsContext getContext() { return mContext; }
150    void throwError(RSError error, const char *errMsg);
151
152    static dispatchTable* dispatch;
153
154 private:
155    static bool usingNative;
156    static bool initDispatch(int targetApi);
157
158    bool init(const char * name, int targetApi, uint32_t flags);
159    static void * threadProc(void *);
160
161    static bool gInitialized;
162    static pthread_mutex_t gInitMutex;
163
164    pthread_t mMessageThreadId;
165    pid_t mNativeMessageThreadId;
166    bool mMessageRun;
167
168    RsDevice mDev;
169    RsContext mContext;
170    RSError mCurrentError;
171
172    ErrorHandlerFunc_t mErrorFunc;
173    MessageHandlerFunc_t mMessageFunc;
174    bool mInit;
175
176    char mCacheDir[PATH_MAX+1];
177    uint32_t mCacheDirLen;
178
179    struct {
180        sp<const Element> U8;
181        sp<const Element> U8_2;
182        sp<const Element> U8_3;
183        sp<const Element> U8_4;
184        sp<const Element> I8;
185        sp<const Element> I8_2;
186        sp<const Element> I8_3;
187        sp<const Element> I8_4;
188        sp<const Element> U16;
189        sp<const Element> U16_2;
190        sp<const Element> U16_3;
191        sp<const Element> U16_4;
192        sp<const Element> I16;
193        sp<const Element> I16_2;
194        sp<const Element> I16_3;
195        sp<const Element> I16_4;
196        sp<const Element> U32;
197        sp<const Element> U32_2;
198        sp<const Element> U32_3;
199        sp<const Element> U32_4;
200        sp<const Element> I32;
201        sp<const Element> I32_2;
202        sp<const Element> I32_3;
203        sp<const Element> I32_4;
204        sp<const Element> U64;
205        sp<const Element> U64_2;
206        sp<const Element> U64_3;
207        sp<const Element> U64_4;
208        sp<const Element> I64;
209        sp<const Element> I64_2;
210        sp<const Element> I64_3;
211        sp<const Element> I64_4;
212        sp<const Element> F32;
213        sp<const Element> F32_2;
214        sp<const Element> F32_3;
215        sp<const Element> F32_4;
216        sp<const Element> F64;
217        sp<const Element> F64_2;
218        sp<const Element> F64_3;
219        sp<const Element> F64_4;
220        sp<const Element> BOOLEAN;
221
222        sp<const Element> ELEMENT;
223        sp<const Element> TYPE;
224        sp<const Element> ALLOCATION;
225        sp<const Element> SAMPLER;
226        sp<const Element> SCRIPT;
227        sp<const Element> MESH;
228        sp<const Element> PROGRAM_FRAGMENT;
229        sp<const Element> PROGRAM_VERTEX;
230        sp<const Element> PROGRAM_RASTER;
231        sp<const Element> PROGRAM_STORE;
232
233        sp<const Element> A_8;
234        sp<const Element> RGB_565;
235        sp<const Element> RGB_888;
236        sp<const Element> RGBA_5551;
237        sp<const Element> RGBA_4444;
238        sp<const Element> RGBA_8888;
239
240        sp<const Element> YUV;
241
242        sp<const Element> MATRIX_4X4;
243        sp<const Element> MATRIX_3X3;
244        sp<const Element> MATRIX_2X2;
245    } mElements;
246
247    struct {
248        sp<const Sampler> CLAMP_NEAREST;
249        sp<const Sampler> CLAMP_LINEAR;
250        sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
251        sp<const Sampler> WRAP_NEAREST;
252        sp<const Sampler> WRAP_LINEAR;
253        sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
254        sp<const Sampler> MIRRORED_REPEAT_NEAREST;
255        sp<const Sampler> MIRRORED_REPEAT_LINEAR;
256        sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
257    } mSamplers;
258    friend class Sampler;
259    friend class Element;
260    friend class ScriptC;
261};
262
263 /**
264  * Base class for all RenderScript objects. Not for direct use by developers.
265  */
266class BaseObj : public android::RSC::LightRefBase<BaseObj> {
267public:
268    void * getID() const;
269    virtual ~BaseObj();
270    virtual void updateFromNative();
271    virtual bool equals(sp<const BaseObj> obj);
272
273protected:
274    void *mID;
275    RS* mRS;
276    const char * mName;
277
278    BaseObj(void *id, sp<RS> rs);
279    void checkValid();
280
281    static void * getObjID(sp<const BaseObj> o);
282
283};
284
285 /**
286  * This class provides the primary method through which data is passed to and
287  * from RenderScript kernels. An Allocation provides the backing store for a
288  * given Type.
289  *
290  * An Allocation also contains a set of usage flags that denote how the
291  * Allocation could be used. For example, an Allocation may have usage flags
292  * specifying that it can be used from a script as well as input to a
293  * Sampler. A developer must synchronize across these different usages using
294  * syncAll(int) in order to ensure that different users of the Allocation have
295  * a consistent view of memory. For example, in the case where an Allocation is
296  * used as the output of one kernel and as Sampler input in a later kernel, a
297  * developer must call syncAll(RS_ALLOCATION_USAGE_SCRIPT) prior to launching the
298  * second kernel to ensure correctness.
299  */
300class Allocation : public BaseObj {
301protected:
302    sp<const Type> mType;
303    uint32_t mUsage;
304    sp<Allocation> mAdaptedAllocation;
305
306    bool mConstrainedLOD;
307    bool mConstrainedFace;
308    bool mConstrainedY;
309    bool mConstrainedZ;
310    bool mReadAllowed;
311    bool mWriteAllowed;
312    bool mAutoPadding;
313    uint32_t mSelectedY;
314    uint32_t mSelectedZ;
315    uint32_t mSelectedLOD;
316    RsAllocationCubemapFace mSelectedFace;
317
318    uint32_t mCurrentDimX;
319    uint32_t mCurrentDimY;
320    uint32_t mCurrentDimZ;
321    uint32_t mCurrentCount;
322
323    void * getIDSafe() const;
324    void updateCacheInfo(sp<const Type> t);
325
326    Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
327
328    void validateIsInt64();
329    void validateIsInt32();
330    void validateIsInt16();
331    void validateIsInt8();
332    void validateIsFloat32();
333    void validateIsFloat64();
334    void validateIsObject();
335
336    virtual void updateFromNative();
337
338    void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
339    void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff,
340                         uint32_t w, uint32_t h, uint32_t d);
341
342public:
343
344    /**
345     * Return Type for the allocation.
346     * @return pointer to underlying Type
347     */
348    sp<const Type> getType() const {
349        return mType;
350    }
351
352    /**
353     * Enable/Disable AutoPadding for Vec3 elements.
354     *
355     * @param useAutoPadding True: enable AutoPadding; flase: disable AutoPadding
356     *
357     */
358    void setAutoPadding(bool useAutoPadding) {
359        mAutoPadding = useAutoPadding;
360    }
361
362    /**
363     * Propagate changes from one usage of the Allocation to other usages of the Allocation.
364     * @param[in] srcLocation source location with changes to propagate elsewhere
365     */
366    void syncAll(RsAllocationUsageType srcLocation);
367
368    /**
369     * Send a buffer to the output stream.  The contents of the Allocation will
370     * be undefined after this operation. This operation is only valid if
371     * USAGE_IO_OUTPUT is set on the Allocation.
372     */
373    void ioSendOutput();
374
375    /**
376     * Receive the latest input into the Allocation. This operation
377     * is only valid if USAGE_IO_INPUT is set on the Allocation.
378     */
379    void ioGetInput();
380
381#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
382    /**
383     * Returns the handle to a raw buffer that is being managed by the screen
384     * compositor. This operation is only valid for Allocations with USAGE_IO_INPUT.
385     * @return Surface associated with allocation
386     */
387    sp<Surface> getSurface();
388
389    /**
390     * Associate a Surface with this Allocation. This
391     * operation is only valid for Allocations with USAGE_IO_OUTPUT.
392     * @param[in] s Surface to associate with allocation
393     */
394    void setSurface(sp<Surface> s);
395#endif
396
397    /**
398     * Generate a mipmap chain. This is only valid if the Type of the Allocation
399     * includes mipmaps. This function will generate a complete set of mipmaps
400     * from the top level LOD and place them into the script memory space. If
401     * the Allocation is also using other memory spaces, a call to
402     * syncAll(Allocation.USAGE_SCRIPT) is required.
403     */
404    void generateMipmaps();
405
406    /**
407     * Copy an array into part of this Allocation.
408     * @param[in] off offset of first Element to be overwritten
409     * @param[in] count number of Elements to copy
410     * @param[in] data array from which to copy
411     */
412    void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
413
414    /**
415     * Copy part of an Allocation into part of this Allocation.
416     * @param[in] off offset of first Element to be overwritten
417     * @param[in] count number of Elements to copy
418     * @param[in] data Allocation from which to copy
419     * @param[in] dataOff offset of first Element in data to copy
420     */
421    void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
422
423    /**
424     * Copy an array into part of this Allocation.
425     * @param[in] off offset of first Element to be overwritten
426     * @param[in] count number of Elements to copy
427     * @param[in] data array from which to copy
428     */
429    void copy1DRangeTo(uint32_t off, size_t count, void *data);
430
431    /**
432     * Copy entire array to an Allocation.
433     * @param[in] data array from which to copy
434     */
435    void copy1DFrom(const void* data);
436
437    /**
438     * Copy entire Allocation to an array.
439     * @param[in] data destination array
440     */
441    void copy1DTo(void* data);
442
443    /**
444     * Copy from an array into a rectangular region in this Allocation. The
445     * array is assumed to be tightly packed.
446     * @param[in] xoff X offset of region to update in this Allocation
447     * @param[in] yoff Y offset of region to update in this Allocation
448     * @param[in] w Width of region to update
449     * @param[in] h Height of region to update
450     * @param[in] data Array from which to copy
451     */
452    void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
453                         const void *data);
454
455    /**
456     * Copy from this Allocation into a rectangular region in an array. The
457     * array is assumed to be tightly packed.
458     * @param[in] xoff X offset of region to copy from this Allocation
459     * @param[in] yoff Y offset of region to copy from this Allocation
460     * @param[in] w Width of region to update
461     * @param[in] h Height of region to update
462     * @param[in] data destination array
463     */
464    void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
465                       void *data);
466
467    /**
468     * Copy from an Allocation into a rectangular region in this Allocation.
469     * @param[in] xoff X offset of region to update in this Allocation
470     * @param[in] yoff Y offset of region to update in this Allocation
471     * @param[in] w Width of region to update
472     * @param[in] h Height of region to update
473     * @param[in] data Allocation from which to copy
474     * @param[in] dataXoff X offset of region to copy from in data
475     * @param[in] dataYoff Y offset of region to copy from in data
476     */
477    void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
478                         sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
479
480    /**
481     * Copy from a strided array into a rectangular region in this Allocation.
482     * @param[in] xoff X offset of region to update in this Allocation
483     * @param[in] yoff Y offset of region to update in this Allocation
484     * @param[in] w Width of region to update
485     * @param[in] h Height of region to update
486     * @param[in] data array from which to copy
487     * @param[in] stride stride of data in bytes
488     */
489    void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
490                           const void *data, size_t stride);
491
492    /**
493     * Copy from a strided array into this Allocation.
494     * @param[in] data array from which to copy
495     * @param[in] stride stride of data in bytes
496     */
497    void copy2DStridedFrom(const void *data, size_t stride);
498
499    /**
500     * Copy from a rectangular region in this Allocation into a strided array.
501     * @param[in] xoff X offset of region to update in this Allocation
502     * @param[in] yoff Y offset of region to update in this Allocation
503     * @param[in] w Width of region to update
504     * @param[in] h Height of region to update
505     * @param[in] data destination array
506     * @param[in] stride stride of data in bytes
507     */
508    void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
509                         void *data, size_t stride);
510
511    /**
512     * Copy this Allocation into a strided array.
513     * @param[in] data destination array
514     * @param[in] stride stride of data in bytes
515     */
516    void copy2DStridedTo(void *data, size_t stride);
517
518
519    /**
520     * Copy from an array into a 3D region in this Allocation. The
521     * array is assumed to be tightly packed.
522     * @param[in] xoff X offset of region to update in this Allocation
523     * @param[in] yoff Y offset of region to update in this Allocation
524     * @param[in] zoff Z offset of region to update in this Allocation
525     * @param[in] w Width of region to update
526     * @param[in] h Height of region to update
527     * @param[in] d Depth of region to update
528     * @param[in] data Array from which to copy
529     */
530    void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
531                         uint32_t h, uint32_t d, const void* data);
532
533    /**
534     * Copy from an Allocation into a 3D region in this Allocation.
535     * @param[in] xoff X offset of region to update in this Allocation
536     * @param[in] yoff Y offset of region to update in this Allocation
537     * @param[in] zoff Z offset of region to update in this Allocation
538     * @param[in] w Width of region to update
539     * @param[in] h Height of region to update
540     * @param[in] d Depth of region to update
541     * @param[in] data Allocation from which to copy
542     * @param[in] dataXoff X offset of region in data to copy from
543     * @param[in] dataYoff Y offset of region in data to copy from
544     * @param[in] dataZoff Z offset of region in data to copy from
545     */
546    void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
547                         uint32_t w, uint32_t h, uint32_t d,
548                         sp<const Allocation> data,
549                         uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
550
551    /**
552     * Copy a 3D region in this Allocation into an array. The
553     * array is assumed to be tightly packed.
554     * @param[in] xoff X offset of region to update in this Allocation
555     * @param[in] yoff Y offset of region to update in this Allocation
556     * @param[in] zoff Z offset of region to update in this Allocation
557     * @param[in] w Width of region to update
558     * @param[in] h Height of region to update
559     * @param[in] d Depth of region to update
560     * @param[in] data Array from which to copy
561     */
562    void copy3DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
563                         uint32_t h, uint32_t d, void* data);
564
565    /**
566     * Creates an Allocation for use by scripts with a given Type.
567     * @param[in] rs Context to which the Allocation will belong
568     * @param[in] type Type of the Allocation
569     * @param[in] mipmaps desired mipmap behavior for the Allocation
570     * @param[in] usage usage for the Allocation
571     * @return new Allocation
572     */
573    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
574                                   RsAllocationMipmapControl mipmaps, uint32_t usage);
575
576    /**
577     * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use
578     * with RS_ALLOCATION_USAGE_SHARED.
579     * @param[in] rs Context to which the Allocation will belong
580     * @param[in] type Type of the Allocation
581     * @param[in] mipmaps desired mipmap behavior for the Allocation
582     * @param[in] usage usage for the Allocation
583     * @param[in] pointer existing backing store to use for this Allocation if possible
584     * @return new Allocation
585     */
586    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
587                                   RsAllocationMipmapControl mipmaps, uint32_t usage, void * pointer);
588
589    /**
590     * Creates an Allocation for use by scripts with a given Type with no mipmaps.
591     * @param[in] rs Context to which the Allocation will belong
592     * @param[in] type Type of the Allocation
593     * @param[in] usage usage for the Allocation
594     * @return new Allocation
595     */
596    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
597                                   uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
598    /**
599     * Creates an Allocation with a specified number of given elements.
600     * @param[in] rs Context to which the Allocation will belong
601     * @param[in] e Element used in the Allocation
602     * @param[in] count Number of elements of the Allocation
603     * @param[in] usage usage for the Allocation
604     * @return new Allocation
605     */
606    static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
607                                   uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
608
609    /**
610     * Creates a 2D Allocation with a specified number of given elements.
611     * @param[in] rs Context to which the Allocation will belong
612     * @param[in] e Element used in the Allocation
613     * @param[in] x Width in Elements of the Allocation
614     * @param[in] y Height of the Allocation
615     * @param[in] usage usage for the Allocation
616     * @return new Allocation
617     */
618    static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
619                                        size_t x, size_t y,
620                                        uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
621
622
623    /**
624     * Get the backing pointer for a USAGE_SHARED allocation.
625     * @param[in] stride optional parameter. when non-NULL, will contain
626     *   stride in bytes of a 2D Allocation
627     * @return pointer to data
628     */
629    void * getPointer(size_t *stride = NULL);
630};
631
632 /**
633  * An Element represents one item within an Allocation. An Element is roughly
634  * equivalent to a C type in a RenderScript kernel. Elements may be basic
635  * or complex. Some basic elements are:
636
637  * - A single float value (equivalent to a float in a kernel)
638  * - A four-element float vector (equivalent to a float4 in a kernel)
639  * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel)
640  * - A single signed 8-bit integer (equivalent to a char in a kernel)
641
642  * Basic Elements are comprised of a Element.DataType and a
643  * Element.DataKind. The DataType encodes C type information of an Element,
644  * while the DataKind encodes how that Element should be interpreted by a
645  * Sampler. Note that Allocation objects with DataKind USER cannot be used as
646  * input for a Sampler. In general, Allocation objects that are intended for
647  * use with a Sampler should use bitmap-derived Elements such as
648  * Element::RGBA_8888.
649 */
650
651
652class Element : public BaseObj {
653public:
654    bool isComplex();
655
656    /**
657     * Elements could be simple, such as an int or a float, or a structure with
658     * multiple sub-elements, such as a collection of floats, float2,
659     * float4. This function returns zero for simple elements or the number of
660     * sub-elements otherwise.
661     * @return number of sub-elements
662     */
663    size_t getSubElementCount() {
664        return mVisibleElementMapSize;
665    }
666
667    /**
668     * For complex Elements, this returns the sub-element at a given index.
669     * @param[in] index index of sub-element
670     * @return sub-element
671     */
672    sp<const Element> getSubElement(uint32_t index);
673
674    /**
675     * For complex Elements, this returns the name of the sub-element at a given
676     * index.
677     * @param[in] index index of sub-element
678     * @return name of sub-element
679     */
680    const char * getSubElementName(uint32_t index);
681
682    /**
683     * For complex Elements, this returns the size of the sub-element at a given
684     * index.
685     * @param[in] index index of sub-element
686     * @return size of sub-element
687     */
688    size_t getSubElementArraySize(uint32_t index);
689
690    /**
691     * Returns the location of a sub-element within a complex Element.
692     * @param[in] index index of sub-element
693     * @return offset in bytes
694     */
695    uint32_t getSubElementOffsetBytes(uint32_t index);
696
697    /**
698     * Returns the data type used for the Element.
699     * @return data type
700     */
701    RsDataType getDataType() const {
702        return mType;
703    }
704
705    /**
706     * Returns the data kind used for the Element.
707     * @return data kind
708     */
709    RsDataKind getDataKind() const {
710        return mKind;
711    }
712
713    /**
714     * Returns the size in bytes of the Element.
715     * @return size in bytes
716     */
717    size_t getSizeBytes() const {
718        return mSizeBytes;
719    }
720
721    /**
722     * Returns the number of vector components for this Element.
723     * @return number of vector components
724     */
725    uint32_t getVectorSize() const {
726        return mVectorSize;
727    }
728
729    /**
730     * Utility function for returning an Element containing a single bool.
731     * @param[in] rs RenderScript context
732     * @return Element
733     */
734    static sp<const Element> BOOLEAN(sp<RS> rs);
735    /**
736     * Utility function for returning an Element containing a single unsigned char.
737     * @param[in] rs RenderScript context
738     * @return Element
739     */
740    static sp<const Element> U8(sp<RS> rs);
741    /**
742     * Utility function for returning an Element containing a single signed char.
743     * @param[in] rs RenderScript context
744     * @return Element
745     */
746    static sp<const Element> I8(sp<RS> rs);
747    /**
748     * Utility function for returning an Element containing a single unsigned short.
749     * @param[in] rs RenderScript context
750     * @return Element
751     */
752    static sp<const Element> U16(sp<RS> rs);
753    /**
754     * Utility function for returning an Element containing a single signed short.
755     * @param[in] rs RenderScript context
756     * @return Element
757     */
758    static sp<const Element> I16(sp<RS> rs);
759    /**
760     * Utility function for returning an Element containing a single unsigned int.
761     * @param[in] rs RenderScript context
762     * @return Element
763     */
764    static sp<const Element> U32(sp<RS> rs);
765    /**
766     * Utility function for returning an Element containing a single signed int.
767     * @param[in] rs RenderScript context
768     * @return Element
769     */
770    static sp<const Element> I32(sp<RS> rs);
771    /**
772     * Utility function for returning an Element containing a single unsigned long long.
773     * @param[in] rs RenderScript context
774     * @return Element
775     */
776    static sp<const Element> U64(sp<RS> rs);
777    /**
778     * Utility function for returning an Element containing a single signed long long.
779     * @param[in] rs RenderScript context
780     * @return Element
781     */
782    static sp<const Element> I64(sp<RS> rs);
783    /**
784     * Utility function for returning an Element containing a single float.
785     * @param[in] rs RenderScript context
786     * @return Element
787     */
788    static sp<const Element> F32(sp<RS> rs);
789    /**
790     * Utility function for returning an Element containing a single double.
791     * @param[in] rs RenderScript context
792     * @return Element
793     */
794    static sp<const Element> F64(sp<RS> rs);
795    /**
796     * Utility function for returning an Element containing a single Element.
797     * @param[in] rs RenderScript context
798     * @return Element
799     */
800    static sp<const Element> ELEMENT(sp<RS> rs);
801    /**
802     * Utility function for returning an Element containing a single Type.
803     * @param[in] rs RenderScript context
804     * @return Element
805     */
806    static sp<const Element> TYPE(sp<RS> rs);
807    /**
808     * Utility function for returning an Element containing a single Allocation.
809     * @param[in] rs RenderScript context
810     * @return Element
811     */
812    static sp<const Element> ALLOCATION(sp<RS> rs);
813    /**
814     * Utility function for returning an Element containing a single Sampler.
815     * @param[in] rs RenderScript context
816     * @return Element
817     */
818    static sp<const Element> SAMPLER(sp<RS> rs);
819    /**
820     * Utility function for returning an Element containing a single Script.
821     * @param[in] rs RenderScript context
822     * @return Element
823     */
824    static sp<const Element> SCRIPT(sp<RS> rs);
825    /**
826     * Utility function for returning an Element containing an ALPHA_8 pixel.
827     * @param[in] rs RenderScript context
828     * @return Element
829     */
830    static sp<const Element> A_8(sp<RS> rs);
831    /**
832     * Utility function for returning an Element containing an RGB_565 pixel.
833     * @param[in] rs RenderScript context
834     * @return Element
835     */
836    static sp<const Element> RGB_565(sp<RS> rs);
837    /**
838     * Utility function for returning an Element containing an RGB_888 pixel.
839     * @param[in] rs RenderScript context
840     * @return Element
841     */
842    static sp<const Element> RGB_888(sp<RS> rs);
843    /**
844     * Utility function for returning an Element containing an RGBA_5551 pixel.
845     * @param[in] rs RenderScript context
846     * @return Element
847     */
848    static sp<const Element> RGBA_5551(sp<RS> rs);
849    /**
850     * Utility function for returning an Element containing an RGBA_4444 pixel.
851     * @param[in] rs RenderScript context
852     * @return Element
853     */
854    static sp<const Element> RGBA_4444(sp<RS> rs);
855    /**
856     * Utility function for returning an Element containing an RGBA_8888 pixel.
857     * @param[in] rs RenderScript context
858     * @return Element
859     */
860    static sp<const Element> RGBA_8888(sp<RS> rs);
861
862    /**
863     * Utility function for returning an Element containing a float2.
864     * @param[in] rs RenderScript context
865     * @return Element
866     */
867    static sp<const Element> F32_2(sp<RS> rs);
868    /**
869     * Utility function for returning an Element containing a float3.
870     * @param[in] rs RenderScript context
871     * @return Element
872     */
873    static sp<const Element> F32_3(sp<RS> rs);
874    /**
875     * Utility function for returning an Element containing a float4.
876     * @param[in] rs RenderScript context
877     * @return Element
878     */
879    static sp<const Element> F32_4(sp<RS> rs);
880    /**
881     * Utility function for returning an Element containing a double2.
882     * @param[in] rs RenderScript context
883     * @return Element
884     */
885    static sp<const Element> F64_2(sp<RS> rs);
886    /**
887     * Utility function for returning an Element containing a double3.
888     * @param[in] rs RenderScript context
889     * @return Element
890     */
891    static sp<const Element> F64_3(sp<RS> rs);
892    /**
893     * Utility function for returning an Element containing a double4.
894     * @param[in] rs RenderScript context
895     * @return Element
896     */
897    static sp<const Element> F64_4(sp<RS> rs);
898    /**
899     * Utility function for returning an Element containing a uchar2.
900     * @param[in] rs RenderScript context
901     * @return Element
902     */
903    static sp<const Element> U8_2(sp<RS> rs);
904    /**
905     * Utility function for returning an Element containing a uchar3.
906     * @param[in] rs RenderScript context
907     * @return Element
908     */
909    static sp<const Element> U8_3(sp<RS> rs);
910    /**
911     * Utility function for returning an Element containing a uchar4.
912     * @param[in] rs RenderScript context
913     * @return Element
914     */
915    static sp<const Element> U8_4(sp<RS> rs);
916    /**
917     * Utility function for returning an Element containing a char2.
918     * @param[in] rs RenderScript context
919     * @return Element
920     */
921    static sp<const Element> I8_2(sp<RS> rs);
922    /**
923     * Utility function for returning an Element containing a char3.
924     * @param[in] rs RenderScript context
925     * @return Element
926     */
927    static sp<const Element> I8_3(sp<RS> rs);
928    /**
929     * Utility function for returning an Element containing a char4.
930     * @param[in] rs RenderScript context
931     * @return Element
932     */
933    static sp<const Element> I8_4(sp<RS> rs);
934    /**
935     * Utility function for returning an Element containing a ushort2.
936     * @param[in] rs RenderScript context
937     * @return Element
938     */
939    static sp<const Element> U16_2(sp<RS> rs);
940    /**
941     * Utility function for returning an Element containing a ushort3.
942     * @param[in] rs RenderScript context
943     * @return Element
944     */
945    static sp<const Element> U16_3(sp<RS> rs);
946    /**
947     * Utility function for returning an Element containing a ushort4.
948     * @param[in] rs RenderScript context
949     * @return Element
950     */
951    static sp<const Element> U16_4(sp<RS> rs);
952    /**
953     * Utility function for returning an Element containing a short2.
954     * @param[in] rs RenderScript context
955     * @return Element
956     */
957    static sp<const Element> I16_2(sp<RS> rs);
958    /**
959     * Utility function for returning an Element containing a short3.
960     * @param[in] rs RenderScript context
961     * @return Element
962     */
963    static sp<const Element> I16_3(sp<RS> rs);
964    /**
965     * Utility function for returning an Element containing a short4.
966     * @param[in] rs RenderScript context
967     * @return Element
968     */
969    static sp<const Element> I16_4(sp<RS> rs);
970    /**
971     * Utility function for returning an Element containing a uint2.
972     * @param[in] rs RenderScript context
973     * @return Element
974     */
975    static sp<const Element> U32_2(sp<RS> rs);
976    /**
977     * Utility function for returning an Element containing a uint3.
978     * @param[in] rs RenderScript context
979     * @return Element
980     */
981    static sp<const Element> U32_3(sp<RS> rs);
982    /**
983     * Utility function for returning an Element containing a uint4.
984     * @param[in] rs RenderScript context
985     * @return Element
986     */
987    static sp<const Element> U32_4(sp<RS> rs);
988    /**
989     * Utility function for returning an Element containing an int2.
990     * @param[in] rs RenderScript context
991     * @return Element
992     */
993    static sp<const Element> I32_2(sp<RS> rs);
994    /**
995     * Utility function for returning an Element containing an int3.
996     * @param[in] rs RenderScript context
997     * @return Element
998     */
999    static sp<const Element> I32_3(sp<RS> rs);
1000    /**
1001     * Utility function for returning an Element containing an int4.
1002     * @param[in] rs RenderScript context
1003     * @return Element
1004     */
1005    static sp<const Element> I32_4(sp<RS> rs);
1006    /**
1007     * Utility function for returning an Element containing a ulong2.
1008     * @param[in] rs RenderScript context
1009     * @return Element
1010     */
1011    static sp<const Element> U64_2(sp<RS> rs);
1012    /**
1013     * Utility function for returning an Element containing a ulong3.
1014     * @param[in] rs RenderScript context
1015     * @return Element
1016     */
1017    static sp<const Element> U64_3(sp<RS> rs);
1018    /**
1019     * Utility function for returning an Element containing a ulong4.
1020     * @param[in] rs RenderScript context
1021     * @return Element
1022     */
1023    static sp<const Element> U64_4(sp<RS> rs);
1024    /**
1025     * Utility function for returning an Element containing a long2.
1026     * @param[in] rs RenderScript context
1027     * @return Element
1028     */
1029    static sp<const Element> I64_2(sp<RS> rs);
1030    /**
1031     * Utility function for returning an Element containing a long3.
1032     * @param[in] rs RenderScript context
1033     * @return Element
1034     */
1035    static sp<const Element> I64_3(sp<RS> rs);
1036    /**
1037     * Utility function for returning an Element containing a long4.
1038     * @param[in] rs RenderScript context
1039     * @return Element
1040     */
1041    static sp<const Element> I64_4(sp<RS> rs);
1042    /**
1043     * Utility function for returning an Element containing a YUV pixel.
1044     * @param[in] rs RenderScript context
1045     * @return Element
1046     */
1047    static sp<const Element> YUV(sp<RS> rs);
1048    /**
1049     * Utility function for returning an Element containing an rs_matrix_4x4.
1050     * @param[in] rs RenderScript context
1051     * @return Element
1052     */
1053    static sp<const Element> MATRIX_4X4(sp<RS> rs);
1054    /**
1055     * Utility function for returning an Element containing an rs_matrix_3x3.
1056     * @param[in] rs RenderScript context
1057     * @return Element
1058     */
1059    static sp<const Element> MATRIX_3X3(sp<RS> rs);
1060    /**
1061     * Utility function for returning an Element containing an rs_matrix_2x2.
1062     * @param[in] rs RenderScript context
1063     * @return Element
1064     */
1065    static sp<const Element> MATRIX_2X2(sp<RS> rs);
1066
1067    void updateFromNative();
1068
1069    /**
1070     * Create an Element with a given DataType.
1071     * @param[in] rs RenderScript context
1072     * @param[in] dt data type
1073     * @return Element
1074     */
1075    static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
1076    /**
1077     * Create a vector Element with the given DataType
1078     * @param[in] rs RenderScript
1079     * @param[in] dt DataType
1080     * @param[in] size vector size
1081     * @return Element
1082     */
1083    static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
1084    /**
1085     * Create an Element with a given DataType and DataKind.
1086     * @param[in] rs RenderScript context
1087     * @param[in] dt DataType
1088     * @param[in] dk DataKind
1089     * @return Element
1090     */
1091    static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
1092
1093    /**
1094     * Returns true if the Element can interoperate with this Element.
1095     * @param[in] e Element to compare
1096     * @return true if Elements can interoperate
1097     */
1098    bool isCompatible(sp<const Element>e) const;
1099
1100    /**
1101     * Builder class for producing complex elements with matching field and name
1102     * pairs. The builder starts empty. The order in which elements are added is
1103     * retained for the layout in memory.
1104     */
1105    class Builder {
1106    private:
1107        RS* mRS;
1108        size_t mElementsCount;
1109        size_t mElementsVecSize;
1110        sp<const Element> * mElements;
1111        char ** mElementNames;
1112        size_t * mElementNameLengths;
1113        uint32_t * mArraySizes;
1114        bool mSkipPadding;
1115
1116    public:
1117        Builder(sp<RS> rs);
1118        ~Builder();
1119        void add(sp<const Element> e, const char * name, uint32_t arraySize = 1);
1120        sp<const Element> create();
1121    };
1122
1123protected:
1124    Element(void *id, sp<RS> rs,
1125            sp<const Element> * elements,
1126            size_t elementCount,
1127            const char ** elementNames,
1128            size_t * elementNameLengths,
1129            uint32_t * arraySizes);
1130    Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
1131    Element(sp<RS> rs);
1132    virtual ~Element();
1133
1134private:
1135    void updateVisibleSubElements();
1136
1137    size_t mElementsCount;
1138    size_t mVisibleElementMapSize;
1139
1140    sp<const Element> * mElements;
1141    char ** mElementNames;
1142    size_t * mElementNameLengths;
1143    uint32_t * mArraySizes;
1144    uint32_t * mVisibleElementMap;
1145    uint32_t * mOffsetInBytes;
1146
1147    RsDataType mType;
1148    RsDataKind mKind;
1149    bool mNormalized;
1150    size_t mSizeBytes;
1151    size_t mVectorSize;
1152};
1153
1154class FieldPacker {
1155protected:
1156    unsigned char* mData;
1157    size_t mPos;
1158    size_t mLen;
1159
1160public:
1161    FieldPacker(size_t len)
1162        : mPos(0), mLen(len) {
1163            mData = new unsigned char[len];
1164        }
1165
1166    virtual ~FieldPacker() {
1167        delete [] mData;
1168    }
1169
1170    void align(size_t v) {
1171        if ((v & (v - 1)) != 0) {
1172            //            ALOGE("Non-power-of-two alignment: %zu", v);
1173            return;
1174        }
1175
1176        while ((mPos & (v - 1)) != 0) {
1177            mData[mPos++] = 0;
1178        }
1179    }
1180
1181    void reset() {
1182        mPos = 0;
1183    }
1184
1185    void reset(size_t i) {
1186        if (i >= mLen) {
1187            //            ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
1188            return;
1189        }
1190        mPos = i;
1191    }
1192
1193    void skip(size_t i) {
1194        size_t res = mPos + i;
1195        if (res > mLen) {
1196            //            ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
1197            return;
1198        }
1199        mPos = res;
1200    }
1201
1202    void* getData() const {
1203        return mData;
1204    }
1205
1206    size_t getLength() const {
1207        return mLen;
1208    }
1209
1210    template <typename T>
1211        void add(T t) {
1212        align(sizeof(t));
1213        if (mPos + sizeof(t) <= mLen) {
1214            memcpy(&mData[mPos], &t, sizeof(t));
1215            mPos += sizeof(t);
1216        }
1217    }
1218
1219    /*
1220      void add(rs_matrix4x4 m) {
1221      for (size_t i = 0; i < 16; i++) {
1222      add(m.m[i]);
1223      }
1224      }
1225
1226      void add(rs_matrix3x3 m) {
1227      for (size_t i = 0; i < 9; i++) {
1228      add(m.m[i]);
1229      }
1230      }
1231
1232      void add(rs_matrix2x2 m) {
1233      for (size_t i = 0; i < 4; i++) {
1234      add(m.m[i]);
1235      }
1236      }
1237    */
1238
1239    void add(sp<BaseObj> obj) {
1240        if (obj != NULL) {
1241            add((uint32_t) (uintptr_t) obj->getID());
1242        } else {
1243            add((uint32_t) 0);
1244        }
1245    }
1246};
1247
1248/**
1249 * A Type describes the Element and dimensions used for an Allocation or a
1250 * parallel operation.
1251 *
1252 * A Type always includes an Element and an X dimension. A Type may be
1253 * multidimensional, up to three dimensions. A nonzero value in the Y or Z
1254 * dimensions indicates that the dimension is present. Note that a Type with
1255 * only a given X dimension and a Type with the same X dimension but Y = 1 are
1256 * not equivalent.
1257 *
1258 * A Type also supports inclusion of level of detail (LOD) or cube map
1259 * faces. LOD and cube map faces are booleans to indicate present or not
1260 * present.
1261 *
1262 * A Type also supports YUV format information to support an Allocation in a YUV
1263 * format. The YUV formats supported are YV12 and NV21.
1264 */
1265class Type : public BaseObj {
1266protected:
1267    friend class Allocation;
1268
1269    uint32_t mDimX;
1270    uint32_t mDimY;
1271    uint32_t mDimZ;
1272    RSYuvFormat mYuvFormat;
1273    bool mDimMipmaps;
1274    bool mDimFaces;
1275    size_t mElementCount;
1276    sp<const Element> mElement;
1277
1278    Type(void *id, sp<RS> rs);
1279
1280    void calcElementCount();
1281    virtual void updateFromNative();
1282
1283public:
1284
1285    /**
1286     * Returns the YUV format.
1287     * @return YUV format of the Allocation
1288     */
1289    RSYuvFormat getYuvFormat() const {
1290        return mYuvFormat;
1291    }
1292
1293    /**
1294     * Returns the Element of the Allocation.
1295     * @return YUV format of the Allocation
1296     */
1297    sp<const Element> getElement() const {
1298        return mElement;
1299    }
1300
1301    /**
1302     * Returns the X dimension of the Allocation.
1303     * @return X dimension of the allocation
1304     */
1305    uint32_t getX() const {
1306        return mDimX;
1307    }
1308
1309    /**
1310     * Returns the Y dimension of the Allocation.
1311     * @return Y dimension of the allocation
1312     */
1313    uint32_t getY() const {
1314        return mDimY;
1315    }
1316
1317    /**
1318     * Returns the Z dimension of the Allocation.
1319     * @return Z dimension of the allocation
1320     */
1321    uint32_t getZ() const {
1322        return mDimZ;
1323    }
1324
1325    /**
1326     * Returns true if the Allocation has mipmaps.
1327     * @return true if the Allocation has mipmaps
1328     */
1329    bool hasMipmaps() const {
1330        return mDimMipmaps;
1331    }
1332
1333    /**
1334     * Returns true if the Allocation is a cube map
1335     * @return true if the Allocation is a cube map
1336     */
1337    bool hasFaces() const {
1338        return mDimFaces;
1339    }
1340
1341    /**
1342     * Returns number of accessible Elements in the Allocation
1343     * @return number of accessible Elements in the Allocation
1344     */
1345    size_t getCount() const {
1346        return mElementCount;
1347    }
1348
1349    /**
1350     * Returns size in bytes of all Elements in the Allocation
1351     * @return size in bytes of all Elements in the Allocation
1352     */
1353    size_t getSizeBytes() const {
1354        return mElementCount * mElement->getSizeBytes();
1355    }
1356
1357    /**
1358     * Creates a new Type with the given Element and dimensions.
1359     * @param[in] rs RenderScript context
1360     * @param[in] e Element
1361     * @param[in] dimX X dimension
1362     * @param[in] dimY Y dimension
1363     * @param[in] dimZ Z dimension
1364     * @return new Type
1365     */
1366    static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ);
1367
1368    class Builder {
1369    protected:
1370        RS* mRS;
1371        uint32_t mDimX;
1372        uint32_t mDimY;
1373        uint32_t mDimZ;
1374        RSYuvFormat mYuvFormat;
1375        bool mDimMipmaps;
1376        bool mDimFaces;
1377        sp<const Element> mElement;
1378
1379    public:
1380        Builder(sp<RS> rs, sp<const Element> e);
1381
1382        void setX(uint32_t value);
1383        void setY(uint32_t value);
1384        void setZ(uint32_t value);
1385        void setYuvFormat(RSYuvFormat format);
1386        void setMipmaps(bool value);
1387        void setFaces(bool value);
1388        sp<const Type> create();
1389    };
1390
1391};
1392
1393/**
1394 * The parent class for all executable Scripts. This should not be used by applications.
1395 */
1396class Script : public BaseObj {
1397private:
1398
1399protected:
1400    Script(void *id, sp<RS> rs);
1401    void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
1402            const void *v, size_t) const;
1403    void bindAllocation(sp<Allocation> va, uint32_t slot) const;
1404    void setVar(uint32_t index, const void *, size_t len) const;
1405    void setVar(uint32_t index, sp<const BaseObj> o) const;
1406    void invoke(uint32_t slot, const void *v, size_t len) const;
1407
1408
1409    void invoke(uint32_t slot) const {
1410        invoke(slot, NULL, 0);
1411    }
1412    void setVar(uint32_t index, float v) const {
1413        setVar(index, &v, sizeof(v));
1414    }
1415    void setVar(uint32_t index, double v) const {
1416        setVar(index, &v, sizeof(v));
1417    }
1418    void setVar(uint32_t index, int32_t v) const {
1419        setVar(index, &v, sizeof(v));
1420    }
1421    void setVar(uint32_t index, uint32_t v) const {
1422        setVar(index, &v, sizeof(v));
1423    }
1424    void setVar(uint32_t index, int64_t v) const {
1425        setVar(index, &v, sizeof(v));
1426    }
1427    void setVar(uint32_t index, bool v) const {
1428        setVar(index, &v, sizeof(v));
1429    }
1430
1431public:
1432    class FieldBase {
1433    protected:
1434        sp<const Element> mElement;
1435        sp<Allocation> mAllocation;
1436
1437        void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
1438
1439    public:
1440        sp<const Element> getElement() {
1441            return mElement;
1442        }
1443
1444        sp<const Type> getType() {
1445            return mAllocation->getType();
1446        }
1447
1448        sp<const Allocation> getAllocation() {
1449            return mAllocation;
1450        }
1451
1452        //void updateAllocation();
1453    };
1454};
1455
1456/**
1457 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only.
1458 */
1459class ScriptC : public Script {
1460protected:
1461    ScriptC(sp<RS> rs,
1462            const void *codeTxt, size_t codeLength,
1463            const char *cachedName, size_t cachedNameLength,
1464            const char *cacheDir, size_t cacheDirLength);
1465
1466};
1467
1468/**
1469 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of
1470 * basic functions. This is not intended to be used directly.
1471 */
1472class ScriptIntrinsic : public Script {
1473 protected:
1474    sp<const Element> mElement;
1475    ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
1476    virtual ~ScriptIntrinsic();
1477};
1478
1479/**
1480 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming
1481 * r,g,b values are use as normalized x,y,z coordinates into a 3D
1482 * allocation. The 8 nearest values are sampled and linearly interpolated. The
1483 * result is placed in the output.
1484 */
1485class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
1486 private:
1487    ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
1488 public:
1489    /**
1490     * Supported Element types are U8_4. Default lookup table is identity.
1491     * @param[in] rs RenderScript context
1492     * @param[in] e Element
1493     * @return new ScriptIntrinsic
1494     */
1495    static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
1496
1497    /**
1498     * Launch the intrinsic.
1499     * @param[in] ain input Allocation
1500     * @param[in] aout output Allocation
1501     */
1502    void forEach(sp<Allocation> ain, sp<Allocation> aout);
1503
1504    /**
1505     * Sets the lookup table. The lookup table must use the same Element as the
1506     * intrinsic.
1507     * @param[in] lut new lookup table
1508     */
1509    void setLUT(sp<Allocation> lut);
1510};
1511
1512/**
1513 * Intrinsic kernel for blending two Allocations.
1514 */
1515class ScriptIntrinsicBlend : public ScriptIntrinsic {
1516 private:
1517    ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
1518 public:
1519    /**
1520     * Supported Element types are U8_4.
1521     * @param[in] rs RenderScript context
1522     * @param[in] e Element
1523     * @return new ScriptIntrinsicBlend
1524     */
1525    static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
1526    /**
1527     * sets dst = {0, 0, 0, 0}
1528     * @param[in] in input Allocation
1529     * @param[in] out output Allocation
1530     */
1531    void forEachClear(sp<Allocation> in, sp<Allocation> out);
1532    /**
1533     * Sets dst = src
1534     * @param[in] in input Allocation
1535     * @param[in] out output Allocation
1536     */
1537    void forEachSrc(sp<Allocation> in, sp<Allocation> out);
1538    /**
1539     * Sets dst = dst (NOP)
1540     * @param[in] in input Allocation
1541     * @param[in] out output Allocation
1542     */
1543    void forEachDst(sp<Allocation> in, sp<Allocation> out);
1544    /**
1545     * Sets dst = src + dst * (1.0 - src.a)
1546     * @param[in] in input Allocation
1547     * @param[in] out output Allocation
1548     */
1549    void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
1550    /**
1551     * Sets dst = dst + src * (1.0 - dst.a)
1552     * @param[in] in input Allocation
1553     * @param[in] out output Allocation
1554     */
1555    void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
1556    /**
1557     * Sets dst = src * dst.a
1558     * @param[in] in input Allocation
1559     * @param[in] out output Allocation
1560     */
1561    void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
1562    /**
1563     * Sets dst = dst * src.a
1564     * @param[in] in input Allocation
1565     * @param[in] out output Allocation
1566     */
1567    void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
1568    /**
1569     * Sets dst = src * (1.0 - dst.a)
1570     * @param[in] in input Allocation
1571     * @param[in] out output Allocation
1572     */
1573    void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
1574    /**
1575     * Sets dst = dst * (1.0 - src.a)
1576     * @param[in] in input Allocation
1577     * @param[in] out output Allocation
1578     */
1579    void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
1580    /**
1581     * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
1582     * @param[in] in input Allocation
1583     * @param[in] out output Allocation
1584     */
1585    void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
1586    /**
1587     * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
1588     * @param[in] in input Allocation
1589     * @param[in] out output Allocation
1590     */
1591    void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
1592    /**
1593     * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
1594     * @param[in] in input Allocation
1595     * @param[in] out output Allocation
1596     */
1597    void forEachXor(sp<Allocation> in, sp<Allocation> out);
1598    /**
1599     * Sets dst = src * dst
1600     * @param[in] in input Allocation
1601     * @param[in] out output Allocation
1602     */
1603    void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
1604    /**
1605     * Sets dst = min(src + dst, 1.0)
1606     * @param[in] in input Allocation
1607     * @param[in] out output Allocation
1608     */
1609    void forEachAdd(sp<Allocation> in, sp<Allocation> out);
1610    /**
1611     * Sets dst = max(dst - src, 0.0)
1612     * @param[in] in input Allocation
1613     * @param[in] out output Allocation
1614     */
1615    void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
1616};
1617
1618/**
1619 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified
1620 * radius to all elements of an Allocation.
1621 */
1622class ScriptIntrinsicBlur : public ScriptIntrinsic {
1623 private:
1624    ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
1625 public:
1626    /**
1627     * Supported Element types are U8 and U8_4.
1628     * @param[in] rs RenderScript context
1629     * @param[in] e Element
1630     * @return new ScriptIntrinsicBlur
1631     */
1632    static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
1633    /**
1634     * Sets the input of the blur.
1635     * @param[in] in input Allocation
1636     */
1637    void setInput(sp<Allocation> in);
1638    /**
1639     * Runs the intrinsic.
1640     * @param[in] output Allocation
1641     */
1642    void forEach(sp<Allocation> out);
1643    /**
1644     * Sets the radius of the blur. The supported range is 0 < radius <= 25.
1645     * @param[in] radius radius of the blur
1646     */
1647    void setRadius(float radius);
1648};
1649
1650/**
1651 * Intrinsic for applying a color matrix to allocations. This has the
1652 * same effect as loading each element and converting it to a
1653 * F32_N, multiplying the result by the 4x4 color matrix
1654 * as performed by rsMatrixMultiply() and writing it to the output
1655 * after conversion back to U8_N or F32_N.
1656 */
1657class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
1658 private:
1659    ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
1660 public:
1661    /**
1662     * Creates a new intrinsic.
1663     * @param[in] rs RenderScript context
1664     * @return new ScriptIntrinsicColorMatrix
1665     */
1666    static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
1667    /**
1668     * Applies the color matrix. Supported types are U8 and F32 with
1669     * vector lengths between 1 and 4.
1670     * @param[in] in input Allocation
1671     * @param[out] out output Allocation
1672     */
1673    void forEach(sp<Allocation> in, sp<Allocation> out);
1674    /**
1675     * Set the value to be added after the color matrix has been
1676     * applied. The default value is {0, 0, 0, 0}.
1677     * @param[in] add float[4] of values
1678     */
1679    void setAdd(float* add);
1680
1681    /**
1682     * Set the color matrix which will be applied to each cell of the
1683     * image. The alpha channel will be copied.
1684     *
1685     * @param[in] m float[9] of values
1686     */
1687    void setColorMatrix3(float* m);
1688    /**
1689     * Set the color matrix which will be applied to each cell of the
1690     * image.
1691     *
1692     * @param[in] m float[16] of values
1693     */
1694    void setColorMatrix4(float* m);
1695    /**
1696     * Set a color matrix to convert from RGB to luminance. The alpha
1697     * channel will be a copy.
1698     */
1699    void setGreyscale();
1700    /**
1701     * Set the matrix to convert from RGB to YUV with a direct copy of
1702     * the 4th channel.
1703     */
1704    void setRGBtoYUV();
1705    /**
1706     * Set the matrix to convert from YUV to RGB with a direct copy of
1707     * the 4th channel.
1708     */
1709    void setYUVtoRGB();
1710};
1711
1712/**
1713 * Intrinsic for applying a 3x3 convolve to an allocation.
1714 */
1715class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
1716 private:
1717    ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
1718 public:
1719    /**
1720     * Supported types U8 and F32 with vector lengths between 1 and
1721     * 4. The default convolution kernel is the identity.
1722     * @param[in] rs RenderScript context
1723     * @param[in] e Element
1724     * @return new ScriptIntrinsicConvolve3x3
1725     */
1726    static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
1727    /**
1728     * Sets input for intrinsic.
1729     * @param[in] in input Allocation
1730     */
1731    void setInput(sp<Allocation> in);
1732    /**
1733     * Launches the intrinsic.
1734     * @param[in] out output Allocation
1735     */
1736    void forEach(sp<Allocation> out);
1737    /**
1738     * Sets convolution kernel.
1739     * @param[in] v float[9] of values
1740     */
1741    void setCoefficients(float* v);
1742};
1743
1744/**
1745 * Intrinsic for applying a 5x5 convolve to an allocation.
1746 */
1747class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
1748 private:
1749    ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
1750 public:
1751    /**
1752     * Supported types U8 and F32 with vector lengths between 1 and
1753     * 4. The default convolution kernel is the identity.
1754     * @param[in] rs RenderScript context
1755     * @param[in] e Element
1756     * @return new ScriptIntrinsicConvolve5x5
1757     */
1758    static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
1759    /**
1760     * Sets input for intrinsic.
1761     * @param[in] in input Allocation
1762     */
1763    void setInput(sp<Allocation> in);
1764    /**
1765     * Launches the intrinsic.
1766     * @param[in] out output Allocation
1767     */
1768    void forEach(sp<Allocation> out);
1769    /**
1770     * Sets convolution kernel.
1771     * @param[in] v float[25] of values
1772     */
1773    void setCoefficients(float* v);
1774};
1775
1776/**
1777 * Intrinsic for computing a histogram.
1778 */
1779class ScriptIntrinsicHistogram : public ScriptIntrinsic {
1780 private:
1781    ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
1782    sp<Allocation> mOut;
1783 public:
1784    /**
1785     * Create an intrinsic for calculating the histogram of an uchar
1786     * or uchar4 image.
1787     *
1788     * Supported elements types are U8_4, U8_3, U8_2, and U8.
1789     *
1790     * @param[in] rs The RenderScript context
1791     * @param[in] e Element type for inputs
1792     *
1793     * @return ScriptIntrinsicHistogram
1794     */
1795    static sp<ScriptIntrinsicHistogram> create(sp<RS> rs, sp<const Element> e);
1796    /**
1797     * Set the output of the histogram.  32 bit integer types are
1798     * supported.
1799     *
1800     * @param[in] aout The output allocation
1801     */
1802    void setOutput(sp<Allocation> aout);
1803    /**
1804     * Set the coefficients used for the dot product calculation. The
1805     * default is {0.299f, 0.587f, 0.114f, 0.f}.
1806     *
1807     * Coefficients must be >= 0 and sum to 1.0 or less.
1808     *
1809     * @param[in] r Red coefficient
1810     * @param[in] g Green coefficient
1811     * @param[in] b Blue coefficient
1812     * @param[in] a Alpha coefficient
1813     */
1814    void setDotCoefficients(float r, float g, float b, float a);
1815    /**
1816     * Process an input buffer and place the histogram into the output
1817     * allocation. The output allocation may be a narrower vector size
1818     * than the input. In this case the vector size of the output is
1819     * used to determine how many of the input channels are used in
1820     * the computation. This is useful if you have an RGBA input
1821     * buffer but only want the histogram for RGB.
1822     *
1823     * 1D and 2D input allocations are supported.
1824     *
1825     * @param[in] ain The input image
1826     */
1827    void forEach(sp<Allocation> ain);
1828    /**
1829     * Process an input buffer and place the histogram into the output
1830     * allocation. The dot product of the input channel and the
1831     * coefficients from 'setDotCoefficients' are used to calculate
1832     * the output values.
1833     *
1834     * 1D and 2D input allocations are supported.
1835     *
1836     * @param ain The input image
1837     */
1838    void forEach_dot(sp<Allocation> ain);
1839};
1840
1841/**
1842 * Intrinsic for applying a per-channel lookup table. Each channel of
1843 * the input has an independant lookup table. The tables are 256
1844 * entries in size and can cover the full value range of U8_4.
1845 **/
1846class ScriptIntrinsicLUT : public ScriptIntrinsic {
1847 private:
1848    sp<Allocation> LUT;
1849    bool mDirty;
1850    unsigned char mCache[1024];
1851    void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
1852    ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
1853
1854 public:
1855    /**
1856     * Supported elements types are U8_4.
1857     *
1858     * The defaults tables are identity.
1859     *
1860     * @param[in] rs The RenderScript context
1861     * @param[in] e Element type for intputs and outputs
1862     *
1863     * @return ScriptIntrinsicLUT
1864     */
1865    static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
1866    /**
1867     * Invoke the kernel and apply the lookup to each cell of ain and
1868     * copy to aout.
1869     *
1870     * @param[in] ain Input allocation
1871     * @param[in] aout Output allocation
1872     */
1873    void forEach(sp<Allocation> ain, sp<Allocation> aout);
1874    /**
1875     * Sets entries in LUT for the red channel.
1876     * @param[in] base base of region to update
1877     * @param[in] length length of region to update
1878     * @param[in] lutValues LUT values to use
1879     */
1880    void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
1881    /**
1882     * Sets entries in LUT for the green channel.
1883     * @param[in] base base of region to update
1884     * @param[in] length length of region to update
1885     * @param[in] lutValues LUT values to use
1886     */
1887    void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
1888    /**
1889     * Sets entries in LUT for the blue channel.
1890     * @param[in] base base of region to update
1891     * @param[in] length length of region to update
1892     * @param[in] lutValues LUT values to use
1893     */
1894    void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
1895    /**
1896     * Sets entries in LUT for the alpha channel.
1897     * @param[in] base base of region to update
1898     * @param[in] length length of region to update
1899     * @param[in] lutValues LUT values to use
1900     */
1901    void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
1902    virtual ~ScriptIntrinsicLUT();
1903};
1904
1905/**
1906 * Intrinsic for performing a resize of a 2D allocation.
1907 */
1908class ScriptIntrinsicResize : public ScriptIntrinsic {
1909 private:
1910    sp<Allocation> mInput;
1911    ScriptIntrinsicResize(sp<RS> rs, sp<const Element> e);
1912 public:
1913    /**
1914     * Supported Element types are U8_4. Default lookup table is identity.
1915     * @param[in] rs RenderScript context
1916     * @param[in] e Element
1917     * @return new ScriptIntrinsic
1918     */
1919    static sp<ScriptIntrinsicResize> create(sp<RS> rs);
1920
1921    /**
1922     * Resize copy the input allocation to the output specified. The
1923     * Allocation is rescaled if necessary using bi-cubic
1924     * interpolation.
1925     * @param[in] ain input Allocation
1926     * @param[in] aout output Allocation
1927     */
1928    void forEach_bicubic(sp<Allocation> aout);
1929
1930    /**
1931     * Set the input of the resize.
1932     * @param[in] lut new lookup table
1933     */
1934    void setInput(sp<Allocation> ain);
1935};
1936
1937/**
1938 * Intrinsic for converting an Android YUV buffer to RGB.
1939 *
1940 * The input allocation should be supplied in a supported YUV format
1941 * as a YUV element Allocation. The output is RGBA; the alpha channel
1942 * will be set to 255.
1943 */
1944class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
1945 private:
1946    ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
1947 public:
1948    /**
1949     * Create an intrinsic for converting YUV to RGB.
1950     *
1951     * Supported elements types are U8_4.
1952     *
1953     * @param[in] rs The RenderScript context
1954     * @param[in] e Element type for output
1955     *
1956     * @return ScriptIntrinsicYuvToRGB
1957     */
1958    static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
1959    /**
1960     * Set the input YUV allocation.
1961     *
1962     * @param[in] ain The input allocation.
1963     */
1964    void setInput(sp<Allocation> in);
1965
1966    /**
1967     * Convert the image to RGB.
1968     *
1969     * @param[in] aout Output allocation. Must match creation element
1970     *                 type.
1971     */
1972    void forEach(sp<Allocation> out);
1973
1974};
1975
1976/**
1977 * Sampler object that defines how Allocations can be read as textures
1978 * within a kernel. Samplers are used in conjunction with the rsSample
1979 * runtime function to return values from normalized coordinates.
1980 *
1981 * Any Allocation used with a Sampler must have been created with
1982 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an
1983 * Allocation that was not created with
1984 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined.
1985 **/
1986 class Sampler : public BaseObj {
1987 private:
1988    Sampler(sp<RS> rs, void* id);
1989    Sampler(sp<RS> rs, void* id, RsSamplerValue min, RsSamplerValue mag,
1990            RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
1991    RsSamplerValue mMin;
1992    RsSamplerValue mMag;
1993    RsSamplerValue mWrapS;
1994    RsSamplerValue mWrapT;
1995    float mAniso;
1996
1997 public:
1998    /**
1999     * Creates a non-standard Sampler.
2000     * @param[in] rs RenderScript context
2001     * @param[in] min minification
2002     * @param[in] mag magnification
2003     * @param[in] wrapS S wrapping mode
2004     * @param[in] wrapT T wrapping mode
2005     * @param[in] anisotropy anisotropy setting
2006     */
2007    static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
2008
2009    /**
2010     * @return minification setting for the sampler
2011     */
2012    RsSamplerValue getMinification();
2013    /**
2014     * @return magnification setting for the sampler
2015     */
2016    RsSamplerValue getMagnification();
2017    /**
2018     * @return S wrapping mode for the sampler
2019     */
2020    RsSamplerValue getWrapS();
2021    /**
2022     * @return T wrapping mode for the sampler
2023     */
2024    RsSamplerValue getWrapT();
2025    /**
2026     * @return anisotropy setting for the sampler
2027     */
2028    float getAnisotropy();
2029
2030    /**
2031     * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2032     * clamp.
2033     *
2034     * @param rs Context to which the sampler will belong.
2035     *
2036     * @return Sampler
2037     */
2038    static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
2039    /**
2040     * Retrieve a sampler with min and mag set to linear and wrap modes set to
2041     * clamp.
2042     *
2043     * @param rs Context to which the sampler will belong.
2044     *
2045     * @return Sampler
2046     */
2047    static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
2048    /**
2049     * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2050     * wrap modes set to clamp.
2051     *
2052     * @param rs Context to which the sampler will belong.
2053     *
2054     * @return Sampler
2055     */
2056    static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
2057    /**
2058     * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2059     * wrap.
2060     *
2061     * @param rs Context to which the sampler will belong.
2062     *
2063     * @return Sampler
2064     */
2065    static sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
2066    /**
2067     * Retrieve a sampler with min and mag set to linear and wrap modes set to
2068     * wrap.
2069     *
2070     * @param rs Context to which the sampler will belong.
2071     *
2072     * @return Sampler
2073     */
2074    static sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
2075    /**
2076     * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
2077     * wrap modes set to wrap.
2078     *
2079     * @param rs Context to which the sampler will belong.
2080     *
2081     * @return Sampler
2082     */
2083    static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
2084    /**
2085     * Retrieve a sampler with min and mag set to nearest and wrap modes set to
2086     * mirrored repeat.
2087     *
2088     * @param rs Context to which the sampler will belong.
2089     *
2090     * @return Sampler
2091     */
2092    static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
2093    /**
2094     * Retrieve a sampler with min and mag set to linear and wrap modes set to
2095     * mirrored repeat.
2096     *
2097     * @param rs Context to which the sampler will belong.
2098     *
2099     * @return Sampler
2100     */
2101    static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
2102    /**
2103     * Retrieve a sampler with min and mag set to linear and wrap modes set to
2104     * mirrored repeat.
2105     *
2106     * @param rs Context to which the sampler will belong.
2107     *
2108     * @return Sampler
2109     */
2110    static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
2111
2112};
2113
2114class Byte2 {
2115 public:
2116  int8_t x, y;
2117
2118  Byte2(int8_t initX, int8_t initY)
2119    : x(initX), y(initY) {}
2120  Byte2() : x(0), y(0) {}
2121};
2122
2123class Byte3 {
2124 public:
2125  int8_t x, y, z;
2126
2127  Byte3(int8_t initX, int8_t initY, int8_t initZ)
2128    : x(initX), y(initY), z(initZ) {}
2129  Byte3() : x(0), y(0), z(0) {}
2130};
2131
2132class Byte4 {
2133 public:
2134  int8_t x, y, z, w;
2135
2136  Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
2137    : x(initX), y(initY), z(initZ), w(initW) {}
2138  Byte4() : x(0), y(0), z(0), w(0) {}
2139};
2140
2141class UByte2 {
2142 public:
2143  uint8_t x, y;
2144
2145  UByte2(uint8_t initX, uint8_t initY)
2146    : x(initX), y(initY) {}
2147  UByte2() : x(0), y(0) {}
2148};
2149
2150class UByte3 {
2151 public:
2152  uint8_t x, y, z;
2153
2154  UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
2155    : x(initX), y(initY), z(initZ) {}
2156  UByte3() : x(0), y(0), z(0) {}
2157};
2158
2159class UByte4 {
2160 public:
2161  uint8_t x, y, z, w;
2162
2163  UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
2164    : x(initX), y(initY), z(initZ), w(initW) {}
2165  UByte4() : x(0), y(0), z(0), w(0) {}
2166};
2167
2168class Short2 {
2169 public:
2170  short x, y;
2171
2172  Short2(short initX, short initY)
2173    : x(initX), y(initY) {}
2174  Short2() : x(0), y(0) {}
2175};
2176
2177class Short3 {
2178 public:
2179  short x, y, z;
2180
2181  Short3(short initX, short initY, short initZ)
2182    : x(initX), y(initY), z(initZ) {}
2183  Short3() : x(0), y(0), z(0) {}
2184};
2185
2186class Short4 {
2187 public:
2188  short x, y, z, w;
2189
2190  Short4(short initX, short initY, short initZ, short initW)
2191    : x(initX), y(initY), z(initZ), w(initW) {}
2192  Short4() : x(0), y(0), z(0), w(0) {}
2193};
2194
2195class UShort2 {
2196 public:
2197  uint16_t x, y;
2198
2199  UShort2(uint16_t initX, uint16_t initY)
2200    : x(initX), y(initY) {}
2201  UShort2() : x(0), y(0) {}
2202};
2203
2204class UShort3 {
2205 public:
2206  uint16_t x, y, z;
2207
2208  UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
2209    : x(initX), y(initY), z(initZ) {}
2210  UShort3() : x(0), y(0), z(0) {}
2211};
2212
2213class UShort4 {
2214 public:
2215  uint16_t x, y, z, w;
2216
2217  UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
2218    : x(initX), y(initY), z(initZ), w(initW) {}
2219  UShort4() : x(0), y(0), z(0), w(0) {}
2220};
2221
2222class Int2 {
2223 public:
2224  int x, y;
2225
2226  Int2(int initX, int initY)
2227    : x(initX), y(initY) {}
2228  Int2() : x(0), y(0) {}
2229};
2230
2231class Int3 {
2232 public:
2233  int x, y, z;
2234
2235  Int3(int initX, int initY, int initZ)
2236    : x(initX), y(initY), z(initZ) {}
2237  Int3() : x(0), y(0), z(0) {}
2238};
2239
2240class Int4 {
2241 public:
2242  int x, y, z, w;
2243
2244  Int4(int initX, int initY, int initZ, int initW)
2245    : x(initX), y(initY), z(initZ), w(initW) {}
2246  Int4() : x(0), y(0), z(0), w(0) {}
2247};
2248
2249class UInt2 {
2250 public:
2251  uint32_t x, y;
2252
2253  UInt2(uint32_t initX, uint32_t initY)
2254    : x(initX), y(initY) {}
2255  UInt2() : x(0), y(0) {}
2256};
2257
2258class UInt3 {
2259 public:
2260  uint32_t x, y, z;
2261
2262  UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
2263    : x(initX), y(initY), z(initZ) {}
2264  UInt3() : x(0), y(0), z(0) {}
2265};
2266
2267class UInt4 {
2268 public:
2269  uint32_t x, y, z, w;
2270
2271  UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
2272    : x(initX), y(initY), z(initZ), w(initW) {}
2273  UInt4() : x(0), y(0), z(0), w(0) {}
2274};
2275
2276class Long2 {
2277 public:
2278  int64_t x, y;
2279
2280  Long2(int64_t initX, int64_t initY)
2281    : x(initX), y(initY) {}
2282  Long2() : x(0), y(0) {}
2283};
2284
2285class Long3 {
2286 public:
2287  int64_t x, y, z;
2288
2289  Long3(int64_t initX, int64_t initY, int64_t initZ)
2290    : x(initX), y(initY), z(initZ) {}
2291  Long3() : x(0), y(0), z(0) {}
2292};
2293
2294class Long4 {
2295 public:
2296  int64_t x, y, z, w;
2297
2298  Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
2299    : x(initX), y(initY), z(initZ), w(initW) {}
2300  Long4() : x(0), y(0), z(0), w(0) {}
2301};
2302
2303class ULong2 {
2304 public:
2305  uint64_t x, y;
2306
2307  ULong2(uint64_t initX, uint64_t initY)
2308    : x(initX), y(initY) {}
2309  ULong2() : x(0), y(0) {}
2310};
2311
2312class ULong3 {
2313 public:
2314  uint64_t x, y, z;
2315
2316  ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
2317    : x(initX), y(initY), z(initZ) {}
2318  ULong3() : x(0), y(0), z(0) {}
2319};
2320
2321class ULong4 {
2322 public:
2323  uint64_t x, y, z, w;
2324
2325  ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
2326    : x(initX), y(initY), z(initZ), w(initW) {}
2327  ULong4() : x(0), y(0), z(0), w(0) {}
2328};
2329
2330class Float2 {
2331 public:
2332  float x, y;
2333
2334  Float2(float initX, float initY)
2335    : x(initX), y(initY) {}
2336  Float2() : x(0), y(0) {}
2337};
2338
2339class Float3 {
2340 public:
2341  float x, y, z;
2342
2343  Float3(float initX, float initY, float initZ)
2344    : x(initX), y(initY), z(initZ) {}
2345  Float3() : x(0.f), y(0.f), z(0.f) {}
2346};
2347
2348class Float4 {
2349 public:
2350  float x, y, z, w;
2351
2352  Float4(float initX, float initY, float initZ, float initW)
2353    : x(initX), y(initY), z(initZ), w(initW) {}
2354  Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
2355};
2356
2357class Double2 {
2358 public:
2359  double x, y;
2360
2361  Double2(double initX, double initY)
2362    : x(initX), y(initY) {}
2363  Double2() : x(0), y(0) {}
2364};
2365
2366class Double3 {
2367 public:
2368  double x, y, z;
2369
2370  Double3(double initX, double initY, double initZ)
2371    : x(initX), y(initY), z(initZ) {}
2372  Double3() : x(0), y(0), z(0) {}
2373};
2374
2375class Double4 {
2376 public:
2377  double x, y, z, w;
2378
2379  Double4(double initX, double initY, double initZ, double initW)
2380    : x(initX), y(initY), z(initZ), w(initW) {}
2381  Double4() : x(0), y(0), z(0), w(0) {}
2382};
2383
2384}
2385
2386}
2387
2388#endif
2389