OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. 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 "ui/ozone/platform/egltest/eglplatform_shim.h" | |
6 | |
7 #include <string.h> | |
8 #include <X11/Xlib.h> | |
9 #include <X11/Xatom.h> | |
10 #include <X11/Xutil.h> | |
11 | |
12 #ifdef __cplusplus | |
13 extern "C" { | |
14 #endif | |
15 | |
16 Display* g_display; | |
17 | |
18 const int kDefaultX = 0; | |
19 const int kDefaultY = 0; | |
20 const int kDefaultWidth = 1280; | |
21 const int kDefaultHeight = 720; | |
22 const int kDefaultBorderWidth = 0; | |
23 | |
24 const char* ShimQueryString(int name) { | |
25 switch (name) { | |
26 case SHIM_EGL_LIBRARY: | |
27 return "libEGL.so.1"; | |
28 case SHIM_GLES_LIBRARY: | |
29 return "libGLESv2.so.2"; | |
30 default: | |
31 return NULL; | |
32 } | |
33 } | |
34 | |
35 bool ShimInitialize(void) { | |
36 g_display = XOpenDisplay(NULL); | |
37 return g_display != NULL; | |
38 } | |
39 | |
40 bool ShimTerminate(void) { | |
41 XCloseDisplay(g_display); | |
42 return true; | |
43 } | |
44 | |
45 ShimNativeWindowId ShimCreateWindow(void) { | |
46 XSetWindowAttributes swa; | |
47 memset(&swa, 0, sizeof(swa)); | |
48 swa.event_mask = 0; | |
49 | |
50 Window window = XCreateWindow(g_display, | |
51 DefaultRootWindow(g_display), | |
52 kDefaultX, | |
53 kDefaultY, | |
54 kDefaultWidth, | |
55 kDefaultHeight, | |
56 kDefaultBorderWidth, | |
57 CopyFromParent, | |
58 InputOutput, | |
59 CopyFromParent, | |
60 CWEventMask, | |
61 &swa); | |
62 | |
63 XMapWindow(g_display, window); | |
64 XStoreName(g_display, window, "EGL test"); | |
65 XFlush(g_display); | |
66 | |
67 return window; | |
68 } | |
69 | |
70 bool ShimQueryWindow(ShimNativeWindowId window_id, int attribute, int* value) { | |
71 XWindowAttributes window_attributes; | |
72 switch (attribute) { | |
73 case SHIM_WINDOW_WIDTH: | |
74 XGetWindowAttributes(g_display, window_id, &window_attributes); | |
75 *value = window_attributes.width; | |
76 return true; | |
77 case SHIM_WINDOW_HEIGHT: | |
78 XGetWindowAttributes(g_display, window_id, &window_attributes); | |
79 *value = window_attributes.height; | |
80 return true; | |
81 default: | |
82 return false; | |
83 } | |
84 } | |
85 | |
86 bool ShimDestroyWindow(ShimNativeWindowId window_id) { | |
87 XDestroyWindow(g_display, window_id); | |
88 return true; | |
89 } | |
90 | |
91 ShimEGLNativeDisplayType ShimGetNativeDisplay(void) { | |
92 return reinterpret_cast<ShimEGLNativeDisplayType>(g_display); | |
93 } | |
94 | |
95 ShimEGLNativeWindowType ShimGetNativeWindow( | |
96 ShimNativeWindowId native_window_id) { | |
97 return native_window_id; | |
98 } | |
99 | |
100 bool ShimReleaseNativeWindow(ShimEGLNativeWindowType native_window) { | |
101 return true; | |
102 } | |
103 | |
104 #ifdef __cplusplus | |
105 } | |
106 #endif | |
OLD | NEW |