| Index: ui/wayland/wayland_display.cc
|
| diff --git a/ui/wayland/wayland_display.cc b/ui/wayland/wayland_display.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e7a8429ea032a128460e2dd31250ed668a1e2531
|
| --- /dev/null
|
| +++ b/ui/wayland/wayland_display.cc
|
| @@ -0,0 +1,164 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "wayland_display.h"
|
| +
|
| +#include "wayland_buffer.h"
|
| +#include "wayland_input_device.h"
|
| +#include "wayland_screen.h"
|
| +#include "wayland_window.h"
|
| +
|
| +#include <stdio.h>
|
| +#include <string.h>
|
| +#include <wayland-client.h>
|
| +
|
| +// static
|
| +WaylandDisplay* WaylandDisplay::Connect(char* name) {
|
| + static WaylandDisplay *display = NULL;
|
| + if (display) {
|
| + return display;
|
| + }
|
| +
|
| + display = new WaylandDisplay(name);
|
| + if (!display->display_) {
|
| + delete display;
|
| + display = NULL;
|
| + return NULL;
|
| + }
|
| +
|
| + wl_display_add_global_listener(display->display_,
|
| + WaylandDisplay::DisplayHandleGlobal,
|
| + display);
|
| + wl_display_iterate(display->display_, WL_DISPLAY_READABLE);
|
| +
|
| + return display;
|
| +}
|
| +
|
| +WaylandDisplay::WaylandDisplay(char* name) : display_(NULL),
|
| + compositor_(NULL),
|
| + shell_(NULL),
|
| + shm_(NULL),
|
| + visual_(NULL) {
|
| + display_ = wl_display_connect(name);
|
| +}
|
| +
|
| +WaylandDisplay::~WaylandDisplay() {
|
| + if (display_) {
|
| + wl_display_destroy(display_);
|
| + }
|
| + if (compositor_) {
|
| + wl_compositor_destroy(compositor_);
|
| + }
|
| + if (visual_) {
|
| + wl_visual_destroy(visual_);
|
| + }
|
| + if (shell_) {
|
| + wl_shell_destroy(shell_);
|
| + }
|
| + if (shm_) {
|
| + wl_shm_destroy(shm_);
|
| + }
|
| + for (std::list<WaylandInputDevice*>::iterator it = input_list_.begin();
|
| + it != input_list_.end(); it++) {
|
| + delete *it;
|
| + }
|
| + for (std::list<WaylandScreen*>::iterator it = screen_list_.begin();
|
| + it != screen_list_.end(); it++) {
|
| + delete *it;
|
| + }
|
| +}
|
| +
|
| +struct wl_surface* WaylandDisplay::CreateSurface() {
|
| + return wl_compositor_create_surface(compositor_);
|
| +}
|
| +
|
| +void WaylandDisplay::SetCursor(WaylandBuffer* buffer,
|
| + int32_t x, int32_t y) {
|
| + for (std::list<WaylandInputDevice*>::iterator it = input_list_.begin();
|
| + it != input_list_.end(); it++) {
|
| + (*it)->Attach(buffer->GetBuffer(), x, y);
|
| + }
|
| +}
|
| +
|
| +struct wl_display* WaylandDisplay::GetNativeDisplay() const {
|
| + return display_;
|
| +}
|
| +
|
| +std::list<WaylandScreen*> WaylandDisplay::GetScreenList() const {
|
| + return screen_list_;
|
| +}
|
| +
|
| +struct wl_shell* WaylandDisplay::GetShell() const {
|
| + return shell_;
|
| +}
|
| +
|
| +struct wl_shm* WaylandDisplay::GetShm() const {
|
| + return shm_;
|
| +}
|
| +
|
| +struct wl_visual* WaylandDisplay::GetVisual() const {
|
| + return visual_;
|
| +}
|
| +
|
| +// static
|
| +void WaylandDisplay::DisplayHandleGlobal(struct wl_display* display,
|
| + uint32_t id,
|
| + const char* interface,
|
| + uint32_t version,
|
| + void* data) {
|
| + WaylandDisplay* disp = static_cast<WaylandDisplay*>(data);
|
| +
|
| + static const struct wl_compositor_listener compositor_listener = {
|
| + WaylandDisplay::CompositorHandleVisual,
|
| + };
|
| + static const struct wl_shell_listener shell_listener = {
|
| + WaylandDisplay::ShellHandleConfigure,
|
| + };
|
| +
|
| + //fprintf(stderr, "Processing: %s\n", interface);
|
| + if (strcmp(interface, "wl_compositor") == 0) {
|
| + disp->compositor_ = wl_compositor_create(display, id, 1);
|
| + wl_compositor_add_listener(disp->compositor_,
|
| + &compositor_listener,
|
| + disp);
|
| + } else if (strcmp(interface, "wl_output") == 0) {
|
| + WaylandScreen* screen = new WaylandScreen(disp, id);
|
| + disp->screen_list_.push_back(screen);
|
| + } else if (strcmp(interface, "wl_input_device") == 0) {
|
| + WaylandInputDevice *input_device = new WaylandInputDevice(display, id);
|
| + disp->input_list_.push_back(input_device);
|
| + } else if (strcmp(interface, "wl_shell") == 0) {
|
| + disp->shell_ = wl_shell_create(display, id, 1);
|
| + wl_shell_add_listener(disp->shell_, &shell_listener, disp);
|
| + } else if (strcmp(interface, "wl_shm") == 0) {
|
| + disp->shm_ = wl_shm_create(display, id, 1);
|
| + }
|
| +}
|
| +
|
| +// static
|
| +void WaylandDisplay::CompositorHandleVisual(void* data,
|
| + struct wl_compositor* compositor,
|
| + uint32_t id,
|
| + uint32_t token) {
|
| + WaylandDisplay* display = static_cast<WaylandDisplay*>(data);
|
| +
|
| + switch (token) {
|
| + case WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32:
|
| + display->visual_ = wl_visual_create(display->display_, id, 1);
|
| + break;
|
| + }
|
| +}
|
| +
|
| +// static
|
| +void WaylandDisplay::ShellHandleConfigure(void* data,
|
| + struct wl_shell* shell,
|
| + uint32_t time,
|
| + uint32_t edges,
|
| + struct wl_surface* surface,
|
| + int32_t width,
|
| + int32_t height) {
|
| + WaylandWindow* window = static_cast<WaylandWindow*>(
|
| + wl_surface_get_user_data(surface));
|
| + window->Configure(time, edges, 0, 0, width, height);
|
| +}
|
|
|