- add sources.
[platform/framework/web/crosswalk.git] / src / ozone / wayland / screen.cc
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Copyright 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #include "ozone/wayland/screen.h"
7
8 #include <wayland-client.h>
9
10 #include "ozone/impl/ozone_display.h"
11 #include "ozone/wayland/display.h"
12
13 namespace ozonewayland {
14
15 WaylandScreen::WaylandScreen(WaylandDisplay* display, uint32_t id)
16     : output_(NULL) {
17   static const wl_output_listener kOutputListener = {
18     WaylandScreen::OutputHandleGeometry,
19     WaylandScreen::OutputHandleMode,
20   };
21
22   output_ = static_cast<wl_output*>(
23       wl_registry_bind(display->registry(), id, &wl_output_interface, 1));
24   wl_output_add_listener(output_, &kOutputListener, this);
25 }
26
27 WaylandScreen::~WaylandScreen() {
28   if (output_)
29     wl_output_destroy(output_);
30 }
31
32 // static
33 void WaylandScreen::OutputHandleGeometry(void *data,
34                                          wl_output *output,
35                                          int32_t x,
36                                          int32_t y,
37                                          int32_t physical_width,
38                                          int32_t physical_height,
39                                          int32_t subpixel,
40                                          const char* make,
41                                          const char* model,
42                                          int32_t output_transform) {
43   WaylandScreen* screen = static_cast<WaylandScreen*>(data);
44   gfx::Point point = gfx::Point(x, y);
45   screen->rect_.set_origin(point);
46 }
47
48 // static
49 void WaylandScreen::OutputHandleMode(void* data,
50                                      wl_output* wl_output,
51                                      uint32_t flags,
52                                      int32_t width,
53                                      int32_t height,
54                                      int32_t refresh) {
55   WaylandScreen* screen = static_cast<WaylandScreen*>(data);
56   if (flags & WL_OUTPUT_MODE_CURRENT) {
57       screen->rect_.set_width(width);
58       screen->rect_.set_height(height);
59       screen->refresh_ = refresh;
60       OzoneDisplay::GetInstance()->OnOutputSizeChanged(screen, width, height);
61   }
62 }
63
64 }  // namespace ozonewayland