OLD | NEW |
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 SkPMColor fMask; | 74 SkPMColor fMask; |
75 }; | 75 }; |
76 | 76 |
77 /////////////////////////////////////////////////////////// | 77 /////////////////////////////////////////////////////////// |
78 | 78 |
79 static void r0(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { | 79 static void r0(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
80 p.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 80 p.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, |
81 SkBlurMask::ConvertRadiusToSigma(Sk
IntToScalar(3)), | 81 SkBlurMask::ConvertRadiusToSigma(SkIn
tToScalar(3)), |
82 SkBlurMaskFilter::kNone_BlurFlag))-
>unref(); | 82 SkBlurMaskFilter::kNone_BlurFlag)); |
83 rastBuilder->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); | 83 rastBuilder->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); |
84 | 84 |
85 p.setMaskFilter(nullptr); | 85 p.setMaskFilter(nullptr); |
86 p.setStyle(SkPaint::kStroke_Style); | 86 p.setStyle(SkPaint::kStroke_Style); |
87 p.setStrokeWidth(SK_Scalar1); | 87 p.setStrokeWidth(SK_Scalar1); |
88 rastBuilder->addLayer(p); | 88 rastBuilder->addLayer(p); |
89 | 89 |
90 p.setAlpha(0x11); | 90 p.setAlpha(0x11); |
91 p.setStyle(SkPaint::kFill_Style); | 91 p.setStyle(SkPaint::kFill_Style); |
92 p.setXfermodeMode(SkXfermode::kSrc_Mode); | 92 p.setXfermodeMode(SkXfermode::kSrc_Mode); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 SkPaint p; | 243 SkPaint p; |
244 SkLayerRasterizer::Builder rastBuilder; | 244 SkLayerRasterizer::Builder rastBuilder; |
245 | 245 |
246 p.setAntiAlias(true); | 246 p.setAntiAlias(true); |
247 proc(&rastBuilder, p); | 247 proc(&rastBuilder, p); |
248 paint->setRasterizer(rastBuilder.detach()); | 248 paint->setRasterizer(rastBuilder.detach()); |
249 } | 249 } |
250 | 250 |
251 #if 1 | 251 #if 1 |
252 SkScalar dir[] = { SK_Scalar1, SK_Scalar1, SK_Scalar1 }; | 252 SkScalar dir[] = { SK_Scalar1, SK_Scalar1, SK_Scalar1 }; |
253 paint->setMaskFilter(SkBlurMaskFilter::CreateEmboss( | 253 paint->setMaskFilter(SkBlurMaskFilter::MakeEmboss( |
254 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3)), dir, | 254 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3)), dir, |
255 SK_Scalar1/4, SkIntToScalar(4)))->unref(); | 255 SK_Scalar1/4, SkIntToScalar(4))); |
256 paint->setColor(SK_ColorBLUE); | 256 paint->setColor(SK_ColorBLUE); |
257 #endif | 257 #endif |
258 } | 258 } |
259 | 259 |
260 class DemoView : public SampleView { | 260 class DemoView : public SampleView { |
261 public: | 261 public: |
262 DemoView() {} | 262 DemoView() {} |
263 | 263 |
264 protected: | 264 protected: |
265 // overrides from SkEventSink | 265 // overrides from SkEventSink |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 auto radial = SkGradientShader::MakeRadial(radialCenter, | 372 auto radial = SkGradientShader::MakeRadial(radialCenter, |
373 radialRadius, radialColors, radialPos, radialCount, | 373 radialRadius, radialColors, radialPos, radialCount, |
374 radialMode); | 374 radialMode); |
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); | |
383 SkMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, light); | |
384 | 382 |
385 auto lightingFilter = SkColorMatrixFilter::MakeLightingFilter( | 383 auto lightingFilter = SkColorMatrixFilter::MakeLightingFilter( |
386 0xff89bc45, 0xff112233); | 384 0xff89bc45, 0xff112233); |
387 | 385 |
388 canvas->save(); | 386 canvas->save(); |
389 canvas->translate(SkIntToScalar(0), SkIntToScalar(5)); | 387 canvas->translate(SkIntToScalar(0), SkIntToScalar(5)); |
390 paint.setAntiAlias(true); | 388 paint.setAntiAlias(true); |
391 paint.setFilterQuality(kLow_SkFilterQuality); | 389 paint.setFilterQuality(kLow_SkFilterQuality); |
392 // !!! draw through a clip | 390 // !!! draw through a clip |
393 paint.setColor(SK_ColorLTGRAY); | 391 paint.setColor(SK_ColorLTGRAY); |
(...skipping 19 matching lines...) Expand all Loading... |
413 paint.setStyle(SkPaint::kFill_Style); | 411 paint.setStyle(SkPaint::kFill_Style); |
414 canvas->translate(SkIntToScalar(50), 0); | 412 canvas->translate(SkIntToScalar(50), 0); |
415 paint.setColor(SK_ColorYELLOW); | 413 paint.setColor(SK_ColorYELLOW); |
416 paint.setShader(linear); | 414 paint.setShader(linear); |
417 paint.setPathEffect(pathEffectTest()); | 415 paint.setPathEffect(pathEffectTest()); |
418 canvas->drawRect(rect, paint); | 416 canvas->drawRect(rect, paint); |
419 paint.setPathEffect(nullptr); | 417 paint.setPathEffect(nullptr); |
420 | 418 |
421 // circle w/ emboss & transparent (exercises 3dshader) | 419 // circle w/ emboss & transparent (exercises 3dshader) |
422 canvas->translate(SkIntToScalar(50), 0); | 420 canvas->translate(SkIntToScalar(50), 0); |
423 paint.setMaskFilter(embossFilter)->unref(); | 421 paint.setMaskFilter(SkEmbossMaskFilter::Make( |
| 422 SkBlurMask::ConvertRadiusToSigma(SkIntToSca
lar(12)/5), light)); |
424 canvas->drawOval(rect, paint); | 423 canvas->drawOval(rect, paint); |
425 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); | 424 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); |
426 // paint.setShader(transparentShader)->unref(); | 425 // paint.setShader(transparentShader)->unref(); |
427 canvas->drawOval(rect, paint); | 426 canvas->drawOval(rect, paint); |
428 canvas->translate(0, SkIntToScalar(-10)); | 427 canvas->translate(0, SkIntToScalar(-10)); |
429 | 428 |
430 // path | 429 // path |
431 canvas->translate(SkIntToScalar(50), 0); | 430 canvas->translate(SkIntToScalar(50), 0); |
432 paint.setColor(SK_ColorRED); | 431 paint.setColor(SK_ColorRED); |
433 paint.setStyle(SkPaint::kStroke_Style); | 432 paint.setStyle(SkPaint::kStroke_Style); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 private: | 560 private: |
562 SkPoint fClickPt; | 561 SkPoint fClickPt; |
563 SkBitmap fBug, fTb, fTx; | 562 SkBitmap fBug, fTb, fTx; |
564 typedef SampleView INHERITED; | 563 typedef SampleView INHERITED; |
565 }; | 564 }; |
566 | 565 |
567 ////////////////////////////////////////////////////////////////////////////// | 566 ////////////////////////////////////////////////////////////////////////////// |
568 | 567 |
569 static SkView* MyFactory() { return new DemoView; } | 568 static SkView* MyFactory() { return new DemoView; } |
570 static SkViewRegister reg(MyFactory); | 569 static SkViewRegister reg(MyFactory); |
OLD | NEW |