#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/viz/service/display/overlay_processor_using_strategy.h"
#include <algorithm>
#include <iterator>
#include <memory>
#include <optional>
#include <set>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/containers/flat_set.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/viz/common/display/overlay_strategy.h"
#include "components/viz/common/features.h"
#include "components/viz/common/quads/aggregated_render_pass.h"
#include "components/viz/common/quads/quad_list.h"
#include "components/viz/common/quads/solid_color_draw_quad.h"
#include "components/viz/common/quads/texture_draw_quad.h"
#include "components/viz/service/debugger/viz_debugger.h"
#include "components/viz/service/display/display_resource_provider.h"
#include "components/viz/service/display/output_surface.h"
#include "components/viz/service/display/overlay_candidate.h"
#include "components/viz/service/display/overlay_combination_cache.h"
#include "components/viz/service/display/overlay_proposed_candidate.h"
#include "components/viz/service/display/overlay_strategy_single_on_top.h"
#include "components/viz/service/display/overlay_strategy_underlay.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/transform.h"
namespace viz {
namespace {
enum class AttemptingMultipleOverlays { … };
enum class PromotingMaskCandidates { … };
constexpr char kNumOverlaysPromotedHistogramName[] = …;
constexpr char kNumOverlaysAttemptedHistogramName[] = …;
constexpr char kNumOverlaysFailedHistogramName[] = …;
constexpr char kWorkingScaleFactorHistogramName[] = …;
constexpr char kFramesAttemptingRequiredOverlaysHistogramName[] = …;
constexpr char kFramesScalingRequiredOverlaysHistogramName[] = …;
constexpr char kFramesWithMaskCandidatesRequireOverlaysHistogramName[] = …;
constexpr char kFramesWithMaskCandidatesHistogramName[] = …;
constexpr char kShouldPromoteCandidatesWithMasksHistogramName[] = …;
OverlayProposedCandidateIndex;
ConstOverlayProposedCandidateIterator;
static void LogShouldPromoteCandidatesWithMasksEnumUMA(
PromotingMaskCandidates attempt) { … }
static void LogFramesWithMaskCandidatesBoolUMA(
const std::vector<OverlayProposedCandidate>& proposed_candidates) { … }
ConstOverlayProposedCandidateIterator MaybeAppendOccludingMaskCandidates(
ConstOverlayProposedCandidateIterator candidates_wth_masks_begin,
ConstOverlayProposedCandidateIterator candidates_wth_masks_end,
std::vector<OverlayProposedCandidate>& test_candidates) { … }
bool IsOccludedByMaskCandidates(
const OverlayProposedCandidate& candidate,
const std::vector<OverlayProposedCandidate*>& mask_candidates) { … }
struct OverlayTestResults { … };
OverlayTestResults ProcessOverlayTestResults(
std::vector<OverlayProposedCandidate>& test_candidates) { … }
float GetMinScaleFactor(const OverlayCandidate& candidate) { … }
void ScaleCandidateSrcRect(const gfx::RectF& org_src_rect,
float scale_factor,
OverlayCandidate* candidate) { … }
void SyncOverlayCandidates(
std::vector<OverlayProposedCandidate>& proposed_candidates,
std::vector<OverlayCandidate>& candidates,
bool copy_from_proposed_candidates) { … }
}
static void LogStrategyEnumUMA(OverlayStrategy strategy) { … }
static void LogFramesAttemptingRequiredCandidateBoolUMA(
const std::vector<OverlayProposedCandidate>& proposed_candidates) { … }
static void LogWorkingScaleFactorCountUMA(float scale_factor) { … }
static void LogFramesScalingRequiredCandidateBoolUMA(bool attempted_scaling) { … }
OverlayProcessorUsingStrategy::OverlayProcessorUsingStrategy()
: … { … }
OverlayProcessorUsingStrategy::~OverlayProcessorUsingStrategy() = default;
gfx::Rect OverlayProcessorUsingStrategy::GetPreviousFrameOverlaysBoundingRect()
const { … }
gfx::Rect OverlayProcessorUsingStrategy::GetAndResetOverlayDamage() { … }
void OverlayProcessorUsingStrategy::NotifyOverlayPromotion(
DisplayResourceProvider* display_resource_provider,
const CandidateList& candidates,
const QuadList& quad_list) { … }
void OverlayProcessorUsingStrategy::SetFrameSequenceNumber(
uint64_t frame_sequence_number) { … }
DBG_FLAG_FBOOL("processor.overlay.disable", disable_overlay)
void OverlayProcessorUsingStrategy::ProcessForOverlays(
DisplayResourceProvider* resource_provider,
AggregatedRenderPassList* render_passes,
const SkM44& output_color_matrix,
const OverlayProcessorInterface::FilterOperationsMap& render_pass_filters,
const OverlayProcessorInterface::FilterOperationsMap&
render_pass_backdrop_filters,
SurfaceDamageRectList surface_damage_rect_list,
OutputSurfaceOverlayPlane* output_surface_plane,
CandidateList* candidates,
gfx::Rect* damage_rect,
std::vector<gfx::Rect>* content_bounds) { … }
void OverlayProcessorUsingStrategy::CheckOverlaySupport(
const OverlayProcessorInterface::OutputSurfaceOverlayPlane* primary_plane,
OverlayCandidateList* candidate_list) { … }
void OverlayProcessorUsingStrategy::ClearOverlayCombinationCache() { … }
gfx::Rect OverlayProcessorUsingStrategy::ComputeDamageExcludingOverlays(
const SurfaceDamageRectList& surface_damage_rect_list,
const gfx::Rect& existing_damage) { … }
OverlayProcessorUsingStrategy::OverlayStatus::OverlayStatus(
const OverlayCandidate& candidate,
const gfx::Rect& key,
const OverlayStatusMap& prev_overlays) { … }
OverlayProcessorUsingStrategy::OverlayStatus::OverlayStatus(
const OverlayStatus&) = default;
OverlayProcessorUsingStrategy::OverlayStatus&
OverlayProcessorUsingStrategy::OverlayStatus::operator=(const OverlayStatus&) =
default;
OverlayProcessorUsingStrategy::OverlayStatus::~OverlayStatus() = default;
void OverlayProcessorUsingStrategy::UpdateOverlayStatusMap(
const OverlayCandidateList& candidates) { … }
void OverlayProcessorUsingStrategy::UpdateDamageRect(
const SurfaceDamageRectList& surface_damage_rect_list,
gfx::Rect& damage_rect) { … }
void OverlayProcessorUsingStrategy::AdjustOutputSurfaceOverlay(
std::optional<OutputSurfaceOverlayPlane>* output_surface_plane) { … }
void OverlayProcessorUsingStrategy::SortProposedOverlayCandidates(
std::vector<OverlayProposedCandidate>* proposed_candidates) { … }
bool OverlayProcessorUsingStrategy::AttemptWithStrategies(
const SkM44& output_color_matrix,
const OverlayProcessorInterface::FilterOperationsMap& render_pass_filters,
const OverlayProcessorInterface::FilterOperationsMap&
render_pass_backdrop_filters,
const DisplayResourceProvider* resource_provider,
AggregatedRenderPassList* render_pass_list,
SurfaceDamageRectList* surface_damage_rect_list,
OverlayProcessorInterface::OutputSurfaceOverlayPlane* primary_plane,
OverlayCandidateList* candidates,
std::vector<gfx::Rect>* content_bounds,
gfx::Rect* incoming_damage) { … }
bool OverlayProcessorUsingStrategy::ShouldAttemptMultipleOverlays(
const std::vector<OverlayProposedCandidate>& sorted_candidates) { … }
bool OverlayProcessorUsingStrategy::AttemptMultipleOverlays(
const std::vector<OverlayProposedCandidate>& sorted_candidates,
OverlayProcessorInterface::OutputSurfaceOverlayPlane* primary_plane,
AggregatedRenderPass* render_pass,
OverlayCandidateList& candidates) { … }
void OverlayProcessorUsingStrategy::AssignUnderlayZOrders(
std::vector<std::vector<OverlayProposedCandidate>::iterator>&
underlay_iters) { … }
gfx::Rect OverlayProcessorUsingStrategy::GetOverlayDamageRectForOutputSurface(
const OverlayCandidate& overlay) const { … }
void OverlayProcessorUsingStrategy::OnOverlaySwitchUMA(
ProposedCandidateKey overlay_tracking_id) { … }
void OverlayProcessorUsingStrategy::UpdateDownscalingCapabilities(
float scale_factor,
bool success) { … }
}