- add sources.
[platform/framework/web/crosswalk.git] / src / ozone / impl / ipc / display_channel.cc
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.
4
5 #include "ozone/impl/ipc/display_channel.h"
6
7 #include "content/child/child_process.h"
8 #include "content/child/child_thread.h"
9 #include "ozone/impl/ipc/messages.h"
10 #include "ozone/impl/ozone_display.h"
11
12 namespace ozonewayland {
13 // GpuChannelManager generates unique routeid for every new
14 // ImageTransportSurface. In Ozone-Wayland, we register a routeid between
15 // DisplayChannel and ChannelHost. Therefore, we hardcore our own routeid with a
16 // unique negitive value to avoid any conflicts from the GpuChannelManager ones.
17 #define WAYLAND_ROUTE_ID -0x1
18
19 namespace {
20
21 content::ChildThread* GetProcessMainThread() {
22   content::ChildProcess* process = content::ChildProcess::current();
23   DCHECK(process && process->main_thread());
24   return process->main_thread();
25 }
26
27 }
28
29 OzoneDisplayChannel::OzoneDisplayChannel() {
30 }
31
32 OzoneDisplayChannel::~OzoneDisplayChannel() {
33   content::ChildThread* thread = GetProcessMainThread();
34   if (thread)
35     thread->RemoveRoute(WAYLAND_ROUTE_ID);
36 }
37
38 bool OzoneDisplayChannel::OnMessageReceived(
39     const IPC::Message& message) {
40   bool handled = true;
41   IPC_BEGIN_MESSAGE_MAP(OzoneDisplayChannel, message)
42   IPC_MESSAGE_HANDLER(WaylandMsg_DisplayChannelEstablished, OnEstablishChannel)
43   IPC_MESSAGE_HANDLER(WaylandWindow_State, OnWidgetStateChanged)
44   IPC_MESSAGE_HANDLER(WaylandWindow_Attributes, OnWidgetAttributesChanged)
45   IPC_MESSAGE_HANDLER(WaylandWindow_Title, OnWidgetTitleChanged)
46   IPC_MESSAGE_UNHANDLED(handled = false)
47   IPC_END_MESSAGE_MAP()
48
49   return handled;
50 }
51
52 void OzoneDisplayChannel::OnEstablishChannel() {
53   OzoneDisplay::GetInstance()->OnChannelEstablished();
54 }
55
56 void OzoneDisplayChannel::Register() {
57   content::ChildThread* thread = GetProcessMainThread();
58   thread->AddRoute(WAYLAND_ROUTE_ID, this);
59 }
60
61 void OzoneDisplayChannel::OnWidgetStateChanged(unsigned handleid,
62                                                unsigned state,
63                                                unsigned width,
64                                                unsigned height) {
65   OzoneDisplay::GetInstance()->OnWidgetStateChanged(handleid,
66                                                     state,
67                                                     width,
68                                                     height);
69 }
70
71 void OzoneDisplayChannel::OnWidgetTitleChanged(unsigned widget,
72                                                string16 title) {
73   OzoneDisplay::GetInstance()->OnWidgetTitleChanged(widget, title);
74 }
75
76 void OzoneDisplayChannel::OnWidgetAttributesChanged(unsigned widget,
77                                                     unsigned parent,
78                                                     unsigned x,
79                                                     unsigned y,
80                                                     unsigned type) {
81   OzoneDisplay::GetInstance()->OnWidgetAttributesChanged(widget,
82                                                          parent,
83                                                          x,
84                                                          y,
85                                                          type);
86 }
87
88 }  // namespace ozonewayland