blob: 516f8b798208c8fe8856bbc6c047cb7bc1bc9b13 [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:
33 // By policy this allocation will hold a pointer to the type
34 // but will not destroy it on destruction.
Jason Samse514b452009-09-25 14:51:22 -070035 Allocation(Context *rsc, const Type *);
Jason Samsfa84da22010-03-01 15:31:04 -080036 Allocation(Context *rsc, const Type *, void *bmp, void *callbackData, RsBitmapCallback_t callback);
37
Jason Sams326e0dd2009-05-22 14:03:28 -070038 virtual ~Allocation();
39
40 void setCpuWritable(bool);
41 void setGpuWritable(bool);
42 void setCpuReadable(bool);
43 void setGpuReadable(bool);
44
45 bool fixAllocation();
46
47 void * getPtr() const {return mPtr;}
48 const Type * getType() const {return mType.get();}
49
Jason Sams7fabe1a2010-02-23 17:44:28 -080050 void deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset);
Jason Samscf4c7c92009-12-14 12:57:40 -080051 void uploadToTexture(const Context *rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -070052 uint32_t getTextureID() const {return mTextureID;}
53
Jason Samscf4c7c92009-12-14 12:57:40 -080054 void deferedUploadToBufferObject(const Context *rsc);
55 void uploadToBufferObject(const Context *rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -070056 uint32_t getBufferObjectID() const {return mBufferID;}
57
58
Jason Sams9397e302009-08-27 20:23:34 -070059 void data(const void *data, uint32_t sizeBytes);
60 void subData(uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes);
Jason Samse5ffb872009-08-09 17:01:55 -070061 void subData(uint32_t xoff, uint32_t yoff,
Jason Sams9397e302009-08-27 20:23:34 -070062 uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes);
Jason Sams326e0dd2009-05-22 14:03:28 -070063 void subData(uint32_t xoff, uint32_t yoff, uint32_t zoff,
Jason Sams9397e302009-08-27 20:23:34 -070064 uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
Jason Sams326e0dd2009-05-22 14:03:28 -070065
Jason Samse579df42009-08-10 14:55:26 -070066 void read(void *data);
67
Jason Samse5ffb872009-08-09 17:01:55 -070068 void enableGLVertexBuffers() const;
69 void setupGLIndexBuffers() const;
70
Jason Sams5c3e3bc2009-10-26 15:19:28 -070071 void addProgramToDirty(const Program *);
72 void removeProgramToDirty(const Program *);
Jason Samse5ffb872009-08-09 17:01:55 -070073
Jason Samsc21cf402009-11-17 17:26:46 -080074 virtual void dumpLOGV(const char *prefix) const;
75
Jason Samscf4c7c92009-12-14 12:57:40 -080076 virtual void uploadCheck(const Context *rsc);
77
Jason Sams326e0dd2009-05-22 14:03:28 -070078protected:
Jason Sams5c3e3bc2009-10-26 15:19:28 -070079 void sendDirty() const;
80
Jason Sams326e0dd2009-05-22 14:03:28 -070081 ObjectBaseRef<const Type> mType;
82 void * mPtr;
83
Jason Sams5c3e3bc2009-10-26 15:19:28 -070084 Vector<const Program *> mToDirtyList;
85
Jason Samsfa84da22010-03-01 15:31:04 -080086 // Is we have a non-null user bitmap callback we do not own the bits and
87 // instead call this function to free the memort when its time.
88 RsBitmapCallback_t mUserBitmapCallback;
89 void *mUserBitmapCallbackData;
90
Jason Sams326e0dd2009-05-22 14:03:28 -070091 // Usage restrictions
92 bool mCpuWrite;
93 bool mCpuRead;
94 bool mGpuWrite;
95 bool mGpuRead;
96
97 // more usage hint data from the application
98 // which can be used by a driver to pick the best memory type.
99 // Likely ignored for now
100 float mReadWriteRatio;
101 float mUpdateSize;
102
103
104 // Is this a legal structure to be used as a texture source.
105 // Initially this will require 1D or 2D and color data
106 bool mIsTexture;
Jason Sams7fabe1a2010-02-23 17:44:28 -0800107 bool mTextureGenMipmap;
Jason Samscf4c7c92009-12-14 12:57:40 -0800108 uint32_t mTextureLOD;
Jason Sams326e0dd2009-05-22 14:03:28 -0700109 uint32_t mTextureID;
110
111 // Is this a legal structure to be used as a vertex source.
112 // Initially this will require 1D and x(yzw). Additional per element data
113 // is allowed.
114 bool mIsVertexBuffer;
115 uint32_t mBufferID;
Jason Samscf4c7c92009-12-14 12:57:40 -0800116
117 bool mUploadDefered;
Jason Samsfa84da22010-03-01 15:31:04 -0800118
119private:
120 void init(Context *rsc, const Type *);
121
Jason Sams326e0dd2009-05-22 14:03:28 -0700122};
123
124}
125}
126#endif
127