Commit 8e7b6c0c authored by Michael Spang's avatar Michael Spang Committed by Commit Bot

Reland "display: Deduplicate display transform code with overlay transform code"

This is a reland of 4430b4c3

Original change's description:
> display: Deduplicate display transform code with overlay transform code
>
> Display rotation transforms are a subset of overlay transforms, so we can
> reuse OverlayTransformToTransform to compute display rotation matrices.
>
> Bug: 1019015
>
> Change-Id: I95d099323cb866ccc4b9cea404e1e6f8f2dfff65
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913604
> Commit-Queue: Michael Spang <spang@chromium.org>
> Reviewed-by: Khushal <khushalsagar@chromium.org>
> Reviewed-by: Ken Buchanan <kenrb@chromium.org>
> Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
> Reviewed-by: Mitsuru Oshima (OOO - back on Dec 2nd) <oshima@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#717832}

TBR=oshima@chromium.org,sadrul@chromium.org,kenrb@chromium.org,kenrb@chromium.org

Bug: 1019015
Change-Id: I3eaa7819971e9ebd51329f22506cb6bb905d429a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931131
Commit-Queue: Michael Spang <spang@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722643}
parent 9998653e
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "ash/shell_state.h" #include "ash/shell_state.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/system/unified/unified_system_tray.h" #include "ash/system/unified/unified_system_tray.h"
#include "ash/utility/transformer_util.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
...@@ -48,6 +47,7 @@ ...@@ -48,6 +47,7 @@
#include "ui/compositor/compositor_switches.h" #include "ui/compositor/compositor_switches.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/display_layout.h" #include "ui/display/display_layout.h"
#include "ui/display/display_transform.h"
#include "ui/display/manager/display_configurator.h" #include "ui/display/manager/display_configurator.h"
#include "ui/display/manager/display_layout_store.h" #include "ui/display/manager/display_layout_store.h"
#include "ui/display/manager/display_manager.h" #include "ui/display/manager/display_manager.h"
...@@ -86,7 +86,7 @@ void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, ...@@ -86,7 +86,7 @@ void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host,
ash_host->SetRootWindowTransformer(std::move(transformer)); ash_host->SetRootWindowTransformer(std::move(transformer));
host->SetDisplayTransformHint( host->SetDisplayTransformHint(
DisplayRotationToOverlayTransform(effective_rotation)); display::DisplayRotationToOverlayTransform(effective_rotation));
// Just moving the display requires the full redraw. // Just moving the display requires the full redraw.
// chrome-os-partner:33558. // chrome-os-partner:33558.
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <cmath> #include <cmath>
#include "third_party/skia/include/core/SkMatrix44.h" #include "ui/display/display_transform.h"
#include "ui/gfx/geometry/size_f.h" #include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
...@@ -26,26 +26,8 @@ display::Display::Rotation RotationBetween( ...@@ -26,26 +26,8 @@ display::Display::Rotation RotationBetween(
gfx::Transform CreateRotationTransform(display::Display::Rotation old_rotation, gfx::Transform CreateRotationTransform(display::Display::Rotation old_rotation,
display::Display::Rotation new_rotation, display::Display::Rotation new_rotation,
const gfx::SizeF& size_to_rotate) { const gfx::SizeF& size_to_rotate) {
gfx::Transform transform = display::Display::GetRotationTransform( return display::CreateRotationTransform(
RotationBetween(old_rotation, new_rotation), size_to_rotate); RotationBetween(old_rotation, new_rotation), size_to_rotate);
return transform;
}
gfx::OverlayTransform DisplayRotationToOverlayTransform(
display::Display::Rotation rotation) {
switch (rotation) {
case display::Display::ROTATE_0:
return gfx::OVERLAY_TRANSFORM_NONE;
case display::Display::ROTATE_90:
return gfx::OVERLAY_TRANSFORM_ROTATE_90;
case display::Display::ROTATE_180:
return gfx::OVERLAY_TRANSFORM_ROTATE_180;
case display::Display::ROTATE_270:
return gfx::OVERLAY_TRANSFORM_ROTATE_270;
}
NOTREACHED();
return gfx::OVERLAY_TRANSFORM_NONE;
} }
} // namespace ash } // namespace ash
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/gfx/overlay_transform.h"
namespace gfx { namespace gfx {
class SizeF; class SizeF;
...@@ -23,10 +22,6 @@ ASH_EXPORT gfx::Transform CreateRotationTransform( ...@@ -23,10 +22,6 @@ ASH_EXPORT gfx::Transform CreateRotationTransform(
display::Display::Rotation new_rotation, display::Display::Rotation new_rotation,
const gfx::SizeF& size_to_rotate); const gfx::SizeF& size_to_rotate);
// Maps display::Display::Rotation to gfx::OverlayTransform.
ASH_EXPORT gfx::OverlayTransform DisplayRotationToOverlayTransform(
display::Display::Rotation rotation);
} // namespace ash } // namespace ash
#endif // ASH_TRANSFORMER_UTIL_H_ #endif // ASH_TRANSFORMER_UTIL_H_
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "ui/base/ime/init/input_method_factory.h" #include "ui/base/ime/init/input_method_factory.h"
#include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/display_transform.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/ozone_platform.h"
#include "ui/platform_window/platform_window_init_properties.h" #include "ui/platform_window/platform_window_init_properties.h"
...@@ -39,8 +40,8 @@ namespace { ...@@ -39,8 +40,8 @@ namespace {
gfx::Transform GetPrimaryDisplayRotationTransform() { gfx::Transform GetPrimaryDisplayRotationTransform() {
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
return display::Display::GetRotationTransform(display.rotation(), return display::CreateRotationTransform(display.rotation(),
gfx::SizeF(display.size())); gfx::SizeF(display.size()));
} }
gfx::Rect GetPrimaryDisplayHostBounds() { gfx::Rect GetPrimaryDisplayHostBounds() {
......
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
#include "third_party/skia/include/core/SkMallocPixelRef.h" #include "third_party/skia/include/core/SkMallocPixelRef.h"
#include "ui/android/window_android.h" #include "ui/android/window_android.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/display_transform.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/gfx/ca_layer_params.h" #include "ui/gfx/ca_layer_params.h"
#include "ui/gfx/swap_result.h" #include "ui/gfx/swap_result.h"
...@@ -94,33 +95,6 @@ NOINLINE void FatalSurfaceFailure() { ...@@ -94,33 +95,6 @@ NOINLINE void FatalSurfaceFailure() {
LOG(FATAL) << "Fatal surface initialization failure"; LOG(FATAL) << "Fatal surface initialization failure";
} }
gfx::OverlayTransform RotationToDisplayTransform(
display::Display::Rotation rotation) {
// Note that the angle provided by |rotation| here is the opposite direction
// of the physical rotation of the device, which is the space in which the UI
// prepares the scene (see
// https://developer.android.com/reference/android/view/Display#getRotation()
// for details).
//
// The rotation which needs to be applied by the display compositor to allow
// the buffers produced by it to be used directly by the system compositor
// needs to be the inverse of this rotation. Since display::Rotation is in
// clockwise direction while gfx::OverlayTransform is anti-clockwise, directly
// mapping them below performs this inversion.
switch (rotation) {
case display::Display::ROTATE_0:
return gfx::OVERLAY_TRANSFORM_NONE;
case display::Display::ROTATE_90:
return gfx::OVERLAY_TRANSFORM_ROTATE_90;
case display::Display::ROTATE_180:
return gfx::OVERLAY_TRANSFORM_ROTATE_180;
case display::Display::ROTATE_270:
return gfx::OVERLAY_TRANSFORM_ROTATE_270;
}
NOTREACHED();
return gfx::OVERLAY_TRANSFORM_NONE;
}
gpu::SharedMemoryLimits GetCompositorContextSharedMemoryLimits( gpu::SharedMemoryLimits GetCompositorContextSharedMemoryLimits(
gfx::NativeWindow window) { gfx::NativeWindow window) {
const gfx::Size screen_size = display::Screen::GetScreen() const gfx::Size screen_size = display::Screen::GetScreen()
...@@ -449,7 +423,7 @@ void CompositorImpl::CreateLayerTreeHost() { ...@@ -449,7 +423,7 @@ void CompositorImpl::CreateLayerTreeHost() {
const auto& display_props = const auto& display_props =
display::Screen::GetScreen()->GetDisplayNearestWindow(root_window_); display::Screen::GetScreen()->GetDisplayNearestWindow(root_window_);
host_->set_display_transform_hint( host_->set_display_transform_hint(
RotationToDisplayTransform(display_props.rotation())); display::DisplayRotationToOverlayTransform(display_props.rotation()));
if (needs_animate_) if (needs_animate_)
host_->SetNeedsAnimate(); host_->SetNeedsAnimate();
...@@ -777,7 +751,7 @@ void CompositorImpl::OnDisplayMetricsChanged(const display::Display& display, ...@@ -777,7 +751,7 @@ void CompositorImpl::OnDisplayMetricsChanged(const display::Display& display,
if (changed_metrics & if (changed_metrics &
display::DisplayObserver::DisplayMetric::DISPLAY_METRIC_ROTATION) { display::DisplayObserver::DisplayMetric::DISPLAY_METRIC_ROTATION) {
host_->set_display_transform_hint( host_->set_display_transform_hint(
RotationToDisplayTransform(display.rotation())); display::DisplayRotationToOverlayTransform(display.rotation()));
} }
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method.h"
#include "ui/display/display_transform.h"
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size_conversions.h" #include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
...@@ -117,8 +118,8 @@ void TestScreen::SetWorkAreaInsets(const gfx::Insets& insets) { ...@@ -117,8 +118,8 @@ void TestScreen::SetWorkAreaInsets(const gfx::Insets& insets) {
gfx::Transform TestScreen::GetRotationTransform() const { gfx::Transform TestScreen::GetRotationTransform() const {
display::Display display = GetPrimaryDisplay(); display::Display display = GetPrimaryDisplay();
return display::Display::GetRotationTransform(display.rotation(), return display::CreateRotationTransform(display.rotation(),
gfx::SizeF(display.size())); gfx::SizeF(display.size()));
} }
gfx::Transform TestScreen::GetUIScaleTransform() const { gfx::Transform TestScreen::GetUIScaleTransform() const {
......
...@@ -34,6 +34,8 @@ jumbo_component("display") { ...@@ -34,6 +34,8 @@ jumbo_component("display") {
"display_observer.h", "display_observer.h",
"display_switches.cc", "display_switches.cc",
"display_switches.h", "display_switches.h",
"display_transform.cc",
"display_transform.h",
"screen.cc", "screen.cc",
"screen.h", "screen.h",
"screen_base.cc", "screen_base.cc",
......
...@@ -285,34 +285,6 @@ int Display::PanelRotationAsDegree() const { ...@@ -285,34 +285,6 @@ int Display::PanelRotationAsDegree() const {
return RotationToDegrees(panel_rotation_); return RotationToDegrees(panel_rotation_);
} }
// static
gfx::Transform Display::GetRotationTransform(Rotation rotation,
const gfx::SizeF& size) {
// NB: Using gfx::Transform::Rotate() introduces very small errors here
// which are later exacerbated by use of gfx::EnclosingRect() in
// WindowTreeHost::GetTransformedRootWindowBoundsInPixels().
const gfx::Transform rotate_90(0.f, -1.f, 0.f, 0.f, //
1.f, 0.f, 0.f, 0.f, //
0.f, 0.f, 1.f, 0.f, //
0.f, 0.f, 0.f, 1.f);
const gfx::Transform rotate_180 = rotate_90 * rotate_90;
const gfx::Transform rotate_270 = rotate_180 * rotate_90;
gfx::Transform translation;
switch (rotation) {
case display::Display::ROTATE_0:
return translation;
case display::Display::ROTATE_90:
translation.Translate(size.height(), 0);
return translation * rotate_90;
case display::Display::ROTATE_180:
translation.Translate(size.width(), size.height());
return translation * rotate_180;
case display::Display::ROTATE_270:
translation.Translate(0, size.width());
return translation * rotate_270;
}
}
gfx::Insets Display::GetWorkAreaInsets() const { gfx::Insets Display::GetWorkAreaInsets() const {
return gfx::Insets(work_area_.y() - bounds_.y(), work_area_.x() - bounds_.x(), return gfx::Insets(work_area_.y() - bounds_.y(), work_area_.x() - bounds_.x(),
bounds_.bottom() - work_area_.bottom(), bounds_.bottom() - work_area_.bottom(),
......
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
#include "ui/display/types/display_constants.h" #include "ui/display/types/display_constants.h"
#include "ui/gfx/color_space.h" #include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/transform.h"
namespace display { namespace display {
...@@ -167,11 +165,6 @@ class DISPLAY_EXPORT Display final { ...@@ -167,11 +165,6 @@ class DISPLAY_EXPORT Display final {
void set_panel_rotation(Rotation rotation) { panel_rotation_ = rotation; } void set_panel_rotation(Rotation rotation) { panel_rotation_ = rotation; }
int PanelRotationAsDegree() const; int PanelRotationAsDegree() const;
// Returns an exact matrix representation of the transform that corrects for
// the display's rotation.
static gfx::Transform GetRotationTransform(Rotation rotation,
const gfx::SizeF& size);
TouchSupport touch_support() const { return touch_support_; } TouchSupport touch_support() const { return touch_support_; }
void set_touch_support(TouchSupport support) { touch_support_ = support; } void set_touch_support(TouchSupport support) { touch_support_ = support; }
......
// Copyright 2019 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/display/display_transform.h"
#include "ui/gfx/overlay_transform_utils.h"
namespace display {
gfx::Transform CreateRotationTransform(display::Display::Rotation rotation,
const gfx::SizeF& size_to_rotate) {
return OverlayTransformToTransform(
DisplayRotationToOverlayTransform(rotation), size_to_rotate);
}
gfx::OverlayTransform DisplayRotationToOverlayTransform(
display::Display::Rotation rotation) {
// Note that the angle provided by |rotation| here is the opposite direction
// of the physical rotation of the device, which is the space in which the UI
// prepares the scene (see
// https://developer.android.com/reference/android/view/Display#getRotation()
// for details).
//
// The rotation which needs to be applied by the display compositor to allow
// the buffers produced by it to be used directly by the system compositor
// needs to be the inverse of this rotation. Since display::Rotation is in
// clockwise direction while gfx::OverlayTransform is anti-clockwise, directly
// mapping them below performs this inversion.
switch (rotation) {
case display::Display::ROTATE_0:
return gfx::OVERLAY_TRANSFORM_NONE;
case display::Display::ROTATE_90:
return gfx::OVERLAY_TRANSFORM_ROTATE_90;
case display::Display::ROTATE_180:
return gfx::OVERLAY_TRANSFORM_ROTATE_180;
case display::Display::ROTATE_270:
return gfx::OVERLAY_TRANSFORM_ROTATE_270;
}
NOTREACHED();
return gfx::OVERLAY_TRANSFORM_NONE;
}
} // namespace display
// Copyright 2019 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.
#ifndef UI_DISPLAY_DISPLAY_TRANSFORM_H_
#define UI_DISPLAY_DISPLAY_TRANSFORM_H_
#include "ui/display/display.h"
#include "ui/display/display_export.h"
#include "ui/gfx/overlay_transform.h"
namespace gfx {
class SizeF;
class Transform;
} // namespace gfx
namespace display {
// Creates an exact gfx::Transform for a rotation.
DISPLAY_EXPORT gfx::Transform CreateRotationTransform(
display::Display::Rotation rotation,
const gfx::SizeF& size_to_rotate);
// Maps display::Display::Rotation to gfx::OverlayTransform.
DISPLAY_EXPORT gfx::OverlayTransform DisplayRotationToOverlayTransform(
display::Display::Rotation rotation);
} // namespace display
#endif // UI_DISPLAY_DISPLAY_TRANSFORM_H_
...@@ -23,6 +23,11 @@ per-file screen*=oshima@chromium.org ...@@ -23,6 +23,11 @@ per-file screen*=oshima@chromium.org
# Canvas painting. # Canvas painting.
per-file canvas*=danakj@chromium.org per-file canvas*=danakj@chromium.org
# Overlay transforms.
per-file overlay*=alexst@chromium.org
per-file overlay*=khushalsagar@chromium.org
per-file overlay*=spang@chromium.org
# Transform, interpolated transform and transform util. # Transform, interpolated transform and transform util.
per-file transform*=danakj@chromium.org per-file transform*=danakj@chromium.org
per-file transform*=vollick@chromium.org per-file transform*=vollick@chromium.org
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment