Commit d5ee5058 authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

[OT-PW] Plumb for the PaintWorkletLayerPainter

This CL does the plubming for the PaintWorkletLayerPainter. It follows
the same implementation as the existing LayerTreeMutator which is
designed for animation worklet.

Change-Id: I173a61173e025d257f1782c5270e41ca24538e9e
Reviewed-on: https://chromium-review.googlesource.com/c/1350332
Commit-Queue: Xida Chen <xidachen@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619628}
parent f9e6eec6
......@@ -4,6 +4,7 @@
#include "cc/test/fake_proxy.h"
#include "cc/paint/paint_worklet_layer_painter.h"
#include "cc/trees/layer_tree_mutator.h"
namespace cc {
......@@ -26,6 +27,9 @@ bool FakeProxy::CommitRequested() const { return false; }
void FakeProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {}
void FakeProxy::SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) {}
bool FakeProxy::SupportsImplScrolling() const {
return true;
}
......
......@@ -12,7 +12,7 @@
#include "services/metrics/public/cpp/ukm_recorder.h"
namespace cc {
class PaintWorkletLayerPainter;
class FakeProxy : public Proxy {
public:
FakeProxy() : layer_tree_host_(nullptr) {}
......@@ -37,6 +37,8 @@ class FakeProxy : public Proxy {
void Start() override {}
void Stop() override {}
void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override;
void SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) override;
bool SupportsImplScrolling() const override;
bool MainFrameWillHappenForTesting() override;
void UpdateBrowserControlsState(BrowserControlsState constraints,
......
......@@ -41,6 +41,7 @@
#include "cc/layers/heads_up_display_layer_impl.h"
#include "cc/layers/layer.h"
#include "cc/layers/painted_scrollbar_layer.h"
#include "cc/paint/paint_worklet_layer_painter.h"
#include "cc/resources/ui_resource_manager.h"
#include "cc/tiles/frame_viewer_instrumentation.h"
#include "cc/trees/clip_node.h"
......@@ -1000,6 +1001,16 @@ void LayerTreeHost::SetLayerTreeMutator(
proxy_->SetMutator(std::move(mutator));
}
void LayerTreeHost::SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) {
// The paint worklet system assumes that the painter will never be called from
// the main thread, which will not be the case if we're running in
// single-threaded mode.
DCHECK(task_runner_provider_->HasImplThread())
<< "PaintWorkletLayerPainter not supported in single-thread mode";
proxy_->SetPaintWorkletLayerPainter(std::move(painter));
}
bool LayerTreeHost::IsSingleThreaded() const {
DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED ||
!task_runner_provider_->HasImplThread());
......
......@@ -61,6 +61,7 @@ class LayerTreeHostImpl;
class LayerTreeHostImplClient;
class LayerTreeHostSingleThreadClient;
class LayerTreeMutator;
class PaintWorkletLayerPainter;
class MutatorEvents;
class MutatorHost;
struct PendingPageScaleAnimation;
......@@ -151,6 +152,11 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
// state on the compositor thread. (Compositor-Worker)
void SetLayerTreeMutator(std::unique_ptr<LayerTreeMutator> mutator);
// Sets the LayerTreePainter interface used to dispatch the JS paint callback
// to a worklet thread.
void SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter);
// Attachs a SwapPromise to the Layer tree, that passes through the
// LayerTreeHost and LayerTreeHostImpl with the next commit and frame
// submission, which can be used to observe that progress. This also
......
......@@ -50,6 +50,7 @@
#include "cc/layers/scrollbar_layer_impl_base.h"
#include "cc/layers/surface_layer_impl.h"
#include "cc/layers/viewport.h"
#include "cc/paint/paint_worklet_layer_painter.h"
#include "cc/raster/bitmap_raster_buffer_provider.h"
#include "cc/raster/gpu_raster_buffer_provider.h"
#include "cc/raster/one_copy_raster_buffer_provider.h"
......@@ -3144,6 +3145,11 @@ void LayerTreeHostImpl::SetLayerTreeMutator(
mutator_host_->SetLayerTreeMutator(std::move(mutator));
}
void LayerTreeHostImpl::SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) {
painter_ = std::move(painter);
}
LayerImpl* LayerTreeHostImpl::ViewportMainScrollLayer() {
return viewport()->MainScrollLayer();
}
......
......@@ -74,6 +74,7 @@ class ImageAnimationController;
class LayerImpl;
class LayerTreeFrameSink;
class LayerTreeImpl;
class PaintWorkletLayerPainter;
class MemoryHistory;
class MutatorEvents;
class MutatorHost;
......@@ -679,6 +680,8 @@ class CC_EXPORT LayerTreeHostImpl
base::TimeDelta delayed_by);
void SetLayerTreeMutator(std::unique_ptr<LayerTreeMutator> mutator);
void SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter);
// The viewport has two scroll nodes, corresponding to the visual and layout
// viewports. However, when we compute the scroll chain we include only one
......@@ -1103,6 +1106,8 @@ class CC_EXPORT LayerTreeHostImpl
int last_color_space_id_ = -1;
bool is_animating_for_snap_;
std::unique_ptr<PaintWorkletLayerPainter> painter_;
const PaintImage::GeneratorClientId paint_image_generator_client_id_;
// Set to true when a scroll gesture being handled on the compositor has
......
......@@ -27,6 +27,7 @@ class Rect;
namespace cc {
class LayerTreeFrameSink;
class LayerTreeMutator;
class PaintWorkletLayerPainter;
class RenderFrameMetadataObserver;
// Abstract interface responsible for proxying commands from the main-thread
......@@ -72,6 +73,9 @@ class CC_EXPORT Proxy {
virtual void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) = 0;
virtual void SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) = 0;
virtual bool SupportsImplScrolling() const = 0;
virtual void UpdateBrowserControlsState(BrowserControlsState constraints,
......
......@@ -15,6 +15,7 @@
#include "cc/base/devtools_instrumentation.h"
#include "cc/benchmarks/benchmark_instrumentation.h"
#include "cc/input/browser_controls_offset_manager.h"
#include "cc/paint/paint_worklet_layer_painter.h"
#include "cc/scheduler/compositor_timing_history.h"
#include "cc/trees/layer_tree_frame_sink.h"
#include "cc/trees/layer_tree_host.h"
......@@ -129,6 +130,13 @@ void ProxyImpl::InitializeMutatorOnImpl(
host_impl_->SetLayerTreeMutator(std::move(mutator));
}
void ProxyImpl::InitializePaintWorkletLayerPainterOnImpl(
std::unique_ptr<PaintWorkletLayerPainter> painter) {
TRACE_EVENT0("cc", "ProxyImpl::InitializePaintWorkletLayerPainterOnImpl");
DCHECK(IsImplThread());
host_impl_->SetPaintWorkletLayerPainter(std::move(painter));
}
void ProxyImpl::UpdateBrowserControlsStateOnImpl(
BrowserControlsState constraints,
BrowserControlsState current,
......
......@@ -40,6 +40,8 @@ class CC_EXPORT ProxyImpl : public LayerTreeHostImplClient,
LayerTreeFrameSink* layer_tree_frame_sink,
base::WeakPtr<ProxyMain> proxy_main_frame_sink_bound_weak_ptr);
void InitializeMutatorOnImpl(std::unique_ptr<LayerTreeMutator> mutator);
void InitializePaintWorkletLayerPainterOnImpl(
std::unique_ptr<PaintWorkletLayerPainter> painter);
void SetInputThrottledUntilCommitOnImpl(bool is_throttled);
void SetDeferMainFrameUpdateOnImpl(bool defer_main_frame_update) const;
void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect);
......
......@@ -12,6 +12,7 @@
#include "cc/base/completion_event.h"
#include "cc/base/devtools_instrumentation.h"
#include "cc/benchmarks/benchmark_instrumentation.h"
#include "cc/paint/paint_worklet_layer_painter.h"
#include "cc/resources/ui_resource_manager.h"
#include "cc/trees/latency_info_swap_promise.h"
#include "cc/trees/layer_tree_frame_sink.h"
......@@ -518,6 +519,16 @@ void ProxyMain::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
base::Passed(std::move(mutator))));
}
void ProxyMain::SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) {
TRACE_EVENT0("cc", "ThreadProxy::SetPaintWorkletLayerPainter");
ImplThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&ProxyImpl::InitializePaintWorkletLayerPainterOnImpl,
base::Unretained(proxy_impl_.get()),
base::Passed(std::move(painter))));
}
bool ProxyMain::SupportsImplScrolling() const {
return true;
}
......
......@@ -18,6 +18,7 @@ class CompletionEvent;
class LayerTreeFrameSink;
class LayerTreeHost;
class LayerTreeMutator;
class PaintWorkletLayerPainter;
class ProxyImpl;
class RenderFrameMetadataObserver;
......@@ -87,6 +88,8 @@ class CC_EXPORT ProxyMain : public Proxy {
void Stop() override;
bool SupportsImplScrolling() const override;
void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override;
void SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) override;
bool MainFrameWillHappenForTesting() override;
void ReleaseLayerTreeFrameSink() override;
void UpdateBrowserControlsState(BrowserControlsState constraints,
......
......@@ -10,6 +10,7 @@
#include "cc/base/devtools_instrumentation.h"
#include "cc/benchmarks/benchmark_instrumentation.h"
#include "cc/input/browser_controls_offset_manager.h"
#include "cc/paint/paint_worklet_layer_painter.h"
#include "cc/resources/ui_resource_manager.h"
#include "cc/scheduler/commit_earlyout_reason.h"
#include "cc/scheduler/compositor_timing_history.h"
......@@ -315,6 +316,11 @@ void SingleThreadProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
host_impl_->SetLayerTreeMutator(std::move(mutator));
}
void SingleThreadProxy::SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) {
NOTREACHED();
}
void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
TRACE_EVENT1("cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw",
can_draw);
......
......@@ -56,6 +56,8 @@ class CC_EXPORT SingleThreadProxy : public Proxy,
void Start() override;
void Stop() override;
void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override;
void SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) override;
bool SupportsImplScrolling() const override;
bool MainFrameWillHappenForTesting() override;
void SetURLForUkm(const GURL& url) override {
......
......@@ -391,6 +391,12 @@ void LayerTreeView::SetMutatorClient(
layer_tree_host_->SetLayerTreeMutator(std::move(client));
}
void LayerTreeView::SetPaintWorkletLayerPainterClient(
std::unique_ptr<cc::PaintWorkletLayerPainter> client) {
TRACE_EVENT0("cc", "LayerTreeView::SetPaintWorkletLayerPainterClient");
layer_tree_host_->SetPaintWorkletLayerPainter(std::move(client));
}
void LayerTreeView::ForceRecalculateRasterScales() {
layer_tree_host_->SetNeedsRecalculateRasterScales();
}
......
......@@ -159,6 +159,8 @@ class LayerTreeView : public blink::WebLayerTreeView,
void RegisterSelection(const cc::LayerSelection& selection) override;
void ClearSelection() override;
void SetMutatorClient(std::unique_ptr<cc::LayerTreeMutator>) override;
void SetPaintWorkletLayerPainterClient(
std::unique_ptr<cc::PaintWorkletLayerPainter>) override;
void ForceRecalculateRasterScales() override;
void SetEventListenerProperties(
cc::EventListenerClass eventClass,
......
......@@ -32,6 +32,7 @@
#include "cc/input/layer_selection_bound.h"
#include "cc/input/overscroll_behavior.h"
#include "cc/layers/layer.h"
#include "cc/paint/paint_worklet_layer_painter.h"
#include "cc/trees/element_id.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_mutator.h"
......@@ -175,6 +176,10 @@ class WebLayerTreeView {
// Mutations are plumbed back to the layer tree via the mutator client.
virtual void SetMutatorClient(std::unique_ptr<cc::LayerTreeMutator>) {}
// Paints are plumbed back to the layer tree via the painter client.
virtual void SetPaintWorkletLayerPainterClient(
std::unique_ptr<cc::PaintWorkletLayerPainter>) {}
// For when the embedder itself change scales on the page (e.g. devtools)
// and wants all of the content at the new scale to be crisp.
virtual void ForceRecalculateRasterScales() {}
......
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