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