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

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

Issue 2081383006: Use GrShape in GrPathRenderer. (Closed) Base URL: https://chromium.googlesource.com/skia.git@shapemembers
Patch Set: Address comments Created 4 years, 6 months 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/GrClipMaskManager.cpp ('k') | src/gpu/GrPathRenderer.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 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrBatchTest.h" 8 #include "GrBatchTest.h"
9 #include "GrColor.h" 9 #include "GrColor.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 // aa. If we have some future driver-mojo path AA that can do the right 918 // aa. If we have some future driver-mojo path AA that can do the right
919 // thing WRT to the blend then we'll need some query on the PR. 919 // thing WRT to the blend then we'll need some query on the PR.
920 bool useCoverageAA = doAA && !fDrawContext->fRenderTarget->isUnifiedMultisam pled(); 920 bool useCoverageAA = doAA && !fDrawContext->fRenderTarget->isUnifiedMultisam pled();
921 bool hasUserStencilSettings = !ss->isUnused(); 921 bool hasUserStencilSettings = !ss->isUnused();
922 bool isStencilBufferMSAA = fDrawContext->fRenderTarget->isStencilBufferMulti sampled(); 922 bool isStencilBufferMSAA = fDrawContext->fRenderTarget->isStencilBufferMulti sampled();
923 923
924 const GrPathRendererChain::DrawType type = 924 const GrPathRendererChain::DrawType type =
925 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType 925 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType
926 : GrPathRendererChain::kColor_DrawType; 926 : GrPathRendererChain::kColor_DrawType;
927 927
928 GrShape shape(path, GrStyle::SimpleFill());
928 GrPathRenderer::CanDrawPathArgs canDrawArgs; 929 GrPathRenderer::CanDrawPathArgs canDrawArgs;
929 canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps( )->shaderCaps(); 930 canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps( )->shaderCaps();
930 canDrawArgs.fViewMatrix = &viewMatrix; 931 canDrawArgs.fViewMatrix = &viewMatrix;
931 canDrawArgs.fPath = &path; 932 canDrawArgs.fShape = &shape;
932 canDrawArgs.fStyle = &GrStyle::SimpleFill();
933 canDrawArgs.fAntiAlias = useCoverageAA; 933 canDrawArgs.fAntiAlias = useCoverageAA;
934 canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; 934 canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings;
935 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; 935 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA;
936 936
937 // Don't allow the SW renderer 937 // Don't allow the SW renderer
938 GrPathRenderer* pr = fDrawContext->fDrawingManager->getPathRenderer(canDrawA rgs, false, type); 938 GrPathRenderer* pr = fDrawContext->fDrawingManager->getPathRenderer(canDrawA rgs, false, type);
939 if (!pr) { 939 if (!pr) {
940 return false; 940 return false;
941 } 941 }
942 942
943 GrPaint paint; 943 GrPaint paint;
944 paint.setCoverageSetOpXPFactory(op, invert); 944 paint.setCoverageSetOpXPFactory(op, invert);
945 945
946 GrPathRenderer::DrawPathArgs args; 946 GrPathRenderer::DrawPathArgs args;
947 args.fResourceProvider = fDrawContext->fDrawingManager->getContext()->resour ceProvider(); 947 args.fResourceProvider = fDrawContext->fDrawingManager->getContext()->resour ceProvider();
948 args.fPaint = &paint; 948 args.fPaint = &paint;
949 args.fUserStencilSettings = ss; 949 args.fUserStencilSettings = ss;
950 args.fDrawContext = fDrawContext; 950 args.fDrawContext = fDrawContext;
951 args.fClip = &clip; 951 args.fClip = &clip;
952 args.fColor = GrColor_WHITE; 952 args.fColor = GrColor_WHITE;
953 args.fViewMatrix = &viewMatrix; 953 args.fViewMatrix = &viewMatrix;
954 args.fPath = &path; 954 args.fShape = &shape;
955 args.fStyle = &GrStyle::SimpleFill();
956 args.fAntiAlias = useCoverageAA; 955 args.fAntiAlias = useCoverageAA;
957 args.fGammaCorrect = fDrawContext->isGammaCorrect(); 956 args.fGammaCorrect = fDrawContext->isGammaCorrect();
958 pr->drawPath(args); 957 pr->drawPath(args);
959 return true; 958 return true;
960 } 959 }
961 960
962 void GrDrawContext::internalDrawPath(const GrClip& clip, 961 void GrDrawContext::internalDrawPath(const GrClip& clip,
963 const GrPaint& paint, 962 const GrPaint& paint,
964 const SkMatrix& viewMatrix, 963 const SkMatrix& viewMatrix,
965 const SkPath& origPath, 964 const SkPath& path,
966 const GrStyle& origStyle) { 965 const GrStyle& style) {
967 ASSERT_SINGLE_OWNER 966 ASSERT_SINGLE_OWNER
968 RETURN_IF_ABANDONED 967 RETURN_IF_ABANDONED
969 SkASSERT(!origPath.isEmpty()); 968 SkASSERT(!path.isEmpty());
970 969
971 bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get()); 970 bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get());
972 constexpr bool kHasUserStencilSettings = false; 971 constexpr bool kHasUserStencilSettings = false;
973 bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled(); 972 bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled();
974 973
975 const GrPathRendererChain::DrawType type = 974 const GrPathRendererChain::DrawType type =
976 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType 975 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType
977 : GrPathRendererChain::kColor_DrawType; 976 : GrPathRendererChain::kColor_DrawType;
978 977
979 SkTLazy<SkPath> tmpPath; 978 GrShape shape(path, style);
980 SkTLazy<GrStyle> tmpStyle;
981
982 GrPathRenderer::CanDrawPathArgs canDrawArgs; 979 GrPathRenderer::CanDrawPathArgs canDrawArgs;
983 canDrawArgs.fShaderCaps = fDrawingManager->getContext()->caps()->shaderCaps( ); 980 canDrawArgs.fShaderCaps = fDrawingManager->getContext()->caps()->shaderCaps( );
984 canDrawArgs.fViewMatrix = &viewMatrix; 981 canDrawArgs.fViewMatrix = &viewMatrix;
985 canDrawArgs.fPath = &origPath; 982 canDrawArgs.fShape = &shape;
986 canDrawArgs.fStyle = &origStyle;
987 canDrawArgs.fAntiAlias = useCoverageAA; 983 canDrawArgs.fAntiAlias = useCoverageAA;
988 canDrawArgs.fHasUserStencilSettings = kHasUserStencilSettings; 984 canDrawArgs.fHasUserStencilSettings = kHasUserStencilSettings;
989 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; 985 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA;
990 986
991 // Try a 1st time without applying any of the style to the geometry (and bar ring sw) 987 // Try a 1st time without applying any of the style to the geometry (and bar ring sw)
992 GrPathRenderer* pr = fDrawingManager->getPathRenderer(canDrawArgs, false, ty pe); 988 GrPathRenderer* pr = fDrawingManager->getPathRenderer(canDrawArgs, false, ty pe);
993 SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); 989 SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix);
994 990
995 if (!pr && canDrawArgs.fStyle->pathEffect()) { 991 if (!pr && shape.style().pathEffect()) {
996 // It didn't work above, so try again with the path effect applied. 992 // It didn't work above, so try again with the path effect applied.
997 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); 993 shape = shape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale);
998 if (!canDrawArgs.fStyle->applyPathEffectToPath(tmpPath.init(), &rec, *ca nDrawArgs.fPath, 994 if (shape.isEmpty()) {
999 styleScale)) {
1000 GrStyle noPathEffect(canDrawArgs.fStyle->strokeRec(), nullptr);
1001 this->internalDrawPath(clip, paint, viewMatrix, *canDrawArgs.fPath, noPathEffect);
1002 return; 995 return;
1003 } 996 }
1004 tmpStyle.init(rec, nullptr);
1005 canDrawArgs.fPath = tmpPath.get();
1006 canDrawArgs.fStyle = tmpStyle.get();
1007 if (canDrawArgs.fPath->isEmpty()) {
1008 return;
1009 }
1010
1011 pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); 997 pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type);
1012 } 998 }
1013 if (!pr) { 999 if (!pr) {
1014 SkASSERT(!canDrawArgs.fStyle->pathEffect()); 1000 if (shape.style().applies()) {
1015 if (canDrawArgs.fStyle->strokeRec().needToApply()) { 1001 shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, st yleScale);
1016 if (!tmpPath.isValid()) { 1002 if (shape.isEmpty()) {
1017 tmpPath.init();
1018 }
1019 // It didn't work above, so try again by applying the stroke to the geometry.
1020 SkStrokeRec::InitStyle fillOrHairline;
1021 if (!canDrawArgs.fStyle->applyToPath(tmpPath.get(), &fillOrHairline,
1022 *canDrawArgs.fPath, styleScale) ) {
1023 return; 1003 return;
1024 } 1004 }
1025 if (!tmpStyle.isValid()) {
1026 tmpStyle.init(fillOrHairline);
1027 } else {
1028 tmpStyle.get()->resetToInitStyle(fillOrHairline);
1029 }
1030 canDrawArgs.fPath = tmpPath.get();
1031 canDrawArgs.fStyle = tmpStyle.get();
1032 if (canDrawArgs.fPath->isEmpty()) {
1033 return;
1034 }
1035
1036 pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type);
1037 } 1005 }
1038
1039 // This time, allow SW renderer 1006 // This time, allow SW renderer
1040 pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type); 1007 pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type);
1041 } 1008 }
1042 1009
1043 if (nullptr == pr) { 1010 if (!pr) {
1044 #ifdef SK_DEBUG 1011 #ifdef SK_DEBUG
1045 SkDebugf("Unable to find path renderer compatible with path.\n"); 1012 SkDebugf("Unable to find path renderer compatible with path.\n");
1046 #endif 1013 #endif
1047 return; 1014 return;
1048 } 1015 }
1049 1016
1050 GrPathRenderer::DrawPathArgs args; 1017 GrPathRenderer::DrawPathArgs args;
1051 args.fResourceProvider = fDrawingManager->getContext()->resourceProvider(); 1018 args.fResourceProvider = fDrawingManager->getContext()->resourceProvider();
1052 args.fPaint = &paint; 1019 args.fPaint = &paint;
1053 args.fUserStencilSettings = &GrUserStencilSettings::kUnused; 1020 args.fUserStencilSettings = &GrUserStencilSettings::kUnused;
1054 args.fDrawContext = this; 1021 args.fDrawContext = this;
1055 args.fClip = &clip; 1022 args.fClip = &clip;
1056 args.fColor = paint.getColor(); 1023 args.fColor = paint.getColor();
1057 args.fViewMatrix = &viewMatrix; 1024 args.fViewMatrix = &viewMatrix;
1058 args.fPath = canDrawArgs.fPath; 1025 args.fShape = canDrawArgs.fShape;
1059 args.fStyle = canDrawArgs.fStyle;
1060 args.fAntiAlias = useCoverageAA; 1026 args.fAntiAlias = useCoverageAA;
1061 args.fGammaCorrect = this->isGammaCorrect(); 1027 args.fGammaCorrect = this->isGammaCorrect();
1062 pr->drawPath(args); 1028 pr->drawPath(args);
1063 } 1029 }
1064 1030
1065 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip, 1031 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip,
1066 GrDrawBatch* batch) { 1032 GrDrawBatch* batch) {
1067 ASSERT_SINGLE_OWNER 1033 ASSERT_SINGLE_OWNER
1068 RETURN_IF_ABANDONED 1034 RETURN_IF_ABANDONED
1069 SkDEBUGCODE(this->validate();) 1035 SkDEBUGCODE(this->validate();)
1070 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); 1036 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch");
1071 1037
1072 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); 1038 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
1073 } 1039 }
OLDNEW
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | src/gpu/GrPathRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698