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 19 matching lines...) Expand all Loading... |
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 cc::PaintFlags flags; | 39 cc::PaintFlags flags; |
40 flags.setLooper(CreateShadowDrawLooperCorrectBlur(shadows_)); | 40 flags.setLooper(CreateShadowDrawLooper(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 |
(...skipping 54 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 |