aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/repeated_bitmap.cpp
blob: e6b06365e6724d2b297073cd49fcbeb683d0f872 (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
/*
 * Copyright 2015 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"
#include "sk_tool_utils.h"
#include "Resources.h"

DEF_SIMPLE_GM(repeated_bitmap, canvas, 576, 576) {
    sk_tool_utils::draw_checkerboard(canvas, 0xFF999999, SK_ColorWHITE, 12);
    SkRect rect = SkRect::MakeLTRB(-4.25f, -4.25f, 4.25f, 4.25f);
    SkPaint paint;
    paint.setColor(0xFF333333);
    SkBitmap bm;
    if (GetResourceAsBitmap("randPixels.png", &bm)) {
        for (int j = 0; j < 4; ++j) {
            for (int i = 0; i < 4; ++i) {
                SkAutoCanvasRestore autoCanvasRestore(canvas, true);
                canvas->scale(12.0f, 12.0f);
                canvas->translate(6.0f + 12.0f * SkIntToScalar(i),
                                  6.0f + 12.0f * SkIntToScalar(j));
                canvas->rotate(18.0f * (i + 4 * j));
                canvas->drawRect(rect, paint);
                canvas->drawBitmap(bm, -4.0f, -4.0f);
            }
        }
    }
}

DEF_SIMPLE_GM(repeated_bitmap_jpg, canvas, 576, 576) {
    sk_tool_utils::draw_checkerboard(canvas, 0xFF999999, SK_ColorWHITE, 12);
    SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f);
    SkPaint paint;
    paint.setColor(0xFF333333);
    SkBitmap bm;
    if (GetResourceAsBitmap("color_wheel.jpg", &bm)) {
        for (int j = 0; j < 4; ++j) {
            for (int i = 0; i < 4; ++i) {
                SkAutoCanvasRestore autoCanvasRestore(canvas, true);
                canvas->translate(96.0f + 192.0f * SkIntToScalar(i),
                                  96.0f + 192.0f * SkIntToScalar(j));
                canvas->rotate(18.0f * (i + 4 * j));
                canvas->drawRect(rect, paint);
                canvas->drawBitmap(bm, -64.0f, -64.0f);
            }
        }
    }
}