summaryrefslogtreecommitdiff
path: root/chromium/third_party/skia/gm/imageblur2.cpp
blob: eba756c9e0ab299fec23b2857166b8535c593858 (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
/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkFont.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkPaint.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkImageFilters.h"
#include "include/utils/SkRandom.h"
#include "tools/ToolUtils.h"

// TODO deprecate imageblur

constexpr int kWidth  = 500;
constexpr int kHeight = 500;

DEF_SIMPLE_GM(imageblur2, canvas, kWidth, kHeight) {
    constexpr float kBlurSigmas[] = { 0.0, 0.3f, 0.5f, 2.0f, 32.0f, 80.0f };
    const char* kTestStrings[] = {
        "The quick`~",
        "brown fox[]",
        "jumped over",
        "the lazy@#$",
        "dog.{}!%^&",
        "*()+=-\\'\"/",
    };
    constexpr int sigmaCount = SK_ARRAY_COUNT(kBlurSigmas);
    constexpr int testStringCount = SK_ARRAY_COUNT(kTestStrings);
    constexpr SkScalar dx = kWidth / sigmaCount;
    constexpr SkScalar dy = kHeight / sigmaCount;
    constexpr SkScalar textSize = 12;

    SkFont font(ToolUtils::create_portable_typeface(), textSize);
    font.setEdging(SkFont::Edging::kAlias);

    for (int x = 0; x < sigmaCount; x++) {
        SkScalar sigmaX = kBlurSigmas[x];
        for (int y = 0; y < sigmaCount; y++) {
            SkScalar sigmaY = kBlurSigmas[y];

            SkPaint paint;
            paint.setImageFilter(SkImageFilters::Blur(sigmaX, sigmaY, nullptr));
            canvas->saveLayer(nullptr, &paint);

            SkRandom rand;
            SkPaint textPaint;
            textPaint.setColor(ToolUtils::color_to_565(rand.nextBits(24) | 0xFF000000));
            for (int i = 0; i < testStringCount; i++) {
                canvas->drawString(kTestStrings[i],
                                   SkIntToScalar(x * dx),
                                   SkIntToScalar(y * dy + textSize * i + textSize),
                                   font,
                                   textPaint);
            }
            canvas->restore();
        }
    }
}