Commit 583eaf66 authored by David Bokan's avatar David Bokan Committed by Commit Bot

[Refactor] Add interface for input->LTHI

This CL adds an interface for the InputHandler implementation to
communicate with the compositor. This CL is a start that mostly just
imposes an interface on the existing structure  of these objects. Future
CLs will continue to refine this into an interface that makes sense for
the compositor to expose. In particular, there are some cases that
definitely shouldn't be part of the compositor interface that require an
"escape hatch" where ThreadedInputHandler currently uses a reference to
the LayerTreeHostImpl:

- cc::Viewport
- The compositor Animation system
- FrameTrackers and metrics
- BrowserControls
- Scrollbar Animations
- Interaction with the PropertyTrees

These will need additional thought and more meaningful changes so will
be done separately.

Bug: 915926
Change-Id: I4bc79478f387614712c0f74bcb3c1355a917f591
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359390Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarXida Chen <xidachen@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801553}
parent 8723a16f
...@@ -12,9 +12,16 @@ namespace viz { ...@@ -12,9 +12,16 @@ namespace viz {
struct BeginFrameArgs; struct BeginFrameArgs;
} }
namespace gfx {
class Vector2dF;
}
namespace cc { namespace cc {
struct CompositorCommitData; struct CompositorCommitData;
class LayerTreeHostImpl;
class LayerTreeSettings;
class ScrollTree;
// This is the interface that LayerTreeHostImpl and the "graphics" side of the // This is the interface that LayerTreeHostImpl and the "graphics" side of the
// compositor uses to talk to the compositor ThreadedInputHandler. This // compositor uses to talk to the compositor ThreadedInputHandler. This
...@@ -71,6 +78,35 @@ class InputDelegateForCompositor { ...@@ -71,6 +78,35 @@ class InputDelegateForCompositor {
virtual bool IsActivelyPrecisionScrolling() const = 0; virtual bool IsActivelyPrecisionScrolling() const = 0;
}; };
// This is the interface that's exposed by the LayerTreeHostImpl to the input
// handler.
class CompositorDelegateForInput {
public:
virtual ScrollTree& GetScrollTree() const = 0;
virtual bool HasAnimatedScrollbars() const = 0;
virtual void SetNeedsCommit() = 0;
virtual void SetNeedsFullViewportRedraw() = 0;
virtual void DidUpdateScrollAnimationCurve() = 0;
virtual void AccumulateScrollDeltaForTracing(const gfx::Vector2dF& delta) = 0;
virtual void DidStartPinchZoom() = 0;
virtual void DidUpdatePinchZoom() = 0;
virtual void DidEndPinchZoom() = 0;
virtual void DidStartScroll() = 0;
virtual void DidMouseLeave() = 0;
virtual bool IsInHighLatencyMode() const = 0;
virtual void WillScrollContent(ElementId element_id) = 0;
virtual void DidScrollContent(ElementId element_id, bool animated) = 0;
virtual float DeviceScaleFactor() const = 0;
virtual float PageScaleFactor() const = 0;
virtual const LayerTreeSettings& GetSettings() const = 0;
// TODO(bokan): Temporary escape hatch for code that hasn't yet been
// converted to use the input<->compositor interface. This will eventually be
// removed.
virtual LayerTreeHostImpl& GetImplDeprecated() = 0;
virtual const LayerTreeHostImpl& GetImplDeprecated() const = 0;
};
} // namespace cc } // namespace cc
#endif // CC_INPUT_COMPOSITOR_INPUT_INTERFACES_H_ #endif // CC_INPUT_COMPOSITOR_INPUT_INTERFACES_H_
This diff is collapsed.
...@@ -31,8 +31,6 @@ class ScrollOffset; ...@@ -31,8 +31,6 @@ class ScrollOffset;
namespace cc { namespace cc {
class LayerImpl; class LayerImpl;
class LayerTreeHostImpl;
class LayerTreeSettings;
class ScrollbarController; class ScrollbarController;
class ScrollElasticityHelper; class ScrollElasticityHelper;
struct ScrollNode; struct ScrollNode;
...@@ -42,7 +40,8 @@ class Viewport; ...@@ -42,7 +40,8 @@ class Viewport;
class CC_EXPORT ThreadedInputHandler : public InputDelegateForCompositor { class CC_EXPORT ThreadedInputHandler : public InputDelegateForCompositor {
public: public:
explicit ThreadedInputHandler(LayerTreeHostImpl* host_impl); explicit ThreadedInputHandler(
CompositorDelegateForInput& compositor_delegate);
~ThreadedInputHandler(); ~ThreadedInputHandler();
// =========== InputHandler "Interface" - will override in a future CL // =========== InputHandler "Interface" - will override in a future CL
...@@ -181,8 +180,6 @@ class CC_EXPORT ThreadedInputHandler : public InputDelegateForCompositor { ...@@ -181,8 +180,6 @@ class CC_EXPORT ThreadedInputHandler : public InputDelegateForCompositor {
LayerTreeImpl& ActiveTree(); LayerTreeImpl& ActiveTree();
LayerTreeImpl& ActiveTree() const; LayerTreeImpl& ActiveTree() const;
const LayerTreeSettings& Settings() const;
bool IsMainThreadScrolling(const InputHandler::ScrollStatus& status, bool IsMainThreadScrolling(const InputHandler::ScrollStatus& status,
const ScrollNode* scroll_node) const; const ScrollNode* scroll_node) const;
...@@ -190,8 +187,6 @@ class CC_EXPORT ThreadedInputHandler : public InputDelegateForCompositor { ...@@ -190,8 +187,6 @@ class CC_EXPORT ThreadedInputHandler : public InputDelegateForCompositor {
LayerImpl* first_scrolling_layer_or_drawn_scrollbar, LayerImpl* first_scrolling_layer_or_drawn_scrollbar,
ui::ScrollInputType type); ui::ScrollInputType type);
void ShowScrollbarsForImplScroll(ElementId element_id);
void UpdateRootLayerStateForSynchronousInputHandler(); void UpdateRootLayerStateForSynchronousInputHandler();
// Called during ScrollBegin once a scroller was successfully latched to // Called during ScrollBegin once a scroller was successfully latched to
...@@ -334,7 +329,9 @@ class CC_EXPORT ThreadedInputHandler : public InputDelegateForCompositor { ...@@ -334,7 +329,9 @@ class CC_EXPORT ThreadedInputHandler : public InputDelegateForCompositor {
return scrollbar_controller_.get(); return scrollbar_controller_.get();
} }
LayerTreeHostImpl& host_impl_; // The input handler is owned by the delegate so their lifetimes are tied
// together.
CompositorDelegateForInput& compositor_delegate_;
InputHandlerClient* input_handler_client_ = nullptr; InputHandlerClient* input_handler_client_ = nullptr;
......
...@@ -276,10 +276,6 @@ void RecordSourceIdConsistency(bool all_valid, bool all_unique) { ...@@ -276,10 +276,6 @@ void RecordSourceIdConsistency(bool all_valid, bool all_unique) {
DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeRasterDurationHistogramTimer, DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeRasterDurationHistogramTimer,
"Scheduling.%s.PendingTreeRasterDuration") "Scheduling.%s.PendingTreeRasterDuration")
void LayerTreeHostImpl::SetNeedsCommitInputChanges() {
client_->SetNeedsCommitOnImplThread();
}
void LayerTreeHostImpl::DidUpdateScrollAnimationCurve() { void LayerTreeHostImpl::DidUpdateScrollAnimationCurve() {
// Because we updated the animation target, notify the SwapPromiseMonitor // Because we updated the animation target, notify the SwapPromiseMonitor
// to tell it that something happened that will cause a swap in the future. // to tell it that something happened that will cause a swap in the future.
...@@ -319,15 +315,32 @@ void LayerTreeHostImpl::DidStartScroll() { ...@@ -319,15 +315,32 @@ void LayerTreeHostImpl::DidStartScroll() {
client_->RenewTreePriority(); client_->RenewTreePriority();
} }
void LayerTreeHostImpl::DidSetRootScrollOffsetForSynchronousInputHandler() { void LayerTreeHostImpl::DidMouseLeave() {
for (auto& pair : scrollbar_animation_controllers_)
pair.second->DidMouseLeave();
}
void LayerTreeHostImpl::SetNeedsFullViewportRedraw() {
// TODO(bokan): Do these really need to be manually called? (Rather than // TODO(bokan): Do these really need to be manually called? (Rather than
// damage/redraw being set from scroll offset changes). // damage/redraw being set from scroll offset changes).
SetFullViewportDamage(); SetFullViewportDamage();
SetNeedsRedraw(); SetNeedsRedraw();
} }
ImplThreadPhase LayerTreeHostImpl::GetCompositorThreadPhase() const { bool LayerTreeHostImpl::IsInHighLatencyMode() const {
return impl_thread_phase_; return impl_thread_phase_ == ImplThreadPhase::IDLE;
}
const LayerTreeSettings& LayerTreeHostImpl::GetSettings() const {
return settings();
}
LayerTreeHostImpl& LayerTreeHostImpl::GetImplDeprecated() {
return *this;
}
const LayerTreeHostImpl& LayerTreeHostImpl::GetImplDeprecated() const {
return *this;
} }
LayerTreeHostImpl::FrameData::FrameData() = default; LayerTreeHostImpl::FrameData::FrameData() = default;
...@@ -373,7 +386,7 @@ LayerTreeHostImpl::LayerTreeHostImpl( ...@@ -373,7 +386,7 @@ LayerTreeHostImpl::LayerTreeHostImpl(
std::make_unique<CompositorFrameReportingController>( std::make_unique<CompositorFrameReportingController>(
/*should_report_metrics=*/!settings /*should_report_metrics=*/!settings
.single_thread_proxy_scheduler)), .single_thread_proxy_scheduler)),
input_handler_(this), input_handler_(*this),
settings_(settings), settings_(settings),
is_synchronous_single_threaded_(!task_runner_provider->HasImplThread() && is_synchronous_single_threaded_(!task_runner_provider->HasImplThread() &&
!settings_.single_thread_proxy_scheduler), !settings_.single_thread_proxy_scheduler),
...@@ -3783,8 +3796,32 @@ InputHandlerScrollResult LayerTreeHostImpl::ScrollUpdate( ...@@ -3783,8 +3796,32 @@ InputHandlerScrollResult LayerTreeHostImpl::ScrollUpdate(
return input_handler_.ScrollUpdate(scroll_state, delayed_by); return input_handler_.ScrollUpdate(scroll_state, delayed_by);
} }
void LayerTreeHostImpl::DidScrollContent(bool animated) { void LayerTreeHostImpl::WillScrollContent(ElementId element_id) {
client_->RenewTreePriority(); // Flash the overlay scrollbar even if the scroll delta is 0.
if (settings().scrollbar_flash_after_any_scroll_update) {
FlashAllScrollbars(false);
} else {
if (ScrollbarAnimationController* animation_controller =
ScrollbarAnimationControllerForElementId(element_id))
animation_controller->WillUpdateScroll();
}
}
void LayerTreeHostImpl::DidScrollContent(ElementId element_id, bool animated) {
if (settings().scrollbar_flash_after_any_scroll_update) {
FlashAllScrollbars(true);
} else {
if (ScrollbarAnimationController* animation_controller =
ScrollbarAnimationControllerForElementId(element_id))
animation_controller->DidScrollUpdate();
}
// We may wish to prioritize smoothness over raster when the user is
// interacting with content, but this needs to be evaluated only for direct
// user scrolls, not for programmatic scrolls.
if (input_delegate_->IsCurrentlyScrolling())
client_->RenewTreePriority();
if (!animated) { if (!animated) {
// SetNeedsRedraw is only called in non-animated cases since an animation // SetNeedsRedraw is only called in non-animated cases since an animation
// won't actually update any scroll offsets until a frame produces a // won't actually update any scroll offsets until a frame produces a
...@@ -3799,6 +3836,10 @@ float LayerTreeHostImpl::DeviceScaleFactor() const { ...@@ -3799,6 +3836,10 @@ float LayerTreeHostImpl::DeviceScaleFactor() const {
return active_tree_->device_scale_factor(); return active_tree_->device_scale_factor();
} }
float LayerTreeHostImpl::PageScaleFactor() const {
return active_tree_->page_scale_factor_for_scroll();
}
void LayerTreeHostImpl::RequestUpdateForSynchronousInputHandler() { void LayerTreeHostImpl::RequestUpdateForSynchronousInputHandler() {
input_handler_.RequestUpdateForSynchronousInputHandler(); input_handler_.RequestUpdateForSynchronousInputHandler();
} }
...@@ -3852,6 +3893,10 @@ InputHandlerPointerResult LayerTreeHostImpl::MouseMoveAt( ...@@ -3852,6 +3893,10 @@ InputHandlerPointerResult LayerTreeHostImpl::MouseMoveAt(
return input_handler_.MouseMoveAt(viewport_point); return input_handler_.MouseMoveAt(viewport_point);
} }
ScrollTree& LayerTreeHostImpl::GetScrollTree() const {
return active_tree_->property_trees()->scroll_tree;
}
bool LayerTreeHostImpl::HasAnimatedScrollbars() const { bool LayerTreeHostImpl::HasAnimatedScrollbars() const {
return !scrollbar_animation_controllers_.empty(); return !scrollbar_animation_controllers_.empty();
} }
......
...@@ -119,11 +119,6 @@ enum class GpuRasterizationStatus { ...@@ -119,11 +119,6 @@ enum class GpuRasterizationStatus {
OFF_DEVICE, OFF_DEVICE,
}; };
enum class ImplThreadPhase {
IDLE,
INSIDE_IMPL_FRAME,
};
// LayerTreeHost->Proxy callback interface. // LayerTreeHost->Proxy callback interface.
class LayerTreeHostImplClient { class LayerTreeHostImplClient {
public: public:
...@@ -205,7 +200,8 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandler, ...@@ -205,7 +200,8 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandler,
public ScrollbarAnimationControllerClient, public ScrollbarAnimationControllerClient,
public VideoFrameControllerClient, public VideoFrameControllerClient,
public MutatorHostClient, public MutatorHostClient,
public ImageAnimationController::Client { public ImageAnimationController::Client,
public CompositorDelegateForInput {
public: public:
// This structure is used to build all the state required for producing a // This structure is used to build all the state required for producing a
// single CompositorFrame. The |render_passes| list becomes the set of // single CompositorFrame. The |render_passes| list becomes the set of
...@@ -396,25 +392,29 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandler, ...@@ -396,25 +392,29 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandler,
void SetEnableFrameRateThrottling(bool enable_frame_rate_throttling); void SetEnableFrameRateThrottling(bool enable_frame_rate_throttling);
// Interface for ThreadedInputHandler // Interface for ThreadedInputHandler
bool HasAnimatedScrollbars() const; ScrollTree& GetScrollTree() const override;
void SetNeedsCommitInputChanges(); bool HasAnimatedScrollbars() const override;
void DidUpdateScrollAnimationCurve(); // Already overridden for BrowserControlsOffsetManagerClient which declares a
void AccumulateScrollDeltaForTracing(const gfx::Vector2dF& delta); // method of the same name.
void DidStartPinchZoom(); // void SetNeedsCommit();
void DidEndPinchZoom(); void SetNeedsFullViewportRedraw() override;
void DidUpdatePinchZoom(); void DidUpdateScrollAnimationCurve() override;
void DidStartScroll(); void AccumulateScrollDeltaForTracing(const gfx::Vector2dF& delta) override;
void DidSetRootScrollOffsetForSynchronousInputHandler(); void DidStartPinchZoom() override;
void DidUpdatePinchZoom() override;
void DidEndPinchZoom() override;
void DidStartScroll() override;
void DidMouseLeave() override;
bool IsInHighLatencyMode() const override;
void WillScrollContent(ElementId element_id) override;
void DidScrollContent(ElementId element_id, bool animated) override;
float DeviceScaleFactor() const override;
float PageScaleFactor() const override;
const LayerTreeSettings& GetSettings() const override;
LayerTreeHostImpl& GetImplDeprecated() override;
const LayerTreeHostImpl& GetImplDeprecated() const override;
FrameSequenceTrackerCollection& frame_trackers() { return frame_trackers_; } FrameSequenceTrackerCollection& frame_trackers() { return frame_trackers_; }
ImplThreadPhase GetCompositorThreadPhase() const;
std::unordered_map<ElementId,
std::unique_ptr<ScrollbarAnimationController>,
ElementIdHash>&
get_scrollbar_animation_controllers() {
return scrollbar_animation_controllers_;
}
void DidScrollContent(bool animated);
float DeviceScaleFactor() const;
// Updates registered ElementIds present in |changed_list|. Call this after // Updates registered ElementIds present in |changed_list|. Call this after
// changing the property trees for the |changed_list| trees. // changing the property trees for the |changed_list| trees.
...@@ -1136,6 +1136,10 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandler, ...@@ -1136,6 +1136,10 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandler,
// success) state. // success) state.
std::vector<std::pair<int, bool>> completed_image_decode_requests_; std::vector<std::pair<int, bool>> completed_image_decode_requests_;
enum class ImplThreadPhase {
IDLE,
INSIDE_IMPL_FRAME,
};
ImplThreadPhase impl_thread_phase_ = ImplThreadPhase::IDLE; ImplThreadPhase impl_thread_phase_ = ImplThreadPhase::IDLE;
ImageAnimationController image_animation_controller_; ImageAnimationController image_animation_controller_;
......
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