blob: 12cf832594383e0e1420ff416f8c3cba9a0857b0 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
2 * Copyright (C) 2009 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_STRUCTURED_ALLOCATION_H
18#define ANDROID_STRUCTURED_ALLOCATION_H
19
20#include "rsType.h"
21
22// ---------------------------------------------------------------------------
23namespace android {
24namespace renderscript {
25
Jason Sams5c3e3bc2009-10-26 15:19:28 -070026class Program;
Jason Sams326e0dd2009-05-22 14:03:28 -070027
28class Allocation : public ObjectBase
29{
30 // The graphics equilivent of malloc. The allocation contains a structure of elements.
31
Jason Sams326e0dd2009-05-22 14:03:28 -070032public:
Jason Samse514b452009-09-25 14:51:22 -070033 Allocation(Context *rsc, const Type *);
Jason Samsfa84da22010-03-01 15:31:04 -080034 Allocation(Context *rsc, const Type *, void *bmp, void *callbackData, RsBitmapCallback_t callback);
35
Jason Sams326e0dd2009-05-22 14:03:28 -070036 virtual ~Allocation();
37
38 void setCpuWritable(bool);
39 void setGpuWritable(bool);
40 void setCpuReadable(bool);
41 void setGpuReadable(bool);
42
43 bool fixAllocation();
44
45 void * getPtr() const {return mPtr;}
46 const Type * getType() const {return mType.get();}
47
Jason Sams7fabe1a2010-02-23 17:44:28 -080048 void deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset);
Jason Samscf4c7c92009-12-14 12:57:40 -080049 void uploadToTexture(const Context *rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -070050 uint32_t getTextureID() const {return mTextureID;}
51
Jason Samscf4c7c92009-12-14 12:57:40 -080052 void deferedUploadToBufferObject(const Context *rsc);
53 void uploadToBufferObject(const Context *rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -070054 uint32_t getBufferObjectID() const {return mBufferID;}
55
Jason Sams96abf812010-10-05 13:32:49 -070056 void copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len);
57
58 void resize1D(Context *rsc, uint32_t dimX);
59 void resize2D(Context *rsc, uint32_t dimX, uint32_t dimY);
Jason Sams326e0dd2009-05-22 14:03:28 -070060
Jason Sams5f0c84c2010-08-31 13:50:42 -070061 void data(Context *rsc, const void *data, uint32_t sizeBytes);
62 void subData(Context *rsc, uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes);
63 void subData(Context *rsc, uint32_t xoff, uint32_t yoff,
Jason Sams9397e302009-08-27 20:23:34 -070064 uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -070065 void subData(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
Jason Sams9397e302009-08-27 20:23:34 -070066 uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
Jason Sams326e0dd2009-05-22 14:03:28 -070067
Jason Sams5f0c84c2010-08-31 13:50:42 -070068 void subElementData(Context *rsc, uint32_t x,
69 const void *data, uint32_t elementOff, uint32_t sizeBytes);
70 void subElementData(Context *rsc, uint32_t x, uint32_t y,
71 const void *data, uint32_t elementOff, uint32_t sizeBytes);
72
Jason Samse579df42009-08-10 14:55:26 -070073 void read(void *data);
74
Jason Samse5ffb872009-08-09 17:01:55 -070075 void enableGLVertexBuffers() const;
76 void setupGLIndexBuffers() const;
77
Jason Sams5c3e3bc2009-10-26 15:19:28 -070078 void addProgramToDirty(const Program *);
79 void removeProgramToDirty(const Program *);
Jason Samse5ffb872009-08-09 17:01:55 -070080
Jason Samsc21cf402009-11-17 17:26:46 -080081 virtual void dumpLOGV(const char *prefix) const;
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070082 virtual void serialize(OStream *stream) const;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070083 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ALLOCATION; }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070084 static Allocation *createFromStream(Context *rsc, IStream *stream);
Jason Samsc21cf402009-11-17 17:26:46 -080085
Jason Samscf4c7c92009-12-14 12:57:40 -080086 virtual void uploadCheck(const Context *rsc);
87
Jason Sams760f1f72010-06-25 12:45:41 -070088 bool getIsTexture() const {return mIsTexture;}
89 bool getIsBufferObject() const {return mIsVertexBuffer;}
90
Jason Sams96abf812010-10-05 13:32:49 -070091 void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
92 void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
Jason Samse3929c92010-08-09 18:13:33 -070093
Jason Sams5c3e3bc2009-10-26 15:19:28 -070094 void sendDirty() const;
Jason Sams900f1612010-09-16 18:18:29 -070095 bool getHasGraphicsMipmaps() const {return mTextureGenMipmap;}
Jason Sams5c3e3bc2009-10-26 15:19:28 -070096
Alex Sakhartchouk1e5168d2010-09-01 16:34:48 -070097protected:
Jason Sams326e0dd2009-05-22 14:03:28 -070098 ObjectBaseRef<const Type> mType;
99 void * mPtr;
100
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700101 Vector<const Program *> mToDirtyList;
102
Jason Samsfa84da22010-03-01 15:31:04 -0800103 // Is we have a non-null user bitmap callback we do not own the bits and
104 // instead call this function to free the memort when its time.
105 RsBitmapCallback_t mUserBitmapCallback;
106 void *mUserBitmapCallbackData;
107
Jason Sams326e0dd2009-05-22 14:03:28 -0700108 // Usage restrictions
109 bool mCpuWrite;
110 bool mCpuRead;
111 bool mGpuWrite;
112 bool mGpuRead;
113
114 // more usage hint data from the application
115 // which can be used by a driver to pick the best memory type.
116 // Likely ignored for now
117 float mReadWriteRatio;
118 float mUpdateSize;
119
120
121 // Is this a legal structure to be used as a texture source.
122 // Initially this will require 1D or 2D and color data
123 bool mIsTexture;
Jason Sams7fabe1a2010-02-23 17:44:28 -0800124 bool mTextureGenMipmap;
Jason Samscf4c7c92009-12-14 12:57:40 -0800125 uint32_t mTextureLOD;
Jason Sams326e0dd2009-05-22 14:03:28 -0700126 uint32_t mTextureID;
127
128 // Is this a legal structure to be used as a vertex source.
129 // Initially this will require 1D and x(yzw). Additional per element data
130 // is allowed.
131 bool mIsVertexBuffer;
132 uint32_t mBufferID;
Jason Samscf4c7c92009-12-14 12:57:40 -0800133
134 bool mUploadDefered;
Jason Samsfa84da22010-03-01 15:31:04 -0800135
136private:
137 void init(Context *rsc, const Type *);
138
Jason Sams326e0dd2009-05-22 14:03:28 -0700139};
140
141}
142}
143#endif
144