OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "main.h" | 5 #include "main.h" |
6 #include "xlib_window.h" | 6 #include "xlib_window.h" |
| 7 #include "base/logging.h" |
7 | 8 |
8 | 9 |
9 Display *xlib_display = NULL; | 10 Display *xlib_display = NULL; |
10 Window xlib_window = 0; | 11 Window xlib_window = 0; |
| 12 XVisualInfo *xlib_visinfo = NULL; |
11 | 13 |
12 GLint g_width = 512; | 14 GLint g_width = 512; |
13 GLint g_height = 512; | 15 GLint g_height = 512; |
14 bool g_override_redirect = true; | 16 bool g_override_redirect = true; |
15 | 17 |
16 | 18 |
17 bool XlibInit() { | 19 bool XlibInit() { |
18 xlib_display = ::XOpenDisplay(0); | 20 xlib_display = XOpenDisplay(0); |
19 if (!xlib_display) | 21 if (!xlib_display) |
20 return false; | 22 return false; |
21 | 23 |
22 int screen = DefaultScreen(xlib_display); | 24 int screen = DefaultScreen(xlib_display); |
23 Window root_window = RootWindow(xlib_display, screen); | 25 Window root_window = RootWindow(xlib_display, screen); |
24 | 26 |
25 XWindowAttributes attributes; | 27 XWindowAttributes attributes; |
26 XGetWindowAttributes(xlib_display, root_window, &attributes); | 28 XGetWindowAttributes(xlib_display, root_window, &attributes); |
27 | 29 |
28 g_width = g_width == -1 ? attributes.width : g_width; | 30 g_width = g_width == -1 ? attributes.width : g_width; |
29 g_height = g_height == -1 ? attributes.height : g_height; | 31 g_height = g_height == -1 ? attributes.height : g_height; |
30 | 32 |
31 int attrib[] = { | 33 XVisualInfo vinfo_template; |
32 GLX_RGBA, | 34 memset(&vinfo_template, sizeof(vinfo_template), 0); |
33 GLX_DOUBLEBUFFER, 1, | 35 vinfo_template.visualid = GetVisualID(); |
34 GLX_RED_SIZE, 1, | 36 int nitems; |
35 GLX_GREEN_SIZE, 1, | 37 xlib_visinfo = XGetVisualInfo(xlib_display, |
36 GLX_BLUE_SIZE, 1, | 38 VisualIDMask, &vinfo_template, &nitems); |
37 GLX_DEPTH_SIZE, 1, | 39 CHECK(nitems == 1); |
38 GLX_STENCIL_SIZE, 1, | 40 |
39 None | |
40 }; | |
41 XVisualInfo *visinfo = glXChooseVisual(xlib_display, screen, attrib); | |
42 unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | | 41 unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | |
43 CWOverrideRedirect; | 42 CWOverrideRedirect; |
44 XSetWindowAttributes attr; | 43 XSetWindowAttributes attr; |
45 attr.background_pixel = 0; | 44 attr.background_pixel = 0; |
46 attr.border_pixel = 0; | 45 attr.border_pixel = 0; |
47 attr.colormap = XCreateColormap(xlib_display, root_window, visinfo->visual, | 46 attr.colormap = XCreateColormap(xlib_display, root_window, |
48 AllocNone); | 47 xlib_visinfo->visual, AllocNone); |
49 attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; | 48 attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; |
50 attr.override_redirect = g_override_redirect ? True : False; | 49 attr.override_redirect = g_override_redirect ? True : False; |
51 xlib_window = ::XCreateWindow(xlib_display, root_window, | 50 xlib_window = XCreateWindow(xlib_display, root_window, |
52 0, 0, g_width, g_height, 0, visinfo->depth, | 51 0, 0, g_width, g_height, 0, xlib_visinfo->depth, |
53 InputOutput, visinfo->visual, mask, &attr); | 52 InputOutput, xlib_visinfo->visual, mask, &attr); |
54 | 53 |
55 ::XMapWindow(xlib_display, xlib_window); | 54 XMapWindow(xlib_display, xlib_window); |
56 ::XSync(xlib_display, True); | 55 XSync(xlib_display, True); |
57 | 56 |
58 ::XGetWindowAttributes(xlib_display, xlib_window, &attributes); | 57 XGetWindowAttributes(xlib_display, xlib_window, &attributes); |
59 g_width = attributes.width; | 58 g_width = attributes.width; |
60 g_height = attributes.height; | 59 g_height = attributes.height; |
61 | 60 |
62 return true; | 61 return true; |
63 } | 62 } |
64 | |
65 | |
OLD | NEW |