blob: 490abcfbbe765a939c4c0c38b7f440cefd3a1b09 [file] [log] [blame]
Jason Samsd19f10d2009-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 Sams83f1c632009-10-26 15:19:28 -070026class Program;
Jason Samsd19f10d2009-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
32
33public:
34 // By policy this allocation will hold a pointer to the type
35 // but will not destroy it on destruction.
Jason Samsa9e7a052009-09-25 14:51:22 -070036 Allocation(Context *rsc, const Type *);
Jason Samsd19f10d2009-05-22 14:03:28 -070037 virtual ~Allocation();
38
39 void setCpuWritable(bool);
40 void setGpuWritable(bool);
41 void setCpuReadable(bool);
42 void setGpuReadable(bool);
43
44 bool fixAllocation();
45
46 void * getPtr() const {return mPtr;}
47 const Type * getType() const {return mType.get();}
48
Jason Sams9dab6672009-11-24 12:26:35 -080049 void uploadToTexture(Context *rsc, uint32_t lodOffset = 0);
Jason Samsd19f10d2009-05-22 14:03:28 -070050 uint32_t getTextureID() const {return mTextureID;}
51
52 void uploadToBufferObject();
53 uint32_t getBufferObjectID() const {return mBufferID;}
54
55
Jason Sams07ae4062009-08-27 20:23:34 -070056 void data(const void *data, uint32_t sizeBytes);
57 void subData(uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes);
Jason Sams1bada8c2009-08-09 17:01:55 -070058 void subData(uint32_t xoff, uint32_t yoff,
Jason Sams07ae4062009-08-27 20:23:34 -070059 uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -070060 void subData(uint32_t xoff, uint32_t yoff, uint32_t zoff,
Jason Sams07ae4062009-08-27 20:23:34 -070061 uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -070062
Jason Sams40a29e82009-08-10 14:55:26 -070063 void read(void *data);
64
Jason Sams1bada8c2009-08-09 17:01:55 -070065 void enableGLVertexBuffers() const;
66 void setupGLIndexBuffers() const;
67
Jason Sams83f1c632009-10-26 15:19:28 -070068 void addProgramToDirty(const Program *);
69 void removeProgramToDirty(const Program *);
Jason Sams1bada8c2009-08-09 17:01:55 -070070
Jason Sams715333b2009-11-17 17:26:46 -080071 virtual void dumpLOGV(const char *prefix) const;
72
Jason Samsd19f10d2009-05-22 14:03:28 -070073protected:
Jason Sams83f1c632009-10-26 15:19:28 -070074 void sendDirty() const;
75
Jason Samsd19f10d2009-05-22 14:03:28 -070076 ObjectBaseRef<const Type> mType;
77 void * mPtr;
78
Jason Sams83f1c632009-10-26 15:19:28 -070079 Vector<const Program *> mToDirtyList;
80
Jason Samsd19f10d2009-05-22 14:03:28 -070081 // Usage restrictions
82 bool mCpuWrite;
83 bool mCpuRead;
84 bool mGpuWrite;
85 bool mGpuRead;
86
87 // more usage hint data from the application
88 // which can be used by a driver to pick the best memory type.
89 // Likely ignored for now
90 float mReadWriteRatio;
91 float mUpdateSize;
92
93
94 // Is this a legal structure to be used as a texture source.
95 // Initially this will require 1D or 2D and color data
96 bool mIsTexture;
97 uint32_t mTextureID;
98
99 // Is this a legal structure to be used as a vertex source.
100 // Initially this will require 1D and x(yzw). Additional per element data
101 // is allowed.
102 bool mIsVertexBuffer;
103 uint32_t mBufferID;
Jason Samsd19f10d2009-05-22 14:03:28 -0700104};
105
106}
107}
108#endif
109