1 /*
2  *					GPAC Multimedia Framework
3  *
4  *			Authors: Jean Le Feuvre
5  *			Copyright (c) Telecom ParisTech 2005-2020
6  *					All rights reserved
7  *
8  *  This file is part of GPAC / X11 video output module
9  *
10  *  GPAC is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU Lesser General Public License as published by
12  *  the Free Software Foundation; either version 2, or (at your option)
13  *  any later version.
14  *
15  *  GPAC is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU Lesser General Public License for more details.
19  *
20  *  You should have received a copy of the GNU Lesser General Public
21  *  License along with this library; see the file COPYING.  If not, write to
22  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  */
25 #ifndef _X11_OUT_H
26 #define _X11_OUT_H
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 
34 #include <gpac/modules/video_out.h>
35 #include <gpac/thread.h>
36 #include <gpac/list.h>
37 
38 #include <X11/Xlib.h>
39 #include <X11/Xutil.h>
40 #include <X11/keysym.h>
41 
42 #if !defined(GPAC_DISABLE_3D) && !defined(GPAC_USE_GLES1X) && !defined(GPAC_USE_TINYGL)
43 #define GPAC_HAS_OPENGL
44 #endif
45 
46 #ifdef GPAC_HAS_OPENGL
47 #include <GL/glx.h>
48 #endif
49 
50 #ifdef GPAC_HAS_X11_SHM
51 #include <X11/extensions/XShm.h>
52 #include <sys/ipc.h>
53 #include <sys/shm.h>
54 #endif
55 
56 #ifdef GPAC_HAS_X11_XV
57 #include <X11/extensions/Xv.h>
58 #include <X11/extensions/Xvlib.h>
59 #endif
60 
61 #if defined(ENABLE_JOYSTICK) || defined(ENABLE_JOYSTICK_NO_CURSOR)
62 #include <linux/joystick.h>
63 #include <unistd.h>
64 #include <fcntl.h>
65 #endif
66 
67 #define X11VID()	XWindow *xWindow = (XWindow *)vout->opaque;
68 
69 #define RGB555(r,g,b) (((r&248)<<7) + ((g&248)<<2)  + (b>>3))
70 #define RGB565(r,g,b) (((r&248)<<8) + ((g&252)<<3)  + (b>>3))
71 
72 typedef struct
73 {
74 	Window par_wnd;	//main window handler passed to module, NULL otherwise
75 	Bool setup_done, no_select_input;	//setup is done
76 	Display *display;	//required by all X11 method, provide by XOpenDisplay, Mozilla wnd ...
77 	Window wnd;	//window handler created by module
78 	Window full_wnd;	//full screen
79 	Screen *screenptr;	//X11 stuff
80 	int screennum;		//...
81 	Visual *visual;		//...
82 	GC the_gc;			//graphics context
83 	XImage *surface;	//main drawing image: software mode
84 	Pixmap pixmap;
85 	u32 pwidth, pheight;
86 	u32 init_flags;
87 	Atom WM_DELETE_WINDOW;	//window deletion
88 
89 	Bool use_shared_memory;	//
90 	/*screensaver state*/
91 	int ss_t, ss_b, ss_i, ss_e;
92 
93 #ifdef GPAC_HAS_X11_SHM
94 	XShmSegmentInfo *shmseginfo;
95 #endif
96 
97 	/*YUV overlay*/
98 #ifdef GPAC_HAS_X11_XV
99 	int xvport;
100 	u32 xv_pf_format;
101 	XvImage *overlay;
102 #endif
103 
104 	char *x_data;
105 
106 	Bool is_init, fullscreen, has_focus;
107 	Bool ctrl_down, alt_down, meta_down;
108 
109 	/*backbuffer size before entering fullscreen mode (used for restore) */
110 	u32 store_width, store_height;
111 
112 	u32 w_width, w_height;
113 	u32 depth, bpp, pixel_format;
114 	Bool output_3d;
115 
116 #ifdef GPAC_HAS_OPENGL
117 	XVisualInfo *glx_visualinfo;
118 	GLXContext glx_context;
119 	Pixmap gl_pixmap;
120 	GLXPixmap gl_offscreen;
121 	Window gl_wnd;
122 	u32 offscreen_type;
123 #endif
124 #if defined(ENABLE_JOYSTICK) || defined(ENABLE_JOYSTICK_NO_CURSOR)
125 	/*joystick device file descriptor*/
126 	s32 prev_x, prev_y, fd;
127 #endif
128 } XWindow;
129 
130 void StretchBits (void *dst, u32 dst_bpp, u32 dst_w, u32 dst_h, u32 dst_pitch,
131                   void *src, u32 src_bpp, u32 src_w, u32 src_h, u32 src_pitch, Bool FlipIt);
132 
133 
134 #endif /* _X11_OUT_H */
135