From 0fb03e7aa14513b47f36a28f41ba4cbff20bb1ee Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 25 Jul 2018 16:55:11 -0400 Subject: [PATCH] macOS: Fix OSR configuration of device scale factor --- .../browser/osr/render_widget_host_view_osr.h | 8 +++ .../osr/render_widget_host_view_osr_mac.mm | 49 +++++++++++++++---- tests/ceftests/os_rendering_unittest.cc | 10 +--- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/libcef/browser/osr/render_widget_host_view_osr.h b/libcef/browser/osr/render_widget_host_view_osr.h index b932714fd..64f7c5c38 100644 --- a/libcef/browser/osr/render_widget_host_view_osr.h +++ b/libcef/browser/osr/render_widget_host_view_osr.h @@ -156,6 +156,10 @@ class CefRenderWidgetHostViewOSR : public content::RenderWidgetHostViewBase, void GetScreenInfo(content::ScreenInfo* results) const override; void TransformPointToRootSurface(gfx::PointF* point) override; gfx::Rect GetBoundsInRootWindow() override; +#if defined(OS_MACOSX) + viz::ScopedSurfaceIdAllocator DidUpdateVisualProperties( + const cc::RenderFrameMetadata& metadata) override; +#endif viz::SurfaceId GetCurrentSurfaceId() const override; content::BrowserAccessibilityManager* CreateBrowserAccessibilityManager( content::BrowserAccessibilityDelegate* delegate, @@ -297,6 +301,10 @@ class CefRenderWidgetHostViewOSR : public content::RenderWidgetHostViewBase, void UpdateBackgroundColorFromRenderer(SkColor color); #if defined(OS_MACOSX) + display::Display GetDisplay(); + void OnDidUpdateVisualPropertiesComplete( + const cc::RenderFrameMetadata& metadata); + friend class MacHelper; bool UpdateNSViewAndDisplay(); #endif // defined(OS_MACOSX) diff --git a/libcef/browser/osr/render_widget_host_view_osr_mac.mm b/libcef/browser/osr/render_widget_host_view_osr_mac.mm index c1d65e576..8a97387c1 100644 --- a/libcef/browser/osr/render_widget_host_view_osr_mac.mm +++ b/libcef/browser/osr/render_widget_host_view_osr_mac.mm @@ -19,15 +19,6 @@ #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" #include "ui/display/screen.h" -namespace { - -display::Display GetDisplay() { - // TODO(cef): Get display info from callbacks. - return display::Screen::GetScreen()->GetDisplayNearestView(nullptr); -} - -} // namespace - class MacHelper : public content::BrowserCompositorMacClient, public ui::AcceleratedWidgetMacNSView { public: @@ -100,6 +91,46 @@ bool CefRenderWidgetHostViewOSR::ShouldContinueToPauseForFrame() { return browser_compositor_->ShouldContinueToPauseForFrame(); } +viz::ScopedSurfaceIdAllocator +CefRenderWidgetHostViewOSR::DidUpdateVisualProperties( + const cc::RenderFrameMetadata& metadata) { + base::OnceCallback allocation_task = base::BindOnce( + base::IgnoreResult( + &CefRenderWidgetHostViewOSR::OnDidUpdateVisualPropertiesComplete), + weak_ptr_factory_.GetWeakPtr(), metadata); + return browser_compositor_->GetScopedRendererSurfaceIdAllocator( + std::move(allocation_task)); +} + +display::Display CefRenderWidgetHostViewOSR::GetDisplay() { + content::ScreenInfo screen_info; + GetScreenInfo(&screen_info); + + // Start with a reasonable display representation. + display::Display display = + display::Screen::GetScreen()->GetDisplayNearestView(nullptr); + + // Populate attributes based on |screen_info|. + display.set_bounds(screen_info.rect); + display.set_work_area(screen_info.available_rect); + display.set_device_scale_factor(screen_info.device_scale_factor); + display.set_color_space(screen_info.color_space); + display.set_color_depth(screen_info.depth); + display.set_depth_per_component(screen_info.depth_per_component); + display.set_is_monochrome(screen_info.is_monochrome); + display.SetRotationAsDegree(screen_info.orientation_angle); + + return display; +} + +void CefRenderWidgetHostViewOSR::OnDidUpdateVisualPropertiesComplete( + const cc::RenderFrameMetadata& metadata) { + DCHECK_EQ(current_device_scale_factor_, metadata.device_scale_factor); + browser_compositor_->SynchronizeVisualProperties( + metadata.device_scale_factor, metadata.viewport_size_in_pixels, + metadata.local_surface_id.value_or(viz::LocalSurfaceId())); +} + const viz::LocalSurfaceId& CefRenderWidgetHostViewOSR::GetLocalSurfaceId() const { return browser_compositor_->GetRendererLocalSurfaceId(); diff --git a/tests/ceftests/os_rendering_unittest.cc b/tests/ceftests/os_rendering_unittest.cc index 37be618f6..e7ba14b74 100644 --- a/tests/ceftests/os_rendering_unittest.cc +++ b/tests/ceftests/os_rendering_unittest.cc @@ -452,11 +452,7 @@ class OSRTestHandler : public RoutingTestHandler, EXPECT_EQ(dirtyRects.size(), 1U); EXPECT_TRUE(IsFullRepaint(dirtyRects[0], GetScaledInt(kOsrWidth), GetScaledInt(kOsrHeight))); -#if defined(OS_MACOSX) - EXPECT_EQ(0xfffd8081U, *(reinterpret_cast(buffer))); -#else EXPECT_EQ(0xffff7f7fU, *(reinterpret_cast(buffer))); -#endif DestroySucceededTestSoon(); } break; @@ -466,11 +462,7 @@ class OSRTestHandler : public RoutingTestHandler, EXPECT_EQ(dirtyRects.size(), 1U); EXPECT_TRUE(IsFullRepaint(dirtyRects[0], GetScaledInt(kOsrWidth), GetScaledInt(kOsrHeight))); -#if defined(OS_MACOSX) - EXPECT_EQ(0x807F070EU, *(reinterpret_cast(buffer))); -#else EXPECT_EQ(0x80800000U, *(reinterpret_cast(buffer))); -#endif DestroySucceededTestSoon(); } break; @@ -715,7 +707,7 @@ class OSRTestHandler : public RoutingTestHandler, // first pixel of border #if defined(OS_MACOSX) - EXPECT_EQ(0xff609ad4U, *(reinterpret_cast(buffer))); + EXPECT_EQ(0xff5d99d6U, *(reinterpret_cast(buffer))); #else EXPECT_EQ(0xff6497eaU, *(reinterpret_cast(buffer))); #endif