OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 | 9 |
10 namespace skiagm { | 10 namespace skiagm { |
11 | 11 |
12 // This GM exercises the use case found in crbug.com/423834. | 12 // This GM exercises the use case found in crbug.com/423834. |
13 // The following pattern: | 13 // The following pattern: |
14 // clipRect(r); | 14 // save(); |
15 // drawRect(r, withAA); | 15 // clipRect(rect, noAA); |
16 // drawRect(r, noAA); | 16 // drawRect(bigRect, noAA); |
| 17 // restore(); |
| 18 // |
| 19 // drawRect(rect, noAA); |
17 // can leave 1 pixel wide remnants of the first rect. | 20 // can leave 1 pixel wide remnants of the first rect. |
18 class ClipDrawDrawGM : public GM { | 21 class ClipDrawDrawGM : public GM { |
19 public: | 22 public: |
20 ClipDrawDrawGM() { | 23 ClipDrawDrawGM() { this->setBGColor(0xFFCCCCCC); } |
21 this->setBGColor(0xFFCCCCCC); | |
22 } | |
23 | 24 |
24 protected: | 25 protected: |
25 SkString onShortName() SK_OVERRIDE { | 26 SkString onShortName() SK_OVERRIDE { return SkString("clipdrawdraw"); } |
26 return SkString("clipdrawdraw"); | |
27 } | |
28 | 27 |
29 SkISize onISize() SK_OVERRIDE { | 28 SkISize onISize() SK_OVERRIDE { return SkISize::Make(512, 512); } |
30 return SkISize::Make(512, 512); | |
31 } | |
32 | 29 |
33 // Vertical remnant | 30 static void Draw(SkCanvas* canvas, const SkRect& rect) { |
34 static void draw1(SkCanvas* canvas) { | |
35 SkPaint p; | 31 SkPaint p; |
36 p.setAntiAlias(true); | 32 p.setAntiAlias(false); |
37 | 33 |
38 const SkRect rect = SkRect::MakeXYWH(8, 9, 404, 313); | 34 const SkRect bigRect = SkRect::MakeWH(600, 600); |
39 | 35 |
40 canvas->save(); | 36 canvas->save(); |
| 37 // draw a black rect through the clip |
| 38 canvas->save(); |
| 39 canvas->clipRect(rect); |
| 40 canvas->drawRect(bigRect, p); |
| 41 canvas->restore(); |
41 | 42 |
42 canvas->scale(0.5f, 0.5f); | 43 // now draw the white rect on top |
43 canvas->translate(265, 265); | 44 p.setColor(SK_ColorWHITE); |
44 | 45 canvas->drawRect(rect, p); |
45 canvas->save(); | |
46 canvas->clipRect(rect); | |
47 canvas->drawRect(rect, p); | |
48 canvas->restore(); | |
49 | |
50 p.setColor(SK_ColorWHITE); | |
51 p.setAntiAlias(false); | |
52 canvas->drawRect(rect, p); | |
53 canvas->restore(); | |
54 } | |
55 | |
56 // Horizontal remnant | |
57 static void draw2(SkCanvas* canvas) { | |
58 SkPaint p; | |
59 p.setAntiAlias(true); | |
60 | |
61 const SkRect rect = SkRect::MakeXYWH(8, 9, 404, 313); | |
62 | |
63 canvas->save(); | |
64 | |
65 canvas->translate(200.800003f, 172.299988f); | |
66 canvas->scale(0.8f, 0.8f); | |
67 | |
68 canvas->save(); | |
69 canvas->clipRect(rect); | |
70 canvas->drawRect(rect, p); | |
71 canvas->restore(); | |
72 | |
73 p.setColor(SK_ColorWHITE); | |
74 p.setAntiAlias(false); | |
75 canvas->drawRect(rect, p); | |
76 canvas->restore(); | 46 canvas->restore(); |
77 } | 47 } |
78 | 48 |
79 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 49 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
80 draw1(canvas); | 50 // Vertical remnant |
81 draw2(canvas); | 51 const SkRect rect1 = SkRect::MakeLTRB(136.5f, 137.5f, 338.5f, 293.5f); |
| 52 |
| 53 // Horizontal remnant |
| 54 // 179.488 rounds the right way (i.e., 179), 179.499 rounds the wrong wa
y (i.e., 180) |
| 55 const SkRect rect2 = SkRect::MakeLTRB(207.5f, 179.499f, 530.5f, 429.5f); |
| 56 |
| 57 Draw(canvas, rect1); |
| 58 Draw(canvas, rect2); |
82 } | 59 } |
83 | 60 |
84 private: | 61 private: |
85 typedef GM INHERITED; | 62 typedef GM INHERITED; |
86 }; | 63 }; |
87 | 64 |
88 ////////////////////////////////////////////////////////////////////////////// | 65 ////////////////////////////////////////////////////////////////////////////// |
89 | 66 |
90 DEF_GM(return SkNEW(ClipDrawDrawGM);) | 67 DEF_GM(return SkNEW(ClipDrawDrawGM);) |
91 | 68 |
92 } | 69 } |
OLD | NEW |