| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef GrGeometryBuffer_DEFINED | 10 #ifndef GrGeometryBuffer_DEFINED |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 * Maps the buffer to be written by the CPU. | 38 * Maps the buffer to be written by the CPU. |
| 39 * | 39 * |
| 40 * The previous content of the buffer is invalidated. It is an error | 40 * The previous content of the buffer is invalidated. It is an error |
| 41 * to draw from the buffer while it is mapped. It is an error to call map | 41 * to draw from the buffer while it is mapped. It is an error to call map |
| 42 * on an already mapped buffer. It may fail if the backend doesn't support | 42 * on an already mapped buffer. It may fail if the backend doesn't support |
| 43 * mapping the buffer. If the buffer is CPU backed then it will always | 43 * mapping the buffer. If the buffer is CPU backed then it will always |
| 44 * succeed and is a free operation. Must be matched by an unmap() call. | 44 * succeed and is a free operation. Must be matched by an unmap() call. |
| 45 * Currently only one map at a time is supported (no nesting of | 45 * Currently only one map at a time is supported (no nesting of |
| 46 * map/unmap). | 46 * map/unmap). |
| 47 * | 47 * |
| 48 * Note that buffer mapping does not go through GrContext and therefore is |
| 49 * not serialized with other operations. |
| 50 * |
| 48 * @return a pointer to the data or NULL if the map fails. | 51 * @return a pointer to the data or NULL if the map fails. |
| 49 */ | 52 */ |
| 50 virtual void* map() = 0; | 53 void* map() { return (fMapPtr = this->onMap()); } |
| 51 | |
| 52 /** | |
| 53 * Returns the same ptr that map() returned at time of map or NULL if the | |
| 54 * is not mapped. | |
| 55 * | |
| 56 * @return ptr to mapped buffer data or undefined if buffer is not mapped. | |
| 57 */ | |
| 58 virtual void* mapPtr() const = 0; | |
| 59 | 54 |
| 60 /** | 55 /** |
| 61 * Unmaps the buffer. | 56 * Unmaps the buffer. |
| 62 * | 57 * |
| 63 * The pointer returned by the previous map call will no longer be valid. | 58 * The pointer returned by the previous map call will no longer be valid. |
| 64 */ | 59 */ |
| 65 virtual void unmap() = 0; | 60 void unmap() { |
| 61 SkASSERT(NULL != fMapPtr); |
| 62 this->onUnmap(); |
| 63 fMapPtr = NULL; |
| 64 } |
| 65 |
| 66 /** |
| 67 * Returns the same ptr that map() returned at time of map or NULL if the |
| 68 * is not mapped. |
| 69 * |
| 70 * @return ptr to mapped buffer data or NULL if buffer is not mapped. |
| 71 */ |
| 72 void* mapPtr() const { return fMapPtr; } |
| 66 | 73 |
| 67 /** | 74 /** |
| 68 Queries whether the buffer has been mapped. | 75 Queries whether the buffer has been mapped. |
| 69 | 76 |
| 70 @return true if the buffer is mapped, false otherwise. | 77 @return true if the buffer is mapped, false otherwise. |
| 71 */ | 78 */ |
| 72 virtual bool isMapped() const = 0; | 79 bool isMapped() const { return NULL != fMapPtr; } |
| 73 | 80 |
| 74 /** | 81 /** |
| 75 * Updates the buffer data. | 82 * Updates the buffer data. |
| 76 * | 83 * |
| 77 * The size of the buffer will be preserved. The src data will be | 84 * The size of the buffer will be preserved. The src data will be |
| 78 * placed at the beginning of the buffer and any remaining contents will | 85 * placed at the beginning of the buffer and any remaining contents will |
| 79 * be undefined. | 86 * be undefined. srcSizeInBytes must be <= to the buffer size. |
| 87 * |
| 88 * The buffer must not be mapped. |
| 89 * |
| 90 * Note that buffer updates do not go through GrContext and therefore are |
| 91 * not serialized with other operations. |
| 80 * | 92 * |
| 81 * @return returns true if the update succeeds, false otherwise. | 93 * @return returns true if the update succeeds, false otherwise. |
| 82 */ | 94 */ |
| 83 virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0; | 95 bool updateData(const void* src, size_t srcSizeInBytes) { |
| 96 SkASSERT(!this->isMapped()); |
| 97 SkASSERT(srcSizeInBytes <= fGpuMemorySize); |
| 98 return this->onUpdateData(src, srcSizeInBytes); |
| 99 } |
| 84 | 100 |
| 85 // GrGpuObject overrides | 101 // GrGpuObject overrides |
| 86 virtual size_t gpuMemorySize() const { return fGpuMemorySize; } | 102 virtual size_t gpuMemorySize() const { return fGpuMemorySize; } |
| 87 | 103 |
| 88 protected: | 104 protected: |
| 89 GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t gpuMemorySize, bool dyna
mic, bool cpuBacked) | 105 GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t gpuMemorySize, bool dyna
mic, bool cpuBacked) |
| 90 : INHERITED(gpu, isWrapped) | 106 : INHERITED(gpu, isWrapped) |
| 107 , fMapPtr(NULL) |
| 91 , fGpuMemorySize(gpuMemorySize) | 108 , fGpuMemorySize(gpuMemorySize) |
| 92 , fDynamic(dynamic) | 109 , fDynamic(dynamic) |
| 93 , fCPUBacked(cpuBacked) {} | 110 , fCPUBacked(cpuBacked) {} |
| 94 | 111 |
| 95 private: | 112 private: |
| 113 virtual void* onMap() = 0; |
| 114 virtual void onUnmap() = 0; |
| 115 virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0; |
| 116 |
| 117 void* fMapPtr; |
| 96 size_t fGpuMemorySize; | 118 size_t fGpuMemorySize; |
| 97 bool fDynamic; | 119 bool fDynamic; |
| 98 bool fCPUBacked; | 120 bool fCPUBacked; |
| 99 | 121 |
| 100 typedef GrGpuObject INHERITED; | 122 typedef GrGpuObject INHERITED; |
| 101 }; | 123 }; |
| 102 | 124 |
| 103 #endif | 125 #endif |
| OLD | NEW |