Commit 6da27479 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

viz/mac: Plumb surface synchronization and local surface ids

Set local surface id based on resize in BrowserCompositorMac.

Bug: 772576
Change-Id: I212c9bd4c694e6300345bb7c83a7a22c73c7ce97
Reviewed-on: https://chromium-review.googlesource.com/830822
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarFady Samuel <fsamuel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524513}
parent 3e7fa0cf
......@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/common/surfaces/local_surface_id.h"
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "content/browser/renderer_host/delegated_frame_host.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_observer.h"
......@@ -26,7 +27,6 @@ class BrowserCompositorMacClient {
public:
virtual SkColor BrowserCompositorMacGetGutterColor(SkColor color) const = 0;
virtual void BrowserCompositorMacOnBeginFrame() = 0;
virtual viz::LocalSurfaceId GetLocalSurfaceId() const = 0;
virtual void OnFrameTokenChanged(uint32_t frame_token) = 0;
};
......@@ -178,6 +178,8 @@ class CONTENT_EXPORT BrowserCompositorMac : public DelegatedFrameHostClient {
const bool enable_viz_ = false;
viz::mojom::CompositorFrameSinkClient* renderer_compositor_frame_sink_ =
nullptr;
viz::LocalSurfaceId compositor_surface_id_;
viz::ParentLocalSurfaceIdAllocator parent_local_surface_id_allocator_;
base::WeakPtrFactory<BrowserCompositorMac> weak_factory_;
};
......
......@@ -12,6 +12,7 @@
#include "base/containers/circular_deque.h"
#include "base/lazy_instance.h"
#include "base/trace_event/trace_event.h"
#include "components/viz/common/features.h"
#include "components/viz/common/switches.h"
#include "content/browser/compositor/image_transport_factory.h"
#include "content/browser/renderer_host/compositor_resize_lock.h"
......@@ -109,7 +110,7 @@ RecyclableCompositorMac::RecyclableCompositorMac()
content::GetContextFactory(),
content::GetContextFactoryPrivate(),
ui::WindowResizeHelperMac::Get()->task_runner(),
false /* enable_surface_synchronization */,
features::IsSurfaceSynchronizationEnabled(),
false /* enable_pixel_canvas */) {
compositor_.SetAcceleratedWidget(
accelerated_widget_mac_->accelerated_widget());
......@@ -188,9 +189,8 @@ BrowserCompositorMac::BrowserCompositorMac(
g_browser_compositor_count += 1;
root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
// TODO(fsamuel): Plumb surface synchronization settings.
delegated_frame_host_.reset(new DelegatedFrameHost(
frame_sink_id, this, false /* enable_surface_synchronization */,
frame_sink_id, this, features::IsSurfaceSynchronizationEnabled(),
enable_viz_));
SetRenderWidgetHostIsHidden(render_widget_host_is_hidden);
......@@ -342,14 +342,24 @@ void BrowserCompositorMac::WasResized() {
// In non-viz, the ui::Compositor is resized in sync with frames coming from
// the renderer. In viz, the ui::Compositor can only resize in sync with the
// NSView.
if (enable_viz_ && recyclable_compositor_) {
if (!enable_viz_ || !recyclable_compositor_)
return;
gfx::Size dip_size;
float scale_factor = 1.f;
GetViewProperties(&dip_size, &scale_factor, nullptr);
gfx::Size pixel_size = gfx::ConvertSizeToPixel(scale_factor, dip_size);
recyclable_compositor_->compositor()->SetScaleAndSize(scale_factor,
pixel_size);
}
gfx::Size old_pixel_size = recyclable_compositor_->compositor()->size();
float old_scale_factor =
recyclable_compositor_->compositor()->device_scale_factor();
if (pixel_size == old_pixel_size && scale_factor == old_scale_factor)
return;
compositor_surface_id_ = parent_local_surface_id_allocator_.GenerateId();
recyclable_compositor_->compositor()->SetScaleAndSize(
scale_factor, pixel_size, compositor_surface_id_);
}
bool BrowserCompositorMac::HasFrameOfSize(const gfx::Size& desired_size) {
......@@ -499,7 +509,7 @@ bool BrowserCompositorMac::DelegatedFrameCanCreateResizeLock() const {
}
viz::LocalSurfaceId BrowserCompositorMac::GetLocalSurfaceId() const {
return client_->GetLocalSurfaceId();
return compositor_surface_id_;
}
std::unique_ptr<CompositorResizeLock>
......
......@@ -22,8 +22,6 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "components/viz/common/surfaces/local_surface_id.h"
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "components/viz/common/surfaces/surface_id.h"
#include "content/browser/renderer_host/browser_compositor_view_mac.h"
#include "content/browser/renderer_host/input/mouse_wheel_phase_handler.h"
......@@ -500,7 +498,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
// BrowserCompositorMacClient implementation.
SkColor BrowserCompositorMacGetGutterColor(SkColor color) const override;
void BrowserCompositorMacOnBeginFrame() override;
viz::LocalSurfaceId GetLocalSurfaceId() const override;
void OnFrameTokenChanged(uint32_t frame_token) override;
// AcceleratedWidgetMacNSView implementation.
......@@ -626,9 +623,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
std::unique_ptr<CursorManager> cursor_manager_;
// The size associated with the current LocalSurfaceId if any.
gfx::Size last_size_;
enum class RepaintState {
// No repaint in progress.
None,
......@@ -640,13 +634,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
ScreenUpdatesDisabled,
} repaint_state_ = RepaintState::None;
// The last device scale factor associated with the current
// LocalSurfaceId if any.
float last_device_scale_factor_ = 0.f;
viz::LocalSurfaceId local_surface_id_;
viz::ParentLocalSurfaceIdAllocator parent_local_surface_id_allocator_;
// Factory used to safely scope delayed calls to ShutdownHost().
base::WeakPtrFactory<RenderWidgetHostViewMac> weak_factory_;
......
......@@ -396,10 +396,6 @@ void RenderWidgetHostViewMac::BrowserCompositorMacOnBeginFrame() {
UpdateNeedsBeginFramesInternal();
}
viz::LocalSurfaceId RenderWidgetHostViewMac::GetLocalSurfaceId() const {
return local_surface_id_;
}
void RenderWidgetHostViewMac::OnFrameTokenChanged(uint32_t frame_token) {
OnFrameTokenChangedForView(frame_token);
}
......@@ -456,7 +452,6 @@ RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget,
viz::FrameSinkId frame_sink_id =
render_widget_host_->AllocateFrameSinkId(is_guest_view_hack_);
local_surface_id_ = parent_local_surface_id_allocator_.GenerateId();
browser_compositor_.reset(
new BrowserCompositorMac(this, this, render_widget_host_->is_hidden(),
[cocoa_view_ window], frame_sink_id));
......@@ -797,11 +792,6 @@ void RenderWidgetHostViewMac::SetBounds(const gfx::Rect& rect) {
if (rect.size().IsEmpty())
return;
if (rect.size() != last_size_) {
local_surface_id_ = parent_local_surface_id_allocator_.GenerateId();
last_size_ = rect.size();
}
// Ignore the position of |rect| for non-popup rwhvs. This is because
// background tabs do not have a window, but the window is required for the
// coordinate conversions. Popups are always for a visible tab.
......@@ -1102,7 +1092,6 @@ void RenderWidgetHostViewMac::UpdateScreenInfo(gfx::NativeView view) {
if (!render_widget_host_ || !render_widget_host_->auto_resize_enabled())
return;
local_surface_id_ = parent_local_surface_id_allocator_.GenerateId();
render_widget_host_->DidAllocateLocalSurfaceIdForAutoResize(
render_widget_host_->last_auto_resize_request_number());
browser_compositor_->WasResized();
......@@ -1786,10 +1775,6 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged(
return;
if (changed_metrics & DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR) {
if (display.device_scale_factor() != last_device_scale_factor_) {
local_surface_id_ = parent_local_surface_id_allocator_.GenerateId();
last_device_scale_factor_ = display.device_scale_factor();
}
RenderWidgetHostImpl* host =
RenderWidgetHostImpl::From(GetRenderWidgetHost());
if (host) {
......
include_rules = [
"+components/viz/common",
"+ui/accelerated_widget_mac",
]
......@@ -15,6 +15,7 @@
#include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/viz/common/features.h"
#include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
#import "ui/base/cocoa/constrained_window/constrained_window_animation.h"
#include "ui/base/hit_test.h"
......@@ -1402,7 +1403,7 @@ void BridgedNativeWidget::CreateCompositor() {
compositor_.reset(new ui::Compositor(
context_factory_private->AllocateFrameSinkId(), context_factory,
context_factory_private, GetCompositorTaskRunner(),
false /* enable_surface_synchronization */,
features::IsSurfaceSynchronizationEnabled(),
ui::IsPixelCanvasRecordingEnabled()));
compositor_->SetAcceleratedWidget(compositor_widget_->accelerated_widget());
compositor_widget_->SetNSView(this);
......
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