Commit b3d05379 authored by Richard Li's avatar Richard Li Committed by Commit Bot

Move media::HDRMetadata, media::DisplayHelper to ui/gl/

We need to pass HDRMetadata to SwapChainPresenter which needs proper
metadata to set video processor. Moving media::HDRMetadata to ui/gl/ is
a prepared work for that.
This CL also move media::DisplayHelper to ui/gl/. Since it only provide
functions related with HDRMetadata, this CL renames it to
HDRMetadataHelper.

Bug: 1122910
Change-Id: I0670c210cd0c194bf0ec1872cb5442d1f6a9b324
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387620
Commit-Queue: Richard Li <richard.li@intel.com>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804522}
parent ee8b2266
...@@ -161,7 +161,6 @@ source_set("base") { ...@@ -161,7 +161,6 @@ source_set("base") {
"format_utils.h", "format_utils.h",
"frame_rate_estimator.cc", "frame_rate_estimator.cc",
"frame_rate_estimator.h", "frame_rate_estimator.h",
"hdr_metadata.cc",
"hdr_metadata.h", "hdr_metadata.h",
"key_system_names.cc", "key_system_names.cc",
"key_system_names.h", "key_system_names.h",
...@@ -347,6 +346,7 @@ source_set("base") { ...@@ -347,6 +346,7 @@ source_set("base") {
"//media:media_buildflags", "//media:media_buildflags",
"//media:shared_memory_support", "//media:shared_memory_support",
"//ui/gfx:color_space", "//ui/gfx:color_space",
"//ui/gl",
] ]
deps = [ deps = [
"//base/allocator:buildflags", "//base/allocator:buildflags",
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/macros.h" #include "base/macros.h"
#include "media/base/hdr_metadata.h"
namespace media { namespace media {
struct HDRMetadata;
class VideoColorSpace; class VideoColorSpace;
class JniHdrMetadata { class JniHdrMetadata {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "media/base/android/media_codec_bridge.h" #include "media/base/android/media_codec_bridge.h"
#include "media/base/android/media_codec_direction.h" #include "media/base/android/media_codec_direction.h"
#include "media/base/audio_decoder_config.h" #include "media/base/audio_decoder_config.h"
#include "media/base/hdr_metadata.h"
#include "media/base/media_export.h" #include "media/base/media_export.h"
#include "media/base/video_decoder_config.h" #include "media/base/video_decoder_config.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -24,7 +25,6 @@ ...@@ -24,7 +25,6 @@
namespace media { namespace media {
class VideoColorSpace; class VideoColorSpace;
struct HDRMetadata;
// Configuration info for MediaCodec. // Configuration info for MediaCodec.
class MEDIA_EXPORT VideoCodecConfig { class MEDIA_EXPORT VideoCodecConfig {
......
...@@ -5,61 +5,15 @@ ...@@ -5,61 +5,15 @@
#ifndef MEDIA_BASE_HDR_METADATA_H_ #ifndef MEDIA_BASE_HDR_METADATA_H_
#define MEDIA_BASE_HDR_METADATA_H_ #define MEDIA_BASE_HDR_METADATA_H_
#include "media/base/media_export.h" #include "ui/gl/hdr_metadata.h"
#include "ui/gfx/geometry/point_f.h"
namespace media { namespace media {
// SMPTE ST 2086 mastering metadata. // TODO(crbug.com/1122910):Delete this file and switch all instances to the gl
struct MEDIA_EXPORT MasteringMetadata { // versions.
using Chromaticity = gfx::PointF; using HDRMetadata = gl::HDRMetadata;
Chromaticity primary_r; using MasteringMetadata = gl::MasteringMetadata;
Chromaticity primary_g; using HdrMetadataType = gl::HdrMetadataType;
Chromaticity primary_b;
Chromaticity white_point;
float luminance_max = 0;
float luminance_min = 0;
MasteringMetadata();
MasteringMetadata(const MasteringMetadata& rhs);
bool operator==(const MasteringMetadata& rhs) const {
return ((primary_r == rhs.primary_r) && (primary_g == rhs.primary_g) &&
(primary_b == rhs.primary_b) && (white_point == rhs.white_point) &&
(luminance_max == rhs.luminance_max) &&
(luminance_min == rhs.luminance_min));
}
};
// HDR metadata common for HDR10 and WebM/VP9-based HDR formats.
struct MEDIA_EXPORT HDRMetadata {
MasteringMetadata mastering_metadata;
// Max content light level (CLL), i.e. maximum brightness level present in the
// stream), in nits.
unsigned max_content_light_level = 0;
// Max frame-average light level (FALL), i.e. maximum average brightness of
// the brightest frame in the stream), in nits.
unsigned max_frame_average_light_level = 0;
HDRMetadata();
HDRMetadata(const HDRMetadata& rhs);
bool operator==(const HDRMetadata& rhs) const {
return (
(max_content_light_level == rhs.max_content_light_level) &&
(max_frame_average_light_level == rhs.max_frame_average_light_level) &&
(mastering_metadata == rhs.mastering_metadata));
}
};
// HDR metadata types as described in
// https://w3c.github.io/media-capabilities/#enumdef-hdrmetadatatype
enum class HdrMetadataType {
kNone,
kSmpteSt2086,
kSmpteSt2094_10,
kSmpteSt2094_40,
};
} // namespace media } // namespace media
......
...@@ -196,8 +196,6 @@ component("gpu") { ...@@ -196,8 +196,6 @@ component("gpu") {
"windows/d3d11_vp9_accelerator.h", "windows/d3d11_vp9_accelerator.h",
"windows/d3d11_vp9_picture.cc", "windows/d3d11_vp9_picture.cc",
"windows/d3d11_vp9_picture.h", "windows/d3d11_vp9_picture.h",
"windows/display_helper.cc",
"windows/display_helper.h",
"windows/dxva_picture_buffer_win.cc", "windows/dxva_picture_buffer_win.cc",
"windows/dxva_picture_buffer_win.h", "windows/dxva_picture_buffer_win.h",
"windows/dxva_video_decode_accelerator_win.cc", "windows/dxva_video_decode_accelerator_win.cc",
...@@ -520,7 +518,6 @@ source_set("unit_tests") { ...@@ -520,7 +518,6 @@ source_set("unit_tests") {
"windows/d3d11_video_decoder_unittest.cc", "windows/d3d11_video_decoder_unittest.cc",
"windows/d3d11_video_device_format_support_unittest.cc", "windows/d3d11_video_device_format_support_unittest.cc",
"windows/d3d11_video_processor_proxy_unittest.cc", "windows/d3d11_video_processor_proxy_unittest.cc",
"windows/display_helper_unittest.cc",
"windows/supported_profile_helpers_unittest.cc", "windows/supported_profile_helpers_unittest.cc",
] ]
libs = [ "dxguid.lib" ] libs = [ "dxguid.lib" ]
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "media/base/status_codes.h" #include "media/base/status_codes.h"
#include "media/base/win/hresult_status_helper.h" #include "media/base/win/hresult_status_helper.h"
#include "media/gpu/windows/d3d11_com_defs.h" #include "media/gpu/windows/d3d11_com_defs.h"
#include "media/gpu/windows/display_helper.h" #include "ui/gl/hdr_metadata_helper_win.h"
namespace media { namespace media {
...@@ -102,7 +102,8 @@ Status CopyingTexture2DWrapper::Init( ...@@ -102,7 +102,8 @@ Status CopyingTexture2DWrapper::Init(
void CopyingTexture2DWrapper::SetStreamHDRMetadata( void CopyingTexture2DWrapper::SetStreamHDRMetadata(
const HDRMetadata& stream_metadata) { const HDRMetadata& stream_metadata) {
auto dxgi_stream_metadata = DisplayHelper::HdrMetadataToDXGI(stream_metadata); auto dxgi_stream_metadata =
gl::HDRMetadataHelperWin::HDRMetadataToDXGI(stream_metadata);
video_processor_->SetStreamHDRMetadata(dxgi_stream_metadata); video_processor_->SetStreamHDRMetadata(dxgi_stream_metadata);
} }
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include "media/gpu/windows/d3d11_copying_texture_wrapper.h" #include "media/gpu/windows/d3d11_copying_texture_wrapper.h"
#include "media/gpu/windows/d3d11_texture_wrapper.h" #include "media/gpu/windows/d3d11_texture_wrapper.h"
#include "media/gpu/windows/d3d11_video_processor_proxy.h" #include "media/gpu/windows/d3d11_video_processor_proxy.h"
#include "media/gpu/windows/display_helper.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/hdr_metadata_helper_win.h"
using ::testing::_; using ::testing::_;
using ::testing::Bool; using ::testing::Bool;
...@@ -273,7 +273,7 @@ TEST_P(D3D11CopyingTexture2DWrapperTest, HDRMetadataIsSentToVideoProcessor) { ...@@ -273,7 +273,7 @@ TEST_P(D3D11CopyingTexture2DWrapperTest, HDRMetadataIsSentToVideoProcessor) {
nullptr, gfx::ColorSpace::CreateSCRGBLinear()); nullptr, gfx::ColorSpace::CreateSCRGBLinear());
const DXGI_HDR_METADATA_HDR10 dxgi_metadata = const DXGI_HDR_METADATA_HDR10 dxgi_metadata =
DisplayHelper::HdrMetadataToDXGI(metadata); gl::HDRMetadataHelperWin::HDRMetadataToDXGI(metadata);
wrapper->SetStreamHDRMetadata(metadata); wrapper->SetStreamHDRMetadata(metadata);
EXPECT_TRUE(processor_raw->last_stream_metadata_); EXPECT_TRUE(processor_raw->last_stream_metadata_);
......
...@@ -32,11 +32,11 @@ ...@@ -32,11 +32,11 @@
#include "media/gpu/windows/d3d11_video_context_wrapper.h" #include "media/gpu/windows/d3d11_video_context_wrapper.h"
#include "media/gpu/windows/d3d11_video_decoder_impl.h" #include "media/gpu/windows/d3d11_video_decoder_impl.h"
#include "media/gpu/windows/d3d11_video_device_format_support.h" #include "media/gpu/windows/d3d11_video_device_format_support.h"
#include "media/gpu/windows/display_helper.h"
#include "media/gpu/windows/supported_profile_helpers.h" #include "media/gpu/windows/supported_profile_helpers.h"
#include "media/media_buildflags.h" #include "media/media_buildflags.h"
#include "ui/gl/gl_angle_util_win.h" #include "ui/gl/gl_angle_util_win.h"
#include "ui/gl/gl_switches.h" #include "ui/gl/gl_switches.h"
#include "ui/gl/hdr_metadata_helper_win.h"
namespace media { namespace media {
...@@ -697,8 +697,8 @@ void D3D11VideoDecoder::CreatePictureBuffers() { ...@@ -697,8 +697,8 @@ void D3D11VideoDecoder::CreatePictureBuffers() {
if (decoder_configurator_->TextureFormat() == DXGI_FORMAT_P010) { if (decoder_configurator_->TextureFormat() == DXGI_FORMAT_P010) {
// For HDR formats, try to get the display metadata. This may fail, which // For HDR formats, try to get the display metadata. This may fail, which
// is okay. We'll just skip sending the metadata. // is okay. We'll just skip sending the metadata.
DisplayHelper display_helper(device_); gl::HDRMetadataHelperWin hdr_metadata_helper(device_);
display_metadata = display_helper.GetDisplayMetadata(); display_metadata = hdr_metadata_helper.GetDisplayMetadata();
} }
// Drop any old pictures. // Drop any old pictures.
......
...@@ -972,7 +972,7 @@ bool DXVAVideoDecodeAccelerator::CreateDX11DevManager() { ...@@ -972,7 +972,7 @@ bool DXVAVideoDecodeAccelerator::CreateDX11DevManager() {
} }
// Create the display information. // Create the display information.
display_helper_.emplace(D3D11Device()); hdr_metadata_helper_.emplace(D3D11Device());
hr = d3d11_device_context_.As(&video_context_); hr = d3d11_device_context_.As(&video_context_);
RETURN_ON_HR_FAILURE(hr, "Failed to get video context", false); RETURN_ON_HR_FAILURE(hr, "Failed to get video context", false);
...@@ -2934,13 +2934,13 @@ bool DXVAVideoDecodeAccelerator::InitializeID3D11VideoProcessor( ...@@ -2934,13 +2934,13 @@ bool DXVAVideoDecodeAccelerator::InitializeID3D11VideoProcessor(
} }
void DXVAVideoDecodeAccelerator::SetDX11ProcessorHDRMetadataIfNeeded() { void DXVAVideoDecodeAccelerator::SetDX11ProcessorHDRMetadataIfNeeded() {
DCHECK(display_helper_); DCHECK(hdr_metadata_helper_);
// If we don't know the input metadata, then we'll still send the // If we don't know the input metadata, then we'll still send the
// monitor output. // monitor output.
// Do nothing without display metadata. // Do nothing without display metadata.
auto dxgi_display_metadata = display_helper_->GetDisplayMetadata(); auto dxgi_display_metadata = hdr_metadata_helper_->GetDisplayMetadata();
if (!dxgi_display_metadata) if (!dxgi_display_metadata)
return; return;
...@@ -2958,7 +2958,7 @@ void DXVAVideoDecodeAccelerator::SetDX11ProcessorHDRMetadataIfNeeded() { ...@@ -2958,7 +2958,7 @@ void DXVAVideoDecodeAccelerator::SetDX11ProcessorHDRMetadataIfNeeded() {
stream_metadata = *config_.hdr_metadata; stream_metadata = *config_.hdr_metadata;
DXGI_HDR_METADATA_HDR10 dxgi_stream_metadata = DXGI_HDR_METADATA_HDR10 dxgi_stream_metadata =
DisplayHelper::HdrMetadataToDXGI(stream_metadata); gl::HDRMetadataHelperWin::HDRMetadataToDXGI(stream_metadata);
video_context2->VideoProcessorSetStreamHDRMetaData( video_context2->VideoProcessorSetStreamHDRMetaData(
d3d11_processor_.Get(), 0, DXGI_HDR_METADATA_TYPE_HDR10, d3d11_processor_.Get(), 0, DXGI_HDR_METADATA_TYPE_HDR10,
......
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
#include "media/gpu/gpu_video_decode_accelerator_helpers.h" #include "media/gpu/gpu_video_decode_accelerator_helpers.h"
#include "media/gpu/media_gpu_export.h" #include "media/gpu/media_gpu_export.h"
#include "media/gpu/windows/d3d11_com_defs.h" #include "media/gpu/windows/d3d11_com_defs.h"
#include "media/gpu/windows/display_helper.h"
#include "media/video/video_decode_accelerator.h" #include "media/video/video_decode_accelerator.h"
#include "ui/gfx/color_space.h" #include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gl/hdr_metadata_helper_win.h"
interface IMFSample; interface IMFSample;
interface IDirect3DSurface9; interface IDirect3DSurface9;
...@@ -607,7 +607,7 @@ class MEDIA_GPU_EXPORT DXVAVideoDecodeAccelerator ...@@ -607,7 +607,7 @@ class MEDIA_GPU_EXPORT DXVAVideoDecodeAccelerator
gfx::Rect current_visible_rect_; gfx::Rect current_visible_rect_;
VideoColorSpace current_color_space_; VideoColorSpace current_color_space_;
base::Optional<DisplayHelper> display_helper_; base::Optional<gl::HDRMetadataHelperWin> hdr_metadata_helper_;
bool use_empty_video_hdr_metadata_ = false; bool use_empty_video_hdr_metadata_ = false;
// WeakPtrFactory for posting tasks back to |this|. // WeakPtrFactory for posting tasks back to |this|.
......
...@@ -132,6 +132,8 @@ component("gl") { ...@@ -132,6 +132,8 @@ component("gl") {
"gpu_switching_manager.h", "gpu_switching_manager.h",
"gpu_timing.cc", "gpu_timing.cc",
"gpu_timing.h", "gpu_timing.h",
"hdr_metadata.cc",
"hdr_metadata.h",
"progress_reporter.h", "progress_reporter.h",
"scoped_binders.cc", "scoped_binders.cc",
"scoped_binders.h", "scoped_binders.h",
...@@ -321,6 +323,8 @@ component("gl") { ...@@ -321,6 +323,8 @@ component("gl") {
"gl_surface_wgl.h", "gl_surface_wgl.h",
"gl_wgl_api_implementation.cc", "gl_wgl_api_implementation.cc",
"gl_wgl_api_implementation.h", "gl_wgl_api_implementation.h",
"hdr_metadata_helper_win.cc",
"hdr_metadata_helper_win.h",
"swap_chain_presenter.cc", "swap_chain_presenter.cc",
"swap_chain_presenter.h", "swap_chain_presenter.h",
"vsync_observer.h", "vsync_observer.h",
...@@ -575,6 +579,7 @@ test("gl_unittests") { ...@@ -575,6 +579,7 @@ test("gl_unittests") {
"direct_composition_surface_win_unittest.cc", "direct_composition_surface_win_unittest.cc",
"gl_image_d3d_unittest.cc", "gl_image_d3d_unittest.cc",
"gl_image_dxgi_unittest.cc", "gl_image_dxgi_unittest.cc",
"hdr_metadata_helper_win_unittest.cc",
"wgl_api_unittest.cc", "wgl_api_unittest.cc",
] ]
} }
...@@ -613,6 +618,11 @@ test("gl_unittests") { ...@@ -613,6 +618,11 @@ test("gl_unittests") {
sources += [ "gl_context_glx_unittest.cc" ] sources += [ "gl_context_glx_unittest.cc" ]
deps += [ "//ui/gfx/x" ] deps += [ "//ui/gfx/x" ]
} }
if (is_win) {
deps += [ "//media/base/win:test_support" ]
libs = [ "dxguid.lib" ]
}
} }
# We can't run this test on real Chrome OS hardware for Ozone, so new target. # We can't run this test on real Chrome OS hardware for Ozone, so new target.
......
...@@ -27,4 +27,7 @@ specific_include_rules = { ...@@ -27,4 +27,7 @@ specific_include_rules = {
"gl_image_egl_pixmap.cc": [ "gl_image_egl_pixmap.cc": [
"+ui/base/ui_base_features.h", "+ui/base/ui_base_features.h",
], ],
"hdr_metadata_helper_win_unittest.cc": [
"+media/base/win/d3d11_mocks.h",
],
} }
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "media/base/hdr_metadata.h" #include "ui/gl/hdr_metadata.h"
namespace media { namespace gl {
MasteringMetadata::MasteringMetadata() = default; MasteringMetadata::MasteringMetadata() = default;
MasteringMetadata::MasteringMetadata(const MasteringMetadata& rhs) = default; MasteringMetadata::MasteringMetadata(const MasteringMetadata& rhs) = default;
...@@ -12,4 +12,4 @@ MasteringMetadata::MasteringMetadata(const MasteringMetadata& rhs) = default; ...@@ -12,4 +12,4 @@ MasteringMetadata::MasteringMetadata(const MasteringMetadata& rhs) = default;
HDRMetadata::HDRMetadata() = default; HDRMetadata::HDRMetadata() = default;
HDRMetadata::HDRMetadata(const HDRMetadata& rhs) = default; HDRMetadata::HDRMetadata(const HDRMetadata& rhs) = default;
} // namespace media } // namespace gl
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GL_HDR_METADATA_H_
#define UI_GL_HDR_METADATA_H_
#include "ui/gfx/geometry/point_f.h"
#include "ui/gl/gl_export.h"
namespace gl {
// SMPTE ST 2086 mastering metadata.
struct GL_EXPORT MasteringMetadata {
using Chromaticity = gfx::PointF;
Chromaticity primary_r;
Chromaticity primary_g;
Chromaticity primary_b;
Chromaticity white_point;
float luminance_max = 0;
float luminance_min = 0;
MasteringMetadata();
MasteringMetadata(const MasteringMetadata& rhs);
bool operator==(const MasteringMetadata& rhs) const {
return ((primary_r == rhs.primary_r) && (primary_g == rhs.primary_g) &&
(primary_b == rhs.primary_b) && (white_point == rhs.white_point) &&
(luminance_max == rhs.luminance_max) &&
(luminance_min == rhs.luminance_min));
}
};
// HDR metadata common for HDR10 and WebM/VP9-based HDR formats.
struct GL_EXPORT HDRMetadata {
MasteringMetadata mastering_metadata;
// Max content light level (CLL), i.e. maximum brightness level present in the
// stream), in nits.
unsigned max_content_light_level = 0;
// Max frame-average light level (FALL), i.e. maximum average brightness of
// the brightest frame in the stream), in nits.
unsigned max_frame_average_light_level = 0;
HDRMetadata();
HDRMetadata(const HDRMetadata& rhs);
bool operator==(const HDRMetadata& rhs) const {
return (
(max_content_light_level == rhs.max_content_light_level) &&
(max_frame_average_light_level == rhs.max_frame_average_light_level) &&
(mastering_metadata == rhs.mastering_metadata));
}
};
// HDR metadata types as described in
// https://w3c.github.io/media-capabilities/#enumdef-hdrmetadatatype
enum class HdrMetadataType {
kNone,
kSmpteSt2086,
kSmpteSt2094_10,
kSmpteSt2094_40,
};
} // namespace gl
#endif // UI_GL_HDR_METADATA_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "media/gpu/windows/display_helper.h" #include "ui/gl/hdr_metadata_helper_win.h"
namespace { namespace {
...@@ -13,33 +13,36 @@ static constexpr int kLuminanceFixedPoint = 10000; ...@@ -13,33 +13,36 @@ static constexpr int kLuminanceFixedPoint = 10000;
} // namespace } // namespace
namespace media { namespace gl {
DisplayHelper::DisplayHelper(const ComD3D11Device& d3d11_device) { HDRMetadataHelperWin::HDRMetadataHelperWin(
const Microsoft::WRL::ComPtr<ID3D11Device>& d3d11_device) {
CacheDisplayMetadata(d3d11_device); CacheDisplayMetadata(d3d11_device);
} }
DisplayHelper::~DisplayHelper() = default; HDRMetadataHelperWin::~HDRMetadataHelperWin() = default;
base::Optional<DXGI_HDR_METADATA_HDR10> DisplayHelper::GetDisplayMetadata() { base::Optional<DXGI_HDR_METADATA_HDR10>
HDRMetadataHelperWin::GetDisplayMetadata() {
return hdr_metadata_; return hdr_metadata_;
} }
void DisplayHelper::CacheDisplayMetadata(const ComD3D11Device& d3d11_device) { void HDRMetadataHelperWin::CacheDisplayMetadata(
const Microsoft::WRL::ComPtr<ID3D11Device>& d3d11_device) {
hdr_metadata_.reset(); hdr_metadata_.reset();
if (!d3d11_device) if (!d3d11_device)
return; return;
ComDXGIDevice dxgi_device; Microsoft::WRL::ComPtr<IDXGIDevice> dxgi_device;
if (FAILED(d3d11_device.As(&dxgi_device))) if (FAILED(d3d11_device.As(&dxgi_device)))
return; return;
ComDXGIAdapter dxgi_adapter; Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
if (FAILED(dxgi_device->GetAdapter(&dxgi_adapter))) if (FAILED(dxgi_device->GetAdapter(&dxgi_adapter)))
return; return;
ComDXGIFactory dxgi_factory; Microsoft::WRL::ComPtr<IDXGIFactory> dxgi_factory;
if (FAILED(dxgi_adapter->GetParent(__uuidof(IDXGIFactory), &dxgi_factory))) if (FAILED(dxgi_adapter->GetParent(__uuidof(IDXGIFactory), &dxgi_factory)))
return; return;
...@@ -50,13 +53,13 @@ void DisplayHelper::CacheDisplayMetadata(const ComD3D11Device& d3d11_device) { ...@@ -50,13 +53,13 @@ void DisplayHelper::CacheDisplayMetadata(const ComD3D11Device& d3d11_device) {
// brightest monitor as the one we want, which makes no sense really. // brightest monitor as the one we want, which makes no sense really.
// TODO(liberato): figure out what monitor we're actually using, or get that // TODO(liberato): figure out what monitor we're actually using, or get that
// from the renderer. // from the renderer.
ComDXGIAdapter adapter; Microsoft::WRL::ComPtr<IDXGIAdapter> adapter;
for (unsigned int i = 0; for (unsigned int i = 0;
dxgi_factory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++) { dxgi_factory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++) {
ComDXGIOutput output; Microsoft::WRL::ComPtr<IDXGIOutput> output;
for (unsigned int u = 0; for (unsigned int u = 0;
adapter->EnumOutputs(u, &output) != DXGI_ERROR_NOT_FOUND; u++) { adapter->EnumOutputs(u, &output) != DXGI_ERROR_NOT_FOUND; u++) {
ComDXGIOutput6 output6; Microsoft::WRL::ComPtr<IDXGIOutput6> output6;
if (FAILED(output.As(&output6))) if (FAILED(output.As(&output6)))
continue; continue;
...@@ -101,7 +104,7 @@ void DisplayHelper::CacheDisplayMetadata(const ComD3D11Device& d3d11_device) { ...@@ -101,7 +104,7 @@ void DisplayHelper::CacheDisplayMetadata(const ComD3D11Device& d3d11_device) {
} }
// static // static
DXGI_HDR_METADATA_HDR10 DisplayHelper::HdrMetadataToDXGI( DXGI_HDR_METADATA_HDR10 HDRMetadataHelperWin::HDRMetadataToDXGI(
const HDRMetadata& hdr_metadata) { const HDRMetadata& hdr_metadata) {
DXGI_HDR_METADATA_HDR10 metadata{}; DXGI_HDR_METADATA_HDR10 metadata{};
...@@ -128,4 +131,4 @@ DXGI_HDR_METADATA_HDR10 DisplayHelper::HdrMetadataToDXGI( ...@@ -128,4 +131,4 @@ DXGI_HDR_METADATA_HDR10 DisplayHelper::HdrMetadataToDXGI(
return metadata; return metadata;
} }
} // namespace media } // namespace gl
...@@ -2,41 +2,50 @@ ...@@ -2,41 +2,50 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef MEDIA_GPU_WINDOWS_DISPLAY_HELPER_H_ #ifndef UI_GL_HDR_METADATA_HELPER_WIN_H_
#define MEDIA_GPU_WINDOWS_DISPLAY_HELPER_H_ #define UI_GL_HDR_METADATA_HELPER_WIN_H_
#include <d3d11_1.h>
#include <dxgi1_6.h>
#include <wrl/client.h>
#include <memory>
#include <utility>
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "media/base/hdr_metadata.h" #include "ui/gl/gl_export.h"
#include "media/gpu/media_gpu_export.h" #include "ui/gl/hdr_metadata.h"
#include "media/gpu/windows/d3d11_com_defs.h"
namespace media { namespace gl {
// This is a very hacky way to get the display characteristics. // This is a very hacky way to get the display characteristics.
// It should be replaced by something that actually knows which // It should be replaced by something that actually knows which
// display is going to be used for, well, display. // display is going to be used for, well, display.
class MEDIA_GPU_EXPORT DisplayHelper { class GL_EXPORT HDRMetadataHelperWin {
public: public:
DisplayHelper(const ComD3D11Device& d3d11_device); explicit HDRMetadataHelperWin(
~DisplayHelper(); const Microsoft::WRL::ComPtr<ID3D11Device>& d3d11_device);
~HDRMetadataHelperWin();
// Return the metadata for the display, if available. Must call // Return the metadata for the display, if available. Must call
// CacheDisplayMetadata first. // CacheDisplayMetadata first.
base::Optional<DXGI_HDR_METADATA_HDR10> GetDisplayMetadata(); base::Optional<DXGI_HDR_METADATA_HDR10> GetDisplayMetadata();
// Convert |hdr_metadata| to DXGI's metadata format. // Convert |hdr_metadata| to DXGI's metadata format.
static DXGI_HDR_METADATA_HDR10 HdrMetadataToDXGI( static DXGI_HDR_METADATA_HDR10 HDRMetadataToDXGI(
const HDRMetadata& hdr_metadata); const HDRMetadata& hdr_metadata);
private: private:
void CacheDisplayMetadata(const ComD3D11Device& d3d11_device); void CacheDisplayMetadata(
const Microsoft::WRL::ComPtr<ID3D11Device>& d3d11_device);
base::Optional<DXGI_HDR_METADATA_HDR10> hdr_metadata_; base::Optional<DXGI_HDR_METADATA_HDR10> hdr_metadata_;
DISALLOW_COPY_AND_ASSIGN(DisplayHelper); DISALLOW_COPY_AND_ASSIGN(HDRMetadataHelperWin);
}; };
} // namespace media } // namespace gl
#endif // MEDIA_GPU_WINDOWS_DISPLAY_HELPER_H_ #endif // UI_GL_HDR_METADATA_HELPER_WIN_H_
\ No newline at end of file
// Copyright 2019 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "media/gpu/windows/display_helper.h" #include "ui/gl/hdr_metadata_helper_win.h"
#include "media/base/win/d3d11_mocks.h" #include "media/base/win/d3d11_mocks.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -15,37 +15,39 @@ using ::testing::Return; ...@@ -15,37 +15,39 @@ using ::testing::Return;
// using ::testing::SaveArg; // using ::testing::SaveArg;
using ::testing::SetArgPointee; using ::testing::SetArgPointee;
namespace media { namespace gl {
class DisplayHelperTest : public ::testing::Test { class HDRMetadataHelperWinTest : public ::testing::Test {
public: public:
void SetUp() override { void SetUp() override {
mock_dxgi_factory_ = MakeComPtr<NiceMock<DXGIFactoryMock>>(); mock_dxgi_factory_ = media::MakeComPtr<NiceMock<media::DXGIFactoryMock>>();
ON_CALL(*mock_dxgi_factory_.Get(), EnumAdapters(_, _)) ON_CALL(*mock_dxgi_factory_.Get(), EnumAdapters(_, _))
.WillByDefault(Return(DXGI_ERROR_NOT_FOUND)); .WillByDefault(Return(DXGI_ERROR_NOT_FOUND));
mock_dxgi_device_ = MakeComPtr<NiceMock<DXGIDeviceMock>>(); mock_dxgi_device_ = media::MakeComPtr<NiceMock<media::DXGIDeviceMock>>();
mock_d3d11_device_ = MakeComPtr<NiceMock<D3D11DeviceMock>>(); mock_d3d11_device_ = media::MakeComPtr<NiceMock<media::D3D11DeviceMock>>();
ON_CALL(*mock_d3d11_device_.Get(), QueryInterface(IID_IDXGIDevice, _)) ON_CALL(*mock_d3d11_device_.Get(), QueryInterface(IID_IDXGIDevice, _))
.WillByDefault(SetComPointeeAndReturnOk<1>(mock_dxgi_device_.Get())); .WillByDefault(
media::SetComPointeeAndReturnOk<1>(mock_dxgi_device_.Get()));
} }
std::unique_ptr<DisplayHelper> CreateHelper() { std::unique_ptr<HDRMetadataHelperWin> CreateHelper() {
// Set the D3D11 device's adapter to the first one, somewhat arbitrarily. // Set the D3D11 device's adapter to the first one, somewhat arbitrarily.
ON_CALL(*mock_dxgi_device_.Get(), GetAdapter(_)) ON_CALL(*mock_dxgi_device_.Get(), GetAdapter(_))
.WillByDefault( .WillByDefault(
SetComPointeeAndReturnOk<0>(mock_dxgi_adapters_[0].Get())); media::SetComPointeeAndReturnOk<0>(mock_dxgi_adapters_[0].Get()));
return std::make_unique<DisplayHelper>(mock_d3d11_device_); return std::make_unique<HDRMetadataHelperWin>(mock_d3d11_device_);
} }
// Adds an adapter that |mock_dxgi_factory_| will enumerate. // Adds an adapter that |mock_dxgi_factory_| will enumerate.
void AddAdapter() { void AddAdapter() {
Microsoft::WRL::ComPtr<DXGIAdapterMock> dxgi_adapter = Microsoft::WRL::ComPtr<media::DXGIAdapterMock> dxgi_adapter =
MakeComPtr<NiceMock<DXGIAdapterMock>>(); media::MakeComPtr<NiceMock<media::DXGIAdapterMock>>();
ON_CALL(*dxgi_adapter.Get(), GetParent(_, _)) ON_CALL(*dxgi_adapter.Get(), GetParent(_, _))
.WillByDefault(SetComPointeeAndReturnOk<1>(mock_dxgi_factory_.Get())); .WillByDefault(
media::SetComPointeeAndReturnOk<1>(mock_dxgi_factory_.Get()));
// By default, the adapter has no outputs. // By default, the adapter has no outputs.
ON_CALL(*dxgi_adapter.Get(), EnumOutputs(_, _)) ON_CALL(*dxgi_adapter.Get(), EnumOutputs(_, _))
...@@ -54,7 +56,7 @@ class DisplayHelperTest : public ::testing::Test { ...@@ -54,7 +56,7 @@ class DisplayHelperTest : public ::testing::Test {
// Make the factory enumerate this adapter. // Make the factory enumerate this adapter.
ON_CALL(*mock_dxgi_factory_.Get(), ON_CALL(*mock_dxgi_factory_.Get(),
EnumAdapters(mock_dxgi_adapters_.size(), _)) EnumAdapters(mock_dxgi_adapters_.size(), _))
.WillByDefault(SetComPointeeAndReturnOk<1>(dxgi_adapter.Get())); .WillByDefault(media::SetComPointeeAndReturnOk<1>(dxgi_adapter.Get()));
mock_dxgi_adapters_.push_back(std::move(dxgi_adapter)); mock_dxgi_adapters_.push_back(std::move(dxgi_adapter));
} }
...@@ -64,8 +66,8 @@ class DisplayHelperTest : public ::testing::Test { ...@@ -64,8 +66,8 @@ class DisplayHelperTest : public ::testing::Test {
// an expectation for output 0. // an expectation for output 0.
void AddOutput(const DXGI_OUTPUT_DESC1& desc1) { void AddOutput(const DXGI_OUTPUT_DESC1& desc1) {
// Create a DXGIOutput6 that can return |desc1|. // Create a DXGIOutput6 that can return |desc1|.
Microsoft::WRL::ComPtr<DXGIOutput6Mock> output6 = Microsoft::WRL::ComPtr<media::DXGIOutput6Mock> output6 =
MakeComPtr<DXGIOutput6Mock>(); media::MakeComPtr<media::DXGIOutput6Mock>();
mock_dxgi_output6s_.push_back(output6); mock_dxgi_output6s_.push_back(output6);
ON_CALL(*output6.Get(), GetDesc1(_)) ON_CALL(*output6.Get(), GetDesc1(_))
.WillByDefault(DoAll(SetArgPointee<0>(desc1), Return(S_OK))); .WillByDefault(DoAll(SetArgPointee<0>(desc1), Return(S_OK)));
...@@ -73,18 +75,20 @@ class DisplayHelperTest : public ::testing::Test { ...@@ -73,18 +75,20 @@ class DisplayHelperTest : public ::testing::Test {
// Tell the current adapter to return |output6| as its 0-th output. // Tell the current adapter to return |output6| as its 0-th output.
auto& dxgi_adapter = mock_dxgi_adapters_[mock_dxgi_adapters_.size() - 1]; auto& dxgi_adapter = mock_dxgi_adapters_[mock_dxgi_adapters_.size() - 1];
ON_CALL(*dxgi_adapter.Get(), EnumOutputs(0, _)) ON_CALL(*dxgi_adapter.Get(), EnumOutputs(0, _))
.WillByDefault(SetComPointeeAndReturnOk<1>(output6.Get())); .WillByDefault(media::SetComPointeeAndReturnOk<1>(output6.Get()));
} }
Microsoft::WRL::ComPtr<D3D11DeviceMock> mock_d3d11_device_; Microsoft::WRL::ComPtr<media::D3D11DeviceMock> mock_d3d11_device_;
Microsoft::WRL::ComPtr<DXGIDeviceMock> mock_dxgi_device_; Microsoft::WRL::ComPtr<media::DXGIDeviceMock> mock_dxgi_device_;
Microsoft::WRL::ComPtr<DXGIFactoryMock> mock_dxgi_factory_; Microsoft::WRL::ComPtr<media::DXGIFactoryMock> mock_dxgi_factory_;
std::vector<Microsoft::WRL::ComPtr<DXGIAdapterMock>> mock_dxgi_adapters_; std::vector<Microsoft::WRL::ComPtr<media::DXGIAdapterMock>>
std::vector<Microsoft::WRL::ComPtr<DXGIOutput6Mock>> mock_dxgi_output6s_; mock_dxgi_adapters_;
std::vector<Microsoft::WRL::ComPtr<DXGIOutputMock>> mock_dxgi_outputs_; std::vector<Microsoft::WRL::ComPtr<media::DXGIOutput6Mock>>
mock_dxgi_output6s_;
std::vector<Microsoft::WRL::ComPtr<media::DXGIOutputMock>> mock_dxgi_outputs_;
}; };
TEST_F(DisplayHelperTest, CachesMetadataIfAvailable) { TEST_F(HDRMetadataHelperWinTest, CachesMetadataIfAvailable) {
// Set up two adapters with one monitor each. // Set up two adapters with one monitor each.
AddAdapter(); AddAdapter();
DXGI_OUTPUT_DESC1 desc{}; DXGI_OUTPUT_DESC1 desc{};
...@@ -136,11 +140,11 @@ TEST_F(DisplayHelperTest, CachesMetadataIfAvailable) { ...@@ -136,11 +140,11 @@ TEST_F(DisplayHelperTest, CachesMetadataIfAvailable) {
EXPECT_EQ(result->MaxFrameAverageLightLevel, desc.MaxFullFrameLuminance); EXPECT_EQ(result->MaxFrameAverageLightLevel, desc.MaxFullFrameLuminance);
} }
TEST_F(DisplayHelperTest, DoesntCacheMetadataIfNotAvailble) { TEST_F(HDRMetadataHelperWinTest, DoesntCacheMetadataIfNotAvailble) {
// Add an empty adapter. // Add an empty adapter.
AddAdapter(); AddAdapter();
auto helper = CreateHelper(); auto helper = CreateHelper();
EXPECT_FALSE(helper->GetDisplayMetadata()); EXPECT_FALSE(helper->GetDisplayMetadata());
} }
} // namespace media } // namespace gl
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