aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/clipdrawdraw.cpp
blob: 0e471dd148d641d1d890daa7740b11dfd458e473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm.h"

namespace skiagm {

// This GM exercises the use case found in crbug.com/423834.
// The following pattern:
//    clipRect(r);
//    drawRect(r, withAA);
//    drawRect(r, noAA);
// can leave 1 pixel wide remnants of the first rect.
class ClipDrawDrawGM : public GM {
public:
    ClipDrawDrawGM() {
        this->setBGColor(0xFFCCCCCC);
    }

protected:
    SkString onShortName() SK_OVERRIDE {
        return SkString("clipdrawdraw");
    }

    SkISize onISize() SK_OVERRIDE {
        return SkISize::Make(512, 512);
    }

    // Vertical remnant
    static void draw1(SkCanvas* canvas) {
        SkPaint p;
        p.setAntiAlias(true);

        const SkRect rect = SkRect::MakeXYWH(8, 9, 404, 313);

        canvas->save();

        canvas->scale(0.5f, 0.5f);
        canvas->translate(265, 265);

        canvas->save();
        canvas->clipRect(rect);
        canvas->drawRect(rect, p);
        canvas->restore();

        p.setColor(SK_ColorWHITE);
        p.setAntiAlias(false);
        canvas->drawRect(rect, p);
        canvas->restore();
    }

    // Horizontal remnant
    static void draw2(SkCanvas* canvas) {
        SkPaint p;
        p.setAntiAlias(true);

        const SkRect rect = SkRect::MakeXYWH(8, 9, 404, 313);

        canvas->save();

        canvas->translate(200.800003f, 172.299988f);
        canvas->scale(0.8f, 0.8f);

        canvas->save();
        canvas->clipRect(rect);
        canvas->drawRect(rect, p);
        canvas->restore();

        p.setColor(SK_ColorWHITE);
        p.setAntiAlias(false);
        canvas->drawRect(rect, p);
        canvas->restore();
    }

    void onDraw(SkCanvas* canvas) SK_OVERRIDE {
        draw1(canvas);
        draw2(canvas);
    }

private:
    typedef GM INHERITED;
};

//////////////////////////////////////////////////////////////////////////////

DEF_GM(return SkNEW(ClipDrawDrawGM);)

}