blob: 7a893f815d2d354767d4bc5030d1049d885f3edf [file] [log] [blame]
Jason Sams221a4b12012-02-22 15:22:41 -08001/*
Jason Sams69cccdf2012-04-02 19:11:49 -07002 * Copyright (C) 2012 The Android Open Source Project
Jason Sams221a4b12012-02-22 15:22:41 -08003 *
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
Jason Samsb2e3dc52012-02-23 17:14:39 -080017#ifndef __ANDROID_ALLOCATION_H__
18#define __ANDROID_ALLOCATION_H__
Jason Sams221a4b12012-02-22 15:22:41 -080019
20#include <pthread.h>
21#include <rs.h>
22
23#include "RenderScript.h"
24#include "Type.h"
25#include "Element.h"
26
Jason Sams69cccdf2012-04-02 19:11:49 -070027namespace android {
28namespace renderscriptCpp {
29
Jason Samsb2e3dc52012-02-23 17:14:39 -080030class Allocation : public BaseObj {
Jason Sams221a4b12012-02-22 15:22:41 -080031protected:
Jason Sams69cccdf2012-04-02 19:11:49 -070032 android::sp<const Type> mType;
Jason Sams221a4b12012-02-22 15:22:41 -080033 uint32_t mUsage;
Jason Sams69cccdf2012-04-02 19:11:49 -070034 android::sp<Allocation> mAdaptedAllocation;
Jason Sams221a4b12012-02-22 15:22:41 -080035
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;
Jason Sams69cccdf2012-04-02 19:11:49 -070054 void updateCacheInfo(sp<const Type> t);
Jason Sams221a4b12012-02-22 15:22:41 -080055
Jason Sams69cccdf2012-04-02 19:11:49 -070056 Allocation(void *id, RenderScript *rs, sp<const Type> t, uint32_t usage);
Jason Sams221a4b12012-02-22 15:22:41 -080057
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
68public:
Jason Sams69cccdf2012-04-02 19:11:49 -070069 android::sp<const Type> getType() {
Jason Sams221a4b12012-02-22 15:22:41 -080070 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
Jason Sams69cccdf2012-04-02 19:11:49 -0700115 static sp<Allocation> createTyped(RenderScript *rs, sp<const Type> type,
Jason Sams221a4b12012-02-22 15:22:41 -0800116 RsAllocationMipmapControl mips, uint32_t usage);
Jason Sams69cccdf2012-04-02 19:11:49 -0700117 static sp<Allocation> createTyped(RenderScript *rs, sp<const Type> type,
Jason Sams221a4b12012-02-22 15:22:41 -0800118 RsAllocationMipmapControl mips, uint32_t usage, void * pointer);
119
Jason Sams69cccdf2012-04-02 19:11:49 -0700120 static sp<Allocation> createTyped(RenderScript *rs, sp<const Type> type,
Jason Sams221a4b12012-02-22 15:22:41 -0800121 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Jason Sams69cccdf2012-04-02 19:11:49 -0700122 static sp<Allocation> createSized(RenderScript *rs, sp<const Element> e, size_t count,
Jason Sams221a4b12012-02-22 15:22:41 -0800123 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
124 //SurfaceTexture *getSurfaceTexture();
125 //void setSurfaceTexture(SurfaceTexture *sur);
126
127};
128
Jason Sams69cccdf2012-04-02 19:11:49 -0700129}
130}
131
Jason Samsb2e3dc52012-02-23 17:14:39 -0800132#endif