Chromium Code Reviews| Index: ui/compositor/paint_context.cc |
| diff --git a/ui/compositor/paint_context.cc b/ui/compositor/paint_context.cc |
| index b2b4fac54b39a4c19adb6b398cd1d3674d3a5e58..185e2fac4e76e9e1b73864a6045cf0afb2023a6d 100644 |
| --- a/ui/compositor/paint_context.cc |
| +++ b/ui/compositor/paint_context.cc |
| @@ -4,16 +4,25 @@ |
| #include "ui/compositor/paint_context.h" |
| +#include "ui/compositor/compositor_switches.h" |
| #include "ui/gfx/canvas.h" |
| +#include "ui/gfx/transform.h" |
| namespace ui { |
| PaintContext::PaintContext(cc::DisplayItemList* list, |
| float device_scale_factor, |
| - const gfx::Rect& invalidation) |
| + const gfx::Rect& invalidation, |
| + const gfx::Size& size) |
|
danakj
2017/07/19 17:00:59
I was thinking about this and wondering if the rea
|
| : list_(list), |
| device_scale_factor_(device_scale_factor), |
| - invalidation_(invalidation) { |
| + paint_recording_scale_x_(IsPixelCanvas() ? device_scale_factor_ : 1.f), |
| + paint_recording_scale_y_(paint_recording_scale_x_), |
| + invalidation_( |
| + gfx::ScaleToEnclosingRect(invalidation, paint_recording_scale_x_)), |
| + paint_recording_bounds_( |
| + gfx::ScaleToRoundedRect(gfx::Rect(size), paint_recording_scale_x_)) { |
| + ComputePaintRecordingScales(size); |
| #if DCHECK_IS_ON() |
| root_visited_ = nullptr; |
| inside_paint_recorder_ = false; |
| @@ -21,11 +30,16 @@ PaintContext::PaintContext(cc::DisplayItemList* list, |
| } |
| PaintContext::PaintContext(const PaintContext& other, |
| - const gfx::Vector2d& offset) |
| + const gfx::Rect& bounds, |
| + const gfx::Rect& parent_bounds, |
| + ScaleType scale_type) |
| : list_(other.list_), |
| device_scale_factor_(other.device_scale_factor_), |
| invalidation_(other.invalidation_), |
| - offset_(other.offset_ + offset) { |
| + paint_recording_bounds_( |
| + other.GetSnappedRecordingBounds(parent_bounds, bounds)), |
| + scale_type_(scale_type) { |
| + ComputePaintRecordingScales(bounds.size()); |
| #if DCHECK_IS_ON() |
| root_visited_ = other.root_visited_; |
| inside_paint_recorder_ = other.inside_paint_recorder_; |
| @@ -36,8 +50,10 @@ PaintContext::PaintContext(const PaintContext& other, |
| CloneWithoutInvalidation c) |
| : list_(other.list_), |
| device_scale_factor_(other.device_scale_factor_), |
| + paint_recording_scale_x_(other.paint_recording_scale_x_), |
| + paint_recording_scale_y_(other.paint_recording_scale_y_), |
| invalidation_(), |
| - offset_(other.offset_) { |
| + paint_recording_bounds_(other.paint_recording_bounds_) { |
| #if DCHECK_IS_ON() |
| root_visited_ = other.root_visited_; |
| inside_paint_recorder_ = other.inside_paint_recorder_; |
| @@ -49,11 +65,69 @@ PaintContext::~PaintContext() { |
| gfx::Rect PaintContext::ToLayerSpaceBounds( |
| const gfx::Size& size_in_context) const { |
| - return gfx::Rect(size_in_context) + offset_; |
| + return gfx::Rect(paint_recording_bounds_.origin(), size_in_context); |
| } |
| -gfx::Rect PaintContext::ToLayerSpaceRect(const gfx::Rect& rect) const { |
| - return rect + offset_; |
| +void PaintContext::ComputePaintRecordingScales(const gfx::Size& size) { |
| + 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; |
| + return; |
| + } |
| + |
| + paint_recording_scale_x_ = paint_recording_scale_y_ = device_scale_factor_; |
| + if (scale_type_ == ScaleType::SCALE_TO_SCALE_FACTOR) |
| + 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()); |
| + } |
| +} |
| + |
| +bool PaintContext::IsPixelCanvas() const { |
| + return IsPixelCanvasRecordingEnabled(); |
| +} |
| + |
| +gfx::Rect PaintContext::GetSnappedRecordingBounds( |
| + const gfx::Rect& parent_bounds, |
| + 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() * device_scale_factor_); |
| + int new_y = std::round(child_origin.y() * device_scale_factor_); |
| + |
| + int new_right; |
| + int new_bottom; |
| + |
| + if (right == parent_bounds.width()) { |
| + new_right = paint_recording_bounds_.width(); |
| + } else { |
| + new_right = std::round(right * device_scale_factor_); |
| + } |
| + |
| + if (bottom == parent_bounds.height()) { |
| + new_bottom = paint_recording_bounds_.height(); |
| + } else { |
| + new_bottom = std::round(bottom * 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 ui |