rsAllocation.h revision afb743aca56c18beb7ab924e75cb6e070ef3e55a
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// --------------------------------------------------------------------------- 23namespace android { 24namespace renderscript { 25 26class Program; 27 28class Allocation : public ObjectBase { 29 // The graphics equilivent of malloc. The allocation contains a structure of elements. 30 31public: 32 Allocation(Context *rsc, const Type *); 33 Allocation(Context *rsc, const Type *, void *bmp, void *callbackData, RsBitmapCallback_t callback); 34 35 virtual ~Allocation(); 36 37 void setCpuWritable(bool); 38 void setGpuWritable(bool); 39 void setCpuReadable(bool); 40 void setGpuReadable(bool); 41 42 bool fixAllocation(); 43 44 void * getPtr() const {return mPtr;} 45 const Type * getType() const {return mType.get();} 46 47 void deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset); 48 void uploadToTexture(const Context *rsc); 49 uint32_t getTextureID() const {return mTextureID;} 50 51 void deferedUploadToBufferObject(const Context *rsc); 52 void uploadToBufferObject(const Context *rsc); 53 uint32_t getBufferObjectID() const {return mBufferID;} 54 55 void copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len); 56 57 void resize1D(Context *rsc, uint32_t dimX); 58 void resize2D(Context *rsc, uint32_t dimX, uint32_t dimY); 59 60 void data(Context *rsc, const void *data, uint32_t sizeBytes); 61 void subData(Context *rsc, uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes); 62 void subData(Context *rsc, uint32_t xoff, uint32_t yoff, 63 uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes); 64 void subData(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, 65 uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes); 66 67 void subElementData(Context *rsc, uint32_t x, 68 const void *data, uint32_t elementOff, uint32_t sizeBytes); 69 void subElementData(Context *rsc, uint32_t x, uint32_t y, 70 const void *data, uint32_t elementOff, uint32_t sizeBytes); 71 72 void read(void *data); 73 74 void enableGLVertexBuffers() const; 75 void setupGLIndexBuffers() const; 76 77 void addProgramToDirty(const Program *); 78 void removeProgramToDirty(const Program *); 79 80 virtual void dumpLOGV(const char *prefix) const; 81 virtual void serialize(OStream *stream) const; 82 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ALLOCATION; } 83 static Allocation *createFromStream(Context *rsc, IStream *stream); 84 85 virtual void uploadCheck(const Context *rsc); 86 87 bool getIsTexture() const {return mIsTexture;} 88 bool getIsBufferObject() const {return mIsVertexBuffer;} 89 90 void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const; 91 void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const; 92 93 void sendDirty() const; 94 bool getHasGraphicsMipmaps() const {return mTextureGenMipmap;} 95 96protected: 97 ObjectBaseRef<const Type> mType; 98 void * mPtr; 99 100 Vector<const Program *> mToDirtyList; 101 102 // Is we have a non-null user bitmap callback we do not own the bits and 103 // instead call this function to free the memort when its time. 104 RsBitmapCallback_t mUserBitmapCallback; 105 void *mUserBitmapCallbackData; 106 107 // Usage restrictions 108 bool mCpuWrite; 109 bool mCpuRead; 110 bool mGpuWrite; 111 bool mGpuRead; 112 113 // more usage hint data from the application 114 // which can be used by a driver to pick the best memory type. 115 // Likely ignored for now 116 float mReadWriteRatio; 117 float mUpdateSize; 118 119 120 // Is this a legal structure to be used as a texture source. 121 // Initially this will require 1D or 2D and color data 122 bool mIsTexture; 123 bool mTextureGenMipmap; 124 uint32_t mTextureLOD; 125 uint32_t mTextureID; 126 127 // Is this a legal structure to be used as a vertex source. 128 // Initially this will require 1D and x(yzw). Additional per element data 129 // is allowed. 130 bool mIsVertexBuffer; 131 uint32_t mBufferID; 132 133 bool mUploadDefered; 134 135private: 136 void init(Context *rsc, const Type *); 137 138}; 139 140} 141} 142#endif 143 144