0

viz: Set an explicit layer ID for RenderSurfaceImpl

This change makes it explicit that a layer ID of 0 valid, and sets a
unique id for RenderSurfaceImpl.

Bug: 324460866
Change-Id: Ib3ea70e9f375f49313ec103469b250e4eab0a14e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5912146
Commit-Queue: Michael Tang <tangm@microsoft.com>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1396195}
This commit is contained in:
Michael Tang
2024-12-13 13:49:23 -08:00
committed by Chromium LUCI CQ
parent fe2702e96c
commit c00a822079
7 changed files with 29 additions and 18 deletions

@ -89,6 +89,11 @@ Layer::Inputs::~Inputs() = default;
Layer::LayerTreeInputs::LayerTreeInputs() = default; Layer::LayerTreeInputs::LayerTreeInputs() = default;
Layer::LayerTreeInputs::~LayerTreeInputs() = default; Layer::LayerTreeInputs::~LayerTreeInputs() = default;
int Layer::GetNextLayerId() {
// Layer IDs start from 1.
return g_next_layer_id.GetNext() + 1;
}
scoped_refptr<Layer> Layer::Create() { scoped_refptr<Layer> Layer::Create() {
return base::WrapRefCounted(new Layer()); return base::WrapRefCounted(new Layer());
} }
@ -96,8 +101,7 @@ scoped_refptr<Layer> Layer::Create() {
Layer::Layer() Layer::Layer()
: parent_(nullptr), : parent_(nullptr),
layer_tree_host_(nullptr), layer_tree_host_(nullptr),
// Layer IDs start from 1. layer_id_(GetNextLayerId()),
layer_id_(g_next_layer_id.GetNext() + 1),
num_descendants_that_draw_content_(0), num_descendants_that_draw_content_(0),
transform_tree_index_(kInvalidPropertyNodeId), transform_tree_index_(kInvalidPropertyNodeId),
effect_tree_index_(kInvalidPropertyNodeId), effect_tree_index_(kInvalidPropertyNodeId),

@ -95,6 +95,9 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>,
INVALID_ID = -1, INVALID_ID = -1,
}; };
// Get a unique layer id.
static int GetNextLayerId();
// Factory to create a new Layer, with a unique id. // Factory to create a new Layer, with a unique id.
static scoped_refptr<Layer> Create(); static scoped_refptr<Layer> Create();

@ -37,7 +37,8 @@ RenderSurfaceImpl::RenderSurfaceImpl(LayerTreeImpl* layer_tree_impl,
ElementId id) ElementId id)
: layer_tree_impl_(layer_tree_impl), : layer_tree_impl_(layer_tree_impl),
id_(id), id_(id),
effect_tree_index_(kInvalidPropertyNodeId) { effect_tree_index_(kInvalidPropertyNodeId),
layer_id_(Layer::GetNextLayerId()) {
DCHECK(id); DCHECK(id);
damage_tracker_ = DamageTracker::Create(); damage_tracker_ = DamageTracker::Create();
} }
@ -459,7 +460,7 @@ void RenderSurfaceImpl::AppendQuads(DrawMode draw_mode,
shared_quad_state->SetAll( shared_quad_state->SetAll(
draw_transform(), content_rect(), content_rect(), mask_filter_info(), draw_transform(), content_rect(), content_rect(), mask_filter_info(),
clip_rect, contents_opaque, draw_properties_.draw_opacity, BlendMode(), clip_rect, contents_opaque, draw_properties_.draw_opacity, BlendMode(),
sorting_context_id, /*layer_id=*/0u, is_fast_rounded_corner()); sorting_context_id, layer_id_, is_fast_rounded_corner());
if (layer_tree_impl_->debug_state().show_debug_borders.test( if (layer_tree_impl_->debug_state().show_debug_borders.test(
DebugBorderType::RENDERPASS)) { DebugBorderType::RENDERPASS)) {

@ -273,6 +273,10 @@ class CC_EXPORT RenderSurfaceImpl {
ElementId id_; ElementId id_;
int effect_tree_index_; int effect_tree_index_;
// A unique id in the same namespace as `Layer::layer_id_`, so viz can
// identify `RenderPassDrawQuads` across the frame, similarly to other quads.
uint32_t layer_id_ = 0;
// Container for properties that render surfaces need to compute before they // Container for properties that render surfaces need to compute before they
// can be drawn. // can be drawn.
struct DrawProperties { struct DrawProperties {

@ -429,7 +429,8 @@ viz::SharedQuadState* Layer::CreateAndAppendSharedQuadState(
data.mask_filter_info_in_target, clip_opt, data.mask_filter_info_in_target, clip_opt,
contents_opaque(), opacity, SkBlendMode::kSrcOver, contents_opaque(), opacity, SkBlendMode::kSrcOver,
/*sorting_context=*/0, /*sorting_context=*/0,
/*layer_id=*/0u, /*fast_rounded_corner=*/false); /*layer_id=*/static_cast<uint32_t>(id()),
/*fast_rounded_corner=*/false);
quad_state->is_fast_rounded_corner = true; quad_state->is_fast_rounded_corner = true;
quad_state->offset_tag = data.offset_tag; quad_state->offset_tag = data.offset_tag;
return quad_state; return quad_state;

@ -74,10 +74,10 @@ class VIZ_COMMON_EXPORT SharedQuadState {
float opacity = 1.0f; float opacity = 1.0f;
SkBlendMode blend_mode = SkBlendMode::kSrcOver; SkBlendMode blend_mode = SkBlendMode::kSrcOver;
int sorting_context_id = 0; int sorting_context_id = 0;
// Optionally set by the client with a stable ID for the layer that produced // Optionally set by the client as a performance hint for viz with a stable ID
// the DrawQuad(s). This is used to help identify that DrawQuad(s) in one // for the layer that produced the DrawQuad(s). This is used to help identify
// frame came from the same layer as DrawQuads() from a previous frame, even // that DrawQuad(s) in one frame came from the same layer as DrawQuads() from
// if they changed position or other attributes. // a previous frame, even if they changed position or other attributes.
uint32_t layer_id = 0; uint32_t layer_id = 0;
// Used by SurfaceAggregator to namespace layer_ids from different clients. // Used by SurfaceAggregator to namespace layer_ids from different clients.
uint32_t layer_namespace_id = 0; uint32_t layer_namespace_id = 0;

@ -173,15 +173,13 @@ OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromDrawQuad(
candidate.overlay_damage_index = candidate.overlay_damage_index =
sqs->overlay_damage_index.value_or(OverlayCandidate::kInvalidDamageIndex); sqs->overlay_damage_index.value_or(OverlayCandidate::kInvalidDamageIndex);
if (sqs->layer_id != 0) { static_assert(
static_assert( std::is_same<decltype(SharedQuadState::layer_id), uint32_t>::value);
std::is_same<decltype(SharedQuadState::layer_id), uint32_t>::value); static_assert(std::is_same<decltype(SharedQuadState::layer_namespace_id),
static_assert(std::is_same<decltype(SharedQuadState::layer_namespace_id), uint32_t>::value);
uint32_t>::value); candidate.aggregated_layer_id =
candidate.aggregated_layer_id = static_cast<uint64_t>(sqs->layer_id) |
static_cast<uint64_t>(sqs->layer_id) | (static_cast<uint64_t>(sqs->layer_namespace_id) << 32);
(static_cast<uint64_t>(sqs->layer_namespace_id) << 32);
}
auto status = CandidateStatus::kFailQuadNotSupported; auto status = CandidateStatus::kFailQuadNotSupported;
switch (quad->material) { switch (quad->material) {