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 if (!drawState->setIdentityViewMatrix()) { |
80 if (!avmr.setIdentity(target->drawState())) { | |
81 return; | 84 return; |
82 } | 85 } |
83 SkRect rect; | 86 SkRect rect; |
84 if (devClipBounds.fTop < devPathBounds.fTop) { | 87 if (devClipBounds.fTop < devPathBounds.fTop) { |
85 rect.iset(devClipBounds.fLeft, devClipBounds.fTop, | 88 rect.iset(devClipBounds.fLeft, devClipBounds.fTop, |
86 devClipBounds.fRight, devPathBounds.fTop); | 89 devClipBounds.fRight, devPathBounds.fTop); |
87 target->drawSimpleRect(rect); | 90 target->drawSimpleRect(drawState, rect); |
88 } | 91 } |
89 if (devClipBounds.fLeft < devPathBounds.fLeft) { | 92 if (devClipBounds.fLeft < devPathBounds.fLeft) { |
90 rect.iset(devClipBounds.fLeft, devPathBounds.fTop, | 93 rect.iset(devClipBounds.fLeft, devPathBounds.fTop, |
91 devPathBounds.fLeft, devPathBounds.fBottom); | 94 devPathBounds.fLeft, devPathBounds.fBottom); |
92 target->drawSimpleRect(rect); | 95 target->drawSimpleRect(drawState, rect); |
93 } | 96 } |
94 if (devClipBounds.fRight > devPathBounds.fRight) { | 97 if (devClipBounds.fRight > devPathBounds.fRight) { |
95 rect.iset(devPathBounds.fRight, devPathBounds.fTop, | 98 rect.iset(devPathBounds.fRight, devPathBounds.fTop, |
96 devClipBounds.fRight, devPathBounds.fBottom); | 99 devClipBounds.fRight, devPathBounds.fBottom); |
97 target->drawSimpleRect(rect); | 100 target->drawSimpleRect(drawState, rect); |
98 } | 101 } |
99 if (devClipBounds.fBottom > devPathBounds.fBottom) { | 102 if (devClipBounds.fBottom > devPathBounds.fBottom) { |
100 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, | 103 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, |
101 devClipBounds.fRight, devClipBounds.fBottom); | 104 devClipBounds.fRight, devClipBounds.fBottom); |
102 target->drawSimpleRect(rect); | 105 target->drawSimpleRect(drawState, rect); |
103 } | 106 } |
104 } | 107 } |
105 | 108 |
106 } | 109 } |
107 | 110 |
108 //////////////////////////////////////////////////////////////////////////////// | 111 //////////////////////////////////////////////////////////////////////////////// |
109 // return true on success; false on failure | 112 // return true on success; false on failure |
110 bool GrSoftwarePathRenderer::onDrawPath(const SkPath& path, | 113 bool GrSoftwarePathRenderer::onDrawPath(GrDrawTarget* target, |
| 114 GrDrawState* drawState, |
| 115 const SkPath& path, |
111 const SkStrokeRec& stroke, | 116 const SkStrokeRec& stroke, |
112 GrDrawTarget* target, | |
113 bool antiAlias) { | 117 bool antiAlias) { |
114 | 118 |
115 if (NULL == fContext) { | 119 if (NULL == fContext) { |
116 return false; | 120 return false; |
117 } | 121 } |
118 | 122 |
119 GrDrawState* drawState = target->drawState(); | |
120 | |
121 SkMatrix vm = drawState->getViewMatrix(); | 123 SkMatrix vm = drawState->getViewMatrix(); |
122 | 124 |
123 SkIRect devPathBounds, devClipBounds; | 125 SkIRect devPathBounds, devClipBounds; |
124 if (!get_path_and_clip_bounds(target, path, vm, | 126 if (!get_path_and_clip_bounds(target, drawState, path, vm, |
125 &devPathBounds, &devClipBounds)) { | 127 &devPathBounds, &devClipBounds)) { |
126 if (path.isInverseFillType()) { | 128 if (path.isInverseFillType()) { |
127 draw_around_inv_path(target, devClipBounds, devPathBounds); | 129 draw_around_inv_path(target, drawState, devClipBounds, devPathBounds
); |
128 } | 130 } |
129 return true; | 131 return true; |
130 } | 132 } |
131 | 133 |
132 SkAutoTUnref<GrTexture> texture( | 134 SkAutoTUnref<GrTexture> texture( |
133 GrSWMaskHelper::DrawPathMaskToTexture(fContext, path, stroke, | 135 GrSWMaskHelper::DrawPathMaskToTexture(fContext, path, stroke, |
134 devPathBounds, | 136 devPathBounds, |
135 antiAlias, &vm)); | 137 antiAlias, &vm)); |
136 if (NULL == texture) { | 138 if (NULL == texture) { |
137 return false; | 139 return false; |
138 } | 140 } |
139 | 141 |
140 GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, devPathBounds); | 142 GrDrawState copy = *drawState; |
| 143 GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, ©, devPathBoun
ds); |
141 | 144 |
142 if (path.isInverseFillType()) { | 145 if (path.isInverseFillType()) { |
143 draw_around_inv_path(target, devClipBounds, devPathBounds); | 146 draw_around_inv_path(target, drawState, devClipBounds, devPathBounds); |
144 } | 147 } |
145 | 148 |
146 return true; | 149 return true; |
147 } | 150 } |
OLD | NEW |