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