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 "GrStrokePathRenderer.h" | 8 #include "GrStrokePathRenderer.h" |
9 | 9 |
10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
11 #include "SkPath.h" | 11 #include "SkPath.h" |
12 #include "SkStrokeRec.h" | 12 #include "SkStrokeRec.h" |
13 | 13 |
14 namespace { | 14 static bool is_clockwise(const SkVector& before, const SkVector& after) { |
15 | |
16 bool is_clockwise(const SkVector& before, const SkVector& after) { | |
17 return before.cross(after) > 0; | 15 return before.cross(after) > 0; |
18 } | 16 } |
19 | 17 |
20 enum IntersectionType { | 18 enum IntersectionType { |
21 kNone_IntersectionType, | 19 kNone_IntersectionType, |
22 kIn_IntersectionType, | 20 kIn_IntersectionType, |
23 kOut_IntersectionType | 21 kOut_IntersectionType |
24 }; | 22 }; |
25 | 23 |
26 IntersectionType intersection(const SkPoint& p1, const SkPoint& p2, | 24 static IntersectionType intersection(const SkPoint& p1, const SkPoint& p2, |
27 const SkPoint& p3, const SkPoint& p4, | 25 const SkPoint& p3, const SkPoint& p4, |
28 SkPoint& res) { | 26 SkPoint& res) { |
29 // Store the values for fast access and easy | 27 // Store the values for fast access and easy |
30 // equations-to-code conversion | 28 // equations-to-code conversion |
31 SkScalar x1 = p1.x(), x2 = p2.x(), x3 = p3.x(), x4 = p4.x(); | 29 SkScalar x1 = p1.x(), x2 = p2.x(), x3 = p3.x(), x4 = p4.x(); |
32 SkScalar y1 = p1.y(), y2 = p2.y(), y3 = p3.y(), y4 = p4.y(); | 30 SkScalar y1 = p1.y(), y2 = p2.y(), y3 = p3.y(), y4 = p4.y(); |
33 | 31 |
34 SkScalar d = SkScalarMul(x1 - x2, y3 - y4) - SkScalarMul(y1 - y2, x3 - x4); | 32 SkScalar d = SkScalarMul(x1 - x2, y3 - y4) - SkScalarMul(y1 - y2, x3 - x4); |
35 // If d is zero, there is no intersection | 33 // If d is zero, there is no intersection |
36 if (SkScalarNearlyZero(d)) { | 34 if (SkScalarNearlyZero(d)) { |
37 return kNone_IntersectionType; | 35 return kNone_IntersectionType; |
38 } | 36 } |
39 | 37 |
40 // Get the x and y | 38 // Get the x and y |
41 SkScalar pre = SkScalarMul(x1, y2) - SkScalarMul(y1, x2), | 39 SkScalar pre = SkScalarMul(x1, y2) - SkScalarMul(y1, x2), |
42 post = SkScalarMul(x3, y4) - SkScalarMul(y3, x4); | 40 post = SkScalarMul(x3, y4) - SkScalarMul(y3, x4); |
43 // Compute the point of intersection | 41 // Compute the point of intersection |
44 res.set(SkScalarDiv(SkScalarMul(pre, x3 - x4) - SkScalarMul(x1 - x2, post),
d), | 42 res.set(SkScalarDiv(SkScalarMul(pre, x3 - x4) - SkScalarMul(x1 - x2, post),
d), |
45 SkScalarDiv(SkScalarMul(pre, y3 - y4) - SkScalarMul(y1 - y2, post),
d)); | 43 SkScalarDiv(SkScalarMul(pre, y3 - y4) - SkScalarMul(y1 - y2, post),
d)); |
46 | 44 |
47 // Check if the x and y coordinates are within both lines | 45 // Check if the x and y coordinates are within both lines |
48 return (res.x() < GrMin(x1, x2) || res.x() > GrMax(x1, x2) || | 46 return (res.x() < GrMin(x1, x2) || res.x() > GrMax(x1, x2) || |
49 res.x() < GrMin(x3, x4) || res.x() > GrMax(x3, x4) || | 47 res.x() < GrMin(x3, x4) || res.x() > GrMax(x3, x4) || |
50 res.y() < GrMin(y1, y2) || res.y() > GrMax(y1, y2) || | 48 res.y() < GrMin(y1, y2) || res.y() > GrMax(y1, y2) || |
51 res.y() < GrMin(y3, y4) || res.y() > GrMax(y3, y4)) ? | 49 res.y() < GrMin(y3, y4) || res.y() > GrMax(y3, y4)) ? |
52 kOut_IntersectionType : kIn_IntersectionType; | 50 kOut_IntersectionType : kIn_IntersectionType; |
53 } | 51 } |
54 | 52 |
55 } // namespace | |
56 | |
57 GrStrokePathRenderer::GrStrokePathRenderer() { | 53 GrStrokePathRenderer::GrStrokePathRenderer() { |
58 } | 54 } |
59 | 55 |
60 bool GrStrokePathRenderer::canDrawPath(const SkPath& path, | 56 bool GrStrokePathRenderer::canDrawPath(const SkPath& path, |
61 const SkStrokeRec& stroke, | 57 const SkStrokeRec& stroke, |
62 const GrDrawTarget* target, | 58 const GrDrawTarget* target, |
63 bool antiAlias) const { | 59 bool antiAlias) const { |
64 // FIXME : put the proper condition once GrDrawTarget::isOpaque is implement
ed | 60 // FIXME : put the proper condition once GrDrawTarget::isOpaque is implement
ed |
65 const bool isOpaque = true; // target->isOpaque(); | 61 const bool isOpaque = true; // target->isOpaque(); |
66 | 62 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 if (vCount > 0) { | 291 if (vCount > 0) { |
296 target->drawIndexed(kTriangles_GrPrimitiveType, | 292 target->drawIndexed(kTriangles_GrPrimitiveType, |
297 0, // start vertex | 293 0, // start vertex |
298 0, // start index | 294 0, // start index |
299 vCount, | 295 vCount, |
300 iCount); | 296 iCount); |
301 } | 297 } |
302 | 298 |
303 return true; | 299 return true; |
304 } | 300 } |
OLD | NEW |