1 /* 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 // --------------------------------------------------------------------------- 23 namespace android { 24 namespace renderscript { 25 26 27 28 class Allocation : public ObjectBase 29 { 30 // The graphics equilivent of malloc. The allocation contains a structure of elements. 31 32 33 public: 34 // By policy this allocation will hold a pointer to the type 35 // but will not destroy it on destruction. 36 Allocation(Context *rsc, const Type *); 37 virtual ~Allocation(); 38 39 void setCpuWritable(bool); 40 void setGpuWritable(bool); 41 void setCpuReadable(bool); 42 void setGpuReadable(bool); 43 44 bool fixAllocation(); 45 getPtr()46 void * getPtr() const {return mPtr;} getType()47 const Type * getType() const {return mType.get();} 48 49 void uploadToTexture(uint32_t lodOffset = 0); getTextureID()50 uint32_t getTextureID() const {return mTextureID;} 51 52 void uploadToBufferObject(); getBufferObjectID()53 uint32_t getBufferObjectID() const {return mBufferID;} 54 55 56 void data(const void *data, uint32_t sizeBytes); 57 void subData(uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes); 58 void subData(uint32_t xoff, uint32_t yoff, 59 uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes); 60 void subData(uint32_t xoff, uint32_t yoff, uint32_t zoff, 61 uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes); 62 63 void read(void *data); 64 65 void enableGLVertexBuffers() const; 66 void setupGLIndexBuffers() const; 67 68 69 protected: 70 ObjectBaseRef<const Type> mType; 71 void * mPtr; 72 73 // Usage restrictions 74 bool mCpuWrite; 75 bool mCpuRead; 76 bool mGpuWrite; 77 bool mGpuRead; 78 79 // more usage hint data from the application 80 // which can be used by a driver to pick the best memory type. 81 // Likely ignored for now 82 float mReadWriteRatio; 83 float mUpdateSize; 84 85 86 // Is this a legal structure to be used as a texture source. 87 // Initially this will require 1D or 2D and color data 88 bool mIsTexture; 89 uint32_t mTextureID; 90 91 // Is this a legal structure to be used as a vertex source. 92 // Initially this will require 1D and x(yzw). Additional per element data 93 // is allowed. 94 bool mIsVertexBuffer; 95 uint32_t mBufferID; 96 }; 97 98 } 99 } 100 #endif 101 102