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

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

Issue 1962243002: Separate user and raw stencil settings (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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/GrDrawContextPriv.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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 return; 368 return;
369 } 369 }
370 370
371 SkPath path; 371 SkPath path;
372 path.setIsVolatile(true); 372 path.setIsVolatile(true);
373 path.addRect(rect); 373 path.addRect(rect);
374 this->internalDrawPath(clip, paint, viewMatrix, path, *style); 374 this->internalDrawPath(clip, paint, viewMatrix, path, *style);
375 } 375 }
376 376
377 bool GrDrawContextPriv::drawAndStencilRect(const SkIRect* scissorRect, 377 bool GrDrawContextPriv::drawAndStencilRect(const SkIRect* scissorRect,
378 const GrStencilSettings& ss, 378 const GrUserStencilSettings* ss,
379 SkRegion::Op op, 379 SkRegion::Op op,
380 bool invert, 380 bool invert,
381 bool doAA, 381 bool doAA,
382 const SkMatrix& viewMatrix, 382 const SkMatrix& viewMatrix,
383 const SkRect& rect) { 383 const SkRect& rect) {
384 ASSERT_SINGLE_OWNER_PRIV 384 ASSERT_SINGLE_OWNER_PRIV
385 RETURN_FALSE_IF_ABANDONED_PRIV 385 RETURN_FALSE_IF_ABANDONED_PRIV
386 SkDEBUGCODE(fDrawContext->validate();) 386 SkDEBUGCODE(fDrawContext->validate();)
387 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil Rect"); 387 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil Rect");
388 388
389 AutoCheckFlush acf(fDrawContext->fDrawingManager); 389 AutoCheckFlush acf(fDrawContext->fDrawingManager);
390 390
391 GrPaint paint; 391 GrPaint paint;
392 paint.setAntiAlias(doAA); 392 paint.setAntiAlias(doAA);
393 paint.setCoverageSetOpXPFactory(op, invert); 393 paint.setCoverageSetOpXPFactory(op, invert);
394 394
395 SkAutoTUnref<GrDrawBatch> batch(fDrawContext->getFillRectBatch(paint, viewMa trix, rect)); 395 SkAutoTUnref<GrDrawBatch> batch(fDrawContext->getFillRectBatch(paint, viewMa trix, rect));
396 if (batch) { 396 if (batch) {
397 GrPipelineBuilder pipelineBuilder(paint, 397 GrPipelineBuilder pipelineBuilder(paint,
398 fDrawContext->accessRenderTarget(), 398 fDrawContext->accessRenderTarget(),
399 GrClip::WideOpen()); 399 GrClip::WideOpen());
400 pipelineBuilder.setStencil(ss); 400 pipelineBuilder.setUserStencil(ss);
401 401
402 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, batch, scissor Rect); 402 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, batch, scissor Rect);
403 return true; 403 return true;
404 } 404 }
405 405
406 SkPath path; 406 SkPath path;
407 path.setIsVolatile(true); 407 path.setIsVolatile(true);
408 path.addRect(rect); 408 path.addRect(rect);
409 return this->drawAndStencilPath(scissorRect, ss, op, invert, doAA, viewMatri x, path); 409 return this->drawAndStencilPath(scissorRect, ss, op, invert, doAA, viewMatri x, path);
410 } 410 }
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 848
849 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. 849 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re.
850 // Scratch textures can be recycled after they are returned to the texture 850 // Scratch textures can be recycled after they are returned to the texture
851 // cache. This presents a potential hazard for buffered drawing. However, 851 // cache. This presents a potential hazard for buffered drawing. However,
852 // the writePixels that uploads to the scratch will perform a flush so we're 852 // the writePixels that uploads to the scratch will perform a flush so we're
853 // OK. 853 // OK.
854 this->internalDrawPath(clip, paint, viewMatrix, path, style); 854 this->internalDrawPath(clip, paint, viewMatrix, path, style);
855 } 855 }
856 856
857 bool GrDrawContextPriv::drawAndStencilPath(const SkIRect* scissorRect, 857 bool GrDrawContextPriv::drawAndStencilPath(const SkIRect* scissorRect,
858 const GrStencilSettings& ss, 858 const GrUserStencilSettings* ss,
859 SkRegion::Op op, 859 SkRegion::Op op,
860 bool invert, 860 bool invert,
861 bool doAA, 861 bool doAA,
862 const SkMatrix& viewMatrix, 862 const SkMatrix& viewMatrix,
863 const SkPath& path) { 863 const SkPath& path) {
864 ASSERT_SINGLE_OWNER_PRIV 864 ASSERT_SINGLE_OWNER_PRIV
865 RETURN_FALSE_IF_ABANDONED_PRIV 865 RETURN_FALSE_IF_ABANDONED_PRIV
866 SkDEBUGCODE(fDrawContext->validate();) 866 SkDEBUGCODE(fDrawContext->validate();)
867 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawPat h"); 867 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawPat h");
868 868
869 if (path.isEmpty() && path.isInverseFillType()) { 869 if (path.isEmpty() && path.isInverseFillType()) {
870 this->drawAndStencilRect(scissorRect, ss, op, invert, false, SkMatrix::I (), 870 this->drawAndStencilRect(scissorRect, ss, op, invert, false, SkMatrix::I (),
871 SkRect::MakeIWH(fDrawContext->width(), 871 SkRect::MakeIWH(fDrawContext->width(),
872 fDrawContext->height())); 872 fDrawContext->height()));
873 return true; 873 return true;
874 } 874 }
875 875
876 AutoCheckFlush acf(fDrawContext->fDrawingManager); 876 AutoCheckFlush acf(fDrawContext->fDrawingManager);
877 877
878 // An Assumption here is that path renderer would use some form of tweaking 878 // An Assumption here is that path renderer would use some form of tweaking
879 // the src color (either the input alpha or in the frag shader) to implement 879 // the src color (either the input alpha or in the frag shader) to implement
880 // aa. If we have some future driver-mojo path AA that can do the right 880 // aa. If we have some future driver-mojo path AA that can do the right
881 // thing WRT to the blend then we'll need some query on the PR. 881 // thing WRT to the blend then we'll need some query on the PR.
882 bool useCoverageAA = doAA && !fDrawContext->fRenderTarget->isUnifiedMultisam pled(); 882 bool useCoverageAA = doAA && !fDrawContext->fRenderTarget->isUnifiedMultisam pled();
883 bool isStencilDisabled = true; 883 bool hasUserStencilSettings = (&GrUserStencilSettings::kUnused != ss);
884 bool isStencilBufferMSAA = fDrawContext->fRenderTarget->isStencilBufferMulti sampled(); 884 bool isStencilBufferMSAA = fDrawContext->fRenderTarget->isStencilBufferMulti sampled();
885 885
886 const GrPathRendererChain::DrawType type = 886 const GrPathRendererChain::DrawType type =
887 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType 887 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType
888 : GrPathRendererChain::kColor_DrawType; 888 : GrPathRendererChain::kColor_DrawType;
889 889
890 GrPathRenderer::CanDrawPathArgs canDrawArgs; 890 GrPathRenderer::CanDrawPathArgs canDrawArgs;
891 canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps( )->shaderCaps(); 891 canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps( )->shaderCaps();
892 canDrawArgs.fViewMatrix = &viewMatrix; 892 canDrawArgs.fViewMatrix = &viewMatrix;
893 canDrawArgs.fPath = &path; 893 canDrawArgs.fPath = &path;
894 canDrawArgs.fStyle = &GrStyle::SimpleFill(); 894 canDrawArgs.fStyle = &GrStyle::SimpleFill();
895 canDrawArgs.fAntiAlias = useCoverageAA; 895 canDrawArgs.fAntiAlias = useCoverageAA;
896 canDrawArgs.fIsStencilDisabled = isStencilDisabled; 896 canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings;
897 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; 897 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA;
898 898
899 // Don't allow the SW renderer 899 // Don't allow the SW renderer
900 GrPathRenderer* pr = fDrawContext->fDrawingManager->getPathRenderer(canDrawA rgs, false, type); 900 GrPathRenderer* pr = fDrawContext->fDrawingManager->getPathRenderer(canDrawA rgs, false, type);
901 if (!pr) { 901 if (!pr) {
902 return false; 902 return false;
903 } 903 }
904 904
905 GrPaint paint; 905 GrPaint paint;
906 paint.setCoverageSetOpXPFactory(op, invert); 906 paint.setCoverageSetOpXPFactory(op, invert);
907 907
908 // TODO: it is unfortunate that we have to convert this to a GrClip to 908 // TODO: it is unfortunate that we have to convert this to a GrClip to
909 // call drawPath. 909 // call drawPath.
910 GrClip clip; 910 GrClip clip;
911 if (scissorRect) { 911 if (scissorRect) {
912 clip.setIRect(*scissorRect); 912 clip.setIRect(*scissorRect);
913 } 913 }
914 914
915 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->accessRenderTarget(), clip); 915 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->accessRenderTarget(), clip);
916 pipelineBuilder.setStencil(ss); 916 pipelineBuilder.setUserStencil(ss);
917 917
918 GrPathRenderer::DrawPathArgs args; 918 GrPathRenderer::DrawPathArgs args;
919 args.fTarget = fDrawContext->getDrawTarget(); 919 args.fTarget = fDrawContext->getDrawTarget();
920 args.fResourceProvider = fDrawContext->fDrawingManager->getContext()->resour ceProvider(); 920 args.fResourceProvider = fDrawContext->fDrawingManager->getContext()->resour ceProvider();
921 args.fPipelineBuilder = &pipelineBuilder; 921 args.fPipelineBuilder = &pipelineBuilder;
922 args.fColor = GrColor_WHITE; 922 args.fColor = GrColor_WHITE;
923 args.fViewMatrix = &viewMatrix; 923 args.fViewMatrix = &viewMatrix;
924 args.fPath = &path; 924 args.fPath = &path;
925 args.fStyle = &GrStyle::SimpleFill(); 925 args.fStyle = &GrStyle::SimpleFill();
926 args.fAntiAlias = useCoverageAA; 926 args.fAntiAlias = useCoverageAA;
927 args.fGammaCorrect = fDrawContext->isGammaCorrect(); 927 args.fGammaCorrect = fDrawContext->isGammaCorrect();
928 pr->drawPath(args); 928 pr->drawPath(args);
929 return true; 929 return true;
930 } 930 }
931 931
932 void GrDrawContext::internalDrawPath(const GrClip& clip, 932 void GrDrawContext::internalDrawPath(const GrClip& clip,
933 const GrPaint& paint, 933 const GrPaint& paint,
934 const SkMatrix& viewMatrix, 934 const SkMatrix& viewMatrix,
935 const SkPath& origPath, 935 const SkPath& origPath,
936 const GrStyle& origStyle) { 936 const GrStyle& origStyle) {
937 ASSERT_SINGLE_OWNER 937 ASSERT_SINGLE_OWNER
938 RETURN_IF_ABANDONED 938 RETURN_IF_ABANDONED
939 SkASSERT(!origPath.isEmpty()); 939 SkASSERT(!origPath.isEmpty());
940 940
941 bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get()); 941 bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get());
942 const bool isStencilDisabled = true; 942 constexpr bool kHasUserStencilSettings = false;
943 bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled(); 943 bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled();
944 944
945 const GrPathRendererChain::DrawType type = 945 const GrPathRendererChain::DrawType type =
946 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType 946 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType
947 : GrPathRendererChain::kColor_DrawType; 947 : GrPathRendererChain::kColor_DrawType;
948 948
949 SkTLazy<SkPath> tmpPath; 949 SkTLazy<SkPath> tmpPath;
950 SkTLazy<GrStyle> tmpStyle; 950 SkTLazy<GrStyle> tmpStyle;
951 951
952 GrPathRenderer::CanDrawPathArgs canDrawArgs; 952 GrPathRenderer::CanDrawPathArgs canDrawArgs;
953 canDrawArgs.fShaderCaps = fDrawingManager->getContext()->caps()->shaderCaps( ); 953 canDrawArgs.fShaderCaps = fDrawingManager->getContext()->caps()->shaderCaps( );
954 canDrawArgs.fViewMatrix = &viewMatrix; 954 canDrawArgs.fViewMatrix = &viewMatrix;
955 canDrawArgs.fPath = &origPath; 955 canDrawArgs.fPath = &origPath;
956 canDrawArgs.fStyle = &origStyle; 956 canDrawArgs.fStyle = &origStyle;
957 canDrawArgs.fAntiAlias = useCoverageAA; 957 canDrawArgs.fAntiAlias = useCoverageAA;
958 canDrawArgs.fIsStencilDisabled = isStencilDisabled; 958 canDrawArgs.fHasUserStencilSettings = kHasUserStencilSettings;
959 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; 959 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA;
960 960
961 // Try a 1st time without applying any of the style to the geometry (and bar ring sw) 961 // Try a 1st time without applying any of the style to the geometry (and bar ring sw)
962 GrPathRenderer* pr = fDrawingManager->getPathRenderer(canDrawArgs, false, ty pe); 962 GrPathRenderer* pr = fDrawingManager->getPathRenderer(canDrawArgs, false, ty pe);
963 SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); 963 SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix);
964 964
965 if (!pr && canDrawArgs.fStyle->pathEffect()) { 965 if (!pr && canDrawArgs.fStyle->pathEffect()) {
966 // It didn't work above, so try again with the path effect applied. 966 // It didn't work above, so try again with the path effect applied.
967 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); 967 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
968 if (!canDrawArgs.fStyle->applyPathEffectToPath(tmpPath.init(), &rec, *ca nDrawArgs.fPath, 968 if (!canDrawArgs.fStyle->applyPathEffectToPath(tmpPath.init(), &rec, *ca nDrawArgs.fPath,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 } 1033 }
1034 1034
1035 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b atch) { 1035 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b atch) {
1036 ASSERT_SINGLE_OWNER 1036 ASSERT_SINGLE_OWNER
1037 RETURN_IF_ABANDONED 1037 RETURN_IF_ABANDONED
1038 SkDEBUGCODE(this->validate();) 1038 SkDEBUGCODE(this->validate();)
1039 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); 1039 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch");
1040 1040
1041 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); 1041 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch);
1042 } 1042 }
OLDNEW
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | src/gpu/GrDrawContextPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698