Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: gm/coloremoji.cpp

Issue 1852743002: Update SkBlurImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT & address code review comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/ImageFilterDAGBench.cpp ('k') | gm/colorfilterimagefilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 9
10 #include "Resources.h" 10 #include "Resources.h"
11 #include "SkBlurImageFilter.h" 11 #include "SkBlurImageFilter.h"
12 #include "SkColorFilterImageFilter.h" 12 #include "SkColorFilterImageFilter.h"
13 #include "SkColorMatrixFilter.h" 13 #include "SkColorMatrixFilter.h"
14 #include "SkCanvas.h" 14 #include "SkCanvas.h"
15 #include "SkGradientShader.h" 15 #include "SkGradientShader.h"
16 #include "SkStream.h" 16 #include "SkStream.h"
17 #include "SkTypeface.h" 17 #include "SkTypeface.h"
18 18
19 /* 19 /*
20 * Spits out a dummy gradient to test blur with shader on paint 20 * Spits out a dummy gradient to test blur with shader on paint
21 */ 21 */
22 static sk_sp<SkShader> MakeLinear() { 22 static sk_sp<SkShader> MakeLinear() {
23 static const SkPoint kPts[] = { { 0, 0 }, { 32, 32 } }; 23 static const SkPoint kPts[] = { { 0, 0 }, { 32, 32 } };
24 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; 24 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
25 static const SkColor kColors[] = {0x80F00080, 0xF0F08000, 0x800080F0 }; 25 static const SkColor kColors[] = {0x80F00080, 0xF0F08000, 0x800080F0 };
26 return SkGradientShader::MakeLinear(kPts, kColors, kPos, SK_ARRAY_COUNT(kCol ors), 26 return SkGradientShader::MakeLinear(kPts, kColors, kPos, SK_ARRAY_COUNT(kCol ors),
27 SkShader::kClamp_TileMode); 27 SkShader::kClamp_TileMode);
28 } 28 }
29 29
30 static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) { 30 static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) {
31 SkScalar matrix[20]; 31 SkScalar matrix[20];
32 memset(matrix, 0, 20 * sizeof(SkScalar)); 32 memset(matrix, 0, 20 * sizeof(SkScalar));
33 matrix[0] = matrix[5] = matrix[10] = 0.2126f; 33 matrix[0] = matrix[5] = matrix[10] = 0.2126f;
34 matrix[1] = matrix[6] = matrix[11] = 0.7152f; 34 matrix[1] = matrix[6] = matrix[11] = 0.7152f;
35 matrix[2] = matrix[7] = matrix[12] = 0.0722f; 35 matrix[2] = matrix[7] = matrix[12] = 0.0722f;
36 matrix[18] = 1.0f; 36 matrix[18] = 1.0f;
37 auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); 37 sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matri x));
38 return SkColorFilterImageFilter::Create(filter.get(), input); 38 return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(filter.get(), i nput.get()));
39 } 39 }
40 40
41 static SkImageFilter* make_blur(float amount, SkImageFilter* input = nullptr) { 41 static sk_sp<SkImageFilter> make_blur(float amount, sk_sp<SkImageFilter> input) {
42 return SkBlurImageFilter::Create(amount, amount, input); 42 return SkBlurImageFilter::Make(amount, amount, std::move(input));
43 } 43 }
44 44
45 namespace skiagm { 45 namespace skiagm {
46 46
47 class ColorEmojiGM : public GM { 47 class ColorEmojiGM : public GM {
48 public: 48 public:
49 ColorEmojiGM() { } 49 ColorEmojiGM() { }
50 50
51 protected: 51 protected:
52 struct EmojiFont { 52 struct EmojiFont {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 for (int makeLinear = 0; makeLinear < 2; makeLinear++) { 91 for (int makeLinear = 0; makeLinear < 2; makeLinear++) {
92 for (int makeBlur = 0; makeBlur < 2; makeBlur++) { 92 for (int makeBlur = 0; makeBlur < 2; makeBlur++) {
93 for (int makeGray = 0; makeGray < 2; makeGray++) { 93 for (int makeGray = 0; makeGray < 2; makeGray++) {
94 SkPaint shaderPaint; 94 SkPaint shaderPaint;
95 shaderPaint.setTypeface(paint.getTypeface()); 95 shaderPaint.setTypeface(paint.getTypeface());
96 if (SkToBool(makeLinear)) { 96 if (SkToBool(makeLinear)) {
97 shaderPaint.setShader(MakeLinear()); 97 shaderPaint.setShader(MakeLinear());
98 } 98 }
99 99
100 if (SkToBool(makeBlur) && SkToBool(makeGray)) { 100 if (SkToBool(makeBlur) && SkToBool(makeGray)) {
101 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(nul lptr)); 101 sk_sp<SkImageFilter> grayScale(make_grayscale(nullptr));
102 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, graySca le)); 102 sk_sp<SkImageFilter> blur(make_blur(3.0f, std::move(gray Scale)));
103 shaderPaint.setImageFilter(blur); 103 shaderPaint.setImageFilter(std::move(blur));
104 } else if (SkToBool(makeBlur)) { 104 } else if (SkToBool(makeBlur)) {
105 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, nullptr )); 105 shaderPaint.setImageFilter(make_blur(3.0f, nullptr));
106 shaderPaint.setImageFilter(blur);
107 } else if (SkToBool(makeGray)) { 106 } else if (SkToBool(makeGray)) {
108 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(nul lptr)); 107 shaderPaint.setImageFilter(make_grayscale(nullptr));
109 shaderPaint.setImageFilter(grayScale);
110 } 108 }
111 shaderPaint.setTextSize(30); 109 shaderPaint.setTextSize(30);
112 canvas->drawText(text, strlen(text), 380, SkIntToScalar(y_of fset), 110 canvas->drawText(text, strlen(text), 380, SkIntToScalar(y_of fset),
113 shaderPaint); 111 shaderPaint);
114 y_offset += 32; 112 y_offset += 32;
115 } 113 }
116 } 114 }
117 } 115 }
118 116
119 // setup work needed to draw text with different clips 117 // setup work needed to draw text with different clips
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 canvas->restore(); 151 canvas->restore();
154 canvas->translate(0, bounds.height() + SkIntToScalar(25)); 152 canvas->translate(0, bounds.height() + SkIntToScalar(25));
155 } 153 }
156 } 154 }
157 155
158 typedef GM INHERITED; 156 typedef GM INHERITED;
159 }; 157 };
160 158
161 ////////////////////////////////////////////////////////////////////////////// 159 //////////////////////////////////////////////////////////////////////////////
162 160
163 static GM* MyFactory(void*) { return new ColorEmojiGM; } 161 DEF_GM(return new ColorEmojiGM;)
164 static GMRegistry reg(MyFactory);
165 162
166 } 163 }
OLDNEW
« no previous file with comments | « bench/ImageFilterDAGBench.cpp ('k') | gm/colorfilterimagefilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698