Chromium Code Reviews| Index: src/gpu/GrGeometryBuffer.h |
| diff --git a/src/gpu/GrGeometryBuffer.h b/src/gpu/GrGeometryBuffer.h |
| index 1e1a367260216d01fe94f74c783aabd7d6c60716..7ad00128f3a21e299f6b64f06f7ea5d1d568e871 100644 |
| --- a/src/gpu/GrGeometryBuffer.h |
| +++ b/src/gpu/GrGeometryBuffer.h |
| @@ -45,42 +45,58 @@ public: |
| * Currently only one map at a time is supported (no nesting of |
| * map/unmap). |
| * |
| + * Note that buffer mapping does not go through GrContext and therefore is |
| + * not serialized with other operations. |
| + * |
| * @return a pointer to the data or NULL if the map fails. |
| */ |
| - virtual void* map() = 0; |
| + void* map() { return (fMapPtr = this->onMap()); } |
| /** |
| - * Returns the same ptr that map() returned at time of map or NULL if the |
| - * is not mapped. |
| + * Unmaps the buffer. |
| * |
| - * @return ptr to mapped buffer data or undefined if buffer is not mapped. |
| + * The pointer returned by the previous map call will no longer be valid. |
| */ |
| - virtual void* mapPtr() const = 0; |
| + void unmap() { |
|
robertphillips
2014/05/08 15:25:46
== -> != ?
bsalomon
2014/05/08 17:02:48
duh, done.
|
| + SkASSERT(NULL == fMapPtr); |
| + this->onUnmap(); |
| + fMapPtr = NULL; |
| + } |
| /** |
| - * Unmaps the buffer. |
| + * Returns the same ptr that map() returned at time of map or NULL if the |
| + * is not mapped. |
| * |
| - * The pointer returned by the previous map call will no longer be valid. |
| + * @return ptr to mapped buffer data or NULL if buffer is not mapped. |
| */ |
| - virtual void unmap() = 0; |
| + void* mapPtr() const { return fMapPtr; } |
| /** |
| Queries whether the buffer has been mapped. |
| @return true if the buffer is mapped, false otherwise. |
| */ |
| - virtual bool isMapped() const = 0; |
| + bool isMapped() const { return NULL != fMapPtr; } |
| /** |
| * Updates the buffer data. |
| * |
| * The size of the buffer will be preserved. The src data will be |
| * placed at the beginning of the buffer and any remaining contents will |
| - * be undefined. |
| + * be undefined. srcSizeInBytes must be <= to the buffer size. |
| + * |
| + * The buffer must not be mapped. |
| + * |
| + * Note that buffer updates do not go through GrContext and therefore are |
| + * not serialized with other operations. |
| * |
| * @return returns true if the update succeeds, false otherwise. |
| */ |
| - virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0; |
| + bool updateData(const void* src, size_t srcSizeInBytes) { |
| + SkASSERT(!this->isMapped()); |
| + SkASSERT(srcSizeInBytes <= fGpuMemorySize); |
| + return this->onUpdateData(src, srcSizeInBytes); |
| + } |
| // GrGpuObject overrides |
| virtual size_t gpuMemorySize() const { return fGpuMemorySize; } |
| @@ -88,11 +104,17 @@ public: |
| protected: |
| GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t gpuMemorySize, bool dynamic, bool cpuBacked) |
| : INHERITED(gpu, isWrapped) |
| + , fMapPtr(NULL) |
| , fGpuMemorySize(gpuMemorySize) |
| , fDynamic(dynamic) |
| , fCPUBacked(cpuBacked) {} |
| private: |
| + virtual void* onMap() = 0; |
| + virtual void onUnmap() = 0; |
| + virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0; |
| + |
| + void* fMapPtr; |
| size_t fGpuMemorySize; |
| bool fDynamic; |
| bool fCPUBacked; |