1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/dri/chromeos/display_message_handler.h"
7 #include "ui/display/types/display_mode.h"
8 #include "ui/display/types/display_snapshot.h"
9 #include "ui/ozone/common/chromeos/display_util.h"
10 #include "ui/ozone/common/gpu/ozone_gpu_message_params.h"
11 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
12 #include "ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h"
18 class FindDisplayById {
20 FindDisplayById(int64_t display_id) : display_id_(display_id) {}
22 bool operator()(const DisplaySnapshot_Params& display) const {
23 return display.display_id == display_id_;
32 DisplayMessageHandler::DisplayMessageHandler(
33 scoped_ptr<NativeDisplayDelegateDri> ndd)
37 DisplayMessageHandler::~DisplayMessageHandler() {}
39 void DisplayMessageHandler::OnChannelEstablished(IPC::Sender* sender) {
43 bool DisplayMessageHandler::OnMessageReceived(const IPC::Message& message) {
46 IPC_BEGIN_MESSAGE_MAP(DisplayMessageHandler, message)
47 IPC_MESSAGE_HANDLER(OzoneGpuMsg_ForceDPMSOn, OnForceDPMSOn)
48 IPC_MESSAGE_HANDLER(OzoneGpuMsg_RefreshNativeDisplays,
49 OnRefreshNativeDisplays)
50 IPC_MESSAGE_HANDLER(OzoneGpuMsg_ConfigureNativeDisplay,
51 OnConfigureNativeDisplay)
52 IPC_MESSAGE_HANDLER(OzoneGpuMsg_DisableNativeDisplay,
53 OnDisableNativeDisplay)
54 IPC_MESSAGE_UNHANDLED(handled = false);
60 void DisplayMessageHandler::OnForceDPMSOn() {
64 void DisplayMessageHandler::OnRefreshNativeDisplays(
65 const std::vector<DisplaySnapshot_Params>& cached_displays) {
66 std::vector<DisplaySnapshot_Params> displays;
67 std::vector<DisplaySnapshot*> native_displays = ndd_->GetDisplays();
69 // If any of the cached displays are in the list of new displays then apply
70 // their configuration immediately.
71 for (size_t i = 0; i < native_displays.size(); ++i) {
72 std::vector<DisplaySnapshot_Params>::const_iterator it =
73 std::find_if(cached_displays.begin(),
74 cached_displays.end(),
75 FindDisplayById(native_displays[i]->display_id()));
77 if (it == cached_displays.end())
80 if (it->has_current_mode)
81 OnConfigureNativeDisplay(it->display_id, it->current_mode, it->origin);
83 OnDisableNativeDisplay(it->display_id);
86 for (size_t i = 0; i < native_displays.size(); ++i)
87 displays.push_back(GetDisplaySnapshotParams(*native_displays[i]));
89 sender_->Send(new OzoneHostMsg_UpdateNativeDisplays(displays));
92 void DisplayMessageHandler::OnConfigureNativeDisplay(
94 const DisplayMode_Params& mode_param,
95 const gfx::Point& origin) {
96 DisplaySnapshot* display = ndd_->FindDisplaySnapshot(id);
98 LOG(ERROR) << "There is no display with ID " << id;
102 const DisplayMode* mode = NULL;
103 for (size_t i = 0; i < display->modes().size(); ++i) {
104 if (mode_param.size == display->modes()[i]->size() &&
105 mode_param.is_interlaced == display->modes()[i]->is_interlaced() &&
106 mode_param.refresh_rate == display->modes()[i]->refresh_rate()) {
107 mode = display->modes()[i];
112 // If the display doesn't have the mode natively, then lookup the mode from
113 // other displays and try using it on the current display (some displays
114 // support panel fitting and they can use different modes even if the mode
115 // isn't explicitly declared).
117 mode = ndd_->FindDisplayMode(mode_param.size,
118 mode_param.is_interlaced,
119 mode_param.refresh_rate);
122 LOG(ERROR) << "Failed to find mode: size=" << mode_param.size.ToString()
123 << " is_interlaced=" << mode_param.is_interlaced
124 << " refresh_rate=" << mode_param.refresh_rate;
128 ndd_->Configure(*display, mode, origin);
131 void DisplayMessageHandler::OnDisableNativeDisplay(int64_t id) {
132 DisplaySnapshot* display = ndd_->FindDisplaySnapshot(id);
134 ndd_->Configure(*display, NULL, gfx::Point());
136 LOG(ERROR) << "There is no display with ID " << id;