chromium/cc/layers/picture_layer_impl.cc

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

#include "cc/layers/picture_layer_impl.h"

#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <cmath>
#include <limits>
#include <memory>
#include <set>
#include <utility>

#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "base/trace_event/traced_value.h"
#include "build/build_config.h"
#include "cc/base/features.h"
#include "cc/base/math_util.h"
#include "cc/benchmarks/micro_benchmark_impl.h"
#include "cc/debug/debug_colors.h"
#include "cc/layers/append_quads_data.h"
#include "cc/layers/solid_color_layer_impl.h"
#include "cc/paint/display_item_list.h"
#include "cc/tiles/tile_manager.h"
#include "cc/tiles/tiling_set_raster_queue_all.h"
#include "cc/trees/effect_node.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
#include "cc/trees/transform_node.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "components/viz/common/quads/debug_border_draw_quad.h"
#include "components/viz/common/quads/picture_draw_quad.h"
#include "components/viz/common/quads/solid_color_draw_quad.h"
#include "components/viz/common/quads/tile_draw_quad.h"
#include "components/viz/common/traced_value.h"
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"

namespace cc {
namespace {
// This must be > 1 as we multiply or divide by this to find a new raster
// scale during pinch.
const float kMaxScaleRatioDuringPinch =;

// When creating a new tiling during pinch, snap to an existing
// tiling's scale if the desired scale is within this ratio.
const float kSnapToExistingTilingRatio =;

// Large contents scale can cause overflow issues. Cap the ideal contents scale
// by this constant, since scales larger than this are usually not correct or
// their scale doesn't matter as long as it's large. Content scales usually
// closely match the default device-scale factor (so it's usually <= 5). See
// Renderer4.IdealContentsScale UMA (deprecated) for distribution of content
// scales.
const float kMaxIdealContentsScale =;

// We try to avoid raster scale adjustment for will-change:transform for
// performance, unless the scale is too small compared to the ideal scale and
// the native scale.
const float kMinScaleRatioForWillChangeTransform =;

// Used to avoid raster scale adjustment during a transform animation by
// using the maximum animation scale, but sometimes the maximum animation scale
// can't be accurately calculated (e.g. with nested scale transforms). We'll
// adjust raster scale if it is not affected by invalid scale and is smaller
// than the ideal scale divided by this ratio. The situation is rare.
// See PropertyTrees::MaximumAnimationToScreenScale() and
// AnimationAffectedByInvalidScale().
const float kRatioToAdjustRasterScaleForTransformAnimation =;

// Intersect rects which may have right() and bottom() that overflow integer
// boundaries. This code is similar to gfx::Rect::Intersect with the exception
// that the types are promoted to int64_t when there is a chance of overflow.
gfx::Rect SafeIntersectRects(const gfx::Rect& one, const gfx::Rect& two) {}

}  // namespace

PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id)
    :{}

PictureLayerImpl::~PictureLayerImpl() {}

mojom::LayerType PictureLayerImpl::GetLayerType() const {}

std::unique_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl(
    LayerTreeImpl* tree_impl) const {}

void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {}

void PictureLayerImpl::AppendQuads(viz::CompositorRenderPass* render_pass,
                                   AppendQuadsData* append_quads_data) {}

bool PictureLayerImpl::UpdateTiles() {}

void PictureLayerImpl::UpdateViewportRectForTilePriorityInContentSpace() {}

PictureLayerImpl* PictureLayerImpl::GetPendingOrActiveTwinLayer() const {}

void PictureLayerImpl::UpdateRasterSource(
    scoped_refptr<RasterSource> raster_source,
    Region* new_invalidation) {}

void PictureLayerImpl::UpdateRasterSourceInternal(
    scoped_refptr<RasterSource> raster_source,
    Region* new_invalidation,
    const PictureLayerTilingSet* pending_set,
    const PaintWorkletRecordMap* pending_paint_worklet_records,
    const DiscardableImageMap* pending_discardable_image_map) {}

void PictureLayerImpl::RegenerateDiscardableImageMapIfNeeded() {}

void PictureLayerImpl::UpdateCanUseLCDText(
    bool raster_translation_aligns_pixels) {}

bool PictureLayerImpl::AffectedByWillChangeTransformHint() const {}

LCDTextDisallowedReason PictureLayerImpl::ComputeLCDTextDisallowedReason(
    bool raster_translation_aligns_pixels) const {}

LCDTextDisallowedReason
PictureLayerImpl::ComputeLCDTextDisallowedReasonForTesting() const {}

void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) {}

gfx::Rect PictureLayerImpl::GetDamageRect() const {}

void PictureLayerImpl::ResetChangeTracking() {}

void PictureLayerImpl::DidBeginTracing() {}

void PictureLayerImpl::ReleaseResources() {}

void PictureLayerImpl::ReleaseTileResources() {}

void PictureLayerImpl::RecreateTileResources() {}

Region PictureLayerImpl::GetInvalidationRegionForDebugging() {}

std::unique_ptr<Tile> PictureLayerImpl::CreateTile(
    const Tile::CreateInfo& info) {}

const Region* PictureLayerImpl::GetPendingInvalidation() {}

const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling(
    const PictureLayerTiling* tiling) const {}

bool PictureLayerImpl::RequiresHighResToDraw() const {}

const PaintWorkletRecordMap& PictureLayerImpl::GetPaintWorkletRecords() const {}

bool PictureLayerImpl::IsDirectlyCompositedImage() const {}

void PictureLayerImpl::OnAllTilesDoneCleared() {}

std::vector<const DrawImage*> PictureLayerImpl::GetDiscardableImagesInRect(
    const gfx::Rect& rect) const {}

ScrollOffsetMap PictureLayerImpl::GetRasterInducingScrollOffsets() const {}

const GlobalStateThatImpactsTilePriority& PictureLayerImpl::global_tile_state()
    const {}

gfx::Rect PictureLayerImpl::GetEnclosingVisibleRectInTargetSpace() const {}

bool PictureLayerImpl::ShouldAnimate(PaintImage::Id paint_image_id) const {}

gfx::Size PictureLayerImpl::CalculateTileSize(const gfx::Size& content_bounds) {}

void PictureLayerImpl::GetContentsResourceId(
    viz::ResourceId* resource_id,
    gfx::Size* resource_size,
    gfx::SizeF* resource_uv_size) const {}

void PictureLayerImpl::UpdateDirectlyCompositedImageFromRasterSource() {}

bool PictureLayerImpl::ShouldDirectlyCompositeImage(float raster_scale) const {}

float PictureLayerImpl::CalculateDirectlyCompositedImageRasterScale() const {}

PictureLayerTiling* PictureLayerImpl::AddTiling(
    const gfx::AxisTransform2d& raster_transform) {}

void PictureLayerImpl::RemoveAllTilings() {}

bool PictureLayerImpl::CanRecreateHighResTilingForLCDTextAndRasterTransform(
    const PictureLayerTiling& high_res) const {}

void PictureLayerImpl::UpdateTilingsForRasterScaleAndTranslation(
    bool has_adjusted_raster_scale) {}

bool PictureLayerImpl::ShouldAdjustRasterScale() const {}

void PictureLayerImpl::AddLowResolutionTilingIfNeeded() {}

void PictureLayerImpl::RecalculateRasterScales() {}

void PictureLayerImpl::AdjustRasterScaleForTransformAnimation(
    const gfx::Vector2dF& preserved_raster_contents_scale) {}

void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
    const std::vector<raw_ptr<PictureLayerTiling, VectorExperimental>>&
        used_tilings) {}

float PictureLayerImpl::MinimumRasterContentsScaleForWillChangeTransform()
    const {}

bool PictureLayerImpl::CalculateRasterTranslation(
    gfx::Vector2dF& raster_translation) const {}

float PictureLayerImpl::MinimumContentsScale() const {}

float PictureLayerImpl::MaximumContentsScale() const {}

void PictureLayerImpl::ResetRasterScale() {}

bool PictureLayerImpl::CanHaveTilings() const {}

void PictureLayerImpl::SanityCheckTilingState() const {}

float PictureLayerImpl::MaximumTilingContentsScale() const {}

std::unique_ptr<PictureLayerTilingSet>
PictureLayerImpl::CreatePictureLayerTilingSet() {}

void PictureLayerImpl::UpdateIdealScales() {}

void PictureLayerImpl::GetDebugBorderProperties(SkColor4f* color,
                                                float* width) const {}

void PictureLayerImpl::GetAllPrioritizedTilesForTracing(
    std::vector<PrioritizedTile>* prioritized_tiles) const {}

void PictureLayerImpl::AsValueInto(
    base::trace_event::TracedValue* state) const {}

size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {}

void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {}

bool PictureLayerImpl::IsOnActiveOrPendingTree() const {}

bool PictureLayerImpl::HasValidTilePriorities() const {}

PictureLayerImpl::ImageInvalidationResult
PictureLayerImpl::InvalidateRegionForImages(
    const PaintImageIdFlatSet& images_to_invalidate) {}

void PictureLayerImpl::InvalidateRasterInducingScrolls(
    const base::flat_set<ElementId>& scrolls_to_invalidate) {}

void PictureLayerImpl::SetPaintWorkletRecord(
    scoped_refptr<const PaintWorkletInput> input,
    PaintRecord record) {}

void PictureLayerImpl::RegisterAnimatedImages() {}

void PictureLayerImpl::UnregisterAnimatedImages() {}

void PictureLayerImpl::SetPaintWorkletInputs(
    const std::vector<DiscardableImageMap::PaintWorkletInputWithImageId>&
        inputs) {}

void PictureLayerImpl::InvalidatePaintWorklets(
    const PaintWorkletInput::PropertyKey& key,
    const PaintWorkletInput::PropertyValue& prev,
    const PaintWorkletInput::PropertyValue& next) {}

PictureLayerImpl::TileUpdateSet PictureLayerImpl::TakeUpdatedTiles() {}

gfx::ContentColorUsage PictureLayerImpl::GetContentColorUsage() const {}

DamageReasonSet PictureLayerImpl::GetDamageReasons() const {}

}  // namespace cc