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