rsCppStructs.h revision b05c850a493a769c88b58be2a6721a9bb06b3a0a
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, uint32_t v) const {
1355        setVar(index, &v, sizeof(v));
1356    }
1357    void setVar(uint32_t index, int64_t v) const {
1358        setVar(index, &v, sizeof(v));
1359    }
1360    void setVar(uint32_t index, bool v) const {
1361        setVar(index, &v, sizeof(v));
1362    }
1363
1364public:
1365    class FieldBase {
1366    protected:
1367        sp<const Element> mElement;
1368        sp<Allocation> mAllocation;
1369
1370        void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
1371
1372    public:
1373        sp<const Element> getElement() {
1374            return mElement;
1375        }
1376
1377        sp<const Type> getType() {
1378            return mAllocation->getType();
1379        }
1380
1381        sp<const Allocation> getAllocation() {
1382            return mAllocation;
1383        }
1384
1385        //void updateAllocation();
1386    };
1387};
1388
1389/**
1390 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only.
1391 */
1392class ScriptC : public Script {
1393protected:
1394    ScriptC(sp<RS> rs,
1395            const void *codeTxt, size_t codeLength,
1396            const char *cachedName, size_t cachedNameLength,
1397            const char *cacheDir, size_t cacheDirLength);
1398
1399};
1400
1401/**
1402 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of
1403 * basic functions. This is not intended to be used directly.
1404 */
1405class ScriptIntrinsic : public Script {
1406 protected:
1407    sp<const Element> mElement;
1408    ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
1409    virtual ~ScriptIntrinsic();
1410};
1411
1412/**
1413 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming
1414 * r,g,b values are use as normalized x,y,z coordinates into a 3D
1415 * allocation. The 8 nearest values are sampled and linearly interpolated. The
1416 * result is placed in the output.
1417 */
1418class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
1419 private:
1420    ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
1421 public:
1422    /**
1423     * Supported Element types are U8_4. Default lookup table is identity.
1424     * @param[in] rs RenderScript context
1425     * @param[in] e Element
1426     * @return new ScriptIntrinsic
1427     */
1428    static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
1429
1430    /**
1431     * Launch the intrinsic.
1432     * @param[in] ain input Allocation
1433     * @param[in] aout output Allocation
1434     */
1435    void forEach(sp<Allocation> ain, sp<Allocation> aout);
1436
1437    /**
1438     * Sets the lookup table. The lookup table must use the same Element as the
1439     * intrinsic.
1440     * @param[in] lut new lookup table
1441     */
1442    void setLUT(sp<Allocation> lut);
1443};
1444
1445/**
1446 * Intrinsic kernel for blending two Allocations.
1447 */
1448class ScriptIntrinsicBlend : public ScriptIntrinsic {
1449 private:
1450    ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
1451 public:
1452    /**
1453     * Supported Element types are U8_4.
1454     * @param[in] rs RenderScript context
1455     * @param[in] e Element
1456     * @return new ScriptIntrinsicBlend
1457     */
1458    static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
1459    /**
1460     * sets dst = {0, 0, 0, 0}
1461     * @param[in] in input Allocation
1462     * @param[in] out output Allocation
1463     */
1464    void forEachClear(sp<Allocation> in, sp<Allocation> out);
1465    /**
1466     * Sets dst = src
1467     * @param[in] in input Allocation
1468     * @param[in] out output Allocation
1469     */
1470    void forEachSrc(sp<Allocation> in, sp<Allocation> out);
1471    /**
1472     * Sets dst = dst (NOP)
1473     * @param[in] in input Allocation
1474     * @param[in] out output Allocation
1475     */
1476    void forEachDst(sp<Allocation> in, sp<Allocation> out);
1477    /**
1478     * Sets dst = src + dst * (1.0 - src.a)
1479     * @param[in] in input Allocation
1480     * @param[in] out output Allocation
1481     */
1482    void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
1483    /**
1484     * Sets dst = dst + src * (1.0 - dst.a)
1485     * @param[in] in input Allocation
1486     * @param[in] out output Allocation
1487     */
1488    void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
1489    /**
1490     * Sets dst = src * dst.a
1491     * @param[in] in input Allocation
1492     * @param[in] out output Allocation
1493     */
1494    void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
1495    /**
1496     * Sets dst = dst * src.a
1497     * @param[in] in input Allocation
1498     * @param[in] out output Allocation
1499     */
1500    void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
1501    /**
1502     * Sets dst = src * (1.0 - dst.a)
1503     * @param[in] in input Allocation
1504     * @param[in] out output Allocation
1505     */
1506    void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
1507    /**
1508     * Sets dst = dst * (1.0 - src.a)
1509     * @param[in] in input Allocation
1510     * @param[in] out output Allocation
1511     */
1512    void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
1513    /**
1514     * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
1515     * @param[in] in input Allocation
1516     * @param[in] out output Allocation
1517     */
1518    void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
1519    /**
1520     * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
1521     * @param[in] in input Allocation
1522     * @param[in] out output Allocation
1523     */
1524    void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
1525    /**
1526     * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
1527     * @param[in] in input Allocation
1528     * @param[in] out output Allocation
1529     */
1530    void forEachXor(sp<Allocation> in, sp<Allocation> out);
1531    /**
1532     * Sets dst = src * dst
1533     * @param[in] in input Allocation
1534     * @param[in] out output Allocation
1535     */
1536    void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
1537    /**
1538     * Sets dst = min(src + dst, 1.0)
1539     * @param[in] in input Allocation
1540     * @param[in] out output Allocation
1541     */
1542    void forEachAdd(sp<Allocation> in, sp<Allocation> out);
1543    /**
1544     * Sets dst = max(dst - src, 0.0)
1545     * @param[in] in input Allocation
1546     * @param[in] out output Allocation
1547     */
1548    void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
1549};
1550
1551/**
1552 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified
1553 * radius to all elements of an Allocation.
1554 */
1555class ScriptIntrinsicBlur : public ScriptIntrinsic {
1556 private:
1557    ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
1558 public:
1559    /**
1560     * Supported Element types are U8 and U8_4.
1561     * @param[in] rs RenderScript context
1562     * @param[in] e Element
1563     * @return new ScriptIntrinsicBlur
1564     */
1565    static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
1566    /**
1567     * Sets the input of the blur.
1568     * @param[in] in input Allocation
1569     */
1570    void setInput(sp<Allocation> in);
1571    /**
1572     * Runs the intrinsic.
1573     * @param[in] output Allocation
1574     */
1575    void forEach(sp<Allocation> out);
1576    /**
1577     * Sets the radius of the blur. The supported range is 0 < radius <= 25.
1578     * @param[in] radius radius of the blur
1579     */
1580    void setRadius(float radius);
1581};
1582
1583/**
1584 * Intrinsic for applying a color matrix to allocations. This has the
1585 * same effect as loading each element and converting it to a
1586 * F32_N, multiplying the result by the 4x4 color matrix
1587 * as performed by rsMatrixMultiply() and writing it to the output
1588 * after conversion back to U8_N or F32_N.
1589 */
1590class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
1591 private:
1592    ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
1593 public:
1594    /**
1595     * Creates a new intrinsic.
1596     * @param[in] rs RenderScript context
1597     * @return new ScriptIntrinsicColorMatrix
1598     */
1599    static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
1600    /**
1601     * Applies the color matrix. Supported types are U8 and F32 with
1602     * vector lengths between 1 and 4.
1603     * @param[in] in input Allocation
1604     * @param[out] out output Allocation
1605     */
1606    void forEach(sp<Allocation> in, sp<Allocation> out);
1607    /**
1608     * Set the value to be added after the color matrix has been
1609     * applied. The default value is {0, 0, 0, 0}.
1610     * @param[in] add float[4] of values
1611     */
1612    void setAdd(float* add);
1613
1614    /**
1615     * Set the color matrix which will be applied to each cell of the
1616     * image. The alpha channel will be copied.
1617     *
1618     * @param[in] m float[9] of values
1619     */
1620    void setColorMatrix3(float* m);
1621    /**
1622     * Set the color matrix which will be applied to each cell of the
1623     * image.
1624     *
1625     * @param[in] m float[16] of values
1626     */
1627    void setColorMatrix4(float* m);
1628    /**
1629     * Set a color matrix to convert from RGB to luminance. The alpha
1630     * channel will be a copy.
1631     */
1632    void setGreyscale();
1633    /**
1634     * Set the matrix to convert from RGB to YUV with a direct copy of
1635     * the 4th channel.
1636     */
1637    void setRGBtoYUV();
1638    /**
1639     * Set the matrix to convert from YUV to RGB with a direct copy of
1640     * the 4th channel.
1641     */
1642    void setYUVtoRGB();
1643};
1644
1645/**
1646 * Intrinsic for applying a 3x3 convolve to an allocation.
1647 */
1648class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
1649 private:
1650    ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
1651 public:
1652    /**
1653     * Supported types U8 and F32 with vector lengths between 1 and
1654     * 4. The default convolution kernel is the identity.
1655     * @param[in] rs RenderScript context
1656     * @param[in] e Element
1657     * @return new ScriptIntrinsicConvolve3x3
1658     */
1659    static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
1660    /**
1661     * Sets input for intrinsic.
1662     * @param[in] in input Allocation
1663     */
1664    void setInput(sp<Allocation> in);
1665    /**
1666     * Launches the intrinsic.
1667     * @param[in] out output Allocation
1668     */
1669    void forEach(sp<Allocation> out);
1670    /**
1671     * Sets convolution kernel.
1672     * @param[in] v float[9] of values
1673     */
1674    void setCoefficients(float* v);
1675};
1676
1677/**
1678 * Intrinsic for applying a 5x5 convolve to an allocation.
1679 */
1680class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
1681 private:
1682    ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
1683 public:
1684    /**
1685     * Supported types U8 and F32 with vector lengths between 1 and
1686     * 4. The default convolution kernel is the identity.
1687     * @param[in] rs RenderScript context
1688     * @param[in] e Element
1689     * @return new ScriptIntrinsicConvolve5x5
1690     */
1691    static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
1692    /**
1693     * Sets input for intrinsic.
1694     * @param[in] in input Allocation
1695     */
1696    void setInput(sp<Allocation> in);
1697    /**
1698     * Launches the intrinsic.
1699     * @param[in] out output Allocation
1700     */
1701    void forEach(sp<Allocation> out);
1702    /**
1703     * Sets convolution kernel.
1704     * @param[in] v float[25] of values
1705     */
1706    void setCoefficients(float* v);
1707};
1708
1709/**
1710 * Intrinsic for computing a histogram.
1711 */
1712class ScriptIntrinsicHistogram : public ScriptIntrinsic {
1713 private:
1714    ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
1715    sp<Allocation> mOut;
1716 public:
1717    /**
1718     * Create an intrinsic for calculating the histogram of an uchar
1719     * or uchar4 image.
1720     *
1721     * Supported elements types are U8_4, U8_3, U8_2, and U8.
1722     *
1723     * @param[in] rs The RenderScript context
1724     * @param[in] e Element type for inputs
1725     *
1726     * @return ScriptIntrinsicHistogram
1727     */
1728    static sp<ScriptIntrinsicHistogram> create(sp<RS> rs, sp<const Element> e);
1729    /**
1730     * Set the output of the histogram.  32 bit integer types are
1731     * supported.
1732     *
1733     * @param[in] aout The output allocation
1734     */
1735    void setOutput(sp<Allocation> aout);
1736    /**
1737     * Set the coefficients used for the dot product calculation. The
1738     * default is {0.299f, 0.587f, 0.114f, 0.f}.
1739     *
1740     * Coefficients must be >= 0 and sum to 1.0 or less.
1741     *
1742     * @param[in] r Red coefficient
1743     * @param[in] g Green coefficient
1744     * @param[in] b Blue coefficient
1745     * @param[in] a Alpha coefficient
1746     */
1747    void setDotCoefficients(float r, float g, float b, float a);
1748    /**
1749     * Process an input buffer and place the histogram into the output
1750     * allocation. The output allocation may be a narrower vector size
1751     * than the input. In this case the vector size of the output is
1752     * used to determine how many of the input channels are used in
1753     * the computation. This is useful if you have an RGBA input
1754     * buffer but only want the histogram for RGB.
1755     *
1756     * 1D and 2D input allocations are supported.
1757     *
1758     * @param[in] ain The input image
1759     */
1760    void forEach(sp<Allocation> ain);
1761    /**
1762     * Process an input buffer and place the histogram into the output
1763     * allocation. The dot product of the input channel and the
1764     * coefficients from 'setDotCoefficients' are used to calculate
1765     * the output values.
1766     *
1767     * 1D and 2D input allocations are supported.
1768     *
1769     * @param ain The input image
1770     */
1771    void forEach_dot(sp<Allocation> ain);
1772};
1773
1774/**
1775 * Intrinsic for applying a per-channel lookup table. Each channel of
1776 * the input has an independant lookup table. The tables are 256
1777 * entries in size and can cover the full value range of U8_4.
1778 **/
1779class ScriptIntrinsicLUT : public ScriptIntrinsic {
1780 private:
1781    sp<Allocation> LUT;
1782    bool mDirty;
1783    unsigned char mCache[1024];
1784    void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
1785    ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
1786
1787 public:
1788    /**
1789     * Supported elements types are U8_4.
1790     *
1791     * The defaults tables are identity.
1792     *
1793     * @param[in] rs The RenderScript context
1794     * @param[in] e Element type for intputs and outputs
1795     *
1796     * @return ScriptIntrinsicLUT
1797     */
1798    static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
1799    /**
1800     * Invoke the kernel and apply the lookup to each cell of ain and
1801     * copy to aout.
1802     *
1803     * @param[in] ain Input allocation
1804     * @param[in] aout Output allocation
1805     */
1806    void forEach(sp<Allocation> ain, sp<Allocation> aout);
1807    /**
1808     * Sets entries in LUT for the red channel.
1809     * @param[in] base base of region to update
1810     * @param[in] length length of region to update
1811     * @param[in] lutValues LUT values to use
1812     */
1813    void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
1814    /**
1815     * Sets entries in LUT for the green channel.
1816     * @param[in] base base of region to update
1817     * @param[in] length length of region to update
1818     * @param[in] lutValues LUT values to use
1819     */
1820    void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
1821    /**
1822     * Sets entries in LUT for the blue channel.
1823     * @param[in] base base of region to update
1824     * @param[in] length length of region to update
1825     * @param[in] lutValues LUT values to use
1826     */
1827    void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
1828    /**
1829     * Sets entries in LUT for the alpha channel.
1830     * @param[in] base base of region to update
1831     * @param[in] length length of region to update
1832     * @param[in] lutValues LUT values to use
1833     */
1834    void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
1835    virtual ~ScriptIntrinsicLUT();
1836};
1837
1838/**
1839 * Intrinsic for converting an Android YUV buffer to RGB.
1840 *
1841 * The input allocation should be supplied in a supported YUV format
1842 * as a YUV element Allocation. The output is RGBA; the alpha channel
1843 * will be set to 255.
1844 */
1845class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
1846 private:
1847    ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
1848 public:
1849    /**
1850     * Create an intrinsic for converting YUV to RGB.
1851     *
1852     * Supported elements types are U8_4.
1853     *
1854     * @param[in] rs The RenderScript context
1855     * @param[in] e Element type for output
1856     *
1857     * @return ScriptIntrinsicYuvToRGB
1858     */
1859    static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
1860    /**
1861     * Set the input YUV allocation.
1862     *
1863     * @param[in] ain The input allocation.
1864     */
1865    void setInput(sp<Allocation> in);
1866
1867    /**
1868     * Convert the image to RGB.
1869     *
1870     * @param[in] aout Output allocation. Must match creation element
1871     *                 type.
1872     */
1873    void forEach(sp<Allocation> out);
1874
1875};
1876
1877/**
1878 * Sampler object that defines how Allocations can be read as textures
1879 * within a kernel. Samplers are used in conjunction with the rsSample
1880 * runtime function to return values from normalized coordinates.
1881 *
1882 * Any Allocation used with a Sampler must have been created with
1883 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an
1884 * Allocation that was not created with
1885 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined.
1886 **/
1887 class Sampler : public BaseObj {
1888 private:
1889    Sampler(sp<RS> rs, void* id);
1890    RsSamplerValue mMin;
1891    RsSamplerValue mMag;
1892    RsSamplerValue mWrapS;
1893    RsSamplerValue mWrapT;
1894    float mAniso;
1895
1896 public:
1897    /**
1898     * Creates a non-standard Sampler.
1899     * @param[in] rs RenderScript context
1900     * @param[in] min minification
1901     * @param[in] mag magnification
1902     * @param[in] wrapS S wrapping mode
1903     * @param[in] wrapT T wrapping mode
1904     * @param[in] anisotropy anisotropy setting
1905     */
1906    static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
1907
1908    /**
1909     * @return minification setting for the sampler
1910     */
1911    RsSamplerValue getMinification();
1912    /**
1913     * @return magnification setting for the sampler
1914     */
1915    RsSamplerValue getMagnification();
1916    /**
1917     * @return S wrapping mode for the sampler
1918     */
1919    RsSamplerValue getWrapS();
1920    /**
1921     * @return T wrapping mode for the sampler
1922     */
1923    RsSamplerValue getWrapT();
1924    /**
1925     * @return anisotropy setting for the sampler
1926     */
1927    float getAnisotropy();
1928
1929    /**
1930     * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1931     * clamp.
1932     *
1933     * @param rs Context to which the sampler will belong.
1934     *
1935     * @return Sampler
1936     */
1937    static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
1938    /**
1939     * Retrieve a sampler with min and mag set to linear and wrap modes set to
1940     * clamp.
1941     *
1942     * @param rs Context to which the sampler will belong.
1943     *
1944     * @return Sampler
1945     */
1946    static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
1947    /**
1948     * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
1949     * wrap modes set to clamp.
1950     *
1951     * @param rs Context to which the sampler will belong.
1952     *
1953     * @return Sampler
1954     */
1955    static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
1956    /**
1957     * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1958     * wrap.
1959     *
1960     * @param rs Context to which the sampler will belong.
1961     *
1962     * @return Sampler
1963     */
1964    static sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
1965    /**
1966     * Retrieve a sampler with min and mag set to linear and wrap modes set to
1967     * wrap.
1968     *
1969     * @param rs Context to which the sampler will belong.
1970     *
1971     * @return Sampler
1972     */
1973    static sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
1974    /**
1975     * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
1976     * wrap modes set to wrap.
1977     *
1978     * @param rs Context to which the sampler will belong.
1979     *
1980     * @return Sampler
1981     */
1982    static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
1983    /**
1984     * Retrieve a sampler with min and mag set to nearest and wrap modes set to
1985     * mirrored repeat.
1986     *
1987     * @param rs Context to which the sampler will belong.
1988     *
1989     * @return Sampler
1990     */
1991    static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
1992    /**
1993     * Retrieve a sampler with min and mag set to linear and wrap modes set to
1994     * mirrored repeat.
1995     *
1996     * @param rs Context to which the sampler will belong.
1997     *
1998     * @return Sampler
1999     */
2000    static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
2001    /**
2002     * Retrieve a sampler with min and mag set to linear and wrap modes set to
2003     * mirrored repeat.
2004     *
2005     * @param rs Context to which the sampler will belong.
2006     *
2007     * @return Sampler
2008     */
2009    static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
2010
2011};
2012
2013class Byte2 {
2014 public:
2015  int8_t x, y;
2016
2017  Byte2(int8_t initX, int8_t initY)
2018    : x(initX), y(initY) {}
2019  Byte2() : x(0), y(0) {}
2020};
2021
2022class Byte3 {
2023 public:
2024  int8_t x, y, z;
2025
2026  Byte3(int8_t initX, int8_t initY, int8_t initZ)
2027    : x(initX), y(initY), z(initZ) {}
2028  Byte3() : x(0), y(0), z(0) {}
2029};
2030
2031class Byte4 {
2032 public:
2033  int8_t x, y, z, w;
2034
2035  Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
2036    : x(initX), y(initY), z(initZ), w(initW) {}
2037  Byte4() : x(0), y(0), z(0), w(0) {}
2038};
2039
2040class UByte2 {
2041 public:
2042  uint8_t x, y;
2043
2044  UByte2(uint8_t initX, uint8_t initY)
2045    : x(initX), y(initY) {}
2046  UByte2() : x(0), y(0) {}
2047};
2048
2049class UByte3 {
2050 public:
2051  uint8_t x, y, z;
2052
2053  UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
2054    : x(initX), y(initY), z(initZ) {}
2055  UByte3() : x(0), y(0), z(0) {}
2056};
2057
2058class UByte4 {
2059 public:
2060  uint8_t x, y, z, w;
2061
2062  UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
2063    : x(initX), y(initY), z(initZ), w(initW) {}
2064  UByte4() : x(0), y(0), z(0), w(0) {}
2065};
2066
2067class Short2 {
2068 public:
2069  short x, y;
2070
2071  Short2(short initX, short initY)
2072    : x(initX), y(initY) {}
2073  Short2() : x(0), y(0) {}
2074};
2075
2076class Short3 {
2077 public:
2078  short x, y, z;
2079
2080  Short3(short initX, short initY, short initZ)
2081    : x(initX), y(initY), z(initZ) {}
2082  Short3() : x(0), y(0), z(0) {}
2083};
2084
2085class Short4 {
2086 public:
2087  short x, y, z, w;
2088
2089  Short4(short initX, short initY, short initZ, short initW)
2090    : x(initX), y(initY), z(initZ), w(initW) {}
2091  Short4() : x(0), y(0), z(0), w(0) {}
2092};
2093
2094class UShort2 {
2095 public:
2096  uint16_t x, y;
2097
2098  UShort2(uint16_t initX, uint16_t initY)
2099    : x(initX), y(initY) {}
2100  UShort2() : x(0), y(0) {}
2101};
2102
2103class UShort3 {
2104 public:
2105  uint16_t x, y, z;
2106
2107  UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
2108    : x(initX), y(initY), z(initZ) {}
2109  UShort3() : x(0), y(0), z(0) {}
2110};
2111
2112class UShort4 {
2113 public:
2114  uint16_t x, y, z, w;
2115
2116  UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
2117    : x(initX), y(initY), z(initZ), w(initW) {}
2118  UShort4() : x(0), y(0), z(0), w(0) {}
2119};
2120
2121class Int2 {
2122 public:
2123  int x, y;
2124
2125  Int2(int initX, int initY)
2126    : x(initX), y(initY) {}
2127  Int2() : x(0), y(0) {}
2128};
2129
2130class Int3 {
2131 public:
2132  int x, y, z;
2133
2134  Int3(int initX, int initY, int initZ)
2135    : x(initX), y(initY), z(initZ) {}
2136  Int3() : x(0), y(0), z(0) {}
2137};
2138
2139class Int4 {
2140 public:
2141  int x, y, z, w;
2142
2143  Int4(int initX, int initY, int initZ, int initW)
2144    : x(initX), y(initY), z(initZ), w(initW) {}
2145  Int4() : x(0), y(0), z(0), w(0) {}
2146};
2147
2148class UInt2 {
2149 public:
2150  uint32_t x, y;
2151
2152  UInt2(uint32_t initX, uint32_t initY)
2153    : x(initX), y(initY) {}
2154  UInt2() : x(0), y(0) {}
2155};
2156
2157class UInt3 {
2158 public:
2159  uint32_t x, y, z;
2160
2161  UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
2162    : x(initX), y(initY), z(initZ) {}
2163  UInt3() : x(0), y(0), z(0) {}
2164};
2165
2166class UInt4 {
2167 public:
2168  uint32_t x, y, z, w;
2169
2170  UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
2171    : x(initX), y(initY), z(initZ), w(initW) {}
2172  UInt4() : x(0), y(0), z(0), w(0) {}
2173};
2174
2175class Long2 {
2176 public:
2177  int64_t x, y;
2178
2179  Long2(int64_t initX, int64_t initY)
2180    : x(initX), y(initY) {}
2181  Long2() : x(0), y(0) {}
2182};
2183
2184class Long3 {
2185 public:
2186  int64_t x, y, z;
2187
2188  Long3(int64_t initX, int64_t initY, int64_t initZ)
2189    : x(initX), y(initY), z(initZ) {}
2190  Long3() : x(0), y(0), z(0) {}
2191};
2192
2193class Long4 {
2194 public:
2195  int64_t x, y, z, w;
2196
2197  Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
2198    : x(initX), y(initY), z(initZ), w(initW) {}
2199  Long4() : x(0), y(0), z(0), w(0) {}
2200};
2201
2202class ULong2 {
2203 public:
2204  uint64_t x, y;
2205
2206  ULong2(uint64_t initX, uint64_t initY)
2207    : x(initX), y(initY) {}
2208  ULong2() : x(0), y(0) {}
2209};
2210
2211class ULong3 {
2212 public:
2213  uint64_t x, y, z;
2214
2215  ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
2216    : x(initX), y(initY), z(initZ) {}
2217  ULong3() : x(0), y(0), z(0) {}
2218};
2219
2220class ULong4 {
2221 public:
2222  uint64_t x, y, z, w;
2223
2224  ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
2225    : x(initX), y(initY), z(initZ), w(initW) {}
2226  ULong4() : x(0), y(0), z(0), w(0) {}
2227};
2228
2229class Float2 {
2230 public:
2231  float x, y;
2232
2233  Float2(float initX, float initY)
2234    : x(initX), y(initY) {}
2235  Float2() : x(0), y(0) {}
2236};
2237
2238class Float3 {
2239 public:
2240  float x, y, z;
2241
2242  Float3(float initX, float initY, float initZ)
2243    : x(initX), y(initY), z(initZ) {}
2244  Float3() : x(0.f), y(0.f), z(0.f) {}
2245};
2246
2247class Float4 {
2248 public:
2249  float x, y, z, w;
2250
2251  Float4(float initX, float initY, float initZ, float initW)
2252    : x(initX), y(initY), z(initZ), w(initW) {}
2253  Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
2254};
2255
2256class Double2 {
2257 public:
2258  double x, y;
2259
2260  Double2(double initX, double initY)
2261    : x(initX), y(initY) {}
2262  Double2() : x(0), y(0) {}
2263};
2264
2265class Double3 {
2266 public:
2267  double x, y, z;
2268
2269  Double3(double initX, double initY, double initZ)
2270    : x(initX), y(initY), z(initZ) {}
2271  Double3() : x(0), y(0), z(0) {}
2272};
2273
2274class Double4 {
2275 public:
2276  double x, y, z, w;
2277
2278  Double4(double initX, double initY, double initZ, double initW)
2279    : x(initX), y(initY), z(initZ), w(initW) {}
2280  Double4() : x(0), y(0), z(0), w(0) {}
2281};
2282
2283}
2284
2285}
2286
2287#endif
2288