1 // Copyright 2013 Intel Corporation. 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 "ozone/impl/ipc/display_channel_host.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "ozone/impl/ipc/messages.h"
10 #include "ozone/impl/ozone_display.h"
11 #include "ozone/wayland/dispatcher.h"
13 namespace ozonewayland {
15 // This should be same as defined in display_channel.
16 #define CHANNEL_ROUTE_ID -0x1
18 OzoneDisplayChannelHost::OzoneDisplayChannelHost()
20 dispatcher_ = WaylandDispatcher::GetInstance();
23 OzoneDisplayChannelHost::~OzoneDisplayChannelHost() {
24 OzoneDisplay::GetInstance()->OnChannelHostDestroyed();
25 DCHECK(deferred_messages_.empty());
28 void OzoneDisplayChannelHost::EstablishChannel() {
32 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
33 base::Bind(base::IgnoreResult(&OzoneDisplayChannelHost::UpdateConnection),
37 void OzoneDisplayChannelHost::SendWidgetState(unsigned w,
41 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
42 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
43 base::Bind(&OzoneDisplayChannelHost::SendWidgetState,
44 base::Unretained(this), w, state, width, height));
48 Send(new WaylandWindow_State(CHANNEL_ROUTE_ID, w, state, width, height));
51 void OzoneDisplayChannelHost::SendWidgetAttributes(unsigned widget,
56 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
57 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
58 base::Bind(&OzoneDisplayChannelHost::SendWidgetAttributes,
59 base::Unretained(this), widget, parent, x, y, type));
63 Send(new WaylandWindow_Attributes(CHANNEL_ROUTE_ID,
71 void OzoneDisplayChannelHost::SendWidgetTitle(
72 unsigned w, const string16& title) {
73 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
74 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
75 base::Bind(&OzoneDisplayChannelHost::SendWidgetTitle,
76 base::Unretained(this), w, title));
80 Send(new WaylandWindow_Title(CHANNEL_ROUTE_ID, w, title));
83 void OzoneDisplayChannelHost::OnChannelEstablished() {
85 Send(new WaylandMsg_DisplayChannelEstablished(CHANNEL_ROUTE_ID));
86 while (!deferred_messages_.empty()) {
87 Send(deferred_messages_.front());
88 deferred_messages_.pop();
92 void OzoneDisplayChannelHost::OnMotionNotify(float x, float y) {
93 dispatcher_->MotionNotify(x, y);
96 void OzoneDisplayChannelHost::OnButtonNotify(unsigned handle,
101 dispatcher_->ButtonNotify(handle, state, flags, x, y);
104 void OzoneDisplayChannelHost::OnAxisNotify(float x,
108 dispatcher_->AxisNotify(x, y, xoffset, yoffset);
111 void OzoneDisplayChannelHost::OnPointerEnter(unsigned handle,
114 dispatcher_->PointerEnter(handle, x, y);
117 void OzoneDisplayChannelHost::OnPointerLeave(unsigned handle,
120 dispatcher_->PointerLeave(handle, x, y);
123 void OzoneDisplayChannelHost::OnKeyNotify(unsigned type,
125 unsigned modifiers) {
126 dispatcher_->KeyNotify(type, code, modifiers);
129 void OzoneDisplayChannelHost::OnOutputSizeChanged(unsigned width,
131 OzoneDisplay::GetInstance()->OnOutputSizeChanged(width, height);
134 bool OzoneDisplayChannelHost::OnMessageReceived(const IPC::Message& message) {
135 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) <<
136 "Must handle messages that were dispatched to another thread!";
139 IPC_BEGIN_MESSAGE_MAP(OzoneDisplayChannelHost, message)
140 IPC_MESSAGE_HANDLER(WaylandInput_MotionNotify, OnMotionNotify)
141 IPC_MESSAGE_HANDLER(WaylandInput_ButtonNotify, OnButtonNotify)
142 IPC_MESSAGE_HANDLER(WaylandInput_AxisNotify, OnAxisNotify)
143 IPC_MESSAGE_HANDLER(WaylandInput_PointerEnter, OnPointerEnter)
144 IPC_MESSAGE_HANDLER(WaylandInput_PointerLeave, OnPointerLeave)
145 IPC_MESSAGE_HANDLER(WaylandInput_KeyNotify, OnKeyNotify)
146 IPC_MESSAGE_HANDLER(WaylandInput_OutputSize, OnOutputSizeChanged)
147 IPC_MESSAGE_UNHANDLED(handled = false)
148 IPC_END_MESSAGE_MAP()
153 void OzoneDisplayChannelHost::OnFilterAdded(IPC::Channel* channel) {
157 void OzoneDisplayChannelHost::OnChannelClosing() {
161 bool OzoneDisplayChannelHost::Send(IPC::Message* message) {
163 deferred_messages_.push(message);
167 // Callee takes ownership of message, regardless of whether Send is
168 // successful. See IPC::Sender.
169 scoped_ptr<IPC::Message> scoped_message(message);
170 return channel_->Send(scoped_message.release());
173 void OzoneDisplayChannelHost::UpdateConnection() {
174 content::GpuProcessHost* host = content::GpuProcessHost::Get(
175 content::GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
176 content::CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP);
179 host->AddFilter(this);
180 OnChannelEstablished();
183 } // namespace ozonewayland