Commit 40b2fccf authored by fsamuel's avatar fsamuel Committed by Commit bot

RenderWidgetCompositor should be decoupled from RenderWidget.

This is a mechanical refactor of RenderWidgetCompositor and
RenderWidget. At this point it removes references for
routing ID, and RenderWidget from RenderWidgetCompositor's
implementation. This is likely not the final refactor as I
am still in the process of detangling WebWidgetClient's
implementation from RenderWidget. Once that happens, I
might have some simplifications.

BUG=577321

Review URL: https://codereview.chromium.org/1587743002

Cr-Commit-Position: refs/heads/master@{#369383}
parent aadf6d08
......@@ -215,6 +215,7 @@
'renderer/gpu/queue_message_swap_promise.h',
'renderer/gpu/render_widget_compositor.cc',
'renderer/gpu/render_widget_compositor.h',
'renderer/gpu/render_widget_compositor_delegate.h',
'renderer/gpu/stream_texture_host_android.cc',
'renderer/gpu/stream_texture_host_android.h',
'renderer/history_controller.cc',
......
......@@ -45,6 +45,7 @@
#include "content/common/content_switches_internal.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
#include "content/public/common/content_switches.h"
#include "content/renderer/gpu/render_widget_compositor_delegate.h"
#include "content/renderer/input/input_handler_manager.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "gpu/command_buffer/service/gpu_switches.h"
......@@ -54,7 +55,6 @@
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "third_party/WebKit/public/web/WebSelection.h"
#include "third_party/WebKit/public/web/WebWidget.h"
#include "ui/gl/gl_switches.h"
#include "ui/native_theme/native_theme_switches.h"
......@@ -135,7 +135,7 @@ cc::LayerSelection ConvertWebSelection(const WebSelection& web_selection) {
return cc_selection;
}
gfx::Size CalculateDefaultTileSize(RenderWidget* widget) {
gfx::Size CalculateDefaultTileSize(float initial_device_scale_factor) {
int default_tile_size = 256;
#if defined(OS_ANDROID)
// TODO(epenner): unify this for all platforms if it
......@@ -180,7 +180,7 @@ gfx::Size CalculateDefaultTileSize(RenderWidget* widget) {
}
#elif defined(OS_CHROMEOS)
// Use 512 for high DPI (dsf=2.0f) devices.
if (widget->screen_info().deviceScaleFactor >= 2.0f)
if (initial_device_scale_factor >= 2.0f)
default_tile_size = 512;
#endif
......@@ -205,27 +205,27 @@ static cc::TopControlsState ConvertTopControlsState(
// static
scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create(
RenderWidget* widget,
RenderWidgetCompositorDelegate* delegate,
float device_scale_factor,
CompositorDependencies* compositor_deps) {
scoped_ptr<RenderWidgetCompositor> compositor(
new RenderWidgetCompositor(widget, compositor_deps));
compositor->Initialize();
new RenderWidgetCompositor(delegate, compositor_deps));
compositor->Initialize(device_scale_factor);
return compositor;
}
RenderWidgetCompositor::RenderWidgetCompositor(
RenderWidget* widget,
RenderWidgetCompositorDelegate* delegate,
CompositorDependencies* compositor_deps)
: num_failed_recreate_attempts_(0),
widget_(widget),
delegate_(delegate),
compositor_deps_(compositor_deps),
never_visible_(false),
layout_and_paint_async_callback_(nullptr),
remote_proto_channel_receiver_(nullptr),
weak_factory_(this) {
}
weak_factory_(this) {}
void RenderWidgetCompositor::Initialize() {
void RenderWidgetCompositor::Initialize(float device_scale_factor) {
base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
cc::LayerTreeSettings settings;
......@@ -257,7 +257,7 @@ void RenderWidgetCompositor::Initialize() {
blink::WebRuntimeFeatures::enableCompositorAnimationTimelines(
settings.use_compositor_animation_timelines);
settings.default_tile_size = CalculateDefaultTileSize(widget_);
settings.default_tile_size = CalculateDefaultTileSize(device_scale_factor);
if (cmd->HasSwitch(switches::kDefaultTileWidth)) {
int tile_width = 0;
GetSwitchValueAsInt(*cmd,
......@@ -456,7 +456,7 @@ void RenderWidgetCompositor::Initialize() {
settings.renderer_settings.use_rgba_4444_textures &=
!cmd->HasSwitch(switches::kDisableRGBA4444Textures);
if (widget_->for_oopif()) {
if (delegate_->ForOOPIF()) {
// TODO(simonhong): Apply BeginFrame scheduling for OOPIF.
// See crbug.com/471411.
settings.use_external_begin_frame_source = false;
......@@ -489,8 +489,7 @@ void RenderWidgetCompositor::Initialize() {
scoped_ptr<cc::BeginFrameSource> external_begin_frame_source;
if (settings.use_external_begin_frame_source) {
external_begin_frame_source =
compositor_deps_->CreateExternalBeginFrameSource(widget_->routing_id());
external_begin_frame_source = delegate_->CreateExternalBeginFrameSource();
}
cc::LayerTreeHost::InitParams params;
......@@ -865,7 +864,7 @@ void RenderWidgetCompositor::setTopControlsShownRatio(float ratio) {
}
void RenderWidgetCompositor::WillBeginMainFrame() {
widget_->WillBeginCompositorFrame();
delegate_->WillBeginCompositorFrame();
}
void RenderWidgetCompositor::DidBeginMainFrame() {
......@@ -874,7 +873,7 @@ void RenderWidgetCompositor::DidBeginMainFrame() {
void RenderWidgetCompositor::BeginMainFrame(const cc::BeginFrameArgs& args) {
compositor_deps_->GetRendererScheduler()->WillBeginFrame(args);
double frame_time_sec = (args.frame_time - base::TimeTicks()).InSecondsF();
widget_->webwidget()->beginFrame(frame_time_sec);
delegate_->BeginMainFrame(frame_time_sec);
}
void RenderWidgetCompositor::BeginMainFrameNotExpectedSoon() {
......@@ -882,8 +881,7 @@ void RenderWidgetCompositor::BeginMainFrameNotExpectedSoon() {
}
void RenderWidgetCompositor::UpdateLayerTreeHost() {
widget_->webwidget()->updateAllLifecyclePhases();
delegate_->UpdateVisualState();
if (temporary_copy_output_request_) {
// For WebViewImpl, this will always have a root layer. For other widgets,
// the widget may be closed before servicing this request, so ignore it.
......@@ -903,24 +901,16 @@ void RenderWidgetCompositor::ApplyViewportDeltas(
const gfx::Vector2dF& elastic_overscroll_delta,
float page_scale,
float top_controls_delta) {
widget_->webwidget()->applyViewportDeltas(
inner_delta,
outer_delta,
elastic_overscroll_delta,
page_scale,
top_controls_delta);
delegate_->ApplyViewportDeltas(inner_delta, outer_delta,
elastic_overscroll_delta, page_scale,
top_controls_delta);
}
void RenderWidgetCompositor::RequestNewOutputSurface() {
// If the host is closing, then no more compositing is possible. This
// prevents shutdown races between handling the close message and
// the CreateOutputSurface task.
if (widget_->host_closing())
return;
bool fallback =
num_failed_recreate_attempts_ >= OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK;
scoped_ptr<cc::OutputSurface> surface(widget_->CreateOutputSurface(fallback));
scoped_ptr<cc::OutputSurface> surface(
delegate_->CreateOutputSurface(fallback));
if (!surface) {
DidFailToInitializeOutputSurface();
......@@ -954,35 +944,35 @@ void RenderWidgetCompositor::WillCommit() {
void RenderWidgetCompositor::DidCommit() {
DCHECK(!temporary_copy_output_request_);
widget_->DidCommitCompositorFrame();
delegate_->DidCommitCompositorFrame();
compositor_deps_->GetRendererScheduler()->DidCommitFrameToCompositor();
}
void RenderWidgetCompositor::DidCommitAndDrawFrame() {
widget_->DidCommitAndDrawCompositorFrame();
delegate_->DidCommitAndDrawCompositorFrame();
}
void RenderWidgetCompositor::DidCompleteSwapBuffers() {
widget_->DidCompleteSwapBuffers();
delegate_->DidCompleteSwapBuffers();
bool threaded = !!compositor_deps_->GetCompositorImplThreadTaskRunner().get();
if (!threaded)
widget_->OnSwapBuffersComplete();
delegate_->OnSwapBuffersComplete();
}
void RenderWidgetCompositor::DidCompletePageScaleAnimation() {
widget_->DidCompletePageScaleAnimation();
delegate_->DidCompletePageScaleAnimation();
}
void RenderWidgetCompositor::ScheduleAnimation() {
widget_->scheduleAnimation();
delegate_->ScheduleAnimation();
}
void RenderWidgetCompositor::DidPostSwapBuffers() {
widget_->OnSwapBuffersPosted();
delegate_->OnSwapBuffersPosted();
}
void RenderWidgetCompositor::DidAbortSwapBuffers() {
widget_->OnSwapBuffersAborted();
delegate_->OnSwapBuffersAborted();
}
void RenderWidgetCompositor::SetProtoReceiver(ProtoReceiver* receiver) {
......@@ -995,39 +985,14 @@ void RenderWidgetCompositor::SendCompositorProto(
size_t unsigned_size = base::checked_cast<size_t>(signed_size);
std::vector<uint8_t> serialized(unsigned_size);
proto.SerializeToArray(serialized.data(), signed_size);
widget_->ForwardCompositorProto(serialized);
delegate_->ForwardCompositorProto(serialized);
}
void RenderWidgetCompositor::RecordFrameTimingEvents(
scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
for (const auto& composite_event : *composite_events ) {
int64_t frameId = composite_event.first;
const std::vector<cc::FrameTimingTracker::CompositeTimingEvent>& events =
composite_event.second;
std::vector<blink::WebFrameTimingEvent> webEvents;
for (size_t i = 0; i < events.size(); ++i) {
webEvents.push_back(blink::WebFrameTimingEvent(
events[i].frame_id,
(events[i].timestamp - base::TimeTicks()).InSecondsF()));
}
widget_->webwidget()->recordFrameTimingEvent(
blink::WebWidget::CompositeEvent, frameId, webEvents);
}
for (const auto& main_frame_event : *main_frame_events ) {
int64_t frameId = main_frame_event.first;
const std::vector<cc::FrameTimingTracker::MainFrameTimingEvent>& events =
main_frame_event.second;
std::vector<blink::WebFrameTimingEvent> webEvents;
for (size_t i = 0; i < events.size(); ++i) {
webEvents.push_back(blink::WebFrameTimingEvent(
events[i].frame_id,
(events[i].timestamp - base::TimeTicks()).InSecondsF(),
(events[i].end_time - base::TimeTicks()).InSecondsF()));
}
widget_->webwidget()->recordFrameTimingEvent(
blink::WebWidget::RenderEvent, frameId, webEvents);
}
delegate_->RecordFrameTimingEvents(std::move(composite_events),
std::move(main_frame_events));
}
void RenderWidgetCompositor::SetSurfaceIdNamespace(
......
......@@ -42,7 +42,8 @@ class CompositorMessage;
}
namespace content {
class RenderWidget;
class RenderWidgetCompositorDelegate;
class CONTENT_EXPORT RenderWidgetCompositor
: NON_EXPORTED_BASE(public blink::WebLayerTreeView),
......@@ -53,7 +54,8 @@ class CONTENT_EXPORT RenderWidgetCompositor
// Attempt to construct and initialize a compositor instance for the widget
// with the given settings. Returns NULL if initialization fails.
static scoped_ptr<RenderWidgetCompositor> Create(
RenderWidget* widget,
RenderWidgetCompositorDelegate* delegate,
float device_scale_factor,
CompositorDependencies* compositor_deps);
~RenderWidgetCompositor() override;
......@@ -184,10 +186,10 @@ class CONTENT_EXPORT RenderWidgetCompositor
};
protected:
RenderWidgetCompositor(RenderWidget* widget,
RenderWidgetCompositor(RenderWidgetCompositorDelegate* delegate,
CompositorDependencies* compositor_deps);
void Initialize();
void Initialize(float device_scale_factor);
cc::LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); }
private:
......@@ -197,8 +199,8 @@ class CONTENT_EXPORT RenderWidgetCompositor
void SynchronouslyComposite();
int num_failed_recreate_attempts_;
RenderWidget* widget_;
CompositorDependencies* compositor_deps_;
RenderWidgetCompositorDelegate* const delegate_;
CompositorDependencies* const compositor_deps_;
scoped_ptr<cc::LayerTreeHost> layer_tree_host_;
bool never_visible_;
......
// Copyright 2015 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 CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_DELEGATE_H_
#define CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_DELEGATE_H_
#include "cc/debug/frame_timing_tracker.h"
namespace blink {
class WebWidget;
struct WebScreenInfo;
}
namespace cc {
class BeginFrameSource;
class OutputSurface;
}
namespace content {
// Consumers of RenderWidgetCompositor implement this delegate in order to
// transport compositing information across processes.
class CONTENT_EXPORT RenderWidgetCompositorDelegate {
public:
// Report viewport related properties during a commit from the compositor
// thread.
virtual void ApplyViewportDeltas(
const gfx::Vector2dF& inner_delta,
const gfx::Vector2dF& outer_delta,
const gfx::Vector2dF& elastic_overscroll_delta,
float page_scale,
float top_controls_delta) = 0;
// Notifies that the compositor has issed a BeginMainFrame.
virtual void BeginMainFrame(double frame_time_sec) = 0;
// Requests an OutputSurface to render into.
virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) = 0;
// Requests an external BeginFrameSource from the delegate.
virtual scoped_ptr<cc::BeginFrameSource> CreateExternalBeginFrameSource() = 0;
// Notifies that the draw commands for a committed frame have been issued.
virtual void DidCommitAndDrawCompositorFrame() = 0;
// Notifies about a compositor frame commit operation having finished.
virtual void DidCommitCompositorFrame() = 0;
// Called by the compositor when page scale animation completed.
virtual void DidCompletePageScaleAnimation() = 0;
// Notifies that the compositor has posted a swapbuffers operation to the GPU
// process.
virtual void DidCompleteSwapBuffers() = 0;
// TODO(simonhong, fsamuel): Remove this once crbug.com/471411 is resolved.
// Indicates whether this RenderWidgetCompositor is for an out-of-process
// iframe or not.
virtual bool ForOOPIF() const = 0;
// Called by the compositor to forward a proto that represents serialized
// compositor state.
virtual void ForwardCompositorProto(const std::vector<uint8_t>& proto) = 0;
// Called by the compositor in single-threaded mode when a swap is aborted.
virtual void OnSwapBuffersAborted() = 0;
// Called by the compositor in single-threaded mode when a swap completes.
virtual void OnSwapBuffersComplete() = 0;
// Called by the compositor in single-threaded mode when a swap is posted.
virtual void OnSwapBuffersPosted() = 0;
// Called by the compositor to request the delegate to record frame timing.
virtual void RecordFrameTimingEvents(
scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet>
main_frame_events) = 0;
// Requests that the client schedule a composite now, and calculate
// appropriate delay for potential future frame.
virtual void ScheduleAnimation() = 0;
// Requests a visual frame-based update to the state of the delegate if there
// an update available.
virtual void UpdateVisualState() = 0;
// Indicates that the compositor is about to begin a frame. This is primarily
// to signal to flow control mechanisms that a frame is beginning, not to
// perform actual painting work.
virtual void WillBeginCompositorFrame() = 0;
protected:
virtual ~RenderWidgetCompositorDelegate() {}
};
} // namespace content
#endif // CONTENT_RENDERER_GPU_RENDER_WIDGET_COMPOSITOR_DELEGATE_H_
......@@ -62,9 +62,10 @@ class RenderWidgetCompositorTest : public testing::Test {
RenderWidgetCompositorTest()
: compositor_deps_(new FakeCompositorDependencies),
render_widget_(new TestRenderWidget(compositor_deps_.get())),
render_widget_compositor_(
RenderWidgetCompositor::Create(render_widget_.get(),
compositor_deps_.get())) {}
render_widget_compositor_(RenderWidgetCompositor::Create(
render_widget_.get(),
1.f /* initial_device_scale_factor */,
compositor_deps_.get())) {}
~RenderWidgetCompositorTest() override {}
protected:
......@@ -243,7 +244,8 @@ class RenderWidgetCompositorOutputSurfaceTest : public testing::Test {
render_widget_(new RenderWidgetOutputSurface(compositor_deps_.get())) {
render_widget_compositor_.reset(new RenderWidgetCompositorOutputSurface(
render_widget_.get(), compositor_deps_.get()));
render_widget_compositor_->Initialize();
render_widget_compositor_->Initialize(
1.f /* initial_device_scale_factor */);
render_widget_->SetCompositor(render_widget_compositor_.get());
}
......
This diff is collapsed.
......@@ -23,6 +23,7 @@
#include "content/common/cursors/webcursor.h"
#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
#include "content/common/input/synthetic_gesture_params.h"
#include "content/renderer/gpu/render_widget_compositor_delegate.h"
#include "content/renderer/input/render_widget_input_handler.h"
#include "content/renderer/input/render_widget_input_handler_delegate.h"
#include "content/renderer/message_delivery_policy.h"
......@@ -103,6 +104,7 @@ class CONTENT_EXPORT RenderWidget
: public IPC::Listener,
public IPC::Sender,
NON_EXPORTED_BASE(virtual public blink::WebWidgetClient),
public RenderWidgetCompositorDelegate,
public RenderWidgetInputHandlerDelegate,
public base::RefCounted<RenderWidget> {
public:
......@@ -137,7 +139,6 @@ class CONTENT_EXPORT RenderWidget
// Temporary for debugging purposes...
bool closing() const { return closing_; }
bool is_swapped_out() { return is_swapped_out_; }
bool for_oopif() { return for_oopif_; }
bool has_host_context_menu_location() {
return has_host_context_menu_location_;
}
......@@ -168,6 +169,32 @@ class CONTENT_EXPORT RenderWidget
// IPC::Sender
bool Send(IPC::Message* msg) override;
// RenderWidgetCompositorDelegate
void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
const gfx::Vector2dF& outer_delta,
const gfx::Vector2dF& elastic_overscroll_delta,
float page_scale,
float top_controls_delta) override;
void BeginMainFrame(double frame_time_sec) override;
scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) override;
scoped_ptr<cc::BeginFrameSource> CreateExternalBeginFrameSource() override;
void DidCommitAndDrawCompositorFrame() override;
void DidCommitCompositorFrame() override;
void DidCompletePageScaleAnimation() override;
void DidCompleteSwapBuffers() override;
bool ForOOPIF() const override;
void ForwardCompositorProto(const std::vector<uint8_t>& proto) override;
void OnSwapBuffersAborted() override;
void OnSwapBuffersComplete() override;
void OnSwapBuffersPosted() override;
void RecordFrameTimingEvents(
scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events)
override;
void ScheduleAnimation() override;
void UpdateVisualState() override;
void WillBeginCompositorFrame() override;
// RenderWidgetInputHandlerDelegate
void FocusChangeComplete() override;
bool HasTouchEventHandlersAt(const gfx::Point& point) const override;
......@@ -256,8 +283,6 @@ class CONTENT_EXPORT RenderWidget
// we should not send an extra ack (see SendAckForMouseMoveFromDebugger).
void IgnoreAckForMouseMoveFromDebugger();
virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback);
// Callback for use with synthetic gestures (e.g. BeginSmoothScroll).
typedef base::Callback<void()> SyntheticGestureCompletionCallback;
......@@ -286,9 +311,6 @@ class CONTENT_EXPORT RenderWidget
// Returns whether we currently should handle an IME event.
bool ShouldHandleImeEvent();
// Called by the compositor when page scale animation completed.
virtual void DidCompletePageScaleAnimation() {}
// ScreenMetricsEmulator class manages screen emulation inside a render
// widget. This includes resizing, placing view on the screen at desired
// position, changing device scale factor, and scaling down the whole
......@@ -298,37 +320,16 @@ class CONTENT_EXPORT RenderWidget
void SetPopupOriginAdjustmentsForEmulation(ScreenMetricsEmulator* emulator);
gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
// Indicates that the compositor is about to begin a frame. This is primarily
// to signal to flow control mechanisms that a frame is beginning, not to
// perform actual painting work.
void WillBeginCompositorFrame();
// Notifies about a compositor frame commit operation having finished.
virtual void DidCommitCompositorFrame();
// Notifies that the draw commands for a committed frame have been issued.
void DidCommitAndDrawCompositorFrame();
// Notifies that the compositor has posted a swapbuffers operation to the GPU
// process.
void DidCompleteSwapBuffers();
void ScheduleComposite();
void ScheduleCompositeWithForcedRedraw();
// Called by the compositor in single-threaded mode when a swap is posted,
// completes or is aborted.
void OnSwapBuffersPosted();
void OnSwapBuffersComplete();
void OnSwapBuffersAborted();
// Checks if the selection bounds have been changed. If they are changed,
// the new value will be sent to the browser process.
void UpdateSelectionBounds();
// Called by the compositor to forward a proto that represents serialized
// compositor state.
void ForwardCompositorProto(const std::vector<uint8_t>& proto);
virtual void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end);
......@@ -340,8 +341,6 @@ class CONTENT_EXPORT RenderWidget
// handle composition range and composition character bounds.
void UpdateCompositionInfo(bool should_update_range);
bool host_closing() const { return host_closing_; }
protected:
// Friend RefCounted so that the dtor can be non-public. Using this class
// without ref-counting is an error.
......
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