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