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

Side by Side Diff: samplecode/SampleGradients.cpp

Issue 296823008: Revert of Remove unused (by clients) SkUnitMapper (https://codereview.chromium.org/283273002/) (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 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 | « samplecode/SampleAll.cpp ('k') | samplecode/SampleLayers.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
12 12
13 static SkShader* setgrad(const SkRect& r, SkColor c0, SkColor c1) { 13 static SkShader* setgrad(const SkRect& r, SkColor c0, SkColor c1) {
14 SkColor colors[] = { c0, c1 }; 14 SkColor colors[] = { c0, c1 };
15 SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fTop } }; 15 SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fTop } };
16 return SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp _TileMode); 16 return SkGradientShader::CreateLinear(pts, colors, NULL, 2,
17 SkShader::kClamp_TileMode, NULL);
17 } 18 }
18 19
19 static void test_alphagradients(SkCanvas* canvas) { 20 static void test_alphagradients(SkCanvas* canvas) {
20 SkRect r; 21 SkRect r;
21 r.set(SkIntToScalar(10), SkIntToScalar(10), 22 r.set(SkIntToScalar(10), SkIntToScalar(10),
22 SkIntToScalar(410), SkIntToScalar(30)); 23 SkIntToScalar(410), SkIntToScalar(30));
23 SkPaint p, p2; 24 SkPaint p, p2;
24 p2.setStyle(SkPaint::kStroke_Style); 25 p2.setStyle(SkPaint::kStroke_Style);
25 26
26 p.setShader(setgrad(r, 0xFF00FF00, 0x0000FF00))->unref(); 27 p.setShader(setgrad(r, 0xFF00FF00, 0x0000FF00))->unref();
(...skipping 29 matching lines...) Expand all
56 }; 57 };
57 58
58 static const GradData gGradData[] = { 59 static const GradData gGradData[] = {
59 { 2, gColors, NULL }, 60 { 2, gColors, NULL },
60 { 2, gColors, gPos0 }, 61 { 2, gColors, gPos0 },
61 { 2, gColors, gPos1 }, 62 { 2, gColors, gPos1 },
62 { 5, gColors, NULL }, 63 { 5, gColors, NULL },
63 { 5, gColors, gPos2 } 64 { 5, gColors, gPos2 }
64 }; 65 };
65 66
66 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader ::TileMode tm) { 67 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
67 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCo unt, tm); 68 SkShader::TileMode tm, SkUnitMapper* mapper) {
69 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
70 data.fCount, tm, mapper);
68 } 71 }
69 72
70 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader ::TileMode tm) { 73 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
74 SkShader::TileMode tm, SkUnitMapper* mapper) {
71 SkPoint center; 75 SkPoint center;
72 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 76 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
73 SkScalarAve(pts[0].fY, pts[1].fY)); 77 SkScalarAve(pts[0].fY, pts[1].fY));
74 return SkGradientShader::CreateRadial(center, center.fX, data.fColors, 78 return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
75 data.fPos, data.fCount, tm); 79 data.fPos, data.fCount, tm, mapper);
76 } 80 }
77 81
78 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader: :TileMode tm) { 82 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
83 SkShader::TileMode tm, SkUnitMapper* mapper) {
79 SkPoint center; 84 SkPoint center;
80 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 85 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
81 SkScalarAve(pts[0].fY, pts[1].fY)); 86 SkScalarAve(pts[0].fY, pts[1].fY));
82 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, dat a.fPos, data.fCount); 87 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
88 data.fPos, data.fCount, mapper);
83 } 89 }
84 90
85 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShade r::TileMode tm) { 91 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
92 SkShader::TileMode tm, SkUnitMapper* mapper) {
86 SkPoint center0, center1; 93 SkPoint center0, center1;
87 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 94 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
88 SkScalarAve(pts[0].fY, pts[1].fY)); 95 SkScalarAve(pts[0].fY, pts[1].fY));
89 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 96 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
90 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 97 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
91 return SkGradientShader::CreateTwoPointRadial( 98 return SkGradientShader::CreateTwoPointRadial(
92 center1, (pts[1].fX - pts[0].fX) / 7, 99 center1, (pts[1].fX - pts[0].fX) / 7,
93 center0, (pts[1].fX - pts[0].fX) / 2, 100 center0, (pts[1].fX - pts[0].fX) / 2,
94 data.fColors, data.fPos, data.fCount, tm); 101 data.fColors, data.fPos, data.fCount, tm, mapper);
95 } 102 }
96 103
97 static SkShader* Make2RadialConcentric(const SkPoint pts[2], const GradData& dat a, 104 static SkShader* Make2RadialConcentric(const SkPoint pts[2], const GradData& dat a,
98 SkShader::TileMode tm) { 105 SkShader::TileMode tm, SkUnitMapper* mapp er) {
99 SkPoint center; 106 SkPoint center;
100 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 107 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
101 SkScalarAve(pts[0].fY, pts[1].fY)); 108 SkScalarAve(pts[0].fY, pts[1].fY));
102 return SkGradientShader::CreateTwoPointRadial( 109 return SkGradientShader::CreateTwoPointRadial(
103 center, (pts[1].fX - pts[0].fX) / 7, 110 center, (pts[1].fX - pts[0].fX) / 7,
104 center, (pts[1].fX - pts[0].fX) / 2, 111 center, (pts[1].fX - pts[0].fX) / 2,
105 data.fColors, data.fPos, data.fCount, tm); 112 data.fColors, data.fPos, data.fCount, tm, mapper);
106 } 113 }
107 114
108 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha der::TileMode tm); 115 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
109 116 SkShader::TileMode tm, SkUnitMapper* mapper);
110 static const GradMaker gGradMakers[] = { 117 static const GradMaker gGradMakers[] = {
111 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2RadialConcentric 118 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2RadialConcentric
112 }; 119 };
113 120
114 /////////////////////////////////////////////////////////////////////////////// 121 ///////////////////////////////////////////////////////////////////////////////
115 122
116 class GradientsView : public SampleView { 123 class GradientsView : public SampleView {
117 public: 124 public:
118 GradientsView() { 125 GradientsView() {
119 this->setBGColor(0xFFDDDDDD); 126 this->setBGColor(0xFFDDDDDD);
(...skipping 20 matching lines...) Expand all
140 147
141 canvas->save(); 148 canvas->save();
142 canvas->translate(SkIntToScalar(20), SkIntToScalar(10)); 149 canvas->translate(SkIntToScalar(20), SkIntToScalar(10));
143 150
144 for (int tm = 0; tm < SkShader::kTileModeCount; ++tm) { 151 for (int tm = 0; tm < SkShader::kTileModeCount; ++tm) {
145 canvas->save(); 152 canvas->save();
146 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { 153 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
147 canvas->save(); 154 canvas->save();
148 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { 155 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
149 SkShader* shader; 156 SkShader* shader;
150 shader = gGradMakers[j](pts, gGradData[i], (SkShader::TileMo de)tm); 157 shader = gGradMakers[j](pts, gGradData[i], (SkShader::TileMo de)tm, NULL);
151 paint.setShader(shader)->unref(); 158 paint.setShader(shader)->unref();
152 canvas->drawRect(r, paint); 159 canvas->drawRect(r, paint);
153 canvas->translate(0, SkIntToScalar(120)); 160 canvas->translate(0, SkIntToScalar(120));
154 } 161 }
155 canvas->restore(); 162 canvas->restore();
156 canvas->translate(SkIntToScalar(120), 0); 163 canvas->translate(SkIntToScalar(120), 0);
157 } 164 }
158 canvas->restore(); 165 canvas->restore();
159 canvas->translate(SK_ARRAY_COUNT(gGradData)*SkIntToScalar(120), 0); 166 canvas->translate(SK_ARRAY_COUNT(gGradData)*SkIntToScalar(120), 0);
160 } 167 }
161 canvas->restore(); 168 canvas->restore();
162 169
163 canvas->translate(0, SkIntToScalar(370)); 170 canvas->translate(0, SkIntToScalar(370));
164 if (false) { // avoid bit rot, suppress warning 171 if (false) { // avoid bit rot, suppress warning
165 test_alphagradients(canvas); 172 test_alphagradients(canvas);
166 } 173 }
167 this->inval(NULL); 174 this->inval(NULL);
168 } 175 }
169 176
170 private: 177 private:
171 typedef SampleView INHERITED; 178 typedef SampleView INHERITED;
172 }; 179 };
173 180
174 /////////////////////////////////////////////////////////////////////////////// 181 ///////////////////////////////////////////////////////////////////////////////
175 182
176 static SkView* MyFactory() { return new GradientsView; } 183 static SkView* MyFactory() { return new GradientsView; }
177 static SkViewRegister reg(MyFactory); 184 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleAll.cpp ('k') | samplecode/SampleLayers.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698