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 "gm.h" | 8 #include "gm.h" |
9 #include "SkAAClip.h" | 9 #include "SkAAClip.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 150.65f); | 60 150.65f); |
61 fRect = fBase; | 61 fRect = fBase; |
62 fRect.inset(5, 5); | 62 fRect.inset(5, 5); |
63 fRect.offset(25, 25); | 63 fRect.offset(25, 25); |
64 | 64 |
65 fBasePath.addRoundRect(fBase, SkIntToScalar(5), SkIntToScalar(5)); | 65 fBasePath.addRoundRect(fBase, SkIntToScalar(5), SkIntToScalar(5)); |
66 fRectPath.addRoundRect(fRect, SkIntToScalar(5), SkIntToScalar(5)); | 66 fRectPath.addRoundRect(fRect, SkIntToScalar(5), SkIntToScalar(5)); |
67 INHERITED::setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); | 67 INHERITED::setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
68 } | 68 } |
69 | 69 |
70 void buildRgn(SkAAClip* clip, SkRegion::Op op) { | 70 void buildRgn(SkAAClip* clip, SkCanvas::ClipOp op) { |
71 clip->setPath(fBasePath, nullptr, true); | 71 clip->setPath(fBasePath, nullptr, true); |
72 | 72 |
73 SkAAClip clip2; | 73 SkAAClip clip2; |
74 clip2.setPath(fRectPath, nullptr, true); | 74 clip2.setPath(fRectPath, nullptr, true); |
75 clip->op(clip2, op); | 75 clip->op(clip2, (SkRegion::Op)op); |
76 } | 76 } |
77 | 77 |
78 void drawOrig(SkCanvas* canvas) { | 78 void drawOrig(SkCanvas* canvas) { |
79 SkPaint paint; | 79 SkPaint paint; |
80 | 80 |
81 paint.setStyle(SkPaint::kStroke_Style); | 81 paint.setStyle(SkPaint::kStroke_Style); |
82 paint.setColor(SK_ColorBLACK); | 82 paint.setColor(SK_ColorBLACK); |
83 | 83 |
84 canvas->drawRect(fBase, paint); | 84 canvas->drawRect(fBase, paint); |
85 canvas->drawRect(fRect, paint); | 85 canvas->drawRect(fRect, paint); |
86 } | 86 } |
87 | 87 |
88 void drawRgnOped(SkCanvas* canvas, SkRegion::Op op, SkColor color) { | 88 void drawRgnOped(SkCanvas* canvas, SkCanvas::ClipOp op, SkColor color) { |
89 | 89 |
90 SkAAClip clip; | 90 SkAAClip clip; |
91 | 91 |
92 this->buildRgn(&clip, op); | 92 this->buildRgn(&clip, op); |
93 this->drawOrig(canvas); | 93 this->drawOrig(canvas); |
94 | 94 |
95 SkPaint paint; | 95 SkPaint paint; |
96 paint.setColor(color); | 96 paint.setColor(color); |
97 paint_rgn(canvas, clip, paint); | 97 paint_rgn(canvas, clip, paint); |
98 } | 98 } |
99 | 99 |
100 void drawPathsOped(SkCanvas* canvas, SkRegion::Op op, SkColor color) { | 100 void drawPathsOped(SkCanvas* canvas, SkCanvas::ClipOp op, SkColor color) { |
101 | 101 |
102 this->drawOrig(canvas); | 102 this->drawOrig(canvas); |
103 | 103 |
104 canvas->save(); | 104 canvas->save(); |
105 | 105 |
106 // create the clip mask with the supplied boolean op | 106 // create the clip mask with the supplied boolean op |
107 if (kPath_GeomType == fGeomType) { | 107 if (kPath_GeomType == fGeomType) { |
108 // path-based case | 108 // path-based case |
109 canvas->clipPath(fBasePath, SkRegion::kReplace_Op, true); | 109 canvas->clipPath(fBasePath, SkCanvas::kReplace_Op, true); |
110 canvas->clipPath(fRectPath, op, true); | 110 canvas->clipPath(fRectPath, op, true); |
111 } else { | 111 } else { |
112 // rect-based case | 112 // rect-based case |
113 canvas->clipRect(fBase, SkRegion::kReplace_Op, true); | 113 canvas->clipRect(fBase, SkCanvas::kReplace_Op, true); |
114 canvas->clipRect(fRect, op, true); | 114 canvas->clipRect(fRect, op, true); |
115 } | 115 } |
116 | 116 |
117 // draw a rect that will entirely cover the clip mask area | 117 // draw a rect that will entirely cover the clip mask area |
118 SkPaint paint; | 118 SkPaint paint; |
119 paint.setColor(color); | 119 paint.setColor(color); |
120 | 120 |
121 SkRect r = SkRect::MakeLTRB(SkIntToScalar(90), SkIntToScalar(90), | 121 SkRect r = SkRect::MakeLTRB(SkIntToScalar(90), SkIntToScalar(90), |
122 SkIntToScalar(180), SkIntToScalar(180)); | 122 SkIntToScalar(180), SkIntToScalar(180)); |
123 | 123 |
(...skipping 13 matching lines...) Expand all Loading... |
137 | 137 |
138 SkISize onISize() override { | 138 SkISize onISize() override { |
139 return SkISize::Make(640, 480); | 139 return SkISize::Make(640, 480); |
140 } | 140 } |
141 | 141 |
142 void onDraw(SkCanvas* canvas) override { | 142 void onDraw(SkCanvas* canvas) override { |
143 | 143 |
144 const struct { | 144 const struct { |
145 SkColor fColor; | 145 SkColor fColor; |
146 const char* fName; | 146 const char* fName; |
147 SkRegion::Op fOp; | 147 SkCanvas::ClipOp fOp; |
148 } gOps[] = { | 148 } gOps[] = { |
149 { SK_ColorBLACK, "Difference", SkRegion::kDifference_Op }, | 149 { SK_ColorBLACK, "Difference", SkCanvas::kDifference_Op }, |
150 { SK_ColorRED, "Intersect", SkRegion::kIntersect_Op }, | 150 { SK_ColorRED, "Intersect", SkCanvas::kIntersect_Op }, |
151 { sk_tool_utils::color_to_565(0xFF008800), "Union", SkRegion::kUnion
_Op }, | 151 { sk_tool_utils::color_to_565(0xFF008800), "Union", SkCanvas::kUnion
_Op }, |
152 { SK_ColorGREEN, "Rev Diff", SkRegion::kReverseDifference_Op }, | 152 { SK_ColorGREEN, "Rev Diff", SkCanvas::kReverseDifference_Op }, |
153 { SK_ColorYELLOW, "Replace", SkRegion::kReplace_Op }, | 153 { SK_ColorYELLOW, "Replace", SkCanvas::kReplace_Op }, |
154 { SK_ColorBLUE, "XOR", SkRegion::kXOR_Op }, | 154 { SK_ColorBLUE, "XOR", SkCanvas::kXOR_Op }, |
155 }; | 155 }; |
156 | 156 |
157 SkPaint textPaint; | 157 SkPaint textPaint; |
158 textPaint.setAntiAlias(true); | 158 textPaint.setAntiAlias(true); |
159 sk_tool_utils::set_portable_typeface(&textPaint); | 159 sk_tool_utils::set_portable_typeface(&textPaint); |
160 textPaint.setTextSize(SK_Scalar1*24); | 160 textPaint.setTextSize(SK_Scalar1*24); |
161 int xOff = 0; | 161 int xOff = 0; |
162 | 162 |
163 for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); op++) { | 163 for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); op++) { |
164 canvas->drawText(gOps[op].fName, strlen(gOps[op].fName), | 164 canvas->drawText(gOps[op].fName, strlen(gOps[op].fName), |
(...skipping 29 matching lines...) Expand all Loading... |
194 }; | 194 }; |
195 | 195 |
196 ////////////////////////////////////////////////////////////////////////////// | 196 ////////////////////////////////////////////////////////////////////////////// |
197 | 197 |
198 // rects | 198 // rects |
199 DEF_GM( return new SimpleClipGM(SimpleClipGM::kRect_GeomType); ) | 199 DEF_GM( return new SimpleClipGM(SimpleClipGM::kRect_GeomType); ) |
200 DEF_GM( return new SimpleClipGM(SimpleClipGM::kPath_GeomType); ) | 200 DEF_GM( return new SimpleClipGM(SimpleClipGM::kPath_GeomType); ) |
201 DEF_GM( return new SimpleClipGM(SimpleClipGM::kAAClip_GeomType); ) | 201 DEF_GM( return new SimpleClipGM(SimpleClipGM::kAAClip_GeomType); ) |
202 | 202 |
203 } | 203 } |
OLD | NEW |