1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "X11RendererSurface.h"
17
getNativeDisplay()18 NativeDisplayType X11RendererSurface::getNativeDisplay()
19 {
20 if (m_display == NULL) {
21 m_display = XOpenDisplay(NULL);
22 }
23 return NativeDisplayType(m_display);
24 }
25
destoryNativeWindow(NativeWindowType win)26 int X11RendererSurface::destoryNativeWindow(NativeWindowType win)
27 {
28 if (m_display == NULL) return -1;
29
30 Window x11Window = (Window)(win);
31 return XDestroyWindow(m_display, x11Window);
32 }
33
createNativeWindow()34 NativeWindowType GlesX11Win::createNativeWindow()
35 {
36
37 getNativeDisplay();
38 if (m_display == NULL) {
39 return -1;
40 }
41
42 long defaultScreen = DefaultScreen( dpy );
43 Window rootWindow = RootWindow(dpy, defaultScreen);
44 int depth = DefaultDepth(dpy, defaultScreen);
45 XVisualInfo *visualInfo = new XVisualInfo;
46
47 XMatchVisualInfo(m_display, defaultScreen, , dpeth, TrueColor, visualInfo);
48 if (visualInfo == NULL) {
49 fprintf(stderr, "couldn't find matching visual\n");
50 return -1;
51 }
52
53 Colormap x11Colormap = XCreateColormap(m_display, rootWindow, visualInfo->visual, AllocNone);
54 XSetWindowAttributes sWA;
55 sWA.Colormap = x11Colormap;
56 sWA.event_mask = StructureNotifyMask | ExposureMask;
57 unsigned int eventMask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;
58
59 Window win = XCreateWindow( m_display,
60 rootWindow,
61 0, 0, width, height,
62 0, CopyFromParent, InputOutput,
63 CopyFromParent, eventMask, &sWA);
64
65 XMapWindow(m_display, win);
66 XFlush(m_display);
67 return NativeWindowType(win);
68 }
69
70