#include "components/viz/service/surfaces/surface_manager.h"
#include <stddef.h>
#include <stdint.h>
#include <string_view>
#include <utility>
#include <vector>
#include "base/containers/adapters.h"
#include "base/containers/queue.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/default_tick_clock.h"
#include "base/trace_event/trace_event.h"
#include "components/viz/common/features.h"
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "components/viz/common/surfaces/surface_info.h"
#include "components/viz/service/surfaces/surface.h"
#include "components/viz/service/surfaces/surface_allocation_group.h"
#include "components/viz/service/surfaces/surface_client.h"
#include "components/viz/service/surfaces/surface_manager_delegate.h"
#if DCHECK_IS_ON()
#include <sstream>
#endif
namespace viz {
namespace {
constexpr base::TimeDelta kExpireInterval = …;
SurfaceObserver::HandleInteraction GetHandleInteraction(
const CompositorFrameMetadata& metadata) { … }
}
SurfaceManager::SurfaceManager(
SurfaceManagerDelegate* delegate,
std::optional<uint32_t> activation_deadline_in_frames,
size_t max_uncommitted_frames)
: … { … }
SurfaceManager::~SurfaceManager() { … }
#if DCHECK_IS_ON()
std::string SurfaceManager::SurfaceReferencesToString() { … }
#endif
void SurfaceManager::SetActivationDeadlineInFramesForTesting(
std::optional<uint32_t> activation_deadline_in_frames) { … }
void SurfaceManager::SetTickClockForTesting(const base::TickClock* tick_clock) { … }
Surface* SurfaceManager::CreateSurface(
base::WeakPtr<SurfaceClient> surface_client,
const SurfaceInfo& surface_info,
const SurfaceId& pending_copy_surface_id) { … }
void SurfaceManager::MarkSurfaceForDestruction(const SurfaceId& surface_id) { … }
void SurfaceManager::InvalidateFrameSinkId(const FrameSinkId& frame_sink_id) { … }
const SurfaceId& SurfaceManager::GetRootSurfaceId() const { … }
std::vector<SurfaceId> SurfaceManager::GetCreatedSurfaceIds() const { … }
void SurfaceManager::AddSurfaceReferences(
const std::vector<SurfaceReference>& references) { … }
void SurfaceManager::RemoveSurfaceReferences(
const std::vector<SurfaceReference>& references) { … }
void SurfaceManager::GarbageCollectSurfaces() { … }
const base::flat_set<SurfaceId>& SurfaceManager::GetSurfacesReferencedByParent(
const SurfaceId& surface_id) const { … }
base::flat_set<SurfaceId>
SurfaceManager::GetSurfacesThatReferenceChildForTesting(
const SurfaceId& surface_id) const { … }
base::TimeTicks SurfaceManager::GetSurfaceReferencedTimestamp(
const SurfaceId& surface_id) const { … }
SurfaceManager::SurfaceIdSet SurfaceManager::GetLiveSurfaces() { … }
void SurfaceManager::AddSurfaceReferenceImpl(
const SurfaceReference& reference) { … }
void SurfaceManager::RemoveSurfaceReferenceImpl(
const SurfaceReference& reference) { … }
bool SurfaceManager::HasTemporaryReference(const SurfaceId& surface_id) const { … }
void SurfaceManager::AddTemporaryReference(const SurfaceId& surface_id) { … }
void SurfaceManager::RemoveTemporaryReferenceImpl(const SurfaceId& surface_id,
RemovedReason reason) { … }
Surface* SurfaceManager::GetLatestInFlightSurface(
const SurfaceRange& surface_range) { … }
void SurfaceManager::ExpireOldTemporaryReferences() { … }
Surface* SurfaceManager::GetSurfaceForId(const SurfaceId& surface_id) const { … }
bool SurfaceManager::SurfaceModified(
const SurfaceId& surface_id,
const BeginFrameAck& ack,
SurfaceObserver::HandleInteraction handle_interaction) { … }
void SurfaceManager::FirstSurfaceActivation(const SurfaceInfo& surface_info) { … }
void SurfaceManager::OnSurfaceHasNewUncommittedFrame(Surface* surface) { … }
void SurfaceManager::SurfaceActivated(Surface* surface) { … }
bool SurfaceManager::ShouldAckInteractiveFrame(const BeginFrameAck& ack) const { … }
void SurfaceManager::SurfaceDestroyed(Surface* surface) { … }
void SurfaceManager::SurfaceDamageExpected(const SurfaceId& surface_id,
const BeginFrameArgs& args) { … }
void SurfaceManager::DestroySurfaceInternal(const SurfaceId& surface_id) { … }
#if DCHECK_IS_ON()
void SurfaceManager::SurfaceReferencesToStringImpl(const SurfaceId& surface_id,
std::string indent,
std::stringstream* str) { … }
#endif
bool SurfaceManager::IsMarkedForDestruction(const SurfaceId& surface_id) { … }
void SurfaceManager::SurfaceWillBeDrawn(Surface* surface) { … }
void SurfaceManager::DropTemporaryReference(const SurfaceId& surface_id) { … }
SurfaceAllocationGroup* SurfaceManager::GetOrCreateAllocationGroupForSurfaceId(
const SurfaceId& surface_id) { … }
SurfaceAllocationGroup* SurfaceManager::GetAllocationGroupForSurfaceId(
const SurfaceId& surface_id) { … }
void SurfaceManager::SetAllocationGroupsNeedGarbageCollection() { … }
void SurfaceManager::MaybeGarbageCollectAllocationGroups() { … }
bool SurfaceManager::HasBlockedEmbedder(
const FrameSinkId& frame_sink_id) const { … }
void SurfaceManager::AggregatedFrameSinksChanged() { … }
void SurfaceManager::CommitFramesInRangeRecursively(
const SurfaceRange& range,
const CommitPredicate& predicate) { … }
}