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

Side by Side Diff: samplecode/SampleAll.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 #include "SampleCode.h" 7 #include "SampleCode.h"
8 #include "SkBlurMask.h" 8 #include "SkBlurMask.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkView.h" 10 #include "SkView.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 375
376 SkEmbossMaskFilter::Light light; 376 SkEmbossMaskFilter::Light light;
377 light.fDirection[0] = SK_Scalar1/2; 377 light.fDirection[0] = SK_Scalar1/2;
378 light.fDirection[1] = SK_Scalar1/2; 378 light.fDirection[1] = SK_Scalar1/2;
379 light.fDirection[2] = SK_Scalar1/3; 379 light.fDirection[2] = SK_Scalar1/3;
380 light.fAmbient = 0x48; 380 light.fAmbient = 0x48;
381 light.fSpecular = 0x80; 381 light.fSpecular = 0x80;
382 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(12)/5); 382 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(12)/5);
383 SkMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, light); 383 SkMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, light);
384 384
385 SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode);
386 auto lightingFilter = SkColorMatrixFilter::MakeLightingFilter( 385 auto lightingFilter = SkColorMatrixFilter::MakeLightingFilter(
387 0xff89bc45, 0xff112233); 386 0xff89bc45, 0xff112233);
388 387
389 canvas->save(); 388 canvas->save();
390 canvas->translate(SkIntToScalar(0), SkIntToScalar(5)); 389 canvas->translate(SkIntToScalar(0), SkIntToScalar(5));
391 paint.setAntiAlias(true); 390 paint.setAntiAlias(true);
392 paint.setFilterQuality(kLow_SkFilterQuality); 391 paint.setFilterQuality(kLow_SkFilterQuality);
393 // !!! draw through a clip 392 // !!! draw through a clip
394 paint.setColor(SK_ColorLTGRAY); 393 paint.setColor(SK_ColorLTGRAY);
395 paint.setStyle(SkPaint::kFill_Style); 394 paint.setStyle(SkPaint::kFill_Style);
396 SkRect clip = {0, 0, SkIntToScalar(320), SkIntToScalar(120)}; 395 SkRect clip = {0, 0, SkIntToScalar(320), SkIntToScalar(120)};
397 canvas->clipRect(clip); 396 canvas->clipRect(clip);
398 paint.setShader(SkShader::MakeBitmapShader(fTx, 397 paint.setShader(SkShader::MakeBitmapShader(fTx,
399 SkShader::kMirror_TileMode, SkShader::kRepeat_TileMode)); 398 SkShader::kMirror_TileMode, SkShader::kRepeat_TileMode));
400 canvas->drawPaint(paint); 399 canvas->drawPaint(paint);
401 canvas->save(); 400 canvas->save();
402 401
403 // line (exercises xfermode, colorShader, colorFilter, filterShader) 402 // line (exercises xfermode, colorShader, colorFilter, filterShader)
404 paint.setColor(SK_ColorGREEN); 403 paint.setColor(SK_ColorGREEN);
405 paint.setStrokeWidth(SkIntToScalar(10)); 404 paint.setStrokeWidth(SkIntToScalar(10));
406 paint.setStyle(SkPaint::kStroke_Style); 405 paint.setStyle(SkPaint::kStroke_Style);
407 paint.setXfermode(xfermode)->unref(); 406 paint.setXfermode(SkXfermode::Make(SkXfermode::kXor_Mode));
408 paint.setColorFilter(lightingFilter); 407 paint.setColorFilter(lightingFilter);
409 canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); // should not be green 408 canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); // should not be green
410 paint.setXfermode(nullptr); 409 paint.setXfermode(nullptr);
411 paint.setColorFilter(nullptr); 410 paint.setColorFilter(nullptr);
412 411
413 // rectangle 412 // rectangle
414 paint.setStyle(SkPaint::kFill_Style); 413 paint.setStyle(SkPaint::kFill_Style);
415 canvas->translate(SkIntToScalar(50), 0); 414 canvas->translate(SkIntToScalar(50), 0);
416 paint.setColor(SK_ColorYELLOW); 415 paint.setColor(SK_ColorYELLOW);
417 paint.setShader(linear); 416 paint.setShader(linear);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 497
499 sk_sp<SkShader> shaderTest() { 498 sk_sp<SkShader> shaderTest() {
500 SkPoint pts[] = { { 0, 0, }, { SkIntToScalar(100), 0 } }; 499 SkPoint pts[] = { { 0, 0, }, { SkIntToScalar(100), 0 } };
501 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; 500 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
502 auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 501 auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr,
503 2, SkShader::kClamp_TileMode); 502 2, SkShader::kClamp_TileMode);
504 pts[1].set(0, SkIntToScalar(100)); 503 pts[1].set(0, SkIntToScalar(100));
505 SkColor colors2[] = {SK_ColorBLACK, SkColorSetARGB(0x80, 0, 0, 0)}; 504 SkColor colors2[] = {SK_ColorBLACK, SkColorSetARGB(0x80, 0, 0, 0)};
506 auto shaderB = SkGradientShader::MakeLinear(pts, colors2, nullptr, 505 auto shaderB = SkGradientShader::MakeLinear(pts, colors2, nullptr,
507 2, SkShader::kClamp_TileMode); 506 2, SkShader::kClamp_TileMode);
508 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kDstIn_Mode )); 507 return SkShader::MakeComposeShader(std::move(shaderA), std::move(shaderB ),
509 return SkShader::MakeComposeShader(shaderA, shaderB, mode); 508 SkXfermode::Make(SkXfermode::kDstIn_M ode));
510 } 509 }
511 510
512 virtual void startTest() { 511 virtual void startTest() {
513 decode_file("/Users/caryclark/Desktop/bugcirc.gif", &fBug); 512 decode_file("/Users/caryclark/Desktop/bugcirc.gif", &fBug);
514 decode_file("/Users/caryclark/Desktop/tbcirc.gif", &fTb); 513 decode_file("/Users/caryclark/Desktop/tbcirc.gif", &fTb);
515 decode_file("/Users/caryclark/Desktop/05psp04.gif", &fTx); 514 decode_file("/Users/caryclark/Desktop/05psp04.gif", &fTx);
516 } 515 }
517 516
518 void drawRaster(SkCanvas* canvas) { 517 void drawRaster(SkCanvas* canvas) {
519 for (size_t index = 0; index < SK_ARRAY_COUNT(gRastProcs); index++) 518 for (size_t index = 0; index < SK_ARRAY_COUNT(gRastProcs); index++)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 private: 561 private:
563 SkPoint fClickPt; 562 SkPoint fClickPt;
564 SkBitmap fBug, fTb, fTx; 563 SkBitmap fBug, fTb, fTx;
565 typedef SampleView INHERITED; 564 typedef SampleView INHERITED;
566 }; 565 };
567 566
568 ////////////////////////////////////////////////////////////////////////////// 567 //////////////////////////////////////////////////////////////////////////////
569 568
570 static SkView* MyFactory() { return new DemoView; } 569 static SkView* MyFactory() { return new DemoView; }
571 static SkViewRegister reg(MyFactory); 570 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698