Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
|
sky
2017/07/26 22:12:11
no (c)
malaykeshav
2017/07/28 01:24:37
Done
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/paint_info.h" | |
| 6 | |
| 7 namespace views { | |
| 8 | |
| 9 PaintInfo::PaintInfo(const ui::PaintContext& context, const gfx::Size& size) | |
| 10 : paint_recording_scale_x_( | |
| 11 context.is_pixel_canvas() ? context.device_scale_factor() : 1.f), | |
| 12 paint_recording_scale_y_(paint_recording_scale_x_), | |
| 13 paint_recording_bounds_( | |
| 14 gfx::ScaleToRoundedRect(gfx::Rect(size), paint_recording_scale_x_)), | |
| 15 context_(context, gfx::Vector2d()), | |
| 16 root_context_(&context) {} | |
| 17 | |
| 18 PaintInfo::PaintInfo(const PaintInfo& other, | |
| 19 const gfx::Rect& bounds, | |
| 20 const gfx::Rect& parent_bounds, | |
| 21 ScaleType scale_type) | |
| 22 : paint_recording_bounds_( | |
|
sky
2017/07/26 22:12:11
Make sure to member initialize paint_recording_sca
malaykeshav
2017/07/28 01:24:37
Done
| |
| 23 other.GetSnappedRecordingBounds(parent_bounds, bounds)), | |
| 24 offset_from_parent_(paint_recording_bounds_.OffsetFromOrigin() - | |
| 25 other.paint_recording_bounds_.OffsetFromOrigin()), | |
| 26 context_(other.context(), offset_from_parent_), | |
| 27 root_context_(nullptr) { | |
|
sky
2017/07/26 22:12:11
How come this doesn't set root_context_? I think t
malaykeshav
2017/07/28 01:24:37
Done
| |
| 28 ComputePaintRecordingScales(bounds.size(), scale_type); | |
| 29 } | |
| 30 | |
| 31 PaintInfo::PaintInfo(const PaintInfo& other) | |
| 32 : paint_recording_scale_x_(other.paint_recording_scale_x_), | |
| 33 paint_recording_scale_y_(other.paint_recording_scale_y_), | |
| 34 paint_recording_bounds_(other.paint_recording_bounds_), | |
| 35 offset_from_parent_(other.offset_from_parent_), | |
| 36 context_(other.context(), ui::PaintContext::CLONE_WITHOUT_INVALIDATION), | |
| 37 root_context_(nullptr) {} | |
| 38 | |
| 39 PaintInfo::~PaintInfo() {} | |
| 40 | |
| 41 bool PaintInfo::IsPixelCanvas() const { | |
| 42 return context().is_pixel_canvas(); | |
| 43 } | |
| 44 | |
| 45 void PaintInfo::ComputePaintRecordingScales(const gfx::Size& size, | |
| 46 ScaleType scale_type) { | |
| 47 if (!IsPixelCanvas()) { | |
| 48 // If pixel canvas is disabled, all recordings are done in DIPs. These are | |
| 49 // later played back on to the raster canvas at |device_scale_factor_|. | |
| 50 paint_recording_scale_x_ = paint_recording_scale_y_ = 1.f; | |
| 51 return; | |
| 52 } | |
| 53 | |
| 54 paint_recording_scale_x_ = paint_recording_scale_y_ = | |
| 55 context().device_scale_factor(); | |
| 56 if (scale_type == ScaleType::kScaleToScaleFactor) | |
| 57 return; | |
| 58 | |
| 59 if (size.width() > 0) { | |
| 60 paint_recording_scale_x_ = | |
| 61 static_cast<float>(paint_recording_bounds_.width()) / | |
| 62 static_cast<float>(size.width()); | |
| 63 } | |
| 64 | |
| 65 if (size.height() > 0) { | |
| 66 paint_recording_scale_y_ = | |
| 67 static_cast<float>(paint_recording_bounds_.height()) / | |
| 68 static_cast<float>(size.height()); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 gfx::Rect PaintInfo::GetSnappedRecordingBounds( | |
| 73 const gfx::Rect& parent_bounds, | |
|
sky
2017/07/26 22:12:11
Don't the coordinate system of the two rects diffe
malaykeshav
2017/07/28 01:24:37
Yes. parent_bounds are not needed. parent_size is
| |
| 74 const gfx::Rect& child_bounds) const { | |
| 75 if (!IsPixelCanvas()) | |
| 76 return (child_bounds + paint_recording_bounds_.OffsetFromOrigin()); | |
| 77 | |
| 78 const gfx::Vector2d& child_origin = child_bounds.OffsetFromOrigin(); | |
| 79 | |
| 80 int right = child_origin.x() + child_bounds.width(); | |
| 81 int bottom = child_origin.y() + child_bounds.height(); | |
| 82 | |
| 83 int new_x = std::round(child_origin.x() * context().device_scale_factor()); | |
| 84 int new_y = std::round(child_origin.y() * context().device_scale_factor()); | |
| 85 | |
| 86 int new_right; | |
| 87 int new_bottom; | |
| 88 | |
| 89 if (right == parent_bounds.width()) { | |
|
sky
2017/07/26 22:12:11
no {}
sky
2017/07/26 22:12:11
Might rounding give you a size > parent_bounds.wid
malaykeshav
2017/07/28 01:24:37
Both the values are in DIP, so there should be no
malaykeshav
2017/07/28 01:24:37
Done.
sky
2017/07/28 16:02:11
Actually, I'm a little confused by why you need to
| |
| 90 new_right = paint_recording_bounds_.width(); | |
| 91 } else { | |
| 92 new_right = std::round(right * context().device_scale_factor()); | |
| 93 } | |
| 94 | |
| 95 if (bottom == parent_bounds.height()) { | |
| 96 new_bottom = paint_recording_bounds_.height(); | |
| 97 } else { | |
| 98 new_bottom = std::round(bottom * context().device_scale_factor()); | |
| 99 } | |
| 100 | |
| 101 return gfx::Rect(new_x + paint_recording_bounds_.x(), | |
| 102 new_y + paint_recording_bounds_.y(), new_right - new_x, | |
| 103 new_bottom - new_y); | |
| 104 } | |
| 105 | |
| 106 } // namespace views | |
| OLD | NEW |