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

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: adding test to ignore 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
« no previous file with comments | « src/gpu/GrBitmapTextContext.cpp ('k') | src/gpu/GrDefaultGeoProcFactory.h » ('j') | 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 /* 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);
322 SkASSERT(gp->getVertexStride() == 2 * sizeof(SkPoint));
323 323
324 if (arg.succeeded()) { 324 if (arg.succeeded()) {
325 SkPoint* verts = (SkPoint*) arg.vertices(); 325 SkPoint* verts = (SkPoint*) arg.vertices();
326 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint)); 326 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint));
327 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); 327 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint));
328 fDrawBuffer->drawNonIndexed(&drawState, kTriangleFan_GrPrimitiveType , 0, 4); 328 fDrawBuffer->drawNonIndexed(&drawState, kTriangleFan_GrPrimitiveType , 0, 4);
329 } 329 }
330 } else { 330 } else {
331 // TODO: Our CPU stretch doesn't filter. But we create separate 331 // TODO: Our CPU stretch doesn't filter. But we create separate
332 // stretched textures when the texture params is either filtered or 332 // stretched textures when the texture params is either filtered or
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 } 746 }
747 return; 747 return;
748 } 748 }
749 749
750 if (width >= 0) { 750 if (width >= 0) {
751 // TODO: consider making static vertex buffers for these cases. 751 // TODO: consider making static vertex buffers for these cases.
752 // Hairline could be done by just adding closing vertex to 752 // Hairline could be done by just adding closing vertex to
753 // unitSquareVertexBuffer() 753 // unitSquareVertexBuffer()
754 754
755 static const int worstCaseVertCount = 10; 755 static const int worstCaseVertCount = 10;
756 drawState.setDefaultVertexAttribs(); 756 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create();
757 drawState.setGeometryProcessor(GrDefaultGeoProcFactory::Create(false))-> unref(); 757 drawState.setGeometryProcessor(gp)->unref();
758 GrDrawTarget::AutoReleaseGeometry geo(target, 758 GrDrawTarget::AutoReleaseGeometry geo(target,
759 worstCaseVertCount, 759 worstCaseVertCount,
760 drawState.getVertexStride(), 760 gp->getVertexStride(),
761 0); 761 0);
762 SkASSERT(gp->getVertexStride() == sizeof(SkPoint));
762 763
763 if (!geo.succeeded()) { 764 if (!geo.succeeded()) {
764 SkDebugf("Failed to get space for vertices!\n"); 765 SkDebugf("Failed to get space for vertices!\n");
765 return; 766 return;
766 } 767 }
767 768
768 GrPrimitiveType primType; 769 GrPrimitiveType primType;
769 int vertCount; 770 int vertCount;
770 SkPoint* vertex = geo.positions(); 771 SkPoint* vertex = geo.positions();
771 772
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 *texOffset = sizeof(SkPoint) + sizeof(GrColor); 822 *texOffset = sizeof(SkPoint) + sizeof(GrColor);
822 flags |= GrDefaultGeoProcFactory::kColor_GPType | 823 flags |= GrDefaultGeoProcFactory::kColor_GPType |
823 GrDefaultGeoProcFactory::kLocalCoord_GPType; 824 GrDefaultGeoProcFactory::kLocalCoord_GPType;
824 } else if (texCoords) { 825 } else if (texCoords) {
825 *texOffset = sizeof(SkPoint); 826 *texOffset = sizeof(SkPoint);
826 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; 827 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType;
827 } else if (colors) { 828 } else if (colors) {
828 *colorOffset = sizeof(SkPoint); 829 *colorOffset = sizeof(SkPoint);
829 flags |= GrDefaultGeoProcFactory::kColor_GPType; 830 flags |= GrDefaultGeoProcFactory::kColor_GPType;
830 } 831 }
831 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::CreateAndSetAttribs (drawState, 832 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags))->unr ef();
832 flags))->unref();
833 } 833 }
834 834
835 void GrContext::drawVertices(const GrPaint& paint, 835 void GrContext::drawVertices(const GrPaint& paint,
836 GrPrimitiveType primitiveType, 836 GrPrimitiveType primitiveType,
837 int vertexCount, 837 int vertexCount,
838 const SkPoint positions[], 838 const SkPoint positions[],
839 const SkPoint texCoords[], 839 const SkPoint texCoords[],
840 const GrColor colors[], 840 const GrColor colors[],
841 const uint16_t indices[], 841 const uint16_t indices[],
842 int indexCount) { 842 int indexCount) {
843 AutoCheckFlush acf(this); 843 AutoCheckFlush acf(this);
844 GrDrawState drawState; 844 GrDrawState drawState;
845 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e 845 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e
846 846
847 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); 847 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
848 if (NULL == target) { 848 if (NULL == target) {
849 return; 849 return;
850 } 850 }
851 851
852 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); 852 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target);
853 853
854 int colorOffset = -1, texOffset = -1; 854 int colorOffset = -1, texOffset = -1;
855 set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffse t); 855 set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffse t);
856 856
857 size_t vertexStride = drawState.getVertexStride(); 857 size_t vertexStride = drawState.getGeometryProcessor()->getVertexStride();
858 SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkP oint) : 0)
859 + (SkToBool(colors) ? sizeof(GrColo r) : 0));
858 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { 860 if (!geo.set(target, vertexCount, vertexStride, indexCount)) {
859 SkDebugf("Failed to get space for vertices!\n"); 861 SkDebugf("Failed to get space for vertices!\n");
860 return; 862 return;
861 } 863 }
862 void* curVertex = geo.vertices(); 864 void* curVertex = geo.vertices();
863 865
864 for (int i = 0; i < vertexCount; ++i) { 866 for (int i = 0; i < vertexCount; ++i) {
865 *((SkPoint*)curVertex) = positions[i]; 867 *((SkPoint*)curVertex) = positions[i];
866 868
867 if (texOffset >= 0) { 869 if (texOffset >= 0) {
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 if (ds) { 1541 if (ds) {
1540 if (paint) { 1542 if (paint) {
1541 SkASSERT(acf); 1543 SkASSERT(acf);
1542 ds->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); 1544 ds->setFromPaint(*paint, fViewMatrix, fRenderTarget.get());
1543 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK 1545 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK
1544 if ((paint->hasMask() || 0xff != paint->fCoverage) && 1546 if ((paint->hasMask() || 0xff != paint->fCoverage) &&
1545 !fDrawState->couldApplyCoverage(fGpu->caps())) { 1547 !fDrawState->couldApplyCoverage(fGpu->caps())) {
1546 SkDebugf("Partial pixel coverage will be incorrectly blended.\n" ); 1548 SkDebugf("Partial pixel coverage will be incorrectly blended.\n" );
1547 } 1549 }
1548 #endif 1550 #endif
1549 // Clear any vertex attributes configured for the previous use of th e
1550 // GrDrawState which can effect which blend optimizations are in eff ect.
1551 ds->setDefaultVertexAttribs();
1552 } else { 1551 } else {
1553 ds->reset(fViewMatrix); 1552 ds->reset(fViewMatrix);
1554 ds->setRenderTarget(fRenderTarget.get()); 1553 ds->setRenderTarget(fRenderTarget.get());
1555 } 1554 }
1556 ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->i sWideOpen()); 1555 ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->i sWideOpen());
1557 } 1556 }
1558 fDrawBuffer->setClip(fClip); 1557 fDrawBuffer->setClip(fClip);
1559 return fDrawBuffer; 1558 return fDrawBuffer;
1560 } 1559 }
1561 1560
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 fResourceCache2->printStats(); 1712 fResourceCache2->printStats();
1714 } 1713 }
1715 #endif 1714 #endif
1716 1715
1717 #if GR_GPU_STATS 1716 #if GR_GPU_STATS
1718 const GrContext::GPUStats* GrContext::gpuStats() const { 1717 const GrContext::GPUStats* GrContext::gpuStats() const {
1719 return fGpu->gpuStats(); 1718 return fGpu->gpuStats();
1720 } 1719 }
1721 #endif 1720 #endif
1722 1721
OLDNEW
« no previous file with comments | « src/gpu/GrBitmapTextContext.cpp ('k') | src/gpu/GrDefaultGeoProcFactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698