Jason Sams | d19f10d | 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 | 83f1c63 | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 26 | class Program; |
Jason Sams | d19f10d | 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 | |
| 32 | |
| 33 | public: |
| 34 | // By policy this allocation will hold a pointer to the type |
| 35 | // but will not destroy it on destruction. |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 36 | Allocation(Context *rsc, const Type *); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
| 46 | void * getPtr() const {return mPtr;} |
| 47 | const Type * getType() const {return mType.get();} |
| 48 | |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 49 | void deferedUploadToTexture(const Context *rsc, uint32_t lodOffset); |
| 50 | void uploadToTexture(const Context *rsc); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 51 | uint32_t getTextureID() const {return mTextureID;} |
| 52 | |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 53 | void deferedUploadToBufferObject(const Context *rsc); |
| 54 | void uploadToBufferObject(const Context *rsc); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 55 | uint32_t getBufferObjectID() const {return mBufferID;} |
| 56 | |
| 57 | |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 58 | void data(const void *data, uint32_t sizeBytes); |
| 59 | void subData(uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 60 | void subData(uint32_t xoff, uint32_t yoff, |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 61 | uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 62 | void subData(uint32_t xoff, uint32_t yoff, uint32_t zoff, |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 63 | uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 64 | |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 65 | void read(void *data); |
| 66 | |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 67 | void enableGLVertexBuffers() const; |
| 68 | void setupGLIndexBuffers() const; |
| 69 | |
Jason Sams | 83f1c63 | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 70 | void addProgramToDirty(const Program *); |
| 71 | void removeProgramToDirty(const Program *); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 72 | |
Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 73 | virtual void dumpLOGV(const char *prefix) const; |
| 74 | |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 75 | virtual void uploadCheck(const Context *rsc); |
| 76 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 77 | protected: |
Jason Sams | 83f1c63 | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 78 | void sendDirty() const; |
| 79 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 80 | ObjectBaseRef<const Type> mType; |
| 81 | void * mPtr; |
| 82 | |
Jason Sams | 83f1c63 | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 83 | Vector<const Program *> mToDirtyList; |
| 84 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 85 | // Usage restrictions |
| 86 | bool mCpuWrite; |
| 87 | bool mCpuRead; |
| 88 | bool mGpuWrite; |
| 89 | bool mGpuRead; |
| 90 | |
| 91 | // more usage hint data from the application |
| 92 | // which can be used by a driver to pick the best memory type. |
| 93 | // Likely ignored for now |
| 94 | float mReadWriteRatio; |
| 95 | float mUpdateSize; |
| 96 | |
| 97 | |
| 98 | // Is this a legal structure to be used as a texture source. |
| 99 | // Initially this will require 1D or 2D and color data |
| 100 | bool mIsTexture; |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 101 | uint32_t mTextureLOD; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 102 | uint32_t mTextureID; |
| 103 | |
| 104 | // Is this a legal structure to be used as a vertex source. |
| 105 | // Initially this will require 1D and x(yzw). Additional per element data |
| 106 | // is allowed. |
| 107 | bool mIsVertexBuffer; |
| 108 | uint32_t mBufferID; |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 109 | |
| 110 | bool mUploadDefered; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | } |
| 114 | } |
| 115 | #endif |
| 116 | |