OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrGLBufferImpl.h" | 8 #include "GrGLBufferImpl.h" |
9 #include "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
10 | 10 |
11 #define GL_CALL(GPU, X) GR_GL_CALL(GPU->glInterface(), X) | 11 #define GL_CALL(GPU, X) GR_GL_CALL(GPU->glInterface(), X) |
12 | 12 |
13 #if GR_DEBUG | 13 #if GR_DEBUG |
14 #define VALIDATE() this->validate() | 14 #define VALIDATE() this->validate() |
15 #else | 15 #else |
16 #define VALIDATE() do {} while(false) | 16 #define VALIDATE() do {} while(false) |
17 #endif | 17 #endif |
18 | 18 |
robertphillips
2013/03/13 15:20:54
GR_?
Comment as to why we even have this #define?
bsalomon
2013/03/13 15:29:22
It's not exposed outside this cpp so I don't think
| |
19 #define DYNAMIC_USAGE_PARAM GR_GL_STREAM_DRAW | |
20 | |
19 GrGLBufferImpl::GrGLBufferImpl(GrGpuGL* gpu, const Desc& desc, GrGLenum bufferTy pe) | 21 GrGLBufferImpl::GrGLBufferImpl(GrGpuGL* gpu, const Desc& desc, GrGLenum bufferTy pe) |
20 : fDesc(desc) | 22 : fDesc(desc) |
21 , fBufferType(bufferType) | 23 , fBufferType(bufferType) |
22 , fLockPtr(NULL) { | 24 , fLockPtr(NULL) { |
23 if (0 == desc.fID) { | 25 if (0 == desc.fID) { |
24 fCPUData = sk_malloc_flags(desc.fSizeInBytes, SK_MALLOC_THROW); | 26 fCPUData = sk_malloc_flags(desc.fSizeInBytes, SK_MALLOC_THROW); |
25 } else { | 27 } else { |
26 fCPUData = NULL; | 28 fCPUData = NULL; |
27 } | 29 } |
28 VALIDATE(); | 30 VALIDATE(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 VALIDATE(); | 71 VALIDATE(); |
70 GrAssert(!this->isLocked()); | 72 GrAssert(!this->isLocked()); |
71 if (0 == fDesc.fID) { | 73 if (0 == fDesc.fID) { |
72 fLockPtr = fCPUData; | 74 fLockPtr = fCPUData; |
73 } else if (gpu->getCaps().bufferLockSupport()) { | 75 } else if (gpu->getCaps().bufferLockSupport()) { |
74 this->bind(gpu); | 76 this->bind(gpu); |
75 // Let driver know it can discard the old data | 77 // Let driver know it can discard the old data |
76 GL_CALL(gpu, BufferData(fBufferType, | 78 GL_CALL(gpu, BufferData(fBufferType, |
77 fDesc.fSizeInBytes, | 79 fDesc.fSizeInBytes, |
78 NULL, | 80 NULL, |
79 fDesc.fDynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STAT IC_DRAW)); | 81 fDesc.fDynamic ? DYNAMIC_USAGE_PARAM : GR_GL_STA TIC_DRAW)); |
80 GR_GL_CALL_RET(gpu->glInterface(), | 82 GR_GL_CALL_RET(gpu->glInterface(), |
81 fLockPtr, | 83 fLockPtr, |
82 MapBuffer(fBufferType, GR_GL_WRITE_ONLY)); | 84 MapBuffer(fBufferType, GR_GL_WRITE_ONLY)); |
83 } | 85 } |
84 return fLockPtr; | 86 return fLockPtr; |
85 } | 87 } |
86 | 88 |
87 void GrGLBufferImpl::unlock(GrGpuGL* gpu) { | 89 void GrGLBufferImpl::unlock(GrGpuGL* gpu) { |
88 VALIDATE(); | 90 VALIDATE(); |
89 GrAssert(this->isLocked()); | 91 GrAssert(this->isLocked()); |
(...skipping 14 matching lines...) Expand all Loading... | |
104 GrAssert(!this->isLocked()); | 106 GrAssert(!this->isLocked()); |
105 VALIDATE(); | 107 VALIDATE(); |
106 if (srcSizeInBytes > fDesc.fSizeInBytes) { | 108 if (srcSizeInBytes > fDesc.fSizeInBytes) { |
107 return false; | 109 return false; |
108 } | 110 } |
109 if (0 == fDesc.fID) { | 111 if (0 == fDesc.fID) { |
110 memcpy(fCPUData, src, srcSizeInBytes); | 112 memcpy(fCPUData, src, srcSizeInBytes); |
111 return true; | 113 return true; |
112 } | 114 } |
113 this->bind(gpu); | 115 this->bind(gpu); |
114 GrGLenum usage = fDesc.fDynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW; | 116 GrGLenum usage = fDesc.fDynamic ? DYNAMIC_USAGE_PARAM : GR_GL_STATIC_DRAW; |
115 | 117 |
116 #if GR_GL_USE_BUFFER_DATA_NULL_HINT | 118 #if GR_GL_USE_BUFFER_DATA_NULL_HINT |
117 if (fDesc.fSizeInBytes == srcSizeInBytes) { | 119 if (fDesc.fSizeInBytes == srcSizeInBytes) { |
118 GL_CALL(gpu, BufferData(fBufferType, srcSizeInBytes, src, usage)); | 120 GL_CALL(gpu, BufferData(fBufferType, srcSizeInBytes, src, usage)); |
119 } else { | 121 } else { |
120 // Before we call glBufferSubData we give the driver a hint using | 122 // Before we call glBufferSubData we give the driver a hint using |
121 // glBufferData with NULL. This makes the old buffer contents | 123 // glBufferData with NULL. This makes the old buffer contents |
122 // inaccessible to future draws. The GPU may still be processing | 124 // inaccessible to future draws. The GPU may still be processing |
123 // draws that reference the old contents. With this hint it can | 125 // draws that reference the old contents. With this hint it can |
124 // assign a different allocation for the new contents to avoid | 126 // assign a different allocation for the new contents to avoid |
(...skipping 26 matching lines...) Expand all Loading... | |
151 #endif | 153 #endif |
152 return true; | 154 return true; |
153 } | 155 } |
154 | 156 |
155 void GrGLBufferImpl::validate() const { | 157 void GrGLBufferImpl::validate() const { |
156 GrAssert(GR_GL_ARRAY_BUFFER == fBufferType || GR_GL_ELEMENT_ARRAY_BUFFER == fBufferType); | 158 GrAssert(GR_GL_ARRAY_BUFFER == fBufferType || GR_GL_ELEMENT_ARRAY_BUFFER == fBufferType); |
157 GrAssert((0 == fDesc.fID) == (NULL != fCPUData)); | 159 GrAssert((0 == fDesc.fID) == (NULL != fCPUData)); |
158 GrAssert(0 != fDesc.fID || !fDesc.fIsWrapped); | 160 GrAssert(0 != fDesc.fID || !fDesc.fIsWrapped); |
159 GrAssert(NULL == fCPUData || NULL == fLockPtr || fCPUData == fLockPtr); | 161 GrAssert(NULL == fCPUData || NULL == fLockPtr || fCPUData == fLockPtr); |
160 } | 162 } |
OLD | NEW |