From 737169965fa97e4c71f2a625315b732969d00264 Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Fri, 12 May 2017 10:38:38 -0400 Subject: [PATCH] Add filled occluders to shadow_utils GM Change-Id: I70a927261b6530d2352d8d5a713b309aa518e6b0 Reviewed-on: https://skia-review.googlesource.com/16545 Commit-Queue: Jim Van Verth Reviewed-by: Mike Reed Reviewed-by: Brian Salomon --- gm/shadowutils.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/gm/shadowutils.cpp b/gm/shadowutils.cpp index 9d9eaae..17e2620 100644 --- a/gm/shadowutils.cpp +++ b/gm/shadowutils.cpp @@ -22,7 +22,7 @@ void draw_shadow(SkCanvas* canvas, const SkPath& path, int height, SkColor color static constexpr int kW = 800; static constexpr int kH = 800; -DEF_SIMPLE_GM(shadow_utils, canvas, kW, kH) { +void draw_paths(SkCanvas* canvas, bool hideOccluders) { SkTArray paths; paths.push_back().addRoundRect(SkRect::MakeWH(50, 50), 10, 10); SkRRect oddRRect; @@ -34,7 +34,7 @@ DEF_SIMPLE_GM(shadow_utils, canvas, kW, kH) { paths.push_back().addOval(SkRect::MakeWH(20, 60)); static constexpr SkScalar kPad = 15.f; - static constexpr SkPoint3 kLightPos = {250, 400, 500}; + static constexpr SkPoint3 kLightPos = { 250, 400, 500 }; static constexpr SkScalar kLightR = 100.f; static constexpr SkScalar kHeight = 50.f; canvas->translate(3 * kPad, 3 * kPad); @@ -47,7 +47,7 @@ DEF_SIMPLE_GM(shadow_utils, canvas, kW, kH) { m->setRotate(33.f, 25.f, 25.f); m->postScale(1.2f, 0.8f, 25.f, 25.f); for (auto& m : matrices) { - for (auto flags : {kNone_ShadowFlag, kTransparentOccluder_ShadowFlag}) { + for (auto flags : { kNone_ShadowFlag, kTransparentOccluder_ShadowFlag }) { for (const auto& path : paths) { SkRect postMBounds = path.getBounds(); m.mapRect(&postMBounds); @@ -68,10 +68,22 @@ DEF_SIMPLE_GM(shadow_utils, canvas, kW, kH) { // Draw the path outline in green on top of the ambient and spot shadows. SkPaint paint; - paint.setColor(SK_ColorGREEN); paint.setAntiAlias(true); - paint.setStyle(SkPaint::kStroke_Style); - paint.setStrokeWidth(0); + if (hideOccluders) { + if (SkToBool(flags & kTransparentOccluder_ShadowFlag)) { + paint.setColor(SK_ColorCYAN); + } else { + paint.setColor(SK_ColorGREEN); + } + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(0); + } else { + paint.setColor(SK_ColorLTGRAY); + if (SkToBool(flags & kTransparentOccluder_ShadowFlag)) { + paint.setAlpha(128); + } + paint.setStyle(SkPaint::kFill_Style); + } canvas->drawPath(path, paint); canvas->restore(); @@ -93,3 +105,11 @@ DEF_SIMPLE_GM(shadow_utils, canvas, kW, kH) { canvas->restore(); } } + +DEF_SIMPLE_GM(shadow_utils, canvas, kW, kH) { + draw_paths(canvas, true); +} + +DEF_SIMPLE_GM(shadow_utils_occl, canvas, kW, kH) { + draw_paths(canvas, false); +} -- 2.7.4