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

Side by Side Diff: samplecode/SampleSlides.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/SampleShaderText.cpp ('k') | samplecode/SampleTiling.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 "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 }; 171 };
172 172
173 static const GradData gGradData[] = { 173 static const GradData gGradData[] = {
174 { 2, gColors, NULL }, 174 { 2, gColors, NULL },
175 { 2, gColors, gPos0 }, 175 { 2, gColors, gPos0 },
176 { 2, gColors, gPos1 }, 176 { 2, gColors, gPos1 },
177 { 5, gColors, NULL }, 177 { 5, gColors, NULL },
178 { 5, gColors, gPos2 } 178 { 5, gColors, gPos2 }
179 }; 179 };
180 180
181 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader ::TileMode tm) { 181 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
182 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCo unt, tm); 182 SkShader::TileMode tm, SkUnitMapper* mapper) {
183 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
184 data.fCount, tm, mapper);
183 } 185 }
184 186
185 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader ::TileMode tm) { 187 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
188 SkShader::TileMode tm, SkUnitMapper* mapper) {
186 SkPoint center; 189 SkPoint center;
187 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 190 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
188 SkScalarAve(pts[0].fY, pts[1].fY)); 191 SkScalarAve(pts[0].fY, pts[1].fY));
189 return SkGradientShader::CreateRadial(center, center.fX, data.fColors, 192 return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
190 data.fPos, data.fCount, tm); 193 data.fPos, data.fCount, tm, mapper);
191 } 194 }
192 195
193 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader: :TileMode tm) { 196 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
197 SkShader::TileMode tm, SkUnitMapper* mapper) {
194 SkPoint center; 198 SkPoint center;
195 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 199 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
196 SkScalarAve(pts[0].fY, pts[1].fY)); 200 SkScalarAve(pts[0].fY, pts[1].fY));
197 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, dat a.fPos, data.fCount); 201 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
202 data.fPos, data.fCount, mapper);
198 } 203 }
199 204
200 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShade r::TileMode tm) { 205 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
206 SkShader::TileMode tm, SkUnitMapper* mapper) {
201 SkPoint center0, center1; 207 SkPoint center0, center1;
202 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 208 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
203 SkScalarAve(pts[0].fY, pts[1].fY)); 209 SkScalarAve(pts[0].fY, pts[1].fY));
204 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 210 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
205 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 211 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
206 return SkGradientShader::CreateTwoPointRadial( 212 return SkGradientShader::CreateTwoPointRadial(
207 center1, (pts[1].fX - pts[0].f X) / 7, 213 center1, (pts[1].fX - pts[0].f X) / 7,
208 center0, (pts[1].fX - pts[0].f X) / 2, 214 center0, (pts[1].fX - pts[0].f X) / 2,
209 data.fColors, data.fPos, data. fCount, tm); 215 data.fColors, data.fPos, data. fCount, tm, mapper);
210 } 216 }
211 217
212 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha der::TileMode tm); 218 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
219 SkShader::TileMode tm, SkUnitMapper* mapper);
213 static const GradMaker gGradMakers[] = { 220 static const GradMaker gGradMakers[] = {
214 MakeLinear, MakeRadial, MakeSweep, Make2Radial 221 MakeLinear, MakeRadial, MakeSweep, Make2Radial
215 }; 222 };
216 223
217 static void gradient_slide(SkCanvas* canvas) { 224 static void gradient_slide(SkCanvas* canvas) {
218 SkPoint pts[2] = { 225 SkPoint pts[2] = {
219 { 0, 0 }, 226 { 0, 0 },
220 { SkIntToScalar(100), SkIntToScalar(100) } 227 { SkIntToScalar(100), SkIntToScalar(100) }
221 }; 228 };
222 SkShader::TileMode tm = SkShader::kClamp_TileMode; 229 SkShader::TileMode tm = SkShader::kClamp_TileMode;
223 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) }; 230 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
224 SkPaint paint; 231 SkPaint paint;
225 paint.setAntiAlias(true); 232 paint.setAntiAlias(true);
226 paint.setDither(true); 233 paint.setDither(true);
227 234
228 canvas->translate(SkIntToScalar(20), SkIntToScalar(10)); 235 canvas->translate(SkIntToScalar(20), SkIntToScalar(10));
229 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { 236 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
230 canvas->save(); 237 canvas->save();
231 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { 238 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
232 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm); 239 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL);
233 paint.setShader(shader); 240 paint.setShader(shader);
234 canvas->drawRect(r, paint); 241 canvas->drawRect(r, paint);
235 shader->unref(); 242 shader->unref();
236 canvas->translate(0, SkIntToScalar(120)); 243 canvas->translate(0, SkIntToScalar(120));
237 } 244 }
238 canvas->restore(); 245 canvas->restore();
239 canvas->translate(SkIntToScalar(120), 0); 246 canvas->translate(SkIntToScalar(120), 0);
240 } 247 }
241 } 248 }
242 249
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 size->set(bm.width(), bm.height()); 328 size->set(bm.width(), bm.height());
322 return SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, 329 return SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode,
323 SkShader::kClamp_TileMode); 330 SkShader::kClamp_TileMode);
324 } 331 }
325 332
326 static SkShader* make_shader1(const SkIPoint& size) { 333 static SkShader* make_shader1(const SkIPoint& size) {
327 SkPoint pts[] = { { 0, 0 }, 334 SkPoint pts[] = { { 0, 0 },
328 { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } }; 335 { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } };
329 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED } ; 336 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED } ;
330 return SkGradientShader::CreateLinear(pts, colors, NULL, 337 return SkGradientShader::CreateLinear(pts, colors, NULL,
331 SK_ARRAY_COUNT(colors), SkShader::kMir ror_TileMode); 338 SK_ARRAY_COUNT(colors), SkShader::kMir ror_TileMode, NULL);
332 } 339 }
333 340
334 class Rec { 341 class Rec {
335 public: 342 public:
336 SkCanvas::VertexMode fMode; 343 SkCanvas::VertexMode fMode;
337 int fCount; 344 int fCount;
338 SkPoint* fVerts; 345 SkPoint* fVerts;
339 SkPoint* fTexs; 346 SkPoint* fTexs;
340 347
341 Rec() : fCount(0), fVerts(NULL), fTexs(NULL) {} 348 Rec() : fCount(0), fVerts(NULL), fTexs(NULL) {}
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 } 725 }
719 726
720 private: 727 private:
721 typedef SampleView INHERITED; 728 typedef SampleView INHERITED;
722 }; 729 };
723 730
724 ////////////////////////////////////////////////////////////////////////////// 731 //////////////////////////////////////////////////////////////////////////////
725 732
726 static SkView* MyFactory() { return new SlideView; } 733 static SkView* MyFactory() { return new SlideView; }
727 static SkViewRegister reg(MyFactory); 734 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleShaderText.cpp ('k') | samplecode/SampleTiling.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698