Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Unified Diff: src/gpu/gl/GrGLBufferImpl.cpp

Issue 1417313003: Move GrGLBufferImpl's GL calls to behind GrGLGpu (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/GrGLBufferImpl.h ('k') | src/gpu/gl/GrGLGpu.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLBufferImpl.cpp
diff --git a/src/gpu/gl/GrGLBufferImpl.cpp b/src/gpu/gl/GrGLBufferImpl.cpp
index 975d087b28987d5c7e12cebe96e8fc7596157a32..6cbf4e0d0eca4dde0274b31c3624a203f972cd9e 100644
--- a/src/gpu/gl/GrGLBufferImpl.cpp
+++ b/src/gpu/gl/GrGLBufferImpl.cpp
@@ -16,10 +16,6 @@
#define VALIDATE() do {} while(false)
#endif
-// GL_STREAM_DRAW triggers an optimization in Chromium's GPU process where a client's vertex buffer
-// objects are implemented as client-side-arrays on tile-deferred architectures.
-#define DYNAMIC_USAGE_PARAM GR_GL_STREAM_DRAW
-
GrGLBufferImpl::GrGLBufferImpl(GrGLGpu* gpu, const Desc& desc, GrGLenum bufferType)
: fDesc(desc)
, fBufferType(bufferType)
@@ -46,13 +42,7 @@ void GrGLBufferImpl::release(GrGLGpu* gpu) {
sk_free(fCPUData);
fCPUData = nullptr;
} else if (fDesc.fID) {
- GL_CALL(gpu, DeleteBuffers(1, &fDesc.fID));
- if (GR_GL_ARRAY_BUFFER == fBufferType) {
- gpu->notifyVertexBufferDelete(fDesc.fID);
- } else {
- SkASSERT(GR_GL_ELEMENT_ARRAY_BUFFER == fBufferType);
- gpu->notifyIndexBufferDelete(fDesc.fID);
- }
+ gpu->releaseBuffer(fDesc.fID, fBufferType);
fDesc.fID = 0;
fGLSizeInBytes = 0;
}
@@ -69,69 +59,15 @@ void GrGLBufferImpl::abandon() {
VALIDATE();
}
-void GrGLBufferImpl::bind(GrGLGpu* gpu) const {
- VALIDATE();
- if (GR_GL_ARRAY_BUFFER == fBufferType) {
- gpu->bindVertexBuffer(fDesc.fID);
- } else {
- SkASSERT(GR_GL_ELEMENT_ARRAY_BUFFER == fBufferType);
- gpu->bindIndexBufferAndDefaultVertexArray(fDesc.fID);
- }
- VALIDATE();
-}
-
void* GrGLBufferImpl::map(GrGLGpu* gpu) {
VALIDATE();
SkASSERT(!this->isMapped());
if (0 == fDesc.fID) {
fMapPtr = fCPUData;
} else {
- switch (gpu->glCaps().mapBufferType()) {
- case GrGLCaps::kNone_MapBufferType:
- VALIDATE();
- return nullptr;
- case GrGLCaps::kMapBuffer_MapBufferType:
- this->bind(gpu);
- // Let driver know it can discard the old data
- if (GR_GL_USE_BUFFER_DATA_NULL_HINT || fDesc.fSizeInBytes != fGLSizeInBytes) {
- fGLSizeInBytes = fDesc.fSizeInBytes;
- GL_CALL(gpu,
- BufferData(fBufferType, fGLSizeInBytes, nullptr,
- fDesc.fDynamic ? DYNAMIC_USAGE_PARAM : GR_GL_STATIC_DRAW));
- }
- GR_GL_CALL_RET(gpu->glInterface(), fMapPtr,
- MapBuffer(fBufferType, GR_GL_WRITE_ONLY));
- break;
- case GrGLCaps::kMapBufferRange_MapBufferType: {
- this->bind(gpu);
- // Make sure the GL buffer size agrees with fDesc before mapping.
- if (fDesc.fSizeInBytes != fGLSizeInBytes) {
- fGLSizeInBytes = fDesc.fSizeInBytes;
- GL_CALL(gpu,
- BufferData(fBufferType, fGLSizeInBytes, nullptr,
- fDesc.fDynamic ? DYNAMIC_USAGE_PARAM : GR_GL_STATIC_DRAW));
- }
- static const GrGLbitfield kAccess = GR_GL_MAP_INVALIDATE_BUFFER_BIT |
- GR_GL_MAP_WRITE_BIT;
- GR_GL_CALL_RET(gpu->glInterface(),
- fMapPtr,
- MapBufferRange(fBufferType, 0, fGLSizeInBytes, kAccess));
- break;
- }
- case GrGLCaps::kChromium_MapBufferType:
- this->bind(gpu);
- // Make sure the GL buffer size agrees with fDesc before mapping.
- if (fDesc.fSizeInBytes != fGLSizeInBytes) {
- fGLSizeInBytes = fDesc.fSizeInBytes;
- GL_CALL(gpu,
- BufferData(fBufferType, fGLSizeInBytes, nullptr,
- fDesc.fDynamic ? DYNAMIC_USAGE_PARAM : GR_GL_STATIC_DRAW));
- }
- GR_GL_CALL_RET(gpu->glInterface(),
- fMapPtr,
- MapBufferSubData(fBufferType, 0, fGLSizeInBytes, GR_GL_WRITE_ONLY));
- break;
- }
+ fMapPtr = gpu->mapBuffer(fDesc.fID, fBufferType, fDesc.fDynamic, fGLSizeInBytes,
+ fDesc.fSizeInBytes);
+ fGLSizeInBytes = fDesc.fSizeInBytes;
}
VALIDATE();
return fMapPtr;
@@ -141,20 +77,7 @@ void GrGLBufferImpl::unmap(GrGLGpu* gpu) {
VALIDATE();
SkASSERT(this->isMapped());
if (0 != fDesc.fID) {
- switch (gpu->glCaps().mapBufferType()) {
- case GrGLCaps::kNone_MapBufferType:
- SkDEBUGFAIL("Shouldn't get here.");
- return;
- case GrGLCaps::kMapBuffer_MapBufferType: // fall through
- case GrGLCaps::kMapBufferRange_MapBufferType:
- this->bind(gpu);
- GL_CALL(gpu, UnmapBuffer(fBufferType));
- break;
- case GrGLCaps::kChromium_MapBufferType:
- this->bind(gpu);
- GR_GL_CALL(gpu->glInterface(), UnmapBufferSubData(fMapPtr));
- break;
- }
+ gpu->unmapBuffer(fDesc.fID, fBufferType, fMapPtr);
}
fMapPtr = nullptr;
}
@@ -174,30 +97,14 @@ bool GrGLBufferImpl::updateData(GrGLGpu* gpu, const void* src, size_t srcSizeInB
memcpy(fCPUData, src, srcSizeInBytes);
return true;
}
- this->bind(gpu);
- GrGLenum usage = fDesc.fDynamic ? DYNAMIC_USAGE_PARAM : GR_GL_STATIC_DRAW;
-
+ gpu->bufferData(fDesc.fID, fBufferType, fDesc.fDynamic, fDesc.fSizeInBytes, src,
+ srcSizeInBytes);
#if GR_GL_USE_BUFFER_DATA_NULL_HINT
- if (fDesc.fSizeInBytes == srcSizeInBytes) {
- GL_CALL(gpu, BufferData(fBufferType, (GrGLsizeiptr) srcSizeInBytes, src, usage));
- } else {
- // Before we call glBufferSubData we give the driver a hint using
- // glBufferData with nullptr. This makes the old buffer contents
- // inaccessible to future draws. The GPU may still be processing
- // draws that reference the old contents. With this hint it can
- // assign a different allocation for the new contents to avoid
- // flushing the gpu past draws consuming the old contents.
- fGLSizeInBytes = fDesc.fSizeInBytes;
- GL_CALL(gpu, BufferData(fBufferType, fGLSizeInBytes, nullptr, usage));
- GL_CALL(gpu, BufferSubData(fBufferType, 0, (GrGLsizeiptr) srcSizeInBytes, src));
- }
+ fGLSizeInBytes = fDesc.fSizeInBytes;
#else
- // Note that we're cheating on the size here. Currently no methods
- // allow a partial update that preserves contents of non-updated
- // portions of the buffer (map() does a glBufferData(..size, nullptr..))
fGLSizeInBytes = srcSizeInBytes;
- GL_CALL(gpu, BufferData(fBufferType, fGLSizeInBytes, src, usage));
#endif
+ VALIDATE();
return true;
}
@@ -206,6 +113,6 @@ void GrGLBufferImpl::validate() const {
// The following assert isn't valid when the buffer has been abandoned:
// SkASSERT((0 == fDesc.fID) == (fCPUData));
SkASSERT(nullptr == fCPUData || 0 == fGLSizeInBytes);
- SkASSERT(nullptr == fMapPtr || fCPUData || fGLSizeInBytes == fDesc.fSizeInBytes);
+ SkASSERT(nullptr == fMapPtr || fCPUData || fGLSizeInBytes <= fDesc.fSizeInBytes);
SkASSERT(nullptr == fCPUData || nullptr == fMapPtr || fCPUData == fMapPtr);
}
« no previous file with comments | « src/gpu/gl/GrGLBufferImpl.h ('k') | src/gpu/gl/GrGLGpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698