| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/shadow_util.h" | 5 #include "ui/gfx/shadow_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 float corner_radius) | 29 float corner_radius) |
| 30 : CanvasImageSource(CalculateSize(shadows, corner_radius), false), | 30 : CanvasImageSource(CalculateSize(shadows, corner_radius), false), |
| 31 shadows_(shadows), | 31 shadows_(shadows), |
| 32 corner_radius_(corner_radius) { | 32 corner_radius_(corner_radius) { |
| 33 DCHECK(!shadows.empty()); | 33 DCHECK(!shadows.empty()); |
| 34 } | 34 } |
| 35 ~ShadowNineboxSource() override {} | 35 ~ShadowNineboxSource() override {} |
| 36 | 36 |
| 37 // CanvasImageSource overrides: | 37 // CanvasImageSource overrides: |
| 38 void Draw(Canvas* canvas) override { | 38 void Draw(Canvas* canvas) override { |
| 39 SkPaint paint; | 39 cc::PaintFlags flags; |
| 40 paint.setLooper(CreateShadowDrawLooperCorrectBlur(shadows_)); | 40 flags.setLooper(CreateShadowDrawLooperCorrectBlur(shadows_)); |
| 41 Insets insets = -ShadowValue::GetMargin(shadows_); | 41 Insets insets = -ShadowValue::GetMargin(shadows_); |
| 42 gfx::Rect bounds(size()); | 42 gfx::Rect bounds(size()); |
| 43 bounds.Inset(insets); | 43 bounds.Inset(insets); |
| 44 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectToSkRect(bounds), | 44 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectToSkRect(bounds), |
| 45 corner_radius_, corner_radius_); | 45 corner_radius_, corner_radius_); |
| 46 | 46 |
| 47 // Clip out the center so it's not painted with the shadow. | 47 // Clip out the center so it's not painted with the shadow. |
| 48 canvas->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference, true); | 48 canvas->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference, true); |
| 49 // Clipping alone is not enough --- due to anti aliasing there will still be | 49 // Clipping alone is not enough --- due to anti aliasing there will still be |
| 50 // some of the fill color in the rounded corners. We must make the fill | 50 // some of the fill color in the rounded corners. We must make the fill |
| 51 // color transparent. | 51 // color transparent. |
| 52 paint.setColor(SK_ColorTRANSPARENT); | 52 flags.setColor(SK_ColorTRANSPARENT); |
| 53 canvas->sk_canvas()->drawRRect(r_rect, paint); | 53 canvas->sk_canvas()->drawRRect(r_rect, flags); |
| 54 } | 54 } |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 static Size CalculateSize(const std::vector<ShadowValue>& shadows, | 57 static Size CalculateSize(const std::vector<ShadowValue>& shadows, |
| 58 float corner_radius) { | 58 float corner_radius) { |
| 59 // The "content" area (the middle tile in the 3x3 grid) is a single pixel. | 59 // The "content" area (the middle tile in the 3x3 grid) is a single pixel. |
| 60 gfx::Rect bounds(0, 0, 1, 1); | 60 gfx::Rect bounds(0, 0, 1, 1); |
| 61 // We need enough space to render the full range of blur. | 61 // We need enough space to render the full range of blur. |
| 62 bounds.Inset(-ShadowValue::GetBlurRegion(shadows)); | 62 bounds.Inset(-ShadowValue::GetBlurRegion(shadows)); |
| 63 // We also need space for the full roundrect corner rounding. | 63 // We also need space for the full roundrect corner rounding. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 SkColorSetA(SK_ColorBLACK, 0x1f)); | 105 SkColorSetA(SK_ColorBLACK, 0x1f)); |
| 106 // To see what this looks like for elevation 24, try this CSS: | 106 // To see what this looks like for elevation 24, try this CSS: |
| 107 // box-shadow: 0 24px 48px rgba(0, 0, 0, .24), | 107 // box-shadow: 0 24px 48px rgba(0, 0, 0, .24), |
| 108 // 0 0 24px rgba(0, 0, 0, .12); | 108 // 0 0 24px rgba(0, 0, 0, .12); |
| 109 auto* source = new ShadowNineboxSource(shadow->values, corner_radius); | 109 auto* source = new ShadowNineboxSource(shadow->values, corner_radius); |
| 110 shadow->ninebox_image = ImageSkia(source, source->size()); | 110 shadow->ninebox_image = ImageSkia(source, source->size()); |
| 111 return *shadow; | 111 return *shadow; |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namespace gfx | 114 } // namespace gfx |
| OLD | NEW |