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.
6 #include "ozone/wayland/window.h"
8 #include "base/logging.h"
9 #include "ozone/wayland/display.h"
10 #include "ozone/wayland/egl/egl_window.h"
11 #include "ozone/wayland/shell_surface.h"
12 #include "ozone/wayland/surface.h"
14 namespace ozonewayland {
16 WaylandWindow::WaylandWindow(unsigned handle) : shell_surface_(NULL),
20 allocation_(gfx::Rect(0, 0, 1, 1)) {
23 WaylandWindow::~WaylandWindow() {
24 wl_surface_set_user_data(GetSurface(), 0);
31 delete shell_surface_;
32 shell_surface_ = NULL;
36 void WaylandWindow::SetShellAttributes(ShellType type) {
40 if (!shell_surface_) {
41 shell_surface_ = new WaylandShellSurface(this);
42 wl_surface_set_user_data(GetSurface(), this);
46 shell_surface_->UpdateShellSurface(type_, NULL, 0, 0);
49 void WaylandWindow::SetShellAttributes(ShellType type,
50 WaylandShellSurface* shell_parent,
53 DCHECK(shell_parent && (type == TRANSIENT));
55 if (!shell_surface_) {
56 shell_surface_ = new WaylandShellSurface(this);
57 wl_surface_set_user_data(GetSurface(), this);
61 shell_surface_->UpdateShellSurface(type_, shell_parent, x, y);
64 void WaylandWindow::SetWindowTitle(const string16& title) {
65 shell_surface_->SetWindowTitle(title);
68 void WaylandWindow::Maximize() {
72 void WaylandWindow::Minimize() {
76 void WaylandWindow::Restore() {
80 void WaylandWindow::ToggleFullscreen() {
81 if (type_ == FULLSCREEN)
82 SetShellAttributes(TOPLEVEL);
84 SetShellAttributes(FULLSCREEN);
87 void WaylandWindow::RealizeAcceleratedWidget() {
88 if (!shell_surface_) {
89 LOG(ERROR) << "Shell type not set. Setting it to TopLevel";
90 SetShellAttributes(TOPLEVEL);
94 window_ = new EGLWindow(shell_surface_->Surface()->wlSurface(),
95 allocation_.width(), allocation_.height());
98 void WaylandWindow::HandleSwapBuffers() {
99 shell_surface_->Surface()->EnsureFrameCallBackDone();
100 shell_surface_->Surface()->AddFrameCallBack();
103 wl_egl_window* WaylandWindow::egl_window() const {
104 return window_ ? window_->egl_window() : 0;
107 struct wl_surface* WaylandWindow::GetSurface() const {
108 return shell_surface_ ? shell_surface_->Surface()->wlSurface() : 0;
111 bool WaylandWindow::SetBounds(const gfx::Rect& new_bounds) {
112 int width = new_bounds.width();
113 int height = new_bounds.height();
114 allocation_ = gfx::Rect(allocation_.x(), allocation_.y(), width, height);
115 if (!shell_surface_ || !window_)
118 return window_->Resize(shell_surface_->Surface(), width, height);
121 } // namespace ozonewayland