HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Lollipop MR1
|
5.1.0_r3
下载
查看原文件
收藏
根目录
frameworks
rs
cpp
rsCppStructs.h
/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ANDROID_RSCPPSTRUCTS_H #define ANDROID_RSCPPSTRUCTS_H #include "rsDefines.h" #include "util/RefBase.h" #include "rsDispatch.h" #include
#include
#include
/** * Every row in an RS allocation is guaranteed to be aligned by this amount, and * every row in a user-backed allocation must be aligned by this amount. */ #define RS_CPU_ALLOCATION_ALIGNMENT 16 namespace android { namespace RSC { typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText); typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen); class RS; class BaseObj; class Element; class Type; class Allocation; class Script; class ScriptC; class Sampler; /** * Possible error codes used by RenderScript. Once a status other than RS_SUCCESS * is returned, the RenderScript context is considered dead and cannot perform any * additional work. */ enum RSError { RS_SUCCESS = 0, ///< No error RS_ERROR_INVALID_PARAMETER = 1, ///< An invalid parameter was passed to a function RS_ERROR_RUNTIME_ERROR = 2, ///< The RenderScript driver returned an error; this is ///< often indicative of a kernel that crashed RS_ERROR_INVALID_ELEMENT = 3, ///< An invalid Element was passed to a function RS_ERROR_MAX = 9999 }; /** * YUV formats supported by the RenderScript API. */ enum RSYuvFormat { RS_YUV_NONE = 0, ///< No YUV data RS_YUV_YV12 = 1, ///< YUV data in YV12 format RS_YUV_NV21 = 2, ///< YUV data in NV21 format RS_YUV_MAX = 3 }; /** * Flags that can control RenderScript behavior on a per-context level. */ enum RSInitFlags { RS_INIT_SYNCHRONOUS = 1, ///< All RenderScript calls will be synchronous. May reduce latency. RS_INIT_LOW_LATENCY = 2, ///< Prefer low latency devices over potentially higher throughput devices. RS_INIT_MAX = 4 }; /** * The RenderScript context. This class controls initialization, resource management, and teardown. */ class RS : public android::RSC::LightRefBase
{ public: RS(); virtual ~RS(); /** * Initializes a RenderScript context. A context must be initialized before it can be used. * @param[in] name Directory name to be used by this context. This should be equivalent to * Context.getCacheDir(). * @param[in] flags Optional flags for this context. * @return true on success */ bool init(std::string name, uint32_t flags = 0); /** * Sets the error handler function for this context. This error handler is * called whenever an error is set. * * @param[in] func Error handler function */ void setErrorHandler(ErrorHandlerFunc_t func); /** * Returns the current error handler function for this context. * * @return pointer to current error handler function or NULL if not set */ ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; } /** * Sets the message handler function for this context. This message handler * is called whenever a message is sent from a RenderScript kernel. * * @param[in] func Message handler function */ void setMessageHandler(MessageHandlerFunc_t func); /** * Returns the current message handler function for this context. * * @return pointer to current message handler function or NULL if not set */ MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; } /** * Returns current status for the context. * * @return current error */ RSError getError(); /** * Waits for any currently running asynchronous operations to finish. This * should only be used for performance testing and timing. */ void finish(); RsContext getContext() { return mContext; } void throwError(RSError error, const char *errMsg); static dispatchTable* dispatch; private: static bool usingNative; static bool initDispatch(int targetApi); bool init(std::string &name, int targetApi, uint32_t flags); static void * threadProc(void *); static bool gInitialized; static pthread_mutex_t gInitMutex; pthread_t mMessageThreadId; pid_t mNativeMessageThreadId; bool mMessageRun; RsDevice mDev; RsContext mContext; RSError mCurrentError; ErrorHandlerFunc_t mErrorFunc; MessageHandlerFunc_t mMessageFunc; bool mInit; std::string mCacheDir; struct { sp
U8; sp
U8_2; sp
U8_3; sp
U8_4; sp
I8; sp
I8_2; sp
I8_3; sp
I8_4; sp
U16; sp
U16_2; sp
U16_3; sp
U16_4; sp
I16; sp
I16_2; sp
I16_3; sp
I16_4; sp
U32; sp
U32_2; sp
U32_3; sp
U32_4; sp
I32; sp
I32_2; sp
I32_3; sp
I32_4; sp
U64; sp
U64_2; sp
U64_3; sp
U64_4; sp
I64; sp
I64_2; sp
I64_3; sp
I64_4; sp
F32; sp
F32_2; sp
F32_3; sp
F32_4; sp
F64; sp
F64_2; sp
F64_3; sp
F64_4; sp
BOOLEAN; sp
ELEMENT; sp
TYPE; sp
ALLOCATION; sp
SAMPLER; sp
SCRIPT; sp
MESH; sp
PROGRAM_FRAGMENT; sp
PROGRAM_VERTEX; sp
PROGRAM_RASTER; sp
PROGRAM_STORE; sp
A_8; sp
RGB_565; sp
RGB_888; sp
RGBA_5551; sp
RGBA_4444; sp
RGBA_8888; sp
YUV; sp
MATRIX_4X4; sp
MATRIX_3X3; sp
MATRIX_2X2; } mElements; struct { sp
CLAMP_NEAREST; sp
CLAMP_LINEAR; sp
CLAMP_LINEAR_MIP_LINEAR; sp
WRAP_NEAREST; sp
WRAP_LINEAR; sp
WRAP_LINEAR_MIP_LINEAR; sp
MIRRORED_REPEAT_NEAREST; sp
MIRRORED_REPEAT_LINEAR; sp
MIRRORED_REPEAT_LINEAR_MIP_LINEAR; } mSamplers; friend class Sampler; friend class Element; friend class ScriptC; }; /** * Base class for all RenderScript objects. Not for direct use by developers. */ class BaseObj : public android::RSC::LightRefBase
{ public: void * getID() const; virtual ~BaseObj(); virtual void updateFromNative(); virtual bool equals(sp
obj); protected: void *mID; RS* mRS; std::string mName; BaseObj(void *id, sp
rs); void checkValid(); static void * getObjID(sp
o); }; /** * This class provides the primary method through which data is passed to and * from RenderScript kernels. An Allocation provides the backing store for a * given Type. * * An Allocation also contains a set of usage flags that denote how the * Allocation could be used. For example, an Allocation may have usage flags * specifying that it can be used from a script as well as input to a * Sampler. A developer must synchronize across these different usages using * syncAll(int) in order to ensure that different users of the Allocation have * a consistent view of memory. For example, in the case where an Allocation is * used as the output of one kernel and as Sampler input in a later kernel, a * developer must call syncAll(RS_ALLOCATION_USAGE_SCRIPT) prior to launching the * second kernel to ensure correctness. */ class Allocation : public BaseObj { protected: sp
mType; uint32_t mUsage; sp
mAdaptedAllocation; bool mConstrainedLOD; bool mConstrainedFace; bool mConstrainedY; bool mConstrainedZ; bool mReadAllowed; bool mWriteAllowed; uint32_t mSelectedY; uint32_t mSelectedZ; uint32_t mSelectedLOD; RsAllocationCubemapFace mSelectedFace; uint32_t mCurrentDimX; uint32_t mCurrentDimY; uint32_t mCurrentDimZ; uint32_t mCurrentCount; void * getIDSafe() const; void updateCacheInfo(sp
t); Allocation(void *id, sp
rs, sp
t, uint32_t usage); void validateIsInt32(); void validateIsInt16(); void validateIsInt8(); void validateIsFloat32(); void validateIsObject(); virtual void updateFromNative(); void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h); void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, uint32_t h, uint32_t d); public: /** * Return Type for the allocation. * @return pointer to underlying Type */ sp
getType() const { return mType; } /** * Propagate changes from one usage of the Allocation to other usages of the Allocation. * @param[in] srcLocation source location with changes to propagate elsewhere */ void syncAll(RsAllocationUsageType srcLocation); void ioSendOutput(); void ioGetInput(); /** * Generate a mipmap chain. This is only valid if the Type of the Allocation * includes mipmaps. This function will generate a complete set of mipmaps * from the top level LOD and place them into the script memory space. If * the Allocation is also using other memory spaces, a call to * syncAll(Allocation.USAGE_SCRIPT) is required. */ void generateMipmaps(); /** * Copy an array into part of this Allocation. * @param[in] off offset of first Element to be overwritten * @param[in] count number of Elements to copy * @param[in] data array from which to copy */ void copy1DRangeFrom(uint32_t off, size_t count, const void *data); /** * Copy part of an Allocation into part of this Allocation. * @param[in] off offset of first Element to be overwritten * @param[in] count number of Elements to copy * @param[in] data Allocation from which to copy * @param[in] dataOff offset of first Element in data to copy */ void copy1DRangeFrom(uint32_t off, size_t count, sp
data, uint32_t dataOff); /** * Copy an array into part of this Allocation. * @param[in] off offset of first Element to be overwritten * @param[in] count number of Elements to copy * @param[in] data array from which to copy */ void copy1DRangeTo(uint32_t off, size_t count, void *data); /** * Copy entire array to an Allocation. * @param[in] data array from which to copy */ void copy1DFrom(const void* data); /** * Copy entire Allocation to an array. * @param[in] data destination array */ void copy1DTo(void* data); /** * Copy from an array into a rectangular region in this Allocation. The * array is assumed to be tightly packed. * @param[in] xoff X offset of region to update in this Allocation * @param[in] yoff Y offset of region to update in this Allocation * @param[in] w Width of region to update * @param[in] h Height of region to update * @param[in] data Array from which to copy */ void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data); /** * Copy from this Allocation into a rectangular region in an array. The * array is assumed to be tightly packed. * @param[in] xoff X offset of region to copy from this Allocation * @param[in] yoff Y offset of region to copy from this Allocation * @param[in] w Width of region to update * @param[in] h Height of region to update * @param[in] data destination array */ void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, void *data); /** * Copy from an Allocation into a rectangular region in this Allocation. * @param[in] xoff X offset of region to update in this Allocation * @param[in] yoff Y offset of region to update in this Allocation * @param[in] w Width of region to update * @param[in] h Height of region to update * @param[in] data Allocation from which to copy * @param[in] dataXoff X offset of region to copy from in data * @param[in] dataYoff Y offset of region to copy from in data */ void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, sp
data, uint32_t dataXoff, uint32_t dataYoff); /** * Copy from a strided array into a rectangular region in this Allocation. * @param[in] xoff X offset of region to update in this Allocation * @param[in] yoff Y offset of region to update in this Allocation * @param[in] w Width of region to update * @param[in] h Height of region to update * @param[in] data array from which to copy * @param[in] stride stride of data in bytes */ void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data, size_t stride); /** * Copy from a strided array into this Allocation. * @param[in] data array from which to copy * @param[in] stride stride of data in bytes */ void copy2DStridedFrom(const void *data, size_t stride); /** * Copy from a rectangular region in this Allocation into a strided array. * @param[in] xoff X offset of region to update in this Allocation * @param[in] yoff Y offset of region to update in this Allocation * @param[in] w Width of region to update * @param[in] h Height of region to update * @param[in] data destination array * @param[in] stride stride of data in bytes */ void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, void *data, size_t stride); /** * Copy this Allocation into a strided array. * @param[in] data destination array * @param[in] stride stride of data in bytes */ void copy2DStridedTo(void *data, size_t stride); /** * Copy from an array into a 3D region in this Allocation. The * array is assumed to be tightly packed. * @param[in] xoff X offset of region to update in this Allocation * @param[in] yoff Y offset of region to update in this Allocation * @param[in] zoff Z offset of region to update in this Allocation * @param[in] w Width of region to update * @param[in] h Height of region to update * @param[in] d Depth of region to update * @param[in] data Array from which to copy */ void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, uint32_t h, uint32_t d, const void* data); /** * Copy from an Allocation into a 3D region in this Allocation. * @param[in] xoff X offset of region to update in this Allocation * @param[in] yoff Y offset of region to update in this Allocation * @param[in] zoff Z offset of region to update in this Allocation * @param[in] w Width of region to update * @param[in] h Height of region to update * @param[in] d Depth of region to update * @param[in] data Allocation from which to copy * @param[in] dataXoff X offset of region in data to copy from * @param[in] dataYoff Y offset of region in data to copy from * @param[in] dataZoff Z offset of region in data to copy from */ void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, uint32_t h, uint32_t d, sp
data, uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff); /** * Creates an Allocation for use by scripts with a given Type. * @param[in] rs Context to which the Allocation will belong * @param[in] type Type of the Allocation * @param[in] mipmaps desired mipmap behavior for the Allocation * @param[in] usage usage for the Allocation * @return new Allocation */ static sp
createTyped(sp
rs, sp
type, RsAllocationMipmapControl mipmaps, uint32_t usage); /** * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use * with RS_ALLOCATION_USAGE_SHARED. * @param[in] rs Context to which the Allocation will belong * @param[in] type Type of the Allocation * @param[in] mipmaps desired mipmap behavior for the Allocation * @param[in] usage usage for the Allocation * @param[in] pointer existing backing store to use for this Allocation if possible * @return new Allocation */ static sp
createTyped(sp
rs, sp
type, RsAllocationMipmapControl mipmaps, uint32_t usage, void * pointer); /** * Creates an Allocation for use by scripts with a given Type with no mipmaps. * @param[in] rs Context to which the Allocation will belong * @param[in] type Type of the Allocation * @param[in] usage usage for the Allocation * @return new Allocation */ static sp
createTyped(sp
rs, sp
type, uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); /** * Creates an Allocation with a specified number of given elements. * @param[in] rs Context to which the Allocation will belong * @param[in] e Element used in the Allocation * @param[in] count Number of elements of the Allocation * @param[in] usage usage for the Allocation * @return new Allocation */ static sp
createSized(sp
rs, sp
e, size_t count, uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); /** * Creates a 2D Allocation with a specified number of given elements. * @param[in] rs Context to which the Allocation will belong * @param[in] e Element used in the Allocation * @param[in] x Width in Elements of the Allocation * @param[in] y Height of the Allocation * @param[in] usage usage for the Allocation * @return new Allocation */ static sp
createSized2D(sp
rs, sp
e, size_t x, size_t y, uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); /** * Get the backing pointer for a USAGE_SHARED allocation. * @param[in] stride optional parameter. when non-NULL, will contain * stride in bytes of a 2D Allocation * @return pointer to data */ void * getPointer(size_t *stride = NULL); }; /** * An Element represents one item within an Allocation. An Element is roughly * equivalent to a C type in a RenderScript kernel. Elements may be basic * or complex. Some basic elements are: * - A single float value (equivalent to a float in a kernel) * - A four-element float vector (equivalent to a float4 in a kernel) * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel) * - A single signed 8-bit integer (equivalent to a char in a kernel) * Basic Elements are comprised of a Element.DataType and a * Element.DataKind. The DataType encodes C type information of an Element, * while the DataKind encodes how that Element should be interpreted by a * Sampler. Note that Allocation objects with DataKind USER cannot be used as * input for a Sampler. In general, Allocation objects that are intended for * use with a Sampler should use bitmap-derived Elements such as * Element::RGBA_8888. */ class Element : public BaseObj { public: bool isComplex(); /** * Elements could be simple, such as an int or a float, or a structure with * multiple sub-elements, such as a collection of floats, float2, * float4. This function returns zero for simple elements or the number of * sub-elements otherwise. * @return number of sub-elements */ size_t getSubElementCount() { return mVisibleElementMap.size(); } /** * For complex Elements, this returns the sub-element at a given index. * @param[in] index index of sub-element * @return sub-element */ sp
getSubElement(uint32_t index); /** * For complex Elements, this returns the name of the sub-element at a given * index. * @param[in] index index of sub-element * @return name of sub-element */ const char * getSubElementName(uint32_t index); /** * For complex Elements, this returns the size of the sub-element at a given * index. * @param[in] index index of sub-element * @return size of sub-element */ size_t getSubElementArraySize(uint32_t index); /** * Returns the location of a sub-element within a complex Element. * @param[in] index index of sub-element * @return offset in bytes */ uint32_t getSubElementOffsetBytes(uint32_t index); /** * Returns the data type used for the Element. * @return data type */ RsDataType getDataType() const { return mType; } /** * Returns the data kind used for the Element. * @return data kind */ RsDataKind getDataKind() const { return mKind; } /** * Returns the size in bytes of the Element. * @return size in bytes */ size_t getSizeBytes() const { return mSizeBytes; } /** * Returns the number of vector components for this Element. * @return number of vector components */ uint32_t getVectorSize() const { return mVectorSize; } /** * Utility function for returning an Element containing a single bool. * @param[in] rs RenderScript context * @return Element */ static sp
BOOLEAN(sp
rs); /** * Utility function for returning an Element containing a single unsigned char. * @param[in] rs RenderScript context * @return Element */ static sp
U8(sp
rs); /** * Utility function for returning an Element containing a single signed char. * @param[in] rs RenderScript context * @return Element */ static sp
I8(sp
rs); /** * Utility function for returning an Element containing a single unsigned short. * @param[in] rs RenderScript context * @return Element */ static sp
U16(sp
rs); /** * Utility function for returning an Element containing a single signed short. * @param[in] rs RenderScript context * @return Element */ static sp
I16(sp
rs); /** * Utility function for returning an Element containing a single unsigned int. * @param[in] rs RenderScript context * @return Element */ static sp
U32(sp
rs); /** * Utility function for returning an Element containing a single signed int. * @param[in] rs RenderScript context * @return Element */ static sp
I32(sp
rs); /** * Utility function for returning an Element containing a single unsigned long long. * @param[in] rs RenderScript context * @return Element */ static sp
U64(sp
rs); /** * Utility function for returning an Element containing a single signed long long. * @param[in] rs RenderScript context * @return Element */ static sp
I64(sp
rs); /** * Utility function for returning an Element containing a single float. * @param[in] rs RenderScript context * @return Element */ static sp
F32(sp
rs); /** * Utility function for returning an Element containing a single double. * @param[in] rs RenderScript context * @return Element */ static sp
F64(sp
rs); /** * Utility function for returning an Element containing a single Element. * @param[in] rs RenderScript context * @return Element */ static sp
ELEMENT(sp
rs); /** * Utility function for returning an Element containing a single Type. * @param[in] rs RenderScript context * @return Element */ static sp
TYPE(sp
rs); /** * Utility function for returning an Element containing a single Allocation. * @param[in] rs RenderScript context * @return Element */ static sp
ALLOCATION(sp
rs); /** * Utility function for returning an Element containing a single Sampler. * @param[in] rs RenderScript context * @return Element */ static sp
SAMPLER(sp
rs); /** * Utility function for returning an Element containing a single Script. * @param[in] rs RenderScript context * @return Element */ static sp
SCRIPT(sp
rs); /** * Utility function for returning an Element containing an ALPHA_8 pixel. * @param[in] rs RenderScript context * @return Element */ static sp
A_8(sp
rs); /** * Utility function for returning an Element containing an RGB_565 pixel. * @param[in] rs RenderScript context * @return Element */ static sp
RGB_565(sp
rs); /** * Utility function for returning an Element containing an RGB_888 pixel. * @param[in] rs RenderScript context * @return Element */ static sp
RGB_888(sp
rs); /** * Utility function for returning an Element containing an RGBA_5551 pixel. * @param[in] rs RenderScript context * @return Element */ static sp
RGBA_5551(sp
rs); /** * Utility function for returning an Element containing an RGBA_4444 pixel. * @param[in] rs RenderScript context * @return Element */ static sp
RGBA_4444(sp
rs); /** * Utility function for returning an Element containing an RGBA_8888 pixel. * @param[in] rs RenderScript context * @return Element */ static sp
RGBA_8888(sp
rs); /** * Utility function for returning an Element containing a float2. * @param[in] rs RenderScript context * @return Element */ static sp
F32_2(sp
rs); /** * Utility function for returning an Element containing a float3. * @param[in] rs RenderScript context * @return Element */ static sp
F32_3(sp
rs); /** * Utility function for returning an Element containing a float4. * @param[in] rs RenderScript context * @return Element */ static sp
F32_4(sp
rs); /** * Utility function for returning an Element containing a double2. * @param[in] rs RenderScript context * @return Element */ static sp
F64_2(sp
rs); /** * Utility function for returning an Element containing a double3. * @param[in] rs RenderScript context * @return Element */ static sp
F64_3(sp
rs); /** * Utility function for returning an Element containing a double4. * @param[in] rs RenderScript context * @return Element */ static sp
F64_4(sp
rs); /** * Utility function for returning an Element containing a uchar2. * @param[in] rs RenderScript context * @return Element */ static sp
U8_2(sp
rs); /** * Utility function for returning an Element containing a uchar3. * @param[in] rs RenderScript context * @return Element */ static sp
U8_3(sp
rs); /** * Utility function for returning an Element containing a uchar4. * @param[in] rs RenderScript context * @return Element */ static sp
U8_4(sp
rs); /** * Utility function for returning an Element containing a char2. * @param[in] rs RenderScript context * @return Element */ static sp
I8_2(sp
rs); /** * Utility function for returning an Element containing a char3. * @param[in] rs RenderScript context * @return Element */ static sp
I8_3(sp
rs); /** * Utility function for returning an Element containing a char4. * @param[in] rs RenderScript context * @return Element */ static sp
I8_4(sp
rs); /** * Utility function for returning an Element containing a ushort2. * @param[in] rs RenderScript context * @return Element */ static sp
U16_2(sp
rs); /** * Utility function for returning an Element containing a ushort3. * @param[in] rs RenderScript context * @return Element */ static sp
U16_3(sp
rs); /** * Utility function for returning an Element containing a ushort4. * @param[in] rs RenderScript context * @return Element */ static sp
U16_4(sp
rs); /** * Utility function for returning an Element containing a short2. * @param[in] rs RenderScript context * @return Element */ static sp
I16_2(sp
rs); /** * Utility function for returning an Element containing a short3. * @param[in] rs RenderScript context * @return Element */ static sp
I16_3(sp
rs); /** * Utility function for returning an Element containing a short4. * @param[in] rs RenderScript context * @return Element */ static sp
I16_4(sp
rs); /** * Utility function for returning an Element containing a uint2. * @param[in] rs RenderScript context * @return Element */ static sp
U32_2(sp
rs); /** * Utility function for returning an Element containing a uint3. * @param[in] rs RenderScript context * @return Element */ static sp
U32_3(sp
rs); /** * Utility function for returning an Element containing a uint4. * @param[in] rs RenderScript context * @return Element */ static sp
U32_4(sp
rs); /** * Utility function for returning an Element containing an int2. * @param[in] rs RenderScript context * @return Element */ static sp
I32_2(sp
rs); /** * Utility function for returning an Element containing an int3. * @param[in] rs RenderScript context * @return Element */ static sp
I32_3(sp
rs); /** * Utility function for returning an Element containing an int4. * @param[in] rs RenderScript context * @return Element */ static sp
I32_4(sp
rs); /** * Utility function for returning an Element containing a ulong2. * @param[in] rs RenderScript context * @return Element */ static sp
U64_2(sp
rs); /** * Utility function for returning an Element containing a ulong3. * @param[in] rs RenderScript context * @return Element */ static sp
U64_3(sp
rs); /** * Utility function for returning an Element containing a ulong4. * @param[in] rs RenderScript context * @return Element */ static sp
U64_4(sp
rs); /** * Utility function for returning an Element containing a long2. * @param[in] rs RenderScript context * @return Element */ static sp
I64_2(sp
rs); /** * Utility function for returning an Element containing a long3. * @param[in] rs RenderScript context * @return Element */ static sp
I64_3(sp
rs); /** * Utility function for returning an Element containing a long4. * @param[in] rs RenderScript context * @return Element */ static sp
I64_4(sp
rs); /** * Utility function for returning an Element containing a YUV pixel. * @param[in] rs RenderScript context * @return Element */ static sp
YUV(sp
rs); /** * Utility function for returning an Element containing an rs_matrix_4x4. * @param[in] rs RenderScript context * @return Element */ static sp
MATRIX_4X4(sp
rs); /** * Utility function for returning an Element containing an rs_matrix_3x3. * @param[in] rs RenderScript context * @return Element */ static sp
MATRIX_3X3(sp
rs); /** * Utility function for returning an Element containing an rs_matrix_2x2. * @param[in] rs RenderScript context * @return Element */ static sp
MATRIX_2X2(sp
rs); void updateFromNative(); /** * Create an Element with a given DataType. * @param[in] rs RenderScript context * @param[in] dt data type * @return Element */ static sp
createUser(sp
rs, RsDataType dt); /** * Create a vector Element with the given DataType * @param[in] rs RenderScript * @param[in] dt DataType * @param[in] size vector size * @return Element */ static sp
createVector(sp
rs, RsDataType dt, uint32_t size); /** * Create an Element with a given DataType and DataKind. * @param[in] rs RenderScript context * @param[in] dt DataType * @param[in] dk DataKind * @return Element */ static sp
createPixel(sp
rs, RsDataType dt, RsDataKind dk); /** * Returns true if the Element can interoperate with this Element. * @param[in] e Element to compare * @return true if Elements can interoperate */ bool isCompatible(sp
e) const; /** * Builder class for producing complex elements with matching field and name * pairs. The builder starts empty. The order in which elements are added is * retained for the layout in memory. */ class Builder { private: RS* mRS; std::vector
> mElements; std::vector
mElementNames; std::vector
mArraySizes; bool mSkipPadding; public: Builder(sp
rs); ~Builder(); void add(sp
e, std::string &name, uint32_t arraySize = 1); sp
create(); }; protected: Element(void *id, sp
rs, std::vector
> &elements, std::vector
&elementNames, std::vector
&arraySizes); Element(void *id, sp
rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size); Element(sp
rs); virtual ~Element(); private: void updateVisibleSubElements(); std::vector
> mElements; std::vector
mElementNames; std::vector
mArraySizes; std::vector
mVisibleElementMap; std::vector
mOffsetInBytes; RsDataType mType; RsDataKind mKind; bool mNormalized; size_t mSizeBytes; size_t mVectorSize; }; class FieldPacker { protected: unsigned char* mData; size_t mPos; size_t mLen; public: FieldPacker(size_t len) : mPos(0), mLen(len) { mData = new unsigned char[len]; } virtual ~FieldPacker() { delete [] mData; } void align(size_t v) { if ((v & (v - 1)) != 0) { // ALOGE("Non-power-of-two alignment: %zu", v); return; } while ((mPos & (v - 1)) != 0) { mData[mPos++] = 0; } } void reset() { mPos = 0; } void reset(size_t i) { if (i >= mLen) { // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen); return; } mPos = i; } void skip(size_t i) { size_t res = mPos + i; if (res > mLen) { // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen); return; } mPos = res; } void* getData() const { return mData; } size_t getLength() const { return mLen; } template
void add(T t) { align(sizeof(t)); if (mPos + sizeof(t) <= mLen) { memcpy(&mData[mPos], &t, sizeof(t)); mPos += sizeof(t); } } /* void add(rs_matrix4x4 m) { for (size_t i = 0; i < 16; i++) { add(m.m[i]); } } void add(rs_matrix3x3 m) { for (size_t i = 0; i < 9; i++) { add(m.m[i]); } } void add(rs_matrix2x2 m) { for (size_t i = 0; i < 4; i++) { add(m.m[i]); } } */ void add(sp
obj) { if (obj != NULL) { add((uint32_t) (uintptr_t) obj->getID()); } else { add((uint32_t) 0); } } }; /** * A Type describes the Element and dimensions used for an Allocation or a * parallel operation. * * A Type always includes an Element and an X dimension. A Type may be * multidimensional, up to three dimensions. A nonzero value in the Y or Z * dimensions indicates that the dimension is present. Note that a Type with * only a given X dimension and a Type with the same X dimension but Y = 1 are * not equivalent. * * A Type also supports inclusion of level of detail (LOD) or cube map * faces. LOD and cube map faces are booleans to indicate present or not * present. * * A Type also supports YUV format information to support an Allocation in a YUV * format. The YUV formats supported are YV12 and NV21. */ class Type : public BaseObj { protected: friend class Allocation; uint32_t mDimX; uint32_t mDimY; uint32_t mDimZ; RSYuvFormat mYuvFormat; bool mDimMipmaps; bool mDimFaces; size_t mElementCount; sp
mElement; Type(void *id, sp
rs); void calcElementCount(); virtual void updateFromNative(); public: /** * Returns the YUV format. * @return YUV format of the Allocation */ RSYuvFormat getYuvFormat() const { return mYuvFormat; } /** * Returns the Element of the Allocation. * @return YUV format of the Allocation */ sp
getElement() const { return mElement; } /** * Returns the X dimension of the Allocation. * @return X dimension of the allocation */ uint32_t getX() const { return mDimX; } /** * Returns the Y dimension of the Allocation. * @return Y dimension of the allocation */ uint32_t getY() const { return mDimY; } /** * Returns the Z dimension of the Allocation. * @return Z dimension of the allocation */ uint32_t getZ() const { return mDimZ; } /** * Returns true if the Allocation has mipmaps. * @return true if the Allocation has mipmaps */ bool hasMipmaps() const { return mDimMipmaps; } /** * Returns true if the Allocation is a cube map * @return true if the Allocation is a cube map */ bool hasFaces() const { return mDimFaces; } /** * Returns number of accessible Elements in the Allocation * @return number of accessible Elements in the Allocation */ size_t getCount() const { return mElementCount; } /** * Returns size in bytes of all Elements in the Allocation * @return size in bytes of all Elements in the Allocation */ size_t getSizeBytes() const { return mElementCount * mElement->getSizeBytes(); } /** * Creates a new Type with the given Element and dimensions. * @param[in] rs RenderScript context * @param[in] e Element * @param[in] dimX X dimension * @param[in] dimY Y dimension * @param[in] dimZ Z dimension * @return new Type */ static sp
create(sp
rs, sp
e, uint32_t dimX, uint32_t dimY, uint32_t dimZ); class Builder { protected: RS* mRS; uint32_t mDimX; uint32_t mDimY; uint32_t mDimZ; RSYuvFormat mYuvFormat; bool mDimMipmaps; bool mDimFaces; sp
mElement; public: Builder(sp
rs, sp
e); void setX(uint32_t value); void setY(uint32_t value); void setZ(uint32_t value); void setYuvFormat(RSYuvFormat format); void setMipmaps(bool value); void setFaces(bool value); sp
create(); }; }; /** * The parent class for all executable Scripts. This should not be used by applications. */ class Script : public BaseObj { private: protected: Script(void *id, sp
rs); void forEach(uint32_t slot, sp
in, sp