OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrBuffer_DEFINED | 8 #ifndef GrBuffer_DEFINED |
9 #define GrBuffer_DEFINED | 9 #define GrBuffer_DEFINED |
10 | 10 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 */ | 103 */ |
104 bool updateData(const void* src, size_t srcSizeInBytes) { | 104 bool updateData(const void* src, size_t srcSizeInBytes) { |
105 SkASSERT(!this->isMapped()); | 105 SkASSERT(!this->isMapped()); |
106 SkASSERT(srcSizeInBytes <= fGpuMemorySize); | 106 SkASSERT(srcSizeInBytes <= fGpuMemorySize); |
107 return this->onUpdateData(src, srcSizeInBytes); | 107 return this->onUpdateData(src, srcSizeInBytes); |
108 } | 108 } |
109 | 109 |
110 protected: | 110 protected: |
111 GrBuffer(GrGpu* gpu, size_t gpuMemorySize, GrBufferType intendedType, | 111 GrBuffer(GrGpu* gpu, size_t gpuMemorySize, GrBufferType intendedType, |
112 GrAccessPattern accessPattern, bool cpuBacked) | 112 GrAccessPattern accessPattern, bool cpuBacked) |
113 : INHERITED(gpu, kCached_LifeCycle), | 113 : INHERITED(gpu), |
114 fMapPtr(nullptr), | 114 fMapPtr(nullptr), |
115 fGpuMemorySize(gpuMemorySize), // TODO: Zero for cpu backed buffers? | 115 fGpuMemorySize(gpuMemorySize), // TODO: Zero for cpu backed buffers? |
116 fAccessPattern(accessPattern), | 116 fAccessPattern(accessPattern), |
117 fCPUBacked(cpuBacked) { | 117 fCPUBacked(cpuBacked), |
| 118 fIntendedType(intendedType) { |
| 119 } |
| 120 |
| 121 void computeScratchKey(GrScratchKey* key) const override { |
118 if (!fCPUBacked && SkIsPow2(fGpuMemorySize) && kDynamic_GrAccessPattern
== fAccessPattern) { | 122 if (!fCPUBacked && SkIsPow2(fGpuMemorySize) && kDynamic_GrAccessPattern
== fAccessPattern) { |
119 GrScratchKey key; | 123 ComputeScratchKeyForDynamicBuffer(fGpuMemorySize, fIntendedType, key
); |
120 ComputeScratchKeyForDynamicBuffer(fGpuMemorySize, intendedType, &key
); | |
121 this->setScratchKey(key); | |
122 } | 124 } |
123 } | 125 } |
124 | 126 |
125 void* fMapPtr; | 127 void* fMapPtr; |
126 | 128 |
127 private: | 129 private: |
128 virtual size_t onGpuMemorySize() const { return fGpuMemorySize; } | 130 size_t onGpuMemorySize() const override { return fGpuMemorySize; } |
129 | 131 |
130 virtual void onMap() = 0; | 132 virtual void onMap() = 0; |
131 virtual void onUnmap() = 0; | 133 virtual void onUnmap() = 0; |
132 virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0; | 134 virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0; |
133 | 135 |
134 size_t fGpuMemorySize; | 136 size_t fGpuMemorySize; |
135 GrAccessPattern fAccessPattern; | 137 GrAccessPattern fAccessPattern; |
136 bool fCPUBacked; | 138 bool fCPUBacked; |
137 | 139 GrBufferType fIntendedType; |
138 typedef GrGpuResource INHERITED; | 140 typedef GrGpuResource INHERITED; |
139 }; | 141 }; |
140 | 142 |
141 #endif | 143 #endif |
OLD | NEW |