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_Wayland.h"
9 
10 /* NB: This already includes wayland-client.h */
11 # include <wayland-egl.h>
12 
13 # define GL_GLEXT_PROTOTYPES
14 
15 # if !defined(HAVE_ECORE_X_XLIB) && !defined(MESA_EGL_NO_X11_HEADERS)
16 #  define MESA_EGL_NO_X11_HEADERS
17 # endif
18 
19 # include <EGL/egl.h>
20 # include <GLES2/gl2.h>
21 # include <GLES2/gl2ext.h>
22 
23 # include "../gl_generic/Evas_Engine_GL_Generic.h"
24 
25 extern int _evas_engine_wl_egl_log_dom;
26 
27 # ifdef ERR
28 #  undef ERR
29 # endif
30 # define ERR(...) EINA_LOG_DOM_ERR(_evas_engine_wl_egl_log_dom, __VA_ARGS__)
31 
32 # ifdef DBG
33 #  undef DBG
34 # endif
35 # define DBG(...) EINA_LOG_DOM_DBG(_evas_engine_wl_egl_log_dom, __VA_ARGS__)
36 
37 # ifdef INF
38 #  undef INF
39 # endif
40 # define INF(...) EINA_LOG_DOM_INFO(_evas_engine_wl_egl_log_dom, __VA_ARGS__)
41 
42 # ifdef WRN
43 #  undef WRN
44 # endif
45 # define WRN(...) EINA_LOG_DOM_WARN(_evas_engine_wl_egl_log_dom, __VA_ARGS__)
46 
47 # ifdef CRI
48 #  undef CRI
49 # endif
50 # define CRI(...) EINA_LOG_DOM_CRIT(_evas_engine_wl_egl_log_dom, __VA_ARGS__)
51 
52 # ifndef EGL_BUFFER_AGE_EXT
53 #  define EGL_BUFFER_AGE_EXT 0x313d
54 # endif
55 
56 struct _Outbuf
57 {
58    Ecore_Wl2_Display *wl2_disp;
59    struct wl_egl_window *win;
60    Ecore_Wl2_Window *wl2_win;
61    int w, h;
62    int depth, screen, rot, alpha;
63 
64    Evas_Engine_Info_Wayland *info;
65    Evas_Engine_GL_Context *gl_context;
66 
67    int prev_age;
68    Render_Output_Swap_Mode swap_mode;
69    int vsync;
70    int frame_cnt;
71 
72    struct
73      {
74         Eina_Bool drew : 1;
75      } draw;
76 
77    EGLContext egl_context;
78    EGLSurface egl_surface;
79    EGLConfig egl_config;
80    EGLDisplay egl_disp;
81 
82    struct {
83       unsigned char depth_buffer_size;
84       unsigned char stencil_buffer_size;
85       unsigned char msaa;
86    } detected;
87 
88    int depth_bits;
89    int stencil_bits;
90    int msaa_bits;
91 
92    Eina_Bool lost_back : 1;
93    Eina_Bool surf : 1;
94 };
95 
96 struct _Context_3D
97 {
98    EGLDisplay display;
99    EGLContext context;
100    EGLSurface surface;
101 };
102 
103 extern Eina_Bool extn_have_buffer_age;
104 extern Eina_Bool extn_have_y_inverted;
105 
106 extern Evas_GL_Common_Context_New glsym_evas_gl_common_context_new;
107 extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_flush;
108 extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_free;
109 extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_use;
110 extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_newframe;
111 extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_done;
112 extern Evas_GL_Common_Context_Resize_Call glsym_evas_gl_common_context_resize;
113 extern Evas_GL_Common_Buffer_Dump_Call glsym_evas_gl_common_buffer_dump;
114 extern Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_lock;
115 extern Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_unlock;
116 
117 extern unsigned int (*glsym_eglSwapBuffersWithDamage) (EGLDisplay a, void *b, const EGLint *d, EGLint c);
118 extern unsigned int (*glsym_eglSetDamageRegionKHR) (EGLDisplay a, EGLSurface b, EGLint *c, EGLint d);
119 
120 Outbuf *eng_window_new(Evas_Engine_Info_Wayland *einfo, int w, int h, Render_Output_Swap_Mode swap_mode);
121 void eng_window_free(Outbuf *gw);
122 void eng_window_use(Outbuf *gw);
123 void eng_window_unsurf(Outbuf *gw);
124 void eng_window_resurf(Outbuf *gw);
125 
126 void eng_outbuf_reconfigure(Outbuf *ob, int w, int h, int rot, Outbuf_Depth depth);
127 int eng_outbuf_rotation_get(Outbuf *ob);
128 Render_Output_Swap_Mode eng_outbuf_swap_mode_get(Outbuf *ob);
129 Eina_Bool eng_outbuf_region_first_rect(Outbuf *ob);
130 void eng_outbuf_damage_region_set(Outbuf *ob, Tilebuf_Rect *damage);
131 void *eng_outbuf_update_region_new(Outbuf *ob, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch);
132 void eng_outbuf_update_region_push(Outbuf *ob, RGBA_Image *update, int x, int y, int w, int h);
133 void eng_outbuf_flush(Outbuf *ob, Tilebuf_Rect *surface_damage, Tilebuf_Rect *buffer_damage, Evas_Render_Mode render_mode);
134 
135 Evas_Engine_GL_Context *eng_outbuf_gl_context_get(Outbuf *ob);
136 void *eng_outbuf_egl_display_get(Outbuf *ob);
137 Eina_Bool eng_preload_make_current(void *data, void *doit);
138 
139 Context_3D *eng_gl_context_new(Outbuf *win);
140 void eng_gl_context_free(Context_3D *context);
141 void eng_gl_context_use(Context_3D *context);
142 
143 void eng_gl_symbols(EGLDisplay disp);
144 
145 static inline int
_re_wincheck(Outbuf * ob)146 _re_wincheck(Outbuf *ob)
147 {
148    if (ob->surf) return 1;
149    eng_window_resurf(ob);
150    ob->lost_back = EINA_TRUE;
151    if (!ob->surf)
152      ERR("Wayland EGL Engine cannot recreate window surface");
153    return 0;
154 }
155 
156 #endif
157