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

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

Powered by Google App Engine
This is Rietveld 408576698