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