| 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 SkPath&, | 14 bool GrSoftwarePathRenderer::canDrawPath(const GrDrawTarget*, |
| 15 const GrDrawState*, |
| 16 const SkPath&, |
| 15 const SkStrokeRec&, | 17 const SkStrokeRec&, |
| 16 const GrDrawTarget*, | |
| 17 bool antiAlias) const { | 18 bool antiAlias) const { |
| 18 if (NULL == fContext) { | 19 if (NULL == fContext) { |
| 19 return false; | 20 return false; |
| 20 } | 21 } |
| 21 | 22 |
| 22 return true; | 23 return true; |
| 23 } | 24 } |
| 24 | 25 |
| 25 GrPathRenderer::StencilSupport GrSoftwarePathRenderer::onGetStencilSupport( | 26 GrPathRenderer::StencilSupport |
| 26 const SkPath&, | 27 GrSoftwarePathRenderer::onGetStencilSupport(const GrDrawTarget*, |
| 27 const SkStrokeRec&, | 28 const GrDrawState*, |
| 28 const GrDrawTarget*) const { | 29 const SkPath&, |
| 30 const SkStrokeRec&) const { |
| 29 return GrPathRenderer::kNoSupport_StencilSupport; | 31 return GrPathRenderer::kNoSupport_StencilSupport; |
| 30 } | 32 } |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 //////////////////////////////////////////////////////////////////////////////// | 36 //////////////////////////////////////////////////////////////////////////////// |
| 35 // gets device coord bounds of path (not considering the fill) and clip. The | 37 // gets device coord bounds of path (not considering the fill) and clip. The |
| 36 // path bounds will be a subset of the clip bounds. returns false if | 38 // path bounds will be a subset of the clip bounds. returns false if |
| 37 // path bounds would be empty. | 39 // path bounds would be empty. |
| 38 bool get_path_and_clip_bounds(const GrDrawTarget* target, | 40 bool get_path_and_clip_bounds(const GrDrawTarget* target, |
| 41 const GrDrawState* drawState, |
| 39 const SkPath& path, | 42 const SkPath& path, |
| 40 const SkMatrix& matrix, | 43 const SkMatrix& matrix, |
| 41 SkIRect* devPathBounds, | 44 SkIRect* devPathBounds, |
| 42 SkIRect* devClipBounds) { | 45 SkIRect* devClipBounds) { |
| 43 // compute bounds as intersection of rt size, clip, and path | 46 // compute bounds as intersection of rt size, clip, and path |
| 44 const GrRenderTarget* rt = target->getDrawState().getRenderTarget(); | 47 const GrRenderTarget* rt = drawState->getRenderTarget(); |
| 45 if (NULL == rt) { | 48 if (NULL == rt) { |
| 46 return false; | 49 return false; |
| 47 } | 50 } |
| 48 *devPathBounds = SkIRect::MakeWH(rt->width(), rt->height()); | 51 *devPathBounds = SkIRect::MakeWH(rt->width(), rt->height()); |
| 49 | 52 |
| 50 target->getClip()->getConservativeBounds(rt, devClipBounds); | 53 target->getClip()->getConservativeBounds(rt, devClipBounds); |
| 51 | 54 |
| 52 // TODO: getConservativeBounds already intersects with the | 55 // TODO: getConservativeBounds already intersects with the |
| 53 // render target's bounding box. Remove this next line | 56 // render target's bounding box. Remove this next line |
| 54 if (!devPathBounds->intersect(*devClipBounds)) { | 57 if (!devPathBounds->intersect(*devClipBounds)) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 67 } | 70 } |
| 68 } else { | 71 } else { |
| 69 *devPathBounds = SkIRect::EmptyIRect(); | 72 *devPathBounds = SkIRect::EmptyIRect(); |
| 70 return false; | 73 return false; |
| 71 } | 74 } |
| 72 return true; | 75 return true; |
| 73 } | 76 } |
| 74 | 77 |
| 75 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
| 76 void draw_around_inv_path(GrDrawTarget* target, | 79 void draw_around_inv_path(GrDrawTarget* target, |
| 80 GrDrawState* drawState, |
| 77 const SkIRect& devClipBounds, | 81 const SkIRect& devClipBounds, |
| 78 const SkIRect& devPathBounds) { | 82 const SkIRect& devPathBounds) { |
| 79 GrDrawState::AutoViewMatrixRestore avmr; | 83 GrDrawState::AutoViewMatrixRestore avmr; |
| 80 if (!avmr.setIdentity(target->drawState())) { | 84 if (!avmr.setIdentity(drawState)) { |
| 81 return; | 85 return; |
| 82 } | 86 } |
| 83 SkRect rect; | 87 SkRect rect; |
| 84 if (devClipBounds.fTop < devPathBounds.fTop) { | 88 if (devClipBounds.fTop < devPathBounds.fTop) { |
| 85 rect.iset(devClipBounds.fLeft, devClipBounds.fTop, | 89 rect.iset(devClipBounds.fLeft, devClipBounds.fTop, |
| 86 devClipBounds.fRight, devPathBounds.fTop); | 90 devClipBounds.fRight, devPathBounds.fTop); |
| 87 target->drawSimpleRect(rect); | 91 target->drawSimpleRect(drawState, rect); |
| 88 } | 92 } |
| 89 if (devClipBounds.fLeft < devPathBounds.fLeft) { | 93 if (devClipBounds.fLeft < devPathBounds.fLeft) { |
| 90 rect.iset(devClipBounds.fLeft, devPathBounds.fTop, | 94 rect.iset(devClipBounds.fLeft, devPathBounds.fTop, |
| 91 devPathBounds.fLeft, devPathBounds.fBottom); | 95 devPathBounds.fLeft, devPathBounds.fBottom); |
| 92 target->drawSimpleRect(rect); | 96 target->drawSimpleRect(drawState, rect); |
| 93 } | 97 } |
| 94 if (devClipBounds.fRight > devPathBounds.fRight) { | 98 if (devClipBounds.fRight > devPathBounds.fRight) { |
| 95 rect.iset(devPathBounds.fRight, devPathBounds.fTop, | 99 rect.iset(devPathBounds.fRight, devPathBounds.fTop, |
| 96 devClipBounds.fRight, devPathBounds.fBottom); | 100 devClipBounds.fRight, devPathBounds.fBottom); |
| 97 target->drawSimpleRect(rect); | 101 target->drawSimpleRect(drawState, rect); |
| 98 } | 102 } |
| 99 if (devClipBounds.fBottom > devPathBounds.fBottom) { | 103 if (devClipBounds.fBottom > devPathBounds.fBottom) { |
| 100 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, | 104 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, |
| 101 devClipBounds.fRight, devClipBounds.fBottom); | 105 devClipBounds.fRight, devClipBounds.fBottom); |
| 102 target->drawSimpleRect(rect); | 106 target->drawSimpleRect(drawState, rect); |
| 103 } | 107 } |
| 104 } | 108 } |
| 105 | 109 |
| 106 } | 110 } |
| 107 | 111 |
| 108 //////////////////////////////////////////////////////////////////////////////// | 112 //////////////////////////////////////////////////////////////////////////////// |
| 109 // return true on success; false on failure | 113 // return true on success; false on failure |
| 110 bool GrSoftwarePathRenderer::onDrawPath(const SkPath& path, | 114 bool GrSoftwarePathRenderer::onDrawPath(GrDrawTarget* target, |
| 115 GrDrawState* drawState, |
| 116 const SkPath& path, |
| 111 const SkStrokeRec& stroke, | 117 const SkStrokeRec& stroke, |
| 112 GrDrawTarget* target, | |
| 113 bool antiAlias) { | 118 bool antiAlias) { |
| 114 | 119 |
| 115 if (NULL == fContext) { | 120 if (NULL == fContext) { |
| 116 return false; | 121 return false; |
| 117 } | 122 } |
| 118 | 123 |
| 119 GrDrawState* drawState = target->drawState(); | |
| 120 | |
| 121 SkMatrix vm = drawState->getViewMatrix(); | 124 SkMatrix vm = drawState->getViewMatrix(); |
| 122 | 125 |
| 123 SkIRect devPathBounds, devClipBounds; | 126 SkIRect devPathBounds, devClipBounds; |
| 124 if (!get_path_and_clip_bounds(target, path, vm, | 127 if (!get_path_and_clip_bounds(target, drawState, path, vm, |
| 125 &devPathBounds, &devClipBounds)) { | 128 &devPathBounds, &devClipBounds)) { |
| 126 if (path.isInverseFillType()) { | 129 if (path.isInverseFillType()) { |
| 127 draw_around_inv_path(target, devClipBounds, devPathBounds); | 130 draw_around_inv_path(target, drawState, devClipBounds, devPathBounds
); |
| 128 } | 131 } |
| 129 return true; | 132 return true; |
| 130 } | 133 } |
| 131 | 134 |
| 132 SkAutoTUnref<GrTexture> texture( | 135 SkAutoTUnref<GrTexture> texture( |
| 133 GrSWMaskHelper::DrawPathMaskToTexture(fContext, path, stroke, | 136 GrSWMaskHelper::DrawPathMaskToTexture(fContext, path, stroke, |
| 134 devPathBounds, | 137 devPathBounds, |
| 135 antiAlias, &vm)); | 138 antiAlias, &vm)); |
| 136 if (NULL == texture) { | 139 if (NULL == texture) { |
| 137 return false; | 140 return false; |
| 138 } | 141 } |
| 139 | 142 |
| 140 GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, devPathBounds); | 143 GrDrawState copy = *drawState; |
| 144 GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, ©, devPathBoun
ds); |
| 141 | 145 |
| 142 if (path.isInverseFillType()) { | 146 if (path.isInverseFillType()) { |
| 143 draw_around_inv_path(target, devClipBounds, devPathBounds); | 147 draw_around_inv_path(target, drawState, devClipBounds, devPathBounds); |
| 144 } | 148 } |
| 145 | 149 |
| 146 return true; | 150 return true; |
| 147 } | 151 } |
| OLD | NEW |