Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / ozone / wayland / ozone_hardware_display.cc
1 // Copyright 2014 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/wayland/ozone_hardware_display.h"
6
7 #include "ozone/wayland/display.h"
8
9 namespace ozonewayland {
10
11 OzoneHardwareDisplay::OzoneHardwareDisplay() : native_display_(NULL) {
12   gfx::OzoneDisplay::SetInstance(this);
13 }
14
15 OzoneHardwareDisplay::~OzoneHardwareDisplay() {
16   Terminate();
17   gfx::OzoneDisplay::SetInstance(NULL);
18 }
19
20 gfx::SurfaceFactoryOzone::HardwareState
21 OzoneHardwareDisplay::InitializeHardware() {
22   if (!native_display_) {
23     native_display_ = new WaylandDisplay(WaylandDisplay::RegisterAsNeeded);
24     if (!native_display_->display()) {
25       delete native_display_;
26       native_display_ = NULL;
27       LOG(ERROR) << "SurfaceFactoryWayland failed to initialize hardware";
28       return gfx::SurfaceFactoryOzone::FAILED;
29     }
30   }
31
32   return gfx::SurfaceFactoryOzone::INITIALIZED;
33 }
34
35 void OzoneHardwareDisplay::ShutdownHardware() {
36   Terminate();
37 }
38
39 intptr_t OzoneHardwareDisplay::GetNativeDisplay() {
40   return (intptr_t)native_display_->display();
41 }
42
43 void OzoneHardwareDisplay::FlushDisplay() {
44   DCHECK(native_display_);
45   native_display_->FlushDisplay();
46 }
47
48 gfx::AcceleratedWidget OzoneHardwareDisplay::GetAcceleratedWidget() {
49   static int opaque_handle = 0;
50   opaque_handle++;
51   ui::WindowStateChangeHandler::GetInstance()->SetWidgetState(opaque_handle,
52                                                               ui::CREATE,
53                                                               0,
54                                                               0);
55
56   return (gfx::AcceleratedWidget)opaque_handle;
57 }
58
59 gfx::AcceleratedWidget OzoneHardwareDisplay::RealizeAcceleratedWidget(
60     gfx::AcceleratedWidget w) {
61   DCHECK(native_display_);
62   return (gfx::AcceleratedWidget)native_display_->RealizeAcceleratedWidget(w);
63 }
64
65 bool OzoneHardwareDisplay::AttemptToResizeAcceleratedWidget(
66     gfx::AcceleratedWidget w, const gfx::Rect& bounds) {
67     ui::WindowStateChangeHandler::GetInstance()->SetWidgetState(
68         w, ui::RESIZE, bounds.width(), bounds.height());
69
70     return true;
71 }
72
73 void OzoneHardwareDisplay::DestroyWidget(gfx::AcceleratedWidget w) {
74   ui::WindowStateChangeHandler::GetInstance()->SetWidgetState(w,
75                                                               ui::DESTROYED);
76 }
77
78 void OzoneHardwareDisplay::LookAheadOutputGeometry() {
79   WaylandDisplay::LookAheadOutputGeometry();
80 }
81
82 void OzoneHardwareDisplay::Terminate() {
83   delete native_display_;
84 }
85
86 }  // namespace ozonewayland