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