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

Side by Side Diff: samplecode/SampleShaders.cpp

Issue 1832223002: switch xfermodes over to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "DecodeFile.h" 8 #include "DecodeFile.h"
9 #include "SampleCode.h" 9 #include "SampleCode.h"
10 #include "SkView.h" 10 #include "SkView.h"
(...skipping 14 matching lines...) Expand all
25 SkPoint pts[2]; 25 SkPoint pts[2];
26 SkColor colors[2]; 26 SkColor colors[2];
27 27
28 pts[0].set(0, 0); 28 pts[0].set(0, 0);
29 pts[1].set(0, SkIntToScalar(bm.height())); 29 pts[1].set(0, SkIntToScalar(bm.height()));
30 colors[0] = SK_ColorBLACK; 30 colors[0] = SK_ColorBLACK;
31 colors[1] = SkColorSetARGB(0, 0, 0, 0); 31 colors[1] = SkColorSetARGB(0, 0, 0, 0);
32 auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShade r::kClamp_TileMode); 32 auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShade r::kClamp_TileMode);
33 33
34 auto shaderB = SkShader::MakeBitmapShader(bm, 34 auto shaderB = SkShader::MakeBitmapShader(bm,
35 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); 35 SkShader::kClamp_TileMode, SkShade r::kClamp_TileMode);
36 36
37 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kDstIn_Mode)); 37 return SkShader::MakeComposeShader(std::move(shaderB), std::move(shaderA),
38 38 SkXfermode::Make(SkXfermode::kDstIn_Mode) );
39 return SkShader::MakeComposeShader(std::move(shaderB), std::move(shaderA), m ode);
40 } 39 }
41 40
42 class ShaderView : public SampleView { 41 class ShaderView : public SampleView {
43 public: 42 public:
44 sk_sp<SkShader> fShader; 43 sk_sp<SkShader> fShader;
45 SkBitmap fBitmap; 44 SkBitmap fBitmap;
46 45
47 ShaderView() { 46 ShaderView() {
48 decode_file("/skimages/logo.gif", &fBitmap); 47 decode_file("/skimages/logo.gif", &fBitmap);
49 48
50 SkPoint pts[2]; 49 SkPoint pts[2];
51 SkColor colors[2]; 50 SkColor colors[2];
52 51
53 pts[0].set(0, 0); 52 pts[0].set(0, 0);
54 pts[1].set(SkIntToScalar(100), 0); 53 pts[1].set(SkIntToScalar(100), 0);
55 colors[0] = SK_ColorRED; 54 colors[0] = SK_ColorRED;
56 colors[1] = SK_ColorBLUE; 55 colors[1] = SK_ColorBLUE;
57 auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkS hader::kClamp_TileMode); 56 auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkS hader::kClamp_TileMode);
58 57
59 pts[0].set(0, 0); 58 pts[0].set(0, 0);
60 pts[1].set(0, SkIntToScalar(100)); 59 pts[1].set(0, SkIntToScalar(100));
61 colors[0] = SK_ColorBLACK; 60 colors[0] = SK_ColorBLACK;
62 colors[1] = SkColorSetARGB(0x80, 0, 0, 0); 61 colors[1] = SkColorSetARGB(0x80, 0, 0, 0);
63 auto shaderB = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkS hader::kClamp_TileMode); 62 auto shaderB = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkS hader::kClamp_TileMode);
64 63
65 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kDstIn_Mode )); 64 fShader = SkShader::MakeComposeShader(std::move(shaderA), std::move(shad erB),
66 65 SkXfermode::Make(SkXfermode::kDstI n_Mode));
67 fShader = SkShader::MakeComposeShader(std::move(shaderA), std::move(shad erB), mode);
68 } 66 }
69 67
70 protected: 68 protected:
71 // overrides from SkEventSink 69 // overrides from SkEventSink
72 bool onQuery(SkEvent* evt) override { 70 bool onQuery(SkEvent* evt) override {
73 if (SampleCode::TitleQ(*evt)) { 71 if (SampleCode::TitleQ(*evt)) {
74 SampleCode::TitleR(evt, "Shaders"); 72 SampleCode::TitleR(evt, "Shaders");
75 return true; 73 return true;
76 } 74 }
77 return this->INHERITED::onQuery(evt); 75 return this->INHERITED::onQuery(evt);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 112 }
115 113
116 private: 114 private:
117 typedef SampleView INHERITED; 115 typedef SampleView INHERITED;
118 }; 116 };
119 117
120 ////////////////////////////////////////////////////////////////////////////// 118 //////////////////////////////////////////////////////////////////////////////
121 119
122 static SkView* MyFactory() { return new ShaderView; } 120 static SkView* MyFactory() { return new ShaderView; }
123 static SkViewRegister reg(MyFactory); 121 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698