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