OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/views/animation/ink_drop_painted_layer_delegates.h" | 5 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" |
6 | 6 |
7 #include "third_party/skia/include/core/SkDrawLooper.h" | 7 #include "third_party/skia/include/core/SkDrawLooper.h" |
8 #include "third_party/skia/include/core/SkPaint.h" | 8 #include "third_party/skia/include/core/SkPaint.h" |
| 9 #include "third_party/skia/include/core/SkRRect.h" |
9 #include "ui/compositor/paint_recorder.h" | 10 #include "ui/compositor/paint_recorder.h" |
10 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
11 #include "ui/gfx/color_palette.h" | 12 #include "ui/gfx/color_palette.h" |
12 #include "ui/gfx/geometry/insets.h" | 13 #include "ui/gfx/geometry/insets.h" |
13 #include "ui/gfx/geometry/point.h" | 14 #include "ui/gfx/geometry/point.h" |
14 #include "ui/gfx/geometry/point_conversions.h" | 15 #include "ui/gfx/geometry/point_conversions.h" |
15 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
16 #include "ui/gfx/geometry/rect_f.h" | 17 #include "ui/gfx/geometry/rect_f.h" |
17 #include "ui/gfx/skia_util.h" | 18 #include "ui/gfx/skia_util.h" |
18 | 19 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 126 } |
126 | 127 |
127 //////////////////////////////////////////////////////////////////////////////// | 128 //////////////////////////////////////////////////////////////////////////////// |
128 // | 129 // |
129 // BorderShadowLayerDelegate | 130 // BorderShadowLayerDelegate |
130 // | 131 // |
131 | 132 |
132 BorderShadowLayerDelegate::BorderShadowLayerDelegate( | 133 BorderShadowLayerDelegate::BorderShadowLayerDelegate( |
133 const std::vector<gfx::ShadowValue>& shadows, | 134 const std::vector<gfx::ShadowValue>& shadows, |
134 const gfx::Rect& shadowed_area_bounds, | 135 const gfx::Rect& shadowed_area_bounds, |
| 136 SkColor fill_color, |
135 int corner_radius) | 137 int corner_radius) |
136 : BasePaintedLayerDelegate(gfx::kPlaceholderColor), | 138 : BasePaintedLayerDelegate(gfx::kPlaceholderColor), |
137 shadows_(shadows), | 139 shadows_(shadows), |
138 bounds_(shadowed_area_bounds), | 140 bounds_(shadowed_area_bounds), |
| 141 fill_color_(fill_color), |
139 corner_radius_(corner_radius) {} | 142 corner_radius_(corner_radius) {} |
140 | 143 |
141 BorderShadowLayerDelegate::~BorderShadowLayerDelegate() {} | 144 BorderShadowLayerDelegate::~BorderShadowLayerDelegate() {} |
142 | 145 |
143 gfx::Rect BorderShadowLayerDelegate::GetPaintedBounds() const { | 146 gfx::Rect BorderShadowLayerDelegate::GetPaintedBounds() const { |
144 gfx::Rect total_rect(bounds_); | 147 gfx::Rect total_rect(bounds_); |
145 total_rect.Inset(gfx::ShadowValue::GetMargin(shadows_)); | 148 total_rect.Inset(gfx::ShadowValue::GetMargin(shadows_)); |
146 return total_rect; | 149 return total_rect; |
147 } | 150 } |
148 | 151 |
149 gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const { | 152 gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const { |
150 return gfx::RectF(bounds_).CenterPoint().OffsetFromOrigin(); | 153 return gfx::RectF(bounds_).CenterPoint().OffsetFromOrigin(); |
151 } | 154 } |
152 | 155 |
153 void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 156 void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
154 SkPaint paint; | 157 SkPaint paint; |
155 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows_)); | |
156 paint.setStyle(SkPaint::kFill_Style); | 158 paint.setStyle(SkPaint::kFill_Style); |
157 paint.setAntiAlias(true); | 159 paint.setAntiAlias(true); |
158 paint.setColor(SK_ColorTRANSPARENT); | 160 paint.setColor(fill_color_); |
| 161 |
159 gfx::RectF rrect_bounds = | 162 gfx::RectF rrect_bounds = |
160 gfx::RectF(bounds_ - GetPaintedBounds().OffsetFromOrigin()); | 163 gfx::RectF(bounds_ - GetPaintedBounds().OffsetFromOrigin()); |
| 164 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectFToSkRect(rrect_bounds), |
| 165 corner_radius_, corner_radius_); |
161 | 166 |
| 167 // First the fill color. |
162 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); | 168 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); |
163 recorder.canvas()->DrawRoundRect(rrect_bounds, corner_radius_, paint); | 169 recorder.canvas()->sk_canvas()->drawRRect(r_rect, paint); |
164 | 170 |
165 SkPaint clear_paint; | 171 // Now the shadow. |
166 clear_paint.setAntiAlias(true); | 172 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows_)); |
167 clear_paint.setXfermodeMode(SkXfermode::kClear_Mode); | 173 recorder.canvas()->sk_canvas()->clipRRect(r_rect, SkRegion::kDifference_Op, |
168 // If we don't care about actually clearing preexisting buffer content, | 174 true); |
169 // this could be replaced with a kDifference clip for the draw above. | 175 recorder.canvas()->sk_canvas()->drawRRect(r_rect, paint); |
170 recorder.canvas()->DrawRoundRect(rrect_bounds, corner_radius_, clear_paint); | |
171 } | 176 } |
172 | 177 |
173 } // namespace views | 178 } // namespace views |
OLD | NEW |