| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | | 316 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
| 317 GrDefaultGeoProcFactory::kLocalCoord_GPType; | 317 GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 318 SkAutoTUnref<const GrGeometryProcessor> gp( | 318 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(GrColor_
WHITE, flags); |
| 319 GrDefaultGeoProcFactory::Create(GrColor_WHITE, flags)); | 319 drawState.setGeometryProcessor(gp)->unref(); |
| 320 | 320 |
| 321 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, gp->getVertexStrid
e(), 0); | 321 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, gp->getVertexStrid
e(), 0); |
| 322 SkASSERT(gp->getVertexStride() == 2 * sizeof(SkPoint)); | 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, gp, kTriangleFan_GrPrimitive
Type, 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 |
| 333 // not. Either implement filtered stretch blit on CPU or just create | 333 // not. Either implement filtered stretch blit on CPU or just create |
| 334 // one when FBO case fails. | 334 // one when FBO case fails. |
| 335 | 335 |
| 336 rtDesc.fFlags = kNone_GrSurfaceFlags; | 336 rtDesc.fFlags = kNone_GrSurfaceFlags; |
| 337 // no longer need to clamp at min RT size. | 337 // no longer need to clamp at min RT size. |
| 338 rtDesc.fWidth = GrNextPow2(desc.fWidth); | 338 rtDesc.fWidth = GrNextPow2(desc.fWidth); |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 } | 751 } |
| 752 return; | 752 return; |
| 753 } | 753 } |
| 754 | 754 |
| 755 if (width >= 0) { | 755 if (width >= 0) { |
| 756 // TODO: consider making static vertex buffers for these cases. | 756 // TODO: consider making static vertex buffers for these cases. |
| 757 // Hairline could be done by just adding closing vertex to | 757 // Hairline could be done by just adding closing vertex to |
| 758 // unitSquareVertexBuffer() | 758 // unitSquareVertexBuffer() |
| 759 | 759 |
| 760 static const int worstCaseVertCount = 10; | 760 static const int worstCaseVertCount = 10; |
| 761 SkAutoTUnref<const GrGeometryProcessor> gp(GrDefaultGeoProcFactory::Crea
te(color)); | 761 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(color); |
| 762 drawState.setGeometryProcessor(gp)->unref(); |
| 762 GrDrawTarget::AutoReleaseGeometry geo(target, | 763 GrDrawTarget::AutoReleaseGeometry geo(target, |
| 763 worstCaseVertCount, | 764 worstCaseVertCount, |
| 764 gp->getVertexStride(), | 765 gp->getVertexStride(), |
| 765 0); | 766 0); |
| 766 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 767 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
| 767 | 768 |
| 768 if (!geo.succeeded()) { | 769 if (!geo.succeeded()) { |
| 769 SkDebugf("Failed to get space for vertices!\n"); | 770 SkDebugf("Failed to get space for vertices!\n"); |
| 770 return; | 771 return; |
| 771 } | 772 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 782 // hairline | 783 // hairline |
| 783 vertCount = 5; | 784 vertCount = 5; |
| 784 primType = kLineStrip_GrPrimitiveType; | 785 primType = kLineStrip_GrPrimitiveType; |
| 785 vertex[0].set(rect.fLeft, rect.fTop); | 786 vertex[0].set(rect.fLeft, rect.fTop); |
| 786 vertex[1].set(rect.fRight, rect.fTop); | 787 vertex[1].set(rect.fRight, rect.fTop); |
| 787 vertex[2].set(rect.fRight, rect.fBottom); | 788 vertex[2].set(rect.fRight, rect.fBottom); |
| 788 vertex[3].set(rect.fLeft, rect.fBottom); | 789 vertex[3].set(rect.fLeft, rect.fBottom); |
| 789 vertex[4].set(rect.fLeft, rect.fTop); | 790 vertex[4].set(rect.fLeft, rect.fTop); |
| 790 } | 791 } |
| 791 | 792 |
| 792 target->drawNonIndexed(&drawState, gp, primType, 0, vertCount); | 793 target->drawNonIndexed(&drawState, primType, 0, vertCount); |
| 793 } else { | 794 } else { |
| 794 // filled BW rect | 795 // filled BW rect |
| 795 target->drawSimpleRect(&drawState, color, rect); | 796 target->drawSimpleRect(&drawState, color, rect); |
| 796 } | 797 } |
| 797 } | 798 } |
| 798 | 799 |
| 799 void GrContext::drawRectToRect(const GrPaint& paint, | 800 void GrContext::drawRectToRect(const GrPaint& paint, |
| 800 const SkRect& dstRect, | 801 const SkRect& dstRect, |
| 801 const SkRect& localRect, | 802 const SkRect& localRect, |
| 802 const SkMatrix* localMatrix) { | 803 const SkMatrix* localMatrix) { |
| 803 AutoCheckFlush acf(this); | 804 AutoCheckFlush acf(this); |
| 804 GrDrawState drawState; | 805 GrDrawState drawState; |
| 805 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 806 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
| 806 if (NULL == target) { | 807 if (NULL == target) { |
| 807 return; | 808 return; |
| 808 } | 809 } |
| 809 | 810 |
| 810 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 811 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
| 811 | 812 |
| 812 target->drawRect(&drawState, paint.getColor(), dstRect, &localRect, localMat
rix); | 813 target->drawRect(&drawState, paint.getColor(), dstRect, &localRect, localMat
rix); |
| 813 } | 814 } |
| 814 | 815 |
| 815 static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords
, | 816 static void set_vertex_attributes(GrDrawState* drawState, |
| 816 const GrColor* colors, | 817 const SkPoint* texCoords, |
| 817 int* colorOffset, | 818 const GrColor* colors, |
| 818 int* texOffset, | 819 int* colorOffset, |
| 819 GrColor color) { | 820 int* texOffset, |
| 821 GrColor color) { |
| 820 *texOffset = -1; | 822 *texOffset = -1; |
| 821 *colorOffset = -1; | 823 *colorOffset = -1; |
| 822 | 824 |
| 823 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; | 825 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; |
| 824 if (texCoords && colors) { | 826 if (texCoords && colors) { |
| 825 *colorOffset = sizeof(SkPoint); | 827 *colorOffset = sizeof(SkPoint); |
| 826 *texOffset = sizeof(SkPoint) + sizeof(GrColor); | 828 *texOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 827 flags |= GrDefaultGeoProcFactory::kColor_GPType | | 829 flags |= GrDefaultGeoProcFactory::kColor_GPType | |
| 828 GrDefaultGeoProcFactory::kLocalCoord_GPType; | 830 GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 829 } else if (texCoords) { | 831 } else if (texCoords) { |
| 830 *texOffset = sizeof(SkPoint); | 832 *texOffset = sizeof(SkPoint); |
| 831 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 833 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 832 } else if (colors) { | 834 } else if (colors) { |
| 833 *colorOffset = sizeof(SkPoint); | 835 *colorOffset = sizeof(SkPoint); |
| 834 flags |= GrDefaultGeoProcFactory::kColor_GPType; | 836 flags |= GrDefaultGeoProcFactory::kColor_GPType; |
| 835 } | 837 } |
| 836 return GrDefaultGeoProcFactory::Create(color, flags); | 838 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(color, flags
))->unref(); |
| 837 } | 839 } |
| 838 | 840 |
| 839 void GrContext::drawVertices(const GrPaint& paint, | 841 void GrContext::drawVertices(const GrPaint& paint, |
| 840 GrPrimitiveType primitiveType, | 842 GrPrimitiveType primitiveType, |
| 841 int vertexCount, | 843 int vertexCount, |
| 842 const SkPoint positions[], | 844 const SkPoint positions[], |
| 843 const SkPoint texCoords[], | 845 const SkPoint texCoords[], |
| 844 const GrColor colors[], | 846 const GrColor colors[], |
| 845 const uint16_t indices[], | 847 const uint16_t indices[], |
| 846 int indexCount) { | 848 int indexCount) { |
| 847 AutoCheckFlush acf(this); | 849 AutoCheckFlush acf(this); |
| 848 GrDrawState drawState; | 850 GrDrawState drawState; |
| 849 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e | 851 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e |
| 850 | 852 |
| 851 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 853 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
| 852 if (NULL == target) { | 854 if (NULL == target) { |
| 853 return; | 855 return; |
| 854 } | 856 } |
| 855 | 857 |
| 856 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); | 858 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
| 857 | 859 |
| 858 int colorOffset = -1, texOffset = -1; | 860 int colorOffset = -1, texOffset = -1; |
| 859 SkAutoTUnref<const GrGeometryProcessor> gp( | 861 set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffse
t, |
| 860 set_vertex_attributes(texCoords, colors, &colorOffset, &texOffset, p
aint.getColor())); | 862 paint.getColor()); |
| 861 | 863 |
| 862 size_t vertexStride = gp->getVertexStride(); | 864 size_t vertexStride = drawState.getGeometryProcessor()->getVertexStride(); |
| 863 SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkP
oint) : 0) | 865 SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkP
oint) : 0) |
| 864 + (SkToBool(colors) ? sizeof(GrColo
r) : 0)); | 866 + (SkToBool(colors) ? sizeof(GrColo
r) : 0)); |
| 865 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { | 867 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { |
| 866 SkDebugf("Failed to get space for vertices!\n"); | 868 SkDebugf("Failed to get space for vertices!\n"); |
| 867 return; | 869 return; |
| 868 } | 870 } |
| 869 void* curVertex = geo.vertices(); | 871 void* curVertex = geo.vertices(); |
| 870 | 872 |
| 871 for (int i = 0; i < vertexCount; ++i) { | 873 for (int i = 0; i < vertexCount; ++i) { |
| 872 *((SkPoint*)curVertex) = positions[i]; | 874 *((SkPoint*)curVertex) = positions[i]; |
| 873 | 875 |
| 874 if (texOffset >= 0) { | 876 if (texOffset >= 0) { |
| 875 *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i]; | 877 *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i]; |
| 876 } | 878 } |
| 877 if (colorOffset >= 0) { | 879 if (colorOffset >= 0) { |
| 878 *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i]; | 880 *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i]; |
| 879 } | 881 } |
| 880 curVertex = (void*)((intptr_t)curVertex + vertexStride); | 882 curVertex = (void*)((intptr_t)curVertex + vertexStride); |
| 881 } | 883 } |
| 882 | 884 |
| 883 // we don't currently apply offscreen AA to this path. Need improved | 885 // we don't currently apply offscreen AA to this path. Need improved |
| 884 // management of GrDrawTarget's geometry to avoid copying points per-tile. | 886 // management of GrDrawTarget's geometry to avoid copying points per-tile. |
| 885 if (indices) { | 887 if (indices) { |
| 886 uint16_t* curIndex = (uint16_t*)geo.indices(); | 888 uint16_t* curIndex = (uint16_t*)geo.indices(); |
| 887 for (int i = 0; i < indexCount; ++i) { | 889 for (int i = 0; i < indexCount; ++i) { |
| 888 curIndex[i] = indices[i]; | 890 curIndex[i] = indices[i]; |
| 889 } | 891 } |
| 890 target->drawIndexed(&drawState, gp, primitiveType, 0, 0, vertexCount, in
dexCount); | 892 target->drawIndexed(&drawState, primitiveType, 0, 0, vertexCount, indexC
ount); |
| 891 } else { | 893 } else { |
| 892 target->drawNonIndexed(&drawState, gp, primitiveType, 0, vertexCount); | 894 target->drawNonIndexed(&drawState, primitiveType, 0, vertexCount); |
| 893 } | 895 } |
| 894 } | 896 } |
| 895 | 897 |
| 896 /////////////////////////////////////////////////////////////////////////////// | 898 /////////////////////////////////////////////////////////////////////////////// |
| 897 | 899 |
| 898 void GrContext::drawRRect(const GrPaint& paint, | 900 void GrContext::drawRRect(const GrPaint& paint, |
| 899 const SkRRect& rrect, | 901 const SkRRect& rrect, |
| 900 const GrStrokeInfo& strokeInfo) { | 902 const GrStrokeInfo& strokeInfo) { |
| 901 if (rrect.isEmpty()) { | 903 if (rrect.isEmpty()) { |
| 902 return; | 904 return; |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1725 fResourceCache2->printStats(); | 1727 fResourceCache2->printStats(); |
| 1726 } | 1728 } |
| 1727 #endif | 1729 #endif |
| 1728 | 1730 |
| 1729 #if GR_GPU_STATS | 1731 #if GR_GPU_STATS |
| 1730 const GrContext::GPUStats* GrContext::gpuStats() const { | 1732 const GrContext::GPUStats* GrContext::gpuStats() const { |
| 1731 return fGpu->gpuStats(); | 1733 return fGpu->gpuStats(); |
| 1732 } | 1734 } |
| 1733 #endif | 1735 #endif |
| 1734 | 1736 |
| OLD | NEW |