Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: ui/ozone/platform/dri/dri_gpu_platform_support.cc

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/dri_gpu_platform_support.h"
6
7 #include "ipc/ipc_message_macros.h"
8 #include "ui/display/types/display_mode.h"
9 #include "ui/display/types/display_snapshot.h"
10 #include "ui/ozone/common/display_util.h"
11 #include "ui/ozone/common/gpu/ozone_gpu_message_params.h"
12 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
13 #include "ui/ozone/platform/dri/dri_surface_factory.h"
14 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h"
15 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h"
16 #include "ui/ozone/platform/dri/native_display_delegate_dri.h"
17
18 namespace ui {
19
20 namespace {
21
22 class FindDisplayById {
23 public:
24 FindDisplayById(int64_t display_id) : display_id_(display_id) {}
25
26 bool operator()(const DisplaySnapshot_Params& display) const {
27 return display.display_id == display_id_;
28 }
29
30 private:
31 int64_t display_id_;
32 };
33
34 } // namespace
35
36 DriGpuPlatformSupport::DriGpuPlatformSupport(
37 DriSurfaceFactory* dri,
38 DriWindowDelegateManager* window_manager,
39 ScreenManager* screen_manager,
40 scoped_ptr<NativeDisplayDelegateDri> ndd)
41 : sender_(NULL),
42 dri_(dri),
43 window_manager_(window_manager),
44 screen_manager_(screen_manager),
45 ndd_(ndd.Pass()) {
46 }
47
48 DriGpuPlatformSupport::~DriGpuPlatformSupport() {
49 }
50
51 void DriGpuPlatformSupport::AddHandler(scoped_ptr<GpuPlatformSupport> handler) {
52 handlers_.push_back(handler.release());
53 }
54
55 void DriGpuPlatformSupport::OnChannelEstablished(IPC::Sender* sender) {
56 sender_ = sender;
57
58 for (size_t i = 0; i < handlers_.size(); ++i)
59 handlers_[i]->OnChannelEstablished(sender);
60 }
61
62 bool DriGpuPlatformSupport::OnMessageReceived(const IPC::Message& message) {
63 bool handled = true;
64
65 IPC_BEGIN_MESSAGE_MAP(DriGpuPlatformSupport, message)
66 IPC_MESSAGE_HANDLER(OzoneGpuMsg_CreateWindowDelegate, OnCreateWindowDelegate)
67 IPC_MESSAGE_HANDLER(OzoneGpuMsg_DestroyWindowDelegate,
68 OnDestroyWindowDelegate)
69 IPC_MESSAGE_HANDLER(OzoneGpuMsg_WindowBoundsChanged, OnWindowBoundsChanged)
70
71 IPC_MESSAGE_HANDLER(OzoneGpuMsg_CursorSet, OnCursorSet)
72 IPC_MESSAGE_HANDLER(OzoneGpuMsg_CursorMove, OnCursorMove)
73
74 IPC_MESSAGE_HANDLER(OzoneGpuMsg_ForceDPMSOn, OnForceDPMSOn)
75 IPC_MESSAGE_HANDLER(OzoneGpuMsg_RefreshNativeDisplays,
76 OnRefreshNativeDisplays)
77 IPC_MESSAGE_HANDLER(OzoneGpuMsg_ConfigureNativeDisplay,
78 OnConfigureNativeDisplay)
79 IPC_MESSAGE_HANDLER(OzoneGpuMsg_DisableNativeDisplay, OnDisableNativeDisplay)
80 IPC_MESSAGE_UNHANDLED(handled = false);
81 IPC_END_MESSAGE_MAP()
82
83 if (!handled)
84 for (size_t i = 0; i < handlers_.size(); ++i)
85 if (handlers_[i]->OnMessageReceived(message))
86 return true;
87
88 return false;
89 }
90
91 void DriGpuPlatformSupport::OnCreateWindowDelegate(
92 gfx::AcceleratedWidget widget) {
93 // Due to how the GPU process starts up this IPC call may happen after the IPC
94 // to create a surface. Since a surface wants to know the window associated
95 // with it, we create it ahead of time. So when this call happens we do not
96 // create a delegate if it already exists.
97 if (!window_manager_->HasWindowDelegate(widget)) {
98 scoped_ptr<DriWindowDelegate> delegate(
99 new DriWindowDelegateImpl(widget, screen_manager_));
100 delegate->Initialize();
101 window_manager_->AddWindowDelegate(widget, delegate.Pass());
102 }
103 }
104
105 void DriGpuPlatformSupport::OnDestroyWindowDelegate(
106 gfx::AcceleratedWidget widget) {
107 scoped_ptr<DriWindowDelegate> delegate =
108 window_manager_->RemoveWindowDelegate(widget);
109 delegate->Shutdown();
110 }
111
112 void DriGpuPlatformSupport::OnWindowBoundsChanged(gfx::AcceleratedWidget widget,
113 const gfx::Rect& bounds) {
114 window_manager_->GetWindowDelegate(widget)->OnBoundsChanged(bounds);
115 }
116
117 void DriGpuPlatformSupport::OnCursorSet(gfx::AcceleratedWidget widget,
118 const std::vector<SkBitmap>& bitmaps,
119 const gfx::Point& location,
120 int frame_delay_ms) {
121 dri_->SetHardwareCursor(widget, bitmaps, location, frame_delay_ms);
122 }
123
124 void DriGpuPlatformSupport::OnCursorMove(gfx::AcceleratedWidget widget,
125 const gfx::Point& location) {
126 dri_->MoveHardwareCursor(widget, location);
127 }
128
129 void DriGpuPlatformSupport::OnForceDPMSOn() {
130 ndd_->ForceDPMSOn();
131 }
132
133 void DriGpuPlatformSupport::OnRefreshNativeDisplays(
134 const std::vector<DisplaySnapshot_Params>& cached_displays) {
135 std::vector<DisplaySnapshot_Params> displays;
136 std::vector<DisplaySnapshot*> native_displays = ndd_->GetDisplays();
137
138 // If any of the cached displays are in the list of new displays then apply
139 // their configuration immediately.
140 for (size_t i = 0; i < native_displays.size(); ++i) {
141 std::vector<DisplaySnapshot_Params>::const_iterator it =
142 std::find_if(cached_displays.begin(),
143 cached_displays.end(),
144 FindDisplayById(native_displays[i]->display_id()));
145
146 if (it == cached_displays.end())
147 continue;
148
149 if (it->has_current_mode)
150 OnConfigureNativeDisplay(it->display_id, it->current_mode, it->origin);
151 else
152 OnDisableNativeDisplay(it->display_id);
153 }
154
155 for (size_t i = 0; i < native_displays.size(); ++i)
156 displays.push_back(GetDisplaySnapshotParams(*native_displays[i]));
157
158 sender_->Send(new OzoneHostMsg_UpdateNativeDisplays(displays));
159 }
160
161 void DriGpuPlatformSupport::OnConfigureNativeDisplay(
162 int64_t id,
163 const DisplayMode_Params& mode_param,
164 const gfx::Point& origin) {
165 DisplaySnapshot* display = ndd_->FindDisplaySnapshot(id);
166 if (!display) {
167 LOG(ERROR) << "There is no display with ID " << id;
168 return;
169 }
170
171 const DisplayMode* mode = NULL;
172 for (size_t i = 0; i < display->modes().size(); ++i) {
173 if (mode_param.size == display->modes()[i]->size() &&
174 mode_param.is_interlaced == display->modes()[i]->is_interlaced() &&
175 mode_param.refresh_rate == display->modes()[i]->refresh_rate()) {
176 mode = display->modes()[i];
177 break;
178 }
179 }
180
181 // If the display doesn't have the mode natively, then lookup the mode from
182 // other displays and try using it on the current display (some displays
183 // support panel fitting and they can use different modes even if the mode
184 // isn't explicitly declared).
185 if (!mode)
186 mode = ndd_->FindDisplayMode(
187 mode_param.size, mode_param.is_interlaced, mode_param.refresh_rate);
188
189 if (!mode) {
190 LOG(ERROR) << "Failed to find mode: size=" << mode_param.size.ToString()
191 << " is_interlaced=" << mode_param.is_interlaced
192 << " refresh_rate=" << mode_param.refresh_rate;
193 return;
194 }
195
196 ndd_->Configure(*display, mode, origin);
197 }
198
199 void DriGpuPlatformSupport::OnDisableNativeDisplay(int64_t id) {
200 DisplaySnapshot* display = ndd_->FindDisplaySnapshot(id);
201 if (display)
202 ndd_->Configure(*display, NULL, gfx::Point());
203 else
204 LOG(ERROR) << "There is no display with ID " << id;
205 }
206
207 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/dri_gpu_platform_support.h ('k') | ui/ozone/platform/dri/dri_gpu_platform_support_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698