#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <string_view>
#include <utility>
#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/queue.h"
#include "base/debug/alias.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/observer_list.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "components/input/utils.h"
#include "components/viz/common/performance_hint_utils.h"
#include "components/viz/common/surfaces/subtree_capture_id.h"
#include "components/viz/common/surfaces/video_capture_target.h"
#include "components/viz/service/display/overdraw_tracker.h"
#include "components/viz/service/display/shared_bitmap_manager.h"
#include "components/viz/service/display_embedder/output_surface_provider.h"
#include "components/viz/service/frame_sinks/compositor_frame_sink_support.h"
#include "components/viz/service/frame_sinks/frame_sink_bundle_impl.h"
#include "components/viz/service/frame_sinks/shared_image_interface_provider.h"
#include "components/viz/service/frame_sinks/video_capture/capturable_frame_sink.h"
#include "components/viz/service/frame_sinks/video_capture/frame_sink_video_capturer_impl.h"
#include "components/viz/service/input/input_manager.h"
#include "components/viz/service/surfaces/pending_copy_output_request.h"
#include "components/viz/service/surfaces/surface.h"
#include "services/viz/privileged/mojom/compositing/frame_sink_manager.mojom.h"
namespace viz {
FrameSinkManagerImpl::InitParams::InitParams() = default;
FrameSinkManagerImpl::InitParams::InitParams(
SharedBitmapManager* shared_bitmap_manager,
OutputSurfaceProvider* output_surface_provider,
GmbVideoFramePoolContextProvider* gmb_context_provider)
: … { … }
FrameSinkManagerImpl::InitParams::InitParams(InitParams&& other) = default;
FrameSinkManagerImpl::InitParams::~InitParams() = default;
FrameSinkManagerImpl::InitParams& FrameSinkManagerImpl::InitParams::operator=(
InitParams&& other) = default;
FrameSinkManagerImpl::FrameSinkSourceMapping::FrameSinkSourceMapping() =
default;
FrameSinkManagerImpl::FrameSinkSourceMapping::FrameSinkSourceMapping(
FrameSinkSourceMapping&& other) = default;
FrameSinkManagerImpl::FrameSinkSourceMapping::~FrameSinkSourceMapping() =
default;
FrameSinkManagerImpl::FrameSinkSourceMapping&
FrameSinkManagerImpl::FrameSinkSourceMapping::operator=(
FrameSinkSourceMapping&& other) = default;
FrameSinkManagerImpl::FrameSinkData::FrameSinkData(bool report_activation)
: … { … }
FrameSinkManagerImpl::FrameSinkData::FrameSinkData(FrameSinkData&& other) =
default;
FrameSinkManagerImpl::FrameSinkData::~FrameSinkData() = default;
FrameSinkManagerImpl::FrameSinkData& FrameSinkManagerImpl::FrameSinkData::
operator=(FrameSinkData&& other) = default;
FrameSinkManagerImpl::FrameSinkManagerImpl(const InitParams& params)
: … { … }
FrameSinkManagerImpl::~FrameSinkManagerImpl() { … }
CompositorFrameSinkImpl* FrameSinkManagerImpl::GetFrameSinkImpl(
const FrameSinkId& id) { … }
FrameSinkBundleImpl* FrameSinkManagerImpl::GetFrameSinkBundle(
const FrameSinkBundleId& id) { … }
void FrameSinkManagerImpl::BindAndSetClient(
mojo::PendingReceiver<mojom::FrameSinkManager> receiver,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
mojo::PendingRemote<mojom::FrameSinkManagerClient> client,
SharedImageInterfaceProvider* shared_image_interface_provider) { … }
void FrameSinkManagerImpl::SetLocalClient(
mojom::FrameSinkManagerClient* client,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { … }
void FrameSinkManagerImpl::SetInputManagerForTesting(
std::unique_ptr<InputManager> input_manager) { … }
void FrameSinkManagerImpl::RegisterFrameSinkId(const FrameSinkId& frame_sink_id,
bool report_activation) { … }
void FrameSinkManagerImpl::InvalidateFrameSinkId(
const FrameSinkId& frame_sink_id) { … }
void FrameSinkManagerImpl::SetFrameSinkDebugLabel(
const FrameSinkId& frame_sink_id,
const std::string& debug_label) { … }
void FrameSinkManagerImpl::CreateRootCompositorFrameSink(
mojom::RootCompositorFrameSinkParamsPtr params) { … }
void FrameSinkManagerImpl::CreateFrameSinkBundle(
const FrameSinkBundleId& bundle_id,
mojo::PendingReceiver<mojom::FrameSinkBundle> receiver,
mojo::PendingRemote<mojom::FrameSinkBundleClient> client) { … }
void FrameSinkManagerImpl::CreateCompositorFrameSink(
const FrameSinkId& frame_sink_id,
const std::optional<FrameSinkBundleId>& bundle_id,
mojo::PendingReceiver<mojom::CompositorFrameSink> receiver,
mojo::PendingRemote<mojom::CompositorFrameSinkClient> client,
input::mojom::RenderInputRouterConfigPtr render_input_router_config) { … }
void FrameSinkManagerImpl::DestroyCompositorFrameSink(
const FrameSinkId& frame_sink_id,
DestroyCompositorFrameSinkCallback callback) { … }
void FrameSinkManagerImpl::RegisterFrameSinkHierarchy(
const FrameSinkId& parent_frame_sink_id,
const FrameSinkId& child_frame_sink_id) { … }
void FrameSinkManagerImpl::UnregisterFrameSinkHierarchy(
const FrameSinkId& parent_frame_sink_id,
const FrameSinkId& child_frame_sink_id) { … }
void FrameSinkManagerImpl::AddVideoDetectorObserver(
mojo::PendingRemote<mojom::VideoDetectorObserver> observer) { … }
void FrameSinkManagerImpl::CreateVideoCapturer(
mojo::PendingReceiver<mojom::FrameSinkVideoCapturer> receiver) { … }
void FrameSinkManagerImpl::EvictSurfaces(
const std::vector<SurfaceId>& surface_ids) { … }
void FrameSinkManagerImpl::RequestCopyOfOutput(
const SurfaceId& surface_id,
std::unique_ptr<CopyOutputRequest> request,
bool capture_exact_surface_id) { … }
void FrameSinkManagerImpl::DestroyFrameSinkBundle(const FrameSinkBundleId& id) { … }
void FrameSinkManagerImpl::OnFirstSurfaceActivation(
const SurfaceInfo& surface_info) { … }
void FrameSinkManagerImpl::OnAggregatedHitTestRegionListUpdated(
const FrameSinkId& frame_sink_id,
const std::vector<AggregatedHitTestRegion>& hit_test_data) { … }
std::string_view FrameSinkManagerImpl::GetFrameSinkDebugLabel(
const FrameSinkId& frame_sink_id) const { … }
void FrameSinkManagerImpl::AggregatedFrameSinksChanged() { … }
void FrameSinkManagerImpl::RegisterCompositorFrameSinkSupport(
const FrameSinkId& frame_sink_id,
CompositorFrameSinkSupport* support) { … }
void FrameSinkManagerImpl::UnregisterCompositorFrameSinkSupport(
const FrameSinkId& frame_sink_id) { … }
void FrameSinkManagerImpl::RegisterBeginFrameSource(
BeginFrameSource* source,
const FrameSinkId& frame_sink_id) { … }
void FrameSinkManagerImpl::UnregisterBeginFrameSource(
BeginFrameSource* source) { … }
void FrameSinkManagerImpl::RecursivelyAttachBeginFrameSource(
const FrameSinkId& frame_sink_id,
BeginFrameSource* source) { … }
void FrameSinkManagerImpl::RecursivelyDetachBeginFrameSource(
const FrameSinkId& frame_sink_id,
BeginFrameSource* source) { … }
CapturableFrameSink* FrameSinkManagerImpl::FindCapturableFrameSink(
const VideoCaptureTarget& target) { … }
void FrameSinkManagerImpl::OnCapturerConnectionLost(
FrameSinkVideoCapturerImpl* capturer) { … }
bool FrameSinkManagerImpl::ChildContains(
const FrameSinkId& child_frame_sink_id,
const FrameSinkId& search_frame_sink_id) const { … }
InputManager* FrameSinkManagerImpl::GetInputManager() { … }
void FrameSinkManagerImpl::SubmitHitTestRegionList(
const SurfaceId& surface_id,
uint64_t frame_index,
std::optional<HitTestRegionList> hit_test_region_list) { … }
void FrameSinkManagerImpl::OnFrameTokenChangedDirect(
const FrameSinkId& frame_sink_id,
uint32_t frame_token,
base::TimeTicks activation_time) { … }
void FrameSinkManagerImpl::OnFrameTokenChanged(const FrameSinkId& frame_sink_id,
uint32_t frame_token) { … }
VideoDetector* FrameSinkManagerImpl::CreateVideoDetectorForTesting(
const base::TickClock* tick_clock,
scoped_refptr<base::SequencedTaskRunner> task_runner) { … }
void FrameSinkManagerImpl::DidBeginFrame(const FrameSinkId& frame_sink_id,
const BeginFrameArgs& args) { … }
void FrameSinkManagerImpl::DidFinishFrame(const FrameSinkId& frame_sink_id,
const BeginFrameArgs& args) { … }
void FrameSinkManagerImpl::AddObserver(FrameSinkObserver* obs) { … }
void FrameSinkManagerImpl::RemoveObserver(FrameSinkObserver* obs) { … }
std::vector<FrameSinkId> FrameSinkManagerImpl::GetRegisteredFrameSinkIds()
const { … }
base::flat_set<FrameSinkId> FrameSinkManagerImpl::GetChildrenByParent(
const FrameSinkId& parent_frame_sink_id) const { … }
CompositorFrameSinkSupport* FrameSinkManagerImpl::GetFrameSinkForId(
const FrameSinkId& frame_sink_id) const { … }
base::TimeDelta FrameSinkManagerImpl::GetPreferredFrameIntervalForFrameSinkId(
const FrameSinkId& id,
mojom::CompositorFrameSinkType* type) const { … }
void FrameSinkManagerImpl::DiscardPendingCopyOfOutputRequests(
const BeginFrameSource* source) { … }
void FrameSinkManagerImpl::OnCaptureStarted(const FrameSinkId& id) { … }
void FrameSinkManagerImpl::OnCaptureStopped(const FrameSinkId& id) { … }
void FrameSinkManagerImpl::VerifySandboxedThreadIds(
const base::flat_set<base::PlatformThreadId>& thread_ids,
base::OnceCallback<void(bool)> verification_callback) { … }
#if BUILDFLAG(IS_ANDROID)
void FrameSinkManagerImpl::CacheBackBuffer(
uint32_t cache_id,
const FrameSinkId& root_frame_sink_id) {
auto it = root_sink_map_.find(root_frame_sink_id);
if (it == root_sink_map_.end())
return;
DCHECK(!base::Contains(cached_back_buffers_, cache_id));
cached_back_buffers_[cache_id] = it->second->GetCacheBackBufferCb();
}
void FrameSinkManagerImpl::EvictBackBuffer(uint32_t cache_id,
EvictBackBufferCallback callback) {
cached_back_buffers_.erase(cache_id);
std::move(callback).Run();
}
#endif
void FrameSinkManagerImpl::UpdateDebugRendererSettings(
const DebugRendererSettings& debug_settings) { … }
void FrameSinkManagerImpl::UpdateThrottlingRecursively(
const FrameSinkId& frame_sink_id,
base::TimeDelta interval) { … }
void FrameSinkManagerImpl::Throttle(const std::vector<FrameSinkId>& ids,
base::TimeDelta interval) { … }
void FrameSinkManagerImpl::StartThrottlingAllFrameSinks(
base::TimeDelta interval) { … }
void FrameSinkManagerImpl::StopThrottlingAllFrameSinks() { … }
void FrameSinkManagerImpl::UpdateThrottling() { … }
void FrameSinkManagerImpl::ClearThrottling(const FrameSinkId& id) { … }
void FrameSinkManagerImpl::CacheSurfaceAnimationManager(
const blink::ViewTransitionToken& transition_token,
std::unique_ptr<SurfaceAnimationManager> manager) { … }
std::unique_ptr<SurfaceAnimationManager>
FrameSinkManagerImpl::TakeSurfaceAnimationManager(
const blink::ViewTransitionToken& transition_token) { … }
bool FrameSinkManagerImpl::ClearSurfaceAnimationManager(
const blink::ViewTransitionToken& transition_token) { … }
void FrameSinkManagerImpl::OnScreenshotCaptured(
const blink::SameDocNavigationScreenshotDestinationToken& destination_token,
std::unique_ptr<CopyOutputResult> copy_output_result) { … }
gpu::SharedImageInterface* FrameSinkManagerImpl::GetSharedImageInterface() { … }
void FrameSinkManagerImpl::StartFrameCounting(base::TimeTicks start_time,
base::TimeDelta bucket_size) { … }
void FrameSinkManagerImpl::StopFrameCounting(
StopFrameCountingCallback callback) { … }
void FrameSinkManagerImpl::StartOverdrawTracking(
const FrameSinkId& root_frame_sink_id,
base::TimeDelta bucket_size) { … }
void FrameSinkManagerImpl::StopOverdrawTracking(
const FrameSinkId& root_frame_sink_id,
StopOverdrawTrackingCallback callback) { … }
void FrameSinkManagerImpl::HasUnclaimedViewTransitionResources(
HasUnclaimedViewTransitionResourcesCallback callback) { … }
void FrameSinkManagerImpl::SetSameDocNavigationScreenshotSize(
const gfx::Size& result_size,
SetSameDocNavigationScreenshotSizeCallback callback) { … }
void FrameSinkManagerImpl::ClearUnclaimedViewTransitionResources(
const blink::ViewTransitionToken& transition_token) { … }
void FrameSinkManagerImpl::CreateMetricsRecorderForTest(
mojo::PendingReceiver<mojom::FrameSinksMetricsRecorder> receiver) { … }
void FrameSinkManagerImpl::EnableFrameSinkManagerTestApi(
mojo::PendingReceiver<mojom::FrameSinkManagerTestApi> receiver) { … }
void FrameSinkManagerImpl::RequestBeginFrameForGpuService(bool toggle) { … }
}