Merge "Add rpi network drivers by default"
[AGL/meta-agl.git] / meta-agl-bsp / meta-freescale-layer / recipes-graphics / wayland / weston-2.0.0 / 0001-libweston-Restore-EGL-support-for-the-fbdev-backend.patch
1 From c43b64cad0fdc55594434a68faa25447b50ca7c5 Mon Sep 17 00:00:00 2001
2 From: Georgi Vlaev <georgi.vlaev@konsulko.com>
3 Date: Wed, 27 Sep 2017 14:00:50 +0300
4 Subject: [PATCH 1/5] libweston: Restore EGL support for the fbdev backend
5
6 In Weston 2.0, the EGL support was dropped from the fbdev-backend,
7 as that was not the correct way to initialize the EGL in first
8 place. However, the vendor support patches in Weston 1.11 still
9 require that functionality. Teporary restore the EGL support in
10 the fbdev-backend, until a separate vendor backend is available,
11 or switch to using etnaviv.
12
13 Signed-off-by: Georgi Vlaev <georgi.vlaev@konsulko.com>
14 ---
15  compositor/main.c            |  2 +
16  libweston/compositor-fbdev.c | 99 +++++++++++++++++++++++++++++++++++++-------
17  libweston/compositor-fbdev.h |  1 +
18  3 files changed, 87 insertions(+), 15 deletions(-)
19
20 diff --git a/compositor/main.c b/compositor/main.c
21 index 72c3cd10..6c45a018 100644
22 --- a/compositor/main.c
23 +++ b/compositor/main.c
24 @@ -574,6 +574,7 @@ usage(int error_code)
25                 "Options for fbdev-backend.so:\n\n"
26                 "  --tty=TTY\t\tThe tty to use\n"
27                 "  --device=DEVICE\tThe framebuffer device to use\n"
28 +               "  --use-gl\t\tUse the GL renderer\n"
29                 "\n");
30  #endif
31  
32 @@ -1444,6 +1445,7 @@ load_fbdev_backend(struct weston_compositor *c,
33         const struct weston_option fbdev_options[] = {
34                 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
35                 { WESTON_OPTION_STRING, "device", 0, &config.device },
36 +               { WESTON_OPTION_BOOLEAN, "use-gl", 0, &config.use_gl },
37         };
38  
39         parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
40 diff --git a/libweston/compositor-fbdev.c b/libweston/compositor-fbdev.c
41 index 44f0cf51..4ca53b67 100644
42 --- a/libweston/compositor-fbdev.c
43 +++ b/libweston/compositor-fbdev.c
44 @@ -49,6 +49,7 @@
45  #include "launcher-util.h"
46  #include "pixman-renderer.h"
47  #include "libinput-seat.h"
48 +#include "gl-renderer.h"
49  #include "presentation-time-server-protocol.h"
50  
51  struct fbdev_backend {
52 @@ -58,6 +59,7 @@ struct fbdev_backend {
53  
54         struct udev *udev;
55         struct udev_input input;
56 +       int use_pixman;
57         uint32_t output_transform;
58         struct wl_listener session_listener;
59  };
60 @@ -94,6 +96,8 @@ struct fbdev_output {
61         uint8_t depth;
62  };
63  
64 +struct gl_renderer_interface *gl_renderer;
65 +
66  static const char default_seat[] = "seat0";
67  
68  static inline struct fbdev_output *
69 @@ -117,8 +121,8 @@ fbdev_output_start_repaint_loop(struct weston_output *output)
70         weston_output_finish_frame(output, &ts, WP_PRESENTATION_FEEDBACK_INVALID);
71  }
72  
73 -static int
74 -fbdev_output_repaint(struct weston_output *base, pixman_region32_t *damage)
75 +static void
76 +fbdev_output_repaint_pixman(struct weston_output *base, pixman_region32_t *damage)
77  {
78         struct fbdev_output *output = to_fbdev_output(base);
79         struct weston_compositor *ec = output->base.compositor;
80 @@ -140,6 +144,26 @@ fbdev_output_repaint(struct weston_output *base, pixman_region32_t *damage)
81          * refresh rate is given in mHz and the interval in ms. */
82         wl_event_source_timer_update(output->finish_frame_timer,
83                                      1000000 / output->mode.refresh);
84 +}
85 +
86 +static int
87 +fbdev_output_repaint(struct weston_output *base, pixman_region32_t *damage)
88 +{
89 +       struct fbdev_output *output = to_fbdev_output(base);
90 +       struct fbdev_backend *backend = output->backend;
91 +       struct weston_compositor *ec = backend->compositor;
92 +
93 +       if (backend->use_pixman) {
94 +               fbdev_output_repaint_pixman(base,damage);
95 +       } else {
96 +               ec->renderer->repaint_output(base, damage);
97 +               /* Update the damage region. */
98 +               pixman_region32_subtract(&ec->primary_plane.damage,
99 +                                       &ec->primary_plane.damage, damage);
100 +
101 +               wl_event_source_timer_update(output->finish_frame_timer,
102 +                                       1000000 / output->mode.refresh);
103 +       }
104  
105         return 0;
106  }
107 @@ -440,16 +464,30 @@ fbdev_output_enable(struct weston_output *base)
108                 return -1;
109         }
110  
111 -       if (fbdev_frame_buffer_map(output, fb_fd) < 0) {
112 -               weston_log("Mapping frame buffer failed.\n");
113 -               return -1;
114 -       }
115 +       if (backend->use_pixman) {
116 +               if (fbdev_frame_buffer_map(output, fb_fd) < 0) {
117 +                       weston_log("Mapping frame buffer failed.\n");
118 +                       return -1;
119 +               }
120 +       } else
121 +               close(fb_fd);
122  
123         output->base.start_repaint_loop = fbdev_output_start_repaint_loop;
124         output->base.repaint = fbdev_output_repaint;
125  
126 -       if (pixman_renderer_output_create(&output->base) < 0)
127 -               goto out_hw_surface;
128 +       if (backend->use_pixman) {
129 +               if (pixman_renderer_output_create(&output->base) < 0)
130 +                       goto out_hw_surface;
131 +       } else {
132 +               setenv("HYBRIS_EGLPLATFORM", "wayland", 1);
133 +               if (gl_renderer->output_window_create(&output->base,
134 +                                               (EGLNativeWindowType)NULL, NULL,
135 +                                               gl_renderer->opaque_attribs,
136 +                                               NULL, 0) < 0) {
137 +                       weston_log("gl_renderer_output_create failed.\n");
138 +                       goto out_hw_surface;
139 +               }
140 +       }
141  
142         loop = wl_display_get_event_loop(backend->compositor->wl_display);
143         output->finish_frame_timer =
144 @@ -534,14 +572,19 @@ static void
145  fbdev_output_destroy(struct weston_output *base)
146  {
147         struct fbdev_output *output = to_fbdev_output(base);
148 +       struct fbdev_backend *backend = output->backend;
149  
150         weston_log("Destroying fbdev output.\n");
151  
152         /* Close the frame buffer. */
153         fbdev_output_disable(base);
154  
155 -       if (base->renderer_state != NULL)
156 -               pixman_renderer_output_destroy(base);
157 +       if (backend->use_pixman) {
158 +               if (base->renderer_state != NULL)
159 +                       pixman_renderer_output_destroy(base);
160 +       } else {
161 +               gl_renderer->output_destroy(base);
162 +       }
163  
164         /* Remove the output. */
165         weston_output_destroy(&output->base);
166 @@ -610,9 +653,11 @@ fbdev_output_reenable(struct fbdev_backend *backend,
167         }
168  
169         /* Map the device if it has the same details as before. */
170 -       if (fbdev_frame_buffer_map(output, fb_fd) < 0) {
171 -               weston_log("Mapping frame buffer failed.\n");
172 -               goto err;
173 +       if (backend->use_pixman) {
174 +               if (fbdev_frame_buffer_map(output, fb_fd) < 0) {
175 +                       weston_log("Mapping frame buffer failed.\n");
176 +                       goto err;
177 +               }
178         }
179  
180         return 0;
181 @@ -628,9 +673,13 @@ static void
182  fbdev_output_disable(struct weston_output *base)
183  {
184         struct fbdev_output *output = to_fbdev_output(base);
185 +       struct fbdev_backend *backend = output->backend;
186  
187         weston_log("Disabling fbdev output.\n");
188  
189 +        if (!backend->use_pixman)
190 +               return;
191 +
192         if (output->hw_surface != NULL) {
193                 pixman_image_unref(output->hw_surface);
194                 output->hw_surface = NULL;
195 @@ -744,11 +793,30 @@ fbdev_backend_create(struct weston_compositor *compositor,
196         backend->base.restore = fbdev_restore;
197  
198         backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
199 +       backend->use_pixman = !param->use_gl;
200  
201         weston_setup_vt_switch_bindings(compositor);
202  
203 -       if (pixman_renderer_init(compositor) < 0)
204 -               goto out_launcher;
205 +       if (backend->use_pixman) {
206 +               if (pixman_renderer_init(compositor) < 0)
207 +                       goto out_launcher;
208 +       } else {
209 +               gl_renderer = weston_load_module("gl-renderer.so",
210 +                                               "gl_renderer_interface");
211 +               if (!gl_renderer) {
212 +                       weston_log("could not load gl renderer\n");
213 +                       goto out_launcher;
214 +               }
215 +
216 +               if (gl_renderer->display_create(compositor, NO_EGL_PLATFORM,
217 +                                       EGL_DEFAULT_DISPLAY,
218 +                                       NULL,
219 +                                       gl_renderer->opaque_attribs,
220 +                                       NULL, 0) < 0) {
221 +                       weston_log("gl_renderer_create failed.\n");
222 +                       goto out_launcher;
223 +               }
224 +       }
225  
226         if (fbdev_output_create(backend, param->device) < 0)
227                 goto out_launcher;
228 @@ -779,6 +847,7 @@ config_init_to_defaults(struct weston_fbdev_backend_config *config)
229          * udev, rather than passing a device node in as a parameter. */
230         config->tty = 0; /* default to current tty */
231         config->device = "/dev/fb0"; /* default frame buffer */
232 +       config->use_gl = 0;
233  }
234  
235  WL_EXPORT int
236 diff --git a/libweston/compositor-fbdev.h b/libweston/compositor-fbdev.h
237 index 8b7d900e..806712f9 100644
238 --- a/libweston/compositor-fbdev.h
239 +++ b/libweston/compositor-fbdev.h
240 @@ -43,6 +43,7 @@ struct weston_fbdev_backend_config {
241  
242         int tty;
243         char *device;
244 +       int use_gl;
245  
246         /** Callback used to configure input devices.
247          *
248 -- 
249 2.11.0
250