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 "NativeSubWindow.h"
17
WaitForMapNotify(Display * d,XEvent * e,char * arg)18 static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg)
19 {
20 if (e->type == MapNotify && e->xmap.window == (Window)arg) {
21 return 1;
22 }
23 return 0;
24 }
25
26 static Display *s_display = NULL;
27
createSubWindow(FBNativeWindowType p_window,EGLNativeDisplayType * display_out,int x,int y,int width,int height)28 EGLNativeWindowType createSubWindow(FBNativeWindowType p_window,
29 EGLNativeDisplayType* display_out,
30 int x, int y,int width, int height){
31
32 // The call to this function is protected by a lock
33 // in FrameBuffer so it is safe to check and initialize s_display here
34 if (!s_display) s_display = XOpenDisplay(NULL);
35 *display_out = s_display;
36
37 XSetWindowAttributes wa;
38 wa.event_mask = StructureNotifyMask;
39 Window win = XCreateWindow(*display_out,p_window,x,y, width,height,0,CopyFromParent,CopyFromParent,CopyFromParent,CWEventMask,&wa);
40 XMapWindow(*display_out,win);
41 XEvent e;
42 XIfEvent(*display_out, &e, WaitForMapNotify, (char *)win);
43 return win;
44 }
45
destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win)46 void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win){
47 XDestroyWindow(dis, win);
48 }
49