| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrSoftwarePathRenderer.h" | 8 #include "GrSoftwarePathRenderer.h" |
| 9 #include "GrAuditTrail.h" |
| 10 #include "GrClip.h" |
| 9 #include "GrSWMaskHelper.h" | 11 #include "GrSWMaskHelper.h" |
| 10 #include "GrTextureProvider.h" | 12 #include "GrTextureProvider.h" |
| 11 #include "batches/GrRectBatchFactory.h" | 13 #include "batches/GrRectBatchFactory.h" |
| 12 | 14 |
| 13 //////////////////////////////////////////////////////////////////////////////// | 15 //////////////////////////////////////////////////////////////////////////////// |
| 14 bool GrSoftwarePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { | 16 bool GrSoftwarePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
| 15 return SkToBool(fTexProvider); | 17 return SkToBool(fTexProvider); |
| 16 } | 18 } |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 47 return false; | 49 return false; |
| 48 } | 50 } |
| 49 } else { | 51 } else { |
| 50 *devPathBounds = SkIRect::EmptyIRect(); | 52 *devPathBounds = SkIRect::EmptyIRect(); |
| 51 return false; | 53 return false; |
| 52 } | 54 } |
| 53 return true; | 55 return true; |
| 54 } | 56 } |
| 55 | 57 |
| 56 //////////////////////////////////////////////////////////////////////////////// | 58 //////////////////////////////////////////////////////////////////////////////// |
| 57 static void draw_non_aa_rect(GrDrawTarget* drawTarget, | 59 |
| 58 const GrPipelineBuilder& pipelineBuilder, | 60 } |
| 59 const GrClip& clip, | 61 |
| 60 GrColor color, | 62 void GrSoftwarePathRenderer::DrawNonAARect(GrDrawContext* drawContext, |
| 61 const SkMatrix& viewMatrix, | 63 const GrPaint* paint, |
| 62 const SkRect& rect, | 64 const GrUserStencilSettings* userSten
cilSettings, |
| 63 const SkMatrix& localMatrix) { | 65 const GrClip& clip, |
| 66 GrColor color, |
| 67 const SkMatrix& viewMatrix, |
| 68 const SkRect& rect, |
| 69 const SkMatrix& localMatrix) { |
| 64 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, v
iewMatrix, rect, | 70 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, v
iewMatrix, rect, |
| 65 nullptr,
&localMatrix)); | 71 nullptr,
&localMatrix)); |
| 66 drawTarget->drawBatch(pipelineBuilder, clip, batch); | 72 |
| 73 GrPipelineBuilder pipelineBuilder(*paint, drawContext->isUnifiedMultisampled
()); |
| 74 pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget()); |
| 75 pipelineBuilder.setUserStencil(userStencilSettings); |
| 76 |
| 77 drawContext->drawBatch(pipelineBuilder, clip, batch); |
| 67 } | 78 } |
| 68 | 79 |
| 69 void draw_around_inv_path(GrDrawTarget* target, | 80 void GrSoftwarePathRenderer::DrawAroundInvPath(GrDrawContext* drawContext, |
| 70 GrPipelineBuilder* pipelineBuilder, | 81 const GrPaint* paint, |
| 71 const GrClip& clip, | 82 const GrUserStencilSettings* user
StencilSettings, |
| 72 GrColor color, | 83 const GrClip& clip, |
| 73 const SkMatrix& viewMatrix, | 84 GrColor color, |
| 74 const SkIRect& devClipBounds, | 85 const SkMatrix& viewMatrix, |
| 75 const SkIRect& devPathBounds) { | 86 const SkIRect& devClipBounds, |
| 87 const SkIRect& devPathBounds) { |
| 76 SkMatrix invert; | 88 SkMatrix invert; |
| 77 if (!viewMatrix.invert(&invert)) { | 89 if (!viewMatrix.invert(&invert)) { |
| 78 return; | 90 return; |
| 79 } | 91 } |
| 80 | 92 |
| 81 SkRect rect; | 93 SkRect rect; |
| 82 if (devClipBounds.fTop < devPathBounds.fTop) { | 94 if (devClipBounds.fTop < devPathBounds.fTop) { |
| 83 rect.iset(devClipBounds.fLeft, devClipBounds.fTop, | 95 rect.iset(devClipBounds.fLeft, devClipBounds.fTop, |
| 84 devClipBounds.fRight, devPathBounds.fTop); | 96 devClipBounds.fRight, devPathBounds.fTop); |
| 85 draw_non_aa_rect(target, *pipelineBuilder, clip, color, SkMatrix::I(), r
ect, invert); | 97 DrawNonAARect(drawContext, paint, userStencilSettings, clip, color, |
| 98 SkMatrix::I(), rect, invert); |
| 86 } | 99 } |
| 87 if (devClipBounds.fLeft < devPathBounds.fLeft) { | 100 if (devClipBounds.fLeft < devPathBounds.fLeft) { |
| 88 rect.iset(devClipBounds.fLeft, devPathBounds.fTop, | 101 rect.iset(devClipBounds.fLeft, devPathBounds.fTop, |
| 89 devPathBounds.fLeft, devPathBounds.fBottom); | 102 devPathBounds.fLeft, devPathBounds.fBottom); |
| 90 draw_non_aa_rect(target, *pipelineBuilder, clip, color, SkMatrix::I(), r
ect, invert); | 103 DrawNonAARect(drawContext, paint, userStencilSettings, clip, color, |
| 104 SkMatrix::I(), rect, invert); |
| 91 } | 105 } |
| 92 if (devClipBounds.fRight > devPathBounds.fRight) { | 106 if (devClipBounds.fRight > devPathBounds.fRight) { |
| 93 rect.iset(devPathBounds.fRight, devPathBounds.fTop, | 107 rect.iset(devPathBounds.fRight, devPathBounds.fTop, |
| 94 devClipBounds.fRight, devPathBounds.fBottom); | 108 devClipBounds.fRight, devPathBounds.fBottom); |
| 95 draw_non_aa_rect(target, *pipelineBuilder, clip, color, SkMatrix::I(), r
ect, invert); | 109 DrawNonAARect(drawContext, paint, userStencilSettings, clip, color, |
| 110 SkMatrix::I(), rect, invert); |
| 96 } | 111 } |
| 97 if (devClipBounds.fBottom > devPathBounds.fBottom) { | 112 if (devClipBounds.fBottom > devPathBounds.fBottom) { |
| 98 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, | 113 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, |
| 99 devClipBounds.fRight, devClipBounds.fBottom); | 114 devClipBounds.fRight, devClipBounds.fBottom); |
| 100 draw_non_aa_rect(target, *pipelineBuilder, clip, color, SkMatrix::I(), r
ect, invert); | 115 DrawNonAARect(drawContext, paint, userStencilSettings, clip, color, |
| 116 SkMatrix::I(), rect, invert); |
| 101 } | 117 } |
| 102 } | 118 } |
| 103 | 119 |
| 104 } | |
| 105 | |
| 106 //////////////////////////////////////////////////////////////////////////////// | 120 //////////////////////////////////////////////////////////////////////////////// |
| 107 // return true on success; false on failure | 121 // return true on success; false on failure |
| 108 bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { | 122 bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { |
| 109 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), "GrSoftwarePathRend
erer::onDrawPath"); | 123 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), |
| 110 if (!fTexProvider || !args.fPipelineBuilder->getRenderTarget()) { | 124 "GrSoftwarePathRenderer::onDrawPath"); |
| 125 if (!fTexProvider) { |
| 111 return false; | 126 return false; |
| 112 } | 127 } |
| 113 | 128 |
| 114 const int width = args.fPipelineBuilder->getRenderTarget()->width(); | |
| 115 const int height = args.fPipelineBuilder->getRenderTarget()->height(); | |
| 116 | |
| 117 SkIRect devPathBounds, devClipBounds; | 129 SkIRect devPathBounds, devClipBounds; |
| 118 if (!get_path_and_clip_bounds(width, height, *args.fClip, *args.fPath, | 130 if (!get_path_and_clip_bounds(args.fDrawContext->width(), args.fDrawContext-
>height(), |
| 131 *args.fClip, *args.fPath, |
| 119 *args.fViewMatrix, &devPathBounds, &devClipBou
nds)) { | 132 *args.fViewMatrix, &devPathBounds, &devClipBou
nds)) { |
| 120 if (args.fPath->isInverseFillType()) { | 133 if (args.fPath->isInverseFillType()) { |
| 121 draw_around_inv_path(args.fTarget, args.fPipelineBuilder, *args.fCli
p, args.fColor, | 134 DrawAroundInvPath(args.fDrawContext, args.fPaint, args.fUserStencilS
ettings, |
| 122 *args.fViewMatrix, devClipBounds, devPathBounds
); | 135 *args.fClip, args.fColor, |
| 136 *args.fViewMatrix, devClipBounds, devPathBounds); |
| 123 } | 137 } |
| 124 return true; | 138 return true; |
| 125 } | 139 } |
| 126 | 140 |
| 127 SkAutoTUnref<GrTexture> texture( | 141 SkAutoTUnref<GrTexture> texture( |
| 128 GrSWMaskHelper::DrawPathMaskToTexture(fTexProvider, *args.fPath, *ar
gs.fStyle, | 142 GrSWMaskHelper::DrawPathMaskToTexture(fTexProvider, *args.fPath, *ar
gs.fStyle, |
| 129 devPathBounds, | 143 devPathBounds, |
| 130 args.fAntiAlias, args.fViewMat
rix)); | 144 args.fAntiAlias, args.fViewMat
rix)); |
| 131 if (nullptr == texture) { | 145 if (nullptr == texture) { |
| 132 return false; | 146 return false; |
| 133 } | 147 } |
| 134 | 148 |
| 135 GrSWMaskHelper::DrawToTargetWithPathMask(texture, args.fTarget, args.fPipeli
neBuilder, | 149 GrSWMaskHelper::DrawToTargetWithPathMask(texture, args.fDrawContext, args.fP
aint, |
| 150 args.fUserStencilSettings, |
| 136 *args.fClip, args.fColor, *args.fVi
ewMatrix, | 151 *args.fClip, args.fColor, *args.fVi
ewMatrix, |
| 137 devPathBounds); | 152 devPathBounds); |
| 138 | 153 |
| 139 if (args.fPath->isInverseFillType()) { | 154 if (args.fPath->isInverseFillType()) { |
| 140 draw_around_inv_path(args.fTarget, args.fPipelineBuilder, *args.fClip, a
rgs.fColor, | 155 DrawAroundInvPath(args.fDrawContext, args.fPaint, args.fUserStencilSetti
ngs, |
| 141 *args.fViewMatrix, devClipBounds, devPathBounds); | 156 *args.fClip, args.fColor, |
| 157 *args.fViewMatrix, devClipBounds, devPathBounds); |
| 142 } | 158 } |
| 143 | 159 |
| 144 return true; | 160 return true; |
| 145 } | 161 } |
| OLD | NEW |