michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef GrGeometryBuffer_DEFINED michael@0: #define GrGeometryBuffer_DEFINED michael@0: michael@0: #include "GrResource.h" michael@0: michael@0: class GrGpu; michael@0: michael@0: /** michael@0: * Parent class for vertex and index buffers michael@0: */ michael@0: class GrGeometryBuffer : public GrResource { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(GrGeometryBuffer); michael@0: michael@0: /** michael@0: *Retrieves whether the buffer was created with the dynamic flag michael@0: * michael@0: * @return true if the buffer was created with the dynamic flag michael@0: */ michael@0: bool dynamic() const { return fDynamic; } michael@0: michael@0: /** michael@0: * Returns true if the buffer is a wrapper around a CPU array. If true it michael@0: * indicates that lock will always succeed and will be free. michael@0: */ michael@0: bool isCPUBacked() const { return fCPUBacked; } michael@0: michael@0: /** michael@0: * Locks the buffer to be written by the CPU. michael@0: * michael@0: * The previous content of the buffer is invalidated. It is an error michael@0: * to draw from the buffer while it is locked. It is an error to call lock michael@0: * on an already locked buffer. It may fail if the backend doesn't support michael@0: * locking the buffer. If the buffer is CPU backed then it will always michael@0: * succeed and is a free operation. Must be matched by an unlock() call. michael@0: * Currently only one lock at a time is supported (no nesting of michael@0: * lock/unlock). michael@0: * michael@0: * @return a pointer to the data or NULL if the lock fails. michael@0: */ michael@0: virtual void* lock() = 0; michael@0: michael@0: /** michael@0: * Returns the same ptr that lock() returned at time of lock or NULL if the michael@0: * is not locked. michael@0: * michael@0: * @return ptr to locked buffer data or undefined if buffer is not locked. michael@0: */ michael@0: virtual void* lockPtr() const = 0; michael@0: michael@0: /** michael@0: * Unlocks the buffer. michael@0: * michael@0: * The pointer returned by the previous lock call will no longer be valid. michael@0: */ michael@0: virtual void unlock() = 0; michael@0: michael@0: /** michael@0: Queries whether the buffer has been locked. michael@0: michael@0: @return true if the buffer is locked, false otherwise. michael@0: */ michael@0: virtual bool isLocked() const = 0; michael@0: michael@0: /** michael@0: * Updates the buffer data. michael@0: * michael@0: * The size of the buffer will be preserved. The src data will be michael@0: * placed at the beginning of the buffer and any remaining contents will michael@0: * be undefined. michael@0: * michael@0: * @return returns true if the update succeeds, false otherwise. michael@0: */ michael@0: virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0; michael@0: michael@0: // GrResource overrides michael@0: virtual size_t sizeInBytes() const { return fSizeInBytes; } michael@0: michael@0: protected: michael@0: GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t sizeInBytes, bool dynamic, bool cpuBacked) michael@0: : INHERITED(gpu, isWrapped) michael@0: , fSizeInBytes(sizeInBytes) michael@0: , fDynamic(dynamic) michael@0: , fCPUBacked(cpuBacked) {} michael@0: michael@0: private: michael@0: size_t fSizeInBytes; michael@0: bool fDynamic; michael@0: bool fCPUBacked; michael@0: michael@0: typedef GrResource INHERITED; michael@0: }; michael@0: michael@0: #endif