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