#include "third_party/blink/renderer/platform/widget/widget_base.h"
#include "base/command_line.h"
#include "base/debug/dump_without_crashing.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/animation/animation_host.h"
#include "cc/animation/animation_id_provider.h"
#include "cc/mojo_embedder/async_layer_tree_frame_sink.h"
#include "cc/raster/categorized_worker_pool.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_settings.h"
#include "cc/trees/paint_holding_reason.h"
#include "components/viz/common/features.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "gpu/command_buffer/common/context_creation_attribs.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "media/base/media_switches.h"
#include "mojo/public/cpp/bindings/direct_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "services/viz/public/cpp/gpu/context_provider_command_buffer.h"
#include "services/viz/public/mojom/compositing/compositor_frame_sink.mojom-blink.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/input/web_input_event_attribution.h"
#include "third_party/blink/public/common/switches.h"
#include "third_party/blink/public/mojom/input/pointer_lock_context.mojom-blink.h"
#include "third_party/blink/public/mojom/widget/record_content_to_visible_time_request.mojom-blink.h"
#include "third_party/blink/public/mojom/widget/visual_properties.mojom-blink.h"
#include "third_party/blink/public/platform/cross_variant_mojo_util.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/web/blink.h"
#include "third_party/blink/renderer/platform/graphics/raster_dark_mode_filter_impl.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/public/agent_group_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/compositor_thread_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/page_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/widget_scheduler.h"
#include "third_party/blink/renderer/platform/widget/compositing/blink_categorized_worker_pool_delegate.h"
#include "third_party/blink/renderer/platform/widget/compositing/layer_tree_settings.h"
#include "third_party/blink/renderer/platform/widget/compositing/layer_tree_view.h"
#include "third_party/blink/renderer/platform/widget/compositing/render_frame_metadata_observer_impl.h"
#include "third_party/blink/renderer/platform/widget/compositing/widget_compositor.h"
#include "third_party/blink/renderer/platform/widget/frame_widget.h"
#include "third_party/blink/renderer/platform/widget/input/ime_event_guard.h"
#include "third_party/blink/renderer/platform/widget/input/main_thread_event_queue.h"
#include "third_party/blink/renderer/platform/widget/input/widget_input_handler_manager.h"
#include "third_party/blink/renderer/platform/widget/widget_base_client.h"
#include "ui/base/ime/mojom/text_input_state.mojom-blink.h"
#include "ui/display/display.h"
#include "ui/display/screen_info.h"
#include "ui/gfx/geometry/dip_util.h"
#include "ui/gfx/presentation_feedback.h"
#if BUILDFLAG(IS_ANDROID)
#include "third_party/blink/renderer/platform/widget/compositing/android_webview/synchronous_layer_tree_frame_sink.h"
#endif
namespace blink {
namespace {
#if BUILDFLAG(IS_ANDROID)
uint32_t g_next_layer_tree_frame_sink_id = 1;
#endif
const gpu::SchedulingPriority kGpuStreamPriorityDefault = …;
const uint32_t kGpuStreamIdDefault = …;
static const int kInvalidNextPreviousFlagsValue = …;
void OnDidPresentForceDrawFrame(
mojom::blink::Widget::ForceRedrawCallback callback,
const gfx::PresentationFeedback& feedback) { … }
bool IsDateTimeInput(ui::TextInputType type) { … }
ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) { … }
ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) { … }
unsigned OrientationTypeToAngle(display::mojom::blink::ScreenOrientation type) { … }
std::unique_ptr<viz::SyntheticBeginFrameSource>
CreateSyntheticBeginFrameSource() { … }
}
WidgetBase::WidgetBase(
WidgetBaseClient* client,
CrossVariantMojoAssociatedRemote<mojom::WidgetHostInterfaceBase>
widget_host,
CrossVariantMojoAssociatedReceiver<mojom::WidgetInterfaceBase> widget,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
bool hidden,
bool never_composited,
bool is_embedded,
bool is_for_scalable_page)
: … { … }
WidgetBase::~WidgetBase() { … }
void WidgetBase::InitializeCompositing(
PageScheduler& page_scheduler,
const display::ScreenInfos& screen_infos,
const cc::LayerTreeSettings* settings,
base::WeakPtr<mojom::blink::FrameWidgetInputHandler>
frame_widget_input_handler,
WidgetBase* previous_widget) { … }
void WidgetBase::InitializeNonCompositing() { … }
void WidgetBase::DidFirstVisuallyNonEmptyPaint(
base::TimeTicks& first_paint_time) { … }
void WidgetBase::Shutdown() { … }
void WidgetBase::DisconnectLayerTreeView(WidgetBase* new_widget) { … }
cc::LayerTreeHost* WidgetBase::LayerTreeHost() const { … }
cc::AnimationHost* WidgetBase::AnimationHost() const { … }
cc::AnimationTimeline* WidgetBase::ScrollAnimationTimeline() const { … }
scheduler::WidgetScheduler* WidgetBase::WidgetScheduler() { … }
void WidgetBase::ForceRedraw(
mojom::blink::Widget::ForceRedrawCallback callback) { … }
void WidgetBase::GetWidgetInputHandler(
mojo::PendingReceiver<mojom::blink::WidgetInputHandler> request,
mojo::PendingRemote<mojom::blink::WidgetInputHandlerHost> host) { … }
void WidgetBase::ShowContextMenu(ui::mojom::blink::MenuSourceType source_type,
const gfx::Point& location) { … }
void WidgetBase::BindInputTargetClient(
mojo::PendingReceiver<viz::mojom::blink::InputTargetClient> host) { … }
void WidgetBase::UpdateVisualProperties(
const VisualProperties& visual_properties_from_browser) { … }
void WidgetBase::UpdateScreenRects(const gfx::Rect& widget_screen_rect,
const gfx::Rect& window_screen_rect,
UpdateScreenRectsCallback callback) { … }
void WidgetBase::WasHidden() { … }
void WidgetBase::WasShown(bool was_evicted,
mojom::blink::RecordContentToVisibleTimeRequestPtr
record_tab_switch_time_request) { … }
void WidgetBase::RequestSuccessfulPresentationTimeForNextFrame(
mojom::blink::RecordContentToVisibleTimeRequestPtr visible_time_request) { … }
void WidgetBase::CancelSuccessfulPresentationTimeRequest() { … }
void WidgetBase::SetupRenderInputRouterConnections(
mojo::PendingReceiver<mojom::blink::RenderInputRouterClient>
browser_request,
mojo::PendingReceiver<mojom::blink::RenderInputRouterClient> viz_request) { … }
void WidgetBase::ApplyViewportChanges(
const cc::ApplyViewportChangesArgs& args) { … }
void WidgetBase::UpdateCompositorScrollState(
const cc::CompositorCommitData& commit_data) { … }
void WidgetBase::OnDeferMainFrameUpdatesChanged(bool defer) { … }
void WidgetBase::OnDeferCommitsChanged(
bool defer,
cc::PaintHoldingReason reason,
std::optional<cc::PaintHoldingCommitTrigger> trigger) { … }
void WidgetBase::OnCommitRequested() { … }
void WidgetBase::DidBeginMainFrame() { … }
void WidgetBase::RequestNewLayerTreeFrameSink(
LayerTreeFrameSinkCallback callback) { … }
void WidgetBase::FinishRequestNewLayerTreeFrameSink(
const KURL& url,
mojo::PendingReceiver<viz::mojom::blink::CompositorFrameSink>
compositor_frame_sink_receiver,
mojo::PendingRemote<viz::mojom::blink::CompositorFrameSinkClient>
compositor_frame_sink_client,
mojo::PendingReceiver<cc::mojom::blink::RenderFrameMetadataObserverClient>
render_frame_metadata_observer_client_receiver,
mojo::PendingRemote<cc::mojom::blink::RenderFrameMetadataObserver>
render_frame_metadata_observer_remote,
std::unique_ptr<RenderFrameMetadataObserverImpl>
render_frame_metadata_observer,
std::unique_ptr<cc::mojo_embedder::AsyncLayerTreeFrameSink::InitParams>
params,
LayerTreeFrameSinkCallback callback,
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { … }
void WidgetBase::DidCommitAndDrawCompositorFrame() { … }
void WidgetBase::DidObserveFirstScrollDelay(
base::TimeDelta first_scroll_delay,
base::TimeTicks first_scroll_timestamp) { … }
void WidgetBase::WillCommitCompositorFrame() { … }
void WidgetBase::DidCommitCompositorFrame(base::TimeTicks commit_start_time,
base::TimeTicks commit_finish_time) { … }
void WidgetBase::DidCompletePageScaleAnimation() { … }
void WidgetBase::RecordStartOfFrameMetrics() { … }
void WidgetBase::RecordEndOfFrameMetrics(
base::TimeTicks frame_begin_time,
cc::ActiveFrameSequenceTrackers trackers) { … }
std::unique_ptr<cc::BeginMainFrameMetrics>
WidgetBase::GetBeginMainFrameMetrics() { … }
std::unique_ptr<cc::WebVitalMetrics> WidgetBase::GetWebVitalMetrics() { … }
void WidgetBase::BeginUpdateLayers() { … }
void WidgetBase::EndUpdateLayers() { … }
void WidgetBase::WillBeginMainFrame() { … }
void WidgetBase::RunPaintBenchmark(int repeat_count,
cc::PaintBenchmarkResult& result) { … }
void WidgetBase::ScheduleAnimationForWebTests() { … }
std::unique_ptr<cc::RenderFrameMetadataObserver>
WidgetBase::CreateRenderFrameObserver() { … }
void WidgetBase::SetCompositorVisible(bool visible) { … }
void WidgetBase::WarmUpCompositor() { … }
void WidgetBase::UpdateVisualState() { … }
void WidgetBase::BeginMainFrame(base::TimeTicks frame_time) { … }
bool WidgetBase::ShouldRecordBeginMainFrameMetrics() { … }
void WidgetBase::AddPresentationCallback(
uint32_t frame_token,
base::OnceCallback<void(const viz::FrameTimingDetails&)> callback) { … }
#if BUILDFLAG(IS_APPLE)
void WidgetBase::AddCoreAnimationErrorCodeCallback(
uint32_t frame_token,
base::OnceCallback<void(gfx::CALayerResult)> callback) {
layer_tree_view_->AddCoreAnimationErrorCodeCallback(frame_token,
std::move(callback));
}
#endif
void WidgetBase::SetCursor(const ui::Cursor& cursor) { … }
void WidgetBase::UpdateTooltipUnderCursor(const String& tooltip_text,
TextDirection dir) { … }
void WidgetBase::UpdateTooltipFromKeyboard(const String& tooltip_text,
TextDirection dir,
const gfx::Rect& bounds) { … }
void WidgetBase::ClearKeyboardTriggeredTooltip() { … }
void WidgetBase::ShowVirtualKeyboard() { … }
void WidgetBase::UpdateTextInputState() { … }
void WidgetBase::AssertAreCompatible(const WidgetBase& a, const WidgetBase& b) { … }
bool WidgetBase::CanComposeInline() { … }
void WidgetBase::UpdateTextInputStateInternal(bool show_virtual_keyboard,
bool reply_to_request) { … }
void WidgetBase::ClearTextInputState() { … }
void WidgetBase::ShowVirtualKeyboardOnElementFocus() { … }
void WidgetBase::ProcessTouchAction(cc::TouchAction touch_action) { … }
void WidgetBase::SetFocus(mojom::blink::FocusState focus_state) { … }
void WidgetBase::BindWidgetCompositor(
mojo::PendingReceiver<mojom::blink::WidgetCompositor> receiver) { … }
void WidgetBase::UpdateCompositionInfo(bool immediate_request) { … }
void WidgetBase::ForceTextInputStateUpdate() { … }
void WidgetBase::RequestCompositionUpdates(bool immediate_request,
bool monitor_updates) { … }
void WidgetBase::GetCompositionRange(gfx::Range* range) { … }
void WidgetBase::GetCompositionCharacterBounds(Vector<gfx::Rect>* bounds) { … }
bool WidgetBase::ShouldUpdateCompositionInfo(const gfx::Range& range,
const Vector<gfx::Rect>& bounds) { … }
void WidgetBase::SetHidden(bool hidden) { … }
ui::TextInputType WidgetBase::GetTextInputType() { … }
void WidgetBase::UpdateSelectionBounds() { … }
void WidgetBase::MouseCaptureLost() { … }
void WidgetBase::SetEditCommandsForNextKeyEvent(
Vector<mojom::blink::EditCommandPtr> edit_commands) { … }
void WidgetBase::CursorVisibilityChange(bool is_visible) { … }
void WidgetBase::ImeSetComposition(
const String& text,
const Vector<ui::ImeTextSpan>& ime_text_spans,
const gfx::Range& replacement_range,
int selection_start,
int selection_end) { … }
void WidgetBase::ImeCommitText(const String& text,
const Vector<ui::ImeTextSpan>& ime_text_spans,
const gfx::Range& replacement_range,
int relative_cursor_pos) { … }
void WidgetBase::ImeFinishComposingText(bool keep_selection) { … }
void WidgetBase::QueueSyntheticEvent(
std::unique_ptr<WebCoalescedInputEvent> event) { … }
bool WidgetBase::IsForProvisionalFrame() { … }
bool WidgetBase::ShouldHandleImeEvents() { … }
void WidgetBase::RequestPresentationAfterScrollAnimationEnd(
mojom::blink::Widget::ForceRedrawCallback callback) { … }
void WidgetBase::FlushInputProcessedCallback() { … }
void WidgetBase::CancelCompositionForPepper() { … }
void WidgetBase::OnImeEventGuardStart(ImeEventGuard* guard) { … }
void WidgetBase::OnImeEventGuardFinish(ImeEventGuard* guard) { … }
void WidgetBase::RequestAnimationAfterDelay(const base::TimeDelta& delay) { … }
void WidgetBase::RequestAnimationAfterDelayTimerFired(TimerBase*) { … }
float WidgetBase::GetOriginalDeviceScaleFactor() const { … }
void WidgetBase::UpdateSurfaceAndScreenInfo(
const viz::LocalSurfaceId& new_local_surface_id,
const gfx::Rect& compositor_viewport_pixel_rect,
const display::ScreenInfos& screen_infos) { … }
void WidgetBase::UpdateScreenInfo(
const display::ScreenInfos& new_screen_infos) { … }
void WidgetBase::UpdateCompositorViewportAndScreenInfo(
const gfx::Rect& compositor_viewport_pixel_rect,
const display::ScreenInfos& new_screen_infos) { … }
void WidgetBase::UpdateCompositorViewportRect(
const gfx::Rect& compositor_viewport_pixel_rect) { … }
void WidgetBase::UpdateSurfaceAndCompositorRect(
const viz::LocalSurfaceId& new_local_surface_id,
const gfx::Rect& compositor_viewport_pixel_rect) { … }
const display::ScreenInfo& WidgetBase::GetScreenInfo() { … }
void WidgetBase::SetScreenRects(const gfx::Rect& widget_screen_rect,
const gfx::Rect& window_screen_rect) { … }
void WidgetBase::SetPendingWindowRect(const gfx::Rect& rect) { … }
void WidgetBase::AckPendingWindowRect() { … }
gfx::Rect WidgetBase::WindowRect() { … }
gfx::Rect WidgetBase::ViewRect() { … }
gfx::Rect WidgetBase::CompositorViewportRect() const { … }
LCDTextPreference WidgetBase::ComputeLCDTextPreference() const { … }
void WidgetBase::CountDroppedPointerDownForEventTiming(unsigned count) { … }
gfx::PointF WidgetBase::DIPsToBlinkSpace(const gfx::PointF& point) { … }
gfx::Point WidgetBase::DIPsToRoundedBlinkSpace(const gfx::Point& point) { … }
gfx::PointF WidgetBase::BlinkSpaceToDIPs(const gfx::PointF& point) { … }
gfx::Point WidgetBase::BlinkSpaceToFlooredDIPs(const gfx::Point& point) { … }
gfx::Size WidgetBase::DIPsToCeiledBlinkSpace(const gfx::Size& size) { … }
gfx::RectF WidgetBase::DIPsToBlinkSpace(const gfx::RectF& rect) { … }
float WidgetBase::DIPsToBlinkSpace(float scalar) { … }
gfx::Size WidgetBase::BlinkSpaceToFlooredDIPs(const gfx::Size& size) { … }
gfx::Rect WidgetBase::BlinkSpaceToEnclosedDIPs(const gfx::Rect& rect) { … }
gfx::RectF WidgetBase::BlinkSpaceToDIPs(const gfx::RectF& rect) { … }
std::optional<int> WidgetBase::GetMaxRenderBufferBounds() const { … }
}