| 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 19 matching lines...) Expand all Loading... |
| 30 #include "GrStencilAndCoverTextContext.h" | 30 #include "GrStencilAndCoverTextContext.h" |
| 31 #include "GrStrokeInfo.h" | 31 #include "GrStrokeInfo.h" |
| 32 #include "GrSurfacePriv.h" | 32 #include "GrSurfacePriv.h" |
| 33 #include "GrTextStrike.h" | 33 #include "GrTextStrike.h" |
| 34 #include "GrTexturePriv.h" | 34 #include "GrTexturePriv.h" |
| 35 #include "GrTraceMarker.h" | 35 #include "GrTraceMarker.h" |
| 36 #include "GrTracing.h" | 36 #include "GrTracing.h" |
| 37 #include "SkDashPathPriv.h" | 37 #include "SkDashPathPriv.h" |
| 38 #include "SkConfig8888.h" | 38 #include "SkConfig8888.h" |
| 39 #include "SkGr.h" | 39 #include "SkGr.h" |
| 40 #include "SkRTConf.h" |
| 40 #include "SkRRect.h" | 41 #include "SkRRect.h" |
| 41 #include "SkStrokeRec.h" | 42 #include "SkStrokeRec.h" |
| 42 #include "SkTLazy.h" | 43 #include "SkTLazy.h" |
| 43 #include "SkTLS.h" | 44 #include "SkTLS.h" |
| 44 #include "SkTraceEvent.h" | 45 #include "SkTraceEvent.h" |
| 45 | 46 |
| 47 // It can be useful to set this to false to test whether a bug is caused by usin
g the |
| 48 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe
r, or to make |
| 49 // debugging simpler. |
| 50 SK_CONF_DECLARE(bool, c_Defer, "gpu.deferContext", true, |
| 51 "Defers rendering in GrContext via GrInOrderDrawBuffer."); |
| 52 |
| 53 #define BUFFERED_DRAW (c_Defer ? kYes_BufferedDraw : kNo_BufferedDraw) |
| 54 |
| 46 #ifdef SK_DEBUG | 55 #ifdef SK_DEBUG |
| 47 // change this to a 1 to see notifications when partial coverage fails | 56 // change this to a 1 to see notifications when partial coverage fails |
| 48 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 | 57 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
| 49 #else | 58 #else |
| 50 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 | 59 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
| 51 #endif | 60 #endif |
| 52 | 61 |
| 53 static const size_t MAX_RESOURCE_CACHE_COUNT = GR_DEFAULT_RESOURCE_CACHE_COUNT_L
IMIT; | 62 static const size_t MAX_RESOURCE_CACHE_COUNT = GR_DEFAULT_RESOURCE_CACHE_COUNT_L
IMIT; |
| 54 static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMI
T * 1024 * 1024; | 63 static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMI
T * 1024 * 1024; |
| 55 | 64 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 fResourceCache = SkNEW_ARGS(GrResourceCache, (fGpu->caps(), | 137 fResourceCache = SkNEW_ARGS(GrResourceCache, (fGpu->caps(), |
| 129 MAX_RESOURCE_CACHE_COUNT, | 138 MAX_RESOURCE_CACHE_COUNT, |
| 130 MAX_RESOURCE_CACHE_BYTES)); | 139 MAX_RESOURCE_CACHE_BYTES)); |
| 131 fResourceCache->setOverbudgetCallback(OverbudgetCB, this); | 140 fResourceCache->setOverbudgetCallback(OverbudgetCB, this); |
| 132 fResourceCache2 = SkNEW(GrResourceCache2); | 141 fResourceCache2 = SkNEW(GrResourceCache2); |
| 133 | 142 |
| 134 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); | 143 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
| 135 | 144 |
| 136 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); | 145 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
| 137 | 146 |
| 147 fLastDrawWasBuffered = kNo_BufferedDraw; |
| 148 |
| 138 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); | 149 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); |
| 139 fOvalRenderer = SkNEW(GrOvalRenderer); | 150 fOvalRenderer = SkNEW(GrOvalRenderer); |
| 140 | 151 |
| 141 fDidTestPMConversions = false; | 152 fDidTestPMConversions = false; |
| 142 | 153 |
| 143 this->setupDrawBuffer(); | 154 this->setupDrawBuffer(); |
| 144 | 155 |
| 145 return true; | 156 return true; |
| 146 } | 157 } |
| 147 | 158 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 rtDesc.fFlags = rtDesc.fFlags | | 350 rtDesc.fFlags = rtDesc.fFlags | |
| 340 kRenderTarget_GrSurfaceFlag | | 351 kRenderTarget_GrSurfaceFlag | |
| 341 kNoStencil_GrSurfaceFlag; | 352 kNoStencil_GrSurfaceFlag; |
| 342 rtDesc.fWidth = GrNextPow2(desc.fWidth); | 353 rtDesc.fWidth = GrNextPow2(desc.fWidth); |
| 343 rtDesc.fHeight = GrNextPow2(desc.fHeight); | 354 rtDesc.fHeight = GrNextPow2(desc.fHeight); |
| 344 | 355 |
| 345 GrTexture* texture = fGpu->createTexture(rtDesc, NULL, 0); | 356 GrTexture* texture = fGpu->createTexture(rtDesc, NULL, 0); |
| 346 | 357 |
| 347 if (texture) { | 358 if (texture) { |
| 348 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); | 359 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); |
| 349 GrDrawState* drawState = fDrawBuffer->drawState(); | 360 GrDrawState* drawState = fGpu->drawState(); |
| 350 drawState->setRenderTarget(texture->asRenderTarget()); | 361 drawState->setRenderTarget(texture->asRenderTarget()); |
| 351 | 362 |
| 352 // if filtering is not desired then we want to ensure all | 363 // if filtering is not desired then we want to ensure all |
| 353 // texels in the resampled image are copies of texels from | 364 // texels in the resampled image are copies of texels from |
| 354 // the original. | 365 // the original. |
| 355 GrTextureParams params(SkShader::kClamp_TileMode, | 366 GrTextureParams params(SkShader::kClamp_TileMode, filter ? GrTexturePara
ms::kBilerp_FilterMode : |
| 356 filter ? GrTextureParams::kBilerp_FilterMode : | 367 GrTexturePara
ms::kNone_FilterMode); |
| 357 GrTextureParams::kNone_FilterMode); | |
| 358 drawState->addColorTextureProcessor(clampedTexture, SkMatrix::I(), param
s); | 368 drawState->addColorTextureProcessor(clampedTexture, SkMatrix::I(), param
s); |
| 359 | 369 |
| 360 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib
s), | 370 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib
s), |
| 361 2 * sizeof(SkPoint)); | 371 2 * sizeof(SkPoint)); |
| 362 | 372 |
| 363 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, 0); | 373 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); |
| 364 | 374 |
| 365 if (arg.succeeded()) { | 375 if (arg.succeeded()) { |
| 366 SkPoint* verts = (SkPoint*) arg.vertices(); | 376 SkPoint* verts = (SkPoint*) arg.vertices(); |
| 367 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(SkPoint)); | 377 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(SkPoint)); |
| 368 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); | 378 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); |
| 369 fDrawBuffer->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); | 379 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); |
| 370 } | 380 } |
| 371 } else { | 381 } else { |
| 372 // TODO: Our CPU stretch doesn't filter. But we create separate | 382 // TODO: Our CPU stretch doesn't filter. But we create separate |
| 373 // stretched textures when the texture params is either filtered or | 383 // stretched textures when the texture params is either filtered or |
| 374 // not. Either implement filtered stretch blit on CPU or just create | 384 // not. Either implement filtered stretch blit on CPU or just create |
| 375 // one when FBO case fails. | 385 // one when FBO case fails. |
| 376 | 386 |
| 377 rtDesc.fFlags = kNone_GrSurfaceFlags; | 387 rtDesc.fFlags = kNone_GrSurfaceFlags; |
| 378 // no longer need to clamp at min RT size. | 388 // no longer need to clamp at min RT size. |
| 379 rtDesc.fWidth = GrNextPow2(desc.fWidth); | 389 rtDesc.fWidth = GrNextPow2(desc.fWidth); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 //////////////////////////////////////////////////////////////////////////////// | 582 //////////////////////////////////////////////////////////////////////////////// |
| 573 | 583 |
| 574 void GrContext::clear(const SkIRect* rect, | 584 void GrContext::clear(const SkIRect* rect, |
| 575 const GrColor color, | 585 const GrColor color, |
| 576 bool canIgnoreRect, | 586 bool canIgnoreRect, |
| 577 GrRenderTarget* renderTarget) { | 587 GrRenderTarget* renderTarget) { |
| 578 ASSERT_OWNED_RESOURCE(renderTarget); | 588 ASSERT_OWNED_RESOURCE(renderTarget); |
| 579 AutoRestoreEffects are; | 589 AutoRestoreEffects are; |
| 580 AutoCheckFlush acf(this); | 590 AutoCheckFlush acf(this); |
| 581 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); | 591 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); |
| 582 GrDrawTarget* target = this->prepareToDraw(NULL, &are, &acf); | 592 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, &are, &acf); |
| 583 if (NULL == target) { | 593 if (NULL == target) { |
| 584 return; | 594 return; |
| 585 } | 595 } |
| 586 target->clear(rect, color, canIgnoreRect, renderTarget); | 596 target->clear(rect, color, canIgnoreRect, renderTarget); |
| 587 } | 597 } |
| 588 | 598 |
| 589 void GrContext::drawPaint(const GrPaint& origPaint) { | 599 void GrContext::drawPaint(const GrPaint& origPaint) { |
| 590 // set rect to be big enough to fill the space, but not super-huge, so we | 600 // set rect to be big enough to fill the space, but not super-huge, so we |
| 591 // don't overflow fixed-point implementations | 601 // don't overflow fixed-point implementations |
| 592 SkRect r; | 602 SkRect r; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 const GrStrokeInfo* strokeInfo) { | 715 const GrStrokeInfo* strokeInfo) { |
| 706 if (strokeInfo && strokeInfo->isDashed()) { | 716 if (strokeInfo && strokeInfo->isDashed()) { |
| 707 SkPath path; | 717 SkPath path; |
| 708 path.addRect(rect); | 718 path.addRect(rect); |
| 709 this->drawPath(paint, path, *strokeInfo); | 719 this->drawPath(paint, path, *strokeInfo); |
| 710 return; | 720 return; |
| 711 } | 721 } |
| 712 | 722 |
| 713 AutoRestoreEffects are; | 723 AutoRestoreEffects are; |
| 714 AutoCheckFlush acf(this); | 724 AutoCheckFlush acf(this); |
| 715 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); | 725 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
| 716 if (NULL == target) { | 726 if (NULL == target) { |
| 717 return; | 727 return; |
| 718 } | 728 } |
| 719 | 729 |
| 720 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); | 730 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
| 721 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); | 731 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); |
| 722 SkMatrix matrix = target->drawState()->getViewMatrix(); | 732 SkMatrix matrix = target->drawState()->getViewMatrix(); |
| 723 | 733 |
| 724 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking | 734 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking |
| 725 // cases where the RT is fully inside a stroke. | 735 // cases where the RT is fully inside a stroke. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 target->drawSimpleRect(rect); | 829 target->drawSimpleRect(rect); |
| 820 } | 830 } |
| 821 } | 831 } |
| 822 | 832 |
| 823 void GrContext::drawRectToRect(const GrPaint& paint, | 833 void GrContext::drawRectToRect(const GrPaint& paint, |
| 824 const SkRect& dstRect, | 834 const SkRect& dstRect, |
| 825 const SkRect& localRect, | 835 const SkRect& localRect, |
| 826 const SkMatrix* localMatrix) { | 836 const SkMatrix* localMatrix) { |
| 827 AutoRestoreEffects are; | 837 AutoRestoreEffects are; |
| 828 AutoCheckFlush acf(this); | 838 AutoCheckFlush acf(this); |
| 829 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); | 839 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
| 830 if (NULL == target) { | 840 if (NULL == target) { |
| 831 return; | 841 return; |
| 832 } | 842 } |
| 833 | 843 |
| 834 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 844 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
| 835 | 845 |
| 836 target->drawRect(dstRect, &localRect, localMatrix); | 846 target->drawRect(dstRect, &localRect, localMatrix); |
| 837 } | 847 } |
| 838 | 848 |
| 839 namespace { | 849 namespace { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 int vertexCount, | 895 int vertexCount, |
| 886 const SkPoint positions[], | 896 const SkPoint positions[], |
| 887 const SkPoint texCoords[], | 897 const SkPoint texCoords[], |
| 888 const GrColor colors[], | 898 const GrColor colors[], |
| 889 const uint16_t indices[], | 899 const uint16_t indices[], |
| 890 int indexCount) { | 900 int indexCount) { |
| 891 AutoRestoreEffects are; | 901 AutoRestoreEffects are; |
| 892 AutoCheckFlush acf(this); | 902 AutoCheckFlush acf(this); |
| 893 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e | 903 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e |
| 894 | 904 |
| 895 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); | 905 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
| 896 if (NULL == target) { | 906 if (NULL == target) { |
| 897 return; | 907 return; |
| 898 } | 908 } |
| 899 GrDrawState* drawState = target->drawState(); | 909 GrDrawState* drawState = target->drawState(); |
| 900 | 910 |
| 901 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); | 911 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
| 902 | 912 |
| 903 int colorOffset = -1, texOffset = -1; | 913 int colorOffset = -1, texOffset = -1; |
| 904 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset
); | 914 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset
); |
| 905 | 915 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 | 959 |
| 950 if (strokeInfo.isDashed()) { | 960 if (strokeInfo.isDashed()) { |
| 951 SkPath path; | 961 SkPath path; |
| 952 path.addRRect(rrect); | 962 path.addRRect(rrect); |
| 953 this->drawPath(paint, path, strokeInfo); | 963 this->drawPath(paint, path, strokeInfo); |
| 954 return; | 964 return; |
| 955 } | 965 } |
| 956 | 966 |
| 957 AutoRestoreEffects are; | 967 AutoRestoreEffects are; |
| 958 AutoCheckFlush acf(this); | 968 AutoCheckFlush acf(this); |
| 959 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); | 969 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
| 960 if (NULL == target) { | 970 if (NULL == target) { |
| 961 return; | 971 return; |
| 962 } | 972 } |
| 963 | 973 |
| 964 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); | 974 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
| 965 | 975 |
| 966 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 976 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 967 | 977 |
| 968 if (!fOvalRenderer->drawRRect(target, this, paint.isAntiAlias(), rrect, stro
keRec)) { | 978 if (!fOvalRenderer->drawRRect(target, this, paint.isAntiAlias(), rrect, stro
keRec)) { |
| 969 SkPath path; | 979 SkPath path; |
| 970 path.addRRect(rrect); | 980 path.addRRect(rrect); |
| 971 this->internalDrawPath(target, paint.isAntiAlias(), path, strokeInfo); | 981 this->internalDrawPath(target, paint.isAntiAlias(), path, strokeInfo); |
| 972 } | 982 } |
| 973 } | 983 } |
| 974 | 984 |
| 975 /////////////////////////////////////////////////////////////////////////////// | 985 /////////////////////////////////////////////////////////////////////////////// |
| 976 | 986 |
| 977 void GrContext::drawDRRect(const GrPaint& paint, | 987 void GrContext::drawDRRect(const GrPaint& paint, |
| 978 const SkRRect& outer, | 988 const SkRRect& outer, |
| 979 const SkRRect& inner) { | 989 const SkRRect& inner) { |
| 980 if (outer.isEmpty()) { | 990 if (outer.isEmpty()) { |
| 981 return; | 991 return; |
| 982 } | 992 } |
| 983 | 993 |
| 984 AutoRestoreEffects are; | 994 AutoRestoreEffects are; |
| 985 AutoCheckFlush acf(this); | 995 AutoCheckFlush acf(this); |
| 986 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); | 996 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
| 987 | 997 |
| 988 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); | 998 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
| 989 | 999 |
| 990 if (!fOvalRenderer->drawDRRect(target, this, paint.isAntiAlias(), outer, inn
er)) { | 1000 if (!fOvalRenderer->drawDRRect(target, this, paint.isAntiAlias(), outer, inn
er)) { |
| 991 SkPath path; | 1001 SkPath path; |
| 992 path.addRRect(inner); | 1002 path.addRRect(inner); |
| 993 path.addRRect(outer); | 1003 path.addRRect(outer); |
| 994 path.setFillType(SkPath::kEvenOdd_FillType); | 1004 path.setFillType(SkPath::kEvenOdd_FillType); |
| 995 | 1005 |
| 996 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); | 1006 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1009 | 1019 |
| 1010 if (strokeInfo.isDashed()) { | 1020 if (strokeInfo.isDashed()) { |
| 1011 SkPath path; | 1021 SkPath path; |
| 1012 path.addOval(oval); | 1022 path.addOval(oval); |
| 1013 this->drawPath(paint, path, strokeInfo); | 1023 this->drawPath(paint, path, strokeInfo); |
| 1014 return; | 1024 return; |
| 1015 } | 1025 } |
| 1016 | 1026 |
| 1017 AutoRestoreEffects are; | 1027 AutoRestoreEffects are; |
| 1018 AutoCheckFlush acf(this); | 1028 AutoCheckFlush acf(this); |
| 1019 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); | 1029 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
| 1020 if (NULL == target) { | 1030 if (NULL == target) { |
| 1021 return; | 1031 return; |
| 1022 } | 1032 } |
| 1023 | 1033 |
| 1024 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); | 1034 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
| 1025 | 1035 |
| 1026 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 1036 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 1027 | 1037 |
| 1028 | 1038 |
| 1029 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke
Rec)) { | 1039 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke
Rec)) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 this->drawPaint(paint); | 1107 this->drawPaint(paint); |
| 1098 } | 1108 } |
| 1099 return; | 1109 return; |
| 1100 } | 1110 } |
| 1101 | 1111 |
| 1102 if (strokeInfo.isDashed()) { | 1112 if (strokeInfo.isDashed()) { |
| 1103 SkPoint pts[2]; | 1113 SkPoint pts[2]; |
| 1104 if (path.isLine(pts)) { | 1114 if (path.isLine(pts)) { |
| 1105 AutoRestoreEffects are; | 1115 AutoRestoreEffects are; |
| 1106 AutoCheckFlush acf(this); | 1116 AutoCheckFlush acf(this); |
| 1107 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); | 1117 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &a
re, &acf); |
| 1108 if (NULL == target) { | 1118 if (NULL == target) { |
| 1109 return; | 1119 return; |
| 1110 } | 1120 } |
| 1111 GrDrawState* drawState = target->drawState(); | 1121 GrDrawState* drawState = target->drawState(); |
| 1112 | 1122 |
| 1113 SkMatrix origViewMatrix = drawState->getViewMatrix(); | 1123 SkMatrix origViewMatrix = drawState->getViewMatrix(); |
| 1114 GrDrawState::AutoViewMatrixRestore avmr; | 1124 GrDrawState::AutoViewMatrixRestore avmr; |
| 1115 if (avmr.setIdentity(target->drawState())) { | 1125 if (avmr.setIdentity(target->drawState())) { |
| 1116 if (GrDashingEffect::DrawDashLine(pts, paint, strokeInfo, fGpu,
target, | 1126 if (GrDashingEffect::DrawDashLine(pts, paint, strokeInfo, fGpu,
target, |
| 1117 origViewMatrix)) { | 1127 origViewMatrix)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1134 return; | 1144 return; |
| 1135 } | 1145 } |
| 1136 | 1146 |
| 1137 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 1147 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. |
| 1138 // Scratch textures can be recycled after they are returned to the texture | 1148 // Scratch textures can be recycled after they are returned to the texture |
| 1139 // cache. This presents a potential hazard for buffered drawing. However, | 1149 // cache. This presents a potential hazard for buffered drawing. However, |
| 1140 // the writePixels that uploads to the scratch will perform a flush so we're | 1150 // the writePixels that uploads to the scratch will perform a flush so we're |
| 1141 // OK. | 1151 // OK. |
| 1142 AutoRestoreEffects are; | 1152 AutoRestoreEffects are; |
| 1143 AutoCheckFlush acf(this); | 1153 AutoCheckFlush acf(this); |
| 1144 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); | 1154 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
| 1145 if (NULL == target) { | 1155 if (NULL == target) { |
| 1146 return; | 1156 return; |
| 1147 } | 1157 } |
| 1148 GrDrawState* drawState = target->drawState(); | 1158 GrDrawState* drawState = target->drawState(); |
| 1149 | 1159 |
| 1150 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC
onvex()); | 1160 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC
onvex()); |
| 1151 | 1161 |
| 1152 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 1162 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 1153 | 1163 |
| 1154 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i
sMultisampled(); | 1164 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i
sMultisampled(); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 } | 1367 } |
| 1358 | 1368 |
| 1359 SkMatrix matrix; | 1369 SkMatrix matrix; |
| 1360 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 1370 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 1361 | 1371 |
| 1362 // This function can be called in the midst of drawing another object (e.g.,
when uploading a | 1372 // This function can be called in the midst of drawing another object (e.g.,
when uploading a |
| 1363 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before | 1373 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before |
| 1364 // drawing a rect to the render target. | 1374 // drawing a rect to the render target. |
| 1365 // The bracket ensures we pop the stack if we wind up flushing below. | 1375 // The bracket ensures we pop the stack if we wind up flushing below. |
| 1366 { | 1376 { |
| 1367 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL); | 1377 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, kYes_BufferedDraw,
NULL, NULL); |
| 1368 GrDrawTarget::AutoGeometryAndStatePush agasp(drawTarget, GrDrawTarget::k
Reset_ASRInit, | 1378 GrDrawTarget::AutoGeometryAndStatePush agasp(drawTarget, GrDrawTarget::k
Reset_ASRInit, |
| 1369 &matrix); | 1379 &matrix); |
| 1370 GrDrawState* drawState = drawTarget->drawState(); | 1380 GrDrawState* drawState = drawTarget->drawState(); |
| 1371 drawState->addColorProcessor(fp); | 1381 drawState->addColorProcessor(fp); |
| 1372 drawState->setRenderTarget(renderTarget); | 1382 drawState->setRenderTarget(renderTarget); |
| 1373 drawState->disableState(GrDrawState::kClip_StateBit); | 1383 drawState->disableState(GrDrawState::kClip_StateBit); |
| 1374 drawTarget->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToS
calar(height))); | 1384 drawTarget->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToS
calar(height))); |
| 1375 } | 1385 } |
| 1376 | 1386 |
| 1377 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 1387 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 if (!fp) { | 1491 if (!fp) { |
| 1482 fp.reset(GrConfigConversionEffect::Create( | 1492 fp.reset(GrConfigConversionEffect::Create( |
| 1483 src, swapRAndB, GrConfigConversionEffect::kNone_PMCo
nversion, | 1493 src, swapRAndB, GrConfigConversionEffect::kNone_PMCo
nversion, |
| 1484 textureMatrix)); | 1494 textureMatrix)); |
| 1485 } | 1495 } |
| 1486 swapRAndB = false; // we will handle the swap in the draw. | 1496 swapRAndB = false; // we will handle the swap in the draw. |
| 1487 | 1497 |
| 1488 // We protect the existing geometry here since it may not be | 1498 // We protect the existing geometry here since it may not be |
| 1489 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) | 1499 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) |
| 1490 // can be invoked in this method | 1500 // can be invoked in this method |
| 1491 { | 1501 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget:
:kReset_ASRInit); |
| 1492 GrDrawTarget::AutoGeometryAndStatePush agasp(fDrawBuffer, | 1502 GrDrawState* drawState = fGpu->drawState(); |
| 1493 GrDrawTarget::k
Reset_ASRInit); | 1503 SkASSERT(fp); |
| 1494 GrDrawState* drawState = fDrawBuffer->drawState(); | 1504 drawState->addColorProcessor(fp); |
| 1495 SkASSERT(fp); | |
| 1496 drawState->addColorProcessor(fp); | |
| 1497 | 1505 |
| 1498 drawState->setRenderTarget(texture->asRenderTarget()); | 1506 drawState->setRenderTarget(texture->asRenderTarget()); |
| 1499 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc
alar(height)); | 1507 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); |
| 1500 fDrawBuffer->drawSimpleRect(rect); | 1508 fGpu->drawSimpleRect(rect); |
| 1501 // we want to read back from the scratch's origin | 1509 // we want to read back from the scratch's origin |
| 1502 left = 0; | 1510 left = 0; |
| 1503 top = 0; | 1511 top = 0; |
| 1504 target = texture->asRenderTarget(); | 1512 target = texture->asRenderTarget(); |
| 1505 } | |
| 1506 this->flushSurfaceWrites(target); | |
| 1507 } | 1513 } |
| 1508 } | 1514 } |
| 1509 } | 1515 } |
| 1510 | |
| 1511 if (!fGpu->readPixels(target, | 1516 if (!fGpu->readPixels(target, |
| 1512 left, top, width, height, | 1517 left, top, width, height, |
| 1513 readConfig, buffer, rowBytes)) { | 1518 readConfig, buffer, rowBytes)) { |
| 1514 return false; | 1519 return false; |
| 1515 } | 1520 } |
| 1516 // Perform any conversions we weren't able to perform using a scratch textur
e. | 1521 // Perform any conversions we weren't able to perform using a scratch textur
e. |
| 1517 if (unpremul || swapRAndB) { | 1522 if (unpremul || swapRAndB) { |
| 1518 SkDstPixelInfo dstPI; | 1523 SkDstPixelInfo dstPI; |
| 1519 if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) { | 1524 if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) { |
| 1520 return false; | 1525 return false; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1544 if (fGpu) { | 1549 if (fGpu) { |
| 1545 fGpu->resolveRenderTarget(target); | 1550 fGpu->resolveRenderTarget(target); |
| 1546 } | 1551 } |
| 1547 } | 1552 } |
| 1548 | 1553 |
| 1549 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { | 1554 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { |
| 1550 SkASSERT(renderTarget); | 1555 SkASSERT(renderTarget); |
| 1551 ASSERT_OWNED_RESOURCE(renderTarget); | 1556 ASSERT_OWNED_RESOURCE(renderTarget); |
| 1552 AutoRestoreEffects are; | 1557 AutoRestoreEffects are; |
| 1553 AutoCheckFlush acf(this); | 1558 AutoCheckFlush acf(this); |
| 1554 GrDrawTarget* target = this->prepareToDraw(NULL, &are, &acf); | 1559 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, &are, &acf); |
| 1555 if (NULL == target) { | 1560 if (NULL == target) { |
| 1556 return; | 1561 return; |
| 1557 } | 1562 } |
| 1558 target->discard(renderTarget); | 1563 target->discard(renderTarget); |
| 1559 } | 1564 } |
| 1560 | 1565 |
| 1561 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
ct, | 1566 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
ct, |
| 1562 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { | 1567 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { |
| 1563 if (NULL == src || NULL == dst) { | 1568 if (NULL == src || NULL == dst) { |
| 1564 return; | 1569 return; |
| 1565 } | 1570 } |
| 1566 ASSERT_OWNED_RESOURCE(src); | 1571 ASSERT_OWNED_RESOURCE(src); |
| 1567 ASSERT_OWNED_RESOURCE(dst); | 1572 ASSERT_OWNED_RESOURCE(dst); |
| 1568 | 1573 |
| 1569 // Since we're going to the draw target and not GPU, no need to check kNoFlu
sh | 1574 // Since we're going to the draw target and not GPU, no need to check kNoFlu
sh |
| 1570 // here. | 1575 // here. |
| 1571 | 1576 |
| 1572 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL); | 1577 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, NULL, NULL); |
| 1573 if (NULL == target) { | 1578 if (NULL == target) { |
| 1574 return; | 1579 return; |
| 1575 } | 1580 } |
| 1576 target->copySurface(dst, src, srcRect, dstPoint); | 1581 target->copySurface(dst, src, srcRect, dstPoint); |
| 1577 | 1582 |
| 1578 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 1583 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 1579 this->flush(); | 1584 this->flush(); |
| 1580 } | 1585 } |
| 1581 } | 1586 } |
| 1582 | 1587 |
| 1583 void GrContext::flushSurfaceWrites(GrSurface* surface) { | 1588 void GrContext::flushSurfaceWrites(GrSurface* surface) { |
| 1584 if (surface->surfacePriv().hasPendingWrite()) { | 1589 if (surface->surfacePriv().hasPendingWrite()) { |
| 1585 this->flush(); | 1590 this->flush(); |
| 1586 } | 1591 } |
| 1587 } | 1592 } |
| 1588 | 1593 |
| 1589 //////////////////////////////////////////////////////////////////////////////// | 1594 //////////////////////////////////////////////////////////////////////////////// |
| 1590 | 1595 |
| 1591 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, | 1596 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, |
| 1597 BufferedDraw buffered, |
| 1592 AutoRestoreEffects* are, | 1598 AutoRestoreEffects* are, |
| 1593 AutoCheckFlush* acf) { | 1599 AutoCheckFlush* acf) { |
| 1594 // All users of this draw state should be freeing up all effects when they'r
e done. | 1600 // All users of this draw state should be freeing up all effects when they'r
e done. |
| 1595 // Otherwise effects that own resources may keep those resources alive indef
initely. | 1601 // Otherwise effects that own resources may keep those resources alive indef
initely. |
| 1596 SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt
ages() && | 1602 SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt
ages() && |
| 1597 !fDrawState->hasGeometryProcessor()); | 1603 !fDrawState->hasGeometryProcessor()); |
| 1598 | 1604 |
| 1599 if (NULL == fGpu) { | 1605 if (NULL == fGpu) { |
| 1600 return NULL; | 1606 return NULL; |
| 1601 } | 1607 } |
| 1602 | 1608 |
| 1609 if (kNo_BufferedDraw == buffered && kYes_BufferedDraw == fLastDrawWasBuffere
d) { |
| 1610 fDrawBuffer->flush(); |
| 1611 fLastDrawWasBuffered = kNo_BufferedDraw; |
| 1612 } |
| 1603 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); | 1613 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); |
| 1604 if (paint) { | 1614 if (paint) { |
| 1605 SkASSERT(are); | 1615 SkASSERT(are); |
| 1606 SkASSERT(acf); | 1616 SkASSERT(acf); |
| 1607 are->set(fDrawState); | 1617 are->set(fDrawState); |
| 1608 fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); | 1618 fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); |
| 1609 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK | 1619 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK |
| 1610 if ((paint->hasMask() || 0xff != paint->fCoverage) && | 1620 if ((paint->hasMask() || 0xff != paint->fCoverage) && |
| 1611 !fDrawState->couldApplyCoverage(fGpu->caps())) { | 1621 !fDrawState->couldApplyCoverage(fGpu->caps())) { |
| 1612 GrPrintf("Partial pixel coverage will be incorrectly blended.\n"); | 1622 GrPrintf("Partial pixel coverage will be incorrectly blended.\n"); |
| 1613 } | 1623 } |
| 1614 #endif | 1624 #endif |
| 1615 // Clear any vertex attributes configured for the previous use of the | 1625 // Clear any vertex attributes configured for the previous use of the |
| 1616 // GrDrawState which can effect which blend optimizations are in effect. | 1626 // GrDrawState which can effect which blend optimizations are in effect. |
| 1617 fDrawState->setDefaultVertexAttribs(); | 1627 fDrawState->setDefaultVertexAttribs(); |
| 1618 } else { | 1628 } else { |
| 1619 fDrawState->reset(fViewMatrix); | 1629 fDrawState->reset(fViewMatrix); |
| 1620 fDrawState->setRenderTarget(fRenderTarget.get()); | 1630 fDrawState->setRenderTarget(fRenderTarget.get()); |
| 1621 } | 1631 } |
| 1632 GrDrawTarget* target; |
| 1633 if (kYes_BufferedDraw == buffered) { |
| 1634 fLastDrawWasBuffered = kYes_BufferedDraw; |
| 1635 target = fDrawBuffer; |
| 1636 } else { |
| 1637 SkASSERT(kNo_BufferedDraw == buffered); |
| 1638 fLastDrawWasBuffered = kNo_BufferedDraw; |
| 1639 target = fGpu; |
| 1640 } |
| 1622 fDrawState->setState(GrDrawState::kClip_StateBit, fClip && | 1641 fDrawState->setState(GrDrawState::kClip_StateBit, fClip && |
| 1623 !fClip->fClipStack->isWideO
pen()); | 1642 !fClip->fClipStack->isWideO
pen()); |
| 1624 fDrawBuffer->setClip(fClip); | 1643 target->setClip(fClip); |
| 1625 SkASSERT(fDrawState == fDrawBuffer->drawState()); | 1644 SkASSERT(fDrawState == target->drawState()); |
| 1626 return fDrawBuffer; | 1645 return target; |
| 1627 } | 1646 } |
| 1628 | 1647 |
| 1629 /* | 1648 /* |
| 1630 * This method finds a path renderer that can draw the specified path on | 1649 * This method finds a path renderer that can draw the specified path on |
| 1631 * the provided target. | 1650 * the provided target. |
| 1632 * Due to its expense, the software path renderer has split out so it can | 1651 * Due to its expense, the software path renderer has split out so it can |
| 1633 * can be individually allowed/disallowed via the "allowSW" boolean. | 1652 * can be individually allowed/disallowed via the "allowSW" boolean. |
| 1634 */ | 1653 */ |
| 1635 GrPathRenderer* GrContext::getPathRenderer(const SkPath& path, | 1654 GrPathRenderer* GrContext::getPathRenderer(const SkPath& path, |
| 1636 const SkStrokeRec& stroke, | 1655 const SkStrokeRec& stroke, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1696 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); | 1715 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); |
| 1697 | 1716 |
| 1698 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, | 1717 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, |
| 1699 fDrawBufferVBAllocPool, | 1718 fDrawBufferVBAllocPool, |
| 1700 fDrawBufferIBAllocPool)); | 1719 fDrawBufferIBAllocPool)); |
| 1701 | 1720 |
| 1702 fDrawBuffer->setDrawState(fDrawState); | 1721 fDrawBuffer->setDrawState(fDrawState); |
| 1703 } | 1722 } |
| 1704 | 1723 |
| 1705 GrDrawTarget* GrContext::getTextTarget() { | 1724 GrDrawTarget* GrContext::getTextTarget() { |
| 1706 return this->prepareToDraw(NULL, NULL, NULL); | 1725 return this->prepareToDraw(NULL, BUFFERED_DRAW, NULL, NULL); |
| 1707 } | 1726 } |
| 1708 | 1727 |
| 1709 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { | 1728 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { |
| 1710 return fGpu->getQuadIndexBuffer(); | 1729 return fGpu->getQuadIndexBuffer(); |
| 1711 } | 1730 } |
| 1712 | 1731 |
| 1713 namespace { | 1732 namespace { |
| 1714 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { | 1733 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| 1715 GrConfigConversionEffect::PMConversion pmToUPM; | 1734 GrConfigConversionEffect::PMConversion pmToUPM; |
| 1716 GrConfigConversionEffect::PMConversion upmToPM; | 1735 GrConfigConversionEffect::PMConversion upmToPM; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1782 fResourceCache->printStats(); | 1801 fResourceCache->printStats(); |
| 1783 } | 1802 } |
| 1784 #endif | 1803 #endif |
| 1785 | 1804 |
| 1786 #if GR_GPU_STATS | 1805 #if GR_GPU_STATS |
| 1787 const GrContext::GPUStats* GrContext::gpuStats() const { | 1806 const GrContext::GPUStats* GrContext::gpuStats() const { |
| 1788 return fGpu->gpuStats(); | 1807 return fGpu->gpuStats(); |
| 1789 } | 1808 } |
| 1790 #endif | 1809 #endif |
| 1791 | 1810 |
| OLD | NEW |