diff options
author | dnicoara@chromium.org <dnicoara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-09 14:42:07 +0000 |
---|---|---|
committer | dnicoara@chromium.org <dnicoara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-09 14:42:07 +0000 |
commit | ad1be9f184e56c357997b780e558102b5580bfe1 (patch) | |
tree | c9bb1d9410c5877def455c141052c24e3f1ebf98 /ui/ozone | |
parent | b27feb3a3a4fc9c6fdd08e94a22ab4378dd951ae (diff) | |
download | chromium_src-ad1be9f184e56c357997b780e558102b5580bfe1.zip chromium_src-ad1be9f184e56c357997b780e558102b5580bfe1.tar.gz chromium_src-ad1be9f184e56c357997b780e558102b5580bfe1.tar.bz2 |
[Ozone-GBM] Add basic support for display configuration over IPC
BUG=377497
NOTRY=true
Review URL: https://codereview.chromium.org/377753002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282036 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/ozone')
19 files changed, 674 insertions, 6 deletions
diff --git a/ui/ozone/common/chromeos/display_mode_proxy.cc b/ui/ozone/common/chromeos/display_mode_proxy.cc new file mode 100644 index 0000000..e398c12 --- /dev/null +++ b/ui/ozone/common/chromeos/display_mode_proxy.cc @@ -0,0 +1,16 @@ +// 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/common/chromeos/display_mode_proxy.h" + +#include "ui/ozone/common/gpu/ozone_gpu_message_params.h" + +namespace ui { + +DisplayModeProxy::DisplayModeProxy(const DisplayMode_Params& params) + : DisplayMode(params.size, params.is_interlaced, params.refresh_rate) {} + +DisplayModeProxy::~DisplayModeProxy() {} + +} // namespace ui diff --git a/ui/ozone/common/chromeos/display_mode_proxy.h b/ui/ozone/common/chromeos/display_mode_proxy.h new file mode 100644 index 0000000..436ea08 --- /dev/null +++ b/ui/ozone/common/chromeos/display_mode_proxy.h @@ -0,0 +1,25 @@ +// 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_COMMON_CHROMEOS_DISPLAY_MODE_PROXY_H_ +#define UI_OZONE_COMMON_CHROMEOS_DISPLAY_MODE_PROXY_H_ + +#include "ui/display/types/chromeos/display_mode.h" + +namespace ui { + +struct DisplayMode_Params; + +class DisplayModeProxy : public DisplayMode { + public: + DisplayModeProxy(const DisplayMode_Params& params); + virtual ~DisplayModeProxy(); + + private: + DISALLOW_COPY_AND_ASSIGN(DisplayModeProxy); +}; + +} // namespace ui + +#endif // UI_OZONE_COMMON_CHROMEOS_DISPLAY_MODE_PROXY_H_ diff --git a/ui/ozone/common/chromeos/display_snapshot_proxy.cc b/ui/ozone/common/chromeos/display_snapshot_proxy.cc new file mode 100644 index 0000000..f634ccf --- /dev/null +++ b/ui/ozone/common/chromeos/display_snapshot_proxy.cc @@ -0,0 +1,53 @@ +// 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/common/chromeos/display_snapshot_proxy.h" + +#include "ui/ozone/common/chromeos/display_mode_proxy.h" +#include "ui/ozone/common/gpu/ozone_gpu_message_params.h" + +namespace ui { + +namespace { + +bool SameModes(const DisplayMode_Params& lhs, const DisplayMode_Params& rhs) { + return lhs.size == rhs.size && lhs.is_interlaced == rhs.is_interlaced && + lhs.refresh_rate == rhs.refresh_rate; +} + +} // namespace + +DisplaySnapshotProxy::DisplaySnapshotProxy(const DisplaySnapshot_Params& params) + : DisplaySnapshot(params.display_id, + params.has_proper_display_id, + params.origin, + params.physical_size, + params.type, + params.is_aspect_preserving_scaling, + params.has_overscan, + params.display_name, + std::vector<const DisplayMode*>(), + NULL, + NULL), + string_representation_(params.string_representation) { + for (size_t i = 0; i < params.modes.size(); ++i) { + modes_.push_back(new DisplayModeProxy(params.modes[i])); + + if (params.has_current_mode && + SameModes(params.modes[i], params.current_mode)) + current_mode_ = modes_.back(); + + if (params.has_native_mode && + SameModes(params.modes[i], params.native_mode)) + native_mode_ = modes_.back(); + } +} + +DisplaySnapshotProxy::~DisplaySnapshotProxy() {} + +std::string DisplaySnapshotProxy::ToString() const { + return string_representation_; +} + +} // namespace ui diff --git a/ui/ozone/common/chromeos/display_snapshot_proxy.h b/ui/ozone/common/chromeos/display_snapshot_proxy.h new file mode 100644 index 0000000..f599fe3 --- /dev/null +++ b/ui/ozone/common/chromeos/display_snapshot_proxy.h @@ -0,0 +1,30 @@ +// 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_COMMON_CHROMEOS_DISPLAY_SNAPSHOT_PROXY_H_ +#define UI_OZONE_COMMON_CHROMEOS_DISPLAY_SNAPSHOT_PROXY_H_ + +#include "ui/display/types/chromeos/display_snapshot.h" + +namespace ui { + +struct DisplaySnapshot_Params; + +class DisplaySnapshotProxy : public DisplaySnapshot { + public: + DisplaySnapshotProxy(const DisplaySnapshot_Params& params); + virtual ~DisplaySnapshotProxy(); + + // DisplaySnapshot override: + virtual std::string ToString() const OVERRIDE; + + private: + std::string string_representation_; + + DISALLOW_COPY_AND_ASSIGN(DisplaySnapshotProxy); +}; + +} // namespace ui + +#endif // UI_OZONE_COMMON_CHROMEOS_DISPLAY_SNAPSHOT_PROXY_H_ diff --git a/ui/ozone/common/chromeos/display_util.cc b/ui/ozone/common/chromeos/display_util.cc new file mode 100644 index 0000000..674f8c1 --- /dev/null +++ b/ui/ozone/common/chromeos/display_util.cc @@ -0,0 +1,48 @@ +// 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/common/chromeos/display_util.h" + +#include "ui/display/types/chromeos/display_mode.h" +#include "ui/display/types/chromeos/display_snapshot.h" + +namespace ui { + +DisplayMode_Params GetDisplayModeParams(const DisplayMode& mode) { + DisplayMode_Params params; + params.size = mode.size(); + params.is_interlaced = mode.is_interlaced(); + params.refresh_rate = mode.refresh_rate(); + + return params; +} + +DisplaySnapshot_Params GetDisplaySnapshotParams( + const DisplaySnapshot& display) { + DisplaySnapshot_Params params; + params.display_id = display.display_id(); + params.has_proper_display_id = display.has_proper_display_id(); + params.origin = display.origin(); + params.physical_size = display.physical_size(); + params.type = display.type(); + params.is_aspect_preserving_scaling = display.is_aspect_preserving_scaling(); + params.has_overscan = display.has_overscan(); + params.display_name = display.display_name(); + for (size_t i = 0; i < display.modes().size(); ++i) + params.modes.push_back(GetDisplayModeParams(*display.modes()[i])); + + params.has_current_mode = display.current_mode() != NULL; + if (params.has_current_mode) + params.current_mode = GetDisplayModeParams(*display.current_mode()); + + params.has_native_mode = display.native_mode() != NULL; + if (params.has_native_mode) + params.native_mode = GetDisplayModeParams(*display.native_mode()); + + params.string_representation = display.ToString(); + + return params; +} + +} // namespace ui diff --git a/ui/ozone/common/chromeos/display_util.h b/ui/ozone/common/chromeos/display_util.h new file mode 100644 index 0000000..f02bf09 --- /dev/null +++ b/ui/ozone/common/chromeos/display_util.h @@ -0,0 +1,21 @@ +// 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_COMMON_CHROMEOS_DISPLAY_UTIL_H_ +#define UI_OZONE_COMMON_CHROMEOS_DISPLAY_UTIL_H_ + +#include "ui/ozone/common/gpu/ozone_gpu_message_params.h" + +namespace ui { + +class DisplayMode; +class DisplaySnapshot; + +DisplayMode_Params GetDisplayModeParams(const DisplayMode& mode); +DisplaySnapshot_Params GetDisplaySnapshotParams( + const DisplaySnapshot& display); + +} // namespace ui + +#endif // UI_OZONE_COMMON_CHROMEOS_DISPLAY_UTIL_H_ diff --git a/ui/ozone/ozone.gyp b/ui/ozone/ozone.gyp index 6cdf292..c000a2e 100644 --- a/ui/ozone/ozone.gyp +++ b/ui/ozone/ozone.gyp @@ -85,6 +85,12 @@ # common/chromeos files are excluded automatically when building with # chromeos=0, by exclusion rules in filename_rules.gypi due to the # 'chromeos' folder name. + 'common/chromeos/display_mode_proxy.cc', + 'common/chromeos/display_mode_proxy.h', + 'common/chromeos/display_snapshot_proxy.cc', + 'common/chromeos/display_snapshot_proxy.h', + 'common/chromeos/display_util.cc', + 'common/chromeos/display_util.h', 'common/chromeos/native_display_delegate_ozone.cc', 'common/chromeos/native_display_delegate_ozone.h', 'common/chromeos/touchscreen_device_manager_ozone.cc', diff --git a/ui/ozone/platform/dri/chromeos/display_message_handler.cc b/ui/ozone/platform/dri/chromeos/display_message_handler.cc new file mode 100644 index 0000000..5cfe2e0 --- /dev/null +++ b/ui/ozone/platform/dri/chromeos/display_message_handler.cc @@ -0,0 +1,95 @@ +// 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/dri/chromeos/display_message_handler.h" + +#include "ui/display/types/chromeos/display_mode.h" +#include "ui/display/types/chromeos/display_snapshot.h" +#include "ui/ozone/common/chromeos/display_util.h" +#include "ui/ozone/common/gpu/ozone_gpu_message_params.h" +#include "ui/ozone/common/gpu/ozone_gpu_messages.h" +#include "ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h" + +namespace ui { + +DisplayMessageHandler::DisplayMessageHandler( + scoped_ptr<NativeDisplayDelegateDri> ndd) + : sender_(NULL), + ndd_(ndd.Pass()) {} + +DisplayMessageHandler::~DisplayMessageHandler() {} + +void DisplayMessageHandler::OnChannelEstablished(IPC::Sender* sender) { + sender_ = sender; +} + +bool DisplayMessageHandler::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + + IPC_BEGIN_MESSAGE_MAP(DisplayMessageHandler, message) + IPC_MESSAGE_HANDLER(OzoneGpuMsg_ForceDPMSOn, OnForceDPMSOn) + IPC_MESSAGE_HANDLER(OzoneGpuMsg_RefreshNativeDisplays, + OnRefreshNativeDisplays) + IPC_MESSAGE_HANDLER(OzoneGpuMsg_ConfigureNativeDisplay, + OnConfigureNativeDisplay) + IPC_MESSAGE_HANDLER(OzoneGpuMsg_DisableNativeDisplay, + OnDisableNativeDisplay) + IPC_MESSAGE_UNHANDLED(handled = false); + IPC_END_MESSAGE_MAP() + + return handled; +} + +void DisplayMessageHandler::OnForceDPMSOn() { + ndd_->ForceDPMSOn(); +} + +void DisplayMessageHandler::OnRefreshNativeDisplays() { + std::vector<DisplaySnapshot_Params> displays; + std::vector<DisplaySnapshot*> native_displays = ndd_->GetDisplays(); + for (size_t i = 0; i < native_displays.size(); ++i) + displays.push_back(GetDisplaySnapshotParams(*native_displays[i])); + + sender_->Send(new OzoneHostMsg_UpdateNativeDisplays(displays)); +} + +void DisplayMessageHandler::OnConfigureNativeDisplay( + int64_t id, + const DisplayMode_Params& mode_param, + const gfx::Point& origin) { + DisplaySnapshot* display = ndd_->FindDisplaySnapshot(id); + if (!display) { + LOG(ERROR) << "There is no display with ID " << id; + return; + } + + const DisplayMode* mode = NULL; + for (size_t i = 0; i < display->modes().size(); ++i) { + if (mode_param.size == display->modes()[i]->size() && + mode_param.is_interlaced == display->modes()[i]->is_interlaced() && + mode_param.refresh_rate == display->modes()[i]->refresh_rate()) { + mode = display->modes()[i]; + break; + } + } + + if (!mode) { + LOG(ERROR) << "Failed to find mode: size=" << mode_param.size.ToString() + << " is_interlaced=" << mode_param.is_interlaced + << " refresh_rate=" << mode_param.refresh_rate; + return; + } + + ndd_->Configure(*display, mode, origin); +} + +void DisplayMessageHandler::OnDisableNativeDisplay(int64_t id) { + DisplaySnapshot* display = ndd_->FindDisplaySnapshot(id); + if (display) + ndd_->Configure(*display, NULL, gfx::Point()); + else + LOG(ERROR) << "There is no display with ID " << id; +} + +} // namespace ui diff --git a/ui/ozone/platform/dri/chromeos/display_message_handler.h b/ui/ozone/platform/dri/chromeos/display_message_handler.h new file mode 100644 index 0000000..4f67ca3 --- /dev/null +++ b/ui/ozone/platform/dri/chromeos/display_message_handler.h @@ -0,0 +1,49 @@ +// 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_DRI_CHROMEOS_DISPLAY_MESSAGE_HANDLER_H_ +#define UI_OZONE_PLATFORM_DRI_CHROMEOS_DISPLAY_MESSAGE_HANDLER_H_ + +#include "base/memory/scoped_ptr.h" +#include "ui/ozone/public/gpu_platform_support.h" + +namespace gfx { +class Point; +} + +namespace ui { + +class NativeDisplayDelegateDri; + +struct DisplayMode_Params; +struct DisplaySnapshot_Params; + +class DisplayMessageHandler : public GpuPlatformSupport { + public: + DisplayMessageHandler(scoped_ptr<NativeDisplayDelegateDri> ndd); + virtual ~DisplayMessageHandler(); + + // GpuPlatformSupport: + virtual void OnChannelEstablished(IPC::Sender* sender) OVERRIDE; + + // IPC::Listener: + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + private: + void OnForceDPMSOn(); + void OnRefreshNativeDisplays(); + void OnConfigureNativeDisplay(int64_t id, + const DisplayMode_Params& mode, + const gfx::Point& origin); + void OnDisableNativeDisplay(int64_t id); + + IPC::Sender* sender_; + scoped_ptr<NativeDisplayDelegateDri> ndd_; + + DISALLOW_COPY_AND_ASSIGN(DisplayMessageHandler); +}; + +} // namespace ui + +#endif // UI_OZONE_PLATFORM_DRI_CHROMEOS_DISPLAY_MESSAGE_HANDLER_H_ diff --git a/ui/ozone/platform/dri/chromeos/native_display_delegate_dri.cc b/ui/ozone/platform/dri/chromeos/native_display_delegate_dri.cc index f765cd3..fff9def 100644 --- a/ui/ozone/platform/dri/chromeos/native_display_delegate_dri.cc +++ b/ui/ozone/platform/dri/chromeos/native_display_delegate_dri.cc @@ -32,11 +32,21 @@ NativeDisplayDelegateDri::NativeDisplayDelegateDri( } NativeDisplayDelegateDri::~NativeDisplayDelegateDri() { - device_manager_->RemoveObserver(this); + if (device_manager_) + device_manager_->RemoveObserver(this); +} + +DisplaySnapshot* NativeDisplayDelegateDri::FindDisplaySnapshot(int64_t id) { + for (size_t i = 0; i < cached_displays_.size(); ++i) + if (cached_displays_[i]->display_id() == id) + return cached_displays_[i]; + + return NULL; } void NativeDisplayDelegateDri::Initialize() { - device_manager_->AddObserver(this); + if (device_manager_) + device_manager_->AddObserver(this); ScopedVector<HardwareDisplayControllerInfo> displays = GetAvailableDisplayControllerInfos(dri_->get_fd()); diff --git a/ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h b/ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h index 6723008..ef97014 100644 --- a/ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h +++ b/ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h @@ -27,6 +27,8 @@ class NativeDisplayDelegateDri DeviceManager* device_manager); virtual ~NativeDisplayDelegateDri(); + DisplaySnapshot* FindDisplaySnapshot(int64_t id); + // NativeDisplayDelegate overrides: virtual void Initialize() OVERRIDE; virtual void GrabServer() OVERRIDE; diff --git a/ui/ozone/platform/dri/chromeos/native_display_delegate_proxy.cc b/ui/ozone/platform/dri/chromeos/native_display_delegate_proxy.cc new file mode 100644 index 0000000..2219e4d --- /dev/null +++ b/ui/ozone/platform/dri/chromeos/native_display_delegate_proxy.cc @@ -0,0 +1,153 @@ +// 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/dri/chromeos/native_display_delegate_proxy.h" + +#include "base/logging.h" +#include "ui/display/types/chromeos/display_snapshot.h" +#include "ui/display/types/chromeos/native_display_observer.h" +#include "ui/events/ozone/device/device_event.h" +#include "ui/events/ozone/device/device_manager.h" +#include "ui/ozone/common/chromeos/display_snapshot_proxy.h" +#include "ui/ozone/common/chromeos/display_util.h" +#include "ui/ozone/common/gpu/ozone_gpu_messages.h" +#include "ui/ozone/platform/dri/gpu_platform_support_host_gbm.h" + +namespace ui { + +NativeDisplayDelegateProxy::NativeDisplayDelegateProxy( + GpuPlatformSupportHostGbm* proxy, + DeviceManager* device_manager) + : proxy_(proxy), + device_manager_(device_manager) { + proxy_->RegisterHandler(this); +} + +NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() { + if (device_manager_) + device_manager_->RemoveObserver(this); + + proxy_->UnregisterHandler(this); +} + +void NativeDisplayDelegateProxy::Initialize() { + if (device_manager_) + device_manager_->AddObserver(this); +} + +void NativeDisplayDelegateProxy::GrabServer() {} + +void NativeDisplayDelegateProxy::UngrabServer() {} + +void NativeDisplayDelegateProxy::SyncWithServer() {} + +void NativeDisplayDelegateProxy::SetBackgroundColor(uint32_t color_argb) { + NOTIMPLEMENTED(); +} + +void NativeDisplayDelegateProxy::ForceDPMSOn() { + proxy_->Send(new OzoneGpuMsg_ForceDPMSOn()); +} + +std::vector<DisplaySnapshot*> NativeDisplayDelegateProxy::GetDisplays() { + return displays_.get(); +} + +void NativeDisplayDelegateProxy::AddMode(const DisplaySnapshot& output, + const DisplayMode* mode) {} + +bool NativeDisplayDelegateProxy::Configure(const DisplaySnapshot& output, + const DisplayMode* mode, + const gfx::Point& origin) { + // TODO(dnicoara) Should handle an asynchronous response. + if (mode) + proxy_->Send(new OzoneGpuMsg_ConfigureNativeDisplay( + output.display_id(), GetDisplayModeParams(*mode), origin)); + else + proxy_->Send(new OzoneGpuMsg_DisableNativeDisplay(output.display_id())); + + return true; +} + +void NativeDisplayDelegateProxy::CreateFrameBuffer(const gfx::Size& size) {} + +bool NativeDisplayDelegateProxy::GetHDCPState(const DisplaySnapshot& output, + HDCPState* state) { + NOTIMPLEMENTED(); + return false; +} + +bool NativeDisplayDelegateProxy::SetHDCPState(const DisplaySnapshot& output, + HDCPState state) { + NOTIMPLEMENTED(); + return false; +} + +std::vector<ColorCalibrationProfile> +NativeDisplayDelegateProxy::GetAvailableColorCalibrationProfiles( + const DisplaySnapshot& output) { + NOTIMPLEMENTED(); + return std::vector<ColorCalibrationProfile>(); +} + +bool NativeDisplayDelegateProxy::SetColorCalibrationProfile( + const DisplaySnapshot& output, + ColorCalibrationProfile new_profile) { + NOTIMPLEMENTED(); + return false; +} + +void NativeDisplayDelegateProxy::AddObserver(NativeDisplayObserver* observer) { + observers_.AddObserver(observer); +} + +void NativeDisplayDelegateProxy::RemoveObserver( + NativeDisplayObserver* observer) { + observers_.RemoveObserver(observer); +} + +void NativeDisplayDelegateProxy::OnDeviceEvent(const DeviceEvent& event) { + if (event.device_type() != DeviceEvent::DISPLAY) + return; + + if (event.action_type() == DeviceEvent::CHANGE) { + VLOG(1) << "Got display changed event"; + proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays()); + } +} + +void NativeDisplayDelegateProxy::OnChannelEstablished( + int host_id, IPC::Sender* sender) { + // Force an initial configure such that the browser process can get the actual + // state. + proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays()); +} + +void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) { +} + +bool NativeDisplayDelegateProxy::OnMessageReceived( + const IPC::Message& message) { + bool handled = true; + + IPC_BEGIN_MESSAGE_MAP(NativeDisplayDelegateProxy, message) + IPC_MESSAGE_HANDLER(OzoneHostMsg_UpdateNativeDisplays, + OnUpdateNativeDisplays) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled; +} + +void NativeDisplayDelegateProxy::OnUpdateNativeDisplays( + const std::vector<DisplaySnapshot_Params>& displays) { + displays_.clear(); + for (size_t i = 0; i < displays.size(); ++i) + displays_.push_back(new DisplaySnapshotProxy(displays[i])); + + FOR_EACH_OBSERVER( + NativeDisplayObserver, observers_, OnConfigurationChanged()); +} + +} // namespace ui diff --git a/ui/ozone/platform/dri/chromeos/native_display_delegate_proxy.h b/ui/ozone/platform/dri/chromeos/native_display_delegate_proxy.h new file mode 100644 index 0000000..19e5ff7 --- /dev/null +++ b/ui/ozone/platform/dri/chromeos/native_display_delegate_proxy.h @@ -0,0 +1,81 @@ +// 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_DRI_CHROMEOS_NATIVE_DISPLAY_DELEGATE_PROXY_H_ +#define UI_OZONE_PLATFORM_DRI_CHROMEOS_NATIVE_DISPLAY_DELEGATE_PROXY_H_ + +#include "base/macros.h" +#include "base/memory/scoped_vector.h" +#include "base/observer_list.h" +#include "ui/display/types/chromeos/native_display_delegate.h" +#include "ui/events/ozone/device/device_event_observer.h" +#include "ui/ozone/public/gpu_platform_support_host.h" + +namespace ui { + +class DeviceManager; +class GpuPlatformSupportHostGbm; + +struct DisplaySnapshot_Params; + +class NativeDisplayDelegateProxy : public NativeDisplayDelegate, + public DeviceEventObserver, + public GpuPlatformSupportHost { + public: + NativeDisplayDelegateProxy(GpuPlatformSupportHostGbm* proxy, + DeviceManager* device_manager); + virtual ~NativeDisplayDelegateProxy(); + + // NativeDisplayDelegate overrides: + virtual void Initialize() OVERRIDE; + virtual void GrabServer() OVERRIDE; + virtual void UngrabServer() OVERRIDE; + virtual void SyncWithServer() OVERRIDE; + virtual void SetBackgroundColor(uint32_t color_argb) OVERRIDE; + virtual void ForceDPMSOn() OVERRIDE; + virtual std::vector<DisplaySnapshot*> GetDisplays() OVERRIDE; + virtual void AddMode(const DisplaySnapshot& output, + const DisplayMode* mode) OVERRIDE; + virtual bool Configure(const DisplaySnapshot& output, + const DisplayMode* mode, + const gfx::Point& origin) OVERRIDE; + virtual void CreateFrameBuffer(const gfx::Size& size) OVERRIDE; + virtual bool GetHDCPState(const DisplaySnapshot& output, + HDCPState* state) OVERRIDE; + virtual bool SetHDCPState(const DisplaySnapshot& output, + HDCPState state) OVERRIDE; + virtual std::vector<ColorCalibrationProfile> + GetAvailableColorCalibrationProfiles( + const DisplaySnapshot& output) OVERRIDE; + virtual bool SetColorCalibrationProfile( + const DisplaySnapshot& output, + ColorCalibrationProfile new_profile) OVERRIDE; + virtual void AddObserver(NativeDisplayObserver* observer) OVERRIDE; + virtual void RemoveObserver(NativeDisplayObserver* observer) OVERRIDE; + + // DeviceEventObserver overrides: + virtual void OnDeviceEvent(const DeviceEvent& event) OVERRIDE; + + // GpuPlatformSupportHost: + virtual void OnChannelEstablished(int host_id, IPC::Sender* sender) OVERRIDE; + virtual void OnChannelDestroyed(int host_id) OVERRIDE; + + // IPC::Listener overrides: + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + private: + void OnUpdateNativeDisplays( + const std::vector<DisplaySnapshot_Params>& displays); + + GpuPlatformSupportHostGbm* proxy_; // Not owned. + DeviceManager* device_manager_; // Not owned. + ScopedVector<DisplaySnapshot> displays_; + ObserverList<NativeDisplayObserver> observers_; + + DISALLOW_COPY_AND_ASSIGN(NativeDisplayDelegateProxy); +}; + +} // namespace ui + +#endif // UI_OZONE_PLATFORM_DRI_CHROMEOS_NATIVE_DISPLAY_DELEGATE_PROXY_H_ diff --git a/ui/ozone/platform/dri/gbm.gypi b/ui/ozone/platform/dri/gbm.gypi index b73a8b2..1261bfa 100644 --- a/ui/ozone/platform/dri/gbm.gypi +++ b/ui/ozone/platform/dri/gbm.gypi @@ -31,6 +31,10 @@ 'sources': [ 'buffer_data.cc', 'buffer_data.h', + 'chromeos/display_message_handler.cc', + 'chromeos/display_message_handler.h', + 'chromeos/native_display_delegate_proxy.cc', + 'chromeos/native_display_delegate_proxy.h', 'gbm_buffer.cc', 'gbm_buffer.h', 'gbm_surface.cc', diff --git a/ui/ozone/platform/dri/gpu_platform_support_gbm.cc b/ui/ozone/platform/dri/gpu_platform_support_gbm.cc index 70c99f4..051538e 100644 --- a/ui/ozone/platform/dri/gpu_platform_support_gbm.cc +++ b/ui/ozone/platform/dri/gpu_platform_support_gbm.cc @@ -14,8 +14,17 @@ GpuPlatformSupportGbm::GpuPlatformSupportGbm(DriSurfaceFactory* dri) : sender_(NULL), dri_(dri) { } +GpuPlatformSupportGbm::~GpuPlatformSupportGbm() {} + +void GpuPlatformSupportGbm::AddHandler(scoped_ptr<GpuPlatformSupport> handler) { + handlers_.push_back(handler.release()); +} + void GpuPlatformSupportGbm::OnChannelEstablished(IPC::Sender* sender) { sender_ = sender; + + for (size_t i = 0; i < handlers_.size(); ++i) + handlers_[i]->OnChannelEstablished(sender); } bool GpuPlatformSupportGbm::OnMessageReceived(const IPC::Message& message) { @@ -27,7 +36,12 @@ bool GpuPlatformSupportGbm::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_UNHANDLED(handled = false); IPC_END_MESSAGE_MAP() - return handled; + if (!handled) + for (size_t i = 0; i < handlers_.size(); ++i) + if (handlers_[i]->OnMessageReceived(message)) + return true; + + return false; } void GpuPlatformSupportGbm::OnCursorSet(gfx::AcceleratedWidget widget, diff --git a/ui/ozone/platform/dri/gpu_platform_support_gbm.h b/ui/ozone/platform/dri/gpu_platform_support_gbm.h index 28066d43..ce547e4 100644 --- a/ui/ozone/platform/dri/gpu_platform_support_gbm.h +++ b/ui/ozone/platform/dri/gpu_platform_support_gbm.h @@ -5,6 +5,8 @@ #ifndef UI_OZONE_PLATFORM_DRI_GPU_PLATFORM_SUPPORT_GBM_H_ #define UI_OZONE_PLATFORM_DRI_GPU_PLATFORM_SUPPORT_GBM_H_ +#include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" #include "ui/gfx/native_widget_types.h" #include "ui/ozone/public/gpu_platform_support.h" @@ -21,6 +23,9 @@ class DriSurfaceFactory; class GpuPlatformSupportGbm : public GpuPlatformSupport { public: GpuPlatformSupportGbm(DriSurfaceFactory* dri); + virtual ~GpuPlatformSupportGbm(); + + void AddHandler(scoped_ptr<GpuPlatformSupport> handler); // GpuPlatformSupport: virtual void OnChannelEstablished(IPC::Sender* sender) OVERRIDE; @@ -37,6 +42,7 @@ class GpuPlatformSupportGbm : public GpuPlatformSupport { void OnCursorMove(gfx::AcceleratedWidget widget, const gfx::Point& location); DriSurfaceFactory* dri_; + ScopedVector<GpuPlatformSupport> handlers_; }; } // namespace ui diff --git a/ui/ozone/platform/dri/gpu_platform_support_host_gbm.cc b/ui/ozone/platform/dri/gpu_platform_support_host_gbm.cc index 39478bd..4f0394a 100644 --- a/ui/ozone/platform/dri/gpu_platform_support_host_gbm.cc +++ b/ui/ozone/platform/dri/gpu_platform_support_host_gbm.cc @@ -4,6 +4,7 @@ #include "ui/ozone/platform/dri/gpu_platform_support_host_gbm.h" +#include "ui/ozone/common/gpu/ozone_gpu_message_params.h" #include "ui/ozone/common/gpu/ozone_gpu_messages.h" namespace ui { @@ -12,10 +13,28 @@ GpuPlatformSupportHostGbm::GpuPlatformSupportHostGbm() : host_id_(-1), sender_(NULL) { } +GpuPlatformSupportHostGbm::~GpuPlatformSupportHostGbm() {} + +void GpuPlatformSupportHostGbm::RegisterHandler( + GpuPlatformSupportHost* handler) { + handlers_.push_back(handler); +} + +void GpuPlatformSupportHostGbm::UnregisterHandler( + GpuPlatformSupportHost* handler) { + std::vector<GpuPlatformSupportHost*>::iterator it = + std::find(handlers_.begin(), handlers_.end(), handler); + if (it != handlers_.end()) + handlers_.erase(it); +} + void GpuPlatformSupportHostGbm::OnChannelEstablished(int host_id, IPC::Sender* sender) { host_id_ = host_id; sender_ = sender; + + for (size_t i = 0; i < handlers_.size(); ++i) + handlers_[i]->OnChannelEstablished(host_id, sender); } void GpuPlatformSupportHostGbm::OnChannelDestroyed(int host_id) { @@ -23,9 +42,23 @@ void GpuPlatformSupportHostGbm::OnChannelDestroyed(int host_id) { host_id_ = -1; sender_ = NULL; } + + for (size_t i = 0; i < handlers_.size(); ++i) + handlers_[i]->OnChannelDestroyed(host_id); } bool GpuPlatformSupportHostGbm::OnMessageReceived(const IPC::Message& message) { + for (size_t i = 0; i < handlers_.size(); ++i) + if (handlers_[i]->OnMessageReceived(message)) + return true; + + return false; +} + +bool GpuPlatformSupportHostGbm::Send(IPC::Message* message) { + if (sender_) + return sender_->Send(message); + return false; } diff --git a/ui/ozone/platform/dri/gpu_platform_support_host_gbm.h b/ui/ozone/platform/dri/gpu_platform_support_host_gbm.h index 6463413..6f60b9e 100644 --- a/ui/ozone/platform/dri/gpu_platform_support_host_gbm.h +++ b/ui/ozone/platform/dri/gpu_platform_support_host_gbm.h @@ -5,6 +5,8 @@ #ifndef UI_OZONE_PLATFORM_DRI_GPU_PLATFORM_SUPPORT_HOST_GBM_H_ #define UI_OZONE_PLATFORM_DRI_GPU_PLATFORM_SUPPORT_HOST_GBM_H_ +#include <vector> + #include "ui/gfx/native_widget_types.h" #include "ui/ozone/platform/dri/hardware_cursor_delegate.h" #include "ui/ozone/public/gpu_platform_support_host.h" @@ -18,9 +20,14 @@ class Point; namespace ui { class GpuPlatformSupportHostGbm : public GpuPlatformSupportHost, - public HardwareCursorDelegate { + public HardwareCursorDelegate, + public IPC::Sender { public: GpuPlatformSupportHostGbm(); + virtual ~GpuPlatformSupportHostGbm(); + + void RegisterHandler(GpuPlatformSupportHost* handler); + void UnregisterHandler(GpuPlatformSupportHost* handler); // GpuPlatformSupportHost: virtual void OnChannelEstablished(int host_id, IPC::Sender* sender) OVERRIDE; @@ -29,6 +36,9 @@ class GpuPlatformSupportHostGbm : public GpuPlatformSupportHost, // IPC::Listener: virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + // IPC::Sender: + virtual bool Send(IPC::Message* message) OVERRIDE; + // HardwareCursorDelegate: virtual void SetHardwareCursor(gfx::AcceleratedWidget widget, const SkBitmap& bitmap, @@ -39,6 +49,7 @@ class GpuPlatformSupportHostGbm : public GpuPlatformSupportHost, private: int host_id_; IPC::Sender* sender_; + std::vector<GpuPlatformSupportHost*> handlers_; }; } // namespace ui diff --git a/ui/ozone/platform/dri/ozone_platform_gbm.cc b/ui/ozone/platform/dri/ozone_platform_gbm.cc index 1ffd179..e80cb79e 100644 --- a/ui/ozone/platform/dri/ozone_platform_gbm.cc +++ b/ui/ozone/platform/dri/ozone_platform_gbm.cc @@ -26,8 +26,10 @@ #include "ui/ozone/public/gpu_platform_support_host.h" #if defined(OS_CHROMEOS) -#include "ui/ozone/common/chromeos/native_display_delegate_ozone.h" #include "ui/ozone/common/chromeos/touchscreen_device_manager_ozone.h" +#include "ui/ozone/platform/dri/chromeos/display_message_handler.h" +#include "ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h" +#include "ui/ozone/platform/dri/chromeos/native_display_delegate_proxy.h" #endif namespace ui { @@ -92,7 +94,8 @@ class OzonePlatformGbm : public OzonePlatform { #if defined(OS_CHROMEOS) virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() OVERRIDE { - return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateOzone()); + return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateProxy( + gpu_platform_support_host_.get(), device_manager_.get())); } virtual scoped_ptr<TouchscreenDeviceManager> CreateTouchscreenDeviceManager() OVERRIDE { @@ -128,6 +131,14 @@ class OzonePlatformGbm : public OzonePlatform { gpu_platform_support_.reset( new GpuPlatformSupportGbm(surface_factory_ozone_.get())); +#if defined(OS_CHROMEOS) + gpu_platform_support_->AddHandler(scoped_ptr<GpuPlatformSupport>( + new DisplayMessageHandler( + scoped_ptr<NativeDisplayDelegateDri>(new NativeDisplayDelegateDri( + dri_.get(), + screen_manager_.get(), + NULL))))); +#endif } private: |