| 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 "cc/paint/paint_canvas.h" |
| 8 #include "cc/paint/paint_flags.h" |
| 7 #include "third_party/skia/include/core/SkDrawLooper.h" | 9 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 8 #include "third_party/skia/include/core/SkPaint.h" | |
| 9 #include "third_party/skia/include/core/SkRRect.h" | 10 #include "third_party/skia/include/core/SkRRect.h" |
| 10 #include "ui/compositor/paint_recorder.h" | 11 #include "ui/compositor/paint_recorder.h" |
| 11 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/color_palette.h" | 13 #include "ui/gfx/color_palette.h" |
| 13 #include "ui/gfx/geometry/insets.h" | 14 #include "ui/gfx/geometry/insets.h" |
| 14 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
| 15 #include "ui/gfx/geometry/point_conversions.h" | 16 #include "ui/gfx/geometry/point_conversions.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 17 #include "ui/gfx/geometry/rect_f.h" | 18 #include "ui/gfx/geometry/rect_f.h" |
| 18 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 49 : BasePaintedLayerDelegate(color), radius_(radius) {} | 50 : BasePaintedLayerDelegate(color), radius_(radius) {} |
| 50 | 51 |
| 51 CircleLayerDelegate::~CircleLayerDelegate() {} | 52 CircleLayerDelegate::~CircleLayerDelegate() {} |
| 52 | 53 |
| 53 gfx::Rect CircleLayerDelegate::GetPaintedBounds() const { | 54 gfx::Rect CircleLayerDelegate::GetPaintedBounds() const { |
| 54 const int diameter = radius_ * 2; | 55 const int diameter = radius_ * 2; |
| 55 return gfx::Rect(0, 0, diameter, diameter); | 56 return gfx::Rect(0, 0, diameter, diameter); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void CircleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 59 void CircleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
| 59 SkPaint paint; | 60 cc::PaintFlags paint; |
| 60 paint.setColor(color()); | 61 paint.setColor(color()); |
| 61 paint.setFlags(SkPaint::kAntiAlias_Flag); | 62 paint.setAntiAlias(true); |
| 62 paint.setStyle(SkPaint::kFill_Style); | 63 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 63 | 64 |
| 64 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); | 65 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); |
| 65 gfx::Canvas* canvas = recorder.canvas(); | 66 gfx::Canvas* canvas = recorder.canvas(); |
| 66 | 67 |
| 67 canvas->DrawCircle(GetPaintedBounds().CenterPoint(), radius_, paint); | 68 canvas->DrawCircle(GetPaintedBounds().CenterPoint(), radius_, paint); |
| 68 } | 69 } |
| 69 | 70 |
| 70 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
| 71 // | 72 // |
| 72 // RectangleLayerDelegate | 73 // RectangleLayerDelegate |
| 73 // | 74 // |
| 74 | 75 |
| 75 RectangleLayerDelegate::RectangleLayerDelegate(SkColor color, gfx::Size size) | 76 RectangleLayerDelegate::RectangleLayerDelegate(SkColor color, gfx::Size size) |
| 76 : BasePaintedLayerDelegate(color), size_(size) {} | 77 : BasePaintedLayerDelegate(color), size_(size) {} |
| 77 | 78 |
| 78 RectangleLayerDelegate::~RectangleLayerDelegate() {} | 79 RectangleLayerDelegate::~RectangleLayerDelegate() {} |
| 79 | 80 |
| 80 gfx::Rect RectangleLayerDelegate::GetPaintedBounds() const { | 81 gfx::Rect RectangleLayerDelegate::GetPaintedBounds() const { |
| 81 return gfx::Rect(size_); | 82 return gfx::Rect(size_); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void RectangleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 85 void RectangleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
| 85 SkPaint paint; | 86 cc::PaintFlags paint; |
| 86 paint.setColor(color()); | 87 paint.setColor(color()); |
| 87 paint.setFlags(SkPaint::kAntiAlias_Flag); | 88 paint.setAntiAlias(true); |
| 88 paint.setStyle(SkPaint::kFill_Style); | 89 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 89 | 90 |
| 90 ui::PaintRecorder recorder(context, size_); | 91 ui::PaintRecorder recorder(context, size_); |
| 91 gfx::Canvas* canvas = recorder.canvas(); | 92 gfx::Canvas* canvas = recorder.canvas(); |
| 92 canvas->DrawRect(GetPaintedBounds(), paint); | 93 canvas->DrawRect(GetPaintedBounds(), paint); |
| 93 } | 94 } |
| 94 | 95 |
| 95 //////////////////////////////////////////////////////////////////////////////// | 96 //////////////////////////////////////////////////////////////////////////////// |
| 96 // | 97 // |
| 97 // RoundedRectangleLayerDelegate | 98 // RoundedRectangleLayerDelegate |
| 98 // | 99 // |
| 99 | 100 |
| 100 RoundedRectangleLayerDelegate::RoundedRectangleLayerDelegate( | 101 RoundedRectangleLayerDelegate::RoundedRectangleLayerDelegate( |
| 101 SkColor color, | 102 SkColor color, |
| 102 const gfx::Size& size, | 103 const gfx::Size& size, |
| 103 int corner_radius) | 104 int corner_radius) |
| 104 : BasePaintedLayerDelegate(color), | 105 : BasePaintedLayerDelegate(color), |
| 105 size_(size), | 106 size_(size), |
| 106 corner_radius_(corner_radius) {} | 107 corner_radius_(corner_radius) {} |
| 107 | 108 |
| 108 RoundedRectangleLayerDelegate::~RoundedRectangleLayerDelegate() {} | 109 RoundedRectangleLayerDelegate::~RoundedRectangleLayerDelegate() {} |
| 109 | 110 |
| 110 gfx::Rect RoundedRectangleLayerDelegate::GetPaintedBounds() const { | 111 gfx::Rect RoundedRectangleLayerDelegate::GetPaintedBounds() const { |
| 111 return gfx::Rect(size_); | 112 return gfx::Rect(size_); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void RoundedRectangleLayerDelegate::OnPaintLayer( | 115 void RoundedRectangleLayerDelegate::OnPaintLayer( |
| 115 const ui::PaintContext& context) { | 116 const ui::PaintContext& context) { |
| 116 SkPaint paint; | 117 cc::PaintFlags paint; |
| 117 paint.setColor(color()); | 118 paint.setColor(color()); |
| 118 paint.setFlags(SkPaint::kAntiAlias_Flag); | 119 paint.setAntiAlias(true); |
| 119 paint.setStyle(SkPaint::kFill_Style); | 120 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 120 | 121 |
| 121 ui::PaintRecorder recorder(context, size_); | 122 ui::PaintRecorder recorder(context, size_); |
| 122 recorder.canvas()->DrawRoundRect(GetPaintedBounds(), corner_radius_, paint); | 123 recorder.canvas()->DrawRoundRect(GetPaintedBounds(), corner_radius_, paint); |
| 123 } | 124 } |
| 124 | 125 |
| 125 //////////////////////////////////////////////////////////////////////////////// | 126 //////////////////////////////////////////////////////////////////////////////// |
| 126 // | 127 // |
| 127 // BorderShadowLayerDelegate | 128 // BorderShadowLayerDelegate |
| 128 // | 129 // |
| 129 | 130 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 144 gfx::Rect total_rect(bounds_); | 145 gfx::Rect total_rect(bounds_); |
| 145 total_rect.Inset(gfx::ShadowValue::GetMargin(shadows_)); | 146 total_rect.Inset(gfx::ShadowValue::GetMargin(shadows_)); |
| 146 return total_rect; | 147 return total_rect; |
| 147 } | 148 } |
| 148 | 149 |
| 149 gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const { | 150 gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const { |
| 150 return gfx::RectF(bounds_).CenterPoint().OffsetFromOrigin(); | 151 return gfx::RectF(bounds_).CenterPoint().OffsetFromOrigin(); |
| 151 } | 152 } |
| 152 | 153 |
| 153 void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 154 void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
| 154 SkPaint paint; | 155 cc::PaintFlags paint; |
| 155 paint.setStyle(SkPaint::kFill_Style); | 156 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 156 paint.setAntiAlias(true); | 157 paint.setAntiAlias(true); |
| 157 paint.setColor(fill_color_); | 158 paint.setColor(fill_color_); |
| 158 | 159 |
| 159 gfx::RectF rrect_bounds = | 160 gfx::RectF rrect_bounds = |
| 160 gfx::RectF(bounds_ - GetPaintedBounds().OffsetFromOrigin()); | 161 gfx::RectF(bounds_ - GetPaintedBounds().OffsetFromOrigin()); |
| 161 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectFToSkRect(rrect_bounds), | 162 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectFToSkRect(rrect_bounds), |
| 162 corner_radius_, corner_radius_); | 163 corner_radius_, corner_radius_); |
| 163 | 164 |
| 164 // First the fill color. | 165 // First the fill color. |
| 165 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); | 166 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); |
| 166 recorder.canvas()->sk_canvas()->drawRRect(r_rect, paint); | 167 recorder.canvas()->sk_canvas()->drawRRect(r_rect, paint); |
| 167 | 168 |
| 168 // Now the shadow. | 169 // Now the shadow. |
| 169 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows_)); | 170 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows_)); |
| 170 recorder.canvas()->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference, | 171 recorder.canvas()->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference, |
| 171 true); | 172 true); |
| 172 recorder.canvas()->sk_canvas()->drawRRect(r_rect, paint); | 173 recorder.canvas()->sk_canvas()->drawRRect(r_rect, paint); |
| 173 } | 174 } |
| 174 | 175 |
| 175 } // namespace views | 176 } // namespace views |
| OLD | NEW |