Skip to content

Commit

Permalink
gpu: Use OverlayCandidate on Windows
Browse files Browse the repository at this point in the history
This CL removes DCLayerOverlay and uses OverlayCandidate instead. It does not use OverlayCandidateFactory to create candidates on Windows due to different requirements on Windows regarding protected video overlays.

Bug: 1132392
Change-Id: I5a6b4e67d778ed4807ae0fc4cb878dc3b1946c71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3824779
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com>
Commit-Queue: Michael Tang <tangm@microsoft.com>
Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1102920}
  • Loading branch information
tangm-msft authored and Chromium LUCI CQ committed Feb 8, 2023
1 parent fa289a3 commit 98c8470
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 191 deletions.
59 changes: 30 additions & 29 deletions components/viz/service/display/dc_layer_overlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,20 @@ DCLayerResult ValidateYUVQuad(

void FromYUVQuad(const YUVVideoDrawQuad* quad,
const gfx::Transform& transform_to_root_target,
DCLayerOverlayCandidate* dc_layer) {
OverlayCandidate* dc_layer) {
// Direct composition path only supports a single NV12 buffer.
DCHECK(quad->y_plane_resource_id() && quad->u_plane_resource_id());
DCHECK_EQ(quad->u_plane_resource_id(), quad->v_plane_resource_id());
dc_layer->resource_id = quad->y_plane_resource_id();

dc_layer->z_order = 1;
dc_layer->content_rect = gfx::ToNearestRect(quad->ya_tex_coord_rect());
dc_layer->quad_rect = quad->rect;
dc_layer->plane_z_order = 1;
dc_layer->display_rect = gfx::RectF(quad->rect);
dc_layer->resource_size_in_pixels = quad->ya_tex_size();
dc_layer->uv_rect =
gfx::ScaleRect(quad->ya_tex_coord_rect(),
1.f / dc_layer->resource_size_in_pixels.width(),
1.f / dc_layer->resource_size_in_pixels.height());

// Quad rect is in quad content space so both quad to target, and target to
// root transforms must be applied to it.
gfx::Transform quad_to_root_transform(
Expand Down Expand Up @@ -191,17 +196,20 @@ DCLayerResult ValidateTextureQuad(

void FromTextureQuad(const TextureDrawQuad* quad,
const gfx::Transform& transform_to_root_target,
DCLayerOverlayCandidate* dc_layer) {
OverlayCandidate* dc_layer) {
dc_layer->resource_id = quad->resource_id();
dc_layer->z_order = 1;
dc_layer->content_rect = gfx::Rect(quad->resource_size_in_pixels());
dc_layer->quad_rect = quad->rect;
dc_layer->plane_z_order = 1;
dc_layer->resource_size_in_pixels = quad->resource_size_in_pixels();
dc_layer->uv_rect =
gfx::BoundingRect(quad->uv_top_left, quad->uv_bottom_right);
dc_layer->display_rect = gfx::RectF(quad->rect);
// Quad rect is in quad content space so both quad to target, and target to
// root transforms must be applied to it.
gfx::Transform quad_to_root_transform;
if (quad->y_flipped) {
quad_to_root_transform.Scale(1.0, -1.0);
quad_to_root_transform.PostTranslate(0.0, dc_layer->content_rect.height());
quad_to_root_transform.PostTranslate(
0.0, dc_layer->resource_size_in_pixels.height());
}
quad_to_root_transform.PostConcat(
quad->shared_quad_state->quad_to_target_transform);
Expand Down Expand Up @@ -413,15 +421,14 @@ void RecordDCLayerResult(DCLayerResult result, QuadList::ConstIterator it) {
}

// This function records the damage rect rect of the current frame.
void RecordOverlayHistograms(
std::vector<DCLayerOverlayCandidate>* dc_layer_overlays,
bool has_occluding_surface_damage,
const gfx::Rect* damage_rect) {
void RecordOverlayHistograms(OverlayCandidateList* dc_layer_overlays,
bool has_occluding_surface_damage,
const gfx::Rect* damage_rect) {
// If an underlay is found, we record the damage rect of this frame as an
// underlay.
bool is_overlay = true;
for (const auto& dc_layer : *dc_layer_overlays) {
if (dc_layer.z_order != 1) {
if (dc_layer.plane_z_order != 1) {
is_overlay = false;
break;
}
Expand Down Expand Up @@ -464,13 +471,6 @@ bool IsClearVideoQuad(const QuadList::ConstIterator& it) {

} // namespace

DCLayerOverlayCandidate::DCLayerOverlayCandidate() = default;
DCLayerOverlayCandidate::DCLayerOverlayCandidate(
const DCLayerOverlayCandidate& other) = default;
DCLayerOverlayCandidate& DCLayerOverlayCandidate::operator=(
const DCLayerOverlayCandidate& other) = default;
DCLayerOverlayCandidate::~DCLayerOverlayCandidate() = default;

DCLayerOverlayProcessor::DCLayerOverlayProcessor(
const DebugRendererSettings* debug_settings,
int allowed_yuv_overlay_count,
Expand Down Expand Up @@ -604,7 +604,7 @@ void DCLayerOverlayProcessor::UpdateRootDamageRect(
}

void DCLayerOverlayProcessor::InsertDebugBorderDrawQuad(
const std::vector<DCLayerOverlayCandidate>* dc_layer_overlays,
const OverlayCandidateList* dc_layer_overlays,
AggregatedRenderPass* render_pass,
const gfx::RectF& display_rect,
gfx::Rect* damage_rect) {
Expand All @@ -627,13 +627,14 @@ void DCLayerOverlayProcessor::InsertDebugBorderDrawQuad(

// Add debug borders for overlays/underlays
for (const auto& dc_layer : *dc_layer_overlays) {
gfx::Rect overlay_rect = dc_layer.transform.MapRect(dc_layer.quad_rect);
gfx::Rect overlay_rect = gfx::ToEnclosingRect(
OverlayCandidate::DisplayRectInTargetSpace(dc_layer));
if (dc_layer.clip_rect)
overlay_rect.Intersect(*dc_layer.clip_rect);

// Overlay:red, Underlay:blue.
SkColor4f border_color =
dc_layer.z_order > 0 ? SkColors::kRed : SkColors::kBlue;
dc_layer.plane_z_order > 0 ? SkColors::kRed : SkColors::kBlue;
auto it =
quad_list.InsertBeforeAndInvalidateAllPointers<DebugBorderDrawQuad>(
quad_list.begin(), 1u);
Expand Down Expand Up @@ -722,7 +723,7 @@ void DCLayerOverlayProcessor::Process(
AggregatedRenderPass* render_pass,
gfx::Rect* damage_rect,
SurfaceDamageRectList surface_damage_rect_list,
std::vector<DCLayerOverlayCandidate>* dc_layer_overlays,
OverlayCandidateList* dc_layer_overlays,
bool is_video_capture_enabled,
bool is_page_fullscreen_mode) {
bool this_frame_has_occluding_damage_rect = false;
Expand Down Expand Up @@ -1043,12 +1044,12 @@ void DCLayerOverlayProcessor::UpdateDCLayerOverlays(
QuadList::Iterator* new_it,
size_t* new_index,
gfx::Rect* damage_rect,
std::vector<DCLayerOverlayCandidate>* dc_layer_overlays,
OverlayCandidateList* dc_layer_overlays,
bool is_page_fullscreen_mode) {
// Record the result first before ProcessForOverlay().
RecordDCLayerResult(DC_LAYER_SUCCESS, it);

DCLayerOverlayCandidate dc_layer;
OverlayCandidate dc_layer;
dc_layer.is_video_fullscreen_letterboxing =
is_page_fullscreen_mode
? IsFullScreenLetterboxing(it, render_pass->quad_list.end(),
Expand Down Expand Up @@ -1112,11 +1113,11 @@ void DCLayerOverlayProcessor::ProcessForUnderlay(
const QuadList::Iterator& it,
size_t processed_overlay_count,
gfx::Rect* damage_rect,
DCLayerOverlayCandidate* dc_layer) {
OverlayCandidate* dc_layer) {
// Assign decreasing z-order so that underlays processed earlier, and hence
// which are above the subsequent underlays, are placed above in the direct
// composition visual tree.
dc_layer->z_order = -1 - processed_overlay_count;
dc_layer->plane_z_order = -1 - processed_overlay_count;

// If the video is translucent and uses SrcOver blend mode, we can achieve the
// same result as compositing with video on top if we replace video quad with
Expand Down
83 changes: 17 additions & 66 deletions components/viz/service/display/dc_layer_overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/threading/thread_checker.h"
#include "components/viz/common/quads/aggregated_render_pass.h"
#include "components/viz/service/display/aggregated_frame.h"
#include "components/viz/service/display/overlay_candidate.h"
#include "components/viz/service/viz_service_export.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "third_party/skia/include/core/SkColor.h"
Expand All @@ -24,54 +25,6 @@ namespace viz {
struct DebugRendererSettings;
class DisplayResourceProvider;

// TODO(weiliangc): Eventually fold this into OverlayProcessorWin and
// OverlayCandidate class.
// Holds all information necessary to construct a direct composition overlay
// from a DrawQuad.
class VIZ_SERVICE_EXPORT DCLayerOverlayCandidate {
public:
DCLayerOverlayCandidate();
DCLayerOverlayCandidate(const DCLayerOverlayCandidate& other);
DCLayerOverlayCandidate& operator=(const DCLayerOverlayCandidate& other);
~DCLayerOverlayCandidate();

// Resource id for a single NV12 image or a swap chain image. See
// DCLayerOverlayImage for details.
ResourceId resource_id = kInvalidResourceId;

// Mailbox corresponding to |resource_id|. This is populated in SkiaRenderer
// for accessing the textures on the GPU thread.
gpu::Mailbox mailbox;

// Stacking order relative to backbuffer which has z-order 0.
int z_order = 1;

// What part of the content to display in pixels.
gfx::Rect content_rect;

// Bounds of the overlay in pre-transform space.
gfx::Rect quad_rect;

// 2D flattened transform that maps |quad_rect| to root target space,
// after applying the |quad_rect.origin()| as an offset.
gfx::Transform transform;

// If |clip_rect| is present, then clip to it in root target space.
absl::optional<gfx::Rect> clip_rect;

// This is the color-space the texture should be displayed as. If invalid,
// then the default for the texture should be used. For YUV textures, that's
// normally BT.709.
gfx::ColorSpace color_space;

gfx::ProtectedVideoType protected_video_type =
gfx::ProtectedVideoType::kClear;

gfx::HDRMetadata hdr_metadata;

bool is_video_fullscreen_letterboxing = false;
};

class VIZ_SERVICE_EXPORT DCLayerOverlayProcessor final
: public gl::DirectCompositionOverlayCapsObserver {
public:
Expand All @@ -97,7 +50,7 @@ class VIZ_SERVICE_EXPORT DCLayerOverlayProcessor final
AggregatedRenderPass* render_pass,
gfx::Rect* damage_rect,
SurfaceDamageRectList surface_damage_rect_list,
std::vector<DCLayerOverlayCandidate>* dc_layer_overlays,
OverlayCandidateList* dc_layer_overlays,
bool is_video_capture_enabled,
bool is_page_fullscreen_mode);
void ClearOverlayState();
Expand All @@ -121,17 +74,16 @@ class VIZ_SERVICE_EXPORT DCLayerOverlayProcessor final

// UpdateDCLayerOverlays() adds the quad at |it| to the overlay list
// |dc_layer_overlays|.
void UpdateDCLayerOverlays(
const gfx::RectF& display_rect,
AggregatedRenderPass* render_pass,
const QuadList::Iterator& it,
const gfx::Rect& quad_rectangle_in_root_space,
bool is_overlay,
QuadList::Iterator* new_it,
size_t* new_index,
gfx::Rect* damage_rect,
std::vector<DCLayerOverlayCandidate>* dc_layer_overlays,
bool is_page_fullscreen_mode);
void UpdateDCLayerOverlays(const gfx::RectF& display_rect,
AggregatedRenderPass* render_pass,
const QuadList::Iterator& it,
const gfx::Rect& quad_rectangle_in_root_space,
bool is_overlay,
QuadList::Iterator* new_it,
size_t* new_index,
gfx::Rect* damage_rect,
OverlayCandidateList* dc_layer_overlays,
bool is_page_fullscreen_mode);

// Returns an iterator to the element after |it|.
QuadList::Iterator ProcessForOverlay(const gfx::RectF& display_rect,
Expand All @@ -143,18 +95,17 @@ class VIZ_SERVICE_EXPORT DCLayerOverlayProcessor final
const QuadList::Iterator& it,
size_t processed_overlay_count,
gfx::Rect* damage_rect,
DCLayerOverlayCandidate* dc_layer);
OverlayCandidate* dc_layer);

void UpdateRootDamageRect(const gfx::RectF& display_rect,
gfx::Rect* damage_rect);

void RemoveOverlayDamageRect(const QuadList::Iterator& it);

void InsertDebugBorderDrawQuad(
const std::vector<DCLayerOverlayCandidate>* dc_layer_overlays,
AggregatedRenderPass* render_pass,
const gfx::RectF& display_rect,
gfx::Rect* damage_rect);
void InsertDebugBorderDrawQuad(const OverlayCandidateList* dc_layer_overlays,
AggregatedRenderPass* render_pass,
const gfx::RectF& display_rect,
gfx::Rect* damage_rect);
bool IsPreviousFrameUnderlayRect(const gfx::Rect& quad_rectangle,
size_t index);

Expand Down
8 changes: 8 additions & 0 deletions components/viz/service/display/overlay_candidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ui/gfx/hdr_metadata.h"
#include "ui/gfx/overlay_priority_hint.h"
#include "ui/gfx/overlay_transform.h"
#include "ui/gfx/video_types.h"

namespace gfx {
class Rect;
Expand Down Expand Up @@ -131,6 +132,13 @@ class VIZ_SERVICE_EXPORT OverlayCandidate {
// Mailbox from resource_id. It is used by SkiaRenderer.
gpu::Mailbox mailbox;

#if BUILDFLAG(IS_WIN)
gfx::ProtectedVideoType protected_video_type =
gfx::ProtectedVideoType::kClear;

bool is_video_fullscreen_letterboxing = false;
#endif

#if BUILDFLAG(IS_ANDROID)
// For candidates from TextureDrawQuads with is_stream_video set to true, this
// records whether the quad is marked as being backed by a SurfaceTexture or
Expand Down

0 comments on commit 98c8470

Please sign in to comment.