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

Side by Side Diff: gm/vertices.cpp

Issue 1825073002: 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: remove flag 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/tileimagefilter.cpp ('k') | gyp/skia_for_android_framework_defines.gypi » ('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 "SkColorFilter.h" 10 #include "SkColorFilter.h"
11 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
12 #include "SkRandom.h" 12 #include "SkRandom.h"
13 13
14 static sk_sp<SkShader> make_shader1(SkScalar w, SkScalar h) { 14 static sk_sp<SkShader> make_shader1(SkScalar w, SkScalar h) {
15 const SkColor colors[] = { 15 const SkColor colors[] = {
16 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, 16 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
17 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW, 17 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW,
18 }; 18 };
19 const SkPoint pts[] = { { w/4, 0 }, { 3*w/4, h } }; 19 const SkPoint pts[] = { { w/4, 0 }, { 3*w/4, h } };
20 20
21 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col ors), 21 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col ors),
22 SkShader::kMirror_TileMode); 22 SkShader::kMirror_TileMode);
23 } 23 }
24 24
25 static sk_sp<SkShader> make_shader2() { 25 static sk_sp<SkShader> make_shader2() {
26 return SkShader::MakeColorShader(SK_ColorBLUE); 26 return SkShader::MakeColorShader(SK_ColorBLUE);
27 } 27 }
28 28
29 static SkColorFilter* make_color_filter() { 29 static sk_sp<SkColorFilter> make_color_filter() {
30 return SkColorFilter::CreateModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode) ; 30 return SkColorFilter::MakeModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode);
31 } 31 }
32 32
33 class VerticesGM : public skiagm::GM { 33 class VerticesGM : public skiagm::GM {
34 SkPoint fPts[9]; 34 SkPoint fPts[9];
35 SkPoint fTexs[9]; 35 SkPoint fTexs[9];
36 SkColor fColors[9]; 36 SkColor fColors[9];
37 sk_sp<SkShader> fShader1; 37 sk_sp<SkShader> fShader1;
38 sk_sp<SkShader> fShader2; 38 sk_sp<SkShader> fShader2;
39 SkAutoTUnref<SkColorFilter> fColorFilter; 39 sk_sp<SkColorFilter> fColorFilter;
40 40
41 public: 41 public:
42 VerticesGM() {} 42 VerticesGM() {}
43 43
44 protected: 44 protected:
45 45
46 void onOnceBeforeDraw() override { 46 void onOnceBeforeDraw() override {
47 const SkScalar X = 30; 47 const SkScalar X = 30;
48 const SkScalar Y = 30; 48 const SkScalar Y = 30;
49 49
50 fPts[0].set(0, 0); fPts[1].set(X/2, 3); fPts[2].set(X, 0); 50 fPts[0].set(0, 0); fPts[1].set(X/2, 3); fPts[2].set(X, 0);
51 fPts[3].set(3, Y/2); fPts[4].set(X/2, Y/2); fPts[5].set(X-3, Y/2); 51 fPts[3].set(3, Y/2); fPts[4].set(X/2, Y/2); fPts[5].set(X-3, Y/2);
52 fPts[6].set(0, Y); fPts[7].set(X/2, Y-3); fPts[8].set(X, Y); 52 fPts[6].set(0, Y); fPts[7].set(X/2, Y-3); fPts[8].set(X, Y);
53 53
54 const SkScalar w = 40; 54 const SkScalar w = 40;
55 const SkScalar h = 40; 55 const SkScalar h = 40;
56 56
57 fTexs[0].set(0, 0); fTexs[1].set(w/2, 0); fTexs[2].set(w, 0); 57 fTexs[0].set(0, 0); fTexs[1].set(w/2, 0); fTexs[2].set(w, 0);
58 fTexs[3].set(0, h/2); fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2); 58 fTexs[3].set(0, h/2); fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2);
59 fTexs[6].set(0, h); fTexs[7].set(w/2, h); fTexs[8].set(w, h); 59 fTexs[6].set(0, h); fTexs[7].set(w/2, h); fTexs[8].set(w, h);
60 60
61 fShader1 = make_shader1(w, h); 61 fShader1 = make_shader1(w, h);
62 fShader2 = make_shader2(); 62 fShader2 = make_shader2();
63 fColorFilter.reset(make_color_filter()); 63 fColorFilter = make_color_filter();
64 64
65 SkRandom rand; 65 SkRandom rand;
66 for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) { 66 for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) {
67 fColors[i] = rand.nextU() | 0xFF000000; 67 fColors[i] = rand.nextU() | 0xFF000000;
68 } 68 }
69 } 69 }
70 70
71 SkString onShortName() override { 71 SkString onShortName() override {
72 SkString name("vertices"); 72 SkString name("vertices");
73 return name; 73 return name;
74 } 74 }
75 75
76 SkISize onISize() override { 76 SkISize onISize() override {
77 return SkISize::Make(600, 600); 77 return SkISize::Make(600, 600);
78 } 78 }
79 79
80 void onDraw(SkCanvas* canvas) override { 80 void onDraw(SkCanvas* canvas) override {
81 // start with the center of a 3x3 grid 81 // start with the center of a 3x3 grid
82 static const uint16_t fan[] = { 82 static const uint16_t fan[] = {
83 4, 83 4,
84 0, 1, 2, 5, 8, 7, 6, 3, 0 84 0, 1, 2, 5, 8, 7, 6, 3, 0
85 }; 85 };
86 86
87 const struct { 87 const struct {
88 const SkColor* fColors; 88 const SkColor* fColors;
89 const SkPoint* fTexs; 89 const SkPoint* fTexs;
90 const sk_sp<SkShader>& fShader; 90 const sk_sp<SkShader>& fShader;
91 SkColorFilter* fColorFilter; 91 const sk_sp<SkColorFilter>& fColorFilter;
92 uint8_t fAlpha; 92 uint8_t fAlpha;
93 } rec[] = { 93 } rec[] = {
94 { fColors, nullptr, fShader1, nullptr , 0xFF }, 94 { fColors, nullptr, fShader1, nullptr , 0xFF },
95 { nullptr, fTexs , fShader1, nullptr , 0xFF }, 95 { nullptr, fTexs , fShader1, nullptr , 0xFF },
96 { fColors, fTexs , fShader1, nullptr , 0xFF }, 96 { fColors, fTexs , fShader1, nullptr , 0xFF },
97 { fColors, nullptr, fShader2, nullptr , 0xFF }, 97 { fColors, nullptr, fShader2, nullptr , 0xFF },
98 { nullptr, fTexs , fShader2, nullptr , 0xFF }, 98 { nullptr, fTexs , fShader2, nullptr , 0xFF },
99 { fColors, fTexs , fShader2, nullptr , 0xFF }, 99 { fColors, fTexs , fShader2, nullptr , 0xFF },
100 { fColors, nullptr, fShader1, fColorFilter, 0xFF }, 100 { fColors, nullptr, fShader1, fColorFilter, 0xFF },
101 { nullptr, fTexs , fShader1, fColorFilter, 0xFF }, 101 { nullptr, fTexs , fShader1, fColorFilter, 0xFF },
102 { fColors, fTexs , fShader1, fColorFilter, 0xFF }, 102 { fColors, fTexs , fShader1, fColorFilter, 0xFF },
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 174 }
175 } 175 }
176 176
177 private: 177 private:
178 typedef skiagm::GM INHERITED; 178 typedef skiagm::GM INHERITED;
179 }; 179 };
180 180
181 //////////////////////////////////////////////////////////////////////////////// ///// 181 //////////////////////////////////////////////////////////////////////////////// /////
182 182
183 DEF_GM(return new VerticesGM();) 183 DEF_GM(return new VerticesGM();)
OLDNEW
« no previous file with comments | « gm/tileimagefilter.cpp ('k') | gyp/skia_for_android_framework_defines.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698