| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 "GrSoftwarePathRenderer.h" | 9 #include "GrSoftwarePathRenderer.h" |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| 11 #include "GrSWMaskHelper.h" | 11 #include "GrSWMaskHelper.h" |
| 12 | 12 |
| 13 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
| 14 bool GrSoftwarePathRenderer::canDrawPath(const GrDrawTarget*, | 14 bool GrSoftwarePathRenderer::canDrawPath(const GrDrawTarget*, |
| 15 const GrDrawState*, | 15 const GrDrawState*, |
| 16 const SkMatrix& viewMatrix, |
| 16 const SkPath&, | 17 const SkPath&, |
| 17 const SkStrokeRec&, | 18 const SkStrokeRec&, |
| 18 bool antiAlias) const { | 19 bool antiAlias) const { |
| 19 if (NULL == fContext) { | 20 if (NULL == fContext) { |
| 20 return false; | 21 return false; |
| 21 } | 22 } |
| 22 | 23 |
| 23 return true; | 24 return true; |
| 24 } | 25 } |
| 25 | 26 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 *devPathBounds = SkIRect::EmptyIRect(); | 73 *devPathBounds = SkIRect::EmptyIRect(); |
| 73 return false; | 74 return false; |
| 74 } | 75 } |
| 75 return true; | 76 return true; |
| 76 } | 77 } |
| 77 | 78 |
| 78 //////////////////////////////////////////////////////////////////////////////// | 79 //////////////////////////////////////////////////////////////////////////////// |
| 79 void draw_around_inv_path(GrDrawTarget* target, | 80 void draw_around_inv_path(GrDrawTarget* target, |
| 80 GrDrawState* drawState, | 81 GrDrawState* drawState, |
| 81 GrColor color, | 82 GrColor color, |
| 83 const SkMatrix& viewMatrix, |
| 82 const SkIRect& devClipBounds, | 84 const SkIRect& devClipBounds, |
| 83 const SkIRect& devPathBounds) { | 85 const SkIRect& devPathBounds) { |
| 84 const SkMatrix& matrix = drawState->getViewMatrix(); | |
| 85 SkMatrix invert; | 86 SkMatrix invert; |
| 86 if (!matrix.invert(&invert)) { | 87 if (!viewMatrix.invert(&invert)) { |
| 87 return; | 88 return; |
| 88 } | 89 } |
| 89 | 90 |
| 90 GrDrawState::AutoViewMatrixRestore avmr(drawState); | |
| 91 | |
| 92 SkRect rect; | 91 SkRect rect; |
| 93 if (devClipBounds.fTop < devPathBounds.fTop) { | 92 if (devClipBounds.fTop < devPathBounds.fTop) { |
| 94 rect.iset(devClipBounds.fLeft, devClipBounds.fTop, | 93 rect.iset(devClipBounds.fLeft, devClipBounds.fTop, |
| 95 devClipBounds.fRight, devPathBounds.fTop); | 94 devClipBounds.fRight, devPathBounds.fTop); |
| 96 target->drawRect(drawState, color, rect, NULL, &invert); | 95 target->drawRect(drawState, color, SkMatrix::I(), rect, NULL, &invert); |
| 97 } | 96 } |
| 98 if (devClipBounds.fLeft < devPathBounds.fLeft) { | 97 if (devClipBounds.fLeft < devPathBounds.fLeft) { |
| 99 rect.iset(devClipBounds.fLeft, devPathBounds.fTop, | 98 rect.iset(devClipBounds.fLeft, devPathBounds.fTop, |
| 100 devPathBounds.fLeft, devPathBounds.fBottom); | 99 devPathBounds.fLeft, devPathBounds.fBottom); |
| 101 target->drawRect(drawState, color, rect, NULL, &invert); | 100 target->drawRect(drawState, color, SkMatrix::I(), rect, NULL, &invert); |
| 102 } | 101 } |
| 103 if (devClipBounds.fRight > devPathBounds.fRight) { | 102 if (devClipBounds.fRight > devPathBounds.fRight) { |
| 104 rect.iset(devPathBounds.fRight, devPathBounds.fTop, | 103 rect.iset(devPathBounds.fRight, devPathBounds.fTop, |
| 105 devClipBounds.fRight, devPathBounds.fBottom); | 104 devClipBounds.fRight, devPathBounds.fBottom); |
| 106 target->drawRect(drawState, color, rect, NULL, &invert); | 105 target->drawRect(drawState, color, SkMatrix::I(), rect, NULL, &invert); |
| 107 } | 106 } |
| 108 if (devClipBounds.fBottom > devPathBounds.fBottom) { | 107 if (devClipBounds.fBottom > devPathBounds.fBottom) { |
| 109 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, | 108 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, |
| 110 devClipBounds.fRight, devClipBounds.fBottom); | 109 devClipBounds.fRight, devClipBounds.fBottom); |
| 111 target->drawRect(drawState, color, rect, NULL, &invert); | 110 target->drawRect(drawState, color, SkMatrix::I(), rect, NULL, &invert); |
| 112 } | 111 } |
| 113 } | 112 } |
| 114 | 113 |
| 115 } | 114 } |
| 116 | 115 |
| 117 //////////////////////////////////////////////////////////////////////////////// | 116 //////////////////////////////////////////////////////////////////////////////// |
| 118 // return true on success; false on failure | 117 // return true on success; false on failure |
| 119 bool GrSoftwarePathRenderer::onDrawPath(GrDrawTarget* target, | 118 bool GrSoftwarePathRenderer::onDrawPath(GrDrawTarget* target, |
| 120 GrDrawState* drawState, | 119 GrDrawState* drawState, |
| 121 GrColor color, | 120 GrColor color, |
| 121 const SkMatrix& viewMatrix, |
| 122 const SkPath& path, | 122 const SkPath& path, |
| 123 const SkStrokeRec& stroke, | 123 const SkStrokeRec& stroke, |
| 124 bool antiAlias) { | 124 bool antiAlias) { |
| 125 | 125 |
| 126 if (NULL == fContext) { | 126 if (NULL == fContext) { |
| 127 return false; | 127 return false; |
| 128 } | 128 } |
| 129 | 129 |
| 130 SkMatrix vm = drawState->getViewMatrix(); | |
| 131 | |
| 132 SkIRect devPathBounds, devClipBounds; | 130 SkIRect devPathBounds, devClipBounds; |
| 133 if (!get_path_and_clip_bounds(target, drawState, path, vm, | 131 if (!get_path_and_clip_bounds(target, drawState, path, viewMatrix, |
| 134 &devPathBounds, &devClipBounds)) { | 132 &devPathBounds, &devClipBounds)) { |
| 135 if (path.isInverseFillType()) { | 133 if (path.isInverseFillType()) { |
| 136 draw_around_inv_path(target, drawState, color, devClipBounds, devPat
hBounds); | 134 draw_around_inv_path(target, drawState, color, viewMatrix, devClipBo
unds,devPathBounds); |
| 137 } | 135 } |
| 138 return true; | 136 return true; |
| 139 } | 137 } |
| 140 | 138 |
| 141 SkAutoTUnref<GrTexture> texture( | 139 SkAutoTUnref<GrTexture> texture( |
| 142 GrSWMaskHelper::DrawPathMaskToTexture(fContext, path, stroke, | 140 GrSWMaskHelper::DrawPathMaskToTexture(fContext, path, stroke, |
| 143 devPathBounds, | 141 devPathBounds, |
| 144 antiAlias, &vm)); | 142 antiAlias, &viewMatrix)); |
| 145 if (NULL == texture) { | 143 if (NULL == texture) { |
| 146 return false; | 144 return false; |
| 147 } | 145 } |
| 148 | 146 |
| 149 GrDrawState copy = *drawState; | 147 GrDrawState copy = *drawState; |
| 150 GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, ©, color, devP
athBounds); | 148 GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, ©, color, view
Matrix, |
| 149 devPathBounds); |
| 151 | 150 |
| 152 if (path.isInverseFillType()) { | 151 if (path.isInverseFillType()) { |
| 153 draw_around_inv_path(target, drawState, color, devClipBounds, devPathBou
nds); | 152 draw_around_inv_path(target, drawState, color, viewMatrix, devClipBounds
, devPathBounds); |
| 154 } | 153 } |
| 155 | 154 |
| 156 return true; | 155 return true; |
| 157 } | 156 } |
| OLD | NEW |