Chromium Code Reviews| Index: ui/views/paint_info.cc |
| diff --git a/ui/views/paint_info.cc b/ui/views/paint_info.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..36accfb1a4d62b4dd3ef3f1685c6334de91482ec |
| --- /dev/null |
| +++ b/ui/views/paint_info.cc |
| @@ -0,0 +1,122 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/views/paint_info.h" |
| + |
| +namespace views { |
| + |
| +// static |
| +PaintInfo PaintInfo::CreateRootPaintInfo(const ui::PaintContext& root_context, |
| + const gfx::Size& size) { |
| + return PaintInfo(root_context, size); |
| +} |
| + |
| +// static |
| +PaintInfo PaintInfo::CreateChildPaintInfo(const PaintInfo& other, |
| + const gfx::Rect& bounds, |
| + const gfx::Size& parent_size, |
| + ScaleType scale_type) { |
| + return PaintInfo(other, bounds, parent_size, scale_type); |
| +} |
| + |
| +PaintInfo::PaintInfo(const ui::PaintContext& root_context, |
|
sky
2017/07/28 16:02:11
Style guide says order of declarations and definit
malaykeshav
2017/07/31 18:54:29
The style guide mentions that classes should be de
sky
2017/08/01 15:10:24
Here's the relevant item, "Function declaration or
malaykeshav
2017/08/01 19:31:01
Done
|
| + const gfx::Size& size) |
| + : paint_recording_scale_x_(root_context.is_pixel_canvas() |
| + ? root_context.device_scale_factor() |
| + : 1.f), |
| + paint_recording_scale_y_(paint_recording_scale_x_), |
| + paint_recording_bounds_( |
| + gfx::ScaleToRoundedRect(gfx::Rect(size), paint_recording_scale_x_)), |
| + context_(root_context, gfx::Vector2d()), |
| + root_context_(&root_context) {} |
| + |
| +PaintInfo::PaintInfo(const PaintInfo& other, |
| + const gfx::Rect& bounds, |
| + const gfx::Size& parent_size, |
| + ScaleType scale_type) |
| + : paint_recording_scale_x_(1.f), |
| + paint_recording_scale_y_(1.f), |
| + paint_recording_bounds_( |
| + other.GetSnappedRecordingBounds(parent_size, bounds)), |
| + offset_from_parent_(paint_recording_bounds_.OffsetFromOrigin() - |
| + other.paint_recording_bounds_.OffsetFromOrigin()), |
| + context_(other.context(), offset_from_parent_), |
| + root_context_(nullptr) { |
| + ComputePaintRecordingScales(bounds.size(), scale_type); |
| +} |
| + |
| +PaintInfo::PaintInfo(const PaintInfo& other) |
| + : paint_recording_scale_x_(other.paint_recording_scale_x_), |
| + paint_recording_scale_y_(other.paint_recording_scale_y_), |
| + paint_recording_bounds_(other.paint_recording_bounds_), |
| + offset_from_parent_(other.offset_from_parent_), |
| + context_(other.context(), ui::PaintContext::CLONE_WITHOUT_INVALIDATION), |
| + root_context_(nullptr) {} |
| + |
| +PaintInfo::~PaintInfo() {} |
| + |
| +bool PaintInfo::IsPixelCanvas() const { |
| + return context().is_pixel_canvas(); |
| +} |
| + |
| +void PaintInfo::ComputePaintRecordingScales(const gfx::Size& size, |
|
sky
2017/07/28 16:02:11
You only call this from one place, how about movin
malaykeshav
2017/07/31 18:54:29
Done
|
| + ScaleType scale_type) { |
| + if (!IsPixelCanvas()) { |
| + // If pixel canvas is disabled, all recordings are done in DIPs. These are |
| + // later played back on to the raster canvas at |device_scale_factor_|. |
| + paint_recording_scale_x_ = paint_recording_scale_y_ = 1.f; |
|
sky
2017/07/28 16:02:11
When you inline this function in the constructor t
malaykeshav
2017/07/31 18:54:29
Ack
|
| + return; |
| + } |
| + |
| + paint_recording_scale_x_ = paint_recording_scale_y_ = |
| + context().device_scale_factor(); |
| + if (scale_type == ScaleType::kScaleToScaleFactor) |
| + return; |
| + |
| + if (size.width() > 0) { |
| + paint_recording_scale_x_ = |
| + static_cast<float>(paint_recording_bounds_.width()) / |
| + static_cast<float>(size.width()); |
| + } |
| + |
| + if (size.height() > 0) { |
| + paint_recording_scale_y_ = |
| + static_cast<float>(paint_recording_bounds_.height()) / |
| + static_cast<float>(size.height()); |
| + } |
| +} |
| + |
| +gfx::Rect PaintInfo::GetSnappedRecordingBounds( |
| + const gfx::Size& parent_size, |
| + const gfx::Rect& child_bounds) const { |
| + if (!IsPixelCanvas()) |
| + return (child_bounds + paint_recording_bounds_.OffsetFromOrigin()); |
| + |
| + const gfx::Vector2d& child_origin = child_bounds.OffsetFromOrigin(); |
| + |
| + int right = child_origin.x() + child_bounds.width(); |
| + int bottom = child_origin.y() + child_bounds.height(); |
| + |
| + int new_x = std::round(child_origin.x() * context().device_scale_factor()); |
| + int new_y = std::round(child_origin.y() * context().device_scale_factor()); |
| + |
| + int new_right; |
| + int new_bottom; |
| + |
| + if (right == parent_size.width()) |
| + new_right = paint_recording_bounds_.width(); |
| + else |
| + new_right = std::round(right * context().device_scale_factor()); |
| + |
| + if (bottom == parent_size.height()) |
| + new_bottom = paint_recording_bounds_.height(); |
| + else |
| + new_bottom = std::round(bottom * context().device_scale_factor()); |
| + |
| + return gfx::Rect(new_x + paint_recording_bounds_.x(), |
| + new_y + paint_recording_bounds_.y(), new_right - new_x, |
| + new_bottom - new_y); |
| +} |
| + |
| +} // namespace views |