• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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_ALLOCATION_H__
18 #define __ANDROID_ALLOCATION_H__
19 
20 #include <pthread.h>
21 #include <rs.h>
22 
23 #include "RenderScript.h"
24 #include "Type.h"
25 #include "Element.h"
26 
27 namespace android {
28 namespace renderscriptCpp {
29 
30 class Allocation : public BaseObj {
31 protected:
32     android::sp<const Type> mType;
33     uint32_t mUsage;
34     android::sp<Allocation> mAdaptedAllocation;
35 
36     bool mConstrainedLOD;
37     bool mConstrainedFace;
38     bool mConstrainedY;
39     bool mConstrainedZ;
40     bool mReadAllowed;
41     bool mWriteAllowed;
42     uint32_t mSelectedY;
43     uint32_t mSelectedZ;
44     uint32_t mSelectedLOD;
45     RsAllocationCubemapFace mSelectedFace;
46 
47     uint32_t mCurrentDimX;
48     uint32_t mCurrentDimY;
49     uint32_t mCurrentDimZ;
50     uint32_t mCurrentCount;
51 
52 
53     void * getIDSafe() const;
54     void updateCacheInfo(sp<const Type> t);
55 
56     Allocation(void *id, RenderScript *rs, sp<const Type> t, uint32_t usage);
57 
58     void validateIsInt32();
59     void validateIsInt16();
60     void validateIsInt8();
61     void validateIsFloat32();
62     void validateIsObject();
63 
64     virtual void updateFromNative();
65 
66     void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
67 
68 public:
getType()69     android::sp<const Type> getType() {
70         return mType;
71     }
72 
73     void syncAll(RsAllocationUsageType srcLocation);
74     void ioSendOutput();
75     void ioGetInput();
76 
77     //void copyFrom(BaseObj[] d);
78     //void copyFromUnchecked(int[] d);
79     //void copyFromUnchecked(short[] d);
80     //void copyFromUnchecked(byte[] d);
81     //void copyFromUnchecked(float[] d);
82     //void copyFrom(int[] d);
83     //void copyFrom(short[] d);
84     //void copyFrom(byte[] d);
85     //void copyFrom(float[] d);
86     //void setFromFieldPacker(int xoff, FieldPacker fp);
87     //void setFromFieldPacker(int xoff, int component_number, FieldPacker fp);
88     void generateMipmaps();
89     void copy1DRangeFromUnchecked(uint32_t off, size_t count, const void *data, size_t dataLen);
90     void copy1DRangeFrom(uint32_t off, size_t count, const int32_t* d, size_t dataLen);
91     void copy1DRangeFrom(uint32_t off, size_t count, const int16_t* d, size_t dataLen);
92     void copy1DRangeFrom(uint32_t off, size_t count, const int8_t* d, size_t dataLen);
93     void copy1DRangeFrom(uint32_t off, size_t count, const float* d, size_t dataLen);
94     void copy1DRangeFrom(uint32_t off, size_t count, const Allocation *data, uint32_t dataOff);
95 
96     void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
97                          const int32_t *data, size_t dataLen);
98     void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
99                          const int16_t *data, size_t dataLen);
100     void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
101                          const int8_t *data, size_t dataLen);
102     void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
103                          const float *data, size_t dataLen);
104     void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
105                          const Allocation *data, size_t dataLen,
106                          uint32_t dataXoff, uint32_t dataYoff);
107 
108     //void copyTo(byte[] d);
109     //void copyTo(short[] d);
110     //void copyTo(int[] d);
111     //void copyTo(float[] d);
112     void resize(int dimX);
113     void resize(int dimX, int dimY);
114 
115     static sp<Allocation> createTyped(RenderScript *rs, sp<const Type> type,
116                                    RsAllocationMipmapControl mips, uint32_t usage);
117     static sp<Allocation> createTyped(RenderScript *rs, sp<const Type> type,
118                                    RsAllocationMipmapControl mips, uint32_t usage, void * pointer);
119 
120     static sp<Allocation> createTyped(RenderScript *rs, sp<const Type> type,
121                                    uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
122     static sp<Allocation> createSized(RenderScript *rs, sp<const Element> e, size_t count,
123                                    uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
124     //SurfaceTexture *getSurfaceTexture();
125     //void setSurfaceTexture(SurfaceTexture *sur);
126 
127 };
128 
129 }
130 }
131 
132 #endif
133