Commit 099f851f authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

cros: Fix capturing orientation

Instead of setting the rotation as part of the transform on
ash root window, call viz SetDisplayTransformHint so that
capturing code as a consumer of viz could get the correct
orientation.

Bug: 847693
Change-Id: Id70f91dc84fc9274145d5a160a51b8c7fa50deed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1825892Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707004}
parent f9526c74
......@@ -30,6 +30,7 @@
#include "ui/base/ui_base_switches_util.h"
#include "ui/compositor/reflector.h"
#include "ui/display/display_layout.h"
#include "ui/display/manager/display_layout_store.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/manager/managed_display_info.h"
#include "ui/display/screen.h"
......@@ -249,15 +250,32 @@ void MirrorWindowController::UpdateWindow(
}
if (features::IsVizDisplayCompositorEnabled()) {
// |mirror_size| is the size of the mirror source in physical pixels.
// The RootWindowTransformer corrects the scale of the mirrored display
// and the location of input events.
gfx::Size mirror_size =
display_manager->GetDisplayInfo(reflecting_source_id_)
.bounds_in_native()
.size();
aura::Window* mirror_window =
mirroring_host_info_map_[display_info.id()]->mirror_window;
// |mirror_size| is the size of the compositor of the mirror source in
// physical pixels. The RootWindowTransformer corrects the scale of the
// mirrored display and the location of input events.
ui::Compositor* source_compositor =
Shell::GetRootWindowForDisplayId(reflecting_source_id_)
->GetHost()
->compositor();
gfx::Size mirror_size = source_compositor->size();
auto* mirroring_host_info = mirroring_host_info_map_[display_info.id()];
// The rotation of the source display (internal display) should be undone
// in the destination display (external display) if mirror mode is enabled
// in tablet mode. This allows the destination display to show in an
// orientation independent of the source display.
// See https://crbug.com/824417
const bool should_undo_rotation = Shell::Get()
->display_manager()
->layout_store()
->forced_mirror_mode_for_tablet();
if (!should_undo_rotation) {
mirroring_host_info->ash_host->AsWindowTreeHost()
->SetDisplayTransformHint(source_compositor->display_transform());
}
aura::Window* mirror_window = mirroring_host_info->mirror_window;
mirror_window->SetBounds(gfx::Rect(mirror_size));
mirror_window->Show();
mirror_window->layer()->SetShowReflectedSurface(reflecting_surface_id,
......
......@@ -12,6 +12,7 @@
#include "ash/shell.h"
#include "ash/utility/transformer_util.h"
#include "base/command_line.h"
#include "components/viz/common/features.h"
#include "ui/compositor/dip_util.h"
#include "ui/display/display.h"
#include "ui/display/manager/display_layout_store.h"
......@@ -56,6 +57,44 @@ gfx::Transform CreateInsetsAndScaleTransform(const gfx::Insets& insets,
return transform;
}
// Returns a transform with rotation adjusted |insets_in_pixel|. The transform
// is applied to the root window so that |insets_in_pixel| looks correct after
// the rotation applied at the output.
gfx::Transform CreateReverseRotatedInsetsTransform(
display::Display::Rotation rotation,
const gfx::Insets& insets_in_pixel,
float device_scale_factor) {
float x_offset = 0;
float y_offset = 0;
switch (rotation) {
case display::Display::ROTATE_0:
x_offset = insets_in_pixel.left();
y_offset = insets_in_pixel.top();
break;
case display::Display::ROTATE_90:
x_offset = insets_in_pixel.top();
y_offset = insets_in_pixel.right();
break;
case display::Display::ROTATE_180:
x_offset = insets_in_pixel.right();
y_offset = insets_in_pixel.bottom();
break;
case display::Display::ROTATE_270:
x_offset = insets_in_pixel.bottom();
y_offset = insets_in_pixel.left();
break;
}
gfx::Transform transform;
if (x_offset != 0 || y_offset != 0) {
x_offset /= device_scale_factor;
y_offset /= device_scale_factor;
transform.Translate(x_offset, y_offset);
}
return transform;
}
// RootWindowTransformer for ash environment.
class AshRootWindowTransformer : public RootWindowTransformer {
public:
......@@ -70,10 +109,16 @@ class AshRootWindowTransformer : public RootWindowTransformer {
display.device_scale_factor()) *
CreateRootWindowRotationTransform(root, display);
transform_ = root_window_bounds_transform_;
insets_and_scale_transform_ = CreateReverseRotatedInsetsTransform(
info.GetLogicalActiveRotation(), host_insets_,
display.device_scale_factor());
MagnificationController* magnifier =
Shell::Get()->magnification_controller();
if (magnifier)
transform_ *= magnifier->GetMagnifierTransform();
if (magnifier) {
gfx::Transform magnifier_scale = magnifier->GetMagnifierTransform();
transform_ *= magnifier_scale;
insets_and_scale_transform_ *= magnifier_scale;
}
CHECK(transform_.GetInverse(&invert_transform_));
}
......@@ -98,6 +143,9 @@ class AshRootWindowTransformer : public RootWindowTransformer {
}
gfx::Insets GetHostInsets() const override { return host_insets_; }
gfx::Transform GetInsetsAndScaleTransform() const override {
return insets_and_scale_transform_;
}
private:
~AshRootWindowTransformer() override = default;
......@@ -115,6 +163,7 @@ class AshRootWindowTransformer : public RootWindowTransformer {
gfx::Transform root_window_bounds_transform_;
gfx::Insets host_insets_;
gfx::Transform insets_and_scale_transform_;
DISALLOW_COPY_AND_ASSIGN(AshRootWindowTransformer);
};
......@@ -180,8 +229,12 @@ class MirrorRootWindowTransformer : public RootWindowTransformer {
transform_.Scale(inverted_scale, inverted_scale);
}
// Make sure the rotation transform is applied in the beginning.
transform_.PreconcatTransform(rotation_transform);
// Apply rotation only when reflector is used for mirroring (non viz display
// compositor).
if (!features::IsVizDisplayCompositorEnabled()) {
// Make sure the rotation transform is applied in the beginning.
transform_.PreconcatTransform(rotation_transform);
}
}
// aura::RootWindowTransformer overrides:
......@@ -195,6 +248,9 @@ class MirrorRootWindowTransformer : public RootWindowTransformer {
return root_bounds_;
}
gfx::Insets GetHostInsets() const override { return insets_; }
gfx::Transform GetInsetsAndScaleTransform() const override {
return transform_;
}
private:
~MirrorRootWindowTransformer() override = default;
......@@ -253,6 +309,9 @@ class PartialBoundsRootWindowTransformer : public RootWindowTransformer {
return root_bounds_;
}
gfx::Insets GetHostInsets() const override { return gfx::Insets(); }
gfx::Transform GetInsetsAndScaleTransform() const override {
return gfx::Transform();
}
private:
gfx::Transform transform_;
......
......@@ -291,7 +291,8 @@ TEST_F(RootWindowTransformersTest, ScaleAndMagnify) {
// on 2.25 scale factor device so that HW overlay kicks in.
// https://crbug.com/869090.
TEST_F(RootWindowTransformersTest, OriginAlignmentWithFractionalScale) {
auto* host_window = Shell::GetPrimaryRootWindow()->GetHost()->window();
auto* host = Shell::GetPrimaryRootWindow()->GetHost();
auto* host_window = host->window();
EXPECT_EQ(Shell::GetPrimaryRootWindow(), host_window);
float device_scale_factor = 2.25f;
......@@ -310,7 +311,7 @@ TEST_F(RootWindowTransformersTest, OriginAlignmentWithFractionalScale) {
gfx::RectF tmp(1998, 2999);
// Creates a transform that can be applied to already scaled layer.
gfx::Transform transform(invert_transform);
transform.ConcatTransform(host_window->layer()->transform());
transform.ConcatTransform(host->GetRootTransform() * invert_transform);
transform.ConcatTransform(scale_transform);
transform.TransformRect(&tmp);
EXPECT_EQ(gfx::SizeF(2999, 1998), tmp.size());
......@@ -323,7 +324,7 @@ TEST_F(RootWindowTransformersTest, OriginAlignmentWithFractionalScale) {
gfx::RectF tmp(2999, 1998);
gfx::Transform transform(invert_transform);
transform.ConcatTransform(host_window->layer()->transform());
transform.ConcatTransform(host->GetRootTransform() * invert_transform);
transform.ConcatTransform(scale_transform);
transform.TransformRect(&tmp);
EXPECT_EQ(gfx::SizeF(2999, 1998), tmp.size());
......@@ -336,7 +337,7 @@ TEST_F(RootWindowTransformersTest, OriginAlignmentWithFractionalScale) {
gfx::RectF tmp(1998, 2999);
gfx::Transform transform(invert_transform);
transform.ConcatTransform(host_window->layer()->transform());
transform.ConcatTransform(host->GetRootTransform() * invert_transform);
transform.ConcatTransform(scale_transform);
transform.TransformRect(&tmp);
EXPECT_EQ(gfx::SizeF(2999, 1998), tmp.size());
......
......@@ -24,6 +24,7 @@
#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/utility/transformer_util.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "base/metrics/histogram.h"
......@@ -75,12 +76,17 @@ void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host,
const display::Display& display) {
display::ManagedDisplayInfo info =
GetDisplayManager()->GetDisplayInfo(display.id());
const display::Display::Rotation effective_rotation =
info.GetLogicalActiveRotation();
aura::WindowTreeHost* host = ash_host->AsWindowTreeHost();
ash_host->SetCursorConfig(display, info.GetLogicalActiveRotation());
ash_host->SetCursorConfig(display, effective_rotation);
std::unique_ptr<RootWindowTransformer> transformer(
CreateRootWindowTransformerForDisplay(host->window(), display));
ash_host->SetRootWindowTransformer(std::move(transformer));
host->SetDisplayTransformHint(
DisplayRotationToOverlayTransform(effective_rotation));
// Just moving the display requires the full redraw.
// chrome-os-partner:33558.
host->compositor()->ScheduleFullRedraw();
......
......@@ -38,6 +38,10 @@ class ASH_EXPORT RootWindowTransformer {
// Returns the insets that specifies the effective area of
// the host window.
virtual gfx::Insets GetHostInsets() const = 0;
// Returns the transform for applying host insets and magnifier scale. It is
// similar to GetTransform() but without the screen rotation.
virtual gfx::Transform GetInsetsAndScaleTransform() const = 0;
};
} // namespace ash
......
......@@ -49,6 +49,9 @@ class SimpleRootWindowTransformer : public RootWindowTransformer {
}
gfx::Insets GetHostInsets() const override { return gfx::Insets(); }
gfx::Transform GetInsetsAndScaleTransform() const override {
return transform_;
}
private:
~SimpleRootWindowTransformer() override = default;
......@@ -86,7 +89,7 @@ void TransformerHelper::SetRootWindowTransformer(
transformer_ = std::move(transformer);
aura::WindowTreeHost* host = ash_host_->AsWindowTreeHost();
aura::Window* window = host->window();
window->SetTransform(transformer_->GetTransform());
window->SetTransform(transformer_->GetInsetsAndScaleTransform());
// If the layer is not animating with a transform animation, then we need to
// update the root window size immediately.
if (!window->layer()->GetAnimator()->IsAnimatingProperty(
......
......@@ -52,4 +52,20 @@ gfx::Transform CreateRotationTransform(display::Display::Rotation old_rotation,
return rotate;
}
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
......@@ -7,6 +7,7 @@
#include "ash/ash_export.h"
#include "ui/display/display.h"
#include "ui/gfx/overlay_transform.h"
namespace gfx {
class SizeF;
......@@ -22,6 +23,10 @@ ASH_EXPORT gfx::Transform CreateRotationTransform(
display::Display::Rotation new_rotation,
const gfx::SizeF& size_to_rotate);
// Maps display::Display::Rotation to gfx::OverlayTransform.
ASH_EXPORT gfx::OverlayTransform DisplayRotationToOverlayTransform(
display::Display::Rotation rotation);
} // namespace ash
#endif // ASH_TRANSFORMER_UTIL_H_
......@@ -111,6 +111,8 @@ viz_component("service") {
"display_embedder/gl_output_surface.h",
"display_embedder/gl_output_surface_buffer_queue.cc",
"display_embedder/gl_output_surface_buffer_queue.h",
"display_embedder/gl_output_surface_chromeos.cc",
"display_embedder/gl_output_surface_chromeos.h",
"display_embedder/gl_output_surface_offscreen.cc",
"display_embedder/gl_output_surface_offscreen.h",
"display_embedder/in_process_gpu_memory_buffer_manager.cc",
......
......@@ -527,13 +527,16 @@ bool Display::DrawAndSwap() {
// The CompositorFrame provided by the SurfaceAggregator includes the display
// transform while |current_surface_size_| is the pre-transform size received
// from the client.
const gfx::OverlayTransform current_display_transform =
output_surface_->GetDisplayTransform();
const gfx::Transform display_transform = gfx::OverlayTransformToTransform(
output_surface_->GetDisplayTransform(), current_surface_size_);
current_display_transform, current_surface_size_);
const gfx::Size current_surface_size =
cc::MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(
display_transform, gfx::Rect(current_surface_size_))
.size();
if (settings_.auto_resize_output_surface &&
last_display_transform_swapped_ == current_display_transform &&
last_render_pass.output_rect.size() != current_surface_size &&
last_render_pass.damage_rect == last_render_pass.output_rect &&
!current_surface_size.IsEmpty()) {
......@@ -610,6 +613,7 @@ bool Display::DrawAndSwap() {
"Graphics.Pipeline.DrawAndSwap",
swapped_trace_id_, "Swap");
swapped_since_resize_ = true;
last_display_transform_swapped_ = current_display_transform;
ui::LatencyInfo::TraceIntermediateFlowEvents(frame.metadata.latency_info,
"Display::DrawAndSwap");
......
......@@ -31,6 +31,7 @@
#include "components/viz/service/viz_service_export.h"
#include "gpu/command_buffer/common/texture_in_use_response.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/overlay_transform.h"
#include "ui/gfx/swap_result.h"
#include "ui/latency/latency_info.h"
......@@ -263,6 +264,9 @@ class VIZ_SERVICE_EXPORT Display : public DisplaySchedulerClient,
int64_t swapped_trace_id_ = 0;
int64_t last_presented_trace_id_ = 0;
gfx::OverlayTransform last_display_transform_swapped_ =
gfx::OVERLAY_TRANSFORM_NONE;
DISALLOW_COPY_AND_ASSIGN(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.
#include "components/viz/service/display_embedder/gl_output_surface_chromeos.h"
namespace viz {
GLOutputSurfaceChromeOS::GLOutputSurfaceChromeOS(
scoped_refptr<VizProcessContextProvider> context_provider,
gpu::SurfaceHandle surface_handle)
: GLOutputSurface(context_provider, surface_handle) {}
GLOutputSurfaceChromeOS::~GLOutputSurfaceChromeOS() = default;
void GLOutputSurfaceChromeOS::SetDisplayTransformHint(
gfx::OverlayTransform transform) {
display_transform_ = transform;
}
gfx::OverlayTransform GLOutputSurfaceChromeOS::GetDisplayTransform() {
return display_transform_;
}
} // namespace viz
// 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 COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_GL_OUTPUT_SURFACE_CHROMEOS_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_GL_OUTPUT_SURFACE_CHROMEOS_H_
#include "components/viz/service/display_embedder/gl_output_surface.h"
namespace viz {
class GLOutputSurfaceChromeOS : public GLOutputSurface {
public:
GLOutputSurfaceChromeOS(
scoped_refptr<VizProcessContextProvider> context_provider,
gpu::SurfaceHandle surface_handle);
~GLOutputSurfaceChromeOS() override;
// GLOutputSurface:
void SetDisplayTransformHint(gfx::OverlayTransform transform) override;
gfx::OverlayTransform GetDisplayTransform() override;
private:
gfx::OverlayTransform display_transform_ = gfx::OVERLAY_TRANSFORM_NONE;
DISALLOW_COPY_AND_ASSIGN(GLOutputSurfaceChromeOS);
};
} // namespace viz
#endif // COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_GL_OUTPUT_SURFACE_CHROMEOS_H_
......@@ -64,6 +64,7 @@
#endif
#if defined(OS_CHROMEOS)
#include "components/viz/service/display_embedder/gl_output_surface_chromeos.h"
#include "components/viz/service/display_embedder/output_surface_unified.h"
#endif
......@@ -206,6 +207,9 @@ std::unique_ptr<OutputSurface> OutputSurfaceProviderImpl::CreateOutputSurface(
#elif defined(OS_ANDROID)
output_surface = std::make_unique<GLOutputSurfaceAndroid>(
std::move(context_provider), surface_handle);
#elif defined(OS_CHROMEOS)
output_surface = std::make_unique<GLOutputSurfaceChromeOS>(
std::move(context_provider), surface_handle);
#else
output_surface = std::make_unique<GLOutputSurface>(
std::move(context_provider), surface_handle);
......
......@@ -202,6 +202,15 @@ unsigned GpuBrowserCompositorOutputSurface::UpdateGpuFence() {
return 0;
}
void GpuBrowserCompositorOutputSurface::SetDisplayTransformHint(
gfx::OverlayTransform transform) {
display_transform_ = transform;
}
gfx::OverlayTransform GpuBrowserCompositorOutputSurface::GetDisplayTransform() {
return display_transform_;
}
gpu::SurfaceHandle GpuBrowserCompositorOutputSurface::GetSurfaceHandle() const {
return surface_handle_;
}
......
......@@ -65,6 +65,8 @@ class GpuBrowserCompositorOutputSurface
unsigned GetOverlayTextureId() const override;
gfx::BufferFormat GetOverlayBufferFormat() const override;
unsigned UpdateGpuFence() override;
void SetDisplayTransformHint(gfx::OverlayTransform transform) override;
gfx::OverlayTransform GetDisplayTransform() override;
void SetDrawRectangle(const gfx::Rect& rect) override;
......@@ -87,6 +89,7 @@ class GpuBrowserCompositorOutputSurface
private:
const gpu::SurfaceHandle surface_handle_;
gfx::OverlayTransform display_transform_ = gfx::OVERLAY_TRANSFORM_NONE;
base::WeakPtrFactory<GpuBrowserCompositorOutputSurface> weak_ptr_factory_{
this};
......
......@@ -487,6 +487,7 @@ void GpuProcessTransportFactory::EstablishedGpuChannel(
features::IsVizHitTestingSurfaceLayerEnabled());
data->display->Resize(compositor->size());
data->display->SetOutputIsSecure(data->output_is_secure);
data->display->SetDisplayTransformHint(compositor->display_transform());
compositor->SetLayerTreeFrameSink(std::move(layer_tree_frame_sink));
}
......@@ -744,6 +745,18 @@ void GpuProcessTransportFactory::AddVSyncParameterObserver(
std::make_unique<viz::VSyncParameterListener>(std::move(observer));
}
void GpuProcessTransportFactory::SetDisplayTransformHint(
ui::Compositor* compositor,
gfx::OverlayTransform transform) {
auto it = per_compositor_data_.find(compositor);
if (it == per_compositor_data_.end())
return;
PerCompositorData* data = it->second.get();
DCHECK(data);
if (data->display)
data->display->SetDisplayTransformHint(transform);
}
void GpuProcessTransportFactory::AddObserver(
ui::ContextFactoryObserver* observer) {
observer_list_.AddObserver(observer);
......
......@@ -106,6 +106,8 @@ class GpuProcessTransportFactory : public ui::ContextFactory,
void AddVSyncParameterObserver(
ui::Compositor* compositor,
viz::mojom::VSyncParameterObserverPtr observer) override;
void SetDisplayTransformHint(ui::Compositor* compositor,
gfx::OverlayTransform transform) override;
// ImageTransportFactory implementation.
void DisableGpuCompositing() override;
......
......@@ -85,6 +85,8 @@ class TestImageTransportFactory : public ui::ContextFactory,
void AddVSyncParameterObserver(
ui::Compositor* compositor,
viz::mojom::VSyncParameterObserverPtr observer) override {}
void SetDisplayTransformHint(ui::Compositor* compositor,
gfx::OverlayTransform transform) override {}
// ImageTransportFactory implementation.
void DisableGpuCompositing() override;
......
......@@ -38,6 +38,7 @@
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/icc_profile.h"
#include "ui/gfx/overlay_transform_utils.h"
#include "ui/gfx/switches.h"
#include "ui/platform_window/platform_window_init_properties.h"
......@@ -160,6 +161,14 @@ gfx::Transform WindowTreeHost::GetInverseRootTransform() const {
return invert;
}
void WindowTreeHost::SetDisplayTransformHint(gfx::OverlayTransform transform) {
if (compositor()->display_transform() == transform)
return;
compositor()->SetDisplayTransformHint(transform);
UpdateCompositorScaleAndSize();
}
gfx::Transform WindowTreeHost::GetRootTransformForLocalEventCoordinates()
const {
return GetRootTransform();
......@@ -184,6 +193,20 @@ void WindowTreeHost::UpdateRootWindowSizeInPixels() {
window()->SetBounds(transformed_bounds_in_pixels);
}
void WindowTreeHost::UpdateCompositorScaleAndSize() {
gfx::Rect new_bounds = GetBoundsInPixels();
if (compositor_->display_transform() == gfx::OVERLAY_TRANSFORM_ROTATE_90 ||
compositor_->display_transform() == gfx::OVERLAY_TRANSFORM_ROTATE_270) {
new_bounds.Transpose();
}
// Allocate a new LocalSurfaceId for the new size or scale factor.
window_->AllocateLocalSurfaceId();
ScopedLocalSurfaceIdValidator lsi_validator(window());
compositor_->SetScaleAndSize(device_scale_factor_, new_bounds.size(),
window_->GetLocalSurfaceIdAllocation());
}
void WindowTreeHost::ConvertDIPToScreenInPixels(gfx::Point* point) const {
ConvertDIPToPixels(point);
gfx::Point location = GetLocationOnScreenInPixels();
......@@ -457,16 +480,12 @@ void WindowTreeHost::OnHostResizedInPixels(
// these two.
if (!compositor_)
return;
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window());
device_scale_factor_ = display.device_scale_factor();
UpdateRootWindowSizeInPixels();
// Allocate a new LocalSurfaceId for the new state.
window_->AllocateLocalSurfaceId();
ScopedLocalSurfaceIdValidator lsi_validator(window());
compositor_->SetScaleAndSize(device_scale_factor_, new_size_in_pixels,
window_->GetLocalSurfaceIdAllocation());
UpdateCompositorScaleAndSize();
for (WindowTreeHostObserver& observer : observers_)
observer.OnHostResized(this);
......
......@@ -28,6 +28,7 @@
#include "ui/events/event_source.h"
#include "ui/events/platform_event.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/overlay_transform.h"
namespace gfx {
class Point;
......@@ -100,6 +101,8 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate,
virtual void SetRootTransform(const gfx::Transform& transform);
virtual gfx::Transform GetInverseRootTransform() const;
void SetDisplayTransformHint(gfx::OverlayTransform transform);
// These functions are used in event translation for translating the local
// coordinates of LocatedEvents. Default implementation calls to non-local
// ones (e.g. GetRootTransform()).
......@@ -114,6 +117,10 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate,
// allows for inconsistencies.
void UpdateRootWindowSizeInPixels();
// Updates the compositor's size and scale from display size, scale and
// transform hint.
void UpdateCompositorScaleAndSize();
// Converts |point| from the root window's coordinate system to native
// screen's.
void ConvertDIPToScreenInPixels(gfx::Point* point) const;
......
......@@ -447,6 +447,14 @@ void Compositor::SetDisplayColorSpace(const gfx::ColorSpace& color_space,
}
}
void Compositor::SetDisplayTransformHint(gfx::OverlayTransform transform) {
if (display_transform_ == transform)
return;
display_transform_ = transform;
context_factory_private_->SetDisplayTransformHint(this, display_transform_);
}
void Compositor::SetBackgroundColor(SkColor color) {
host_->set_background_color(color);
......
......@@ -37,6 +37,7 @@
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/overlay_transform.h"
namespace base {
class SingleThreadTaskRunner;
......@@ -156,6 +157,11 @@ class COMPOSITOR_EXPORT ContextFactoryPrivate {
virtual void AddVSyncParameterObserver(
Compositor* compositor,
viz::mojom::VSyncParameterObserverPtr observer) = 0;
// Set the transform/rotation info for the display output surface that this
// compositor represents.
virtual void SetDisplayTransformHint(Compositor* compositor,
gfx::OverlayTransform transform) = 0;
};
// This class abstracts the creation of the 3D context for the compositor. It is
......@@ -290,6 +296,10 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient,
const gfx::ColorSpace& color_space,
float sdr_white_level = gfx::ColorSpace::kDefaultSDRWhiteLevel);
// Set the transform/rotation info for the display output surface.
void SetDisplayTransformHint(gfx::OverlayTransform transform);
gfx::OverlayTransform display_transform() const { return display_transform_; }
// Returns the size of the widget that is being drawn to in pixel coordinates.
const gfx::Size& size() const { return size_; }
......@@ -513,6 +523,8 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient,
const char* trace_environment_name_;
gfx::OverlayTransform display_transform_ = gfx::OVERLAY_TRANSFORM_NONE;
base::WeakPtrFactory<Compositor> context_creation_weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(Compositor);
......
......@@ -143,6 +143,8 @@ void HostContextFactoryPrivate::ConfigureCompositor(
compositor_data.display_private->Resize(compositor->size());
compositor_data.display_private->SetOutputIsSecure(
compositor_data.output_is_secure);
compositor_data.display_private->SetDisplayTransformHint(
compositor->display_transform());
// Create LayerTreeFrameSink with the browser end of CompositorFrameSink.
cc::mojo_embedder::AsyncLayerTreeFrameSink::InitParams params;
......@@ -313,6 +315,17 @@ void HostContextFactoryPrivate::AddVSyncParameterObserver(
}
}
void HostContextFactoryPrivate::SetDisplayTransformHint(
Compositor* compositor,
gfx::OverlayTransform transform) {
auto iter = compositor_data_map_.find(compositor);
if (iter == compositor_data_map_.end())
return;
if (iter->second.display_private)
iter->second.display_private->SetDisplayTransformHint(transform);
}
HostContextFactoryPrivate::CompositorData::CompositorData() = default;
HostContextFactoryPrivate::CompositorData::CompositorData(
CompositorData&& other) = default;
......
......@@ -90,6 +90,8 @@ class HostContextFactoryPrivate : public ContextFactoryPrivate {
void AddVSyncParameterObserver(
Compositor* compositor,
viz::mojom::VSyncParameterObserverPtr observer) override;
void SetDisplayTransformHint(Compositor* compositor,
gfx::OverlayTransform transform) override;
private:
struct CompositorData {
......
......@@ -99,6 +99,8 @@ class InProcessContextFactory : public ContextFactory,
void AddVSyncParameterObserver(
ui::Compositor* compositor,
viz::mojom::VSyncParameterObserverPtr observer) override {}
void SetDisplayTransformHint(Compositor* compositor,
gfx::OverlayTransform transform) override {}
void AddObserver(ContextFactoryObserver* observer) override;
void RemoveObserver(ContextFactoryObserver* observer) override;
bool SyncTokensRequiredForDisplayCompositor() override;
......
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