chromium/components/viz/service/display/display.cc

// Copyright 2014 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/display/display.h"

#include <stddef.h>

#include <algorithm>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <utility>

#include "base/check.h"
#include "base/containers/contains.h"
#include "base/debug/dump_without_crashing.h"
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/common/trace_event_common.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "base/trace_event/typed_macros.h"
#include "build/build_config.h"
#include "cc/base/math_util.h"
#include "cc/base/region.h"
#include "cc/base/simple_enclosed_region.h"
#include "components/viz/common/display/renderer_settings.h"
#include "components/viz/common/features.h"
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/common/quads/aggregated_render_pass_draw_quad.h"
#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/quads/draw_quad.h"
#include "components/viz/common/quads/shared_quad_state.h"
#include "components/viz/common/switches.h"
#include "components/viz/common/viz_utils.h"
#include "components/viz/service/debugger/viz_debugger.h"
#include "components/viz/service/display/aggregated_frame.h"
#include "components/viz/service/display/damage_frame_annotator.h"
#include "components/viz/service/display/delegated_ink_point_renderer_base.h"
#include "components/viz/service/display/direct_renderer.h"
#include "components/viz/service/display/display_client.h"
#include "components/viz/service/display/display_resource_provider_null.h"
#include "components/viz/service/display/display_resource_provider_skia.h"
#include "components/viz/service/display/display_resource_provider_software.h"
#include "components/viz/service/display/display_scheduler.h"
#include "components/viz/service/display/display_utils.h"
#include "components/viz/service/display/frame_interval_decider.h"
#include "components/viz/service/display/frame_interval_matchers.h"
#include "components/viz/service/display/null_renderer.h"
#include "components/viz/service/display/occlusion_culler.h"
#include "components/viz/service/display/output_surface.h"
#include "components/viz/service/display/overdraw_tracker.h"
#include "components/viz/service/display/overlay_candidate_factory.h"
#include "components/viz/service/display/renderer_utils.h"
#include "components/viz/service/display/skia_output_surface.h"
#include "components/viz/service/display/skia_renderer.h"
#include "components/viz/service/display/software_renderer.h"
#include "components/viz/service/display/surface_aggregator.h"
#include "components/viz/service/surfaces/surface.h"
#include "components/viz/service/surfaces/surface_manager.h"
#include "gpu/command_buffer/common/swap_buffers_complete_params.h"
#include "gpu/command_buffer/service/scheduler.h"
#include "gpu/command_buffer/service/scheduler_sequence.h"
#include "gpu/command_buffer/service/shared_image/shared_image_format_service_utils.h"
#include "services/viz/public/mojom/compositing/compositor_frame_sink.mojom.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/chrome_latency_info.pbzero.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gpu_fence_handle.h"
#include "ui/gfx/overlay_transform.h"
#include "ui/gfx/overlay_transform_utils.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/gfx/swap_result.h"

#if BUILDFLAG(IS_ANDROID)
#include "ui/gfx/android/android_surface_control_compat.h"
#endif
namespace viz {

namespace {

#if !BUILDFLAG(IS_MAC)
constexpr base::TimeDelta kAllowedDeltaFromFuture =;
#endif

// Assign each Display instance a starting value for the the display-trace id,
// so that multiple Displays all don't start at 0, because that makes it
// difficult to associate the trace-events with the particular displays.
int64_t GetStartingTraceId() {}

gfx::PresentationFeedback SanitizePresentationFeedback(
    const gfx::PresentationFeedback& feedback,
    base::TimeTicks draw_time) {}

void IssueDisplayRenderingStatsEvent() {}

}  // namespace

constexpr base::TimeDelta Display::kDrawToSwapMin;
constexpr base::TimeDelta Display::kDrawToSwapMax;

Display::PresentationGroupTiming::PresentationGroupTiming() = default;

Display::PresentationGroupTiming::PresentationGroupTiming(
    Display::PresentationGroupTiming&& other) = default;

Display::PresentationGroupTiming::~PresentationGroupTiming() = default;

void Display::PresentationGroupTiming::AddPresentationHelper(
    std::unique_ptr<Surface::PresentationHelper> helper) {}

void Display::PresentationGroupTiming::OnDraw(
    base::TimeTicks frame_time,
    base::TimeTicks draw_start_timestamp,
    base::flat_set<base::PlatformThreadId> thread_ids,
    HintSession::BoostType boost_type) {}

void Display::PresentationGroupTiming::OnSwap(gfx::SwapTimings timings,
                                              DisplaySchedulerBase* scheduler) {}

void Display::PresentationGroupTiming::OnPresent(
    const gfx::PresentationFeedback& feedback) {}

Display::Display(
    SharedBitmapManager* bitmap_manager,
    gpu::SharedImageManager* shared_image_manager,
    gpu::SyncPointManager* sync_point_manager,
    gpu::Scheduler* gpu_scheduler,
    const RendererSettings& settings,
    const DebugRendererSettings* debug_settings,
    const FrameSinkId& frame_sink_id,
    std::unique_ptr<DisplayCompositorMemoryAndTaskController> gpu_dependency,
    std::unique_ptr<OutputSurface> output_surface,
    std::unique_ptr<OverlayProcessorInterface> overlay_processor,
    std::unique_ptr<DisplaySchedulerBase> scheduler,
    scoped_refptr<base::SingleThreadTaskRunner> current_task_runner)
    :{}

Display::~Display() {}

void Display::Initialize(DisplayClient* client,
                         SurfaceManager* surface_manager,
                         bool hw_support_for_multiple_refresh_rates) {}

void Display::AddObserver(DisplayObserver* observer) {}

void Display::RemoveObserver(DisplayObserver* observer) {}

void Display::SetLocalSurfaceId(const LocalSurfaceId& id,
                                float device_scale_factor) {}

void Display::SetVisible(bool visible) {}

void Display::Resize(const gfx::Size& size) {}

void Display::SetOutputSurfaceClipRect(const gfx::Rect& clip_rect) {}

void Display::InvalidateCurrentSurfaceId() {}

void Display::DisableSwapUntilResize(
    base::OnceClosure no_pending_swaps_callback) {}

void Display::SetColorMatrix(const SkM44& matrix) {}

void Display::SetDisplayColorSpaces(
    const gfx::DisplayColorSpaces& display_color_spaces) {}

void Display::SetOutputIsSecure(bool secure) {}

void Display::InitializeRenderer() {}

bool Display::IsRootFrameMissing() const {}

bool Display::HasPendingSurfaces(const BeginFrameArgs& args) const {}

void Display::OnContextLost() {}

namespace {

DBG_FLAG_FBOOL("frame.debug.non_root_passes", debug_non_root_passes)

DBG_FLAG_FBOOL("frame.render_pass.non_root_passes_in_root_space",
               non_root_passes_in_root_space)

void DebugDrawFrame(
    const AggregatedFrame& frame,
    const std::unique_ptr<DisplayResourceProvider>& resource_provider) {}

void DebugDrawFrameVisible(const AggregatedFrame& frame) {}

void VisualDebuggerSync(gfx::OverlayTransform current_display_transform,
                        gfx::Size current_surface_size,
                        int64_t last_presented_trace_id) {}

}  // namespace

void Display::MaybeLogQuadsProperties(
    AggregatedRenderPass& last_render_pass,
    const SurfaceDamageRectList* surface_damage_rect_list) {}

void Display::StartTrackingOverdraw(int interval_length_in_seconds) {}

OverdrawTracker::OverdrawTimeSeries Display::StopTrackingOverdraw() {}

bool Display::DrawAndSwap(const DrawAndSwapParams& params) {}

void Display::DidReceiveSwapBuffersAck(
    const gpu::SwapBuffersCompleteParams& params,
    gfx::GpuFenceHandle release_fence) {}

void Display::DidReceiveCALayerParams(
    const gfx::CALayerParams& ca_layer_params) {}

void Display::DidSwapWithSize(const gfx::Size& pixel_size) {}

void Display::DidReceivePresentationFeedback(
    const gfx::PresentationFeedback& feedback) {}

void Display::DidReceiveReleasedOverlays(
    const std::vector<gpu::Mailbox>& released_overlays) {}

void Display::AddChildWindowToBrowser(gpu::SurfaceHandle child_window) {}

void Display::DidFinishFrame(const BeginFrameAck& ack) {}

const SurfaceId& Display::CurrentSurfaceId() const {}

LocalSurfaceId Display::GetSurfaceAtAggregation(
    const FrameSinkId& frame_sink_id) const {}

void Display::SoftwareDeviceUpdatedCALayerParams(
    const gfx::CALayerParams& ca_layer_params) {}

void Display::ForceImmediateDrawAndSwapIfPossible() {}

void Display::SetNeedsOneBeginFrame() {}

void Display::SetPreferredFrameInterval(base::TimeDelta interval) {}

base::TimeDelta Display::GetPreferredFrameIntervalForFrameSinkId(
    const FrameSinkId& id,
    mojom::CompositorFrameSinkType* type) {}

void Display::SetSupportedFrameIntervals(
    base::flat_set<base::TimeDelta> intervals) {}

void Display::SetHwSupportForMultipleRefreshRates(bool support) {}

#if BUILDFLAG(IS_ANDROID)
bool Display::OutputSurfaceSupportsSetFrameRate() {
  return output_surface_ &&
         output_surface_->capabilities().supports_surfaceless &&
         gfx::SurfaceControl::SupportsSetFrameRate();
}

void Display::SetFrameIntervalOnOutputSurface(base::TimeDelta interval) {
  float interval_s = interval.InSecondsF();
  float frame_rate = interval_s == 0 ? 0 : (1 / interval_s);
  output_surface_->SetFrameRate(frame_rate);
}

base::ScopedClosureRunner Display::GetCacheBackBufferCb() {
  return output_surface_->GetCacheBackBufferCb();
}
#endif

void Display::DisableGPUAccessByDefault() {}

void Display::PreserveChildSurfaceControls() {}

void Display::InitDelegatedInkPointRendererReceiver(
    mojo::PendingReceiver<gfx::mojom::DelegatedInkPointRenderer>
        pending_receiver) {}

void Display::ResetDisplayClientForTesting(DisplayClient* old_client) {}

}  // namespace viz