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 30 matching lines...) Expand all Loading... |
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 | 48 * Note that buffer mapping does not go through GrContext and therefore is |
49 * not serialized with other operations. | 49 * not serialized with other operations. |
50 * | 50 * |
51 * @return a pointer to the data or NULL if the map fails. | 51 * @return a pointer to the data or nullptr if the map fails. |
52 */ | 52 */ |
53 void* map() { return (fMapPtr = this->onMap()); } | 53 void* map() { return (fMapPtr = this->onMap()); } |
54 | 54 |
55 /** | 55 /** |
56 * Unmaps the buffer. | 56 * Unmaps the buffer. |
57 * | 57 * |
58 * 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. |
59 */ | 59 */ |
60 void unmap() { | 60 void unmap() { |
61 SkASSERT(fMapPtr); | 61 SkASSERT(fMapPtr); |
62 this->onUnmap(); | 62 this->onUnmap(); |
63 fMapPtr = NULL; | 63 fMapPtr = nullptr; |
64 } | 64 } |
65 | 65 |
66 /** | 66 /** |
67 * Returns the same ptr that map() returned at time of map or NULL if the | 67 * Returns the same ptr that map() returned at time of map or nullptr if the |
68 * is not mapped. | 68 * is not mapped. |
69 * | 69 * |
70 * @return ptr to mapped buffer data or NULL if buffer is not mapped. | 70 * @return ptr to mapped buffer data or nullptr if buffer is not mapped. |
71 */ | 71 */ |
72 void* mapPtr() const { return fMapPtr; } | 72 void* mapPtr() const { return fMapPtr; } |
73 | 73 |
74 /** | 74 /** |
75 Queries whether the buffer has been mapped. | 75 Queries whether the buffer has been mapped. |
76 | 76 |
77 @return true if the buffer is mapped, false otherwise. | 77 @return true if the buffer is mapped, false otherwise. |
78 */ | 78 */ |
79 bool isMapped() const { return SkToBool(fMapPtr); } | 79 bool isMapped() const { return SkToBool(fMapPtr); } |
80 | 80 |
(...skipping 13 matching lines...) Expand all Loading... |
94 */ | 94 */ |
95 bool updateData(const void* src, size_t srcSizeInBytes) { | 95 bool updateData(const void* src, size_t srcSizeInBytes) { |
96 SkASSERT(!this->isMapped()); | 96 SkASSERT(!this->isMapped()); |
97 SkASSERT(srcSizeInBytes <= fGpuMemorySize); | 97 SkASSERT(srcSizeInBytes <= fGpuMemorySize); |
98 return this->onUpdateData(src, srcSizeInBytes); | 98 return this->onUpdateData(src, srcSizeInBytes); |
99 } | 99 } |
100 | 100 |
101 protected: | 101 protected: |
102 GrGeometryBuffer(GrGpu* gpu, size_t gpuMemorySize, bool dynamic, bool cpuBac
ked) | 102 GrGeometryBuffer(GrGpu* gpu, size_t gpuMemorySize, bool dynamic, bool cpuBac
ked) |
103 : INHERITED(gpu, kCached_LifeCycle) | 103 : INHERITED(gpu, kCached_LifeCycle) |
104 , fMapPtr(NULL) | 104 , fMapPtr(nullptr) |
105 , fGpuMemorySize(gpuMemorySize) | 105 , fGpuMemorySize(gpuMemorySize) |
106 , fDynamic(dynamic) | 106 , fDynamic(dynamic) |
107 , fCPUBacked(cpuBacked) {} | 107 , fCPUBacked(cpuBacked) {} |
108 | 108 |
109 private: | 109 private: |
110 virtual size_t onGpuMemorySize() const { return fGpuMemorySize; } | 110 virtual size_t onGpuMemorySize() const { return fGpuMemorySize; } |
111 | 111 |
112 virtual void* onMap() = 0; | 112 virtual void* onMap() = 0; |
113 virtual void onUnmap() = 0; | 113 virtual void onUnmap() = 0; |
114 virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0; | 114 virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0; |
115 | 115 |
116 void* fMapPtr; | 116 void* fMapPtr; |
117 size_t fGpuMemorySize; | 117 size_t fGpuMemorySize; |
118 bool fDynamic; | 118 bool fDynamic; |
119 bool fCPUBacked; | 119 bool fCPUBacked; |
120 | 120 |
121 typedef GrGpuResource INHERITED; | 121 typedef GrGpuResource INHERITED; |
122 }; | 122 }; |
123 | 123 |
124 #endif | 124 #endif |
OLD | NEW |