| Index: ui/compositor/paint_context.cc
|
| diff --git a/ui/compositor/paint_context.cc b/ui/compositor/paint_context.cc
|
| index b2b4fac54b39a4c19adb6b398cd1d3674d3a5e58..16e90f400d79d70ffcf1d78baa79c64ff53bb683 100644
|
| --- a/ui/compositor/paint_context.cc
|
| +++ b/ui/compositor/paint_context.cc
|
| @@ -4,16 +4,26 @@
|
|
|
| #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)
|
| : 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::ScaleToCornerScaledRect(gfx::Rect(size),
|
| + paint_recording_scale_x_)) {
|
| + ComputePaintRecordingScales(size);
|
| #if DCHECK_IS_ON()
|
| root_visited_ = nullptr;
|
| inside_paint_recorder_ = false;
|
| @@ -21,11 +31,17 @@ 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)),
|
| + offset_(other.offset_ + paint_recording_bounds_.OffsetFromOrigin()),
|
| + scale_type_(scale_type) {
|
| + ComputePaintRecordingScales(bounds.size());
|
| #if DCHECK_IS_ON()
|
| root_visited_ = other.root_visited_;
|
| inside_paint_recorder_ = other.inside_paint_recorder_;
|
| @@ -36,7 +52,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_(),
|
| + paint_recording_bounds_(other.paint_recording_bounds_),
|
| offset_(other.offset_) {
|
| #if DCHECK_IS_ON()
|
| root_visited_ = other.root_visited_;
|
| @@ -52,8 +71,74 @@ gfx::Rect PaintContext::ToLayerSpaceBounds(
|
| return gfx::Rect(size_in_context) + offset_;
|
| }
|
|
|
| -gfx::Rect PaintContext::ToLayerSpaceRect(const gfx::Rect& rect) const {
|
| - return rect + offset_;
|
| +void PaintContext::ComputePaintRecordingScales(const gfx::Size& size) {
|
| + if (!IsPixelCanvas()) {
|
| + 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::Transform PaintContext::TransformToParentRecordingSpace() const {
|
| + gfx::Transform to_parent_pixel_space;
|
| + if (IsPixelCanvas()) {
|
| + // This is just an optimization to prevent the computation of effective
|
| + // scale factors which would return 1.f if the Pixel Canvas is disabled.
|
| + to_parent_pixel_space.Scale(SkFloatToScalar(paint_recording_scale_x_),
|
| + SkFloatToScalar(paint_recording_scale_y_));
|
| + }
|
| + to_parent_pixel_space.Translate(paint_recording_bounds().OffsetFromOrigin());
|
| + return to_parent_pixel_space;
|
| +}
|
| +
|
| +gfx::Rect PaintContext::GetSnappedRecordingBounds(
|
| + const gfx::Rect& parent_bounds,
|
| + const gfx::Rect& child_bounds) const {
|
| + if (!IsPixelCanvas())
|
| + return child_bounds;
|
| +
|
| + 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, new_y, new_right - new_x, new_bottom - new_y);
|
| }
|
|
|
| } // namespace ui
|
|
|