OLD | NEW |
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 Loading... |
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() == 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 } | 742 } |
743 return; | 743 return; |
744 } | 744 } |
745 | 745 |
746 if (width >= 0) { | 746 if (width >= 0) { |
747 // TODO: consider making static vertex buffers for these cases. | 747 // TODO: consider making static vertex buffers for these cases. |
748 // Hairline could be done by just adding closing vertex to | 748 // Hairline could be done by just adding closing vertex to |
749 // unitSquareVertexBuffer() | 749 // unitSquareVertexBuffer() |
750 | 750 |
751 static const int worstCaseVertCount = 10; | 751 static const int worstCaseVertCount = 10; |
752 drawState.setDefaultVertexAttribs(); | 752 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(); |
753 drawState.setGeometryProcessor(GrDefaultGeoProcFactory::Create(false))->
unref(); | 753 drawState.setGeometryProcessor(gp)->unref(); |
754 GrDrawTarget::AutoReleaseGeometry geo(target, | 754 GrDrawTarget::AutoReleaseGeometry geo(target, |
755 worstCaseVertCount, | 755 worstCaseVertCount, |
756 drawState.getVertexStride(), | 756 gp->getVertexStride(), |
757 0); | 757 0); |
| 758 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
758 | 759 |
759 if (!geo.succeeded()) { | 760 if (!geo.succeeded()) { |
760 SkDebugf("Failed to get space for vertices!\n"); | 761 SkDebugf("Failed to get space for vertices!\n"); |
761 return; | 762 return; |
762 } | 763 } |
763 | 764 |
764 GrPrimitiveType primType; | 765 GrPrimitiveType primType; |
765 int vertCount; | 766 int vertCount; |
766 SkPoint* vertex = geo.positions(); | 767 SkPoint* vertex = geo.positions(); |
767 | 768 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 *texOffset = sizeof(SkPoint) + sizeof(GrColor); | 818 *texOffset = sizeof(SkPoint) + sizeof(GrColor); |
818 flags |= GrDefaultGeoProcFactory::kColor_GPType | | 819 flags |= GrDefaultGeoProcFactory::kColor_GPType | |
819 GrDefaultGeoProcFactory::kLocalCoord_GPType; | 820 GrDefaultGeoProcFactory::kLocalCoord_GPType; |
820 } else if (texCoords) { | 821 } else if (texCoords) { |
821 *texOffset = sizeof(SkPoint); | 822 *texOffset = sizeof(SkPoint); |
822 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 823 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
823 } else if (colors) { | 824 } else if (colors) { |
824 *colorOffset = sizeof(SkPoint); | 825 *colorOffset = sizeof(SkPoint); |
825 flags |= GrDefaultGeoProcFactory::kColor_GPType; | 826 flags |= GrDefaultGeoProcFactory::kColor_GPType; |
826 } | 827 } |
827 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::CreateAndSetAttribs
(drawState, | 828 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags))->unr
ef(); |
828
flags))->unref(); | |
829 } | 829 } |
830 | 830 |
831 void GrContext::drawVertices(const GrPaint& paint, | 831 void GrContext::drawVertices(const GrPaint& paint, |
832 GrPrimitiveType primitiveType, | 832 GrPrimitiveType primitiveType, |
833 int vertexCount, | 833 int vertexCount, |
834 const SkPoint positions[], | 834 const SkPoint positions[], |
835 const SkPoint texCoords[], | 835 const SkPoint texCoords[], |
836 const GrColor colors[], | 836 const GrColor colors[], |
837 const uint16_t indices[], | 837 const uint16_t indices[], |
838 int indexCount) { | 838 int indexCount) { |
839 AutoCheckFlush acf(this); | 839 AutoCheckFlush acf(this); |
840 GrDrawState drawState; | 840 GrDrawState drawState; |
841 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e | 841 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e |
842 | 842 |
843 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 843 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
844 if (NULL == target) { | 844 if (NULL == target) { |
845 return; | 845 return; |
846 } | 846 } |
847 | 847 |
848 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); | 848 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
849 | 849 |
850 int colorOffset = -1, texOffset = -1; | 850 int colorOffset = -1, texOffset = -1; |
851 set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffse
t); | 851 set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffse
t); |
852 | 852 |
853 size_t vertexStride = drawState.getVertexStride(); | 853 size_t vertexStride = drawState.getGeometryProcessor()->getVertexStride(); |
| 854 SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkP
oint) : 0) |
| 855 + (SkToBool(colors) ? sizeof(GrColo
r) : 0)); |
854 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { | 856 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { |
855 SkDebugf("Failed to get space for vertices!\n"); | 857 SkDebugf("Failed to get space for vertices!\n"); |
856 return; | 858 return; |
857 } | 859 } |
858 void* curVertex = geo.vertices(); | 860 void* curVertex = geo.vertices(); |
859 | 861 |
860 for (int i = 0; i < vertexCount; ++i) { | 862 for (int i = 0; i < vertexCount; ++i) { |
861 *((SkPoint*)curVertex) = positions[i]; | 863 *((SkPoint*)curVertex) = positions[i]; |
862 | 864 |
863 if (texOffset >= 0) { | 865 if (texOffset >= 0) { |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 if (ds) { | 1537 if (ds) { |
1536 if (paint) { | 1538 if (paint) { |
1537 SkASSERT(acf); | 1539 SkASSERT(acf); |
1538 ds->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); | 1540 ds->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); |
1539 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK | 1541 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK |
1540 if ((paint->hasMask() || 0xff != paint->fCoverage) && | 1542 if ((paint->hasMask() || 0xff != paint->fCoverage) && |
1541 !fDrawState->couldApplyCoverage(fGpu->caps())) { | 1543 !fDrawState->couldApplyCoverage(fGpu->caps())) { |
1542 SkDebugf("Partial pixel coverage will be incorrectly blended.\n"
); | 1544 SkDebugf("Partial pixel coverage will be incorrectly blended.\n"
); |
1543 } | 1545 } |
1544 #endif | 1546 #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 { | 1547 } else { |
1549 ds->reset(fViewMatrix); | 1548 ds->reset(fViewMatrix); |
1550 ds->setRenderTarget(fRenderTarget.get()); | 1549 ds->setRenderTarget(fRenderTarget.get()); |
1551 } | 1550 } |
1552 ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->i
sWideOpen()); | 1551 ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->i
sWideOpen()); |
1553 } | 1552 } |
1554 fDrawBuffer->setClip(fClip); | 1553 fDrawBuffer->setClip(fClip); |
1555 return fDrawBuffer; | 1554 return fDrawBuffer; |
1556 } | 1555 } |
1557 | 1556 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 fResourceCache2->printStats(); | 1708 fResourceCache2->printStats(); |
1710 } | 1709 } |
1711 #endif | 1710 #endif |
1712 | 1711 |
1713 #if GR_GPU_STATS | 1712 #if GR_GPU_STATS |
1714 const GrContext::GPUStats* GrContext::gpuStats() const { | 1713 const GrContext::GPUStats* GrContext::gpuStats() const { |
1715 return fGpu->gpuStats(); | 1714 return fGpu->gpuStats(); |
1716 } | 1715 } |
1717 #endif | 1716 #endif |
1718 | 1717 |
OLD | NEW |