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 #include "GrGLBuffer.h" | 8 #include "GrGLBuffer.h" |
9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "SkTraceMemoryDump.h" | 10 #include "SkTraceMemoryDump.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 89 } |
90 | 90 |
91 GrGLBuffer::GrGLBuffer(GrGLGpu* gpu, size_t size, GrBufferType intendedType, | 91 GrGLBuffer::GrGLBuffer(GrGLGpu* gpu, size_t size, GrBufferType intendedType, |
92 GrAccessPattern accessPattern, bool cpuBacked, const void
* data) | 92 GrAccessPattern accessPattern, bool cpuBacked, const void
* data) |
93 : INHERITED(gpu, size, intendedType, accessPattern, cpuBacked), | 93 : INHERITED(gpu, size, intendedType, accessPattern, cpuBacked), |
94 fCPUData(nullptr), | 94 fCPUData(nullptr), |
95 fIntendedType(intendedType), | 95 fIntendedType(intendedType), |
96 fBufferID(0), | 96 fBufferID(0), |
97 fSizeInBytes(size), | 97 fSizeInBytes(size), |
98 fUsage(gr_to_gl_access_pattern(intendedType, accessPattern)), | 98 fUsage(gr_to_gl_access_pattern(intendedType, accessPattern)), |
99 fGLSizeInBytes(0) { | 99 fGLSizeInBytes(0), |
| 100 fHasAttachedToTexture(false) { |
100 if (this->isCPUBacked()) { | 101 if (this->isCPUBacked()) { |
101 // Core profile uses vertex array objects, which disallow client side ar
rays. | 102 // Core profile uses vertex array objects, which disallow client side ar
rays. |
102 SkASSERT(!gpu->glCaps().isCoreProfile()); | 103 SkASSERT(!gpu->glCaps().isCoreProfile()); |
103 if (gpu->caps()->mustClearUploadedBufferData()) { | 104 if (gpu->caps()->mustClearUploadedBufferData()) { |
104 fCPUData = sk_calloc_throw(fSizeInBytes); | 105 fCPUData = sk_calloc_throw(fSizeInBytes); |
105 } else { | 106 } else { |
106 fCPUData = sk_malloc_flags(fSizeInBytes, SK_MALLOC_THROW); | 107 fCPUData = sk_malloc_flags(fSizeInBytes, SK_MALLOC_THROW); |
107 } | 108 } |
108 if (data) { | 109 if (data) { |
109 memcpy(fCPUData, data, fSizeInBytes); | 110 memcpy(fCPUData, data, fSizeInBytes); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 VALIDATE(); | 145 VALIDATE(); |
145 // make sure we've not been abandoned or already released | 146 // make sure we've not been abandoned or already released |
146 if (fCPUData) { | 147 if (fCPUData) { |
147 SkASSERT(!fBufferID); | 148 SkASSERT(!fBufferID); |
148 sk_free(fCPUData); | 149 sk_free(fCPUData); |
149 fCPUData = nullptr; | 150 fCPUData = nullptr; |
150 } else if (fBufferID) { | 151 } else if (fBufferID) { |
151 GL_CALL(DeleteBuffers(1, &fBufferID)); | 152 GL_CALL(DeleteBuffers(1, &fBufferID)); |
152 fBufferID = 0; | 153 fBufferID = 0; |
153 fGLSizeInBytes = 0; | 154 fGLSizeInBytes = 0; |
| 155 this->glGpu()->notifyBufferReleased(this); |
154 } | 156 } |
155 fMapPtr = nullptr; | 157 fMapPtr = nullptr; |
156 VALIDATE(); | 158 VALIDATE(); |
157 } | 159 } |
158 | 160 |
159 INHERITED::onRelease(); | 161 INHERITED::onRelease(); |
160 } | 162 } |
161 | 163 |
162 void GrGLBuffer::onAbandon() { | 164 void GrGLBuffer::onAbandon() { |
163 fBufferID = 0; | 165 fBufferID = 0; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 317 |
316 void GrGLBuffer::validate() const { | 318 void GrGLBuffer::validate() const { |
317 // The following assert isn't valid when the buffer has been abandoned: | 319 // The following assert isn't valid when the buffer has been abandoned: |
318 // SkASSERT((0 == fDesc.fID) == (fCPUData)); | 320 // SkASSERT((0 == fDesc.fID) == (fCPUData)); |
319 SkASSERT(0 != fBufferID || 0 == fGLSizeInBytes); | 321 SkASSERT(0 != fBufferID || 0 == fGLSizeInBytes); |
320 SkASSERT(nullptr == fMapPtr || fCPUData || fGLSizeInBytes <= fSizeInBytes); | 322 SkASSERT(nullptr == fMapPtr || fCPUData || fGLSizeInBytes <= fSizeInBytes); |
321 SkASSERT(nullptr == fCPUData || nullptr == fMapPtr || fCPUData == fMapPtr); | 323 SkASSERT(nullptr == fCPUData || nullptr == fMapPtr || fCPUData == fMapPtr); |
322 } | 324 } |
323 | 325 |
324 #endif | 326 #endif |
OLD | NEW |