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

Side by Side Diff: src/gpu/GrContext.cpp

Issue 761563002: First step to moving vertex attributes to the geometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more cleanup Created 6 years 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrContext.h" 9 #include "GrContext.h"
10 10
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 drawState.setRenderTarget(texture->asRenderTarget()); 306 drawState.setRenderTarget(texture->asRenderTarget());
307 307
308 // if filtering is not desired then we want to ensure all 308 // if filtering is not desired then we want to ensure all
309 // texels in the resampled image are copies of texels from 309 // texels in the resampled image are copies of texels from
310 // the original. 310 // the original.
311 GrTextureParams params(SkShader::kClamp_TileMode, 311 GrTextureParams params(SkShader::kClamp_TileMode,
312 filter ? GrTextureParams::kBilerp_FilterMode : 312 filter ? GrTextureParams::kBilerp_FilterMode :
313 GrTextureParams::kNone_FilterMode); 313 GrTextureParams::kNone_FilterMode);
314 drawState.addColorTextureProcessor(clampedTexture, SkMatrix::I(), params ); 314 drawState.addColorTextureProcessor(clampedTexture, SkMatrix::I(), params );
315 315
316 drawState.setGeometryProcessor( 316 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType |
317 GrDefaultGeoProcFactory::CreateAndSetAttribs( 317 GrDefaultGeoProcFactory::kLocalCoord_GPType;
318 &drawState, 318 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(flags);
319 GrDefaultGeoProcFactory::kPosition_GPType | 319 drawState.setGeometryProcessor(gp)->unref();
320 GrDefaultGeoProcFactory::kLocalCoord_GPType))->unref();
321 320
322 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, drawState.getVerte xStride(), 0); 321 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, gp->getVertexStrid e(), 0);
323 322
324 if (arg.succeeded()) { 323 if (arg.succeeded()) {
325 SkPoint* verts = (SkPoint*) arg.vertices(); 324 SkPoint* verts = (SkPoint*) arg.vertices();
326 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint)); 325 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint));
327 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); 326 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint));
328 fDrawBuffer->drawNonIndexed(&drawState, kTriangleFan_GrPrimitiveType , 0, 4); 327 fDrawBuffer->drawNonIndexed(&drawState, kTriangleFan_GrPrimitiveType , 0, 4);
329 } 328 }
330 } else { 329 } else {
331 // TODO: Our CPU stretch doesn't filter. But we create separate 330 // TODO: Our CPU stretch doesn't filter. But we create separate
332 // stretched textures when the texture params is either filtered or 331 // stretched textures when the texture params is either filtered or
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 } 741 }
743 return; 742 return;
744 } 743 }
745 744
746 if (width >= 0) { 745 if (width >= 0) {
747 // TODO: consider making static vertex buffers for these cases. 746 // TODO: consider making static vertex buffers for these cases.
748 // Hairline could be done by just adding closing vertex to 747 // Hairline could be done by just adding closing vertex to
749 // unitSquareVertexBuffer() 748 // unitSquareVertexBuffer()
750 749
751 static const int worstCaseVertCount = 10; 750 static const int worstCaseVertCount = 10;
752 drawState.setDefaultVertexAttribs(); 751 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create();
753 drawState.setGeometryProcessor(GrDefaultGeoProcFactory::Create(false))-> unref(); 752 drawState.setGeometryProcessor(gp)->unref();
754 GrDrawTarget::AutoReleaseGeometry geo(target, 753 GrDrawTarget::AutoReleaseGeometry geo(target,
755 worstCaseVertCount, 754 worstCaseVertCount,
756 drawState.getVertexStride(), 755 gp->getVertexStride(),
757 0); 756 0);
758 757
759 if (!geo.succeeded()) { 758 if (!geo.succeeded()) {
760 SkDebugf("Failed to get space for vertices!\n"); 759 SkDebugf("Failed to get space for vertices!\n");
761 return; 760 return;
762 } 761 }
763 762
764 GrPrimitiveType primType; 763 GrPrimitiveType primType;
765 int vertCount; 764 int vertCount;
766 SkPoint* vertex = geo.positions(); 765 SkPoint* vertex = geo.positions();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 *texOffset = sizeof(SkPoint) + sizeof(GrColor); 816 *texOffset = sizeof(SkPoint) + sizeof(GrColor);
818 flags |= GrDefaultGeoProcFactory::kColor_GPType | 817 flags |= GrDefaultGeoProcFactory::kColor_GPType |
819 GrDefaultGeoProcFactory::kLocalCoord_GPType; 818 GrDefaultGeoProcFactory::kLocalCoord_GPType;
820 } else if (texCoords) { 819 } else if (texCoords) {
821 *texOffset = sizeof(SkPoint); 820 *texOffset = sizeof(SkPoint);
822 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; 821 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType;
823 } else if (colors) { 822 } else if (colors) {
824 *colorOffset = sizeof(SkPoint); 823 *colorOffset = sizeof(SkPoint);
825 flags |= GrDefaultGeoProcFactory::kColor_GPType; 824 flags |= GrDefaultGeoProcFactory::kColor_GPType;
826 } 825 }
827 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::CreateAndSetAttribs (drawState, 826 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags))->unr ef();
828 flags))->unref();
829 } 827 }
830 828
831 void GrContext::drawVertices(const GrPaint& paint, 829 void GrContext::drawVertices(const GrPaint& paint,
832 GrPrimitiveType primitiveType, 830 GrPrimitiveType primitiveType,
833 int vertexCount, 831 int vertexCount,
834 const SkPoint positions[], 832 const SkPoint positions[],
835 const SkPoint texCoords[], 833 const SkPoint texCoords[],
836 const GrColor colors[], 834 const GrColor colors[],
837 const uint16_t indices[], 835 const uint16_t indices[],
838 int indexCount) { 836 int indexCount) {
839 AutoCheckFlush acf(this); 837 AutoCheckFlush acf(this);
840 GrDrawState drawState; 838 GrDrawState drawState;
841 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e 839 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e
842 840
843 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); 841 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
844 if (NULL == target) { 842 if (NULL == target) {
845 return; 843 return;
846 } 844 }
847 845
848 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); 846 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target);
849 847
850 int colorOffset = -1, texOffset = -1; 848 int colorOffset = -1, texOffset = -1;
851 set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffse t); 849 set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffse t);
852 850
853 size_t vertexStride = drawState.getVertexStride(); 851 size_t vertexStride = drawState.getGeometryProcessor()->getVertexStride();
854 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { 852 if (!geo.set(target, vertexCount, vertexStride, indexCount)) {
855 SkDebugf("Failed to get space for vertices!\n"); 853 SkDebugf("Failed to get space for vertices!\n");
856 return; 854 return;
857 } 855 }
858 void* curVertex = geo.vertices(); 856 void* curVertex = geo.vertices();
859 857
860 for (int i = 0; i < vertexCount; ++i) { 858 for (int i = 0; i < vertexCount; ++i) {
861 *((SkPoint*)curVertex) = positions[i]; 859 *((SkPoint*)curVertex) = positions[i];
862 860
863 if (texOffset >= 0) { 861 if (texOffset >= 0) {
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 if (ds) { 1533 if (ds) {
1536 if (paint) { 1534 if (paint) {
1537 SkASSERT(acf); 1535 SkASSERT(acf);
1538 ds->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); 1536 ds->setFromPaint(*paint, fViewMatrix, fRenderTarget.get());
1539 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK 1537 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK
1540 if ((paint->hasMask() || 0xff != paint->fCoverage) && 1538 if ((paint->hasMask() || 0xff != paint->fCoverage) &&
1541 !fDrawState->couldApplyCoverage(fGpu->caps())) { 1539 !fDrawState->couldApplyCoverage(fGpu->caps())) {
1542 SkDebugf("Partial pixel coverage will be incorrectly blended.\n" ); 1540 SkDebugf("Partial pixel coverage will be incorrectly blended.\n" );
1543 } 1541 }
1544 #endif 1542 #endif
1545 // Clear any vertex attributes configured for the previous use of th e
1546 // GrDrawState which can effect which blend optimizations are in eff ect.
1547 ds->setDefaultVertexAttribs();
1548 } else { 1543 } else {
1549 ds->reset(fViewMatrix); 1544 ds->reset(fViewMatrix);
1550 ds->setRenderTarget(fRenderTarget.get()); 1545 ds->setRenderTarget(fRenderTarget.get());
1551 } 1546 }
1552 ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->i sWideOpen()); 1547 ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->i sWideOpen());
1553 } 1548 }
1554 fDrawBuffer->setClip(fClip); 1549 fDrawBuffer->setClip(fClip);
1555 return fDrawBuffer; 1550 return fDrawBuffer;
1556 } 1551 }
1557 1552
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 fResourceCache2->printStats(); 1704 fResourceCache2->printStats();
1710 } 1705 }
1711 #endif 1706 #endif
1712 1707
1713 #if GR_GPU_STATS 1708 #if GR_GPU_STATS
1714 const GrContext::GPUStats* GrContext::gpuStats() const { 1709 const GrContext::GPUStats* GrContext::gpuStats() const {
1715 return fGpu->gpuStats(); 1710 return fGpu->gpuStats();
1716 } 1711 }
1717 #endif 1712 #endif
1718 1713
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698