summaryrefslogtreecommitdiffstats
path: root/chromium/ui/ozone/platform/egltest/eglplatform_shim_xeleven.cc
blob: af1228d0fc0dd8f9b0b4ac18bf9d0fb9eda00ad4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2014 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 "ui/ozone/platform/egltest/eglplatform_shim.h"

#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>

#ifdef __cplusplus
extern "C" {
#endif

Display* g_display;

const int kDefaultX = 0;
const int kDefaultY = 0;
const int kDefaultWidth = 800;
const int kDefaultHeight = 600;
const int kDefaultBorderWidth = 0;

const char* ShimQueryString(int name) {
  switch (name) {
    case SHIM_EGL_LIBRARY:
      return "libEGL.so.1";
    case SHIM_GLES_LIBRARY:
      return "libGLESv2.so.2";
    default:
      return NULL;
  }
}

bool ShimInitialize(void) {
  g_display = XOpenDisplay(NULL);
  return g_display != NULL;
}

bool ShimTerminate(void) {
  XCloseDisplay(g_display);
  return true;
}

ShimNativeWindowId ShimCreateWindow(void) {
  XSetWindowAttributes swa;
  memset(&swa, 0, sizeof(swa));
  swa.event_mask = 0;

  Window window = XCreateWindow(g_display,
                                DefaultRootWindow(g_display),
                                kDefaultX,
                                kDefaultY,
                                kDefaultWidth,
                                kDefaultHeight,
                                kDefaultBorderWidth,
                                CopyFromParent,
                                InputOutput,
                                CopyFromParent,
                                CWEventMask,
                                &swa);

  XMapWindow(g_display, window);
  XStoreName(g_display, window, "EGL test");
  XFlush(g_display);

  return window;
}

bool ShimQueryWindow(ShimNativeWindowId window_id, int attribute, int* value) {
  XWindowAttributes window_attributes;
  switch (attribute) {
    case SHIM_WINDOW_WIDTH:
      XGetWindowAttributes(g_display, window_id, &window_attributes);
      *value = window_attributes.width;
      return true;
    case SHIM_WINDOW_HEIGHT:
      XGetWindowAttributes(g_display, window_id, &window_attributes);
      *value = window_attributes.height;
      return true;
    default:
      return false;
  }
}

bool ShimDestroyWindow(ShimNativeWindowId window_id) {
  XDestroyWindow(g_display, window_id);
  return true;
}

ShimEGLNativeDisplayType ShimGetNativeDisplay(void) {
  return reinterpret_cast<ShimEGLNativeDisplayType>(g_display);
}

ShimEGLNativeWindowType ShimGetNativeWindow(
    ShimNativeWindowId native_window_id) {
  return native_window_id;
}

bool ShimReleaseNativeWindow(ShimEGLNativeWindowType native_window) {
  return true;
}

#ifdef __cplusplus
}
#endif