1 /*****************************************************************
2  * gmerlin - a general purpose multimedia framework and applications
3  *
4  * Copyright (c) 2001 - 2011 Members of the Gmerlin project
5  * gmerlin-general@lists.sourceforge.net
6  * http://gmerlin.sourceforge.net
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  * *****************************************************************/
21 
22 #include <gmerlin/parameter.h>
23 #include <gmerlin/accelerator.h>
24 #include <gavl/gavl.h>
25 
26 /* Min- Max values for Hue, Saturation, Brightness and Contrast */
27 
28 #define BG_BRIGHTNESS_MIN  -10.0
29 #define BG_BRIGHTNESS_MAX   10.0
30 #define BG_BRIGHTNESS_DELTA  0.5
31 
32 #define BG_SATURATION_MIN    -10.0
33 #define BG_SATURATION_MAX     10.0
34 #define BG_SATURATION_DELTA    0.5
35 
36 #define BG_CONTRAST_MIN      -10.0
37 #define BG_CONTRAST_MAX       10.0
38 #define BG_CONTRAST_DELTA      0.5
39 
40 typedef struct
41   {
42   const bg_accelerator_map_t * accel_map;
43   int (*accel_callback)(void * data, int accel);
44 
45   int (*key_callback)(void * data, int key, int mask);
46   int (*key_release_callback)(void * data, int key, int mask);
47 
48   int (*button_callback)(void * data, int x, int y, int button, int mask);
49   int (*button_release_callback)(void * data, int x, int y, int button, int mask);
50   int (*motion_callback)(void * data, int x, int y, int mask);
51 
52   void (*size_changed)(void * data, int width, int height);
53   void (*set_fullscreen)(void * data, int fullscreen);
54 
55   void * data;
56   } bg_x11_window_callbacks_t;
57 
58 /* OpenGL display attributes (see bg_x11_window_set_gl_attribute()) */
59 
60 #define BG_GL_ATTRIBUTE_BUFFER_SIZE       0 /**< Depth of the color buffer. */
61 #define BG_GL_ATTRIBUTE_LEVEL             1 /**< Level in plane stacking. */
62 #define BG_GL_ATTRIBUTE_RGBA              2 /**< True if RGBA mode. */
63 #define BG_GL_ATTRIBUTE_DOUBLEBUFFER      3 /**< Double buffering supported. */
64 #define BG_GL_ATTRIBUTE_STEREO            4 /**< Stereo buffering supported. */
65 #define BG_GL_ATTRIBUTE_AUX_BUFFERS       5 /**< Number of aux buffers. */
66 #define BG_GL_ATTRIBUTE_RED_SIZE          6 /**< Number of red component bits. */
67 #define BG_GL_ATTRIBUTE_GREEN_SIZE        7 /**< Number of green component bits. */
68 #define BG_GL_ATTRIBUTE_BLUE_SIZE         8 /**< Number of blue component bits. */
69 #define BG_GL_ATTRIBUTE_ALPHA_SIZE        9 /**< Number of alpha component bits. */
70 #define BG_GL_ATTRIBUTE_DEPTH_SIZE       10 /**< Number of depth bits. */
71 #define BG_GL_ATTRIBUTE_STENCIL_SIZE     11 /**< Number of stencil bits. */
72 #define BG_GL_ATTRIBUTE_ACCUM_RED_SIZE   12 /**< Number of red accum bits. */
73 #define BG_GL_ATTRIBUTE_ACCUM_GREEN_SIZE 13 /**< Number of green accum bits. */
74 #define BG_GL_ATTRIBUTE_ACCUM_BLUE_SIZE  14 /**< Number of blue accum bits. */
75 #define BG_GL_ATTRIBUTE_ACCUM_ALPHA_SIZE 15 /**< Number of alpha accum bits. */
76 #define BG_GL_ATTRIBUTE_NUM              16 /* Must be last and highest */
77 
78 typedef struct bg_x11_window_s bg_x11_window_t;
79 
80 bg_x11_window_t * bg_x11_window_create(const char * display_string);
81 
82 /* For attribute artgument see BG_GL_ATTRIBUTE_ above */
83 void bg_x11_window_set_gl_attribute(bg_x11_window_t * win, int attribute, int value);
84 
85 const char * bg_x11_window_get_display_string(bg_x11_window_t * w);
86 
87 void bg_x11_window_destroy(bg_x11_window_t *);
88 
89 const bg_parameter_info_t * bg_x11_window_get_parameters(bg_x11_window_t *);
90 
91 void
92 bg_x11_window_set_parameter(void * data, const char * name,
93                             const bg_parameter_value_t * val);
94 int
95 bg_x11_window_get_parameter(void * data, const char * name,
96                             bg_parameter_value_t * val);
97 
98 
99 void bg_x11_window_set_size(bg_x11_window_t *, int width, int height);
100 
101 void bg_x11_window_clear(bg_x11_window_t *);
102 
103 int bg_x11_window_realize(bg_x11_window_t *);
104 
105 /* Handle X11 events, callbacks are called from here */
106 void bg_x11_window_set_callbacks(bg_x11_window_t*, bg_x11_window_callbacks_t*);
107 void bg_x11_window_handle_events(bg_x11_window_t*, int milliseconds);
108 
109 
110 int bg_x11_window_set_fullscreen(bg_x11_window_t * w,int fullscreen);
111 void bg_x11_window_set_title(bg_x11_window_t * w, const char * title);
112 void bg_x11_window_set_options(bg_x11_window_t * w,
113                                const char * name, const char * klass,
114                                const gavl_video_frame_t * icon,
115                                const gavl_video_format_t * icon_format);
116 
117 void bg_x11_window_show(bg_x11_window_t * w, int show);
118 
119 void bg_x11_window_resize(bg_x11_window_t * win, int width, int height);
120 void bg_x11_window_get_size(bg_x11_window_t * win, int * width, int * height);
121 
122 
123 /*
124  *   All opengl calls must be enclosed by x11_window_set_gl() and
125  *   x11_window_unset_gl()
126  */
127 
128 void bg_x11_window_set_gl(bg_x11_window_t *);
129 void bg_x11_window_unset_gl(bg_x11_window_t *);
130 
131 int bg_x11_window_start_gl(bg_x11_window_t * win);
132 void bg_x11_window_stop_gl(bg_x11_window_t * win);
133 
134 
135 /*
136  *  Swap buffers and make your rendered work visible
137  */
138 void bg_x11_window_swap_gl(bg_x11_window_t *);
139 
140 void bg_x11_window_cleanup_gl(bg_x11_window_t *);
141 
142 /* For Video output */
143 
144 int bg_x11_window_open_video(bg_x11_window_t*, gavl_video_format_t * format);
145 
146 int bg_x11_window_add_overlay_stream(bg_x11_window_t*,
147                                      gavl_video_format_t * format);
148 
149 void bg_x11_window_set_overlay(bg_x11_window_t*, int stream, gavl_overlay_t * ovl);
150 
151 gavl_overlay_t * bg_x11_window_create_overlay(bg_x11_window_t*, int);
152 void bg_x11_window_destroy_overlay(bg_x11_window_t*, int, gavl_overlay_t *);
153 
154 gavl_video_frame_t * bg_x11_window_create_frame(bg_x11_window_t*);
155 void bg_x11_window_destroy_frame(bg_x11_window_t*, gavl_video_frame_t *);
156 
157 void bg_x11_window_set_rectangles(bg_x11_window_t * w,
158                                   gavl_rectangle_f_t * src_rect,
159                                   gavl_rectangle_i_t * dst_rect);
160 
161 int bg_x11_window_set_brightness(bg_x11_window_t*, float val);
162 int bg_x11_window_set_saturation(bg_x11_window_t*, float val);
163 int bg_x11_window_set_contrast(bg_x11_window_t*, float val);
164 
165 void bg_x11_window_put_frame(bg_x11_window_t*, gavl_video_frame_t * frame);
166 void bg_x11_window_put_still(bg_x11_window_t*, gavl_video_frame_t * frame);
167 
168 void bg_x11_window_close_video(bg_x11_window_t*);
169 
170 /* Grab window */
171 
172 typedef struct bg_x11_grab_window_s bg_x11_grab_window_t;
173 
174 const bg_parameter_info_t * bg_x11_grab_window_get_parameters(bg_x11_grab_window_t * win);
175 
176 void bg_x11_grab_window_set_parameter(void * data, const char * name,
177                                       const bg_parameter_value_t * val);
178 
179 int bg_x11_grab_window_get_parameter(void * data, const char * name,
180                                      bg_parameter_value_t * val);
181 
182 
183 bg_x11_grab_window_t * bg_x11_grab_window_create();
184 void bg_x11_grab_window_destroy(bg_x11_grab_window_t *);
185 
186 int bg_x11_grab_window_init(bg_x11_grab_window_t *, gavl_video_format_t * format);
187 int bg_x11_grab_window_grab(bg_x11_grab_window_t *, gavl_video_frame_t  * frame);
188 void bg_x11_grab_window_close(bg_x11_grab_window_t * win);
189