#ifndef CC_TREES_LAYER_TREE_HOST_H_
#define CC_TREES_LAYER_TREE_HOST_H_
#include <stddef.h>
#include <stdint.h>
#include <limits>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "arkweb/build/features/features.h"
#include "base/auto_reset.h"
#include "base/cancelable_callback.h"
#include "base/containers/flat_map.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/base/completion_event.h"
#include "cc/benchmarks/micro_benchmark.h"
#include "cc/benchmarks/micro_benchmark_controller.h"
#include "cc/cc_export.h"
#include "cc/input/browser_controls_offset_tag_modifications.h"
#include "cc/input/browser_controls_state.h"
#include "cc/input/compositor_input_interfaces.h"
#include "cc/input/event_listener_properties.h"
#include "cc/input/input_handler.h"
#include "cc/input/layer_selection_bound.h"
#include "cc/input/scrollbar.h"
#include "cc/layers/layer.h"
#include "cc/layers/layer_collections.h"
#include "cc/layers/layer_list_iterator.h"
#include "cc/metrics/begin_main_frame_metrics.h"
#include "cc/metrics/events_metrics_manager.h"
#include "cc/metrics/frame_sequence_tracker.h"
#include "cc/paint/node_id.h"
#include "cc/resources/ui_resource_request.h"
#include "cc/trees/browser_controls_params.h"
#include "cc/trees/commit_state.h"
#include "cc/trees/compositor_mode.h"
#include "cc/trees/layer_tree_frame_sink.h"
#include "cc/trees/layer_tree_host_client.h"
#include "cc/trees/layer_tree_settings.h"
#include "cc/trees/mutator_host.h"
#include "cc/trees/paint_holding_reason.h"
#include "cc/trees/presentation_time_callback_buffer.h"
#include "cc/trees/property_tree_delegate.h"
#include "cc/trees/proxy.h"
#include "cc/trees/swap_promise.h"
#include "cc/trees/swap_promise_manager.h"
#include "cc/trees/target_property.h"
#include "cc/trees/viewport_layers.h"
#include "cc/trees/viewport_property_ids.h"
#include "components/viz/common/surfaces/local_surface_id.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "ui/gfx/delegated_ink_metadata.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/overlay_transform.h"
namespace cc {
class ViewTransitionRequest;
class HeadsUpDisplayLayer;
class PropertyTreeDelegate;
class LayerTreeHostImpl;
class LayerTreeHostImplClient;
class LayerTreeHostSingleThreadClient;
class LayerTreeMutator;
class MutatorEvents;
class MutatorHost;
class PaintWorkletLayerPainter;
class RasterDarkModeFilter;
class RenderFrameMetadataObserver;
class RenderingStatsInstrumentation;
class TaskGraphRunner;
class UIResourceManager;
class UkmRecorderFactory;
#if BUILDFLAG(IS_ARKWEB)
class LayerTreeHostExt;
#endif
struct CommitState;
struct CompositorCommitData;
struct OverscrollBehavior;
struct RenderingStats;
class CC_EXPORT ScopedDeferMainFrameUpdate {
public:
explicit ScopedDeferMainFrameUpdate(LayerTreeHost* host);
~ScopedDeferMainFrameUpdate();
private:
base::WeakPtr<LayerTreeHost> host_;
};
class CC_EXPORT ScopedPauseRendering {
public:
explicit ScopedPauseRendering(LayerTreeHost* host);
~ScopedPauseRendering();
private:
base::WeakPtr<LayerTreeHost> host_;
};
class CC_EXPORT ScopedKeepSurfaceAlive {
public:
explicit ScopedKeepSurfaceAlive(LayerTreeHost* host,
const viz::SurfaceId& surface_id);
~ScopedKeepSurfaceAlive();
private:
const base::WeakPtr<LayerTreeHost> host_;
const viz::SurfaceRange range_;
};
class CC_EXPORT LayerTreeHost : public MutatorHostClient {
public:
struct CC_EXPORT InitParams {
InitParams();
~InitParams();
InitParams(InitParams&&);
InitParams& operator=(InitParams&&);
raw_ptr<LayerTreeHostClient> client = nullptr;
raw_ptr<LayerTreeHostSchedulingClient> scheduling_client = nullptr;
raw_ptr<TaskGraphRunner> task_graph_runner = nullptr;
raw_ptr<const LayerTreeSettings> settings = nullptr;
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner;
raw_ptr<MutatorHost> mutator_host = nullptr;
raw_ptr<RasterDarkModeFilter> dark_mode_filter = nullptr;
scoped_refptr<base::SequencedTaskRunner> image_worker_task_runner;
std::unique_ptr<UkmRecorderFactory> ukm_recorder_factory;
raw_ptr<PropertyTreeDelegate> property_tree_delegate = nullptr;
};
static std::unique_ptr<LayerTreeHost> CreateThreaded(
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
InitParams params);
static std::unique_ptr<LayerTreeHost> CreateSingleThreaded(
LayerTreeHostSingleThreadClient* single_thread_client,
InitParams params);
LayerTreeHost(const LayerTreeHost&) = delete;
~LayerTreeHost() override;
LayerTreeHost& operator=(const LayerTreeHost&) = delete;
#if BUILDFLAG(IS_ARKWEB)
friend class LayerTreeHostExt;
virtual LayerTreeHostExt* AsLayerTreeHostExt() { return nullptr; }
#endif
int GetId() const;
const CommitState* pending_commit_state() const {
DCHECK(IsMainThread());
return pending_commit_state_.get();
}
const ThreadUnsafeCommitState& thread_unsafe_commit_state() const {
DCHECK(IsMainThread());
return thread_unsafe_commit_state_;
}
ThreadUnsafeCommitState& GetUnsafeStateForCommit() {
return thread_unsafe_commit_state();
}
int SourceFrameNumber() const;
UIResourceManager* GetUIResourceManager();
TaskRunnerProvider* GetTaskRunnerProvider();
bool IsMainThread() const;
bool IsImplThread() const;
const LayerTreeSettings& GetSettings() const;
void SetLayerTreeMutator(std::unique_ptr<LayerTreeMutator> mutator);
void SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter);
void QueueSwapPromise(std::unique_ptr<SwapPromise> swap_promise);
SwapPromiseManager* GetSwapPromiseManager();
std::unique_ptr<EventsMetricsManager::ScopedMonitor>
GetScopedEventMetricsMonitor(
EventsMetricsManager::ScopedMonitor::DoneCallback done_callback);
void ClearEventsMetrics();
size_t saved_events_metrics_count_for_testing() const {
DCHECK(IsMainThread());
return events_metrics_manager_.saved_events_metrics_count_for_testing();
}
std::unique_ptr<BeginMainFrameMetrics> TakeBeginMainFrameMetrics() {
return std::move(pending_commit_state()->begin_main_frame_metrics);
}
void SetVisible(bool visible);
bool IsVisible() const;
void SetShouldWarmUp();
bool ShouldWarmUp() const;
void SetLayerTreeFrameSink(
std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink);
std::unique_ptr<LayerTreeFrameSink> ReleaseLayerTreeFrameSink();
std::unique_ptr<ScopedKeepSurfaceAlive> CreateScopedKeepSurfaceAlive(
const viz::SurfaceId& surface_id);
void SetNeedsAnimate(bool urgent = false);
void SetNeedsAnimateIfNotInsideMainFrame();
virtual void SetNeedsUpdateLayers();
virtual void SetNeedsCommit();
void OnCommitRequested();
virtual void SetTargetLocalSurfaceId(
const viz::LocalSurfaceId& target_local_surface_id);
bool RequestedMainFramePending() const;
void SetNeedsRecalculateRasterScales();
bool CommitRequested() const;
std::unique_ptr<ScopedDeferMainFrameUpdate> DeferMainFrameUpdate();
[[nodiscard]] std::unique_ptr<ScopedPauseRendering> PauseRendering();
bool MainFrameUpdatesAreDeferred() const;
void OnDeferMainFrameUpdatesChanged(bool);
bool StartDeferringCommits(base::TimeDelta timeout,
PaintHoldingReason reason);
void StopDeferringCommits(PaintHoldingCommitTrigger);
bool IsDeferringCommits() const;
bool IsRenderingPaused() const;
void OnDeferCommitsChanged(bool defer_status,
PaintHoldingReason reason,
std::optional<PaintHoldingCommitTrigger> trigger);
void SetShouldThrottleFrameRate(bool flag);
bool defer_main_frame_update() const {
DCHECK(IsMainThread());
return defer_main_frame_update_count_;
}
void CompositeForTest(base::TimeTicks frame_begin_time,
bool raster,
base::OnceClosure callback);
void SetNeedsRedrawRect(const gfx::Rect& damage_rect);
void SetNeedsCommitWithForcedRedraw();
void RequestMainFrameOnCompositorAnimation(
PropertyChangeForcesCommitCriteria
property_change_forces_commit_criteria);
void UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagModifications>
offset_tag_modifications);
const base::WeakPtr<CompositorDelegateForInput>& GetDelegateForInput() const;
void DetachInputDelegateAndRenderFrameObserver();
void SetDebugState(const LayerTreeDebugState& debug_state);
const LayerTreeDebugState& GetDebugState() const;
int ScheduleMicroBenchmark(const std::string& benchmark_name,
base::Value::Dict settings,
MicroBenchmark::DoneCallback callback);
bool SendMessageToMicroBenchmark(int id, base::Value::Dict message);
void SetNextCommitWaitsForActivation();
void RequestPresentationTimeForNextFrame(
PresentationTimeCallbackBuffer::Callback callback);
void RequestSuccessfulPresentationTimeForNextFrame(
PresentationTimeCallbackBuffer::SuccessfulCallbackWithDetails callback);
void RequestScrollAnimationEndNotification(base::OnceClosure callback);
void SetRootLayer(scoped_refptr<Layer> root_layer);
Layer* root_layer() { return thread_unsafe_commit_state().root_layer.get(); }
const Layer* root_layer() const {
return thread_unsafe_commit_state().root_layer.get();
}
bool has_root_layer() const { return root_layer(); }
void RegisterViewportPropertyIds(const ViewportPropertyIds&);
void SetViewportPropertyIds(const ViewportPropertyIds& ids);
ViewportPropertyIds ViewportPropertyIdsForTesting() const {
return pending_commit_state()->viewport_property_ids;
}
Layer* InnerViewportScrollLayerForTesting();
Layer* OuterViewportScrollLayerForTesting();
ElementId OuterViewportScrollElementId() const;
void RegisterSelection(const LayerSelection& selection);
const LayerSelection& selection() const {
return pending_commit_state()->selection;
}
void SetHaveScrollEventHandlers(bool have_event_handlers);
bool have_scroll_event_handlers() const {
return pending_commit_state()->have_scroll_event_handlers;
}
void SetEventListenerProperties(EventListenerClass event_class,
EventListenerProperties event_properties);
EventListenerProperties event_listener_properties(
EventListenerClass event_class) const {
DCHECK(IsMainThread());
return pending_commit_state()
->event_listener_properties[static_cast<size_t>(event_class)];
}
void SetViewportRectAndScale(
const gfx::Rect& device_viewport_rect,
float device_scale_factor,
const viz::LocalSurfaceId& local_surface_id_from_parent);
void SetVisualDeviceViewportIntersectionRect(
const gfx::Rect& intersection_rect);
void SetVisualDeviceViewportSize(const gfx::Size&);
void SetMaxSafeAreaInsets(const gfx::InsetsF& max_safe_area_insets);
gfx::Rect device_viewport_rect() const {
return pending_commit_state()->device_viewport_rect;
}
void UpdateViewportIsMobileOptimized(bool is_viewport_mobile_optimized);
bool IsMobileOptimized() const;
void SetPrefersReducedMotion(bool prefers_reduced_motion);
void SetMayThrottleIfUndrawnFrames(bool may_throttle_if_undrawn_frames);
bool GetMayThrottleIfUndrawnFramesForTesting() const;
void SetBrowserControlsParams(const BrowserControlsParams& params);
void SetBrowserControlsShownRatio(float top_ratio, float bottom_ratio);
void SetLoadProgress(float progress);
void SetOverscrollBehavior(const OverscrollBehavior& overscroll_behavior);
const OverscrollBehavior& overscroll_behavior() const {
return pending_commit_state()->overscroll_behavior;
}
void SetPageScaleFactorAndLimits(float page_scale_factor,
float min_page_scale_factor,
float max_page_scale_factor);
float page_scale_factor() const {
return pending_commit_state()->page_scale_factor;
}
float min_page_scale_factor() const {
return pending_commit_state()->min_page_scale_factor;
}
float max_page_scale_factor() const {
return pending_commit_state()->max_page_scale_factor;
}
void set_background_color(SkColor4f color) {
pending_commit_state()->background_color = color;
}
SkColor4f background_color() const {
return pending_commit_state()->background_color;
}
void set_display_transform_hint(gfx::OverlayTransform hint) {
pending_commit_state()->display_transform_hint = hint;
}
gfx::OverlayTransform display_transform_hint() const {
return pending_commit_state()->display_transform_hint;
}
void StartPageScaleAnimation(const gfx::Point& target_offset,
bool use_anchor,
float scale,
base::TimeDelta duration);
bool HasPendingPageScaleAnimation() const;
float device_scale_factor() const {
return pending_commit_state()->device_scale_factor;
}
float painted_device_scale_factor() const {
return pending_commit_state()->painted_device_scale_factor;
}
void SetRecordingScaleFactor(float recording_scale_factor);
void SetLocalSurfaceIdFromParent(
const viz::LocalSurfaceId& local_surface_id_from_parent);
const viz::LocalSurfaceId& local_surface_id_from_parent() const {
return pending_commit_state()->local_surface_id_from_parent;
}
void RequestNewLocalSurfaceId();
void RequestViewportScreenshot(
const base::UnguessableToken& destination_token);
void SetPrimaryMainFrameItemSequenceNumber(
int64_t primary_main_frame_item_sequence_number);
int64_t primary_main_frame_item_sequence_number_for_testing() const {
return pending_commit_state()->primary_main_frame_item_sequence_number;
}
bool new_local_surface_id_request_for_testing() const {
return pending_commit_state()->new_local_surface_id_request;
}
void SetDisplayColorSpaces(
const gfx::DisplayColorSpaces& display_color_spaces);
const gfx::DisplayColorSpaces& display_color_spaces() const {
return pending_commit_state()->display_color_spaces;
}
bool HasCompositorDrivenScrollAnimationForTesting() const {
DCHECK(IsMainThread());
return scroll_animation_.in_progress;
}
void SetExternalPageScaleFactor(float page_scale_factor,
bool is_external_pinch_gesture_active);
bool is_external_pinch_gesture_active_for_testing() {
return pending_commit_state()->is_external_pinch_gesture_active;
}
void RequestForceSendMetadata() {
pending_commit_state()->force_send_metadata_request = true;
}
bool TakeForceSendMetadataRequest();
PropertyTrees* property_trees() {
return &thread_unsafe_commit_state().property_trees;
}
const PropertyTrees* property_trees() const {
return &thread_unsafe_commit_state().property_trees;
}
MutatorHost* mutator_host() {
return thread_unsafe_commit_state().mutator_host;
}
const MutatorHost* mutator_host() const {
return thread_unsafe_commit_state().mutator_host;
}
void SetPropertyTreesForTesting(const PropertyTrees* property_trees);
void SetNeedsDisplayOnAllLayers();
void RegisterLayer(Layer* layer);
void UnregisterLayer(Layer* layer);
Layer* LayerById(int id);
bool PaintContent(const LayerList& update_layer_list);
bool in_paint_layer_contents() const {
DCHECK(IsMainThread());
return in_paint_layer_contents_;
}
bool in_commit() const {
return commit_completion_event_ && !commit_completion_event_->IsSignaled();
}
void SetHasCopyRequest(bool has_copy_request);
bool has_copy_request() const {
DCHECK(IsMainThread());
return has_copy_request_;
}
void AddSurfaceRange(const viz::SurfaceRange& surface_range);
void RemoveSurfaceRange(const viz::SurfaceRange& surface_range);
void AddLayerShouldPushProperties(Layer* layer);
void SetPageScaleFromImplSide(float page_scale);
void SetElasticOverscrollFromImplSide(gfx::Vector2dF elastic_overscroll);
gfx::Vector2dF elastic_overscroll() const {
return pending_commit_state()->elastic_overscroll;
}
void UpdateHudLayer(bool show_hud_info);
HeadsUpDisplayLayer* hud_layer() {
DCHECK(IsMainThread());
return hud_layer_.get();
}
const HeadsUpDisplayLayer* hud_layer() const {
DCHECK(IsMainThread());
return hud_layer_.get();
}
bool is_hud_layer(const Layer*) const;
virtual void SetNeedsFullTreeSync();
void ResetNeedsFullTreeSyncForTesting();
bool needs_full_tree_sync() const {
return pending_commit_state()->needs_full_tree_sync;
}
void SetPropertyTreesNeedRebuild();
Layer* LayerByElementId(ElementId element_id);
const Layer* LayerByElementId(ElementId element_id) const;
void RegisterElement(ElementId element_id, Layer* layer);
void UnregisterElement(ElementId element_id, const Layer* layer);
void SetElementIdsForTesting();
void BuildPropertyTreesForTesting();
LayerListIterator begin();
LayerListConstIterator begin() const;
LayerListIterator end();
LayerListConstIterator end() const;
LayerListReverseIterator rbegin();
LayerListReverseConstIterator rbegin() const;
LayerListReverseIterator rend();
LayerListReverseConstIterator rend() const;
void WillBeginMainFrame();
void DidBeginMainFrame();
void BeginMainFrame(const viz::BeginFrameArgs& args);
void BeginMainFrameNotExpectedSoon();
void BeginMainFrameNotExpectedUntil(base::TimeTicks time);
void AnimateLayers(base::TimeTicks monotonic_frame_begin_time);
void RequestMainFrameUpdate(bool report_metrics);
std::unique_ptr<CommitState> WillCommit(
std::unique_ptr<CompletionEvent> completion,
bool has_updates);
std::unique_ptr<CommitState> ActivateCommitState();
void CommitComplete(int source_frame_number, const CommitTimestamps&);
void RequestNewLayerTreeFrameSink();
void DidInitializeLayerTreeFrameSink();
void DidFailToInitializeLayerTreeFrameSink();
std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
LayerTreeHostImplClient* client);
void DidLoseLayerTreeFrameSink();
void DidCommitAndDrawFrame(int source_frame_number) {
DCHECK(IsMainThread());
client_->DidCommitAndDrawFrame(source_frame_number);
}
void DidReceiveCompositorFrameAckDeprecatedForCompositor() {
DCHECK(IsMainThread());
client_->DidReceiveCompositorFrameAckDeprecatedForCompositor();
}
bool UpdateLayers();
void DidPresentCompositorFrame(
uint32_t frame_token,
std::vector<PresentationTimeCallbackBuffer::Callback>
presentation_callbacks,
std::vector<PresentationTimeCallbackBuffer::SuccessfulCallbackWithDetails>
successful_presentation_callbacks,
const viz::FrameTimingDetails& frame_timing_details);
void DidCompletePageScaleAnimation();
virtual void ApplyCompositorChanges(CompositorCommitData* commit_data);
void ApplyMutatorEvents(std::unique_ptr<MutatorEvents> events);
void RecordStartOfFrameMetrics();
void RecordEndOfFrameMetrics(base::TimeTicks frame_begin_time,
ActiveFrameSequenceTrackers trackers);
void NotifyCompositorMetricsTrackerResults(CustomTrackerResults results);
void NotifyImageDecodeFinished(int request_id, bool decode_succeeded);
void NotifyTransitionRequestsFinished(
const uint32_t sequence_id,
const viz::ViewTransitionElementResourceRects& rects);
LayerTreeHostClient* client() {
DCHECK(IsMainThread());
return client_;
}
LayerTreeHostSchedulingClient* scheduling_client() {
DCHECK(IsMainThread());
return scheduling_client_;
}
void CollectRenderingStats(RenderingStats* stats) const;
RenderingStatsInstrumentation* rendering_stats_instrumentation() const {
DCHECK(IsMainThread());
return rendering_stats_instrumentation_.get();
}
Proxy* proxy() {
DCHECK(IsMainThread());
return proxy_.get();
}
bool IsSingleThreaded() const;
bool IsThreaded() const;
bool IsUsingLayerLists() const;
bool IsOwnerThread() const override;
bool InProtectedSequence() const override;
void WaitForProtectedSequenceCompletion() const override;
bool MustWaitForCommitForTesting() const {
return !!commit_completion_event_;
}
bool IsElementInPropertyTrees(ElementId element_id,
ElementListType list_type) const override;
void SetMutatorsNeedCommit() override;
void SetMutatorsNeedRebuildPropertyTrees() override;
void SetElementFilterMutated(ElementId element_id,
ElementListType list_type,
const FilterOperations& filters) override;
void SetElementBackdropFilterMutated(
ElementId element_id,
ElementListType list_type,
const FilterOperations& backdrop_filters) override;
void SetElementOpacityMutated(ElementId element_id,
ElementListType list_type,
float opacity) override;
void SetElementTransformMutated(ElementId element_id,
ElementListType list_type,
const gfx::Transform& transform) override;
void SetElementScrollOffsetMutated(ElementId element_id,
ElementListType list_type,
const gfx::PointF& scroll_offset) override;
void ElementIsAnimatingChanged(const PropertyToElementIdMap& element_id_map,
ElementListType list_type,
const PropertyAnimationState& mask,
const PropertyAnimationState& state) override;
void MaximumScaleChanged(ElementId element_id,
ElementListType list_type,
float maximum_scale) override;
void OnCustomPropertyMutated(
PaintWorkletInput::PropertyKey property_key,
PaintWorkletInput::PropertyValue property_value) override {}
bool RunsOnCurrentThread() const override;
void ScrollOffsetAnimationFinished(ElementId element_id) override {}
void NotifyAnimationWorkletStateChange(AnimationWorkletMutationState state,
ElementListType tree_type) override {}
void QueueImageDecode(const DrawImage& image,
base::OnceCallback<void(bool)> callback,
bool speculative);
void ImageDecodesFinished(const std::vector<std::pair<int, bool>>& results);
void RequestBeginMainFrameNotExpected(bool new_state);
float recording_scale_factor() const {
DCHECK(IsMainThread());
return recording_scale_factor_;
}
const ViewportPropertyIds& viewport_property_ids() const {
return pending_commit_state()->viewport_property_ids;
}
void SetSourceURL(ukm::SourceId source_id, const GURL& url);
base::ReadOnlySharedMemoryRegion CreateSharedMemoryForDroppedFramesUkm();
void SetRenderFrameObserver(
std::unique_ptr<RenderFrameMetadataObserver> observer);
std::string LayersAsString() const;
bool CaptureContent(std::vector<NodeInfo>* content) const;
void SetDelegatedInkMetadata(
std::unique_ptr<gfx::DelegatedInkMetadata> metadata);
gfx::DelegatedInkMetadata* DelegatedInkMetadataForTesting() {
return pending_commit_state()->delegated_ink_metadata.get();
}
void DidObserveFirstScrollDelay(int source_frame_number,
base::TimeDelta first_scroll_delay,
base::TimeTicks first_scroll_timestamp);
void AddViewTransitionRequest(std::unique_ptr<ViewTransitionRequest> request);
std::vector<ViewTransitionRequest::ViewTransitionCaptureCallback>
TakeViewTransitionCallbacksForTesting();
double GetAverageThroughput() const;
bool in_composite_for_test() const { return in_composite_for_test_; }
[[nodiscard]] base::AutoReset<bool> ForceSyncCompositeForTest() {
return base::AutoReset<bool>(&in_composite_for_test_, true);
}
[[nodiscard]] base::AutoReset<bool> SimulateSyncingDeltasForTesting() {
return base::AutoReset<bool>(&syncing_deltas_for_test_, true);
}
void DropActiveScrollDeltaNextCommit(ElementId scroll_element);
protected:
LayerTreeHost(InitParams params, CompositorMode mode);
void InitializeThreaded(
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner);
void InitializeSingleThreaded(
LayerTreeHostSingleThreadClient* single_thread_client,
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);
void InitializeForTesting(
std::unique_ptr<TaskRunnerProvider> task_runner_provider,
std::unique_ptr<Proxy> proxy_for_testing);
void SetTaskRunnerProviderForTesting(
std::unique_ptr<TaskRunnerProvider> task_runner_provider);
void SetUIResourceManagerForTesting(
std::unique_ptr<UIResourceManager> ui_resource_manager);
TaskGraphRunner* task_graph_runner() const {
DCHECK(IsMainThread());
return task_graph_runner_;
}
CommitState* pending_commit_state() {
DCHECK(task_runner_provider_->IsMainThread());
return pending_commit_state_.get();
}
ThreadUnsafeCommitState& thread_unsafe_commit_state() {
DCHECK(IsMainThread());
WaitForProtectedSequenceCompletion();
return thread_unsafe_commit_state_;
}
void OnCommitForSwapPromises();
MicroBenchmarkController micro_benchmark_controller_;
base::WeakPtr<CompositorDelegateForInput> compositor_delegate_weak_ptr_;
scoped_refptr<base::SequencedTaskRunner> image_worker_task_runner_;
std::unique_ptr<UkmRecorderFactory> ukm_recorder_factory_;
private:
friend class LayerTreeHostSerializationTest;
friend class LayerTreeTest;
friend class ScopedDeferMainFrameUpdate;
friend class ScopedPauseRendering;
friend class ScopedKeepSurfaceAlive;
enum { kNumFramesToConsiderBeforeRemovingSlowPathFlag = 60 };
virtual std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImplInternal(
LayerTreeHostImplClient* client,
MutatorHost* mutator_host,
const LayerTreeSettings& settings,
TaskRunnerProvider* task_runner_provider,
raw_ptr<RasterDarkModeFilter>& dark_mode_filter,
int id,
raw_ptr<TaskGraphRunner>& task_graph_runner,
scoped_refptr<base::SequencedTaskRunner> image_worker_task_runner,
LayerTreeHostSchedulingClient* scheduling_client,
RenderingStatsInstrumentation* rendering_stats_instrumentation,
std::unique_ptr<UkmRecorderFactory>& ukm_recorder_factory,
base::WeakPtr<CompositorDelegateForInput>& compositor_delegate_weak_ptr);
void ApplyViewportChanges(const CompositorCommitData& commit_data);
void ApplyPageScaleDeltaFromImplSide(float page_scale_delta);
void InitializeProxy(std::unique_ptr<Proxy> proxy);
bool DoUpdateLayers();
void WaitForCommitCompletion(bool for_protected_sequence) const;
void UpdateDeferMainFrameUpdateInternal();
void UpdatePauseRenderingInternal();
void UpdateScrollOffsetFromImpl(
const ElementId&,
const gfx::Vector2dF& delta,
ScrollSourceType type,
const std::optional<TargetSnapAreaElementIds>&);
const CompositorMode compositor_mode_;
std::unique_ptr<UIResourceManager> ui_resource_manager_;
raw_ptr<LayerTreeHostClient> client_;
raw_ptr<LayerTreeHostSchedulingClient> scheduling_client_;
std::unique_ptr<Proxy> proxy_;
std::unique_ptr<TaskRunnerProvider> task_runner_provider_;
std::unique_ptr<RenderingStatsInstrumentation>
rendering_stats_instrumentation_;
std::unique_ptr<CommitState> pending_commit_state_;
ThreadUnsafeCommitState thread_unsafe_commit_state_;
SwapPromiseManager swap_promise_manager_;
std::unique_ptr<LayerTreeFrameSink> new_layer_tree_frame_sink_;
std::unique_ptr<LayerTreeFrameSink> current_layer_tree_frame_sink_;
const LayerTreeSettings settings_;
bool visible_ = false;
bool should_warm_up_ = false;
bool did_complete_scale_animation_ = false;
const int id_;
bool inside_main_frame_ = false;
raw_ptr<TaskGraphRunner> task_graph_runner_;
float recording_scale_factor_ = 1.f;
bool is_pinch_gesture_active_from_impl_ = false;
uint32_t defer_main_frame_update_count_ = 0;
uint32_t pause_rendering_count_ = 0;
gfx::Rect visual_device_viewport_intersection_rect_;
scoped_refptr<HeadsUpDisplayLayer> hud_layer_;
std::unordered_map<int, raw_ptr<Layer, CtnExperimental>> layer_id_map_;
std::unordered_map<ElementId, raw_ptr<Layer, CtnExperimental>, ElementIdHash>
element_layers_map_;
bool in_paint_layer_contents_ = false;
bool has_copy_request_ = false;
raw_ptr<MutatorHost> mutator_host_;
raw_ptr<RasterDarkModeFilter> dark_mode_filter_;
std::unordered_map<int, std::pair<base::OnceCallback<void(bool)>, bool>>
pending_image_decodes_;
struct ScrollAnimationState {
ScrollAnimationState();
~ScrollAnimationState();
bool in_progress = false;
base::OnceClosure end_notification;
} scroll_animation_;
mutable std::unique_ptr<CompletionEvent> commit_completion_event_;
EventsMetricsManager events_metrics_manager_;
base::flat_map<blink::ViewTransitionToken, bool>
view_transition_needs_new_lsid_;
const uint32_t view_transition_needs_new_lsid_max_size_ = 100;
base::flat_map<uint32_t, ViewTransitionRequest::ViewTransitionCaptureCallback>
view_transition_callbacks_;
bool in_composite_for_test_ = false;
bool syncing_deltas_for_test_ = false;
std::unique_ptr<PropertyTreeDelegate> owned_property_tree_delegate_;
raw_ptr<PropertyTreeDelegate> property_tree_delegate_;
base::WeakPtrFactory<LayerTreeHost> weak_ptr_factory_{this};
};
}
#if BUILDFLAG(IS_ARKWEB)
#include "arkweb/chromium_ext/cc/trees/layer_tree_host_ext.h"
#endif
#endif