#include "components/viz/service/layers/layer_context_impl.h"
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/notimplemented.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/types/expected_macros.h"
#include "cc/debug/rendering_stats_instrumentation.h"
#include "cc/layers/layer_impl.h"
#include "cc/layers/solid_color_layer_impl.h"
#include "cc/layers/tile_display_layer_impl.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/layer_tree_settings.h"
#include "cc/trees/property_tree.h"
#include "cc/trees/task_runner_provider.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/service/frame_sinks/compositor_frame_sink_support.h"
#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
namespace viz {
namespace {
int GenerateNextDisplayTreeId() { … }
cc::LayerTreeSettings GetDisplayTreeSettings() { … }
std::unique_ptr<cc::LayerImpl> CreateLayer(LayerContextImpl& context,
cc::LayerTreeImpl& tree,
cc::mojom::LayerType type,
int id) { … }
template <typename TreeType>
bool IsPropertyTreeIndexValid(const TreeType& tree, int32_t index) { … }
template <typename TreeType>
bool IsOptionalPropertyTreeIndexValid(const TreeType& tree, int32_t index) { … }
base::expected<void, std::string> UpdatePropertyTreeNode(
cc::PropertyTrees& trees,
cc::TransformNode& node,
const mojom::TransformNode& wire) { … }
base::expected<void, std::string> UpdatePropertyTreeNode(
cc::PropertyTrees& trees,
cc::ClipNode& node,
const mojom::ClipNode& wire) { … }
base::expected<void, std::string> UpdatePropertyTreeNode(
cc::PropertyTrees& trees,
cc::EffectNode& node,
const mojom::EffectNode& wire) { … }
base::expected<void, std::string> UpdatePropertyTreeNode(
cc::PropertyTrees& trees,
cc::ScrollNode& node,
const mojom::ScrollNode& wire) { … }
template <typename TreeType>
bool ResizePropertyTree(TreeType& tree, uint32_t num_nodes) { … }
template <typename TreeType, typename WireContainerType>
base::expected<bool, std::string> UpdatePropertyTree(
cc::PropertyTrees& trees,
TreeType& tree,
const WireContainerType& wire_updates) { … }
base::expected<std::vector<cc::StickyPositionNodeData>, std::string>
DeserializeStickyPositionData(
cc::PropertyTrees& trees,
std::vector<mojom::StickyPositionNodeDataPtr>& wire_data) { … }
base::expected<std::vector<cc::AnchorPositionScrollData>, std::string>
DeserializeAnchorPositionScrollData(
std::vector<mojom::AnchorPositionScrollDataPtr>& wire_data) { … }
base::expected<void, std::string> UpdateTransformTreeProperties(
cc::PropertyTrees& trees,
cc::TransformTree& tree,
mojom::TransformTreeUpdate& update) { … }
base::expected<void, std::string> UpdateLayer(const mojom::Layer& wire,
cc::LayerImpl& layer) { … }
base::expected<void, std::string> CreateOrUpdateLayers(
LayerContextImpl& context,
const std::vector<mojom::LayerPtr>& updates,
std::optional<std::vector<int32_t>>& layer_order,
cc::LayerTreeImpl& layers) { … }
base::expected<void, std::string> UpdateViewportPropertyIds(
cc::LayerTreeImpl& layers,
cc::PropertyTrees& trees,
mojom::LayerTreeUpdate& update) { … }
base::expected<cc::TileDisplayLayerImpl::TileResource, std::string>
DeserializeTileResource(mojom::TileResource& wire) { … }
base::expected<cc::TileDisplayLayerImpl::TileContents, std::string>
DeserializeTileContents(mojom::TileContents& wire) { … }
base::expected<void, std::string> DeserializeTiling(
cc::TileDisplayLayerImpl& layer,
mojom::Tiling& wire) { … }
}
LayerContextImpl::LayerContextImpl(CompositorFrameSinkSupport* compositor_sink,
mojom::PendingLayerContext& context)
: … { … }
LayerContextImpl::~LayerContextImpl() { … }
void LayerContextImpl::BeginFrame(const BeginFrameArgs& args) { … }
void LayerContextImpl::ReturnResources(
std::vector<ReturnedResource> resources) { … }
void LayerContextImpl::DidLoseLayerTreeFrameSinkOnImplThread() { … }
void LayerContextImpl::SetBeginFrameSource(BeginFrameSource* source) { … }
void LayerContextImpl::DidReceiveCompositorFrameAckOnImplThread() { … }
void LayerContextImpl::OnCanDrawStateChanged(bool can_draw) { … }
void LayerContextImpl::NotifyReadyToActivate() { … }
bool LayerContextImpl::IsReadyToActivate() { … }
void LayerContextImpl::NotifyReadyToDraw() { … }
void LayerContextImpl::SetNeedsRedrawOnImplThread() { … }
void LayerContextImpl::SetNeedsOneBeginImplFrameOnImplThread() { … }
void LayerContextImpl::SetNeedsUpdateDisplayTreeOnImplThread() { … }
void LayerContextImpl::SetNeedsPrepareTilesOnImplThread() { … }
void LayerContextImpl::SetNeedsCommitOnImplThread() { … }
void LayerContextImpl::SetVideoNeedsBeginFrames(bool needs_begin_frames) { … }
void LayerContextImpl::SetDeferBeginMainFrameFromImpl(
bool defer_begin_main_frame) { … }
bool LayerContextImpl::IsInsideDraw() { … }
void LayerContextImpl::RenewTreePriority() { … }
void LayerContextImpl::PostDelayedAnimationTaskOnImplThread(
base::OnceClosure task,
base::TimeDelta delay) { … }
void LayerContextImpl::DidActivateSyncTree() { … }
void LayerContextImpl::DidPrepareTiles() { … }
void LayerContextImpl::DidCompletePageScaleAnimationOnImplThread() { … }
void LayerContextImpl::OnDrawForLayerTreeFrameSink(
bool resourceless_software_draw,
bool skip_draw) { … }
void LayerContextImpl::SetNeedsImplSideInvalidation(
bool needs_first_draw_on_activation) { … }
void LayerContextImpl::NotifyImageDecodeRequestFinished(int request_id,
bool decode_succeeded) { … }
void LayerContextImpl::NotifyTransitionRequestFinished(uint32_t sequence_id) { … }
void LayerContextImpl::DidPresentCompositorFrameOnImplThread(
uint32_t frame_token,
cc::PresentationTimeCallbackBuffer::PendingCallbacks callbacks,
const FrameTimingDetails& details) { … }
void LayerContextImpl::NotifyAnimationWorkletStateChange(
cc::AnimationWorkletMutationState state,
cc::ElementListType element_list_type) { … }
void LayerContextImpl::NotifyPaintWorkletStateChange(
cc::Scheduler::PaintWorkletState state) { … }
void LayerContextImpl::NotifyThroughputTrackerResults(
cc::CustomTrackerResults results) { … }
bool LayerContextImpl::IsInSynchronousComposite() const { … }
void LayerContextImpl::FrameSinksToThrottleUpdated(
const base::flat_set<FrameSinkId>& ids) { … }
void LayerContextImpl::ClearHistory() { … }
void LayerContextImpl::SetHasActiveThreadedScroll(bool is_scrolling) { … }
void LayerContextImpl::SetWaitingForScrollEvent(bool waiting_for_scroll_event) { … }
size_t LayerContextImpl::CommitDurationSampleCountForTesting() const { … }
void LayerContextImpl::DidObserveFirstScrollDelay(
int source_frame_number,
base::TimeDelta first_scroll_delay,
base::TimeTicks first_scroll_timestamp) { … }
bool LayerContextImpl::BindToClient(cc::LayerTreeFrameSinkClient* client) { … }
void LayerContextImpl::DetachFromClient() { … }
void LayerContextImpl::SetLocalSurfaceId(
const LocalSurfaceId& local_surface_id) { … }
void LayerContextImpl::SubmitCompositorFrame(CompositorFrame frame,
bool hit_test_data_changed) { … }
void LayerContextImpl::DidNotProduceFrame(const BeginFrameAck& ack,
cc::FrameSkippedReason reason) { … }
void LayerContextImpl::DidAllocateSharedBitmap(
base::ReadOnlySharedMemoryRegion region,
const SharedBitmapId& id) { … }
void LayerContextImpl::DidDeleteSharedBitmap(const SharedBitmapId& id) { … }
void LayerContextImpl::DidAppendQuadsWithResources(
const std::vector<TransferableResource>& resources) { … }
void LayerContextImpl::SetVisible(bool visible) { … }
void LayerContextImpl::UpdateDisplayTree(mojom::LayerTreeUpdatePtr update) { … }
base::expected<void, std::string> LayerContextImpl::DoUpdateDisplayTree(
mojom::LayerTreeUpdatePtr update) { … }
void LayerContextImpl::UpdateDisplayTiling(mojom::TilingPtr tiling) { … }
}