| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
| 10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
| 11 #include "SkGaussianEdgeShader.h" | 11 #include "SkGaussianEdgeShader.h" |
| 12 #include "SkRRectsGaussianEdgeShader.h" | 12 #include "SkRRectsGaussianEdgeShader.h" |
| 13 #include "SkPath.h" | 13 #include "SkPath.h" |
| 14 #include "SkPathOps.h" | 14 #include "SkPathOps.h" |
| 15 #include "SkRRect.h" | 15 #include "SkRRect.h" |
| 16 #include "SkStroke.h" | 16 #include "SkStroke.h" |
| 17 | 17 |
| 18 constexpr int kNumCols = 2; | 18 constexpr int kNumCols = 2; |
| 19 constexpr int kNumRows = 5; | 19 constexpr int kNumRows = 5; |
| 20 constexpr int kCellSize = 128; | 20 constexpr int kCellSize = 128; |
| 21 constexpr SkScalar kPad = 8.0f; | 21 constexpr SkScalar kPad = 8.0f; |
| 22 constexpr SkScalar kBlurRadius = 8.0f; |
| 22 constexpr SkScalar kPeriod = 8.0f; | 23 constexpr SkScalar kPeriod = 8.0f; |
| 23 constexpr int kClipOffset = 32; | 24 constexpr int kClipOffset = 32; |
| 24 | 25 |
| 25 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 26 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 26 | 27 |
| 27 class Object { | 28 class Object { |
| 28 public: | 29 public: |
| 29 virtual ~Object() {} | 30 virtual ~Object() {} |
| 30 virtual bool asRRect(SkRRect* rr) const = 0; | 31 virtual bool asRRect(SkRRect* rr) const = 0; |
| 31 virtual SkPath asPath(SkScalar inset) const = 0; | 32 virtual SkPath asPath(SkScalar inset) const = 0; |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 // The goal is to replace this clipped draw (which clips the | 342 // The goal is to replace this clipped draw (which clips the |
| 342 // shadow) with a draw using the geometric clip | 343 // shadow) with a draw using the geometric clip |
| 343 if (kGaussianEdge_Mode == fMode) { | 344 if (kGaussianEdge_Mode == fMode) { |
| 344 canvas->save(); | 345 canvas->save(); |
| 345 clipObj->clip(canvas); | 346 clipObj->clip(canvas); |
| 346 | 347 |
| 347 // Draw with GaussianEdgeShader | 348 // Draw with GaussianEdgeShader |
| 348 SkPaint paint; | 349 SkPaint paint; |
| 349 paint.setAntiAlias(true); | 350 paint.setAntiAlias(true); |
| 350 // G channel is an F6.2 radius | 351 // G channel is an F6.2 radius |
| 351 paint.setColor(SkColorSetARGB(255, 0, (unsigned char)(4*
kPad), 0)); | 352 paint.setColor(SkColorSetARGB(255, 0, (unsigned char)(4*
kBlurRadius), 0)); |
| 352 paint.setShader(SkGaussianEdgeShader::Make()); | 353 paint.setShader(SkGaussianEdgeShader::Make()); |
| 353 drawObj->draw(canvas, paint); | 354 drawObj->draw(canvas, paint); |
| 354 canvas->restore(); | 355 canvas->restore(); |
| 355 } else if (kBlurMask_Mode == fMode) { | 356 } else if (kBlurMask_Mode == fMode) { |
| 356 SkPath clippedPath; | 357 SkPath clippedPath; |
| 357 | 358 |
| 358 SkScalar sigma = kPad / 4.0f; | 359 SkScalar sigma = kBlurRadius / 4.0f; |
| 359 | 360 |
| 360 if (clipObj->contains(drawObj->bounds())) { | 361 if (clipObj->contains(drawObj->bounds())) { |
| 361 clippedPath = drawObj->asPath(2.0f*sigma); | 362 clippedPath = drawObj->asPath(2.0f*sigma); |
| 362 } else { | 363 } else { |
| 363 SkPath drawnPath = drawObj->asPath(2.0f*sigma); | 364 SkPath drawnPath = drawObj->asPath(2.0f*sigma); |
| 364 SkPath clipPath = clipObj->asPath(2.0f*sigma); | 365 SkPath clipPath = clipObj->asPath(2.0f*sigma); |
| 365 | 366 |
| 366 SkAssertResult(Op(clipPath, drawnPath, kIntersect_SkPath
Op, &clippedPath)); | 367 SkAssertResult(Op(clipPath, drawnPath, kIntersect_SkPath
Op, &clippedPath)); |
| 367 } | 368 } |
| 368 | 369 |
| 369 SkPaint blurPaint; | 370 SkPaint blurPaint; |
| 370 blurPaint.setAntiAlias(true); | 371 blurPaint.setAntiAlias(true); |
| 371 blurPaint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlu
rStyle, sigma)); | 372 blurPaint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlu
rStyle, sigma)); |
| 372 canvas->drawPath(clippedPath, blurPaint); | 373 canvas->drawPath(clippedPath, blurPaint); |
| 373 } else { | 374 } else { |
| 374 SkASSERT(kRRectsGaussianEdge_Mode == fMode); | 375 SkASSERT(kRRectsGaussianEdge_Mode == fMode); |
| 375 | 376 |
| 376 SkRect cover = drawObj->bounds(); | 377 SkRect cover = drawObj->bounds(); |
| 377 SkAssertResult(cover.intersect(clipObj->bounds())); | 378 SkAssertResult(cover.intersect(clipObj->bounds())); |
| 378 | 379 |
| 379 SkPaint paint; | 380 SkPaint paint; |
| 380 | 381 |
| 381 SkRRect clipRR, drawnRR; | 382 SkRRect clipRR, drawnRR; |
| 382 | 383 |
| 383 if (clipObj->asRRect(&clipRR) && drawObj->asRRect(&drawnRR))
{ | 384 if (clipObj->asRRect(&clipRR) && drawObj->asRRect(&drawnRR))
{ |
| 384 paint.setShader(SkRRectsGaussianEdgeShader::Make(clipRR,
drawnRR, | 385 paint.setShader(SkRRectsGaussianEdgeShader::Make(clipRR,
drawnRR, |
| 385 kPad, 0
.0f)); | 386 kBlurRa
dius)); |
| 386 } | 387 } |
| 387 | 388 |
| 388 canvas->drawRect(cover, paint); | 389 canvas->drawRect(cover, paint); |
| 389 } | 390 } |
| 390 | 391 |
| 391 // Draw the clip and draw objects for reference | 392 // Draw the clip and draw objects for reference |
| 392 SkPaint strokePaint; | 393 SkPaint strokePaint; |
| 393 strokePaint.setStyle(SkPaint::kStroke_Style); | 394 strokePaint.setStyle(SkPaint::kStroke_Style); |
| 394 strokePaint.setStrokeWidth(0); | 395 strokePaint.setStrokeWidth(0); |
| 395 strokePaint.setColor(SK_ColorRED); | 396 strokePaint.setColor(SK_ColorRED); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 Mode fMode; | 428 Mode fMode; |
| 428 bool fPause; | 429 bool fPause; |
| 429 | 430 |
| 430 typedef GM INHERITED; | 431 typedef GM INHERITED; |
| 431 }; | 432 }; |
| 432 | 433 |
| 433 ////////////////////////////////////////////////////////////////////////////// | 434 ////////////////////////////////////////////////////////////////////////////// |
| 434 | 435 |
| 435 DEF_GM(return new RevealGM;) | 436 DEF_GM(return new RevealGM;) |
| 436 } | 437 } |
| OLD | NEW |