#include "components/viz/service/display/surface_aggregator.h"
#include <stddef.h>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include "base/auto_reset.h"
#include "base/check_op.h"
#include "base/containers/adapters.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/ranges.h"
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/typed_macros.h"
#include "cc/base/math_util.h"
#include "components/viz/common/features.h"
#include "components/viz/common/quads/aggregated_render_pass.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/compositor_render_pass_draw_quad.h"
#include "components/viz/common/quads/debug_border_draw_quad.h"
#include "components/viz/common/quads/draw_quad.h"
#include "components/viz/common/quads/offset_tag.h"
#include "components/viz/common/quads/shared_quad_state.h"
#include "components/viz/common/quads/solid_color_draw_quad.h"
#include "components/viz/common/quads/surface_draw_quad.h"
#include "components/viz/common/quads/texture_draw_quad.h"
#include "components/viz/common/quads/yuv_video_draw_quad.h"
#include "components/viz/common/surfaces/surface_range.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/display_resource_provider.h"
#include "components/viz/service/display/overlay_candidate.h"
#include "components/viz/service/display/renderer_utils.h"
#include "components/viz/service/display/resolved_frame_data.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.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/overlay_transform_utils.h"
namespace viz {
struct MaskFilterInfoExt { … };
namespace {
enum class RenderPassDamage { … };
constexpr float kOpacityEpsilon = …;
void MoveMatchingRequests(
CompositorRenderPassId render_pass_id,
std::multimap<CompositorRenderPassId, std::unique_ptr<CopyOutputRequest>>*
copy_requests,
std::vector<std::unique_ptr<CopyOutputRequest>>* output_requests) { … }
std::optional<gfx::Rect> CalculateClipRect(
const std::optional<gfx::Rect> surface_clip,
const std::optional<gfx::Rect> quad_clip,
const gfx::Transform& target_transform) { … }
SharedQuadState* CopyAndScaleSharedQuadState(
const SharedQuadState* source_sqs,
uint32_t client_namespace_id,
const gfx::Transform& quad_to_target_transform,
const gfx::Transform& target_transform,
const gfx::Rect& quad_layer_rect,
const gfx::Rect& visible_quad_layer_rect,
const std::optional<gfx::Rect> added_clip_rect,
const MaskFilterInfoExt& mask_filter_info_ext,
AggregatedRenderPass* dest_render_pass) { … }
SharedQuadState* CopySharedQuadState(
const SharedQuadState* source_sqs,
uint32_t client_namespace_id,
const gfx::Transform& target_transform,
const std::optional<gfx::Rect> added_clip_rect,
const MaskFilterInfoExt& mask_filter_info,
AggregatedRenderPass* dest_render_pass) { … }
void UpdatePersistentPassDataMergeState(ResolvedPassData& resolved_pass,
AggregatedRenderPass* dest_pass,
bool is_merged_pass) { … }
bool ChangeInMergeState(ResolvedPassData& resolved_pass) { … }
void UpdateNeedsRedraw(
ResolvedPassData& resolved_pass,
AggregatedRenderPass* dest_pass,
const std::optional<gfx::Rect> dest_root_target_clip_rect) { … }
bool RenderPassNeedsFullDamage(ResolvedPassData& resolved_pass) { … }
gfx::Rect ComputeDrawableRectForQuad(const DrawQuad* quad) { … }
gfx::Rect TransformRectToDestRootTargetSpace(
const gfx::Rect& rect_in_target_space,
const gfx::Transform& target_to_dest_transform,
const gfx::Transform& dest_to_root_target_transform,
const std::optional<gfx::Rect> dest_root_target_clip_rect) { … }
}
constexpr base::TimeDelta SurfaceAggregator::kHistogramMinTime;
constexpr base::TimeDelta SurfaceAggregator::kHistogramMaxTime;
struct SurfaceAggregator::PrewalkResult { … };
SurfaceAggregator::SurfaceAggregator(
SurfaceManager* manager,
DisplayResourceProvider* provider,
bool needs_surface_damage_rect_list,
ExtraPassForReadbackOption extra_pass_option,
bool prevent_merging_surfaces_to_root_pass)
: … { … }
SurfaceAggregator::~SurfaceAggregator() { … }
void SurfaceAggregator::AddRenderPassFilterDamageToDamageList(
const ResolvedFrameData& resolved_frame,
const CompositorRenderPassDrawQuad* render_pass_quad,
const gfx::Transform& parent_target_transform,
const std::optional<gfx::Rect> dest_root_target_clip_rect,
const gfx::Transform& dest_transform_to_root_target) { … }
void SurfaceAggregator::AddSurfaceDamageToDamageList(
const gfx::Rect& default_damage_rect,
const gfx::Transform& parent_target_transform,
const std::optional<gfx::Rect> dest_root_target_clip_rect,
const gfx::Transform& dest_transform_to_root_target,
ResolvedFrameData* resolved_frame) { … }
const DrawQuad* SurfaceAggregator::FindQuadWithOverlayDamage(
const CompositorRenderPass& source_pass,
AggregatedRenderPass* dest_pass,
const gfx::Transform& pass_to_root_target_transform,
size_t* overlay_damage_index) { … }
bool SurfaceAggregator::CanPotentiallyMergePass(
const SurfaceDrawQuad& surface_quad) { … }
void SurfaceAggregator::OnSurfaceDestroyed(const SurfaceId& surface_id) { … }
const ResolvedFrameData* SurfaceAggregator::GetLatestFrameData(
const SurfaceId& surface_id) { … }
ResolvedFrameData* SurfaceAggregator::GetResolvedFrame(
const SurfaceRange& range) { … }
ResolvedFrameData* SurfaceAggregator::GetResolvedFrame(
const SurfaceId& surface_id) { … }
void SurfaceAggregator::HandleSurfaceQuad(
const CompositorRenderPass& source_pass,
const SurfaceDrawQuad* surface_quad,
uint32_t embedder_client_namespace_id,
float parent_device_scale_factor,
const gfx::Transform& target_transform,
const std::optional<gfx::Rect> added_clip_rect,
const std::optional<gfx::Rect> dest_root_target_clip_rect,
AggregatedRenderPass* dest_pass,
const MaskFilterInfoExt& mask_filter_info) { … }
void SurfaceAggregator::EmitSurfaceContent(
ResolvedFrameData& resolved_frame,
float parent_device_scale_factor,
const SurfaceDrawQuad* surface_quad,
uint32_t embedder_client_namespace_id,
const gfx::Transform& target_transform,
const std::optional<gfx::Rect> added_clip_rect,
const std::optional<gfx::Rect> dest_root_target_clip_rect,
AggregatedRenderPass* dest_pass,
const MaskFilterInfoExt& mask_filter_info) { … }
void SurfaceAggregator::EmitDefaultBackgroundColorQuad(
const SurfaceDrawQuad* surface_quad,
uint32_t embedder_client_namespace_id,
const gfx::Transform& target_transform,
const std::optional<gfx::Rect> clip_rect,
AggregatedRenderPass* dest_pass,
const MaskFilterInfoExt& mask_filter_info) { … }
void SurfaceAggregator::EmitGutterQuadsIfNecessary(
const gfx::Rect& primary_rect,
const gfx::Rect& fallback_rect,
const SharedQuadState* primary_shared_quad_state,
uint32_t embedder_client_namespace_id,
const gfx::Transform& target_transform,
const std::optional<gfx::Rect> clip_rect,
SkColor4f background_color,
AggregatedRenderPass* dest_pass,
const MaskFilterInfoExt& mask_filter_info) { … }
void SurfaceAggregator::AddColorConversionPass() { … }
void SurfaceAggregator::AddRootReadbackPass() { … }
void SurfaceAggregator::AddDisplayTransformPass() { … }
void SurfaceAggregator::AddRenderPassHelper(
AggregatedRenderPassId render_pass_id,
const gfx::Rect& render_pass_output_rect,
const gfx::Rect& render_pass_damage_rect,
gfx::ContentColorUsage pass_color_usage,
bool pass_has_transparent_background,
bool pass_is_color_conversion_pass,
const gfx::Transform& quad_state_to_target_transform,
bool quad_state_contents_opaque,
SkBlendMode quad_state_blend_mode,
AggregatedRenderPassId quad_pass_id) { … }
void SurfaceAggregator::CopyQuadsToPass(
ResolvedFrameData& resolved_frame,
ResolvedPassData& resolved_pass,
AggregatedRenderPass* dest_pass,
float parent_device_scale_factor,
const gfx::Transform& target_transform,
const std::optional<gfx::Rect> clip_rect,
const std::optional<gfx::Rect> dest_root_target_clip_rect,
const MaskFilterInfoExt& parent_mask_filter_info_ext) { … }
void SurfaceAggregator::CopyPasses(ResolvedFrameData& resolved_frame) { … }
void SurfaceAggregator::SetRenderPassDamageRect(
AggregatedRenderPass* copy_pass,
ResolvedPassData& resolved_pass) { … }
void SurfaceAggregator::ProcessAddedAndRemovedSurfaces() { … }
gfx::Rect SurfaceAggregator::PrewalkRenderPass(
ResolvedFrameData& resolved_frame,
ResolvedPassData& resolved_pass,
const gfx::Rect& damage_from_parent,
const gfx::Transform& target_to_root_transform,
const ResolvedPassData* parent_pass,
PrewalkResult& result) { … }
bool SurfaceAggregator::CheckFrameSinksChanged(const SurfaceId& surface_id) { … }
gfx::Rect SurfaceAggregator::PrewalkSurface(ResolvedFrameData& resolved_frame,
ResolvedPassData* parent_pass,
const gfx::Rect& damage_from_parent,
PrewalkResult& result) { … }
void SurfaceAggregator::CopyUndrawnSurfaces(PrewalkResult* prewalk_result) { … }
void SurfaceAggregator::MarkAndPropagateCopyRequestPasses(
ResolvedPassData& resolved_pass) { … }
AggregatedFrame SurfaceAggregator::Aggregate(
const SurfaceId& surface_id,
base::TimeTicks expected_display_time,
gfx::OverlayTransform display_transform,
const gfx::Rect& target_damage,
int64_t display_trace_id) { … }
void SurfaceAggregator::RecordStatHistograms() { … }
void SurfaceAggregator::ResetAfterAggregate() { … }
void SurfaceAggregator::SetFullDamageForSurface(const SurfaceId& surface_id) { … }
void SurfaceAggregator::SetDisplayColorSpaces(
const gfx::DisplayColorSpaces& display_color_spaces) { … }
void SurfaceAggregator::SetMaxRenderTargetSize(int max_size) { … }
bool SurfaceAggregator::CheckForDisplayDamage(const SurfaceId& surface_id) { … }
bool SurfaceAggregator::ForceReleaseResourcesIfNeeded(
const SurfaceId& surface_id) { … }
bool SurfaceAggregator::HasFrameAnnotator() const { … }
void SurfaceAggregator::SetFrameAnnotator(
std::unique_ptr<FrameAnnotator> frame_annotator) { … }
void SurfaceAggregator::DestroyFrameAnnotator() { … }
bool SurfaceAggregator::IsRootSurface(const Surface* surface) const { … }
void SurfaceAggregator::TransformAndStoreDelegatedInkMetadata(
const gfx::Transform& parent_quad_to_root_target_transform,
const gfx::DelegatedInkMetadata* metadata) { … }
void SurfaceAggregator::DebugLogSurface(const Surface* surface,
bool will_draw) { … }
}