Commit 53142d1d authored by Richard Li's avatar Richard Li Committed by Commit Bot

Enable allow-tearing for video overlays

Chromium has the command-line option "disable-gpu-vsync" to control
presentation with vblank but it doesn't take effect when presenting
video with overlays. This CL enables this feature to reduce video
presenting latency.


Change-Id: I1e74937d15ff8a9f0355fea57a62f3431c27b9ff
Bug: 807406
Change-Id: I1e74937d15ff8a9f0355fea57a62f3431c27b9ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1905266
Commit-Queue: Richard Li <richard.li@intel.com>
Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715569}
parent 896db8dc
......@@ -41,12 +41,6 @@ namespace {
// is made current, then this surface will be suspended.
IDCompositionSurface* g_current_surface = nullptr;
bool AllowTearing() {
// Swap chain tearing is used only if vsync is disabled explicitly.
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGpuVsync) &&
DirectCompositionSurfaceWin::IsSwapChainTearingSupported();
}
} // namespace
DirectCompositionChildSurfaceWin::DirectCompositionChildSurfaceWin() = default;
......@@ -117,8 +111,11 @@ bool DirectCompositionChildSurfaceWin::ReleaseDrawTexture(bool will_discard) {
dcomp_surface_serial_++;
} else if (!will_discard) {
TRACE_EVENT0("gpu", "DirectCompositionChildSurfaceWin::PresentSwapChain");
UINT interval = first_swap_ || !vsync_enabled_ || AllowTearing() ? 0 : 1;
UINT flags = AllowTearing() ? DXGI_PRESENT_ALLOW_TEARING : 0;
const bool use_swap_chain_tearing =
DirectCompositionSurfaceWin::AllowTearing();
UINT interval =
first_swap_ || !vsync_enabled_ || use_swap_chain_tearing ? 0 : 1;
UINT flags = use_swap_chain_tearing ? DXGI_PRESENT_ALLOW_TEARING : 0;
DXGI_PRESENT_PARAMETERS params = {};
RECT dirty_rect = swap_rect_.ToRECT();
params.DirtyRectsCount = 1;
......@@ -307,7 +304,9 @@ bool DirectCompositionChildSurfaceWin::SetDrawRectangle(
desc.AlphaMode = (has_alpha_ || enable_dc_layers_)
? DXGI_ALPHA_MODE_PREMULTIPLIED
: DXGI_ALPHA_MODE_IGNORE;
desc.Flags = AllowTearing() ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0;
desc.Flags = DirectCompositionSurfaceWin::AllowTearing()
? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING
: 0;
HRESULT hr = dxgi_factory->CreateSwapChainForComposition(
d3d11_device_.Get(), &desc, nullptr, &swap_chain_);
first_swap_ = true;
......@@ -405,7 +404,9 @@ bool DirectCompositionChildSurfaceWin::Resize(const gfx::Size& size,
// ResizeBuffers can't change alpha blending mode.
if (swap_chain_ && resize_only) {
DXGI_FORMAT format = ColorSpaceUtils::GetDXGIFormat(color_space_);
UINT flags = AllowTearing() ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0;
UINT flags = DirectCompositionSurfaceWin::AllowTearing()
? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING
: 0;
HRESULT hr = swap_chain_->ResizeBuffers(2 /* BufferCount */, size.width(),
size.height(), format, flags);
UMA_HISTOGRAM_BOOLEAN("GPU.DirectComposition.SwapChainResizeResult",
......
......@@ -444,6 +444,14 @@ bool DirectCompositionSurfaceWin::IsSwapChainTearingSupported() {
return supported;
}
// static
bool DirectCompositionSurfaceWin::AllowTearing() {
// Swap chain tearing is used only if vsync is disabled explicitly.
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGpuVsync) &&
DirectCompositionSurfaceWin::IsSwapChainTearingSupported();
}
bool DirectCompositionSurfaceWin::Initialize(GLSurfaceFormat format) {
d3d11_device_ = QueryD3D11DeviceObjectFromANGLE();
if (!d3d11_device_) {
......
......@@ -81,6 +81,8 @@ class GL_EXPORT DirectCompositionSurfaceWin : public GLSurfaceEGL,
// Returns true if swap chain tearing is supported.
static bool IsSwapChainTearingSupported();
static bool AllowTearing();
static void SetScaledOverlaysSupportedForTesting(bool value);
static void SetOverlayFormatUsedForTesting(DXGI_FORMAT format);
......
......@@ -872,10 +872,13 @@ bool SwapChainPresenter::PresentToSwapChain(
DCHECK(SUCCEEDED(hr));
event.Wait();
}
const bool use_swap_chain_tearing =
DirectCompositionSurfaceWin::AllowTearing();
UINT flags = use_swap_chain_tearing ? DXGI_PRESENT_ALLOW_TEARING : 0;
UINT interval = use_swap_chain_tearing ? 0 : 1;
// Ignore DXGI_STATUS_OCCLUDED since that's not an error but only indicates
// that the window is occluded and we can stop rendering.
HRESULT hr = swap_chain_->Present(1, 0);
HRESULT hr = swap_chain_->Present(interval, flags);
if (FAILED(hr) && hr != DXGI_STATUS_OCCLUDED) {
DLOG(ERROR) << "Present failed with error 0x" << std::hex << hr;
return false;
......@@ -1159,6 +1162,8 @@ bool SwapChainPresenter::ReallocateSwapChain(
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
desc.Flags =
DXGI_SWAP_CHAIN_FLAG_YUV_VIDEO | DXGI_SWAP_CHAIN_FLAG_FULLSCREEN_VIDEO;
if (DirectCompositionSurfaceWin::AllowTearing())
desc.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
if (IsProtectedVideo(protected_video_type))
desc.Flags |= DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY;
if (protected_video_type == gfx::ProtectedVideoType::kHardwareProtected)
......@@ -1205,6 +1210,8 @@ bool SwapChainPresenter::ReallocateSwapChain(
desc.Flags |= DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY;
if (protected_video_type == gfx::ProtectedVideoType::kHardwareProtected)
desc.Flags |= DXGI_SWAP_CHAIN_FLAG_HW_PROTECTED;
if (DirectCompositionSurfaceWin::AllowTearing())
desc.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
HRESULT hr = media_factory->CreateSwapChainForCompositionSurfaceHandle(
d3d11_device_.Get(), swap_chain_handle_.Get(), &desc, nullptr,
......
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