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

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

Issue 791743003: Remove GP from drawstate, revision of invariant output for GP (Closed) Base URL: https://skia.googlesource.com/skia.git@color-to-gp
Patch Set: more windows fix 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(GrColor_ WHITE, flags); 318 SkAutoTUnref<const GrGeometryProcessor> gp(
319 drawState.setGeometryProcessor(gp)->unref(); 319 GrDefaultGeoProcFactory::Create(GrColor_WHITE, flags));
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, kTriangleFan_GrPrimitiveType , 0, 4); 328 fDrawBuffer->drawNonIndexed(&drawState, gp, kTriangleFan_GrPrimitive Type, 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
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 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(color); 761 SkAutoTUnref<const GrGeometryProcessor> gp(GrDefaultGeoProcFactory::Crea te(color));
762 drawState.setGeometryProcessor(gp)->unref();
763 GrDrawTarget::AutoReleaseGeometry geo(target, 762 GrDrawTarget::AutoReleaseGeometry geo(target,
764 worstCaseVertCount, 763 worstCaseVertCount,
765 gp->getVertexStride(), 764 gp->getVertexStride(),
766 0); 765 0);
767 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); 766 SkASSERT(gp->getVertexStride() == sizeof(SkPoint));
768 767
769 if (!geo.succeeded()) { 768 if (!geo.succeeded()) {
770 SkDebugf("Failed to get space for vertices!\n"); 769 SkDebugf("Failed to get space for vertices!\n");
771 return; 770 return;
772 } 771 }
(...skipping 10 matching lines...) Expand all
783 // hairline 782 // hairline
784 vertCount = 5; 783 vertCount = 5;
785 primType = kLineStrip_GrPrimitiveType; 784 primType = kLineStrip_GrPrimitiveType;
786 vertex[0].set(rect.fLeft, rect.fTop); 785 vertex[0].set(rect.fLeft, rect.fTop);
787 vertex[1].set(rect.fRight, rect.fTop); 786 vertex[1].set(rect.fRight, rect.fTop);
788 vertex[2].set(rect.fRight, rect.fBottom); 787 vertex[2].set(rect.fRight, rect.fBottom);
789 vertex[3].set(rect.fLeft, rect.fBottom); 788 vertex[3].set(rect.fLeft, rect.fBottom);
790 vertex[4].set(rect.fLeft, rect.fTop); 789 vertex[4].set(rect.fLeft, rect.fTop);
791 } 790 }
792 791
793 target->drawNonIndexed(&drawState, primType, 0, vertCount); 792 target->drawNonIndexed(&drawState, gp, primType, 0, vertCount);
794 } else { 793 } else {
795 // filled BW rect 794 // filled BW rect
796 target->drawSimpleRect(&drawState, color, rect); 795 target->drawSimpleRect(&drawState, color, rect);
797 } 796 }
798 } 797 }
799 798
800 void GrContext::drawRectToRect(const GrPaint& paint, 799 void GrContext::drawRectToRect(const GrPaint& paint,
801 const SkRect& dstRect, 800 const SkRect& dstRect,
802 const SkRect& localRect, 801 const SkRect& localRect,
803 const SkMatrix* localMatrix) { 802 const SkMatrix* localMatrix) {
804 AutoCheckFlush acf(this); 803 AutoCheckFlush acf(this);
805 GrDrawState drawState; 804 GrDrawState drawState;
806 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); 805 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
807 if (NULL == target) { 806 if (NULL == target) {
808 return; 807 return;
809 } 808 }
810 809
811 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); 810 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target);
812 811
813 target->drawRect(&drawState, paint.getColor(), dstRect, &localRect, localMat rix); 812 target->drawRect(&drawState, paint.getColor(), dstRect, &localRect, localMat rix);
814 } 813 }
815 814
816 static void set_vertex_attributes(GrDrawState* drawState, 815 static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords ,
817 const SkPoint* texCoords, 816 const GrColor* colors,
818 const GrColor* colors, 817 int* colorOffset,
819 int* colorOffset, 818 int* texOffset,
820 int* texOffset, 819 GrColor color) {
821 GrColor color) {
822 *texOffset = -1; 820 *texOffset = -1;
823 *colorOffset = -1; 821 *colorOffset = -1;
824 822
825 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; 823 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType;
826 if (texCoords && colors) { 824 if (texCoords && colors) {
827 *colorOffset = sizeof(SkPoint); 825 *colorOffset = sizeof(SkPoint);
828 *texOffset = sizeof(SkPoint) + sizeof(GrColor); 826 *texOffset = sizeof(SkPoint) + sizeof(GrColor);
829 flags |= GrDefaultGeoProcFactory::kColor_GPType | 827 flags |= GrDefaultGeoProcFactory::kColor_GPType |
830 GrDefaultGeoProcFactory::kLocalCoord_GPType; 828 GrDefaultGeoProcFactory::kLocalCoord_GPType;
831 } else if (texCoords) { 829 } else if (texCoords) {
832 *texOffset = sizeof(SkPoint); 830 *texOffset = sizeof(SkPoint);
833 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; 831 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType;
834 } else if (colors) { 832 } else if (colors) {
835 *colorOffset = sizeof(SkPoint); 833 *colorOffset = sizeof(SkPoint);
836 flags |= GrDefaultGeoProcFactory::kColor_GPType; 834 flags |= GrDefaultGeoProcFactory::kColor_GPType;
837 } 835 }
838 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(color, flags ))->unref(); 836 return GrDefaultGeoProcFactory::Create(color, flags);
839 } 837 }
840 838
841 void GrContext::drawVertices(const GrPaint& paint, 839 void GrContext::drawVertices(const GrPaint& paint,
842 GrPrimitiveType primitiveType, 840 GrPrimitiveType primitiveType,
843 int vertexCount, 841 int vertexCount,
844 const SkPoint positions[], 842 const SkPoint positions[],
845 const SkPoint texCoords[], 843 const SkPoint texCoords[],
846 const GrColor colors[], 844 const GrColor colors[],
847 const uint16_t indices[], 845 const uint16_t indices[],
848 int indexCount) { 846 int indexCount) {
849 AutoCheckFlush acf(this); 847 AutoCheckFlush acf(this);
850 GrDrawState drawState; 848 GrDrawState drawState;
851 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e 849 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e
852 850
853 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); 851 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
854 if (NULL == target) { 852 if (NULL == target) {
855 return; 853 return;
856 } 854 }
857 855
858 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); 856 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target);
859 857
860 int colorOffset = -1, texOffset = -1; 858 int colorOffset = -1, texOffset = -1;
861 set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffse t, 859 SkAutoTUnref<const GrGeometryProcessor> gp(
862 paint.getColor()); 860 set_vertex_attributes(texCoords, colors, &colorOffset, &texOffset, p aint.getColor()));
863 861
864 size_t vertexStride = drawState.getGeometryProcessor()->getVertexStride(); 862 size_t vertexStride = gp->getVertexStride();
865 SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkP oint) : 0) 863 SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkP oint) : 0)
866 + (SkToBool(colors) ? sizeof(GrColo r) : 0)); 864 + (SkToBool(colors) ? sizeof(GrColo r) : 0));
867 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { 865 if (!geo.set(target, vertexCount, vertexStride, indexCount)) {
868 SkDebugf("Failed to get space for vertices!\n"); 866 SkDebugf("Failed to get space for vertices!\n");
869 return; 867 return;
870 } 868 }
871 void* curVertex = geo.vertices(); 869 void* curVertex = geo.vertices();
872 870
873 for (int i = 0; i < vertexCount; ++i) { 871 for (int i = 0; i < vertexCount; ++i) {
874 *((SkPoint*)curVertex) = positions[i]; 872 *((SkPoint*)curVertex) = positions[i];
875 873
876 if (texOffset >= 0) { 874 if (texOffset >= 0) {
877 *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i]; 875 *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i];
878 } 876 }
879 if (colorOffset >= 0) { 877 if (colorOffset >= 0) {
880 *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i]; 878 *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i];
881 } 879 }
882 curVertex = (void*)((intptr_t)curVertex + vertexStride); 880 curVertex = (void*)((intptr_t)curVertex + vertexStride);
883 } 881 }
884 882
885 // we don't currently apply offscreen AA to this path. Need improved 883 // we don't currently apply offscreen AA to this path. Need improved
886 // management of GrDrawTarget's geometry to avoid copying points per-tile. 884 // management of GrDrawTarget's geometry to avoid copying points per-tile.
887 if (indices) { 885 if (indices) {
888 uint16_t* curIndex = (uint16_t*)geo.indices(); 886 uint16_t* curIndex = (uint16_t*)geo.indices();
889 for (int i = 0; i < indexCount; ++i) { 887 for (int i = 0; i < indexCount; ++i) {
890 curIndex[i] = indices[i]; 888 curIndex[i] = indices[i];
891 } 889 }
892 target->drawIndexed(&drawState, primitiveType, 0, 0, vertexCount, indexC ount); 890 target->drawIndexed(&drawState, gp, primitiveType, 0, 0, vertexCount, in dexCount);
893 } else { 891 } else {
894 target->drawNonIndexed(&drawState, primitiveType, 0, vertexCount); 892 target->drawNonIndexed(&drawState, gp, primitiveType, 0, vertexCount);
895 } 893 }
896 } 894 }
897 895
898 /////////////////////////////////////////////////////////////////////////////// 896 ///////////////////////////////////////////////////////////////////////////////
899 897
900 void GrContext::drawRRect(const GrPaint& paint, 898 void GrContext::drawRRect(const GrPaint& paint,
901 const SkRRect& rrect, 899 const SkRRect& rrect,
902 const GrStrokeInfo& strokeInfo) { 900 const GrStrokeInfo& strokeInfo) {
903 if (rrect.isEmpty()) { 901 if (rrect.isEmpty()) {
904 return; 902 return;
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 fResourceCache2->printStats(); 1725 fResourceCache2->printStats();
1728 } 1726 }
1729 #endif 1727 #endif
1730 1728
1731 #if GR_GPU_STATS 1729 #if GR_GPU_STATS
1732 const GrContext::GPUStats* GrContext::gpuStats() const { 1730 const GrContext::GPUStats* GrContext::gpuStats() const {
1733 return fGpu->gpuStats(); 1731 return fGpu->gpuStats();
1734 } 1732 }
1735 #endif 1733 #endif
1736 1734
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