Skip to content

Commit

Permalink
Refactor OverlayCandidateFactory constructor
Browse files Browse the repository at this point in the history
Currently, we pass many options to OverlayCandidateFactory through
constructor to allow/disallow different conditions for a valid
OverlayCandidate.

As we plan to add more of these options, to improve the readability and
to make it easy to construct OverlayCandidateFactory, this CL refactor
all these options into a OverlayContext struct.

Bug: b:284994089
Change-Id: Idc49e5aee628dbcfc80d69573381dfb067586930
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4549859
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
Reviewed-by: Kevin Haslett <khaslett@chromium.org>
Commit-Queue: Zoraiz Naeem <zoraiznaeem@chromium.org>
Reviewed-by: Peter McNeeley <petermcneeley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1153552}
  • Loading branch information
Zoraiz Naeem authored and Chromium LUCI CQ committed Jun 5, 2023
1 parent 59502ed commit dd7f235
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 106 deletions.
66 changes: 33 additions & 33 deletions components/viz/service/display/overlay_candidate_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromDrawQuad(
// We don't support an opacity value different than one for an overlay plane.
// Render pass quads should have their |sqs| opacity integrated directly into
// their final output buffers.
if (!is_delegated_context_ &&
if (!context_.is_delegated_context &&
!cc::MathUtil::IsWithinEpsilon(sqs->opacity, 1.0f)) {
return CandidateStatus::kFailOpacity;
}
Expand All @@ -151,18 +151,21 @@ OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromDrawQuad(
return FromVideoHoleQuad(VideoHoleDrawQuad::MaterialCast(quad),
candidate);
case DrawQuad::Material::kSolidColor:
if (!is_delegated_context_)
if (!context_.is_delegated_context) {
return CandidateStatus::kFailQuadNotSupported;
}
return FromSolidColorQuad(SolidColorDrawQuad::MaterialCast(quad),
candidate);
case DrawQuad::Material::kAggregatedRenderPass:
if (!is_delegated_context_)
if (!context_.is_delegated_context) {
return CandidateStatus::kFailQuadNotSupported;
}
return FromAggregateQuad(AggregatedRenderPassDrawQuad::MaterialCast(quad),
candidate);
case DrawQuad::Material::kTiledContent:
if (!is_delegated_context_)
if (!context_.is_delegated_context) {
return CandidateStatus::kFailQuadNotSupported;
}
return FromTileQuad(TileDrawQuad::MaterialCast(quad), candidate);
default:
break;
Expand All @@ -178,20 +181,14 @@ OverlayCandidateFactory::OverlayCandidateFactory(
const SkM44* output_color_matrix,
const gfx::RectF primary_rect,
const OverlayProcessorInterface::FilterOperationsMap* render_pass_filters,
bool is_delegated_context,
bool supports_clip_rect,
bool supports_arbitrary_transform,
bool supports_rounded_corner_masks)
const OverlayContext& context)
: render_pass_(render_pass),
resource_provider_(resource_provider),
surface_damage_rect_list_(surface_damage_rect_list),
primary_rect_(primary_rect),
render_pass_filters_(render_pass_filters),
is_delegated_context_(is_delegated_context),
supports_clip_rect_(supports_clip_rect),
supports_arbitrary_transform_(supports_arbitrary_transform),
supports_rounded_display_masks_(supports_rounded_corner_masks) {
DCHECK(supports_clip_rect_ || !supports_arbitrary_transform_);
context_(context) {
DCHECK(context_.supports_clip_rect || !context_.supports_arbitrary_transform);

has_custom_color_matrix_ = *output_color_matrix != SkM44();

Expand Down Expand Up @@ -326,7 +323,7 @@ OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromDrawQuadResource(
const SharedQuadState* sqs = quad->shared_quad_state;

candidate.display_rect = gfx::RectF(quad->rect);
if (supports_arbitrary_transform_) {
if (context_.supports_arbitrary_transform) {
gfx::Transform transform = sqs->quad_to_target_transform;
if (y_flipped) {
transform.PreConcat(gfx::OverlayTransformToTransform(
Expand All @@ -337,9 +334,10 @@ OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromDrawQuadResource(
gfx::OverlayTransform overlay_transform =
GetOverlayTransform(sqs->quad_to_target_transform, y_flipped);
if (overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) {
return is_delegated_context_ ? GetReasonForTransformNotAxisAligned(
sqs->quad_to_target_transform)
: CandidateStatus::kFailNotAxisAligned;
return context_.is_delegated_context
? GetReasonForTransformNotAxisAligned(
sqs->quad_to_target_transform)
: CandidateStatus::kFailNotAxisAligned;
}
candidate.transform = overlay_transform;

Expand Down Expand Up @@ -373,7 +371,7 @@ OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromDrawQuadResource(
if (resource_id != kInvalidResourceId) {
candidate.mailbox = resource_provider_->GetMailbox(resource_id);

if (!is_delegated_context_) {
if (!context_.is_delegated_context) {
struct TrackingIdData {
gfx::Rect rect;
FrameSinkId frame_sink_id;
Expand All @@ -386,18 +384,19 @@ OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromDrawQuadResource(
}
}

if (is_delegated_context_) {
if (context_.is_delegated_context) {
// Lacros cannot currently delegate clip rects on quads that extend outside
// the primary rect. This is because there are bugs that cause the Lacros
// window and drop shadow to move incorrectly in that case.
bool quad_within_window = primary_rect_.Contains(candidate.display_rect);
bool transform_supports_clipping =
supports_arbitrary_transform_ ||
const bool quad_within_window =
primary_rect_.Contains(candidate.display_rect);
const bool transform_supports_clipping =
context_.supports_arbitrary_transform ||
absl::holds_alternative<gfx::OverlayTransform>(candidate.transform);
bool has_content_clipping = quad->visible_rect != quad->rect;
bool can_delegate_clipping = supports_clip_rect_ && quad_within_window &&
transform_supports_clipping &&
!has_content_clipping;
const bool has_content_clipping = quad->visible_rect != quad->rect;
const bool can_delegate_clipping =
context_.supports_clip_rect && quad_within_window &&
transform_supports_clipping && !has_content_clipping;
if (can_delegate_clipping) {
if (candidate.clip_rect.has_value() && candidate.clip_rect->IsEmpty()) {
return CandidateStatus::kFailVisible;
Expand Down Expand Up @@ -491,7 +490,7 @@ OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromVideoHoleQuad(
OverlayCandidate& candidate) const {
candidate.display_rect = gfx::RectF(quad->rect);
const SharedQuadState* sqs = quad->shared_quad_state;
if (supports_arbitrary_transform_) {
if (context_.supports_arbitrary_transform) {
candidate.transform = sqs->quad_to_target_transform;
} else {
gfx::OverlayTransform overlay_transform =
Expand Down Expand Up @@ -532,23 +531,23 @@ OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromTileQuad(
OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromTextureQuad(
const TextureDrawQuad* quad,
OverlayCandidate& candidate) const {
if (!is_delegated_context_ &&
if (!context_.is_delegated_context &&
quad->overlay_priority_hint == OverlayPriority::kLow) {
// For current implementation low priority means this does not promote to
// overlay.
return CandidateStatus::kFailPriority;
}

if (!quad->rounded_display_masks_info.IsEmpty() &&
!supports_rounded_display_masks_) {
DCHECK(!is_delegated_context_);
!context_.supports_rounded_display_masks) {
DCHECK(!context_.is_delegated_context);
return CandidateStatus::kFailRoundedDisplayMasksNotSupported;
}

if (quad->nearest_neighbor)
return CandidateStatus::kFailNearFilter;

if (is_delegated_context_) {
if (context_.is_delegated_context) {
// Always convey |background_color| even when transparent. This allows for
// the wayland server to make blending optimizations even when the quad is
// considered opaque. Specifically Exo will try to ensure the opaqueness of
Expand All @@ -572,8 +571,9 @@ OverlayCandidate::CandidateStatus OverlayCandidateFactory::FromTextureQuad(
candidate);
if (rtn == CandidateStatus::kSuccess) {
// Only handle clip rect for required overlays
if (!is_delegated_context_ && candidate.requires_overlay)
if (!context_.is_delegated_context && candidate.requires_overlay) {
HandleClipAndSubsampling(candidate);
}

// Texture quads for UI elements like scroll bars have empty
// |size_in_pixels| as 'set_resource_size_in_pixels' is not called as these
Expand Down Expand Up @@ -682,7 +682,7 @@ void OverlayCandidateFactory::AssignDamage(const DrawQuad* quad,
// For underlays the function 'EstimateVisibleDamage()' is called to update
// |damage_area_estimate| to more accurately reflect the actual visible
// damage.
if (!is_delegated_context_) {
if (!context_.is_delegated_context) {
candidate.damage_area_estimate =
GetDamageEstimate(candidate).size().GetArea();
}
Expand Down
17 changes: 9 additions & 8 deletions components/viz/service/display/overlay_candidate_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class VIZ_SERVICE_EXPORT OverlayCandidateFactory {
public:
using CandidateStatus = OverlayCandidate::CandidateStatus;

struct VIZ_SERVICE_EXPORT OverlayContext {
bool is_delegated_context = false;
bool supports_clip_rect = false;
bool supports_arbitrary_transform = false;
bool supports_rounded_display_masks = false;
};

// The coordinate space of |render_pass| is the target space for candidates
// produced by this factory.
OverlayCandidateFactory(
Expand All @@ -56,10 +63,7 @@ class VIZ_SERVICE_EXPORT OverlayCandidateFactory {
const SkM44* output_color_matrix,
const gfx::RectF primary_rect,
const OverlayProcessorInterface::FilterOperationsMap* render_pass_filters,
bool is_delegated_context = false,
bool supports_clip_rect = false,
bool supports_arbitrary_transform = false,
bool supports_rounded_display_masks = false);
const OverlayContext& context);

OverlayCandidateFactory(const OverlayCandidateFactory&) = delete;
OverlayCandidateFactory& operator=(const OverlayCandidateFactory&) = delete;
Expand Down Expand Up @@ -148,10 +152,7 @@ class VIZ_SERVICE_EXPORT OverlayCandidateFactory {
const gfx::RectF primary_rect_;
raw_ptr<const OverlayProcessorInterface::FilterOperationsMap>
render_pass_filters_;
const bool is_delegated_context_;
const bool supports_clip_rect_;
const bool supports_arbitrary_transform_;
const bool supports_rounded_display_masks_;
const OverlayContext context_;

// The union of all surface damages that are not specifically assigned to a
// draw quad.
Expand Down

0 comments on commit dd7f235

Please sign in to comment.