Skip to content

Commit

Permalink
hdr: Add auto-detection of HDR setting
Browse files Browse the repository at this point in the history
Add an IPC function to be called whenever the display settings
are changed, to check if HDR settings have changed.

Remove hdr from GPUInfo.

Bug: 682416
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ib63a37cdad44fb0f5cae6e31948e9322f7298802
Reviewed-on: https://chromium-review.googlesource.com/708136
Commit-Queue: ccameron chromium <ccameron@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Fredrik Hubinette <hubbe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#508882}
  • Loading branch information
ccameron-chromium authored and Commit Bot committed Oct 14, 2017
1 parent f4db11e commit 51e1d9e
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class TestGpuService : public mojom::GpuService {
void RequestCompleteGpuInfo(
RequestCompleteGpuInfoCallback callback) override {}

void RequestHDRStatus(RequestHDRStatusCallback callback) override {}

void LoadedShader(const std::string& key, const std::string& data) override {}

void DestroyingVideoSurface(
Expand Down
22 changes: 22 additions & 0 deletions components/viz/service/gl/gpu_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#include "media/gpu/android/content_video_view_overlay_allocator.h"
#endif

#if defined(OS_WIN)
#include "gpu/ipc/service/direct_composition_surface_win.h"
#endif

namespace viz {

namespace {
Expand Down Expand Up @@ -314,6 +318,24 @@ void GpuServiceImpl::RequestCompleteGpuInfo(
this, std::move(callback))));
}

void GpuServiceImpl::RequestHDRStatus(RequestHDRStatusCallback callback) {
DCHECK(io_runner_->BelongsToCurrentThread());
main_runner_->PostTask(
FROM_HERE, base::BindOnce(&GpuServiceImpl::RequestHDRStatusOnMainThread,
weak_ptr_, std::move(callback)));
}

void GpuServiceImpl::RequestHDRStatusOnMainThread(
RequestHDRStatusCallback callback) {
DCHECK(main_runner_->BelongsToCurrentThread());
bool hdr_enabled = false;
#if defined(OS_WIN)
hdr_enabled = gpu::DirectCompositionSurfaceWin::IsHDRSupported();
#endif
io_runner_->PostTask(FROM_HERE,
base::BindOnce(std::move(callback), hdr_enabled));
}

#if defined(OS_MACOSX)
void GpuServiceImpl::UpdateGpuInfoPlatform(
base::OnceClosure on_gpu_info_updated) {
Expand Down
3 changes: 3 additions & 0 deletions components/viz/service/gl/gpu_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
void GetVideoMemoryUsageStats(
GetVideoMemoryUsageStatsCallback callback) override;
void RequestCompleteGpuInfo(RequestCompleteGpuInfoCallback callback) override;
void RequestHDRStatus(RequestHDRStatusCallback callback) override;
void LoadedShader(const std::string& key, const std::string& data) override;
void DestroyingVideoSurface(int32_t surface_id,
DestroyingVideoSurfaceCallback callback) override;
Expand All @@ -161,6 +162,8 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
void ThrowJavaException() override;
void Stop(StopCallback callback) override;

void RequestHDRStatusOnMainThread(RequestHDRStatusCallback callback);

scoped_refptr<base::SingleThreadTaskRunner> main_runner_;
scoped_refptr<base::SingleThreadTaskRunner> io_runner_;

Expand Down
46 changes: 46 additions & 0 deletions content/browser/browser_main_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
#include "sql/sql_memory_dump_provider.h"
#include "third_party/boringssl/src/include/openssl/evp.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/display/display_switches.h"
#include "ui/gfx/switches.h"

#if defined(USE_AURA) || defined(OS_MACOSX)
Expand Down Expand Up @@ -171,6 +172,7 @@
#include "content/common/sandbox_win.h"
#include "net/base/winsock_init.h"
#include "ui/base/l10n/l10n_util_win.h"
#include "ui/display/win/screen_win.h"
#endif

#if defined(OS_CHROMEOS)
Expand Down Expand Up @@ -521,6 +523,48 @@ class GpuDataManagerVisualProxy : public GpuDataManagerObserver {
} // namespace internal
#endif

#if defined(OS_WIN)
namespace {

// Provides a bridge whereby display::win::ScreenWin can ask the GPU process
// about the HDR status of the system.
class HDRProxy {
public:
static void Initialize() {
display::win::ScreenWin::SetRequestHDRStatusCallback(
base::Bind(&HDRProxy::RequestHDRStatus));
}

static void RequestHDRStatus() {
// The request must be sent to the GPU process from the IO thread.
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&HDRProxy::RequestOnIOThread));
}

private:
static void RequestOnIOThread() {
auto* gpu_process_host =
GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, false);
if (gpu_process_host) {
gpu_process_host->RequestHDRStatus(
base::Bind(&HDRProxy::GotResultOnIOThread));
} else {
bool hdr_enabled = false;
GotResultOnIOThread(hdr_enabled);
}
}
static void GotResultOnIOThread(bool hdr_enabled) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&HDRProxy::GotResult, hdr_enabled));
}
static void GotResult(bool hdr_enabled) {
display::win::ScreenWin::SetHDREnabled(hdr_enabled);
}
};

} // namespace
#endif

// The currently-running BrowserMainLoop. There can be one or zero.
BrowserMainLoop* g_current_browser_main_loop = NULL;

Expand Down Expand Up @@ -1485,6 +1529,8 @@ int BrowserMainLoop::BrowserThreadsStarted() {
}

#if defined(OS_WIN)
if (base::FeatureList::IsEnabled(features::kHighDynamicRange))
HDRProxy::Initialize();
system_message_window_.reset(new media::SystemMessageWindowWin);
#elif defined(OS_LINUX) && defined(USE_UDEV)
device_monitor_linux_.reset(
Expand Down
4 changes: 4 additions & 0 deletions content/browser/gpu/gpu_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ void GpuProcessHost::RequestGPUInfo(RequestGPUInfoCallback request_cb) {
request_gpu_info_callbacks_.push_back(std::move(request_cb));
}

void GpuProcessHost::RequestHDRStatus(RequestHDRStatusCallback request_cb) {
gpu_service_ptr_->RequestHDRStatus(std::move(request_cb));
}

#if defined(OS_ANDROID)
void GpuProcessHost::SendDestroyingVideoSurface(int surface_id,
const base::Closure& done_cb) {
Expand Down
2 changes: 2 additions & 0 deletions content/browser/gpu/gpu_process_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
BufferCreationStatus status)>;

using RequestGPUInfoCallback = base::Callback<void(const gpu::GPUInfo&)>;
using RequestHDRStatusCallback = base::Callback<void(bool)>;

static bool gpu_enabled() { return gpu_enabled_; }
static int gpu_crash_count() { return gpu_crash_count_; }
Expand Down Expand Up @@ -149,6 +150,7 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
const gpu::SyncToken& sync_token);

void RequestGPUInfo(RequestGPUInfoCallback request_cb);
void RequestHDRStatus(RequestHDRStatusCallback request_cb);

#if defined(OS_ANDROID)
// Tells the GPU process that the given surface is being destroyed so that it
Expand Down
2 changes: 0 additions & 2 deletions gpu/config/gpu_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ void GPUInfo::EnumerateFields(Enumerator* enumerator) const {
bool in_process_gpu;
bool passthrough_cmd_decoder;
bool supports_overlays;
bool hdr;
bool can_support_threaded_texture_mailbox;
CollectInfoResult basic_info_state;
CollectInfoResult context_info_state;
Expand Down Expand Up @@ -195,7 +194,6 @@ void GPUInfo::EnumerateFields(Enumerator* enumerator) const {
enumerator->AddBool("inProcessGpu", in_process_gpu);
enumerator->AddBool("passthroughCmdDecoder", passthrough_cmd_decoder);
enumerator->AddBool("supportsOverlays", supports_overlays);
enumerator->AddBool("hdr", hdr);
enumerator->AddBool("canSupportThreadedTextureMailbox",
can_support_threaded_texture_mailbox);
enumerator->AddInt("basicInfoState", basic_info_state);
Expand Down
3 changes: 0 additions & 3 deletions gpu/config/gpu_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ struct GPU_EXPORT GPUInfo {
// True if the current set of outputs supports overlays.
bool supports_overlays = false;

// True if the current set of outputs supports HDR.
bool hdr = false;

// True only on android when extensions for threaded mailbox sharing are
// present. Threaded mailbox sharing is used on Android only, so this check
// is only implemented on Android.
Expand Down
1 change: 0 additions & 1 deletion gpu/config/gpu_info_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ void MergeGPUInfoGL(GPUInfo* basic_gpu_info,
basic_gpu_info->passthrough_cmd_decoder =
context_gpu_info.passthrough_cmd_decoder;
basic_gpu_info->supports_overlays = context_gpu_info.supports_overlays;
basic_gpu_info->hdr = context_gpu_info.hdr;
basic_gpu_info->context_info_state = context_gpu_info.context_info_state;
basic_gpu_info->initialization_time = context_gpu_info.initialization_time;
basic_gpu_info->video_decode_accelerator_capabilities =
Expand Down
1 change: 0 additions & 1 deletion gpu/ipc/common/gpu_info.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ struct GpuInfo {
bool in_process_gpu;
bool passthrough_cmd_decoder;
bool supports_overlays;
bool hdr;
bool can_support_threaded_texture_mailbox;
CollectInfoResult basic_info_state;
CollectInfoResult context_info_state;
Expand Down
1 change: 0 additions & 1 deletion gpu/ipc/common/gpu_info_struct_traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ bool StructTraits<gpu::mojom::GpuInfoDataView, gpu::GPUInfo>::Read(
out->in_process_gpu = data.in_process_gpu();
out->passthrough_cmd_decoder = data.passthrough_cmd_decoder();
out->supports_overlays = data.supports_overlays();
out->hdr = data.hdr();
out->can_support_threaded_texture_mailbox =
data.can_support_threaded_texture_mailbox();
out->process_crash_count = data.process_crash_count();
Expand Down
2 changes: 0 additions & 2 deletions gpu/ipc/common/gpu_info_struct_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ struct StructTraits<gpu::mojom::GpuInfoDataView, gpu::GPUInfo> {
return input.supports_overlays;
}

static bool hdr(const gpu::GPUInfo& input) { return input.hdr; }

static bool can_support_threaded_texture_mailbox(const gpu::GPUInfo& input) {
return input.can_support_threaded_texture_mailbox;
}
Expand Down
3 changes: 0 additions & 3 deletions gpu/ipc/service/gpu_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ void CollectGraphicsInfo(GPUInfo* gpu_info) {
DirectCompositionSurfaceWin::AreOverlaysSupported()) {
gpu_info->supports_overlays = true;
}
if (DirectCompositionSurfaceWin::IsHDRSupported()) {
gpu_info->hdr = true;
}
#endif // defined(OS_WIN)

if (result != kCollectInfoFatalFailure) {
Expand Down
4 changes: 4 additions & 0 deletions services/viz/privileged/interfaces/gl/gpu_service.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ interface GpuService {

RequestCompleteGpuInfo() => (gpu.mojom.GpuInfo gpu_info);

// Requests that the GPU process query system availability of HDR output and
// return it.
RequestHDRStatus() => (bool hdr_enabled);

// Notify GPU that a shader program was loaded from disk. Key is an
// SHA-1 hash, and data a binary blob with serialized program info.
// Note that this method is used only from a trusted process.
Expand Down
35 changes: 29 additions & 6 deletions ui/display/win/screen_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "ui/display/display.h"
#include "ui/display/display_layout.h"
#include "ui/display/display_layout_builder.h"
#include "ui/display/display_switches.h"
#include "ui/display/win/display_info.h"
#include "ui/display/win/dpi.h"
#include "ui/display/win/scaling_util.h"
Expand Down Expand Up @@ -223,8 +222,7 @@ gfx::Point ScalePointRelative(const gfx::Point& from_origin,
ScreenWin::ScreenWin() : ScreenWin(true) {}

ScreenWin::ScreenWin(bool initialize)
: color_profile_reader_(new ColorProfileReader(this)),
hdr_enabled_(base::FeatureList::IsEnabled(features::kHighDynamicRange)) {
: color_profile_reader_(new ColorProfileReader(this)) {
DCHECK(!g_screen_win_instance);
g_screen_win_instance = this;
if (initialize)
Expand Down Expand Up @@ -377,6 +375,27 @@ float ScreenWin::GetSystemScaleFactor() {
return GetUnforcedDeviceScaleFactor();
}

// static
void ScreenWin::SetRequestHDRStatusCallback(
RequestHDRStatusCallback request_hdr_status_callback) {
if (!g_screen_win_instance)
return;
g_screen_win_instance->request_hdr_status_callback_ =
std::move(request_hdr_status_callback);
g_screen_win_instance->request_hdr_status_callback_.Run();
}

// static
void ScreenWin::SetHDREnabled(bool hdr_enabled) {
if (!g_screen_win_instance)
return;

if (g_screen_win_instance->hdr_enabled_ == hdr_enabled)
return;
g_screen_win_instance->hdr_enabled_ = hdr_enabled;
g_screen_win_instance->UpdateAllDisplaysAndNotify();
}

HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const {
NOTREACHED();
return nullptr;
Expand Down Expand Up @@ -518,9 +537,9 @@ void ScreenWin::OnWndProc(HWND hwnd,
return;

color_profile_reader_->UpdateIfNeeded();
std::vector<Display> old_displays = std::move(displays_);
UpdateFromDisplayInfos(GetDisplayInfosFromSystem());
change_notifier_.NotifyDisplaysChanged(old_displays, displays_);
if (request_hdr_status_callback_)
request_hdr_status_callback_.Run();
UpdateAllDisplaysAndNotify();
}

void ScreenWin::OnColorProfilesChanged() {
Expand All @@ -538,6 +557,10 @@ void ScreenWin::OnColorProfilesChanged() {
if (!changed)
return;

UpdateAllDisplaysAndNotify();
}

void ScreenWin::UpdateAllDisplaysAndNotify() {
std::vector<Display> old_displays = std::move(displays_);
UpdateFromDisplayInfos(GetDisplayInfosFromSystem());
change_notifier_.NotifyDisplaysChanged(old_displays, displays_);
Expand Down
23 changes: 20 additions & 3 deletions ui/display/win/screen_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ class DISPLAY_EXPORT ScreenWin : public Screen,
// you are targeting.
static float GetSystemScaleFactor();

// Set a callback to use to query the status of HDR. This callback will be
// called when the status of HDR may have changed.
using RequestHDRStatusCallback = base::Callback<void()>;
static void SetRequestHDRStatusCallback(
RequestHDRStatusCallback request_hdr_status_callback);

// Set whether or not to treat all displays as HDR capable. Note that
// more precise information about which displays are HDR capable is
// available. We make a conscious choice to force all displays to HDR mode if
// any display is in HDR mode, under the assumption that the user will be
// using the HDR display to view media, and thus will want all media queries
// to return that HDR is supported.
static void SetHDREnabled(bool hdr_enabled);

// Returns the HWND associated with the NativeView.
virtual HWND GetHWNDFromNativeView(gfx::NativeView view) const;

Expand Down Expand Up @@ -155,6 +169,7 @@ class DISPLAY_EXPORT ScreenWin : public Screen,
private:
void Initialize();
void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
void UpdateAllDisplaysAndNotify();

// Returns the ScreenWinDisplay closest to or enclosing |hwnd|.
ScreenWinDisplay GetScreenWinDisplayNearestHWND(HWND hwnd) const;
Expand Down Expand Up @@ -203,9 +218,11 @@ class DISPLAY_EXPORT ScreenWin : public Screen,
// A helper to read color profiles from the filesystem.
std::unique_ptr<ColorProfileReader> color_profile_reader_;

// Whether or not HDR mode is enabled.
// TODO(ccameron): Set this via the GPU process when the system "HDR and
// advanced color" setting is enabled.
// Callback to use to query when the HDR status may have changed.
RequestHDRStatusCallback request_hdr_status_callback_;

// Whether or not HDR mode is enabled for any monitor via the "HDR and
// advanced color" setting.
bool hdr_enabled_ = false;

DISALLOW_COPY_AND_ASSIGN(ScreenWin);
Expand Down

0 comments on commit 51e1d9e

Please sign in to comment.