blob: eba756c9e0ab299fec23b2857166b8535c593858 [file] [log] [blame]
joshualitt5acfea72014-08-11 13:55:34 -07001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkFont.h"
11#include "include/core/SkImageFilter.h"
12#include "include/core/SkPaint.h"
13#include "include/core/SkScalar.h"
14#include "include/core/SkTypeface.h"
15#include "include/core/SkTypes.h"
Michael Ludwig898bbfa2019-08-02 15:21:23 -040016#include "include/effects/SkImageFilters.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "include/utils/SkRandom.h"
18#include "tools/ToolUtils.h"
joshualitt5acfea72014-08-11 13:55:34 -070019
20// TODO deprecate imageblur
21
Hal Canary6ac0df82019-01-07 16:01:22 -050022constexpr int kWidth = 500;
23constexpr int kHeight = 500;
joshualitt5acfea72014-08-11 13:55:34 -070024
Hal Canary6ac0df82019-01-07 16:01:22 -050025DEF_SIMPLE_GM(imageblur2, canvas, kWidth, kHeight) {
26 constexpr float kBlurSigmas[] = { 0.0, 0.3f, 0.5f, 2.0f, 32.0f, 80.0f };
27 const char* kTestStrings[] = {
joshualitt5acfea72014-08-11 13:55:34 -070028 "The quick`~",
29 "brown fox[]",
30 "jumped over",
31 "the lazy@#$",
32 "dog.{}!%^&",
33 "*()+=-\\'\"/",
Hal Canary6ac0df82019-01-07 16:01:22 -050034 };
35 constexpr int sigmaCount = SK_ARRAY_COUNT(kBlurSigmas);
36 constexpr int testStringCount = SK_ARRAY_COUNT(kTestStrings);
37 constexpr SkScalar dx = kWidth / sigmaCount;
38 constexpr SkScalar dy = kHeight / sigmaCount;
39 constexpr SkScalar textSize = 12;
joshualitt5acfea72014-08-11 13:55:34 -070040
Mike Kleinea3f0142019-03-20 11:12:10 -050041 SkFont font(ToolUtils::create_portable_typeface(), textSize);
Hal Canary6ac0df82019-01-07 16:01:22 -050042 font.setEdging(SkFont::Edging::kAlias);
joshualitt5acfea72014-08-11 13:55:34 -070043
Hal Canary6ac0df82019-01-07 16:01:22 -050044 for (int x = 0; x < sigmaCount; x++) {
45 SkScalar sigmaX = kBlurSigmas[x];
46 for (int y = 0; y < sigmaCount; y++) {
47 SkScalar sigmaY = kBlurSigmas[y];
joshualitt5acfea72014-08-11 13:55:34 -070048
Hal Canary6ac0df82019-01-07 16:01:22 -050049 SkPaint paint;
Michael Ludwig898bbfa2019-08-02 15:21:23 -040050 paint.setImageFilter(SkImageFilters::Blur(sigmaX, sigmaY, nullptr));
Hal Canary6ac0df82019-01-07 16:01:22 -050051 canvas->saveLayer(nullptr, &paint);
joshualitt5acfea72014-08-11 13:55:34 -070052
Hal Canary6ac0df82019-01-07 16:01:22 -050053 SkRandom rand;
54 SkPaint textPaint;
Mike Kleinea3f0142019-03-20 11:12:10 -050055 textPaint.setColor(ToolUtils::color_to_565(rand.nextBits(24) | 0xFF000000));
Hal Canary6ac0df82019-01-07 16:01:22 -050056 for (int i = 0; i < testStringCount; i++) {
57 canvas->drawString(kTestStrings[i],
58 SkIntToScalar(x * dx),
59 SkIntToScalar(y * dy + textSize * i + textSize),
60 font,
61 textPaint);
joshualitt5acfea72014-08-11 13:55:34 -070062 }
Hal Canary6ac0df82019-01-07 16:01:22 -050063 canvas->restore();
joshualitt5acfea72014-08-11 13:55:34 -070064 }
65 }
joshualitt5acfea72014-08-11 13:55:34 -070066}