chromium/components/viz/service/frame_sinks/compositor_frame_sink_support.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/viz/service/frame_sinks/compositor_frame_sink_support.h"

#include <algorithm>
#include <string>
#include <utility>

#include "base/check.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/system/sys_info.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/typed_macros.h"
#include "build/build_config.h"
#include "cc/base/features.h"
#include "components/input/utils.h"
#include "components/viz/common/constants.h"
#include "components/viz/common/features.h"
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/quads/compositor_frame_metadata.h"
#include "components/viz/common/quads/compositor_render_pass.h"
#include "components/viz/common/resources/bitmap_allocation.h"
#include "components/viz/common/surfaces/surface_info.h"
#include "components/viz/common/surfaces/video_capture_target.h"
#include "components/viz/common/viz_utils.h"
#include "components/viz/service/display/display.h"
#include "components/viz/service/display/shared_bitmap_manager.h"
#include "components/viz/service/frame_sinks/frame_counter.h"
#include "components/viz/service/frame_sinks/frame_sink_bundle_impl.h"
#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
#include "components/viz/service/layers/layer_context_impl.h"
#include "components/viz/service/surfaces/surface.h"
#include "components/viz/service/surfaces/surface_reference.h"
#include "components/viz/service/transitions/surface_animation_manager.h"
#include "media/filters/video_cadence_estimator.h"
#include "mojo/public/cpp/system/platform_handle.h"

// This determines whether the provided time since last interval corresponds
// to a cadence frame that needs to be rendered.
bool HasElapsedCadenceInterval(
    base::TimeDelta render_interval,
    base::TimeDelta frame_duration,
    base::TimeDelta time_since_last_render_interval) {}

namespace viz {
namespace {

bool RecordShouldSendBeginFrame(const std::string& reason, bool should_send) {}

void AdjustPresentationFeedback(gfx::PresentationFeedback* feedback,
                                base::TimeTicks swap_start) {}

// Takes a given `rect` and then transforms it to a given space via
// `transform_to_space` to be interested by an `intersectee_in_space`, then
// transforms it back to its original space. NOTE: `transform_to_space` must be
// invertible.
gfx::Rect IntersectInSpace(const gfx::Rect& rect,
                           const gfx::Transform& transform_to_space,
                           const gfx::Rect& intersectee_in_space) {}

void RemoveSurfaceReferenceAndDispatchCopyOutputRequestCallback(
    base::WeakPtr<FrameSinkManagerImpl> frame_sink_manager,
    const SurfaceId& holds_ref_surface_id,
    const blink::SameDocNavigationScreenshotDestinationToken& destination_token,
    std::unique_ptr<CopyOutputResult> result) {}

}  // namespace

CompositorFrameSinkSupport::CompositorFrameSinkSupport(
    mojom::CompositorFrameSinkClient* client,
    FrameSinkManagerImpl* frame_sink_manager,
    const FrameSinkId& frame_sink_id,
    bool is_root)
    :{}

CompositorFrameSinkSupport::~CompositorFrameSinkSupport() {}

FrameTimingDetailsMap CompositorFrameSinkSupport::TakeFrameTimingDetailsMap() {}

void CompositorFrameSinkSupport::SetUpHitTest(
    LatestLocalSurfaceIdLookupDelegate* local_surface_id_lookup_delegate) {}

void CompositorFrameSinkSupport::SetAggregatedDamageCallbackForTesting(
    AggregatedDamageCallback callback) {}

void CompositorFrameSinkSupport::SetBeginFrameSource(
    BeginFrameSource* begin_frame_source) {}

void CompositorFrameSinkSupport::SetBundle(const FrameSinkBundleId& bundle_id) {}

void CompositorFrameSinkSupport::SetLastKnownVsync(
    base::TimeDelta vsync_interval) {}

bool CompositorFrameSinkSupport::ThrottleBeginFrame(base::TimeDelta interval,
                                                    bool simple_cadence_only) {}

void CompositorFrameSinkSupport::ApplyPreferredFrameRate(uint64_t source_id) {}

void CompositorFrameSinkSupport::OnSurfaceCommitted(Surface* surface) {}

void CompositorFrameSinkSupport::OnSurfaceActivated(Surface* surface) {}

void CompositorFrameSinkSupport::OnSurfaceWillDraw(Surface* surface) {}

void CompositorFrameSinkSupport::OnFrameTokenChanged(uint32_t frame_token) {}

void CompositorFrameSinkSupport::SendCompositorFrameAck() {}

void CompositorFrameSinkSupport::OnSurfaceAggregatedDamage(
    Surface* surface,
    const LocalSurfaceId& local_surface_id,
    const CompositorFrame& frame,
    const gfx::Rect& damage_rect,
    base::TimeTicks expected_display_time) {}

bool CompositorFrameSinkSupport::IsVideoCaptureStarted() {}

base::flat_set<base::PlatformThreadId>
CompositorFrameSinkSupport::GetThreadIds() {}

void CompositorFrameSinkSupport::OnSurfaceDestroyed(Surface* surface) {}

void CompositorFrameSinkSupport::OnSurfacePresented(
    uint32_t frame_token,
    base::TimeTicks draw_start_timestamp,
    const gfx::SwapTimings& swap_timings,
    const gfx::PresentationFeedback& feedback) {}

void CompositorFrameSinkSupport::RefResources(
    const std::vector<TransferableResource>& resources) {}

void CompositorFrameSinkSupport::UnrefResources(
    std::vector<ReturnedResource> resources) {}

void CompositorFrameSinkSupport::ReturnResources(
    std::vector<ReturnedResource> resources) {}

void CompositorFrameSinkSupport::ReceiveFromChild(
    const std::vector<TransferableResource>& resources) {}

std::vector<PendingCopyOutputRequest>
CompositorFrameSinkSupport::TakeCopyOutputRequests(
    const LocalSurfaceId& latest_local_id) {}

void CompositorFrameSinkSupport::EvictSurface(const LocalSurfaceId& id) {}

void CompositorFrameSinkSupport::MaybeEvictSurfaces() {}

void CompositorFrameSinkSupport::EvictLastActiveSurface() {}

void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) {}

void CompositorFrameSinkSupport::SetWantsAnimateOnlyBeginFrames() {}

void CompositorFrameSinkSupport::SetWantsBeginFrameAcks() {}

void CompositorFrameSinkSupport::SetAutoNeedsBeginFrame() {}

bool CompositorFrameSinkSupport::WantsAnimateOnlyBeginFrames() const {}

void CompositorFrameSinkSupport::InitializeCompositorFrameSinkType(
    mojom::CompositorFrameSinkType type) {}

void CompositorFrameSinkSupport::BindLayerContext(
    mojom::PendingLayerContext& context) {}

void CompositorFrameSinkSupport::SetThreadIds(
    bool from_untrusted_client,
    base::flat_set<base::PlatformThreadId> unverified_thread_ids) {}

void CompositorFrameSinkSupport::UpdateThreadIdsPostVerification(
    base::flat_set<base::PlatformThreadId> thread_ids,
    bool passed_verification) {}

base::TimeDelta CompositorFrameSinkSupport::GetPreferredFrameInterval(
    mojom::CompositorFrameSinkType* type) const {}

bool CompositorFrameSinkSupport::IsRoot() const {}

void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) {}

void CompositorFrameSinkSupport::SubmitCompositorFrame(
    const LocalSurfaceId& local_surface_id,
    CompositorFrame frame,
    std::optional<HitTestRegionList> hit_test_region_list,
    uint64_t submit_time) {}

bool CompositorFrameSinkSupport::DidAllocateSharedBitmap(
    base::ReadOnlySharedMemoryRegion region,
    const SharedBitmapId& id) {}

void CompositorFrameSinkSupport::DidDeleteSharedBitmap(
    const SharedBitmapId& id) {}

void CompositorFrameSinkSupport::SubmitCompositorFrameLocally(
    const SurfaceId& surface_id,
    CompositorFrame frame,
    const RendererSettings& settings) {}

SubmitResult CompositorFrameSinkSupport::MaybeSubmitCompositorFrame(
    const LocalSurfaceId& local_surface_id,
    CompositorFrame frame,
    std::optional<HitTestRegionList> hit_test_region_list,
    uint64_t submit_time,
    mojom::CompositorFrameSink::SubmitCompositorFrameSyncCallback callback) {}

SurfaceReference CompositorFrameSinkSupport::MakeTopLevelRootReference(
    const SurfaceId& surface_id) {}

void CompositorFrameSinkSupport::HandleCallback() {}

void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() {}

void CompositorFrameSinkSupport::DidPresentCompositorFrame(
    uint32_t frame_token,
    base::TimeTicks draw_start_timestamp,
    const gfx::SwapTimings& swap_timings,
    const gfx::PresentationFeedback& feedback) {}

void CompositorFrameSinkSupport::DidRejectCompositorFrame(
    uint32_t frame_token,
    std::vector<TransferableResource> frame_resource_list,
    std::vector<ui::LatencyInfo> latency_info) {}

void CompositorFrameSinkSupport::UpdateDisplayRootReference(
    const Surface* surface) {}

void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) {}

const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs()
    const {}

void CompositorFrameSinkSupport::OnBeginFrameSourcePausedChanged(bool paused) {}

void CompositorFrameSinkSupport::UpdateNeedsBeginFramesInternal() {}

void CompositorFrameSinkSupport::StartObservingBeginFrameSource() {}

void CompositorFrameSinkSupport::StopObservingBeginFrameSource() {}

const FrameSinkId& CompositorFrameSinkSupport::GetFrameSinkId() const {}

void CompositorFrameSinkSupport::AttachCaptureClient(
    CapturableFrameSink::Client* client) {}

void CompositorFrameSinkSupport::DetachCaptureClient(
    CapturableFrameSink::Client* client) {}

void CompositorFrameSinkSupport::OnClientCaptureStarted() {}

void CompositorFrameSinkSupport::OnClientCaptureStopped() {}

std::optional<CapturableFrameSink::RegionProperties>
CompositorFrameSinkSupport::GetRequestRegionProperties(
    const VideoCaptureSubTarget& sub_target) const {}

void CompositorFrameSinkSupport::RequestCopyOfOutput(
    PendingCopyOutputRequest pending_copy_output_request) {}

const CompositorFrameMetadata*
CompositorFrameSinkSupport::GetLastActivatedFrameMetadata() {}

HitTestAggregator* CompositorFrameSinkSupport::GetHitTestAggregator() {}

Surface* CompositorFrameSinkSupport::GetLastCreatedSurfaceForTesting() {}

// static
const char* CompositorFrameSinkSupport::GetSubmitResultAsString(
    SubmitResult result) {}

int64_t CompositorFrameSinkSupport::ComputeTraceId() {}

bool CompositorFrameSinkSupport::ShouldSendBeginFrame(
    base::TimeTicks frame_time,
    base::TimeDelta vsync_interval) {}

void CompositorFrameSinkSupport::CheckPendingSurfaces() {}

bool CompositorFrameSinkSupport::ShouldMergeBeginFrameWithAcks() const {}

bool CompositorFrameSinkSupport::ShouldThrottleBeginFrameAsRequested(
    base::TimeTicks frame_time,
    base::TimeDelta vsync_interval) {}

void CompositorFrameSinkSupport::ProcessCompositorFrameTransitionDirective(
    const CompositorFrameTransitionDirective& directive,
    Surface* surface) {}

void CompositorFrameSinkSupport::OnSaveTransitionDirectiveProcessed(
    const CompositorFrameTransitionDirective& directive) {}

bool CompositorFrameSinkSupport::IsEvicted(
    const LocalSurfaceId& local_surface_id) const {}

void CompositorFrameSinkSupport::ClearAllPendingCopyOutputRequests() {}

void CompositorFrameSinkSupport::SetExternalReservedResourceDelegate(
    ReservedResourceDelegate* delegate) {}

void CompositorFrameSinkSupport::SetLayerContextWantsBeginFrames(
    bool wants_begin_frames) {}

void CompositorFrameSinkSupport::DestroySelf() {}

void CompositorFrameSinkSupport::ScheduleSelfDestruction() {}

void CompositorFrameSinkSupport::ForAllReservedResourceDelegates(
    base::FunctionRef<void(ReservedResourceDelegate&)> func) {}

CompositorFrameSinkSupport::PendingFrameDetails::PendingFrameDetails(
    base::TimeTicks frame_submit_timestamp,
    SurfaceManager* surface_manager)
    :{}

void CompositorFrameSinkSupport::PendingFrameDetails::
    SetOrObserveFrameEmbedTimeStamp() {}

CompositorFrameSinkSupport::PendingFrameDetails::~PendingFrameDetails() {}

void CompositorFrameSinkSupport::PendingFrameDetails::set_surface_id(
    SurfaceId surface_id) {}

void CompositorFrameSinkSupport::PendingFrameDetails::OnAddedSurfaceReference(
    const SurfaceId& parent_id,
    const SurfaceId& child_id) {}

}  // namespace viz