aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/clipdrawdraw.cpp
blob: 1aecb9ff3b177516d9cffaf9ddf82d7b9dc06edc (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
/*
 * 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"

// This GM exercises the use case found in crbug.com/423834.
// The following pattern:
//    save();
//    clipRect(rect, noAA);
//    drawRect(bigRect, noAA);
//    restore();
//
//    drawRect(rect, noAA);
// can leave 1 pixel wide remnants of the first rect.
static void Draw(SkCanvas* canvas, const SkRect& rect) {
        SkPaint p;
        p.setAntiAlias(false);

        const SkRect bigRect = SkRect::MakeWH(600, 600);

        canvas->save();
            // draw a black rect through the clip
            canvas->save();
                canvas->clipRect(rect);
                canvas->drawRect(bigRect, p);
            canvas->restore();

            // now draw the white rect on top
            p.setColor(SK_ColorWHITE);
            canvas->drawRect(rect, p);
        canvas->restore();
}

DEF_SIMPLE_GM_BG(clipdrawdraw, canvas, 512, 512,
                 sk_tool_utils::color_to_565(0xFFCCCCCC)) {
        // Vertical remnant
        const SkRect rect1 = SkRect::MakeLTRB(136.5f, 137.5f, 338.5f, 293.5f);

        // Horizontal remnant
        // 179.488 rounds the right way (i.e., 179), 179.499 rounds the wrong way (i.e., 180)
        const SkRect rect2 = SkRect::MakeLTRB(207.5f, 179.499f, 530.5f, 429.5f);

        Draw(canvas, rect1);
        Draw(canvas, rect2);
}