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

Side by Side Diff: gm/lumafilter.cpp

Issue 1790353002: Revert of more shader-->sp conversions (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/lcdblendmodes.cpp ('k') | gm/matrixconvolution.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, SkColorFilter* filter, SkXfermode::Mode mode, 29 static void draw_scene(SkCanvas* canvas, SkColorFilter* filter,
30 const sk_sp<SkShader>& s1, const sk_sp<SkShader>& s2) { 30 SkXfermode::Mode mode, SkShader* s1,
31 SkShader* s2) {
31 SkPaint paint; 32 SkPaint paint;
32 paint.setAntiAlias(true); 33 paint.setAntiAlias(true);
33 SkRect r, c, bounds = SkRect::MakeWH(kSize, kSize); 34 SkRect r, c, bounds = SkRect::MakeWH(kSize, kSize);
34 35
35 c = bounds; 36 c = bounds;
36 c.fRight = bounds.centerX(); 37 c.fRight = bounds.centerX();
37 paint.setARGB(0x20, 0, 0, 0xff); 38 paint.setARGB(0x20, 0, 0, 0xff);
38 canvas->drawRect(bounds, paint); 39 canvas->drawRect(bounds, paint);
39 40
40 canvas->saveLayer(&bounds, nullptr); 41 canvas->saveLayer(&bounds, nullptr);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 class LumaFilterGM : public skiagm::GM { 78 class LumaFilterGM : public skiagm::GM {
78 public: 79 public:
79 LumaFilterGM() { 80 LumaFilterGM() {
80 SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) }; 81 SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) };
81 SkColor g2Colors[] = { kColor2, SkColorSetA(kColor2, 0x20) }; 82 SkColor g2Colors[] = { kColor2, SkColorSetA(kColor2, 0x20) };
82 SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } }; 83 SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } };
83 SkPoint g2Points[] = { { 0, 0 }, { kSize, 0 } }; 84 SkPoint g2Points[] = { { 0, 0 }, { kSize, 0 } };
84 SkScalar pos[] = { 0.2f, 1.0f }; 85 SkScalar pos[] = { 0.2f, 1.0f };
85 86
86 fFilter.reset(SkLumaColorFilter::Create()); 87 fFilter.reset(SkLumaColorFilter::Create());
87 fGr1 = SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_CO UNT(g1Colors), 88 fGr1.reset(SkGradientShader::CreateLinear(g1Points,
88 SkShader::kClamp_TileMode); 89 g1Colors,
89 fGr2 = SkGradientShader::MakeLinear(g2Points, g2Colors, pos, SK_ARRAY_CO UNT(g2Colors), 90 pos,
90 SkShader::kClamp_TileMode); 91 SK_ARRAY_COUNT(g1Colors),
92 SkShader::kClamp_TileMode));
93 fGr2.reset(SkGradientShader::CreateLinear(g2Points,
94 g2Colors,
95 pos,
96 SK_ARRAY_COUNT(g2Colors),
97 SkShader::kClamp_TileMode));
91 } 98 }
92 99
93 protected: 100 protected:
94 101
95 SkString onShortName() override { 102 SkString onShortName() override {
96 return SkString("lumafilter"); 103 return SkString("lumafilter");
97 } 104 }
98 105
99 SkISize onISize() override { 106 SkISize onISize() override {
100 return SkISize::Make(600, 420); 107 return SkISize::Make(600, 420);
101 } 108 }
102 109
103 void onDraw(SkCanvas* canvas) override { 110 void onDraw(SkCanvas* canvas) override {
104 SkXfermode::Mode modes[] = { SkXfermode::kSrcOver_Mode, 111 SkXfermode::Mode modes[] = { SkXfermode::kSrcOver_Mode,
105 SkXfermode::kDstOver_Mode, 112 SkXfermode::kDstOver_Mode,
106 SkXfermode::kSrcATop_Mode, 113 SkXfermode::kSrcATop_Mode,
107 SkXfermode::kDstATop_Mode, 114 SkXfermode::kDstATop_Mode,
108 SkXfermode::kSrcIn_Mode, 115 SkXfermode::kSrcIn_Mode,
109 SkXfermode::kDstIn_Mode, 116 SkXfermode::kDstIn_Mode,
110 }; 117 };
111 struct { 118 struct {
112 const sk_sp<SkShader>& fShader1; 119 SkShader* fShader1;
113 const sk_sp<SkShader>& fShader2; 120 SkShader* fShader2;
114 } shaders[] = { 121 } shaders[] = {
115 { nullptr, nullptr }, 122 { nullptr, nullptr },
116 { nullptr, fGr2 }, 123 { nullptr, fGr2 },
117 { fGr1, nullptr }, 124 { fGr1, nullptr },
118 { fGr1, fGr2 }, 125 { fGr1, fGr2 },
119 }; 126 };
120 127
121 SkScalar gridStep = kSize + 2 * kInset; 128 SkScalar gridStep = kSize + 2 * kInset;
122 for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) { 129 for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) {
123 draw_label(canvas, SkXfermode::ModeName(modes[i]), 130 draw_label(canvas, SkXfermode::ModeName(modes[i]),
124 SkPoint::Make(gridStep * (0.5f + i), 20)); 131 SkPoint::Make(gridStep * (0.5f + i), 20));
125 } 132 }
126 133
127 for (size_t i = 0; i < SK_ARRAY_COUNT(shaders); ++i) { 134 for (size_t i = 0; i < SK_ARRAY_COUNT(shaders); ++i) {
128 canvas->save(); 135 canvas->save();
129 canvas->translate(kInset, gridStep * i + 30); 136 canvas->translate(kInset, gridStep * i + 30);
130 for (size_t m = 0; m < SK_ARRAY_COUNT(modes); ++m) { 137 for (size_t m = 0; m < SK_ARRAY_COUNT(modes); ++m) {
131 draw_scene(canvas, fFilter, modes[m], shaders[i].fShader1, 138 draw_scene(canvas, fFilter, modes[m], shaders[i].fShader1,
132 shaders[i].fShader2); 139 shaders[i].fShader2);
133 canvas->translate(gridStep, 0); 140 canvas->translate(gridStep, 0);
134 } 141 }
135 canvas->restore(); 142 canvas->restore();
136 } 143 }
137 } 144 }
138 145
139 private: 146 private:
140 SkAutoTUnref<SkColorFilter> fFilter; 147 SkAutoTUnref<SkColorFilter> fFilter;
141 sk_sp<SkShader> fGr1, fGr2; 148 SkAutoTUnref<SkShader> fGr1, fGr2;
142 149
143 typedef skiagm::GM INHERITED; 150 typedef skiagm::GM INHERITED;
144 }; 151 };
145 152
146 ////////////////////////////////////////////////////////////////////////////// 153 //////////////////////////////////////////////////////////////////////////////
147 154
148 DEF_GM(return new LumaFilterGM;) 155 DEF_GM(return new LumaFilterGM;)
OLDNEW
« no previous file with comments | « gm/lcdblendmodes.cpp ('k') | gm/matrixconvolution.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698