aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/Checkerboard.cpp
blob: 80de125f1569f87c114df4e54e082f4f408a84be (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
/*
 * 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 "Checkerboard.h"
#include "SkCanvas.h"
#include "SkShader.h"

SkShader* sk_tools::CreateCheckerboardShader(
        SkColor c1, SkColor c2, int size) {
    SkBitmap bm;
    bm.allocN32Pixels(2 * size, 2 * size);
    bm.eraseColor(c1);
    bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
    bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
    return SkShader::CreateBitmapShader(
            bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
}

void sk_tools::DrawCheckerboard(SkCanvas* canvas,
                                    SkColor c1, SkColor c2, int size) {
    SkPaint paint;
    paint.setShader(CreateCheckerboardShader(c1, c2, size))->unref();
    canvas->drawPaint(paint);
}