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

Side by Side Diff: src/gpu/gl/GrGLGpu.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 unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 8
9 #include "GrGLGpu.h" 9 #include "GrGLGpu.h"
10 #include "GrGLGLSL.h" 10 #include "GrGLGLSL.h"
(...skipping 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 } 1554 }
1555 1555
1556 void GrGLGpu::buildProgramDesc(GrProgramDesc* desc, 1556 void GrGLGpu::buildProgramDesc(GrProgramDesc* desc,
1557 const GrPrimitiveProcessor& primProc, 1557 const GrPrimitiveProcessor& primProc,
1558 const GrPipeline& pipeline) const { 1558 const GrPipeline& pipeline) const {
1559 if (!GrGLProgramDescBuilder::Build(desc, primProc, pipeline, this)) { 1559 if (!GrGLProgramDescBuilder::Build(desc, primProc, pipeline, this)) {
1560 SkDEBUGFAIL("Failed to generate GL program descriptor"); 1560 SkDEBUGFAIL("Failed to generate GL program descriptor");
1561 } 1561 }
1562 } 1562 }
1563 1563
1564 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) {
1565 this->handleDirtyContext();
1566 if (GR_GL_ARRAY_BUFFER == type) {
1567 this->bindVertexBuffer(id);
1568 } else {
1569 SkASSERT(GR_GL_ELEMENT_ARRAY_BUFFER == type);
1570 this->bindIndexBufferAndDefaultVertexArray(id);
1571 }
1572 }
1573
1574 void GrGLGpu::releaseBuffer(GrGLuint id, GrGLenum type) {
1575 this->handleDirtyContext();
1576 GL_CALL(DeleteBuffers(1, &id));
1577 if (GR_GL_ARRAY_BUFFER == type) {
1578 this->notifyVertexBufferDelete(id);
1579 } else {
1580 SkASSERT(GR_GL_ELEMENT_ARRAY_BUFFER == type);
1581 this->notifyIndexBufferDelete(id);
1582 }
1583 }
1584
1585 // GL_STREAM_DRAW triggers an optimization in Chromium's GPU process where a cli ent's vertex buffer
1586 // objects are implemented as client-side-arrays on tile-deferred architectures.
1587 #define DYNAMIC_USAGE_PARAM GR_GL_STREAM_DRAW
1588
1589 void* GrGLGpu::mapBuffer(GrGLuint id, GrGLenum type, bool dynamic, size_t curren tSize,
1590 size_t requestedSize) {
1591 void* mapPtr = nullptr;
1592 // Handling dirty context is done in the bindBuffer call
1593 switch (this->glCaps().mapBufferType()) {
1594 case GrGLCaps::kNone_MapBufferType:
1595 break;
1596 case GrGLCaps::kMapBuffer_MapBufferType:
1597 this->bindBuffer(id, type);
1598 // Let driver know it can discard the old data
1599 if (GR_GL_USE_BUFFER_DATA_NULL_HINT || currentSize != requestedSize) {
1600 GL_CALL(BufferData(type, requestedSize, nullptr,
1601 dynamic ? DYNAMIC_USAGE_PARAM : GR_GL_STATIC_ DRAW));
1602 }
1603 GL_CALL_RET(mapPtr, MapBuffer(type, GR_GL_WRITE_ONLY));
1604 break;
1605 case GrGLCaps::kMapBufferRange_MapBufferType: {
1606 this->bindBuffer(id, type);
1607 // Make sure the GL buffer size agrees with fDesc before mapping.
1608 if (currentSize != requestedSize) {
1609 GL_CALL(BufferData(type, requestedSize, nullptr,
1610 dynamic ? DYNAMIC_USAGE_PARAM : GR_GL_STATIC_ DRAW));
1611 }
1612 static const GrGLbitfield kAccess = GR_GL_MAP_INVALIDATE_BUFFER_BIT |
1613 GR_GL_MAP_WRITE_BIT;
1614 GL_CALL_RET(mapPtr, MapBufferRange(type, 0, requestedSize, kAccess)) ;
1615 break;
1616 }
1617 case GrGLCaps::kChromium_MapBufferType:
1618 this->bindBuffer(id, type);
1619 // Make sure the GL buffer size agrees with fDesc before mapping.
1620 if (currentSize != requestedSize) {
1621 GL_CALL(BufferData(type, requestedSize, nullptr,
1622 dynamic ? DYNAMIC_USAGE_PARAM : GR_GL_STATIC_ DRAW));
1623 }
1624 GL_CALL_RET(mapPtr, MapBufferSubData(type, 0, requestedSize, GR_GL_W RITE_ONLY));
1625 break;
1626 }
1627 return mapPtr;
1628 }
1629
1630 void GrGLGpu::bufferData(GrGLuint id, GrGLenum type, bool dynamic, size_t curren tSize,
1631 const void* src, size_t srcSizeInBytes) {
1632 SkASSERT(srcSizeInBytes <= currentSize);
1633 // bindbuffer handles dirty context
1634 this->bindBuffer(id, type);
1635 GrGLenum usage = dynamic ? DYNAMIC_USAGE_PARAM : GR_GL_STATIC_DRAW;
1636
1637 #if GR_GL_USE_BUFFER_DATA_NULL_HINT
1638 if (currentSize == srcSizeInBytes) {
1639 GL_CALL(BufferData(type, (GrGLsizeiptr) srcSizeInBytes, src, usage));
1640 } else {
1641 // Before we call glBufferSubData we give the driver a hint using
1642 // glBufferData with nullptr. This makes the old buffer contents
1643 // inaccessible to future draws. The GPU may still be processing
1644 // draws that reference the old contents. With this hint it can
1645 // assign a different allocation for the new contents to avoid
1646 // flushing the gpu past draws consuming the old contents.
1647 // TODO I think we actually want to try calling bufferData here
1648 GL_CALL(BufferData(type, currentSize, nullptr, usage));
1649 GL_CALL(BufferSubData(type, 0, (GrGLsizeiptr) srcSizeInBytes, src));
1650 }
1651 #else
1652 // Note that we're cheating on the size here. Currently no methods
1653 // allow a partial update that preserves contents of non-updated
1654 // portions of the buffer (map() does a glBufferData(..size, nullptr..))
1655 GL_CALL(BufferData(type, srcSizeInBytes, src, usage));
1656 #endif
1657 }
1658
1659 void GrGLGpu::unmapBuffer(GrGLuint id, GrGLenum type, void* mapPtr) {
1660 // bind buffer handles the dirty context
1661 switch (this->glCaps().mapBufferType()) {
1662 case GrGLCaps::kNone_MapBufferType:
1663 SkDEBUGFAIL("Shouldn't get here.");
1664 return;
1665 case GrGLCaps::kMapBuffer_MapBufferType: // fall through
1666 case GrGLCaps::kMapBufferRange_MapBufferType:
1667 this->bindBuffer(id, type);
1668 GL_CALL(UnmapBuffer(type));
1669 break;
1670 case GrGLCaps::kChromium_MapBufferType:
1671 this->bindBuffer(id, type);
1672 GL_CALL(UnmapBufferSubData(mapPtr));
1673 break;
1674 }
1675 }
1676
1564 void GrGLGpu::disableScissor() { 1677 void GrGLGpu::disableScissor() {
1565 if (kNo_TriState != fHWScissorSettings.fEnabled) { 1678 if (kNo_TriState != fHWScissorSettings.fEnabled) {
1566 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); 1679 GL_CALL(Disable(GR_GL_SCISSOR_TEST));
1567 fHWScissorSettings.fEnabled = kNo_TriState; 1680 fHWScissorSettings.fEnabled = kNo_TriState;
1568 return; 1681 return;
1569 } 1682 }
1570 } 1683 }
1571 1684
1572 void GrGLGpu::onClear(GrRenderTarget* target, const SkIRect& rect, GrColor color ) { 1685 void GrGLGpu::onClear(GrRenderTarget* target, const SkIRect& rect, GrColor color ) {
1573 // parent class should never let us get here with no RT 1686 // parent class should never let us get here with no RT
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after
3182 this->setVertexArrayID(gpu, 0); 3295 this->setVertexArrayID(gpu, 0);
3183 } 3296 }
3184 int attrCount = gpu->glCaps().maxVertexAttributes(); 3297 int attrCount = gpu->glCaps().maxVertexAttributes();
3185 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3298 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3186 fDefaultVertexArrayAttribState.resize(attrCount); 3299 fDefaultVertexArrayAttribState.resize(attrCount);
3187 } 3300 }
3188 attribState = &fDefaultVertexArrayAttribState; 3301 attribState = &fDefaultVertexArrayAttribState;
3189 } 3302 }
3190 return attribState; 3303 return attribState;
3191 } 3304 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698