Commit b3ebda54 authored by Maggie Chen's avatar Maggie Chen Committed by Commit Bot

Update the hardware overlay cap query in Direct Composition

Rename InitializeHardwareOverlaySupport() to
UpdateHardwareOverlaySupport() and update the code of hardware overlay
cap query in preparation for display change.

Bug: 1042989
Change-Id: Iff36a6a5b4caf49c730736550e11360ee69d6513
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2013320Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Commit-Queue: Maggie Chen <magchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733892}
parent 671029f8
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
namespace gl { namespace gl {
namespace { namespace {
// Whether the overlay caps are valid or not.
bool g_overlay_caps_valid = false;
// Indicates support for either NV12 or YUY2 hardware overlays. // Indicates support for either NV12 or YUY2 hardware overlays.
bool g_supports_overlays = false; bool g_supports_overlays = false;
...@@ -51,11 +53,19 @@ bool FlagsSupportsOverlays(UINT flags) { ...@@ -51,11 +53,19 @@ bool FlagsSupportsOverlays(UINT flags) {
DXGI_OVERLAY_SUPPORT_FLAG_SCALING)); DXGI_OVERLAY_SUPPORT_FLAG_SCALING));
} }
void InitializeHardwareOverlaySupport() { void UpdateHardwareOverlaySupport() {
static bool overlay_support_initialized = false; if (g_overlay_caps_valid)
if (overlay_support_initialized)
return; return;
overlay_support_initialized = true; g_overlay_caps_valid = true;
bool prev_supports_overlays = g_supports_overlays;
DXGI_FORMAT prev_overlay_format_used = g_overlay_format_used;
// Reset all caps in case of early exit.
g_supports_overlays = false;
g_overlay_format_used = DXGI_FORMAT_NV12;
g_nv12_overlay_support_flags = 0;
g_yuy2_overlay_support_flags = 0;
g_overlay_monitor_size = gfx::Size();
// Check for DirectComposition support first to prevent likely crashes. // Check for DirectComposition support first to prevent likely crashes.
if (!DirectCompositionSurfaceWin::IsDirectCompositionSupported()) if (!DirectCompositionSurfaceWin::IsDirectCompositionSupported())
...@@ -92,6 +102,8 @@ void InitializeHardwareOverlaySupport() { ...@@ -92,6 +102,8 @@ void InitializeHardwareOverlaySupport() {
return; return;
} }
bool supports_overlays = false;
DXGI_FORMAT overlay_format_used = DXGI_FORMAT_NV12;
unsigned int i = 0; unsigned int i = 0;
while (true) { while (true) {
Microsoft::WRL::ComPtr<IDXGIOutput> output; Microsoft::WRL::ComPtr<IDXGIOutput> output;
...@@ -128,17 +140,17 @@ void InitializeHardwareOverlaySupport() { ...@@ -128,17 +140,17 @@ void InitializeHardwareOverlaySupport() {
// performing an extra scaling Blt before calling the driver. Even when // performing an extra scaling Blt before calling the driver. Even when
// scaled overlays aren't actually supported, presentation using the // scaled overlays aren't actually supported, presentation using the
// overlay path should be relatively efficient. // overlay path should be relatively efficient.
g_overlay_format_used = DXGI_FORMAT_NV12; overlay_format_used = DXGI_FORMAT_NV12;
g_supports_overlays = true; supports_overlays = true;
} }
} }
if (!g_supports_overlays && if (!supports_overlays &&
FlagsSupportsOverlays(g_yuy2_overlay_support_flags)) { FlagsSupportsOverlays(g_yuy2_overlay_support_flags)) {
// If NV12 isn't supported, fallback to YUY2 if it's supported. // If NV12 isn't supported, fallback to YUY2 if it's supported.
g_overlay_format_used = DXGI_FORMAT_YUY2; overlay_format_used = DXGI_FORMAT_YUY2;
g_supports_overlays = true; supports_overlays = true;
} }
if (g_supports_overlays) { if (supports_overlays) {
DXGI_OUTPUT_DESC monitor_desc = {}; DXGI_OUTPUT_DESC monitor_desc = {};
if (SUCCEEDED(output3->GetDesc(&monitor_desc))) { if (SUCCEEDED(output3->GetDesc(&monitor_desc))) {
g_overlay_monitor_size = g_overlay_monitor_size =
...@@ -151,15 +163,23 @@ void InitializeHardwareOverlaySupport() { ...@@ -151,15 +163,23 @@ void InitializeHardwareOverlaySupport() {
// https://docs.microsoft.com/en-us/windows-hardware/drivers/display/multiplane-overlay-hardware-requirements // https://docs.microsoft.com/en-us/windows-hardware/drivers/display/multiplane-overlay-hardware-requirements
// TODO(sunnyps): If the above is true, then we can only look at first // TODO(sunnyps): If the above is true, then we can only look at first
// output instead of iterating over all outputs. // output instead of iterating over all outputs.
if (g_supports_overlays) if (supports_overlays)
break; break;
} }
if (g_supports_overlays) {
g_supports_overlays = supports_overlays;
g_overlay_format_used = overlay_format_used;
if (supports_overlays != prev_supports_overlays ||
overlay_format_used != prev_overlay_format_used) {
// Record the new histograms
if (supports_overlays) {
base::UmaHistogramSparse("GPU.DirectComposition.OverlayFormatUsed3", base::UmaHistogramSparse("GPU.DirectComposition.OverlayFormatUsed3",
g_overlay_format_used); overlay_format_used);
} }
UMA_HISTOGRAM_BOOLEAN("GPU.DirectComposition.OverlaysSupported", UMA_HISTOGRAM_BOOLEAN("GPU.DirectComposition.OverlaysSupported",
g_supports_overlays); supports_overlays);
}
} }
bool SupportsPresentationFeedback() { bool SupportsPresentationFeedback() {
...@@ -267,7 +287,7 @@ bool DirectCompositionSurfaceWin::IsDirectCompositionSupported() { ...@@ -267,7 +287,7 @@ bool DirectCompositionSurfaceWin::IsDirectCompositionSupported() {
bool DirectCompositionSurfaceWin::AreOverlaysSupported() { bool DirectCompositionSurfaceWin::AreOverlaysSupported() {
// Always initialize and record overlay support information irrespective of // Always initialize and record overlay support information irrespective of
// command line flags. // command line flags.
InitializeHardwareOverlaySupport(); UpdateHardwareOverlaySupport();
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
// Enable flag should be checked before the disable flag, so we could // Enable flag should be checked before the disable flag, so we could
...@@ -284,7 +304,7 @@ bool DirectCompositionSurfaceWin::AreOverlaysSupported() { ...@@ -284,7 +304,7 @@ bool DirectCompositionSurfaceWin::AreOverlaysSupported() {
bool DirectCompositionSurfaceWin::IsDecodeSwapChainSupported() { bool DirectCompositionSurfaceWin::IsDecodeSwapChainSupported() {
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
features::kDirectCompositionUseNV12DecodeSwapChain)) { features::kDirectCompositionUseNV12DecodeSwapChain)) {
InitializeHardwareOverlaySupport(); UpdateHardwareOverlaySupport();
return GetOverlayFormatUsed() == DXGI_FORMAT_NV12; return GetOverlayFormatUsed() == DXGI_FORMAT_NV12;
} }
return false; return false;
...@@ -295,9 +315,14 @@ void DirectCompositionSurfaceWin::DisableOverlays() { ...@@ -295,9 +315,14 @@ void DirectCompositionSurfaceWin::DisableOverlays() {
g_supports_overlays = false; g_supports_overlays = false;
} }
// static
void DirectCompositionSurfaceWin::InvalidateOverlayCaps() {
g_overlay_caps_valid = false;
}
// static // static
bool DirectCompositionSurfaceWin::AreScaledOverlaysSupported() { bool DirectCompositionSurfaceWin::AreScaledOverlaysSupported() {
InitializeHardwareOverlaySupport(); UpdateHardwareOverlaySupport();
if (g_overlay_format_used == DXGI_FORMAT_NV12) if (g_overlay_format_used == DXGI_FORMAT_NV12)
return !!(g_nv12_overlay_support_flags & DXGI_OVERLAY_SUPPORT_FLAG_SCALING); return !!(g_nv12_overlay_support_flags & DXGI_OVERLAY_SUPPORT_FLAG_SCALING);
DCHECK_EQ(DXGI_FORMAT_YUY2, g_overlay_format_used); DCHECK_EQ(DXGI_FORMAT_YUY2, g_overlay_format_used);
...@@ -306,7 +331,7 @@ bool DirectCompositionSurfaceWin::AreScaledOverlaysSupported() { ...@@ -306,7 +331,7 @@ bool DirectCompositionSurfaceWin::AreScaledOverlaysSupported() {
// static // static
UINT DirectCompositionSurfaceWin::GetOverlaySupportFlags(DXGI_FORMAT format) { UINT DirectCompositionSurfaceWin::GetOverlaySupportFlags(DXGI_FORMAT format) {
InitializeHardwareOverlaySupport(); UpdateHardwareOverlaySupport();
if (format == DXGI_FORMAT_NV12) if (format == DXGI_FORMAT_NV12)
return g_nv12_overlay_support_flags; return g_nv12_overlay_support_flags;
DCHECK_EQ(DXGI_FORMAT_YUY2, format); DCHECK_EQ(DXGI_FORMAT_YUY2, format);
...@@ -326,7 +351,7 @@ DXGI_FORMAT DirectCompositionSurfaceWin::GetOverlayFormatUsed() { ...@@ -326,7 +351,7 @@ DXGI_FORMAT DirectCompositionSurfaceWin::GetOverlayFormatUsed() {
// static // static
void DirectCompositionSurfaceWin::SetScaledOverlaysSupportedForTesting( void DirectCompositionSurfaceWin::SetScaledOverlaysSupportedForTesting(
bool supported) { bool supported) {
InitializeHardwareOverlaySupport(); UpdateHardwareOverlaySupport();
if (supported) { if (supported) {
g_nv12_overlay_support_flags |= DXGI_OVERLAY_SUPPORT_FLAG_SCALING; g_nv12_overlay_support_flags |= DXGI_OVERLAY_SUPPORT_FLAG_SCALING;
g_yuy2_overlay_support_flags |= DXGI_OVERLAY_SUPPORT_FLAG_SCALING; g_yuy2_overlay_support_flags |= DXGI_OVERLAY_SUPPORT_FLAG_SCALING;
...@@ -341,7 +366,7 @@ void DirectCompositionSurfaceWin::SetScaledOverlaysSupportedForTesting( ...@@ -341,7 +366,7 @@ void DirectCompositionSurfaceWin::SetScaledOverlaysSupportedForTesting(
void DirectCompositionSurfaceWin::SetOverlayFormatUsedForTesting( void DirectCompositionSurfaceWin::SetOverlayFormatUsedForTesting(
DXGI_FORMAT format) { DXGI_FORMAT format) {
DCHECK(format == DXGI_FORMAT_NV12 || format == DXGI_FORMAT_YUY2); DCHECK(format == DXGI_FORMAT_NV12 || format == DXGI_FORMAT_YUY2);
InitializeHardwareOverlaySupport(); UpdateHardwareOverlaySupport();
g_overlay_format_used = format; g_overlay_format_used = format;
DCHECK_EQ(format, GetOverlayFormatUsed()); DCHECK_EQ(format, GetOverlayFormatUsed());
} }
......
...@@ -60,6 +60,9 @@ class GL_EXPORT DirectCompositionSurfaceWin : public GLSurfaceEGL, ...@@ -60,6 +60,9 @@ class GL_EXPORT DirectCompositionSurfaceWin : public GLSurfaceEGL,
// current GPU process' lifetime. // current GPU process' lifetime.
static void DisableOverlays(); static void DisableOverlays();
// Indicate the overlay caps are invalid.
static void InvalidateOverlayCaps();
// Returns true if scaled hardware overlays are supported. // Returns true if scaled hardware overlays are supported.
static bool AreScaledOverlaysSupported(); static bool AreScaledOverlaysSupported();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment