1 #ifndef EVAS_ENGINE_H
2 #define EVAS_ENGINE_H
3 
4 #include "config.h"
5 #include "evas_common_private.h"
6 #include "evas_private.h"
7 #include "Evas.h"
8 #include "Evas_Engine_GL_X11.h"
9 
10 #define GL_GLEXT_PROTOTYPES
11 
12 #ifdef GL_GLES
13 # define SUPPORT_X11 1
14 # include <EGL/egl.h>
15 # include <GLES2/gl2.h>
16 # include <GLES2/gl2ext.h>
17 # include <X11/Xlib.h>
18 # include <X11/Xatom.h>
19 # include <X11/Xutil.h>
20 # include <X11/extensions/Xrender.h>
21 # include <X11/Xresource.h> // xres - dpi
22 #else
23 # include <X11/Xlib.h>
24 # include <X11/Xatom.h>
25 # include <X11/Xutil.h>
26 # include <X11/extensions/Xrender.h>
27 # include <X11/Xresource.h> // xres - dpi
28 # include <GL/gl.h>
29 # include <GL/glext.h>
30 # include <GL/glx.h>
31 #endif
32 
33 #include "../gl_generic/Evas_Engine_GL_Generic.h"
34 
35 extern int _evas_engine_GL_X11_log_dom ;
36 #ifdef ERR
37 # undef ERR
38 #endif
39 #define ERR(...) EINA_LOG_DOM_ERR(_evas_engine_GL_X11_log_dom, __VA_ARGS__)
40 
41 #ifdef DBG
42 # undef DBG
43 #endif
44 #define DBG(...) EINA_LOG_DOM_DBG(_evas_engine_GL_X11_log_dom, __VA_ARGS__)
45 
46 #ifdef INF
47 # undef INF
48 #endif
49 #define INF(...) EINA_LOG_DOM_INFO(_evas_engine_GL_X11_log_dom, __VA_ARGS__)
50 
51 #ifdef WRN
52 # undef WRN
53 #endif
54 #define WRN(...) EINA_LOG_DOM_WARN(_evas_engine_GL_X11_log_dom, __VA_ARGS__)
55 
56 #ifdef CRI
57 # undef CRI
58 #endif
59 #define CRI(...) EINA_LOG_DOM_CRIT(_evas_engine_GL_X11_log_dom, __VA_ARGS__)
60 
61 struct _Outbuf
62 {
63 #ifdef GL_GLES
64    EGLContext       egl_context;
65    EGLSurface       egl_surface;
66    EGLConfig        egl_config;
67    EGLDisplay       egl_disp;
68 #else
69    GLXContext       context;
70    GLXWindow        glxwin;
71 #endif
72    struct {
73       unsigned char depth_buffer_size;
74       unsigned char stencil_buffer_size;
75       unsigned char msaa;
76 #ifndef GL_GLES
77       Eina_Bool     loose_binding : 1;
78 #else
79       Eina_Bool     no_multi_buffer_native : 1;
80 #endif
81    } detected;
82 
83 
84    Evas            *evas;
85    Display         *disp;
86    XVisualInfo     *visualinfo;
87    Visual          *visual;
88    int              depth_bits;
89    int              stencil_bits;
90    int              msaa_bits;
91    Evas_Engine_GL_Context *gl_context;
92    Evas_Engine_Info_GL_X11 *info;
93 
94    Render_Output_Swap_Mode swap_mode;
95    Colormap         colormap;
96    Window           win;
97    unsigned int     w, h;
98    int              screen;
99    int              depth;
100    int              alpha;
101    int              rot;
102    int              prev_age;
103    int              frame_cnt;
104    int              vsync;
105 
106    unsigned char    lost_back : 1;
107    unsigned char    surf : 1;
108 
109    struct {
110       unsigned char drew : 1;
111    } draw;
112 };
113 
114 struct _Context_3D
115 {
116 #ifdef GL_GLES
117    EGLDisplay      display;
118    EGLContext      context;
119    EGLSurface      surface;
120 #else
121    Display        *display;
122    GLXContext      context;
123    GLXWindow       glxwin;
124    Window          win;
125 #endif
126 };
127 
128 extern int extn_have_buffer_age;
129 extern int partial_render_debug;
130 extern int swap_buffer_debug_mode;
131 extern int swap_buffer_debug;
132 extern const char *debug_dir;
133 
134 extern Evas_GL_Common_Context_New glsym_evas_gl_common_context_new;
135 extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_flush;
136 extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_free;
137 extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_use;
138 extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_newframe;
139 extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_done;
140 extern Evas_GL_Common_Context_Resize_Call glsym_evas_gl_common_context_resize;
141 extern Evas_GL_Common_Buffer_Dump_Call glsym_evas_gl_common_buffer_dump;
142 extern Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_lock;
143 extern Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_unlock;
144 
145 #ifdef GL_GLES
146 
147 #ifndef EGL_BUFFER_AGE_EXT
148 # define EGL_BUFFER_AGE_EXT 0x313d
149 #endif
150 
151 extern unsigned int   (*glsym_eglSwapBuffersWithDamage) (EGLDisplay a, void *b, const EGLint *d, EGLint c);
152 extern unsigned int   (*glsym_eglSetDamageRegionKHR)  (EGLDisplay a, EGLSurface b, EGLint *c, EGLint d);
153 
154 #else
155 
156 #ifndef GLX_BACK_BUFFER_AGE_EXT
157 # define GLX_BACK_BUFFER_AGE_EXT 0x20f4
158 #endif
159 
160 extern void     (*glsym_glXQueryDrawable)   (Display *a, XID b, int c, unsigned int *d);
161 extern void     (*glsym_glXSwapIntervalEXT) (Display *s, GLXDrawable b, int c);
162 extern int      (*glsym_glXSwapIntervalSGI) (int a);
163 extern int      (*glsym_glXGetVideoSync)    (unsigned int *a);
164 extern int      (*glsym_glXWaitVideoSync)   (int a, int b, unsigned int *c);
165 
166 #endif
167 
168 Outbuf *eng_window_new(Evas_Engine_Info_GL_X11 *info,
169                        Display *disp, Window win, int screen,
170                        Visual *vis, Colormap cmap,
171                        int depth, unsigned int w, unsigned int h, int indirect,
172                        int alpha, int rot,
173                        Render_Output_Swap_Mode swap_mode,
174                        int depth_bits, int stencil_bits, int msaa_bits);
175 void      eng_window_free(Outbuf *gw);
176 void      eng_window_use(Outbuf *gw);
177 void      eng_window_unsurf(Outbuf *gw);
178 void      eng_window_resurf(Outbuf *gw);
179 
180 void     *eng_best_visual_get(Evas_Engine_Info_GL_X11 *einfo);
181 Colormap  eng_best_colormap_get(Evas_Engine_Info_GL_X11 *einfo);
182 int       eng_best_depth_get(Evas_Engine_Info_GL_X11 *einfo);
183 
184 Context_3D *eng_gl_context_new(Outbuf *win);
185 void      eng_gl_context_free(Context_3D *context);
186 void      eng_gl_context_use(Context_3D *context);
187 
188 void eng_outbuf_reconfigure(Outbuf *ob, int w, int h, int rot, Outbuf_Depth depth);
189 int eng_outbuf_get_rot(Outbuf *ob);
190 Render_Output_Swap_Mode eng_outbuf_swap_mode(Outbuf *ob);
191 #ifdef GL_GLES
192 void eng_outbuf_damage_region_set(Outbuf *ob, Tilebuf_Rect *damage);
193 #endif
194 Eina_Bool eng_outbuf_region_first_rect(Outbuf *ob);
195 void *eng_outbuf_new_region_for_update(Outbuf *ob,
196                                        int x, int y, int w, int h,
197                                        int *cx, int *cy, int *cw, int *ch);
198 void eng_outbuf_push_updated_region(Outbuf *ob, RGBA_Image *update,
199                                     int x, int y, int w, int h);
200 void eng_outbuf_flush(Outbuf *ob, Tilebuf_Rect *surface_damage, Tilebuf_Rect *buffer_damage, Evas_Render_Mode render_mode);
201 Evas_Engine_GL_Context *eng_outbuf_gl_context_get(Outbuf *ob);
202 void *eng_outbuf_egl_display_get(Outbuf *ob);
203 
204 Eina_Bool eng_preload_make_current(void *data, void *doit);
205 void eng_gl_symbols(Outbuf *ob);
206 
207 static inline int
_re_wincheck(Outbuf * ob)208 _re_wincheck(Outbuf *ob)
209 {
210    if (ob->surf) return 1;
211    eng_window_resurf(ob);
212    ob->lost_back = 1;
213    if (!ob->surf)
214      {
215         ERR("GL engine can't re-create window surface!");
216      }
217    return 0;
218 }
219 
220 #ifdef GL_GLES
221 EGLBoolean evas_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
222 EGLContext evas_eglGetCurrentContext(void);
223 EGLSurface evas_eglGetCurrentSurface(EGLint readdraw);
224 EGLDisplay evas_eglGetCurrentDisplay(void);
225 #else
226 Eina_Bool __glXMakeContextCurrent(Display *disp, GLXDrawable glxwin,
227                                   GLXContext context);
228 #endif
229 
230 extern Eina_Bool gles3_supported;
231 
232 #endif
233