28 #ifndef __HardwareBuffer__
29 #define __HardwareBuffer__
107 HBU_STATIC_WRITE_ONLY = 5,
113 HBU_DYNAMIC_WRITE_ONLY = 6,
115 HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE = 14
152 virtual void* lockImpl(
size_t offset,
size_t length,
LockOptions options) = 0;
154 virtual void unlockImpl(
void) = 0;
159 : mUsage(usage), mIsLocked(false), mSystemMemory(systemMemory),
160 mUseShadowBuffer(useShadowBuffer), mpShadowBuffer(NULL), mShadowUpdated(false),
161 mSuppressHardwareUpdate(false)
164 if (useShadowBuffer && usage == HBU_DYNAMIC)
166 mUsage = HBU_DYNAMIC_WRITE_ONLY;
168 else if (useShadowBuffer && usage == HBU_STATIC)
170 mUsage = HBU_STATIC_WRITE_ONLY;
182 assert(!isLocked() &&
"Cannot lock this buffer, it is already locked!");
184 if (mUseShadowBuffer)
186 if (options != HBL_READ_ONLY)
190 mShadowUpdated =
true;
193 ret = mpShadowBuffer->lock(offset, length, options);
198 ret = lockImpl(offset, length, options);
212 return this->lock(0, mSizeInBytes, options);
228 assert(isLocked() &&
"Cannot unlock this buffer, it is not locked!");
231 if (mUseShadowBuffer && mpShadowBuffer->isLocked())
233 mpShadowBuffer->unlock();
252 virtual void readData(
size_t offset,
size_t length,
void* pDest) = 0;
261 virtual void writeData(
size_t offset,
size_t length,
const void* pSource,
262 bool discardWholeBuffer =
false) = 0;
275 size_t dstOffset,
size_t length,
bool discardWholeBuffer =
false)
277 const void *srcData = srcBuffer.
lock(
278 srcOffset, length, HBL_READ_ONLY);
279 this->writeData(dstOffset, length, srcData, discardWholeBuffer);
290 size_t sz = std::min(getSizeInBytes(), srcBuffer.
getSizeInBytes());
291 copyData(srcBuffer, 0, 0, sz,
true);
297 if (mUseShadowBuffer && mShadowUpdated && !mSuppressHardwareUpdate)
300 const void *srcData = mpShadowBuffer->lockImpl(
301 mLockStart, mLockSize, HBL_READ_ONLY);
304 if (mLockStart == 0 && mLockSize == mSizeInBytes)
305 lockOpt = HBL_DISCARD;
307 lockOpt = HBL_NORMAL;
309 void *destData = this->lockImpl(
310 mLockStart, mLockSize, lockOpt);
312 memcpy(destData, srcData, mLockSize);
314 mpShadowBuffer->unlockImpl();
315 mShadowUpdated =
false;
329 return mIsLocked || (mUseShadowBuffer && mpShadowBuffer->isLocked());
333 mSuppressHardwareUpdate = suppress;
size_t getSizeInBytes(void) const
Returns the size of this buffer in bytes.
bool mSuppressHardwareUpdate
HardwareBuffer * mpShadowBuffer
virtual void * lock(size_t offset, size_t length, LockOptions options)
Lock the buffer for (potentially) reading / writing.
HardwareBuffer(Usage usage, bool systemMemory, bool useShadowBuffer)
Constructor, to be called by HardwareBufferManager only.
virtual void copyData(HardwareBuffer &srcBuffer, size_t srcOffset, size_t dstOffset, size_t length, bool discardWholeBuffer=false)
Copy data from another buffer into this one.
Discards the entire buffer while locking; this allows optimisation to be performed because synchronis...
void * lock(LockOptions options)
Lock the entire buffer for (potentially) reading / writing.
LockOptions
Locking options.
virtual ~HardwareBuffer()
Normal mode, ie allows read/write and contents are preserved.
bool isLocked(void) const
Returns whether or not this buffer is currently locked.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
void suppressHardwareUpdate(bool suppress)
Pass true to suppress hardware upload of shadow buffer changes.
bool hasShadowBuffer(void) const
Returns whether this buffer has a system memory shadow for quicker reading.
Usage
Enums describing buffer usage; not mutually exclusive.
Usage getUsage(void) const
Returns the Usage flags with which this buffer was created.
virtual void unlock(void)
Releases the lock on this buffer.
Lock the buffer for reading only.
virtual void copyData(HardwareBuffer &srcBuffer)
Copy all data from another buffer into this one.
Abstract class defining common features of hardware buffers.
bool isSystemMemory(void) const
Returns whether this buffer is held in system memory.
virtual void _updateFromShadow(void)
Updates the real buffer from the shadow buffer, if required.