OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ui/ozone/platform/dri/chromeos/display_message_handler.h" |
| 6 |
| 7 #include "ui/display/types/chromeos/display_mode.h" |
| 8 #include "ui/display/types/chromeos/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" |
| 13 |
| 14 namespace ui { |
| 15 |
| 16 DisplayMessageHandler::DisplayMessageHandler( |
| 17 scoped_ptr<NativeDisplayDelegateDri> ndd) |
| 18 : sender_(NULL), |
| 19 ndd_(ndd.Pass()) {} |
| 20 |
| 21 DisplayMessageHandler::~DisplayMessageHandler() {} |
| 22 |
| 23 void DisplayMessageHandler::OnChannelEstablished(IPC::Sender* sender) { |
| 24 sender_ = sender; |
| 25 } |
| 26 |
| 27 bool DisplayMessageHandler::OnMessageReceived(const IPC::Message& message) { |
| 28 bool handled = true; |
| 29 |
| 30 IPC_BEGIN_MESSAGE_MAP(DisplayMessageHandler, message) |
| 31 IPC_MESSAGE_HANDLER(OzoneGpuMsg_ForceDPMSOn, OnForceDPMSOn) |
| 32 IPC_MESSAGE_HANDLER(OzoneGpuMsg_RefreshNativeDisplays, |
| 33 OnRefreshNativeDisplays) |
| 34 IPC_MESSAGE_HANDLER(OzoneGpuMsg_ConfigureNativeDisplay, |
| 35 OnConfigureNativeDisplay) |
| 36 IPC_MESSAGE_HANDLER(OzoneGpuMsg_DisableNativeDisplay, |
| 37 OnDisableNativeDisplay) |
| 38 IPC_MESSAGE_UNHANDLED(handled = false); |
| 39 IPC_END_MESSAGE_MAP() |
| 40 |
| 41 return handled; |
| 42 } |
| 43 |
| 44 void DisplayMessageHandler::OnForceDPMSOn() { |
| 45 ndd_->ForceDPMSOn(); |
| 46 } |
| 47 |
| 48 void DisplayMessageHandler::OnRefreshNativeDisplays() { |
| 49 std::vector<DisplaySnapshot_Params> displays; |
| 50 std::vector<DisplaySnapshot*> native_displays = ndd_->GetDisplays(); |
| 51 for (size_t i = 0; i < native_displays.size(); ++i) |
| 52 displays.push_back(GetDisplaySnapshotParams(*native_displays[i])); |
| 53 |
| 54 sender_->Send(new OzoneHostMsg_UpdateNativeDisplays(displays)); |
| 55 } |
| 56 |
| 57 void DisplayMessageHandler::OnConfigureNativeDisplay( |
| 58 int64_t id, |
| 59 const DisplayMode_Params& mode_param, |
| 60 const gfx::Point& origin) { |
| 61 DisplaySnapshot* display = ndd_->FindDisplaySnapshot(id); |
| 62 if (!display) { |
| 63 LOG(ERROR) << "There is no display with ID " << id; |
| 64 return; |
| 65 } |
| 66 |
| 67 const DisplayMode* mode = NULL; |
| 68 for (size_t i = 0; i < display->modes().size(); ++i) { |
| 69 if (mode_param.size == display->modes()[i]->size() && |
| 70 mode_param.is_interlaced == display->modes()[i]->is_interlaced() && |
| 71 mode_param.refresh_rate == display->modes()[i]->refresh_rate()) { |
| 72 mode = display->modes()[i]; |
| 73 break; |
| 74 } |
| 75 } |
| 76 |
| 77 if (!mode) { |
| 78 LOG(ERROR) << "Failed to find mode: size=" << mode_param.size.ToString() |
| 79 << " is_interlaced=" << mode_param.is_interlaced |
| 80 << " refresh_rate=" << mode_param.refresh_rate; |
| 81 return; |
| 82 } |
| 83 |
| 84 ndd_->Configure(*display, mode, origin); |
| 85 } |
| 86 |
| 87 void DisplayMessageHandler::OnDisableNativeDisplay(int64_t id) { |
| 88 DisplaySnapshot* display = ndd_->FindDisplaySnapshot(id); |
| 89 if (display) |
| 90 ndd_->Configure(*display, NULL, gfx::Point()); |
| 91 else |
| 92 LOG(ERROR) << "There is no display with ID " << id; |
| 93 } |
| 94 |
| 95 } // namespace ui |
OLD | NEW |