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

Side by Side Diff: gm/gradients_no_texture.cpp

Issue 288343009: Remove unused (by clients) SkUnitMapper (https://codereview.chromium.org/283273002/) (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE is unneeded Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « gm/gradients_2pt_conical.cpp ('k') | gm/shaderbounds.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 #include "gm.h" 7 #include "gm.h"
8 #include "SkGradientShader.h" 8 #include "SkGradientShader.h"
9 9
10 using namespace skiagm; 10 using namespace skiagm;
11 11
12 struct GradData { 12 struct GradData {
13 int fCount; 13 int fCount;
14 const SkColor* fColors; 14 const SkColor* fColors;
15 const SkScalar* fPos; 15 const SkScalar* fPos;
16 }; 16 };
17 17
18 static const SkColor gColors[] = { 18 static const SkColor gColors[] = {
19 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, 19 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE,
20 }; 20 };
21 21
22 static const GradData gGradData[] = { 22 static const GradData gGradData[] = {
23 { 1, gColors, NULL }, 23 { 1, gColors, NULL },
24 { 2, gColors, NULL }, 24 { 2, gColors, NULL },
25 { 3, gColors, NULL }, 25 { 3, gColors, NULL },
26 { 4, gColors, NULL }, 26 { 4, gColors, NULL },
27 }; 27 };
28 28
29 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, 29 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader ::TileMode tm) {
30 SkShader::TileMode tm, SkUnitMapper* mapper) { 30 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCo unt, tm);
31 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
32 data.fCount, tm, mapper);
33 } 31 }
34 32
35 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, 33 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader ::TileMode tm) {
36 SkShader::TileMode tm, SkUnitMapper* mapper) {
37 SkPoint center; 34 SkPoint center;
38 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 35 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
39 SkScalarAve(pts[0].fY, pts[1].fY)); 36 SkScalarAve(pts[0].fY, pts[1].fY));
40 return SkGradientShader::CreateRadial(center, center.fX, data.fColors, 37 return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
41 data.fPos, data.fCount, tm, mapper); 38 data.fPos, data.fCount, tm);
42 } 39 }
43 40
44 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, 41 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader: :TileMode) {
45 SkShader::TileMode, SkUnitMapper* mapper) {
46 SkPoint center; 42 SkPoint center;
47 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 43 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
48 SkScalarAve(pts[0].fY, pts[1].fY)); 44 SkScalarAve(pts[0].fY, pts[1].fY));
49 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, 45 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, dat a.fPos, data.fCount);
50 data.fPos, data.fCount, mapper);
51 } 46 }
52 47
53 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, 48 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShade r::TileMode tm) {
54 SkShader::TileMode tm, SkUnitMapper* mapper) {
55 SkPoint center0, center1; 49 SkPoint center0, center1;
56 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 50 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
57 SkScalarAve(pts[0].fY, pts[1].fY)); 51 SkScalarAve(pts[0].fY, pts[1].fY));
58 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 52 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
59 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 53 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
60 return SkGradientShader::CreateTwoPointRadial( 54 return SkGradientShader::CreateTwoPointRadial(
61 center1, (pts[1].fX - pts[0].fX) / 7, 55 center1, (pts[1].fX - pts[0].fX) / 7,
62 center0, (pts[1].fX - pts[0].fX) / 2, 56 center0, (pts[1].fX - pts[0].fX) / 2,
63 data.fColors, data.fPos, data.fCount, tm, mapper); 57 data.fColors, data.fPos, data.fCount, tm);
64 } 58 }
65 59
66 static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, 60 static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, SkShad er::TileMode tm) {
67 SkShader::TileMode tm, SkUnitMapper* mapper) {
68 SkPoint center0, center1; 61 SkPoint center0, center1;
69 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); 62 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
70 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 63 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
71 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 64 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
72 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 65 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
73 return SkGradientShader::CreateTwoPointConical(center1, radius1, 66 return SkGradientShader::CreateTwoPointConical(center1, radius1,
74 center0, radius0, 67 center0, radius0,
75 data.fColors, data.fPos, 68 data.fColors, data.fPos,
76 data.fCount, tm, mapper); 69 data.fCount, tm);
77 } 70 }
78 71
79 72
80 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, 73 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha der::TileMode tm);
81 SkShader::TileMode tm, SkUnitMapper* mapper); 74
82 static const GradMaker gGradMakers[] = { 75 static const GradMaker gGradMakers[] = {
83 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical, 76 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical,
84 }; 77 };
85 78
86 /////////////////////////////////////////////////////////////////////////////// 79 ///////////////////////////////////////////////////////////////////////////////
87 80
88 class GradientsNoTextureGM : public GM { 81 class GradientsNoTextureGM : public GM {
89 public: 82 public:
90 GradientsNoTextureGM() { 83 GradientsNoTextureGM() {
91 this->setBGColor(0xFFDDDDDD); 84 this->setBGColor(0xFFDDDDDD);
(...skipping 14 matching lines...) Expand all
106 SkRect kRect = { 0, 0, SkIntToScalar(50), SkIntToScalar(50) }; 99 SkRect kRect = { 0, 0, SkIntToScalar(50), SkIntToScalar(50) };
107 SkPaint paint; 100 SkPaint paint;
108 paint.setAntiAlias(true); 101 paint.setAntiAlias(true);
109 102
110 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); 103 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
111 static const uint8_t kAlphas[] = { 0xff, 0x40 }; 104 static const uint8_t kAlphas[] = { 0xff, 0x40 };
112 for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphas); ++a) { 105 for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphas); ++a) {
113 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) { 106 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) {
114 canvas->save(); 107 canvas->save();
115 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) { 108 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) {
116 SkShader* shader = gGradMakers[j](kPts, gGradData[i], kTM, N ULL); 109 SkShader* shader = gGradMakers[j](kPts, gGradData[i], kTM);
117 paint.setShader(shader)->unref(); 110 paint.setShader(shader)->unref();
118 paint.setAlpha(kAlphas[a]); 111 paint.setAlpha(kAlphas[a]);
119 canvas->drawRect(kRect, paint); 112 canvas->drawRect(kRect, paint);
120 canvas->translate(0, SkIntToScalar(kRect.height() + 20)); 113 canvas->translate(0, SkIntToScalar(kRect.height() + 20));
121 } 114 }
122 canvas->restore(); 115 canvas->restore();
123 canvas->translate(SkIntToScalar(kRect.width() + 20), 0); 116 canvas->translate(SkIntToScalar(kRect.width() + 20), 0);
124 } 117 }
125 } 118 }
126 } 119 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 249 }
257 250
258 private: 251 private:
259 typedef GM INHERITED; 252 typedef GM INHERITED;
260 }; 253 };
261 254
262 /////////////////////////////////////////////////////////////////////////////// 255 ///////////////////////////////////////////////////////////////////////////////
263 256
264 DEF_GM( return SkNEW(GradientsNoTextureGM)); 257 DEF_GM( return SkNEW(GradientsNoTextureGM));
265 DEF_GM( return SkNEW(GradientsManyColorsGM)); 258 DEF_GM( return SkNEW(GradientsManyColorsGM));
OLDNEW
« no previous file with comments | « gm/gradients_2pt_conical.cpp ('k') | gm/shaderbounds.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698