Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 26 | class Program; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 27 | |
| 28 | class Allocation : public ObjectBase |
| 29 | { |
| 30 | // The graphics equilivent of malloc. The allocation contains a structure of elements. |
| 31 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | public: |
| 33 | // By policy this allocation will hold a pointer to the type |
| 34 | // but will not destroy it on destruction. |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 35 | Allocation(Context *rsc, const Type *); |
Jason Sams | fa84da2 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 36 | Allocation(Context *rsc, const Type *, void *bmp, void *callbackData, RsBitmapCallback_t callback); |
| 37 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 38 | 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 Sams | 7fabe1a | 2010-02-23 17:44:28 -0800 | [diff] [blame] | 50 | void deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset); |
Jason Sams | cf4c7c9 | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 51 | void uploadToTexture(const Context *rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 52 | uint32_t getTextureID() const {return mTextureID;} |
| 53 | |
Jason Sams | cf4c7c9 | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 54 | void deferedUploadToBufferObject(const Context *rsc); |
| 55 | void uploadToBufferObject(const Context *rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 56 | uint32_t getBufferObjectID() const {return mBufferID;} |
| 57 | |
| 58 | |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 59 | void data(const void *data, uint32_t sizeBytes); |
| 60 | void subData(uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes); |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 61 | void subData(uint32_t xoff, uint32_t yoff, |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 62 | uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 63 | void subData(uint32_t xoff, uint32_t yoff, uint32_t zoff, |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 64 | uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 65 | |
Jason Sams | e579df4 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 66 | void read(void *data); |
| 67 | |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 68 | void enableGLVertexBuffers() const; |
| 69 | void setupGLIndexBuffers() const; |
| 70 | |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 71 | void addProgramToDirty(const Program *); |
| 72 | void removeProgramToDirty(const Program *); |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 73 | |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 74 | virtual void dumpLOGV(const char *prefix) const; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 75 | virtual void serialize(OStream *stream) const; |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 76 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ALLOCATION; } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 77 | static Allocation *createFromStream(Context *rsc, IStream *stream); |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 78 | |
Jason Sams | cf4c7c9 | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 79 | virtual void uploadCheck(const Context *rsc); |
| 80 | |
Jason Sams | 760f1f7 | 2010-06-25 12:45:41 -0700 | [diff] [blame] | 81 | bool getIsTexture() const {return mIsTexture;} |
| 82 | bool getIsBufferObject() const {return mIsVertexBuffer;} |
| 83 | |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 84 | void incRefs(const void *ptr, size_t ct) const; |
| 85 | void decRefs(const void *ptr, size_t ct) const; |
| 86 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 87 | protected: |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 88 | void sendDirty() const; |
| 89 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 90 | ObjectBaseRef<const Type> mType; |
| 91 | void * mPtr; |
| 92 | |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 93 | Vector<const Program *> mToDirtyList; |
| 94 | |
Jason Sams | fa84da2 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 95 | // Is we have a non-null user bitmap callback we do not own the bits and |
| 96 | // instead call this function to free the memort when its time. |
| 97 | RsBitmapCallback_t mUserBitmapCallback; |
| 98 | void *mUserBitmapCallbackData; |
| 99 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 100 | // Usage restrictions |
| 101 | bool mCpuWrite; |
| 102 | bool mCpuRead; |
| 103 | bool mGpuWrite; |
| 104 | bool mGpuRead; |
| 105 | |
| 106 | // more usage hint data from the application |
| 107 | // which can be used by a driver to pick the best memory type. |
| 108 | // Likely ignored for now |
| 109 | float mReadWriteRatio; |
| 110 | float mUpdateSize; |
| 111 | |
| 112 | |
| 113 | // Is this a legal structure to be used as a texture source. |
| 114 | // Initially this will require 1D or 2D and color data |
| 115 | bool mIsTexture; |
Jason Sams | 7fabe1a | 2010-02-23 17:44:28 -0800 | [diff] [blame] | 116 | bool mTextureGenMipmap; |
Jason Sams | cf4c7c9 | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 117 | uint32_t mTextureLOD; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 118 | uint32_t mTextureID; |
| 119 | |
| 120 | // Is this a legal structure to be used as a vertex source. |
| 121 | // Initially this will require 1D and x(yzw). Additional per element data |
| 122 | // is allowed. |
| 123 | bool mIsVertexBuffer; |
| 124 | uint32_t mBufferID; |
Jason Sams | cf4c7c9 | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 125 | |
| 126 | bool mUploadDefered; |
Jason Sams | fa84da2 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 127 | |
| 128 | private: |
| 129 | void init(Context *rsc, const Type *); |
| 130 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | } |
| 134 | } |
| 135 | #endif |
| 136 | |