summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authordnicoara <dnicoara@chromium.org>2015-05-07 12:29:23 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-07 19:29:55 +0000
commitb29d05101c3f628039146b13a8e3bb361531c7be (patch)
tree901a9ec3d4ca293e86fdc18be20ef9fee111aa26 /ui
parent743ec3bdabdd1b0dd0813d42aea00020a2e25b3b (diff)
downloadchromium_src-b29d05101c3f628039146b13a8e3bb361531c7be.zip
chromium_src-b29d05101c3f628039146b13a8e3bb361531c7be.tar.gz
chromium_src-b29d05101c3f628039146b13a8e3bb361531c7be.tar.bz2
[Ozone-Drm] Move ownership of display configuration objects into platform
All the display state will be owned by the platform. This fixes issues with tests (such as video decode) that will have 1 platform instance but re-create NativeDisplayDelegate for each test. BUG=483319 TBR=jam@chromium.org Review URL: https://codereview.chromium.org/1123053002 Cr-Commit-Position: refs/heads/master@{#328817}
Diffstat (limited to 'ui')
-rw-r--r--ui/ozone/platform/drm/BUILD.gn4
-rw-r--r--ui/ozone/platform/drm/drm.gypi4
-rw-r--r--ui/ozone/platform/drm/host/display_manager.cc42
-rw-r--r--ui/ozone/platform/drm/host/display_manager.h40
-rw-r--r--ui/ozone/platform/drm/host/drm_display_host_manager.cc410
-rw-r--r--ui/ozone/platform/drm/host/drm_display_host_manager.h146
-rw-r--r--ui/ozone/platform/drm/host/drm_native_display_delegate.cc398
-rw-r--r--ui/ozone/platform/drm/host/drm_native_display_delegate.h135
-rw-r--r--ui/ozone/platform/drm/host/drm_window_host.cc4
-rw-r--r--ui/ozone/platform/drm/host/drm_window_host.h16
-rw-r--r--ui/ozone/platform/drm/ozone_platform_drm.cc13
-rw-r--r--ui/ozone/platform/drm/ozone_platform_gbm.cc13
12 files changed, 634 insertions, 591 deletions
diff --git a/ui/ozone/platform/drm/BUILD.gn b/ui/ozone/platform/drm/BUILD.gn
index 91b3e5a..7ad72fa 100644
--- a/ui/ozone/platform/drm/BUILD.gn
+++ b/ui/ozone/platform/drm/BUILD.gn
@@ -67,12 +67,12 @@ source_set("drm_common") {
"gpu/screen_manager.cc",
"gpu/screen_manager.h",
"host/channel_observer.h",
- "host/display_manager.cc",
- "host/display_manager.h",
"host/drm_cursor.cc",
"host/drm_cursor.h",
"host/drm_device_handle.cc",
"host/drm_device_handle.h",
+ "host/drm_display_host_manager.cc",
+ "host/drm_display_host_manager.h",
"host/drm_gpu_platform_support_host.cc",
"host/drm_gpu_platform_support_host.h",
"host/drm_native_display_delegate.cc",
diff --git a/ui/ozone/platform/drm/drm.gypi b/ui/ozone/platform/drm/drm.gypi
index 9946c8b..634b74e 100644
--- a/ui/ozone/platform/drm/drm.gypi
+++ b/ui/ozone/platform/drm/drm.gypi
@@ -88,12 +88,12 @@
'gpu/screen_manager.cc',
'gpu/screen_manager.h',
'host/channel_observer.h',
- 'host/display_manager.cc',
- 'host/display_manager.h',
'host/drm_cursor.cc',
'host/drm_cursor.h',
'host/drm_device_handle.cc',
'host/drm_device_handle.h',
+ 'host/drm_display_host_manager.cc',
+ 'host/drm_display_host_manager.h',
'host/drm_gpu_platform_support_host.cc',
'host/drm_gpu_platform_support_host.h',
'host/drm_native_display_delegate.cc',
diff --git a/ui/ozone/platform/drm/host/display_manager.cc b/ui/ozone/platform/drm/host/display_manager.cc
deleted file mode 100644
index ddf8163..0000000
--- a/ui/ozone/platform/drm/host/display_manager.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2014 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.
-
-#include "ui/ozone/platform/drm/host/display_manager.h"
-
-#include "base/logging.h"
-#include "ui/display/types/display_snapshot.h"
-
-namespace ui {
-
-DisplayManager::DisplayManager() {
-}
-
-DisplayManager::~DisplayManager() {
-}
-
-void DisplayManager::RegisterDisplay(DisplaySnapshot* display) {
- std::pair<DisplayMap::iterator, bool> result = display_map_.insert(
- std::pair<int64_t, DisplaySnapshot*>(display->display_id(), display));
- DCHECK(result.second) << "Display " << display->display_id()
- << " already added.";
-}
-
-void DisplayManager::UnregisterDisplay(DisplaySnapshot* display) {
- DisplayMap::iterator it = display_map_.find(display->display_id());
- if (it != display_map_.end())
- display_map_.erase(it);
- else
- NOTREACHED() << "Attempting to remove non-existing display "
- << display->display_id();
-}
-
-DisplaySnapshot* DisplayManager::GetDisplay(int64_t display) {
- DisplayMap::iterator it = display_map_.find(display);
- if (it == display_map_.end())
- return nullptr;
-
- return it->second;
-}
-
-} // namespace ui
diff --git a/ui/ozone/platform/drm/host/display_manager.h b/ui/ozone/platform/drm/host/display_manager.h
deleted file mode 100644
index 146a855..0000000
--- a/ui/ozone/platform/drm/host/display_manager.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2014 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_OZONE_PLATFORM_DRM_HOST_DISPLAY_MANAGER_H_
-#define UI_OZONE_PLATFORM_DRM_HOST_DISPLAY_MANAGER_H_
-
-#include <stdint.h>
-
-#include <map>
-
-#include "base/macros.h"
-
-namespace ui {
-
-class DisplaySnapshot;
-
-class DisplayManager {
- public:
- DisplayManager();
- ~DisplayManager();
-
- void RegisterDisplay(DisplaySnapshot* display);
- void UnregisterDisplay(DisplaySnapshot* display);
-
- // Returns the display state for |display| or NULL if not found.
- DisplaySnapshot* GetDisplay(int64_t display);
-
- private:
- typedef std::map<int64_t, DisplaySnapshot*> DisplayMap;
-
- // Keeps a mapping between the display ID and a pointer to the display state.
- DisplayMap display_map_;
-
- DISALLOW_COPY_AND_ASSIGN(DisplayManager);
-};
-
-} // namespace ui
-
-#endif // UI_OZONE_PLATFORM_DRM_HOST_DISPLAY_MANAGER_H_
diff --git a/ui/ozone/platform/drm/host/drm_display_host_manager.cc b/ui/ozone/platform/drm/host/drm_display_host_manager.cc
new file mode 100644
index 0000000..192ce96
--- /dev/null
+++ b/ui/ozone/platform/drm/host/drm_display_host_manager.cc
@@ -0,0 +1,410 @@
+// Copyright 2014 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.
+
+#include "ui/ozone/platform/drm/host/drm_display_host_manager.h"
+
+#include <stdio.h>
+
+#include "base/logging.h"
+#include "base/thread_task_runner_handle.h"
+#include "base/threading/thread_restrictions.h"
+#include "base/threading/worker_pool.h"
+#include "ui/display/types/display_snapshot.h"
+#include "ui/events/ozone/device/device_event.h"
+#include "ui/events/ozone/device/device_manager.h"
+#include "ui/ozone/common/display_snapshot_proxy.h"
+#include "ui/ozone/common/display_util.h"
+#include "ui/ozone/common/gpu/ozone_gpu_messages.h"
+#include "ui/ozone/platform/drm/host/drm_device_handle.h"
+#include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
+#include "ui/ozone/platform/drm/host/drm_native_display_delegate.h"
+
+namespace ui {
+
+namespace {
+
+typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)>
+ OnOpenDeviceReplyCallback;
+
+const char* kDisplayActionString[] = {
+ "ADD",
+ "REMOVE",
+ "CHANGE",
+};
+
+void OpenDeviceOnWorkerThread(
+ const base::FilePath& path,
+ const scoped_refptr<base::TaskRunner>& reply_runner,
+ const OnOpenDeviceReplyCallback& callback) {
+ scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle());
+ handle->Initialize(path);
+ reply_runner->PostTask(
+ FROM_HERE, base::Bind(callback, path, base::Passed(handle.Pass())));
+}
+
+void CloseDeviceOnWorkerThread(
+ scoped_ptr<DrmDeviceHandle> handle,
+ const scoped_refptr<base::TaskRunner>& reply_runner,
+ const base::Closure& callback) {
+ handle.reset();
+ reply_runner->PostTask(FROM_HERE, callback);
+}
+
+class FindDisplaySnapshotById {
+ public:
+ FindDisplaySnapshotById(int64_t display_id) : display_id_(display_id) {}
+
+ bool operator()(const DisplaySnapshot* display) {
+ return display->display_id() == display_id_;
+ }
+
+ private:
+ int64_t display_id_;
+};
+
+} // namespace
+
+DrmDisplayHostManager::DrmDisplayHostManager(
+ DrmGpuPlatformSupportHost* proxy,
+ DeviceManager* device_manager,
+ const base::FilePath& primary_graphics_card_path)
+ : proxy_(proxy),
+ device_manager_(device_manager),
+ delegate_(nullptr),
+ primary_graphics_card_path_(primary_graphics_card_path),
+ has_dummy_display_(false),
+ task_pending_(false),
+ weak_ptr_factory_(this) {
+ {
+ // First device needs to be treated specially. We need to open this
+ // synchronously since the GPU process will need it to initialize the
+ // graphics state.
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle());
+ if (!handle->Initialize(primary_graphics_card_path_)) {
+ LOG(FATAL) << "Failed to open primary graphics card";
+ return;
+ }
+ drm_devices_.add(primary_graphics_card_path_, handle.Pass());
+ }
+
+ device_manager_->AddObserver(this);
+ proxy_->RegisterHandler(this);
+
+ DisplaySnapshot_Params params;
+ bool success = false;
+ {
+ // The file generated by frecon that contains EDID for the 1st display.
+ const base::FilePath kEDIDFile("/tmp/display_info.bin");
+
+ // Just read it on current thread as this is necessary information
+ // to start. This access only tmpfs, which is fast.
+ // TODO(dnicoara|oshima): crbug.com/450886.
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ success = CreateSnapshotFromEDIDFile(kEDIDFile, &params);
+ }
+
+ // Fallback to command line if the file doesn't exit or failed to read.
+ if (success || CreateSnapshotFromCommandLine(&params)) {
+ LOG_IF(ERROR, !success) << "Failed to read display_info.bin.";
+ DCHECK_NE(DISPLAY_CONNECTION_TYPE_NONE, params.type);
+ displays_.push_back(new DisplaySnapshotProxy(params));
+ has_dummy_display_ = true;
+ } else {
+ LOG(ERROR) << "Failed to obtain initial display info";
+ }
+}
+
+DrmDisplayHostManager::~DrmDisplayHostManager() {
+ device_manager_->RemoveObserver(this);
+ proxy_->UnregisterHandler(this);
+
+ for (auto it = drm_devices_.begin(); it != drm_devices_.end(); ++it) {
+ base::WorkerPool::PostTask(FROM_HERE,
+ base::Bind(&CloseDeviceOnWorkerThread,
+ base::Passed(drm_devices_.take(it)),
+ base::ThreadTaskRunnerHandle::Get(),
+ base::Bind(&base::DoNothing)),
+ false /* task_is_slow */);
+ }
+}
+
+DisplaySnapshot* DrmDisplayHostManager::GetDisplay(int64_t display_id) {
+ auto it = std::find_if(displays_.begin(), displays_.end(),
+ FindDisplaySnapshotById(display_id));
+ if (it == displays_.end())
+ return nullptr;
+
+ return *it;
+}
+
+void DrmDisplayHostManager::AddDelegate(DrmNativeDisplayDelegate* delegate) {
+ DCHECK(!delegate_);
+ delegate_ = delegate;
+}
+
+void DrmDisplayHostManager::RemoveDelegate(DrmNativeDisplayDelegate* delegate) {
+ DCHECK_EQ(delegate_, delegate);
+ delegate_ = nullptr;
+}
+
+bool DrmDisplayHostManager::TakeDisplayControl() {
+ proxy_->Send(new OzoneGpuMsg_TakeDisplayControl());
+ return true;
+}
+
+bool DrmDisplayHostManager::RelinquishDisplayControl() {
+ proxy_->Send(new OzoneGpuMsg_RelinquishDisplayControl());
+ return true;
+}
+
+void DrmDisplayHostManager::UpdateDisplays(
+ const GetDisplaysCallback& callback) {
+ get_displays_callback_ = callback;
+ if (!proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays())) {
+ get_displays_callback_.Reset();
+ callback.Run(displays_.get());
+ }
+}
+
+void DrmDisplayHostManager::Configure(int64_t display_id,
+ const DisplayMode* mode,
+ const gfx::Point& origin,
+ const ConfigureCallback& callback) {
+ // The dummy display is used on the first run only. Note: cannot post a task
+ // here since there is no task runner.
+ if (has_dummy_display_) {
+ callback.Run(true);
+ return;
+ }
+
+ configure_callback_map_[display_id] = callback;
+
+ bool status = false;
+ if (mode) {
+ status = proxy_->Send(new OzoneGpuMsg_ConfigureNativeDisplay(
+ display_id, GetDisplayModeParams(*mode), origin));
+ } else {
+ status = proxy_->Send(new OzoneGpuMsg_DisableNativeDisplay(display_id));
+ }
+
+ if (!status)
+ OnDisplayConfigured(display_id, false);
+}
+
+void DrmDisplayHostManager::GetHDCPState(int64_t display_id,
+ const GetHDCPStateCallback& callback) {
+ get_hdcp_state_callback_map_[display_id] = callback;
+ if (!proxy_->Send(new OzoneGpuMsg_GetHDCPState(display_id)))
+ OnHDCPStateReceived(display_id, false, HDCP_STATE_UNDESIRED);
+}
+
+void DrmDisplayHostManager::SetHDCPState(int64_t display_id,
+ HDCPState state,
+ const SetHDCPStateCallback& callback) {
+ set_hdcp_state_callback_map_[display_id] = callback;
+ if (!proxy_->Send(new OzoneGpuMsg_SetHDCPState(display_id, state)))
+ OnHDCPStateUpdated(display_id, false);
+}
+
+bool DrmDisplayHostManager::SetGammaRamp(
+ int64_t display_id,
+ const std::vector<GammaRampRGBEntry>& lut) {
+ proxy_->Send(new OzoneGpuMsg_SetGammaRamp(display_id, lut));
+ return true;
+}
+
+void DrmDisplayHostManager::OnDeviceEvent(const DeviceEvent& event) {
+ if (event.device_type() != DeviceEvent::DISPLAY)
+ return;
+
+ event_queue_.push(DisplayEvent(event.action_type(), event.path()));
+ ProcessEvent();
+}
+
+void DrmDisplayHostManager::ProcessEvent() {
+ while (!event_queue_.empty() && !task_pending_) {
+ DisplayEvent event = event_queue_.front();
+ event_queue_.pop();
+ VLOG(1) << "Got display event " << kDisplayActionString[event.action_type]
+ << " for " << event.path.value();
+ switch (event.action_type) {
+ case DeviceEvent::ADD:
+ if (drm_devices_.find(event.path) == drm_devices_.end()) {
+ task_pending_ = base::WorkerPool::PostTask(
+ FROM_HERE,
+ base::Bind(&OpenDeviceOnWorkerThread, event.path,
+ base::ThreadTaskRunnerHandle::Get(),
+ base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice,
+ weak_ptr_factory_.GetWeakPtr())),
+ false /* task_is_slow */);
+ }
+ break;
+ case DeviceEvent::CHANGE:
+ task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice,
+ weak_ptr_factory_.GetWeakPtr()));
+ break;
+ case DeviceEvent::REMOVE:
+ DCHECK(event.path != primary_graphics_card_path_)
+ << "Removing primary graphics card";
+ auto it = drm_devices_.find(event.path);
+ if (it != drm_devices_.end()) {
+ task_pending_ = base::WorkerPool::PostTask(
+ FROM_HERE,
+ base::Bind(
+ &CloseDeviceOnWorkerThread,
+ base::Passed(drm_devices_.take_and_erase(it)),
+ base::ThreadTaskRunnerHandle::Get(),
+ base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice,
+ weak_ptr_factory_.GetWeakPtr(), event.path)),
+ false /* task_is_slow */);
+ return;
+ }
+ break;
+ }
+ }
+}
+
+void DrmDisplayHostManager::OnAddGraphicsDevice(
+ const base::FilePath& path,
+ scoped_ptr<DrmDeviceHandle> handle) {
+ if (handle->IsValid()) {
+ base::ScopedFD file = handle->Duplicate();
+ drm_devices_.add(path, handle.Pass());
+ proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(
+ path, base::FileDescriptor(file.Pass())));
+ NotifyDisplayDelegate();
+ }
+
+ task_pending_ = false;
+ ProcessEvent();
+}
+
+void DrmDisplayHostManager::OnUpdateGraphicsDevice() {
+ NotifyDisplayDelegate();
+ task_pending_ = false;
+ ProcessEvent();
+}
+
+void DrmDisplayHostManager::OnRemoveGraphicsDevice(const base::FilePath& path) {
+ proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(path));
+ NotifyDisplayDelegate();
+ task_pending_ = false;
+ ProcessEvent();
+}
+
+void DrmDisplayHostManager::OnChannelEstablished(
+ int host_id,
+ scoped_refptr<base::SingleThreadTaskRunner> send_runner,
+ const base::Callback<void(IPC::Message*)>& send_callback) {
+ auto it = drm_devices_.find(primary_graphics_card_path_);
+ DCHECK(it != drm_devices_.end());
+ // Send the primary device first since this is used to initialize graphics
+ // state.
+ proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(
+ it->first, base::FileDescriptor(it->second->Duplicate())));
+
+ for (auto pair : drm_devices_) {
+ if (pair.second->IsValid() && pair.first != primary_graphics_card_path_) {
+ proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(
+ pair.first, base::FileDescriptor(pair.second->Duplicate())));
+ }
+ }
+
+ device_manager_->ScanDevices(this);
+ NotifyDisplayDelegate();
+}
+
+void DrmDisplayHostManager::OnChannelDestroyed(int host_id) {
+ // If the channel got destroyed in the middle of a configuration then just
+ // respond with failure.
+ if (!get_displays_callback_.is_null()) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&DrmDisplayHostManager::RunUpdateDisplaysCallback,
+ weak_ptr_factory_.GetWeakPtr(), get_displays_callback_));
+ get_displays_callback_.Reset();
+ }
+
+ for (const auto& pair : configure_callback_map_) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(pair.second, false));
+ }
+ configure_callback_map_.clear();
+}
+
+bool DrmDisplayHostManager::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+
+ IPC_BEGIN_MESSAGE_MAP(DrmDisplayHostManager, message)
+ IPC_MESSAGE_HANDLER(OzoneHostMsg_UpdateNativeDisplays, OnUpdateNativeDisplays)
+ IPC_MESSAGE_HANDLER(OzoneHostMsg_DisplayConfigured, OnDisplayConfigured)
+ IPC_MESSAGE_HANDLER(OzoneHostMsg_HDCPStateReceived, OnHDCPStateReceived)
+ IPC_MESSAGE_HANDLER(OzoneHostMsg_HDCPStateUpdated, OnHDCPStateUpdated)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+}
+
+void DrmDisplayHostManager::OnUpdateNativeDisplays(
+ const std::vector<DisplaySnapshot_Params>& displays) {
+ has_dummy_display_ = false;
+ displays_.clear();
+ for (size_t i = 0; i < displays.size(); ++i)
+ displays_.push_back(new DisplaySnapshotProxy(displays[i]));
+
+ if (!get_displays_callback_.is_null()) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&DrmDisplayHostManager::RunUpdateDisplaysCallback,
+ weak_ptr_factory_.GetWeakPtr(), get_displays_callback_));
+ get_displays_callback_.Reset();
+ }
+}
+
+void DrmDisplayHostManager::OnDisplayConfigured(int64_t display_id,
+ bool status) {
+ auto it = configure_callback_map_.find(display_id);
+ if (it != configure_callback_map_.end()) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(it->second, status));
+ configure_callback_map_.erase(it);
+ }
+}
+
+void DrmDisplayHostManager::OnHDCPStateReceived(int64_t display_id,
+ bool status,
+ HDCPState state) {
+ auto it = get_hdcp_state_callback_map_.find(display_id);
+ if (it != get_hdcp_state_callback_map_.end()) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(it->second, status, state));
+ get_hdcp_state_callback_map_.erase(it);
+ }
+}
+
+void DrmDisplayHostManager::OnHDCPStateUpdated(int64_t display_id,
+ bool status) {
+ auto it = set_hdcp_state_callback_map_.find(display_id);
+ if (it != set_hdcp_state_callback_map_.end()) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(it->second, status));
+ set_hdcp_state_callback_map_.erase(it);
+ }
+}
+
+void DrmDisplayHostManager::RunUpdateDisplaysCallback(
+ const GetDisplaysCallback& callback) const {
+ callback.Run(displays_.get());
+}
+
+void DrmDisplayHostManager::NotifyDisplayDelegate() const {
+ if (delegate_)
+ delegate_->OnConfigurationChanged();
+}
+
+} // namespace ui
diff --git a/ui/ozone/platform/drm/host/drm_display_host_manager.h b/ui/ozone/platform/drm/host/drm_display_host_manager.h
new file mode 100644
index 0000000..a7e8454
--- /dev/null
+++ b/ui/ozone/platform/drm/host/drm_display_host_manager.h
@@ -0,0 +1,146 @@
+// Copyright 2014 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_OZONE_PLATFORM_DRM_HOST_DRM_DISPLAY_HOST_MANAGER_H_
+#define UI_OZONE_PLATFORM_DRM_HOST_DRM_DISPLAY_HOST_MANAGER_H_
+
+#include <map>
+#include <queue>
+
+#include "base/containers/scoped_ptr_hash_map.h"
+#include "base/files/file.h"
+#include "base/files/file_path.h"
+#include "base/macros.h"
+#include "base/memory/scoped_vector.h"
+#include "base/memory/weak_ptr.h"
+#include "ui/display/types/native_display_delegate.h"
+#include "ui/events/ozone/device/device_event.h"
+#include "ui/events/ozone/device/device_event_observer.h"
+#include "ui/ozone/public/gpu_platform_support_host.h"
+
+namespace ui {
+
+class DeviceManager;
+class DrmDeviceHandle;
+class DrmGpuPlatformSupportHost;
+class DrmNativeDisplayDelegate;
+
+struct DisplaySnapshot_Params;
+
+class DrmDisplayHostManager : public DeviceEventObserver,
+ public GpuPlatformSupportHost {
+ public:
+ DrmDisplayHostManager(DrmGpuPlatformSupportHost* proxy,
+ DeviceManager* device_manager,
+ const base::FilePath& primary_graphics_card_path);
+ ~DrmDisplayHostManager() override;
+
+ DisplaySnapshot* GetDisplay(int64_t display_id);
+
+ void AddDelegate(DrmNativeDisplayDelegate* delegate);
+ void RemoveDelegate(DrmNativeDisplayDelegate* delegate);
+
+ bool TakeDisplayControl();
+ bool RelinquishDisplayControl();
+ void UpdateDisplays(const GetDisplaysCallback& callback);
+ void Configure(int64_t display_id,
+ const DisplayMode* mode,
+ const gfx::Point& origin,
+ const ConfigureCallback& callback);
+ void GetHDCPState(int64_t display_id, const GetHDCPStateCallback& callback);
+ void SetHDCPState(int64_t display_id,
+ HDCPState state,
+ const SetHDCPStateCallback& callback);
+ bool SetGammaRamp(int64_t display_id,
+ const std::vector<GammaRampRGBEntry>& lut);
+
+ // DeviceEventObserver overrides:
+ void OnDeviceEvent(const DeviceEvent& event) override;
+
+ // GpuPlatformSupportHost:
+ void OnChannelEstablished(
+ int host_id,
+ scoped_refptr<base::SingleThreadTaskRunner> send_runner,
+ const base::Callback<void(IPC::Message*)>& send_callback) override;
+ void OnChannelDestroyed(int host_id) override;
+
+ // IPC::Listener overrides:
+ bool OnMessageReceived(const IPC::Message& message) override;
+
+ private:
+ struct DisplayEvent {
+ DisplayEvent(DeviceEvent::ActionType action_type,
+ const base::FilePath& path)
+ : action_type(action_type), path(path) {}
+
+ DeviceEvent::ActionType action_type;
+ base::FilePath path;
+ };
+
+ void OnUpdateNativeDisplays(
+ const std::vector<DisplaySnapshot_Params>& displays);
+ void OnDisplayConfigured(int64_t display_id, bool status);
+
+ void ProcessEvent();
+
+ // Called as a result of finishing to process the display hotplug event. These
+ // are responsible for dequing the event and scheduling the next event.
+ void OnAddGraphicsDevice(const base::FilePath& path,
+ scoped_ptr<DrmDeviceHandle> handle);
+ void OnUpdateGraphicsDevice();
+ void OnRemoveGraphicsDevice(const base::FilePath& path);
+
+ void OnHDCPStateReceived(int64_t display_id, bool status, HDCPState state);
+ void OnHDCPStateUpdated(int64_t display_id, bool status);
+
+ void RunUpdateDisplaysCallback(const GetDisplaysCallback& callback) const;
+
+ void NotifyDisplayDelegate() const;
+
+ DrmGpuPlatformSupportHost* proxy_; // Not owned.
+ DeviceManager* device_manager_; // Not owned.
+
+ DrmNativeDisplayDelegate* delegate_; // Not owned.
+
+ // File path for the primary graphics card which is opened by default in the
+ // GPU process. We'll avoid opening this in hotplug events since it will race
+ // with the GPU process trying to open it and aquire DRM master.
+ base::FilePath primary_graphics_card_path_;
+
+ // Keeps track if there is a dummy display. This happens on initialization
+ // when there is no connection to the GPU to update the displays.
+ bool has_dummy_display_;
+
+ ScopedVector<DisplaySnapshot> displays_;
+
+ GetDisplaysCallback get_displays_callback_;
+
+ // Map between display_id and the configuration callback.
+ std::map<int64_t, ConfigureCallback> configure_callback_map_;
+
+ std::map<int64_t, GetHDCPStateCallback> get_hdcp_state_callback_map_;
+
+ std::map<int64_t, SetHDCPStateCallback> set_hdcp_state_callback_map_;
+
+ // Used to serialize display event processing. This is done since
+ // opening/closing DRM devices cannot be done on the UI thread and are handled
+ // on a worker thread. Thus, we need to queue events in order to process them
+ // in the correct order.
+ std::queue<DisplayEvent> event_queue_;
+
+ // True if a display event is currently being processed on a worker thread.
+ bool task_pending_;
+
+ // Keeps track of all the active DRM devices.
+ base::ScopedPtrHashMap<base::FilePath, scoped_ptr<DrmDeviceHandle>>
+ drm_devices_;
+
+ base::WeakPtrFactory<DrmDisplayHostManager> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(DrmDisplayHostManager);
+};
+
+} // namespace ui
+
+#endif // UI_OZONE_PLATFORM_DRM_HOST_DRM_DISPLAY_HOST_MANAGER_H_
diff --git a/ui/ozone/platform/drm/host/drm_native_display_delegate.cc b/ui/ozone/platform/drm/host/drm_native_display_delegate.cc
index fffa9ca..93c3bc7 100644
--- a/ui/ozone/platform/drm/host/drm_native_display_delegate.cc
+++ b/ui/ozone/platform/drm/host/drm_native_display_delegate.cc
@@ -4,144 +4,28 @@
#include "ui/ozone/platform/drm/host/drm_native_display_delegate.h"
-#include <stdio.h>
-
-#include "base/logging.h"
-#include "base/thread_task_runner_handle.h"
-#include "base/threading/thread_restrictions.h"
-#include "base/threading/worker_pool.h"
#include "ui/display/types/display_snapshot.h"
#include "ui/display/types/native_display_observer.h"
-#include "ui/events/ozone/device/device_event.h"
-#include "ui/events/ozone/device/device_manager.h"
-#include "ui/ozone/common/display_snapshot_proxy.h"
-#include "ui/ozone/common/display_util.h"
-#include "ui/ozone/common/gpu/ozone_gpu_messages.h"
-#include "ui/ozone/platform/drm/host/display_manager.h"
-#include "ui/ozone/platform/drm/host/drm_device_handle.h"
-#include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
+#include "ui/ozone/platform/drm/host/drm_display_host_manager.h"
namespace ui {
-namespace {
-
-typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)>
- OnOpenDeviceReplyCallback;
-
-const char* kDisplayActionString[] = {
- "ADD",
- "REMOVE",
- "CHANGE",
-};
-
-void OpenDeviceOnWorkerThread(
- const base::FilePath& path,
- const scoped_refptr<base::TaskRunner>& reply_runner,
- const OnOpenDeviceReplyCallback& callback) {
- scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle());
- handle->Initialize(path);
- reply_runner->PostTask(
- FROM_HERE, base::Bind(callback, path, base::Passed(handle.Pass())));
-}
-
-void CloseDeviceOnWorkerThread(
- scoped_ptr<DrmDeviceHandle> handle,
- const scoped_refptr<base::TaskRunner>& reply_runner,
- const base::Closure& callback) {
- handle.reset();
- reply_runner->PostTask(FROM_HERE, callback);
-}
-
-class DrmDisplaySnapshotProxy : public DisplaySnapshotProxy {
- public:
- DrmDisplaySnapshotProxy(const DisplaySnapshot_Params& params,
- DisplayManager* display_manager)
- : DisplaySnapshotProxy(params), display_manager_(display_manager) {
- display_manager_->RegisterDisplay(this);
- }
-
- ~DrmDisplaySnapshotProxy() override {
- display_manager_->UnregisterDisplay(this);
- }
-
- private:
- DisplayManager* display_manager_; // Not owned.
-
- DISALLOW_COPY_AND_ASSIGN(DrmDisplaySnapshotProxy);
-};
-
-} // namespace
-
DrmNativeDisplayDelegate::DrmNativeDisplayDelegate(
- DrmGpuPlatformSupportHost* proxy,
- DeviceManager* device_manager,
- DisplayManager* display_manager,
- const base::FilePath& primary_graphics_card_path)
- : proxy_(proxy),
- device_manager_(device_manager),
- display_manager_(display_manager),
- primary_graphics_card_path_(primary_graphics_card_path),
- has_dummy_display_(false),
- task_pending_(false),
- weak_ptr_factory_(this) {
- proxy_->RegisterHandler(this);
+ DrmDisplayHostManager* display_manager)
+ : display_manager_(display_manager) {
}
DrmNativeDisplayDelegate::~DrmNativeDisplayDelegate() {
- device_manager_->RemoveObserver(this);
- proxy_->UnregisterHandler(this);
+ display_manager_->RemoveDelegate(this);
+}
- for (auto it = drm_devices_.begin(); it != drm_devices_.end(); ++it) {
- base::WorkerPool::PostTask(FROM_HERE,
- base::Bind(&CloseDeviceOnWorkerThread,
- base::Passed(drm_devices_.take(it)),
- base::ThreadTaskRunnerHandle::Get(),
- base::Bind(&base::DoNothing)),
- false /* task_is_slow */);
- }
+void DrmNativeDisplayDelegate::OnConfigurationChanged() {
+ FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
+ OnConfigurationChanged());
}
void DrmNativeDisplayDelegate::Initialize() {
- {
- // First device needs to be treated specially. We need to open this
- // synchronously since the GPU process will need it to initialize the
- // graphics state.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle());
- if (!handle->Initialize(primary_graphics_card_path_)) {
- LOG(FATAL) << "Failed to open primary graphics card";
- return;
- }
- drm_devices_.add(primary_graphics_card_path_, handle.Pass());
- }
-
- device_manager_->AddObserver(this);
- device_manager_->ScanDevices(this);
-
- if (!displays_.empty())
- return;
- DisplaySnapshot_Params params;
- bool success = false;
- {
- // The file generated by frecon that contains EDID for the 1st display.
- const base::FilePath kEDIDFile("/tmp/display_info.bin");
-
- // Just read it on current thread as this is necessary information
- // to start. This access only tmpfs, which is fast.
- // TODO(dnicoara|oshima): crbug.com/450886.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- success = CreateSnapshotFromEDIDFile(kEDIDFile, &params);
- }
-
- // Fallback to command line if the file doesn't exit or failed to read.
- if (success || CreateSnapshotFromCommandLine(&params)) {
- LOG_IF(ERROR, !success) << "Failed to read display_info.bin.";
- DCHECK_NE(DISPLAY_CONNECTION_TYPE_NONE, params.type);
- displays_.push_back(new DrmDisplaySnapshotProxy(params, display_manager_));
- has_dummy_display_ = true;
- } else {
- LOG(ERROR) << "Failed to obtain initial display info";
- }
+ display_manager_->AddDelegate(this);
}
void DrmNativeDisplayDelegate::GrabServer() {
@@ -151,20 +35,17 @@ void DrmNativeDisplayDelegate::UngrabServer() {
}
bool DrmNativeDisplayDelegate::TakeDisplayControl() {
- proxy_->Send(new OzoneGpuMsg_TakeDisplayControl());
- return true;
+ return display_manager_->TakeDisplayControl();
}
bool DrmNativeDisplayDelegate::RelinquishDisplayControl() {
- proxy_->Send(new OzoneGpuMsg_RelinquishDisplayControl());
- return true;
+ return display_manager_->RelinquishDisplayControl();
}
void DrmNativeDisplayDelegate::SyncWithServer() {
}
void DrmNativeDisplayDelegate::SetBackgroundColor(uint32_t color_argb) {
- NOTIMPLEMENTED();
}
void DrmNativeDisplayDelegate::ForceDPMSOn() {
@@ -172,73 +53,45 @@ void DrmNativeDisplayDelegate::ForceDPMSOn() {
void DrmNativeDisplayDelegate::GetDisplays(
const GetDisplaysCallback& callback) {
- get_displays_callback_ = callback;
- // GetDisplays() is supposed to force a refresh of the display list.
- if (!proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays())) {
- get_displays_callback_.Reset();
- callback.Run(displays_.get());
- }
+ display_manager_->UpdateDisplays(callback);
}
-void DrmNativeDisplayDelegate::AddMode(const DisplaySnapshot& output,
- const DisplayMode* mode) {
+void DrmNativeDisplayDelegate::AddMode(const ui::DisplaySnapshot& output,
+ const ui::DisplayMode* mode) {
}
-void DrmNativeDisplayDelegate::Configure(const DisplaySnapshot& output,
- const DisplayMode* mode,
+void DrmNativeDisplayDelegate::Configure(const ui::DisplaySnapshot& output,
+ const ui::DisplayMode* mode,
const gfx::Point& origin,
const ConfigureCallback& callback) {
- // The dummy display is used on the first run only. Note: cannot post a task
- // here since there is no task runner.
- if (has_dummy_display_) {
- callback.Run(true);
- return;
- }
-
- configure_callback_map_[output.display_id()] = callback;
-
- bool status = false;
- if (mode) {
- status = proxy_->Send(new OzoneGpuMsg_ConfigureNativeDisplay(
- output.display_id(), GetDisplayModeParams(*mode), origin));
- } else {
- status =
- proxy_->Send(new OzoneGpuMsg_DisableNativeDisplay(output.display_id()));
- }
-
- if (!status)
- OnDisplayConfigured(output.display_id(), false);
+ display_manager_->Configure(output.display_id(), mode, origin, callback);
}
void DrmNativeDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {
}
void DrmNativeDisplayDelegate::GetHDCPState(
- const DisplaySnapshot& output,
+ const ui::DisplaySnapshot& output,
const GetHDCPStateCallback& callback) {
- get_hdcp_state_callback_map_[output.display_id()] = callback;
- if (!proxy_->Send(new OzoneGpuMsg_GetHDCPState(output.display_id())))
- OnHDCPStateReceived(output.display_id(), false, HDCP_STATE_UNDESIRED);
+ display_manager_->GetHDCPState(output.display_id(), callback);
}
void DrmNativeDisplayDelegate::SetHDCPState(
- const DisplaySnapshot& output,
- HDCPState state,
+ const ui::DisplaySnapshot& output,
+ ui::HDCPState state,
const SetHDCPStateCallback& callback) {
- set_hdcp_state_callback_map_[output.display_id()] = callback;
- if (!proxy_->Send(new OzoneGpuMsg_SetHDCPState(output.display_id(), state)))
- OnHDCPStateUpdated(output.display_id(), false);
+ display_manager_->SetHDCPState(output.display_id(), state, callback);
}
-std::vector<ColorCalibrationProfile>
+std::vector<ui::ColorCalibrationProfile>
DrmNativeDisplayDelegate::GetAvailableColorCalibrationProfiles(
- const DisplaySnapshot& output) {
- return std::vector<ColorCalibrationProfile>();
+ const ui::DisplaySnapshot& output) {
+ return std::vector<ui::ColorCalibrationProfile>();
}
bool DrmNativeDisplayDelegate::SetColorCalibrationProfile(
- const DisplaySnapshot& output,
- ColorCalibrationProfile new_profile) {
+ const ui::DisplaySnapshot& output,
+ ui::ColorCalibrationProfile new_profile) {
NOTIMPLEMENTED();
return false;
}
@@ -246,8 +99,7 @@ bool DrmNativeDisplayDelegate::SetColorCalibrationProfile(
bool DrmNativeDisplayDelegate::SetGammaRamp(
const ui::DisplaySnapshot& output,
const std::vector<GammaRampRGBEntry>& lut) {
- proxy_->Send(new OzoneGpuMsg_SetGammaRamp(output.display_id(), lut));
- return true;
+ return display_manager_->SetGammaRamp(output.display_id(), lut);
}
void DrmNativeDisplayDelegate::AddObserver(NativeDisplayObserver* observer) {
@@ -258,198 +110,4 @@ void DrmNativeDisplayDelegate::RemoveObserver(NativeDisplayObserver* observer) {
observers_.RemoveObserver(observer);
}
-void DrmNativeDisplayDelegate::OnDeviceEvent(const DeviceEvent& event) {
- if (event.device_type() != DeviceEvent::DISPLAY)
- return;
-
- event_queue_.push(DisplayEvent(event.action_type(), event.path()));
- ProcessEvent();
-}
-
-void DrmNativeDisplayDelegate::ProcessEvent() {
- while (!event_queue_.empty() && !task_pending_) {
- DisplayEvent event = event_queue_.front();
- event_queue_.pop();
- VLOG(1) << "Got display event " << kDisplayActionString[event.action_type]
- << " for " << event.path.value();
- switch (event.action_type) {
- case DeviceEvent::ADD:
- if (drm_devices_.find(event.path) == drm_devices_.end()) {
- task_pending_ = base::WorkerPool::PostTask(
- FROM_HERE,
- base::Bind(
- &OpenDeviceOnWorkerThread, event.path,
- base::ThreadTaskRunnerHandle::Get(),
- base::Bind(&DrmNativeDisplayDelegate::OnAddGraphicsDevice,
- weak_ptr_factory_.GetWeakPtr())),
- false /* task_is_slow */);
- }
- break;
- case DeviceEvent::CHANGE:
- task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(&DrmNativeDisplayDelegate::OnUpdateGraphicsDevice,
- weak_ptr_factory_.GetWeakPtr()));
- break;
- case DeviceEvent::REMOVE:
- DCHECK(event.path != primary_graphics_card_path_)
- << "Removing primary graphics card";
- auto it = drm_devices_.find(event.path);
- if (it != drm_devices_.end()) {
- task_pending_ = base::WorkerPool::PostTask(
- FROM_HERE,
- base::Bind(
- &CloseDeviceOnWorkerThread,
- base::Passed(drm_devices_.take_and_erase(it)),
- base::ThreadTaskRunnerHandle::Get(),
- base::Bind(&DrmNativeDisplayDelegate::OnRemoveGraphicsDevice,
- weak_ptr_factory_.GetWeakPtr(), event.path)),
- false /* task_is_slow */);
- return;
- }
- break;
- }
- }
-}
-
-void DrmNativeDisplayDelegate::OnAddGraphicsDevice(
- const base::FilePath& path,
- scoped_ptr<DrmDeviceHandle> handle) {
- if (handle->IsValid()) {
- base::ScopedFD file = handle->Duplicate();
- drm_devices_.add(path, handle.Pass());
- proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(
- path, base::FileDescriptor(file.Pass())));
- FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
- OnConfigurationChanged());
- }
-
- task_pending_ = false;
- ProcessEvent();
-}
-
-void DrmNativeDisplayDelegate::OnUpdateGraphicsDevice() {
- FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
- OnConfigurationChanged());
- task_pending_ = false;
- ProcessEvent();
-}
-
-void DrmNativeDisplayDelegate::OnRemoveGraphicsDevice(
- const base::FilePath& path) {
- proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(path));
- FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
- OnConfigurationChanged());
- task_pending_ = false;
- ProcessEvent();
-}
-
-void DrmNativeDisplayDelegate::OnChannelEstablished(
- int host_id,
- scoped_refptr<base::SingleThreadTaskRunner> send_runner,
- const base::Callback<void(IPC::Message*)>& send_callback) {
- auto it = drm_devices_.find(primary_graphics_card_path_);
- DCHECK(it != drm_devices_.end());
- // Send the primary device first since this is used to initialize graphics
- // state.
- proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(
- it->first, base::FileDescriptor(it->second->Duplicate())));
-
- for (auto pair : drm_devices_) {
- if (pair.second->IsValid() && pair.first != primary_graphics_card_path_) {
- proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(
- pair.first, base::FileDescriptor(pair.second->Duplicate())));
- }
- }
-
- device_manager_->ScanDevices(this);
- FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
- OnConfigurationChanged());
-}
-
-void DrmNativeDisplayDelegate::OnChannelDestroyed(int host_id) {
- // If the channel got destroyed in the middle of a configuration then just
- // respond with failure.
- if (!get_displays_callback_.is_null()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(&DrmNativeDisplayDelegate::RunUpdateDisplaysCallback,
- weak_ptr_factory_.GetWeakPtr(), get_displays_callback_));
- get_displays_callback_.Reset();
- }
-
- for (const auto& pair : configure_callback_map_) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(pair.second, false));
- }
- configure_callback_map_.clear();
-}
-
-bool DrmNativeDisplayDelegate::OnMessageReceived(const IPC::Message& message) {
- bool handled = true;
-
- IPC_BEGIN_MESSAGE_MAP(DrmNativeDisplayDelegate, message)
- IPC_MESSAGE_HANDLER(OzoneHostMsg_UpdateNativeDisplays, OnUpdateNativeDisplays)
- IPC_MESSAGE_HANDLER(OzoneHostMsg_DisplayConfigured, OnDisplayConfigured)
- IPC_MESSAGE_HANDLER(OzoneHostMsg_HDCPStateReceived, OnHDCPStateReceived)
- IPC_MESSAGE_HANDLER(OzoneHostMsg_HDCPStateUpdated, OnHDCPStateUpdated)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
-
- return handled;
-}
-
-void DrmNativeDisplayDelegate::OnUpdateNativeDisplays(
- const std::vector<DisplaySnapshot_Params>& displays) {
- has_dummy_display_ = false;
- displays_.clear();
- for (size_t i = 0; i < displays.size(); ++i)
- displays_.push_back(
- new DrmDisplaySnapshotProxy(displays[i], display_manager_));
-
- if (!get_displays_callback_.is_null()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(&DrmNativeDisplayDelegate::RunUpdateDisplaysCallback,
- weak_ptr_factory_.GetWeakPtr(), get_displays_callback_));
- get_displays_callback_.Reset();
- }
-}
-
-void DrmNativeDisplayDelegate::OnDisplayConfigured(int64_t display_id,
- bool status) {
- auto it = configure_callback_map_.find(display_id);
- if (it != configure_callback_map_.end()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(it->second, status));
- configure_callback_map_.erase(it);
- }
-}
-
-void DrmNativeDisplayDelegate::OnHDCPStateReceived(int64_t display_id,
- bool status,
- HDCPState state) {
- auto it = get_hdcp_state_callback_map_.find(display_id);
- if (it != get_hdcp_state_callback_map_.end()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(it->second, status, state));
- get_hdcp_state_callback_map_.erase(it);
- }
-}
-
-void DrmNativeDisplayDelegate::OnHDCPStateUpdated(int64_t display_id,
- bool status) {
- auto it = set_hdcp_state_callback_map_.find(display_id);
- if (it != set_hdcp_state_callback_map_.end()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(it->second, status));
- set_hdcp_state_callback_map_.erase(it);
- }
-}
-
-void DrmNativeDisplayDelegate::RunUpdateDisplaysCallback(
- const GetDisplaysCallback& callback) const {
- callback.Run(displays_.get());
-}
-
} // namespace ui
diff --git a/ui/ozone/platform/drm/host/drm_native_display_delegate.h b/ui/ozone/platform/drm/host/drm_native_display_delegate.h
index 09d01a4..c85c694 100644
--- a/ui/ozone/platform/drm/host/drm_native_display_delegate.h
+++ b/ui/ozone/platform/drm/host/drm_native_display_delegate.h
@@ -2,42 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef UI_OZONE_PLATFORM_DRM_HOST_NATIVE_DISPLAY_DELEGATE_HOST_H_
-#define UI_OZONE_PLATFORM_DRM_HOST_NATIVE_DISPLAY_DELEGATE_HOST_H_
+#ifndef UI_OZONE_PLATFORM_DRM_HOST_DRM_NATIVE_DISPLAY_DELEGATE_H_
+#define UI_OZONE_PLATFORM_DRM_HOST_DRM_NATIVE_DISPLAY_DELEGATE_H_
-#include <map>
-#include <queue>
-
-#include "base/containers/scoped_ptr_hash_map.h"
-#include "base/files/file.h"
-#include "base/files/file_path.h"
#include "base/macros.h"
-#include "base/memory/scoped_vector.h"
#include "base/observer_list.h"
#include "ui/display/types/native_display_delegate.h"
-#include "ui/events/ozone/device/device_event.h"
-#include "ui/events/ozone/device/device_event_observer.h"
-#include "ui/ozone/public/gpu_platform_support_host.h"
namespace ui {
-class DeviceManager;
-class DisplayManager;
-class DrmDeviceHandle;
-class DrmGpuPlatformSupportHost;
-
-struct DisplaySnapshot_Params;
+class DrmDisplayHostManager;
-class DrmNativeDisplayDelegate : public NativeDisplayDelegate,
- public DeviceEventObserver,
- public GpuPlatformSupportHost {
+class DrmNativeDisplayDelegate : public NativeDisplayDelegate {
public:
- DrmNativeDisplayDelegate(DrmGpuPlatformSupportHost* proxy,
- DeviceManager* device_manager,
- DisplayManager* display_manager,
- const base::FilePath& primary_graphics_card_path);
+ DrmNativeDisplayDelegate(DrmDisplayHostManager* display_manager);
~DrmNativeDisplayDelegate() override;
+ void OnConfigurationChanged();
+
// NativeDisplayDelegate overrides:
void Initialize() override;
void GrabServer() override;
@@ -48,110 +30,37 @@ class DrmNativeDisplayDelegate : public NativeDisplayDelegate,
void SetBackgroundColor(uint32_t color_argb) override;
void ForceDPMSOn() override;
void GetDisplays(const GetDisplaysCallback& callback) override;
- void AddMode(const DisplaySnapshot& output, const DisplayMode* mode) override;
- void Configure(const DisplaySnapshot& output,
- const DisplayMode* mode,
+ void AddMode(const ui::DisplaySnapshot& output,
+ const ui::DisplayMode* mode) override;
+ void Configure(const ui::DisplaySnapshot& output,
+ const ui::DisplayMode* mode,
const gfx::Point& origin,
const ConfigureCallback& callback) override;
void CreateFrameBuffer(const gfx::Size& size) override;
- void GetHDCPState(const DisplaySnapshot& output,
+ void GetHDCPState(const ui::DisplaySnapshot& output,
const GetHDCPStateCallback& callback) override;
- void SetHDCPState(const DisplaySnapshot& output,
- HDCPState state,
+ void SetHDCPState(const ui::DisplaySnapshot& output,
+ ui::HDCPState state,
const SetHDCPStateCallback& callback) override;
- std::vector<ColorCalibrationProfile> GetAvailableColorCalibrationProfiles(
- const DisplaySnapshot& output) override;
- bool SetColorCalibrationProfile(const DisplaySnapshot& output,
- ColorCalibrationProfile new_profile) override;
+ std::vector<ui::ColorCalibrationProfile> GetAvailableColorCalibrationProfiles(
+ const ui::DisplaySnapshot& output) override;
+ bool SetColorCalibrationProfile(
+ const ui::DisplaySnapshot& output,
+ ui::ColorCalibrationProfile new_profile) override;
bool SetGammaRamp(const ui::DisplaySnapshot& output,
const std::vector<GammaRampRGBEntry>& lut) override;
+
void AddObserver(NativeDisplayObserver* observer) override;
void RemoveObserver(NativeDisplayObserver* observer) override;
- // DeviceEventObserver overrides:
- void OnDeviceEvent(const DeviceEvent& event) override;
-
- // GpuPlatformSupportHost:
- void OnChannelEstablished(
- int host_id,
- scoped_refptr<base::SingleThreadTaskRunner> send_runner,
- const base::Callback<void(IPC::Message*)>& send_callback) override;
- void OnChannelDestroyed(int host_id) override;
-
- // IPC::Listener overrides:
- bool OnMessageReceived(const IPC::Message& message) override;
-
private:
- struct DisplayEvent {
- DisplayEvent(DeviceEvent::ActionType action_type,
- const base::FilePath& path)
- : action_type(action_type), path(path) {}
-
- DeviceEvent::ActionType action_type;
- base::FilePath path;
- };
-
- void OnUpdateNativeDisplays(
- const std::vector<DisplaySnapshot_Params>& displays);
- void OnDisplayConfigured(int64_t display_id, bool status);
-
- void ProcessEvent();
-
- // Called as a result of finishing to process the display hotplug event. These
- // are responsible for dequing the event and scheduling the next event.
- void OnAddGraphicsDevice(const base::FilePath& path,
- scoped_ptr<DrmDeviceHandle> handle);
- void OnUpdateGraphicsDevice();
- void OnRemoveGraphicsDevice(const base::FilePath& path);
-
- void OnHDCPStateReceived(int64_t display_id, bool status, HDCPState state);
- void OnHDCPStateUpdated(int64_t display_id, bool status);
+ DrmDisplayHostManager* display_manager_; // Not owned.
- void RunUpdateDisplaysCallback(const GetDisplaysCallback& callback) const;
-
- DrmGpuPlatformSupportHost* proxy_; // Not owned.
- DeviceManager* device_manager_; // Not owned.
- DisplayManager* display_manager_; // Not owned.
-
- // File path for the primary graphics card which is opened by default in the
- // GPU process. We'll avoid opening this in hotplug events since it will race
- // with the GPU process trying to open it and aquire DRM master.
- const base::FilePath primary_graphics_card_path_;
-
- // Keeps track if there is a dummy display. This happens on initialization
- // when there is no connection to the GPU to update the displays.
- bool has_dummy_display_;
-
- ScopedVector<DisplaySnapshot> displays_;
ObserverList<NativeDisplayObserver> observers_;
- GetDisplaysCallback get_displays_callback_;
-
- // Map between display_id and the configuration callback.
- std::map<int64_t, ConfigureCallback> configure_callback_map_;
-
- std::map<int64_t, GetHDCPStateCallback> get_hdcp_state_callback_map_;
-
- std::map<int64_t, SetHDCPStateCallback> set_hdcp_state_callback_map_;
-
- // Used to serialize display event processing. This is done since
- // opening/closing DRM devices cannot be done on the UI thread and are handled
- // on a worker thread. Thus, we need to queue events in order to process them
- // in the correct order.
- std::queue<DisplayEvent> event_queue_;
-
- // True if a display event is currently being processed on a worker thread.
- bool task_pending_;
-
- // Keeps track of all the active DRM devices.
- base::ScopedPtrHashMap<base::FilePath, scoped_ptr<DrmDeviceHandle>>
- drm_devices_;
-
- base::WeakPtrFactory<DrmNativeDisplayDelegate> weak_ptr_factory_;
-
DISALLOW_COPY_AND_ASSIGN(DrmNativeDisplayDelegate);
};
} // namespace ui
-#endif // UI_OZONE_PLATFORM_DRM_HOST_NATIVE_DISPLAY_DELEGATE_HOST_H_
+#endif // UI_OZONE_PLATFORM_DRM_HOST_DRM_NATIVE_DISPLAY_DELEGATE_H_
diff --git a/ui/ozone/platform/drm/host/drm_window_host.cc b/ui/ozone/platform/drm/host/drm_window_host.cc
index 4bf3385..d1926cb 100644
--- a/ui/ozone/platform/drm/host/drm_window_host.cc
+++ b/ui/ozone/platform/drm/host/drm_window_host.cc
@@ -12,8 +12,8 @@
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/display.h"
#include "ui/ozone/common/gpu/ozone_gpu_messages.h"
-#include "ui/ozone/platform/drm/host/display_manager.h"
#include "ui/ozone/platform/drm/host/drm_cursor.h"
+#include "ui/ozone/platform/drm/host/drm_display_host_manager.h"
#include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
#include "ui/ozone/platform/drm/host/drm_window_host_manager.h"
#include "ui/platform_window/platform_window_delegate.h"
@@ -26,7 +26,7 @@ DrmWindowHost::DrmWindowHost(PlatformWindowDelegate* delegate,
EventFactoryEvdev* event_factory,
DrmCursor* cursor,
DrmWindowHostManager* window_manager,
- DisplayManager* display_manager)
+ DrmDisplayHostManager* display_manager)
: delegate_(delegate),
sender_(sender),
event_factory_(event_factory),
diff --git a/ui/ozone/platform/drm/host/drm_window_host.h b/ui/ozone/platform/drm/host/drm_window_host.h
index 74021f8..70f1393 100644
--- a/ui/ozone/platform/drm/host/drm_window_host.h
+++ b/ui/ozone/platform/drm/host/drm_window_host.h
@@ -15,7 +15,7 @@
namespace ui {
-class DisplayManager;
+class DrmDisplayHostManager;
class DrmCursor;
class DrmGpuPlatformSupportHost;
class DrmGpuWindow;
@@ -42,7 +42,7 @@ class DrmWindowHost : public PlatformWindow,
EventFactoryEvdev* event_factory,
DrmCursor* cursor,
DrmWindowHostManager* window_manager,
- DisplayManager* display_manager);
+ DrmDisplayHostManager* display_manager);
~DrmWindowHost() override;
void Initialize();
@@ -78,12 +78,12 @@ class DrmWindowHost : public PlatformWindow,
private:
void SendBoundsChange();
- PlatformWindowDelegate* delegate_; // Not owned.
- DrmGpuPlatformSupportHost* sender_; // Not owned.
- EventFactoryEvdev* event_factory_; // Not owned.
- DrmCursor* cursor_; // Not owned.
- DrmWindowHostManager* window_manager_; // Not owned.
- DisplayManager* display_manager_; // Not owned.
+ PlatformWindowDelegate* delegate_; // Not owned.
+ DrmGpuPlatformSupportHost* sender_; // Not owned.
+ EventFactoryEvdev* event_factory_; // Not owned.
+ DrmCursor* cursor_; // Not owned.
+ DrmWindowHostManager* window_manager_; // Not owned.
+ DrmDisplayHostManager* display_manager_; // Not owned.
gfx::Rect bounds_;
gfx::AcceleratedWidget widget_;
diff --git a/ui/ozone/platform/drm/ozone_platform_drm.cc b/ui/ozone/platform/drm/ozone_platform_drm.cc
index 3803031..9ad1080 100644
--- a/ui/ozone/platform/drm/ozone_platform_drm.cc
+++ b/ui/ozone/platform/drm/ozone_platform_drm.cc
@@ -22,8 +22,8 @@
#include "ui/ozone/platform/drm/gpu/drm_window.h"
#include "ui/ozone/platform/drm/gpu/gpu_lock.h"
#include "ui/ozone/platform/drm/gpu/screen_manager.h"
-#include "ui/ozone/platform/drm/host/display_manager.h"
#include "ui/ozone/platform/drm/host/drm_cursor.h"
+#include "ui/ozone/platform/drm/host/drm_display_host_manager.h"
#include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
#include "ui/ozone/platform/drm/host/drm_native_display_delegate.h"
#include "ui/ozone/platform/drm/host/drm_window_host.h"
@@ -84,9 +84,8 @@ class OzonePlatformDrm : public OzonePlatform {
return platform_window.Pass();
}
scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() override {
- return make_scoped_ptr(new DrmNativeDisplayDelegate(
- gpu_platform_support_host_.get(), device_manager_.get(),
- display_manager_.get(), GetPrimaryDisplayCardPath()));
+ return make_scoped_ptr(
+ new DrmNativeDisplayDelegate(display_manager_.get()));
}
void InitializeUI() override {
#if defined(OS_CHROMEOS)
@@ -94,7 +93,6 @@ class OzonePlatformDrm : public OzonePlatform {
#endif
drm_device_manager_.reset(new DrmDeviceManager(
scoped_ptr<DrmDeviceGenerator>(new DrmDeviceGenerator())));
- display_manager_.reset(new DisplayManager());
window_manager_.reset(new DrmWindowHostManager());
cursor_.reset(new DrmCursor(window_manager_.get()));
surface_factory_ozone_.reset(new DrmSurfaceFactory(screen_manager_.get()));
@@ -104,6 +102,9 @@ class OzonePlatformDrm : public OzonePlatform {
drm_device_manager_.get(), screen_manager_.get(), ndd.Pass()));
gpu_platform_support_host_.reset(
new DrmGpuPlatformSupportHost(cursor_.get()));
+ display_manager_.reset(new DrmDisplayHostManager(
+ gpu_platform_support_host_.get(), device_manager_.get(),
+ GetPrimaryDisplayCardPath()));
cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
#if defined(USE_XKBCOMMON)
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(make_scoped_ptr(
@@ -137,8 +138,8 @@ class OzonePlatformDrm : public OzonePlatform {
scoped_ptr<DrmWindowHostManager> window_manager_;
scoped_ptr<DrmCursor> cursor_;
scoped_ptr<EventFactoryEvdev> event_factory_ozone_;
- scoped_ptr<DisplayManager> display_manager_;
scoped_ptr<DrmGpuPlatformSupportHost> gpu_platform_support_host_;
+ scoped_ptr<DrmDisplayHostManager> display_manager_;
#if defined(USE_XKBCOMMON)
XkbEvdevCodes xkb_evdev_code_converter_;
diff --git a/ui/ozone/platform/drm/ozone_platform_gbm.cc b/ui/ozone/platform/drm/ozone_platform_gbm.cc
index d1fefb6..f5e027e 100644
--- a/ui/ozone/platform/drm/ozone_platform_gbm.cc
+++ b/ui/ozone/platform/drm/ozone_platform_gbm.cc
@@ -27,8 +27,8 @@
#include "ui/ozone/platform/drm/gpu/gpu_lock.h"
#include "ui/ozone/platform/drm/gpu/scanout_buffer.h"
#include "ui/ozone/platform/drm/gpu/screen_manager.h"
-#include "ui/ozone/platform/drm/host/display_manager.h"
#include "ui/ozone/platform/drm/host/drm_cursor.h"
+#include "ui/ozone/platform/drm/host/drm_display_host_manager.h"
#include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
#include "ui/ozone/platform/drm/host/drm_native_display_delegate.h"
#include "ui/ozone/platform/drm/host/drm_window_host.h"
@@ -141,12 +141,10 @@ class OzonePlatformGbm : public OzonePlatform {
return platform_window.Pass();
}
scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() override {
- return make_scoped_ptr(new DrmNativeDisplayDelegate(
- gpu_platform_support_host_.get(), device_manager_.get(),
- display_manager_.get(), GetPrimaryDisplayCardPath()));
+ return make_scoped_ptr(
+ new DrmNativeDisplayDelegate(display_manager_.get()));
}
void InitializeUI() override {
- display_manager_.reset(new DisplayManager());
// Needed since the browser process creates the accelerated widgets and that
// happens through SFO.
if (!surface_factory_ozone_)
@@ -156,6 +154,9 @@ class OzonePlatformGbm : public OzonePlatform {
cursor_.reset(new DrmCursor(window_manager_.get()));
gpu_platform_support_host_.reset(
new DrmGpuPlatformSupportHost(cursor_.get()));
+ display_manager_.reset(new DrmDisplayHostManager(
+ gpu_platform_support_host_.get(), device_manager_.get(),
+ GetPrimaryDisplayCardPath()));
cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
#if defined(USE_XKBCOMMON)
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(make_scoped_ptr(
@@ -209,7 +210,7 @@ class OzonePlatformGbm : public OzonePlatform {
scoped_ptr<DrmCursor> cursor_;
scoped_ptr<EventFactoryEvdev> event_factory_ozone_;
scoped_ptr<DrmGpuPlatformSupportHost> gpu_platform_support_host_;
- scoped_ptr<DisplayManager> display_manager_;
+ scoped_ptr<DrmDisplayHostManager> display_manager_;
#if defined(USE_XKBCOMMON)
XkbEvdevCodes xkb_evdev_code_converter_;