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

Side by Side Diff: gm/lumafilter.cpp

Issue 1821103004: Revert of Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.o… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « gm/imagefiltersgraph.cpp ('k') | gm/megalooper.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 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
11 #include "SkLumaColorFilter.h" 11 #include "SkLumaColorFilter.h"
12 12
13 static SkScalar kSize = 80; 13 static SkScalar kSize = 80;
14 static SkScalar kInset = 10; 14 static SkScalar kInset = 10;
15 static SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0xff, 0); 15 static SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0xff, 0);
16 static SkColor kColor2 = SkColorSetARGB(0xff, 0x82, 0xff, 0); 16 static SkColor kColor2 = SkColorSetARGB(0xff, 0x82, 0xff, 0);
17 17
18 static void draw_label(SkCanvas* canvas, const char* label, 18 static void draw_label(SkCanvas* canvas, const char* label,
19 const SkPoint& offset) { 19 const SkPoint& offset) {
20 SkPaint paint; 20 SkPaint paint;
21 sk_tool_utils::set_portable_typeface(&paint); 21 sk_tool_utils::set_portable_typeface(&paint);
22 size_t len = strlen(label); 22 size_t len = strlen(label);
23 23
24 SkScalar width = paint.measureText(label, len); 24 SkScalar width = paint.measureText(label, len);
25 canvas->drawText(label, len, offset.x() - width / 2, offset.y(), 25 canvas->drawText(label, len, offset.x() - width / 2, offset.y(),
26 paint); 26 paint);
27 } 27 }
28 28
29 static void draw_scene(SkCanvas* canvas, const sk_sp<SkColorFilter>& filter, SkX fermode::Mode mode, 29 static void draw_scene(SkCanvas* canvas, SkColorFilter* filter, SkXfermode::Mode mode,
30 const sk_sp<SkShader>& s1, const sk_sp<SkShader>& s2) { 30 const sk_sp<SkShader>& s1, const sk_sp<SkShader>& s2) {
31 SkPaint paint; 31 SkPaint paint;
32 paint.setAntiAlias(true); 32 paint.setAntiAlias(true);
33 SkRect r, c, bounds = SkRect::MakeWH(kSize, kSize); 33 SkRect r, c, bounds = SkRect::MakeWH(kSize, kSize);
34 34
35 c = bounds; 35 c = bounds;
36 c.fRight = bounds.centerX(); 36 c.fRight = bounds.centerX();
37 paint.setARGB(0x20, 0, 0, 0xff); 37 paint.setARGB(0x20, 0, 0, 0xff);
38 canvas->drawRect(bounds, paint); 38 canvas->drawRect(bounds, paint);
39 39
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 class LumaFilterGM : public skiagm::GM { 77 class LumaFilterGM : public skiagm::GM {
78 public: 78 public:
79 LumaFilterGM() { 79 LumaFilterGM() {
80 SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) }; 80 SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) };
81 SkColor g2Colors[] = { kColor2, SkColorSetA(kColor2, 0x20) }; 81 SkColor g2Colors[] = { kColor2, SkColorSetA(kColor2, 0x20) };
82 SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } }; 82 SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } };
83 SkPoint g2Points[] = { { 0, 0 }, { kSize, 0 } }; 83 SkPoint g2Points[] = { { 0, 0 }, { kSize, 0 } };
84 SkScalar pos[] = { 0.2f, 1.0f }; 84 SkScalar pos[] = { 0.2f, 1.0f };
85 85
86 fFilter = SkLumaColorFilter::Make(); 86 fFilter.reset(SkLumaColorFilter::Create());
87 fGr1 = SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_CO UNT(g1Colors), 87 fGr1 = SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_CO UNT(g1Colors),
88 SkShader::kClamp_TileMode); 88 SkShader::kClamp_TileMode);
89 fGr2 = SkGradientShader::MakeLinear(g2Points, g2Colors, pos, SK_ARRAY_CO UNT(g2Colors), 89 fGr2 = SkGradientShader::MakeLinear(g2Points, g2Colors, pos, SK_ARRAY_CO UNT(g2Colors),
90 SkShader::kClamp_TileMode); 90 SkShader::kClamp_TileMode);
91 } 91 }
92 92
93 protected: 93 protected:
94 94
95 SkString onShortName() override { 95 SkString onShortName() override {
96 return SkString("lumafilter"); 96 return SkString("lumafilter");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 for (size_t m = 0; m < SK_ARRAY_COUNT(modes); ++m) { 130 for (size_t m = 0; m < SK_ARRAY_COUNT(modes); ++m) {
131 draw_scene(canvas, fFilter, modes[m], shaders[i].fShader1, 131 draw_scene(canvas, fFilter, modes[m], shaders[i].fShader1,
132 shaders[i].fShader2); 132 shaders[i].fShader2);
133 canvas->translate(gridStep, 0); 133 canvas->translate(gridStep, 0);
134 } 134 }
135 canvas->restore(); 135 canvas->restore();
136 } 136 }
137 } 137 }
138 138
139 private: 139 private:
140 sk_sp<SkColorFilter> fFilter; 140 SkAutoTUnref<SkColorFilter> fFilter;
141 sk_sp<SkShader> fGr1, fGr2; 141 sk_sp<SkShader> fGr1, fGr2;
142 142
143 typedef skiagm::GM INHERITED; 143 typedef skiagm::GM INHERITED;
144 }; 144 };
145 145
146 ////////////////////////////////////////////////////////////////////////////// 146 //////////////////////////////////////////////////////////////////////////////
147 147
148 DEF_GM(return new LumaFilterGM;) 148 DEF_GM(return new LumaFilterGM;)
OLDNEW
« no previous file with comments | « gm/imagefiltersgraph.cpp ('k') | gm/megalooper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698