blob: 0e471dd148d641d1d890daa7740b11dfd458e473 [file] [log] [blame]
robertphillips028b98a2015-01-14 09:44:02 -08001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9
10namespace skiagm {
11
12// This GM exercises the use case found in crbug.com/423834.
13// The following pattern:
14// clipRect(r);
15// drawRect(r, withAA);
16// drawRect(r, noAA);
17// can leave 1 pixel wide remnants of the first rect.
18class ClipDrawDrawGM : public GM {
19public:
20 ClipDrawDrawGM() {
21 this->setBGColor(0xFFCCCCCC);
22 }
23
24protected:
25 SkString onShortName() SK_OVERRIDE {
26 return SkString("clipdrawdraw");
27 }
28
29 SkISize onISize() SK_OVERRIDE {
30 return SkISize::Make(512, 512);
31 }
32
33 // Vertical remnant
34 static void draw1(SkCanvas* canvas) {
35 SkPaint p;
36 p.setAntiAlias(true);
37
38 const SkRect rect = SkRect::MakeXYWH(8, 9, 404, 313);
39
40 canvas->save();
41
42 canvas->scale(0.5f, 0.5f);
43 canvas->translate(265, 265);
44
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();
77 }
78
79 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
80 draw1(canvas);
81 draw2(canvas);
82 }
83
84private:
85 typedef GM INHERITED;
86};
87
88//////////////////////////////////////////////////////////////////////////////
89
90DEF_GM(return SkNEW(ClipDrawDrawGM);)
91
92}