~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/egl/drivers/dri2/platform_wayland.c

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 *    Benjamin Franzke <benjaminfranzke@googlemail.com>
28
28
 */
29
29
 
 
30
#include <dlfcn.h>
 
31
#include <errno.h>
 
32
#include <fcntl.h>
 
33
#include <limits.h>
30
34
#include <stdint.h>
31
35
#include <stdlib.h>
32
36
#include <string.h>
33
 
#include <limits.h>
34
 
#include <dlfcn.h>
35
 
#include <errno.h>
36
37
#include <unistd.h>
37
 
#include <vulkan/vulkan_core.h>
38
 
#include <vulkan/vulkan_wayland.h>
39
 
#include <fcntl.h>
40
38
#include <xf86drm.h>
41
39
#include "drm-uapi/drm_fourcc.h"
42
40
#include <sys/mman.h>
 
41
#include <vulkan/vulkan_core.h>
 
42
#include <vulkan/vulkan_wayland.h>
43
43
 
 
44
#include "util/anon_file.h"
 
45
#include "util/u_vector.h"
44
46
#include "egl_dri2.h"
45
 
#include "loader_dri_helper.h"
46
 
#include "loader.h"
47
 
#include "util/u_vector.h"
48
 
#include "util/anon_file.h"
49
47
#include "eglglobals.h"
50
48
#include "kopper_interface.h"
 
49
#include "loader.h"
 
50
#include "loader_dri_helper.h"
51
51
 
 
52
#include "linux-dmabuf-unstable-v1-client-protocol.h"
 
53
#include "wayland-drm-client-protocol.h"
 
54
#include <wayland-client.h>
52
55
#include <wayland-egl-backend.h>
53
 
#include <wayland-client.h>
54
 
#include "wayland-drm-client-protocol.h"
55
 
#include "linux-dmabuf-unstable-v1-client-protocol.h"
56
56
 
57
57
/*
58
58
 * The index of entries in this table is used as a bitmask in
78
78
} dri2_wl_visuals[] = {
79
79
   {
80
80
      "ABGR16F",
81
 
      WL_DRM_FORMAT_ABGR16F, WL_SHM_FORMAT_ABGR16161616F,
82
 
      __DRI_IMAGE_FORMAT_ABGR16161616F, 0, 64,
83
 
      { 0, 16, 32, 48 },
84
 
      { 16, 16, 16, 16 },
 
81
      WL_DRM_FORMAT_ABGR16F,
 
82
      WL_SHM_FORMAT_ABGR16161616F,
 
83
      __DRI_IMAGE_FORMAT_ABGR16161616F,
 
84
      0,
 
85
      64,
 
86
      {0, 16, 32, 48},
 
87
      {16, 16, 16, 16},
85
88
   },
86
89
   {
87
90
      "XBGR16F",
88
 
      WL_DRM_FORMAT_XBGR16F, WL_SHM_FORMAT_XBGR16161616F,
89
 
      __DRI_IMAGE_FORMAT_XBGR16161616F, 0, 64,
90
 
      { 0, 16, 32, -1 },
91
 
      { 16, 16, 16, 0 },
 
91
      WL_DRM_FORMAT_XBGR16F,
 
92
      WL_SHM_FORMAT_XBGR16161616F,
 
93
      __DRI_IMAGE_FORMAT_XBGR16161616F,
 
94
      0,
 
95
      64,
 
96
      {0, 16, 32, -1},
 
97
      {16, 16, 16, 0},
92
98
   },
93
99
   {
94
100
      "XRGB2101010",
95
 
      WL_DRM_FORMAT_XRGB2101010, WL_SHM_FORMAT_XRGB2101010,
96
 
      __DRI_IMAGE_FORMAT_XRGB2101010, __DRI_IMAGE_FORMAT_XBGR2101010, 32,
97
 
      { 20, 10, 0, -1 },
98
 
      { 10, 10, 10, 0 },
 
101
      WL_DRM_FORMAT_XRGB2101010,
 
102
      WL_SHM_FORMAT_XRGB2101010,
 
103
      __DRI_IMAGE_FORMAT_XRGB2101010,
 
104
      __DRI_IMAGE_FORMAT_XBGR2101010,
 
105
      32,
 
106
      {20, 10, 0, -1},
 
107
      {10, 10, 10, 0},
99
108
   },
100
109
   {
101
110
      "ARGB2101010",
102
 
      WL_DRM_FORMAT_ARGB2101010, WL_SHM_FORMAT_ARGB2101010,
103
 
      __DRI_IMAGE_FORMAT_ARGB2101010, __DRI_IMAGE_FORMAT_ABGR2101010, 32,
104
 
      { 20, 10, 0, 30 },
105
 
      { 10, 10, 10, 2 },
 
111
      WL_DRM_FORMAT_ARGB2101010,
 
112
      WL_SHM_FORMAT_ARGB2101010,
 
113
      __DRI_IMAGE_FORMAT_ARGB2101010,
 
114
      __DRI_IMAGE_FORMAT_ABGR2101010,
 
115
      32,
 
116
      {20, 10, 0, 30},
 
117
      {10, 10, 10, 2},
106
118
   },
107
119
   {
108
120
      "XBGR2101010",
109
 
      WL_DRM_FORMAT_XBGR2101010, WL_SHM_FORMAT_XBGR2101010,
110
 
      __DRI_IMAGE_FORMAT_XBGR2101010, __DRI_IMAGE_FORMAT_XRGB2101010, 32,
111
 
      { 0, 10, 20, -1 },
112
 
      { 10, 10, 10, 0 },
 
121
      WL_DRM_FORMAT_XBGR2101010,
 
122
      WL_SHM_FORMAT_XBGR2101010,
 
123
      __DRI_IMAGE_FORMAT_XBGR2101010,
 
124
      __DRI_IMAGE_FORMAT_XRGB2101010,
 
125
      32,
 
126
      {0, 10, 20, -1},
 
127
      {10, 10, 10, 0},
113
128
   },
114
129
   {
115
130
      "ABGR2101010",
116
 
      WL_DRM_FORMAT_ABGR2101010, WL_SHM_FORMAT_ABGR2101010,
117
 
      __DRI_IMAGE_FORMAT_ABGR2101010, __DRI_IMAGE_FORMAT_ARGB2101010, 32,
118
 
      { 0, 10, 20, 30 },
119
 
      { 10, 10, 10, 2 },
 
131
      WL_DRM_FORMAT_ABGR2101010,
 
132
      WL_SHM_FORMAT_ABGR2101010,
 
133
      __DRI_IMAGE_FORMAT_ABGR2101010,
 
134
      __DRI_IMAGE_FORMAT_ARGB2101010,
 
135
      32,
 
136
      {0, 10, 20, 30},
 
137
      {10, 10, 10, 2},
120
138
   },
121
139
   {
122
140
      "XRGB8888",
123
 
      WL_DRM_FORMAT_XRGB8888, WL_SHM_FORMAT_XRGB8888,
124
 
      __DRI_IMAGE_FORMAT_XRGB8888, __DRI_IMAGE_FORMAT_NONE, 32,
125
 
      { 16, 8, 0, -1 },
126
 
      { 8, 8, 8, 0 },
 
141
      WL_DRM_FORMAT_XRGB8888,
 
142
      WL_SHM_FORMAT_XRGB8888,
 
143
      __DRI_IMAGE_FORMAT_XRGB8888,
 
144
      __DRI_IMAGE_FORMAT_NONE,
 
145
      32,
 
146
      {16, 8, 0, -1},
 
147
      {8, 8, 8, 0},
127
148
   },
128
149
   {
129
150
      "ARGB8888",
130
 
      WL_DRM_FORMAT_ARGB8888, WL_SHM_FORMAT_ARGB8888,
131
 
      __DRI_IMAGE_FORMAT_ARGB8888, __DRI_IMAGE_FORMAT_NONE, 32,
132
 
      { 16, 8, 0, 24 },
133
 
      { 8, 8, 8, 8 },
 
151
      WL_DRM_FORMAT_ARGB8888,
 
152
      WL_SHM_FORMAT_ARGB8888,
 
153
      __DRI_IMAGE_FORMAT_ARGB8888,
 
154
      __DRI_IMAGE_FORMAT_NONE,
 
155
      32,
 
156
      {16, 8, 0, 24},
 
157
      {8, 8, 8, 8},
134
158
   },
135
159
   {
136
160
      "ABGR8888",
137
 
      WL_DRM_FORMAT_ABGR8888, WL_SHM_FORMAT_ABGR8888,
138
 
      __DRI_IMAGE_FORMAT_ABGR8888, __DRI_IMAGE_FORMAT_NONE, 32,
139
 
      { 0, 8, 16, 24 },
140
 
      { 8, 8, 8, 8 },
 
161
      WL_DRM_FORMAT_ABGR8888,
 
162
      WL_SHM_FORMAT_ABGR8888,
 
163
      __DRI_IMAGE_FORMAT_ABGR8888,
 
164
      __DRI_IMAGE_FORMAT_NONE,
 
165
      32,
 
166
      {0, 8, 16, 24},
 
167
      {8, 8, 8, 8},
141
168
   },
142
169
   {
143
170
      "XBGR8888",
144
 
      WL_DRM_FORMAT_XBGR8888, WL_SHM_FORMAT_XBGR8888,
145
 
      __DRI_IMAGE_FORMAT_XBGR8888, __DRI_IMAGE_FORMAT_NONE, 32,
146
 
      { 0, 8, 16, -1 },
147
 
      { 8, 8, 8, 0 },
 
171
      WL_DRM_FORMAT_XBGR8888,
 
172
      WL_SHM_FORMAT_XBGR8888,
 
173
      __DRI_IMAGE_FORMAT_XBGR8888,
 
174
      __DRI_IMAGE_FORMAT_NONE,
 
175
      32,
 
176
      {0, 8, 16, -1},
 
177
      {8, 8, 8, 0},
148
178
   },
149
179
   {
150
180
      "RGB565",
151
 
      WL_DRM_FORMAT_RGB565, WL_SHM_FORMAT_RGB565,
152
 
      __DRI_IMAGE_FORMAT_RGB565, __DRI_IMAGE_FORMAT_NONE, 16,
153
 
      { 11, 5, 0, -1 },
154
 
      { 5, 6, 5, 0 },
 
181
      WL_DRM_FORMAT_RGB565,
 
182
      WL_SHM_FORMAT_RGB565,
 
183
      __DRI_IMAGE_FORMAT_RGB565,
 
184
      __DRI_IMAGE_FORMAT_NONE,
 
185
      16,
 
186
      {11, 5, 0, -1},
 
187
      {5, 6, 5, 0},
155
188
   },
156
189
};
157
190
 
158
191
static int
159
192
dri2_wl_visual_idx_from_config(struct dri2_egl_display *dri2_dpy,
160
 
                               const __DRIconfig *config,
161
 
                               bool force_opaque)
 
193
                               const __DRIconfig *config, bool force_opaque)
162
194
{
163
195
   int shifts[4];
164
196
   unsigned int sizes[4];
168
200
   for (unsigned int i = 0; i < ARRAY_SIZE(dri2_wl_visuals); i++) {
169
201
      const struct dri2_wl_visual *wl_visual = &dri2_wl_visuals[i];
170
202
 
171
 
      int cmp_rgb_shifts = memcmp(shifts, wl_visual->rgba_shifts,
172
 
                                  3 * sizeof(shifts[0]));
173
 
      int cmp_rgb_sizes = memcmp(sizes, wl_visual->rgba_sizes,
174
 
                                 3 * sizeof(sizes[0]));
 
203
      int cmp_rgb_shifts =
 
204
         memcmp(shifts, wl_visual->rgba_shifts, 3 * sizeof(shifts[0]));
 
205
      int cmp_rgb_sizes =
 
206
         memcmp(sizes, wl_visual->rgba_sizes, 3 * sizeof(sizes[0]));
175
207
 
176
208
      if (cmp_rgb_shifts == 0 && cmp_rgb_sizes == 0 &&
177
209
          wl_visual->rgba_shifts[3] == (force_opaque ? -1 : shifts[3]) &&
219
251
}
220
252
 
221
253
bool
222
 
dri2_wl_is_format_supported(void* user_data, uint32_t format)
 
254
dri2_wl_is_format_supported(void *user_data, uint32_t format)
223
255
{
224
 
   _EGLDisplay *disp = (_EGLDisplay *) user_data;
 
256
   _EGLDisplay *disp = (_EGLDisplay *)user_data;
225
257
   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
226
258
   int j = dri2_wl_visual_idx_from_fourcc(format);
227
259
 
229
261
      return false;
230
262
 
231
263
   for (int i = 0; dri2_dpy->driver_configs[i]; i++)
232
 
      if (j == dri2_wl_visual_idx_from_config(dri2_dpy,
233
 
                                              dri2_dpy->driver_configs[i],
234
 
                                              false))
 
264
      if (j == dri2_wl_visual_idx_from_config(
 
265
                  dri2_dpy, dri2_dpy->driver_configs[i], false))
235
266
         return true;
236
267
 
237
268
   return false;
253
284
      if (dri2_surf->color_buffers[i].wl_buffer == buffer)
254
285
         break;
255
286
 
256
 
   assert (i < ARRAY_SIZE(dri2_surf->color_buffers));
 
287
   assert(i < ARRAY_SIZE(dri2_surf->color_buffers));
257
288
 
258
289
   if (dri2_surf->color_buffers[i].wl_release) {
259
290
      wl_buffer_destroy(buffer);
266
297
}
267
298
 
268
299
static const struct wl_buffer_listener wl_buffer_listener = {
269
 
   .release = wl_buffer_release
 
300
   .release = wl_buffer_release,
270
301
};
271
302
 
272
303
static void
298
329
 
299
330
   /* Here we have an array of u_vector's to store the modifiers supported by
300
331
    * each format in the bitmask. */
301
 
   formats->modifiers = calloc(formats->num_formats,
302
 
                               sizeof(*formats->modifiers));
 
332
   formats->modifiers =
 
333
      calloc(formats->num_formats, sizeof(*formats->modifiers));
303
334
   if (!formats->modifiers)
304
335
      goto err_modifier;
305
336
 
323
354
}
324
355
 
325
356
static void
326
 
dmabuf_feedback_format_table_fini(struct dmabuf_feedback_format_table *format_table)
 
357
dmabuf_feedback_format_table_fini(
 
358
   struct dmabuf_feedback_format_table *format_table)
327
359
{
328
360
   if (format_table->data && format_table->data != MAP_FAILED)
329
361
      munmap(format_table->data, format_table->size);
330
362
}
331
363
 
332
364
static void
333
 
dmabuf_feedback_format_table_init(struct dmabuf_feedback_format_table *format_table)
 
365
dmabuf_feedback_format_table_init(
 
366
   struct dmabuf_feedback_format_table *format_table)
334
367
{
335
368
   memset(format_table, 0, sizeof(*format_table));
336
369
}
357
390
{
358
391
   dmabuf_feedback_tranche_fini(&dmabuf_feedback->pending_tranche);
359
392
 
360
 
   util_dynarray_foreach(&dmabuf_feedback->tranches,
361
 
                         struct dmabuf_feedback_tranche, tranche)
 
393
   util_dynarray_foreach (&dmabuf_feedback->tranches,
 
394
                          struct dmabuf_feedback_tranche, tranche)
362
395
      dmabuf_feedback_tranche_fini(tranche);
363
396
   util_dynarray_fini(&dmabuf_feedback->tranches);
364
397
 
417
450
static struct wl_surface *
418
451
get_wl_surface_proxy(struct wl_egl_window *window)
419
452
{
420
 
    /* Version 3 of wl_egl_window introduced a version field at the same
421
 
     * location where a pointer to wl_surface was stored. Thus, if
422
 
     * window->version is dereferenceable, we've been given an older version of
423
 
     * wl_egl_window, and window->version points to wl_surface */
424
 
   if (_eglPointerIsDereferencable((void *)(window->version))) {
 
453
   /* Version 3 of wl_egl_window introduced a version field at the same
 
454
    * location where a pointer to wl_surface was stored. Thus, if
 
455
    * window->version is dereferenceable, we've been given an older version of
 
456
    * wl_egl_window, and window->version points to wl_surface */
 
457
   if (_eglPointerIsDereferenceable((void *)(window->version))) {
425
458
      return wl_proxy_create_wrapper((void *)(window->version));
426
459
   }
427
460
   return wl_proxy_create_wrapper(window->surface);
428
461
}
429
462
 
430
463
static void
431
 
surface_dmabuf_feedback_format_table(void *data,
432
 
                                     struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1,
433
 
                                     int32_t fd, uint32_t size)
 
464
surface_dmabuf_feedback_format_table(
 
465
   void *data,
 
466
   struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1,
 
467
   int32_t fd, uint32_t size)
434
468
{
435
469
   struct dri2_egl_surface *dri2_surf = data;
436
470
   struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback;
437
471
 
438
472
   feedback->format_table.size = size;
439
 
   feedback->format_table.data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
 
473
   feedback->format_table.data =
 
474
      mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
440
475
 
441
476
   close(fd);
442
477
}
443
478
 
444
479
static void
445
 
surface_dmabuf_feedback_main_device(void *data,
446
 
                                    struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
447
 
                                    struct wl_array *device)
 
480
surface_dmabuf_feedback_main_device(
 
481
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
 
482
   struct wl_array *device)
448
483
{
449
484
   struct dri2_egl_surface *dri2_surf = data;
450
485
   struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback;
467
502
}
468
503
 
469
504
static void
470
 
surface_dmabuf_feedback_tranche_target_device(void *data,
471
 
                                              struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
472
 
                                              struct wl_array *device)
 
505
surface_dmabuf_feedback_tranche_target_device(
 
506
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
 
507
   struct wl_array *device)
473
508
{
474
509
   struct dri2_egl_surface *dri2_surf = data;
475
510
   struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback;
479
514
}
480
515
 
481
516
static void
482
 
surface_dmabuf_feedback_tranche_flags(void *data,
483
 
                                      struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
484
 
                                      uint32_t flags)
 
517
surface_dmabuf_feedback_tranche_flags(
 
518
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
 
519
   uint32_t flags)
485
520
{
486
521
   struct dri2_egl_surface *dri2_surf = data;
487
522
   struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback;
490
525
}
491
526
 
492
527
static void
493
 
surface_dmabuf_feedback_tranche_formats(void *data,
494
 
                                        struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
495
 
                                        struct wl_array *indices)
 
528
surface_dmabuf_feedback_tranche_formats(
 
529
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
 
530
   struct wl_array *indices)
496
531
{
497
532
   struct dri2_egl_surface *dri2_surf = data;
498
533
   struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback;
502
537
   int visual_idx;
503
538
 
504
539
   /* Compositor may advertise or not a format table. If it does, we use it.
505
 
    * Otherwise, we steal the most recent advertised format table. If we don't have
506
 
    * a most recent advertised format table, compositor did something wrong. */
 
540
    * Otherwise, we steal the most recent advertised format table. If we don't
 
541
    * have a most recent advertised format table, compositor did something
 
542
    * wrong. */
507
543
   if (feedback->format_table.data == NULL) {
508
544
      feedback->format_table = dri2_surf->dmabuf_feedback.format_table;
509
 
      dmabuf_feedback_format_table_init(&dri2_surf->dmabuf_feedback.format_table);
 
545
      dmabuf_feedback_format_table_init(
 
546
         &dri2_surf->dmabuf_feedback.format_table);
510
547
   }
511
548
   if (feedback->format_table.data == MAP_FAILED) {
512
549
      _eglLog(_EGL_WARNING, "wayland-egl: we could not map the format table "
515
552
      return;
516
553
   }
517
554
   if (feedback->format_table.data == NULL) {
518
 
      _eglLog(_EGL_WARNING, "wayland-egl: compositor didn't advertise a format "
519
 
                            "table, so we won't be able to use this batch of dma-buf "
520
 
                            "feedback events.");
 
555
      _eglLog(_EGL_WARNING,
 
556
              "wayland-egl: compositor didn't advertise a format "
 
557
              "table, so we won't be able to use this batch of dma-buf "
 
558
              "feedback events.");
521
559
      return;
522
560
   }
523
561
 
524
 
   wl_array_for_each(index, indices) {
 
562
   wl_array_for_each (index, indices) {
525
563
      format = feedback->format_table.data[*index].format;
526
564
      modifier = feedback->format_table.data[*index].modifier;
527
565
 
543
581
}
544
582
 
545
583
static void
546
 
surface_dmabuf_feedback_tranche_done(void *data,
547
 
                                     struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback)
 
584
surface_dmabuf_feedback_tranche_done(
 
585
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback)
548
586
{
549
587
   struct dri2_egl_surface *dri2_surf = data;
550
588
   struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback;
557
595
}
558
596
 
559
597
static void
560
 
surface_dmabuf_feedback_done(void *data,
561
 
                             struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback)
 
598
surface_dmabuf_feedback_done(
 
599
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback)
562
600
{
563
601
   struct dri2_egl_surface *dri2_surf = data;
564
602
 
575
613
}
576
614
 
577
615
static const struct zwp_linux_dmabuf_feedback_v1_listener
578
 
surface_dmabuf_feedback_listener = {
579
 
   .format_table = surface_dmabuf_feedback_format_table,
580
 
   .main_device = surface_dmabuf_feedback_main_device,
581
 
   .tranche_target_device = surface_dmabuf_feedback_tranche_target_device,
582
 
   .tranche_flags = surface_dmabuf_feedback_tranche_flags,
583
 
   .tranche_formats = surface_dmabuf_feedback_tranche_formats,
584
 
   .tranche_done = surface_dmabuf_feedback_tranche_done,
585
 
   .done = surface_dmabuf_feedback_done,
 
616
   surface_dmabuf_feedback_listener = {
 
617
      .format_table = surface_dmabuf_feedback_format_table,
 
618
      .main_device = surface_dmabuf_feedback_main_device,
 
619
      .tranche_target_device = surface_dmabuf_feedback_tranche_target_device,
 
620
      .tranche_flags = surface_dmabuf_feedback_tranche_flags,
 
621
      .tranche_formats = surface_dmabuf_feedback_tranche_formats,
 
622
      .tranche_done = surface_dmabuf_feedback_tranche_done,
 
623
      .done = surface_dmabuf_feedback_done,
586
624
};
587
625
 
588
626
/**
624
662
                                dri2_surf->base.GLColorspace);
625
663
 
626
664
   if (!config) {
627
 
      _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration");
 
665
      _eglError(EGL_BAD_MATCH,
 
666
                "Unsupported surfacetype/colorspace configuration");
628
667
      goto cleanup_surf;
629
668
   }
630
669
 
648
687
            continue;
649
688
         }
650
689
 
651
 
         int cmp_rgb_shifts = memcmp(transparent_visual->rgba_shifts,
652
 
                                     opaque_visual->rgba_shifts,
653
 
                                     3 * sizeof(opaque_visual->rgba_shifts[0]));
654
 
         int cmp_rgb_sizes = memcmp(transparent_visual->rgba_sizes,
655
 
                                    opaque_visual->rgba_sizes,
656
 
                                    3 * sizeof(opaque_visual->rgba_sizes[0]));
 
690
         int cmp_rgb_shifts =
 
691
            memcmp(transparent_visual->rgba_shifts, opaque_visual->rgba_shifts,
 
692
                   3 * sizeof(opaque_visual->rgba_shifts[0]));
 
693
         int cmp_rgb_sizes =
 
694
            memcmp(transparent_visual->rgba_sizes, opaque_visual->rgba_sizes,
 
695
                   3 * sizeof(opaque_visual->rgba_sizes[0]));
657
696
 
658
697
         if (cmp_rgb_shifts == 0 && cmp_rgb_sizes == 0) {
659
698
            found_opaque_equivalent = true;
708
747
   wl_proxy_set_queue((struct wl_proxy *)dri2_surf->wl_surface_wrapper,
709
748
                      dri2_surf->wl_queue);
710
749
 
711
 
   if (dri2_dpy->wl_dmabuf && zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >=
712
 
                              ZWP_LINUX_DMABUF_V1_GET_SURFACE_FEEDBACK_SINCE_VERSION) {
 
750
   if (dri2_dpy->wl_dmabuf &&
 
751
       zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >=
 
752
          ZWP_LINUX_DMABUF_V1_GET_SURFACE_FEEDBACK_SINCE_VERSION) {
713
753
      dmabuf_wrapper = wl_proxy_create_wrapper(dri2_dpy->wl_dmabuf);
714
754
      if (!dmabuf_wrapper) {
715
755
         _eglError(EGL_BAD_ALLOC, "dri2_create_surface");
717
757
      }
718
758
      wl_proxy_set_queue((struct wl_proxy *)dmabuf_wrapper,
719
759
                         dri2_surf->wl_queue);
720
 
      dri2_surf->wl_dmabuf_feedback =
721
 
         zwp_linux_dmabuf_v1_get_surface_feedback(dmabuf_wrapper,
722
 
                                                  dri2_surf->wl_surface_wrapper);
 
760
      dri2_surf->wl_dmabuf_feedback = zwp_linux_dmabuf_v1_get_surface_feedback(
 
761
         dmabuf_wrapper, dri2_surf->wl_surface_wrapper);
723
762
      wl_proxy_wrapper_destroy(dmabuf_wrapper);
724
763
 
725
 
      zwp_linux_dmabuf_feedback_v1_add_listener(dri2_surf->wl_dmabuf_feedback,
726
 
                                                &surface_dmabuf_feedback_listener,
727
 
                                                dri2_surf);
 
764
      zwp_linux_dmabuf_feedback_v1_add_listener(
 
765
         dri2_surf->wl_dmabuf_feedback, &surface_dmabuf_feedback_listener,
 
766
         dri2_surf);
728
767
 
729
768
      if (dmabuf_feedback_init(&dri2_surf->pending_dmabuf_feedback) < 0) {
730
769
         zwp_linux_dmabuf_feedback_v1_destroy(dri2_surf->wl_dmabuf_feedback);
747
786
      dri2_surf->wl_win->resize_callback = resize_callback;
748
787
 
749
788
   if (!dri2_create_drawable(dri2_dpy, config, dri2_surf, dri2_surf))
750
 
       goto cleanup_dmabuf_feedback;
 
789
      goto cleanup_dmabuf_feedback;
751
790
 
752
791
   dri2_surf->base.SwapInterval = dri2_dpy->default_swap_interval;
753
792
 
754
793
   return &dri2_surf->base;
755
794
 
756
 
 cleanup_dmabuf_feedback:
 
795
cleanup_dmabuf_feedback:
757
796
   if (dri2_surf->wl_dmabuf_feedback) {
758
797
      zwp_linux_dmabuf_feedback_v1_destroy(dri2_surf->wl_dmabuf_feedback);
759
798
      dmabuf_feedback_fini(&dri2_surf->dmabuf_feedback);
760
799
      dmabuf_feedback_fini(&dri2_surf->pending_dmabuf_feedback);
761
800
   }
762
 
 cleanup_surf_wrapper:
 
801
cleanup_surf_wrapper:
763
802
   wl_proxy_wrapper_destroy(dri2_surf->wl_surface_wrapper);
764
 
 cleanup_dpy_wrapper:
 
803
cleanup_dpy_wrapper:
765
804
   wl_proxy_wrapper_destroy(dri2_surf->wl_dpy_wrapper);
766
 
 cleanup_drm:
 
805
cleanup_drm:
767
806
   if (dri2_surf->wl_drm_wrapper)
768
807
      wl_proxy_wrapper_destroy(dri2_surf->wl_drm_wrapper);
769
 
 cleanup_queue:
 
808
cleanup_queue:
770
809
   wl_event_queue_destroy(dri2_surf->wl_queue);
771
 
 cleanup_surf:
 
810
cleanup_surf:
772
811
   free(dri2_surf);
773
812
 
774
813
   return NULL;
785
824
    *   EGL_BAD_PARAMETER.
786
825
    */
787
826
   _eglError(EGL_BAD_PARAMETER, "cannot create EGL pixmap surfaces on "
788
 
             "Wayland");
 
827
                                "Wayland");
789
828
   return NULL;
790
829
}
791
830
 
888
927
 
889
928
static void
890
929
create_dri_image_from_dmabuf_feedback(struct dri2_egl_surface *dri2_surf,
891
 
                                      unsigned int dri_image_format, uint32_t use_flags)
 
930
                                      unsigned int dri_image_format,
 
931
                                      uint32_t use_flags)
892
932
{
893
933
   struct dri2_egl_display *dri2_dpy =
894
934
      dri2_egl_display(dri2_surf->base.Resource.Display);
914
954
    * tranches whose target device differs from the main device, as compositors
915
955
    * do not expose (in dma-buf feedback tranches) formats/modifiers that are
916
956
    * incompatible with the main device. */
917
 
   util_dynarray_foreach(&dri2_surf->dmabuf_feedback.tranches,
918
 
                         struct dmabuf_feedback_tranche, tranche) {
 
957
   util_dynarray_foreach (&dri2_surf->dmabuf_feedback.tranches,
 
958
                          struct dmabuf_feedback_tranche, tranche) {
919
959
      /* Ignore tranches that do not contain dri2_surf->format */
920
960
      if (!BITSET_TEST(tranche->formats.formats_bitmap, visual_idx))
921
961
         continue;
934
974
      if (tranche->flags & ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT)
935
975
         flags |= __DRI_IMAGE_USE_SCANOUT;
936
976
 
937
 
      dri2_surf->back->dri_image =
938
 
         loader_dri_create_image(dri2_dpy->dri_screen_render_gpu, dri2_dpy->image,
939
 
                                 dri2_surf->base.Width,
940
 
                                 dri2_surf->base.Height,
941
 
                                 dri_image_format,
942
 
                                 (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) ? 0 : flags,
943
 
                                 modifiers, num_modifiers, NULL);
 
977
      dri2_surf->back->dri_image = loader_dri_create_image(
 
978
         dri2_dpy->dri_screen_render_gpu, dri2_dpy->image,
 
979
         dri2_surf->base.Width, dri2_surf->base.Height, dri_image_format,
 
980
         (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) ? 0 : flags,
 
981
         modifiers, num_modifiers, NULL);
944
982
 
945
983
      if (dri2_surf->back->dri_image)
946
984
         return;
972
1010
   /* If our DRIImage implementation does not support createImageWithModifiers,
973
1011
    * then fall back to the old createImage, and hope it allocates an image
974
1012
    * which is acceptable to the winsys. */
975
 
   dri2_surf->back->dri_image =
976
 
      loader_dri_create_image(dri2_dpy->dri_screen_render_gpu, dri2_dpy->image,
977
 
                              dri2_surf->base.Width,
978
 
                              dri2_surf->base.Height,
979
 
                              dri_image_format,
980
 
                              (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) ? 0 : use_flags,
981
 
                              modifiers, num_modifiers, NULL);
 
1013
   dri2_surf->back->dri_image = loader_dri_create_image(
 
1014
      dri2_dpy->dri_screen_render_gpu, dri2_dpy->image, dri2_surf->base.Width,
 
1015
      dri2_surf->base.Height, dri_image_format,
 
1016
      (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) ? 0 : use_flags,
 
1017
      modifiers, num_modifiers, NULL);
982
1018
}
983
1019
 
984
1020
static int
998
1034
 
999
1035
   /* Substitute dri image format if server does not support original format */
1000
1036
   if (!BITSET_TEST(dri2_dpy->formats.formats_bitmap, visual_idx))
1001
 
      linear_dri_image_format = dri2_wl_visuals[visual_idx].alt_dri_image_format;
 
1037
      linear_dri_image_format =
 
1038
         dri2_wl_visuals[visual_idx].alt_dri_image_format;
1002
1039
 
1003
1040
   /* These asserts hold, as long as dri2_wl_visuals[] is self-consistent and
1004
1041
    * the PRIME substitution logic in dri2_wl_add_configs_for_visuals() is free
1005
1042
    * of bugs.
1006
1043
    */
1007
1044
   assert(linear_dri_image_format != __DRI_IMAGE_FORMAT_NONE);
1008
 
   assert(BITSET_TEST(dri2_dpy->formats.formats_bitmap,
1009
 
          dri2_wl_visual_idx_from_dri_image_format(linear_dri_image_format)));
 
1045
   assert(BITSET_TEST(
 
1046
      dri2_dpy->formats.formats_bitmap,
 
1047
      dri2_wl_visual_idx_from_dri_image_format(linear_dri_image_format)));
1010
1048
 
1011
1049
   /* There might be a buffer release already queued that wasn't processed */
1012
1050
   wl_display_dispatch_queue_pending(dri2_dpy->wl_dpy, dri2_surf->wl_queue);
1019
1057
         if (dri2_surf->color_buffers[i].locked)
1020
1058
            continue;
1021
1059
 
1022
 
         if (!dri2_surf->back ||
1023
 
             !dri2_surf->back->dri_image ||
 
1060
         if (!dri2_surf->back || !dri2_surf->back->dri_image ||
1024
1061
             (dri2_surf->color_buffers[i].age > 0 &&
1025
1062
              dri2_surf->color_buffers[i].age < dri2_surf->back->age))
1026
1063
            dri2_surf->back = &dri2_surf->color_buffers[i];
1035
1072
       * event. So, we spam the server with roundtrips as they always cause a
1036
1073
       * client flush.
1037
1074
       */
1038
 
      if (wl_display_roundtrip_queue(dri2_dpy->wl_dpy,
1039
 
                                     dri2_surf->wl_queue) < 0)
1040
 
          return -1;
 
1075
      if (wl_display_roundtrip_queue(dri2_dpy->wl_dpy, dri2_surf->wl_queue) < 0)
 
1076
         return -1;
1041
1077
   }
1042
1078
 
1043
1079
   if (dri2_surf->back == NULL)
1058
1094
      __DRIimage *linear_copy_display_gpu_image = NULL;
1059
1095
 
1060
1096
      if (dri2_dpy->dri_screen_display_gpu) {
1061
 
         linear_copy_display_gpu_image =
1062
 
               loader_dri_create_image(dri2_dpy->dri_screen_display_gpu,
1063
 
                                       dri2_dpy->image,
1064
 
                                       dri2_surf->base.Width,
1065
 
                                       dri2_surf->base.Height,
1066
 
                                       linear_dri_image_format,
1067
 
                                       use_flags | __DRI_IMAGE_USE_LINEAR,
1068
 
                                       &linear_mod, 1, NULL);
 
1097
         linear_copy_display_gpu_image = loader_dri_create_image(
 
1098
            dri2_dpy->dri_screen_display_gpu, dri2_dpy->image,
 
1099
            dri2_surf->base.Width, dri2_surf->base.Height,
 
1100
            linear_dri_image_format, use_flags | __DRI_IMAGE_USE_LINEAR,
 
1101
            &linear_mod, 1, NULL);
1069
1102
 
1070
1103
         if (linear_copy_display_gpu_image) {
1071
1104
            int i, ret;
1075
1108
            int offsets[4];
1076
1109
 
1077
1110
            if (!dri2_dpy->image->queryImage(linear_copy_display_gpu_image,
1078
 
                                             __DRI_IMAGE_ATTRIB_NUM_PLANES, &num_planes))
 
1111
                                             __DRI_IMAGE_ATTRIB_NUM_PLANES,
 
1112
                                             &num_planes))
1079
1113
               num_planes = 1;
1080
1114
 
1081
1115
            for (i = 0; i < num_planes; i++) {
1082
1116
               __DRIimage *image = dri2_dpy->image->fromPlanar(
1083
 
                                      linear_copy_display_gpu_image, i, NULL);
 
1117
                  linear_copy_display_gpu_image, i, NULL);
1084
1118
 
1085
1119
               if (!image) {
1086
1120
                  assert(i == 0);
1090
1124
               buffer_fds[i] = -1;
1091
1125
               ret = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FD,
1092
1126
                                                 &buffer_fds[i]);
1093
 
               ret &= dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE,
1094
 
                                                  &strides[i]);
1095
 
               ret &= dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_OFFSET,
1096
 
                                                  &offsets[i]);
 
1127
               ret &= dri2_dpy->image->queryImage(
 
1128
                  image, __DRI_IMAGE_ATTRIB_STRIDE, &strides[i]);
 
1129
               ret &= dri2_dpy->image->queryImage(
 
1130
                  image, __DRI_IMAGE_ATTRIB_OFFSET, &offsets[i]);
1097
1131
 
1098
1132
               if (image != linear_copy_display_gpu_image)
1099
1133
                  dri2_dpy->image->destroyImage(image);
1111
1145
            /* The linear buffer was created in the display GPU's vram, so we
1112
1146
             * need to make it visible to render GPU
1113
1147
             */
1114
 
            dri2_surf->back->linear_copy =
1115
 
               dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen_render_gpu,
1116
 
                                                   dri2_surf->base.Width,
1117
 
                                                   dri2_surf->base.Height,
1118
 
                                                   loader_image_format_to_fourcc(
1119
 
                                                      linear_dri_image_format),
1120
 
                                                   &buffer_fds[0], num_planes,
1121
 
                                                   &strides[0],
1122
 
                                                   &offsets[0],
1123
 
                                                   dri2_surf->back);
 
1148
            dri2_surf->back->linear_copy = dri2_dpy->image->createImageFromFds(
 
1149
               dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
 
1150
               dri2_surf->base.Height,
 
1151
               loader_image_format_to_fourcc(linear_dri_image_format),
 
1152
               &buffer_fds[0], num_planes, &strides[0], &offsets[0],
 
1153
               dri2_surf->back);
1124
1154
            for (i = 0; i < num_planes; ++i) {
1125
1155
               if (buffer_fds[i] != -1)
1126
1156
                  close(buffer_fds[i]);
1130
1160
      }
1131
1161
 
1132
1162
      if (!dri2_surf->back->linear_copy) {
1133
 
         dri2_surf->back->linear_copy =
1134
 
               loader_dri_create_image(dri2_dpy->dri_screen_render_gpu, dri2_dpy->image,
1135
 
                                       dri2_surf->base.Width,
1136
 
                                       dri2_surf->base.Height,
1137
 
                                       linear_dri_image_format,
1138
 
                                       use_flags | __DRI_IMAGE_USE_LINEAR,
1139
 
                                       &linear_mod, 1, NULL);
 
1163
         dri2_surf->back->linear_copy = loader_dri_create_image(
 
1164
            dri2_dpy->dri_screen_render_gpu, dri2_dpy->image,
 
1165
            dri2_surf->base.Width, dri2_surf->base.Height,
 
1166
            linear_dri_image_format, use_flags | __DRI_IMAGE_USE_LINEAR,
 
1167
            &linear_mod, 1, NULL);
1140
1168
      }
1141
1169
 
1142
1170
      if (dri2_surf->back->linear_copy == NULL)
1145
1173
 
1146
1174
   if (dri2_surf->back->dri_image == NULL) {
1147
1175
      if (dri2_surf->wl_dmabuf_feedback)
1148
 
         create_dri_image_from_dmabuf_feedback(dri2_surf, dri_image_format, use_flags);
 
1176
         create_dri_image_from_dmabuf_feedback(dri2_surf, dri_image_format,
 
1177
                                               use_flags);
1149
1178
      if (dri2_surf->back->dri_image == NULL)
1150
1179
         create_dri_image(dri2_surf, dri_image_format, use_flags);
1151
1180
      dri2_surf->back->age = 0;
1159
1188
   return 0;
1160
1189
}
1161
1190
 
1162
 
 
1163
1191
static void
1164
1192
back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
1165
1193
{
1196
1224
       (dri2_surf->base.Width != dri2_surf->wl_win->width ||
1197
1225
        dri2_surf->base.Height != dri2_surf->wl_win->height)) {
1198
1226
 
1199
 
      dri2_surf->base.Width  = dri2_surf->wl_win->width;
 
1227
      dri2_surf->base.Width = dri2_surf->wl_win->width;
1200
1228
      dri2_surf->base.Height = dri2_surf->wl_win->height;
1201
1229
      dri2_surf->dx = dri2_surf->wl_win->dx;
1202
1230
      dri2_surf->dy = dri2_surf->wl_win->dy;
1225
1253
         wl_buffer_destroy(dri2_surf->color_buffers[i].wl_buffer);
1226
1254
         dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].dri_image);
1227
1255
         if (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu)
1228
 
            dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].linear_copy);
 
1256
            dri2_dpy->image->destroyImage(
 
1257
               dri2_surf->color_buffers[i].linear_copy);
1229
1258
         dri2_surf->color_buffers[i].wl_buffer = NULL;
1230
1259
         dri2_surf->color_buffers[i].dri_image = NULL;
1231
1260
         dri2_surf->color_buffers[i].linear_copy = NULL;
1246
1275
}
1247
1276
 
1248
1277
static __DRIbuffer *
1249
 
dri2_wl_get_buffers_with_format(__DRIdrawable * driDrawable,
1250
 
                                int *width, int *height,
1251
 
                                unsigned int *attachments, int count,
1252
 
                                int *out_count, void *loaderPrivate)
 
1278
dri2_wl_get_buffers_with_format(__DRIdrawable *driDrawable, int *width,
 
1279
                                int *height, unsigned int *attachments,
 
1280
                                int count, int *out_count, void *loaderPrivate)
1253
1281
{
1254
1282
   struct dri2_egl_surface *dri2_surf = loaderPrivate;
1255
1283
   int i, j;
1288
1316
}
1289
1317
 
1290
1318
static __DRIbuffer *
1291
 
dri2_wl_get_buffers(__DRIdrawable * driDrawable,
1292
 
                    int *width, int *height,
1293
 
                    unsigned int *attachments, int count,
1294
 
                    int *out_count, void *loaderPrivate)
 
1319
dri2_wl_get_buffers(__DRIdrawable *driDrawable, int *width, int *height,
 
1320
                    unsigned int *attachments, int count, int *out_count,
 
1321
                    void *loaderPrivate)
1295
1322
{
1296
1323
   struct dri2_egl_surface *dri2_surf = loaderPrivate;
1297
1324
   unsigned int *attachments_with_format;
1308
1335
   }
1309
1336
 
1310
1337
   for (int i = 0; i < count; ++i) {
1311
 
      attachments_with_format[2*i] = attachments[i];
1312
 
      attachments_with_format[2*i + 1] = dri2_wl_visuals[visual_idx].bpp;
 
1338
      attachments_with_format[2 * i] = attachments[i];
 
1339
      attachments_with_format[2 * i + 1] = dri2_wl_visuals[visual_idx].bpp;
1313
1340
   }
1314
1341
 
1315
 
   buffer =
1316
 
      dri2_wl_get_buffers_with_format(driDrawable,
1317
 
                                      width, height,
1318
 
                                      attachments_with_format, count,
1319
 
                                      out_count, loaderPrivate);
 
1342
   buffer = dri2_wl_get_buffers_with_format(driDrawable, width, height,
 
1343
                                            attachments_with_format, count,
 
1344
                                            out_count, loaderPrivate);
1320
1345
 
1321
1346
   free(attachments_with_format);
1322
1347
 
1324
1349
}
1325
1350
 
1326
1351
static int
1327
 
image_get_buffers(__DRIdrawable *driDrawable,
1328
 
                  unsigned int format,
1329
 
                  uint32_t *stamp,
1330
 
                  void *loaderPrivate,
1331
 
                  uint32_t buffer_mask,
 
1352
image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
 
1353
                  uint32_t *stamp, void *loaderPrivate, uint32_t buffer_mask,
1332
1354
                  struct __DRIimageList *buffers)
1333
1355
{
1334
1356
   struct dri2_egl_surface *dri2_surf = loaderPrivate;
1343
1365
}
1344
1366
 
1345
1367
static void
1346
 
dri2_wl_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
 
1368
dri2_wl_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate)
1347
1369
{
1348
 
   (void) driDrawable;
1349
 
   (void) loaderPrivate;
 
1370
   (void)driDrawable;
 
1371
   (void)loaderPrivate;
1350
1372
}
1351
1373
 
1352
1374
static unsigned
1363
1385
}
1364
1386
 
1365
1387
static const __DRIdri2LoaderExtension dri2_loader_extension = {
1366
 
   .base = { __DRI_DRI2_LOADER, 4 },
 
1388
   .base = {__DRI_DRI2_LOADER, 4},
1367
1389
 
1368
 
   .getBuffers           = dri2_wl_get_buffers,
1369
 
   .flushFrontBuffer     = dri2_wl_flush_front_buffer,
 
1390
   .getBuffers = dri2_wl_get_buffers,
 
1391
   .flushFrontBuffer = dri2_wl_flush_front_buffer,
1370
1392
   .getBuffersWithFormat = dri2_wl_get_buffers_with_format,
1371
 
   .getCapability        = dri2_wl_get_capability,
 
1393
   .getCapability = dri2_wl_get_capability,
1372
1394
};
1373
1395
 
1374
1396
static const __DRIimageLoaderExtension image_loader_extension = {
1375
 
   .base = { __DRI_IMAGE_LOADER, 2 },
 
1397
   .base = {__DRI_IMAGE_LOADER, 2},
1376
1398
 
1377
 
   .getBuffers          = image_get_buffers,
1378
 
   .flushFrontBuffer    = dri2_wl_flush_front_buffer,
1379
 
   .getCapability       = dri2_wl_get_capability,
 
1399
   .getBuffers = image_get_buffers,
 
1400
   .flushFrontBuffer = dri2_wl_flush_front_buffer,
 
1401
   .getCapability = dri2_wl_get_capability,
1380
1402
};
1381
1403
 
1382
1404
static void
1383
 
wayland_throttle_callback(void *data,
1384
 
                          struct wl_callback *callback,
 
1405
wayland_throttle_callback(void *data, struct wl_callback *callback,
1385
1406
                          uint32_t time)
1386
1407
{
1387
1408
   struct dri2_egl_surface *dri2_surf = data;
1391
1412
}
1392
1413
 
1393
1414
static const struct wl_callback_listener throttle_listener = {
1394
 
   .done = wayland_throttle_callback
1395
 
};
 
1415
   .done = wayland_throttle_callback};
1396
1416
 
1397
1417
static EGLBoolean
1398
 
get_fourcc(struct dri2_egl_display *dri2_dpy,
1399
 
           __DRIimage *image, int *fourcc)
 
1418
get_fourcc(struct dri2_egl_display *dri2_dpy, __DRIimage *image, int *fourcc)
1400
1419
{
1401
1420
   EGLBoolean query;
1402
1421
   int dri_format;
1403
1422
   int visual_idx;
1404
1423
 
1405
 
   query = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FOURCC,
1406
 
                                       fourcc);
 
1424
   query =
 
1425
      dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FOURCC, fourcc);
1407
1426
   if (query)
1408
1427
      return true;
1409
1428
 
1422
1441
 
1423
1442
static struct wl_buffer *
1424
1443
create_wl_buffer(struct dri2_egl_display *dri2_dpy,
1425
 
                 struct dri2_egl_surface *dri2_surf,
1426
 
                 __DRIimage *image)
 
1444
                 struct dri2_egl_surface *dri2_surf, __DRIimage *image)
1427
1445
{
1428
1446
   struct wl_buffer *ret = NULL;
1429
1447
   EGLBoolean query;
1431
1449
   uint64_t modifier = DRM_FORMAT_MOD_INVALID;
1432
1450
 
1433
1451
   query = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_WIDTH, &width);
1434
 
   query &= dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_HEIGHT,
1435
 
                                        &height);
 
1452
   query &=
 
1453
      dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_HEIGHT, &height);
1436
1454
   query &= get_fourcc(dri2_dpy, image, &fourcc);
1437
1455
   if (!query)
1438
1456
      return NULL;
1445
1463
   if (dri2_dpy->image->base.version >= 15) {
1446
1464
      int mod_hi, mod_lo;
1447
1465
 
1448
 
      query = dri2_dpy->image->queryImage(image,
1449
 
                                          __DRI_IMAGE_ATTRIB_MODIFIER_UPPER,
1450
 
                                          &mod_hi);
1451
 
      query &= dri2_dpy->image->queryImage(image,
1452
 
                                           __DRI_IMAGE_ATTRIB_MODIFIER_LOWER,
1453
 
                                           &mod_lo);
 
1466
      query = dri2_dpy->image->queryImage(
 
1467
         image, __DRI_IMAGE_ATTRIB_MODIFIER_UPPER, &mod_hi);
 
1468
      query &= dri2_dpy->image->queryImage(
 
1469
         image, __DRI_IMAGE_ATTRIB_MODIFIER_LOWER, &mod_lo);
1454
1470
      if (query) {
1455
1471
         modifier = combine_u32_into_u64(mod_hi, mod_lo);
1456
1472
      }
1462
1478
   assert(visual_idx != -1);
1463
1479
 
1464
1480
   uint64_t *mod;
1465
 
   u_vector_foreach(mod, &dri2_dpy->formats.modifiers[visual_idx]) {
 
1481
   u_vector_foreach(mod, &dri2_dpy->formats.modifiers[visual_idx])
 
1482
   {
1466
1483
      if (*mod == DRM_FORMAT_MOD_INVALID) {
1467
1484
         mod_invalid_supported = true;
1468
1485
      }
1489
1506
       * and the wl_buffer inherits it race-free. */
1490
1507
      params = zwp_linux_dmabuf_v1_create_params(dri2_dpy->wl_dmabuf);
1491
1508
      if (dri2_surf)
1492
 
         wl_proxy_set_queue((struct wl_proxy *) params, dri2_surf->wl_queue);
 
1509
         wl_proxy_set_queue((struct wl_proxy *)params, dri2_surf->wl_queue);
1493
1510
 
1494
1511
      for (i = 0; i < num_planes; i++) {
1495
1512
         __DRIimage *p_image;
1502
1519
            p_image = image;
1503
1520
         }
1504
1521
 
1505
 
         query = dri2_dpy->image->queryImage(p_image,
1506
 
                                             __DRI_IMAGE_ATTRIB_FD,
1507
 
                                             &fd);
1508
 
         query &= dri2_dpy->image->queryImage(p_image,
1509
 
                                              __DRI_IMAGE_ATTRIB_STRIDE,
1510
 
                                              &stride);
1511
 
         query &= dri2_dpy->image->queryImage(p_image,
1512
 
                                              __DRI_IMAGE_ATTRIB_OFFSET,
1513
 
                                              &offset);
 
1522
         query =
 
1523
            dri2_dpy->image->queryImage(p_image, __DRI_IMAGE_ATTRIB_FD, &fd);
 
1524
         query &= dri2_dpy->image->queryImage(
 
1525
            p_image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
 
1526
         query &= dri2_dpy->image->queryImage(
 
1527
            p_image, __DRI_IMAGE_ATTRIB_OFFSET, &offset);
1514
1528
         if (image != p_image)
1515
1529
            dri2_dpy->image->destroyImage(p_image);
1516
1530
 
1538
1552
         return NULL;
1539
1553
 
1540
1554
      query = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FD, &fd);
1541
 
      query &= dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
 
1555
      query &=
 
1556
         dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
1542
1557
      if (!query) {
1543
1558
         if (fd >= 0)
1544
1559
            close(fd);
1554
1569
}
1555
1570
 
1556
1571
static EGLBoolean
1557
 
try_damage_buffer(struct dri2_egl_surface *dri2_surf,
1558
 
                  const EGLint *rects,
 
1572
try_damage_buffer(struct dri2_egl_surface *dri2_surf, const EGLint *rects,
1559
1573
                  EGLint n_rects)
1560
1574
{
1561
 
   if (wl_proxy_get_version((struct wl_proxy *) dri2_surf->wl_surface_wrapper)
1562
 
       < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION)
 
1575
   if (wl_proxy_get_version((struct wl_proxy *)dri2_surf->wl_surface_wrapper) <
 
1576
       WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION)
1563
1577
      return EGL_FALSE;
1564
1578
 
1565
1579
   for (int i = 0; i < n_rects; i++) {
1566
1580
      const int *rect = &rects[i * 4];
1567
1581
 
1568
 
      wl_surface_damage_buffer(dri2_surf->wl_surface_wrapper,
1569
 
                               rect[0],
 
1582
      wl_surface_damage_buffer(dri2_surf->wl_surface_wrapper, rect[0],
1570
1583
                               dri2_surf->base.Height - rect[1] - rect[3],
1571
1584
                               rect[2], rect[3]);
1572
1585
   }
1577
1590
 * Called via eglSwapBuffers(), drv->SwapBuffers().
1578
1591
 */
1579
1592
static EGLBoolean
1580
 
dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp,
1581
 
                                 _EGLSurface *draw,
1582
 
                                 const EGLint *rects,
1583
 
                                 EGLint n_rects)
 
1593
dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *draw,
 
1594
                                 const EGLint *rects, EGLint n_rects)
1584
1595
{
1585
1596
   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
1586
1597
   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
1602
1613
   dri2_dpy->flush->invalidate(dri2_surf->dri_drawable);
1603
1614
 
1604
1615
   while (dri2_surf->throttle_callback != NULL)
1605
 
      if (wl_display_dispatch_queue(dri2_dpy->wl_dpy,
1606
 
                                    dri2_surf->wl_queue) == -1)
 
1616
      if (wl_display_dispatch_queue(dri2_dpy->wl_dpy, dri2_surf->wl_queue) ==
 
1617
          -1)
1607
1618
         return -1;
1608
1619
 
1609
1620
   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++)
1618
1629
   if (draw->SwapInterval > 0) {
1619
1630
      dri2_surf->throttle_callback =
1620
1631
         wl_surface_frame(dri2_surf->wl_surface_wrapper);
1621
 
      wl_callback_add_listener(dri2_surf->throttle_callback,
1622
 
                               &throttle_listener, dri2_surf);
 
1632
      wl_callback_add_listener(dri2_surf->throttle_callback, &throttle_listener,
 
1633
                               dri2_surf);
1623
1634
   }
1624
1635
 
1625
1636
   dri2_surf->back->age = 1;
1639
1650
 
1640
1651
      dri2_surf->current->wl_release = false;
1641
1652
 
1642
 
      wl_buffer_add_listener(dri2_surf->current->wl_buffer,
1643
 
                             &wl_buffer_listener, dri2_surf);
 
1653
      wl_buffer_add_listener(dri2_surf->current->wl_buffer, &wl_buffer_listener,
 
1654
                             dri2_surf);
1644
1655
   }
1645
1656
 
1646
1657
   wl_surface_attach(dri2_surf->wl_surface_wrapper,
1647
 
                     dri2_surf->current->wl_buffer,
1648
 
                     dri2_surf->dx, dri2_surf->dy);
 
1658
                     dri2_surf->current->wl_buffer, dri2_surf->dx,
 
1659
                     dri2_surf->dy);
1649
1660
 
1650
 
   dri2_surf->wl_win->attached_width  = dri2_surf->base.Width;
 
1661
   dri2_surf->wl_win->attached_width = dri2_surf->base.Width;
1651
1662
   dri2_surf->wl_win->attached_height = dri2_surf->base.Height;
1652
1663
   /* reset resize growing parameters */
1653
1664
   dri2_surf->dx = 0;
1657
1668
    * ignore the damage region and post maximum damage, due to
1658
1669
    * https://bugs.freedesktop.org/78190 */
1659
1670
   if (!n_rects || !try_damage_buffer(dri2_surf, rects, n_rects))
1660
 
      wl_surface_damage(dri2_surf->wl_surface_wrapper,
1661
 
                        0, 0, INT32_MAX, INT32_MAX);
 
1671
      wl_surface_damage(dri2_surf->wl_surface_wrapper, 0, 0, INT32_MAX,
 
1672
                        INT32_MAX);
1662
1673
 
1663
1674
   if (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) {
1664
1675
      _EGLContext *ctx = _eglGetCurrentContext();
1665
1676
      struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
1666
 
      dri2_dpy->image->blitImage(dri2_ctx->dri_context,
1667
 
                                 dri2_surf->current->linear_copy,
1668
 
                                 dri2_surf->current->dri_image,
1669
 
                                 0, 0, dri2_surf->base.Width,
1670
 
                                 dri2_surf->base.Height,
1671
 
                                 0, 0, dri2_surf->base.Width,
1672
 
                                 dri2_surf->base.Height, 0);
 
1677
      dri2_dpy->image->blitImage(
 
1678
         dri2_ctx->dri_context, dri2_surf->current->linear_copy,
 
1679
         dri2_surf->current->dri_image, 0, 0, dri2_surf->base.Width,
 
1680
         dri2_surf->base.Height, 0, 0, dri2_surf->base.Width,
 
1681
         dri2_surf->base.Height, 0);
1673
1682
   }
1674
1683
 
1675
1684
   wl_surface_commit(dri2_surf->wl_surface_wrapper);
1680
1689
    * buffer */
1681
1690
   if (dri2_surf->throttle_callback == NULL) {
1682
1691
      dri2_surf->throttle_callback = wl_display_sync(dri2_surf->wl_dpy_wrapper);
1683
 
      wl_callback_add_listener(dri2_surf->throttle_callback,
1684
 
                               &throttle_listener, dri2_surf);
 
1692
      wl_callback_add_listener(dri2_surf->throttle_callback, &throttle_listener,
 
1693
                               dri2_surf);
1685
1694
   }
1686
1695
 
1687
1696
   wl_display_flush(dri2_dpy->wl_dpy);
1735
1744
    * buffer can get is a buffer release, which doesn't happen with an explicit
1736
1745
    * attach. */
1737
1746
   if (buffer)
1738
 
      wl_proxy_set_queue((struct wl_proxy *) buffer, NULL);
 
1747
      wl_proxy_set_queue((struct wl_proxy *)buffer, NULL);
1739
1748
 
1740
1749
   return buffer;
1741
1750
 
1836
1845
   .device = drm_handle_device,
1837
1846
   .format = drm_handle_format,
1838
1847
   .authenticated = drm_handle_authenticated,
1839
 
   .capabilities = drm_handle_capabilities
 
1848
   .capabilities = drm_handle_capabilities,
1840
1849
};
1841
1850
 
1842
1851
static void
1879
1888
static void
1880
1889
wl_drm_bind(struct dri2_egl_display *dri2_dpy)
1881
1890
{
1882
 
   dri2_dpy->wl_drm = wl_registry_bind(dri2_dpy->wl_registry, dri2_dpy->wl_drm_name,
1883
 
                                       &wl_drm_interface, dri2_dpy->wl_drm_version);
 
1891
   dri2_dpy->wl_drm =
 
1892
      wl_registry_bind(dri2_dpy->wl_registry, dri2_dpy->wl_drm_name,
 
1893
                       &wl_drm_interface, dri2_dpy->wl_drm_version);
1884
1894
   wl_drm_add_listener(dri2_dpy->wl_drm, &drm_listener, dri2_dpy);
1885
1895
}
1886
1896
 
1887
1897
static void
1888
 
default_dmabuf_feedback_format_table(void *data,
1889
 
                                     struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1,
1890
 
                                     int32_t fd, uint32_t size)
 
1898
default_dmabuf_feedback_format_table(
 
1899
   void *data,
 
1900
   struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1,
 
1901
   int32_t fd, uint32_t size)
1891
1902
{
1892
1903
   struct dri2_egl_display *dri2_dpy = data;
1893
1904
 
1894
1905
   dri2_dpy->format_table.size = size;
1895
 
   dri2_dpy->format_table.data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
 
1906
   dri2_dpy->format_table.data =
 
1907
      mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
1896
1908
 
1897
1909
   close(fd);
1898
1910
}
1899
1911
 
1900
1912
static void
1901
 
default_dmabuf_feedback_main_device(void *data,
1902
 
                                    struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
1903
 
                                    struct wl_array *device)
 
1913
default_dmabuf_feedback_main_device(
 
1914
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
 
1915
   struct wl_array *device)
1904
1916
{
1905
1917
   struct dri2_egl_display *dri2_dpy = data;
1906
1918
   char *node;
1924
1936
}
1925
1937
 
1926
1938
static void
1927
 
default_dmabuf_feedback_tranche_target_device(void *data,
1928
 
                                              struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
1929
 
                                              struct wl_array *device)
1930
 
{
1931
 
   /* ignore this event */
1932
 
}
1933
 
 
1934
 
static void
1935
 
default_dmabuf_feedback_tranche_flags(void *data,
1936
 
                                      struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
1937
 
                                      uint32_t flags)
1938
 
{
1939
 
   /* ignore this event */
1940
 
}
1941
 
 
1942
 
static void
1943
 
default_dmabuf_feedback_tranche_formats(void *data,
1944
 
                                        struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
1945
 
                                        struct wl_array *indices)
 
1939
default_dmabuf_feedback_tranche_target_device(
 
1940
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
 
1941
   struct wl_array *device)
 
1942
{
 
1943
   /* ignore this event */
 
1944
}
 
1945
 
 
1946
static void
 
1947
default_dmabuf_feedback_tranche_flags(
 
1948
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
 
1949
   uint32_t flags)
 
1950
{
 
1951
   /* ignore this event */
 
1952
}
 
1953
 
 
1954
static void
 
1955
default_dmabuf_feedback_tranche_formats(
 
1956
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback,
 
1957
   struct wl_array *indices)
1946
1958
{
1947
1959
   struct dri2_egl_display *dri2_dpy = data;
1948
1960
   uint64_t *modifier_ptr, modifier;
1957
1969
      return;
1958
1970
   }
1959
1971
   if (dri2_dpy->format_table.data == NULL) {
1960
 
      _eglLog(_EGL_WARNING, "wayland-egl: compositor didn't advertise a format "
1961
 
                            "table, so we won't be able to use this batch of dma-buf "
1962
 
                            "feedback events.");
 
1972
      _eglLog(_EGL_WARNING,
 
1973
              "wayland-egl: compositor didn't advertise a format "
 
1974
              "table, so we won't be able to use this batch of dma-buf "
 
1975
              "feedback events.");
1963
1976
      return;
1964
1977
   }
1965
1978
 
1966
 
   wl_array_for_each(index, indices) {
 
1979
   wl_array_for_each (index, indices) {
1967
1980
      format = dri2_dpy->format_table.data[*index].format;
1968
1981
      modifier = dri2_dpy->format_table.data[*index].modifier;
1969
1982
 
1980
1993
}
1981
1994
 
1982
1995
static void
1983
 
default_dmabuf_feedback_tranche_done(void *data,
1984
 
                                     struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback)
 
1996
default_dmabuf_feedback_tranche_done(
 
1997
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback)
1985
1998
{
1986
1999
   /* ignore this event */
1987
2000
}
1988
2001
 
1989
2002
static void
1990
 
default_dmabuf_feedback_done(void *data,
1991
 
                             struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback)
 
2003
default_dmabuf_feedback_done(
 
2004
   void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback)
1992
2005
{
1993
2006
   /* ignore this event */
1994
2007
}
1995
2008
 
1996
2009
static const struct zwp_linux_dmabuf_feedback_v1_listener
1997
 
dmabuf_feedback_listener = {
1998
 
   .format_table = default_dmabuf_feedback_format_table,
1999
 
   .main_device = default_dmabuf_feedback_main_device,
2000
 
   .tranche_target_device = default_dmabuf_feedback_tranche_target_device,
2001
 
   .tranche_flags = default_dmabuf_feedback_tranche_flags,
2002
 
   .tranche_formats = default_dmabuf_feedback_tranche_formats,
2003
 
   .tranche_done = default_dmabuf_feedback_tranche_done,
2004
 
   .done = default_dmabuf_feedback_done,
 
2010
   dmabuf_feedback_listener = {
 
2011
      .format_table = default_dmabuf_feedback_format_table,
 
2012
      .main_device = default_dmabuf_feedback_main_device,
 
2013
      .tranche_target_device = default_dmabuf_feedback_tranche_target_device,
 
2014
      .tranche_flags = default_dmabuf_feedback_tranche_flags,
 
2015
      .tranche_formats = default_dmabuf_feedback_tranche_formats,
 
2016
      .tranche_done = default_dmabuf_feedback_tranche_done,
 
2017
      .done = default_dmabuf_feedback_done,
2005
2018
};
2006
2019
 
2007
2020
static void
2014
2027
   if (strcmp(interface, wl_drm_interface.name) == 0) {
2015
2028
      dri2_dpy->wl_drm_version = MIN2(version, 2);
2016
2029
      dri2_dpy->wl_drm_name = name;
2017
 
   } else if (strcmp(interface, zwp_linux_dmabuf_v1_interface.name) == 0 && version >= 3) {
2018
 
      dri2_dpy->wl_dmabuf =
2019
 
         wl_registry_bind(registry, name, &zwp_linux_dmabuf_v1_interface,
2020
 
                          MIN2(version, ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION));
 
2030
   } else if (strcmp(interface, zwp_linux_dmabuf_v1_interface.name) == 0 &&
 
2031
              version >= 3) {
 
2032
      dri2_dpy->wl_dmabuf = wl_registry_bind(
 
2033
         registry, name, &zwp_linux_dmabuf_v1_interface,
 
2034
         MIN2(version, ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION));
2021
2035
      zwp_linux_dmabuf_v1_add_listener(dri2_dpy->wl_dmabuf, &dmabuf_listener,
2022
2036
                                       dri2_dpy);
2023
2037
   }
2031
2045
 
2032
2046
static const struct wl_registry_listener registry_listener_drm = {
2033
2047
   .global = registry_handle_global_drm,
2034
 
   .global_remove = registry_handle_global_remove
 
2048
   .global_remove = registry_handle_global_remove,
2035
2049
};
2036
2050
 
2037
2051
static void
2078
2092
dri2_wl_add_configs_for_visuals(_EGLDisplay *disp)
2079
2093
{
2080
2094
   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
2081
 
   unsigned int format_count[ARRAY_SIZE(dri2_wl_visuals)] = { 0 };
 
2095
   unsigned int format_count[ARRAY_SIZE(dri2_wl_visuals)] = {0};
2082
2096
   unsigned int count = 0;
2083
2097
   bool assigned;
2084
2098
 
2091
2105
         if (!BITSET_TEST(dri2_dpy->formats.formats_bitmap, j))
2092
2106
            continue;
2093
2107
 
2094
 
         dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i],
2095
 
               count + 1, EGL_WINDOW_BIT, NULL, dri2_wl_visuals[j].rgba_shifts, dri2_wl_visuals[j].rgba_sizes);
 
2108
         dri2_conf = dri2_add_config(
 
2109
            disp, dri2_dpy->driver_configs[i], count + 1, EGL_WINDOW_BIT, NULL,
 
2110
            dri2_wl_visuals[j].rgba_shifts, dri2_wl_visuals[j].rgba_sizes);
2096
2111
         if (dri2_conf) {
2097
2112
            if (dri2_conf->base.ConfigID == count + 1)
2098
2113
               count++;
2107
2122
 
2108
2123
         /* No match for config. Try if we can blitImage convert to a visual */
2109
2124
         c = dri2_wl_visual_idx_from_config(dri2_dpy,
2110
 
                                            dri2_dpy->driver_configs[i],
2111
 
                                            false);
 
2125
                                            dri2_dpy->driver_configs[i], false);
2112
2126
 
2113
2127
         if (c == -1)
2114
2128
            continue;
2124
2138
          * by our client gpu during PRIME blitImage conversion to a linear
2125
2139
          * wl_buffer, so add visual c as supported by the client renderer.
2126
2140
          */
2127
 
         dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i],
2128
 
                                     count + 1, EGL_WINDOW_BIT, NULL,
2129
 
                                     dri2_wl_visuals[c].rgba_shifts,
2130
 
                                     dri2_wl_visuals[c].rgba_sizes);
 
2141
         dri2_conf = dri2_add_config(
 
2142
            disp, dri2_dpy->driver_configs[i], count + 1, EGL_WINDOW_BIT, NULL,
 
2143
            dri2_wl_visuals[c].rgba_shifts, dri2_wl_visuals[c].rgba_sizes);
2131
2144
         if (dri2_conf) {
2132
2145
            if (dri2_conf->base.ConfigID == count + 1)
2133
2146
               count++;
2134
2147
            format_count[c]++;
2135
2148
            if (format_count[c] == 1)
2136
 
               _eglLog(_EGL_DEBUG, "Client format %s to server format %s via "
2137
 
                       "PRIME blitImage.", dri2_wl_visuals[c].format_name,
 
2149
               _eglLog(_EGL_DEBUG,
 
2150
                       "Client format %s to server format %s via "
 
2151
                       "PRIME blitImage.",
 
2152
                       dri2_wl_visuals[c].format_name,
2138
2153
                       dri2_wl_visuals[s].format_name);
2139
2154
         }
2140
2155
      }
2162
2177
 
2163
2178
   dri2_dpy->fd_render_gpu = -1;
2164
2179
   dri2_dpy->fd_display_gpu = -1;
2165
 
   disp->DriverData = (void *) dri2_dpy;
 
2180
   disp->DriverData = (void *)dri2_dpy;
2166
2181
 
2167
2182
   if (dri2_wl_formats_init(&dri2_dpy->formats) < 0)
2168
2183
      goto cleanup;
2182
2197
   if (dri2_dpy->wl_dpy_wrapper == NULL)
2183
2198
      goto cleanup;
2184
2199
 
2185
 
   wl_proxy_set_queue((struct wl_proxy *) dri2_dpy->wl_dpy_wrapper,
 
2200
   wl_proxy_set_queue((struct wl_proxy *)dri2_dpy->wl_dpy_wrapper,
2186
2201
                      dri2_dpy->wl_queue);
2187
2202
 
2188
2203
   if (dri2_dpy->own_device)
2189
2204
      wl_display_dispatch_pending(dri2_dpy->wl_dpy);
2190
2205
 
2191
2206
   dri2_dpy->wl_registry = wl_display_get_registry(dri2_dpy->wl_dpy_wrapper);
2192
 
   wl_registry_add_listener(dri2_dpy->wl_registry,
2193
 
                            &registry_listener_drm, dri2_dpy);
 
2207
   wl_registry_add_listener(dri2_dpy->wl_registry, &registry_listener_drm,
 
2208
                            dri2_dpy);
2194
2209
 
2195
2210
   if (roundtrip(dri2_dpy) < 0)
2196
2211
      goto cleanup;
2197
2212
 
2198
2213
   /* Get default dma-buf feedback */
2199
 
   if (dri2_dpy->wl_dmabuf && zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >=
2200
 
                              ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION) {
 
2214
   if (dri2_dpy->wl_dmabuf &&
 
2215
       zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >=
 
2216
          ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION) {
2201
2217
      dmabuf_feedback_format_table_init(&dri2_dpy->format_table);
2202
2218
      dri2_dpy->wl_dmabuf_feedback =
2203
2219
         zwp_linux_dmabuf_v1_get_default_feedback(dri2_dpy->wl_dmabuf);
2204
 
      zwp_linux_dmabuf_feedback_v1_add_listener(dri2_dpy->wl_dmabuf_feedback,
2205
 
                                                &dmabuf_feedback_listener, dri2_dpy);
 
2220
      zwp_linux_dmabuf_feedback_v1_add_listener(
 
2221
         dri2_dpy->wl_dmabuf_feedback, &dmabuf_feedback_listener, dri2_dpy);
2206
2222
   }
2207
2223
 
2208
2224
   if (roundtrip(dri2_dpy) < 0)
2233
2249
         goto cleanup;
2234
2250
   }
2235
2251
 
2236
 
   loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu, &dri2_dpy->fd_display_gpu);
 
2252
   loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu,
 
2253
                                &dri2_dpy->fd_display_gpu);
2237
2254
 
2238
2255
   dev = _eglAddDevice(dri2_dpy->fd_render_gpu, false);
2239
2256
   if (!dev) {
2245
2262
 
2246
2263
   if (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) {
2247
2264
      free(dri2_dpy->device_name);
2248
 
      dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu);
 
2265
      dri2_dpy->device_name =
 
2266
         loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu);
2249
2267
      if (!dri2_dpy->device_name) {
2250
2268
         _eglError(EGL_BAD_ALLOC, "wayland-egl: failed to get device name "
2251
2269
                                  "for requested GPU");
2257
2275
    * will return a render-node when the requested gpu is different
2258
2276
    * to the server, but also if the client asks for the same gpu than
2259
2277
    * the server by requesting its pci-id */
2260
 
   dri2_dpy->is_render_node = drmGetNodeTypeFromFd(dri2_dpy->fd_render_gpu) == DRM_NODE_RENDER;
 
2278
   dri2_dpy->is_render_node =
 
2279
      drmGetNodeTypeFromFd(dri2_dpy->fd_render_gpu) == DRM_NODE_RENDER;
2261
2280
 
2262
2281
   dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd_render_gpu);
2263
2282
   if (dri2_dpy->driver_name == NULL) {
2295
2314
      /* To use Prime, we must have _DRI_IMAGE v7 at least. createImageFromFds
2296
2315
       * support indicates that Prime export/import is supported by the driver.
2297
2316
       * We deprecated the support to GEM names API, so we bail out if the
2298
 
       * driver does not suport Prime. */
 
2317
       * driver does not support Prime. */
2299
2318
      if (!(dri2_dpy->capabilities & WL_DRM_CAPABILITY_PRIME) ||
2300
2319
          (dri2_dpy->image->base.version < 7) ||
2301
2320
          (dri2_dpy->image->createImageFromFds == NULL)) {
2322
2341
   dri2_set_WL_bind_wayland_display(disp);
2323
2342
   /* When cannot convert EGLImage to wl_buffer when on a different gpu,
2324
2343
    * because the buffer of the EGLImage has likely a tiling mode the server
2325
 
    * gpu won't support. These is no way to check for now. Thus do not support the
2326
 
    * extension */
 
2344
    * gpu won't support. These is no way to check for now. Thus do not support
 
2345
    * the extension */
2327
2346
   if (dri2_dpy->fd_render_gpu == dri2_dpy->fd_display_gpu)
2328
2347
      disp->Extensions.WL_create_wayland_buffer_from_image = EGL_TRUE;
2329
2348
 
2340
2359
 
2341
2360
   return EGL_TRUE;
2342
2361
 
2343
 
 cleanup:
 
2362
cleanup:
2344
2363
   dri2_display_destroy(disp);
2345
2364
   return EGL_FALSE;
2346
2365
}
2356
2375
}
2357
2376
 
2358
2377
static EGLBoolean
2359
 
dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface *dri2_surf,
2360
 
                               int format, int w, int h,
2361
 
                               void **data, int *size,
 
2378
dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface *dri2_surf, int format,
 
2379
                               int w, int h, void **data, int *size,
2362
2380
                               struct wl_buffer **buffer)
2363
2381
{
2364
2382
   struct dri2_egl_display *dri2_dpy =
2411
2429
      if (!zink)
2412
2430
         dri2_wl_release_buffers(dri2_surf);
2413
2431
 
2414
 
      dri2_surf->base.Width  = dri2_surf->wl_win->width;
 
2432
      dri2_surf->base.Width = dri2_surf->wl_win->width;
2415
2433
      dri2_surf->base.Height = dri2_surf->wl_win->height;
2416
2434
      dri2_surf->dx = dri2_surf->wl_win->dx;
2417
2435
      dri2_surf->dy = dri2_surf->wl_win->dy;
2436
2454
   }
2437
2455
 
2438
2456
   /* else choose any another free location */
2439
 
   if (!dri2_surf->back) {
 
2457
   while (!dri2_surf->back) {
2440
2458
      for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
2441
2459
         if (!dri2_surf->color_buffers[i].locked) {
2442
 
             dri2_surf->back = &dri2_surf->color_buffers[i];
2443
 
             if (zink)
2444
 
                continue;
2445
 
             if (!dri2_wl_swrast_allocate_buffer(dri2_surf,
2446
 
                                                 dri2_surf->format,
2447
 
                                                 dri2_surf->base.Width,
2448
 
                                                 dri2_surf->base.Height,
2449
 
                                                 &dri2_surf->back->data,
2450
 
                                                 &dri2_surf->back->data_size,
2451
 
                                                 &dri2_surf->back->wl_buffer)) {
2452
 
                _eglError(EGL_BAD_ALLOC, "failed to allocate color buffer");
2453
 
                 return -1;
2454
 
             }
2455
 
             wl_buffer_add_listener(dri2_surf->back->wl_buffer,
2456
 
                                    &wl_buffer_listener, dri2_surf);
2457
 
             break;
 
2460
            dri2_surf->back = &dri2_surf->color_buffers[i];
 
2461
            if (zink)
 
2462
               continue;
 
2463
            if (!dri2_wl_swrast_allocate_buffer(
 
2464
                   dri2_surf, dri2_surf->format, dri2_surf->base.Width,
 
2465
                   dri2_surf->base.Height, &dri2_surf->back->data,
 
2466
                   &dri2_surf->back->data_size, &dri2_surf->back->wl_buffer)) {
 
2467
               _eglError(EGL_BAD_ALLOC, "failed to allocate color buffer");
 
2468
               return -1;
 
2469
            }
 
2470
            wl_buffer_add_listener(dri2_surf->back->wl_buffer,
 
2471
                                   &wl_buffer_listener, dri2_surf);
 
2472
            break;
2458
2473
         }
2459
2474
      }
2460
 
   }
2461
2475
 
2462
 
   if (!dri2_surf->back) {
2463
 
      _eglError(EGL_BAD_ALLOC, "failed to find free buffer");
2464
 
      return -1;
 
2476
      /* wait for the compositor to release a buffer */
 
2477
      if (!dri2_surf->back) {
 
2478
         if (wl_display_dispatch_queue(dri2_dpy->wl_dpy, dri2_surf->wl_queue) ==
 
2479
             -1) {
 
2480
            _eglError(EGL_BAD_ALLOC, "waiting for a free buffer failed");
 
2481
            return -1;
 
2482
         }
 
2483
      }
2465
2484
   }
2466
2485
 
2467
2486
   dri2_surf->back->locked = true;
2489
2508
   return 0;
2490
2509
}
2491
2510
 
2492
 
static void*
 
2511
static void *
2493
2512
dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface *dri2_surf)
2494
2513
{
2495
2514
   /* if there has been a resize: */
2499
2518
   return dri2_surf->current->data;
2500
2519
}
2501
2520
 
2502
 
static void*
 
2521
static void *
2503
2522
dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface *dri2_surf)
2504
2523
{
2505
2524
   assert(dri2_surf->back);
2509
2528
static void
2510
2529
dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface *dri2_surf)
2511
2530
{
2512
 
   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display);
 
2531
   struct dri2_egl_display *dri2_dpy =
 
2532
      dri2_egl_display(dri2_surf->base.Resource.Display);
2513
2533
 
2514
2534
   while (dri2_surf->throttle_callback != NULL)
2515
 
      if (wl_display_dispatch_queue(dri2_dpy->wl_dpy,
2516
 
                                    dri2_surf->wl_queue) == -1)
 
2535
      if (wl_display_dispatch_queue(dri2_dpy->wl_dpy, dri2_surf->wl_queue) ==
 
2536
          -1)
2517
2537
         return;
2518
2538
 
2519
2539
   if (dri2_surf->base.SwapInterval > 0) {
2520
2540
      dri2_surf->throttle_callback =
2521
2541
         wl_surface_frame(dri2_surf->wl_surface_wrapper);
2522
 
      wl_callback_add_listener(dri2_surf->throttle_callback,
2523
 
                               &throttle_listener, dri2_surf);
 
2542
      wl_callback_add_listener(dri2_surf->throttle_callback, &throttle_listener,
 
2543
                               dri2_surf);
2524
2544
   }
2525
2545
 
2526
2546
   dri2_surf->current = dri2_surf->back;
2527
2547
   dri2_surf->back = NULL;
2528
2548
 
2529
2549
   wl_surface_attach(dri2_surf->wl_surface_wrapper,
2530
 
                     dri2_surf->current->wl_buffer,
2531
 
                     dri2_surf->dx, dri2_surf->dy);
 
2550
                     dri2_surf->current->wl_buffer, dri2_surf->dx,
 
2551
                     dri2_surf->dy);
2532
2552
 
2533
 
   dri2_surf->wl_win->attached_width  = dri2_surf->base.Width;
 
2553
   dri2_surf->wl_win->attached_width = dri2_surf->base.Width;
2534
2554
   dri2_surf->wl_win->attached_height = dri2_surf->base.Height;
2535
2555
   /* reset resize growing parameters */
2536
2556
   dri2_surf->dx = 0;
2537
2557
   dri2_surf->dy = 0;
2538
2558
 
2539
 
   wl_surface_damage(dri2_surf->wl_surface_wrapper,
2540
 
                     0, 0, INT32_MAX, INT32_MAX);
 
2559
   wl_surface_damage(dri2_surf->wl_surface_wrapper, 0, 0, INT32_MAX, INT32_MAX);
2541
2560
   wl_surface_commit(dri2_surf->wl_surface_wrapper);
2542
2561
 
2543
2562
   /* If we're not waiting for a frame callback then we'll at least throttle
2546
2565
    * buffer */
2547
2566
   if (dri2_surf->throttle_callback == NULL) {
2548
2567
      dri2_surf->throttle_callback = wl_display_sync(dri2_surf->wl_dpy_wrapper);
2549
 
      wl_callback_add_listener(dri2_surf->throttle_callback,
2550
 
                               &throttle_listener, dri2_surf);
 
2568
      wl_callback_add_listener(dri2_surf->throttle_callback, &throttle_listener,
 
2569
                               dri2_surf);
2551
2570
   }
2552
2571
 
2553
2572
   wl_display_flush(dri2_dpy->wl_dpy);
2554
2573
}
2555
2574
 
2556
2575
static void
2557
 
dri2_wl_swrast_get_drawable_info(__DRIdrawable * draw,
2558
 
                                 int *x, int *y, int *w, int *h,
2559
 
                                 void *loaderPrivate)
 
2576
dri2_wl_swrast_get_drawable_info(__DRIdrawable *draw, int *x, int *y, int *w,
 
2577
                                 int *h, void *loaderPrivate)
2560
2578
{
2561
2579
   struct dri2_egl_surface *dri2_surf = loaderPrivate;
2562
2580
 
2563
 
   (void) swrast_update_buffers(dri2_surf);
 
2581
   (void)swrast_update_buffers(dri2_surf);
2564
2582
   *x = 0;
2565
2583
   *y = 0;
2566
2584
   *w = dri2_surf->base.Width;
2568
2586
}
2569
2587
 
2570
2588
static void
2571
 
dri2_wl_swrast_get_image(__DRIdrawable * read,
2572
 
                         int x, int y, int w, int h,
 
2589
dri2_wl_swrast_get_image(__DRIdrawable *read, int x, int y, int w, int h,
2573
2590
                         char *data, void *loaderPrivate)
2574
2591
{
2575
2592
   struct dri2_egl_surface *dri2_surf = loaderPrivate;
2576
2593
   int copy_width = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, w);
2577
2594
   int x_offset = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, x);
2578
 
   int src_stride = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, dri2_surf->base.Width);
 
2595
   int src_stride = dri2_wl_swrast_get_stride_for_format(dri2_surf->format,
 
2596
                                                         dri2_surf->base.Width);
2579
2597
   int dst_stride = copy_width;
2580
2598
   char *src, *dst;
2581
2599
 
2592
2610
   src += y * src_stride;
2593
2611
   dst = data;
2594
2612
 
2595
 
   if (copy_width > src_stride-x_offset)
2596
 
      copy_width = src_stride-x_offset;
2597
 
   if (h > dri2_surf->base.Height-y)
2598
 
      h = dri2_surf->base.Height-y;
 
2613
   if (copy_width > src_stride - x_offset)
 
2614
      copy_width = src_stride - x_offset;
 
2615
   if (h > dri2_surf->base.Height - y)
 
2616
      h = dri2_surf->base.Height - y;
2599
2617
 
2600
 
   for (; h>0; h--) {
 
2618
   for (; h > 0; h--) {
2601
2619
      memcpy(dst, src, copy_width);
2602
2620
      src += src_stride;
2603
2621
      dst += dst_stride;
2605
2623
}
2606
2624
 
2607
2625
static void
2608
 
dri2_wl_swrast_put_image2(__DRIdrawable * draw, int op,
2609
 
                         int x, int y, int w, int h, int stride,
2610
 
                         char *data, void *loaderPrivate)
 
2626
dri2_wl_swrast_put_image2(__DRIdrawable *draw, int op, int x, int y, int w,
 
2627
                          int h, int stride, char *data, void *loaderPrivate)
2611
2628
{
2612
2629
   struct dri2_egl_surface *dri2_surf = loaderPrivate;
2613
2630
   int copy_width = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, w);
2614
 
   int dst_stride = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, dri2_surf->base.Width);
 
2631
   int dst_stride = dri2_wl_swrast_get_stride_for_format(dri2_surf->format,
 
2632
                                                         dri2_surf->base.Width);
2615
2633
   int x_offset = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, x);
2616
2634
   char *src, *dst;
2617
2635
 
2618
2636
   assert(copy_width <= stride);
2619
2637
 
2620
 
   (void) swrast_update_buffers(dri2_surf);
 
2638
   (void)swrast_update_buffers(dri2_surf);
2621
2639
   dst = dri2_wl_swrast_get_backbuffer_data(dri2_surf);
2622
2640
 
2623
2641
   /* partial copy, copy old content */
2624
2642
   if (copy_width < dst_stride)
2625
 
      dri2_wl_swrast_get_image(draw, 0, 0,
2626
 
                               dri2_surf->base.Width, dri2_surf->base.Height,
2627
 
                               dst, loaderPrivate);
 
2643
      dri2_wl_swrast_get_image(draw, 0, 0, dri2_surf->base.Width,
 
2644
                               dri2_surf->base.Height, dst, loaderPrivate);
2628
2645
 
2629
2646
   dst += x_offset;
2630
2647
   dst += y * dst_stride;
2632
2649
   src = data;
2633
2650
 
2634
2651
   /* drivers expect we do these checks (and some rely on it) */
2635
 
   if (copy_width > dst_stride-x_offset)
2636
 
      copy_width = dst_stride-x_offset;
2637
 
   if (h > dri2_surf->base.Height-y)
2638
 
      h = dri2_surf->base.Height-y;
 
2652
   if (copy_width > dst_stride - x_offset)
 
2653
      copy_width = dst_stride - x_offset;
 
2654
   if (h > dri2_surf->base.Height - y)
 
2655
      h = dri2_surf->base.Height - y;
2639
2656
 
2640
 
   for (; h>0; h--) {
 
2657
   for (; h > 0; h--) {
2641
2658
      memcpy(dst, src, copy_width);
2642
2659
      src += stride;
2643
2660
      dst += dst_stride;
2646
2663
}
2647
2664
 
2648
2665
static void
2649
 
dri2_wl_swrast_put_image(__DRIdrawable * draw, int op,
2650
 
                         int x, int y, int w, int h,
2651
 
                         char *data, void *loaderPrivate)
 
2666
dri2_wl_swrast_put_image(__DRIdrawable *draw, int op, int x, int y, int w,
 
2667
                         int h, char *data, void *loaderPrivate)
2652
2668
{
2653
2669
   struct dri2_egl_surface *dri2_surf = loaderPrivate;
2654
2670
   int stride;
2655
2671
 
2656
2672
   stride = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, w);
2657
 
   dri2_wl_swrast_put_image2(draw, op, x, y, w, h,
2658
 
                             stride, data, loaderPrivate);
 
2673
   dri2_wl_swrast_put_image2(draw, op, x, y, w, h, stride, data, loaderPrivate);
2659
2674
}
2660
2675
 
2661
2676
static EGLBoolean
2688
2703
}
2689
2704
 
2690
2705
static const struct wl_shm_listener shm_listener = {
2691
 
   .format = shm_handle_format
 
2706
   .format = shm_handle_format,
2692
2707
};
2693
2708
 
2694
2709
static void
2699
2714
   struct dri2_egl_display *dri2_dpy = data;
2700
2715
 
2701
2716
   if (strcmp(interface, wl_shm_interface.name) == 0) {
2702
 
      dri2_dpy->wl_shm =
2703
 
         wl_registry_bind(registry, name, &wl_shm_interface, 1);
 
2717
      dri2_dpy->wl_shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
2704
2718
      wl_shm_add_listener(dri2_dpy->wl_shm, &shm_listener, dri2_dpy);
2705
2719
   }
2706
2720
}
2707
2721
 
2708
2722
static const struct wl_registry_listener registry_listener_swrast = {
2709
2723
   .global = registry_handle_global_swrast,
2710
 
   .global_remove = registry_handle_global_remove
 
2724
   .global_remove = registry_handle_global_remove,
2711
2725
};
2712
2726
 
2713
2727
static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl = {
2721
2735
};
2722
2736
 
2723
2737
static const __DRIswrastLoaderExtension swrast_loader_extension = {
2724
 
   .base = { __DRI_SWRAST_LOADER, 2 },
 
2738
   .base = {__DRI_SWRAST_LOADER, 2},
2725
2739
 
2726
2740
   .getDrawableInfo = dri2_wl_swrast_get_drawable_info,
2727
 
   .putImage        = dri2_wl_swrast_put_image,
2728
 
   .getImage        = dri2_wl_swrast_get_image,
2729
 
   .putImage2       = dri2_wl_swrast_put_image2,
 
2741
   .putImage = dri2_wl_swrast_put_image,
 
2742
   .getImage = dri2_wl_swrast_get_image,
 
2743
   .putImage2 = dri2_wl_swrast_put_image2,
2730
2744
};
2731
2745
 
2732
 
static_assert(sizeof(struct kopper_vk_surface_create_storage) >= sizeof(VkWaylandSurfaceCreateInfoKHR), "");
 
2746
static_assert(sizeof(struct kopper_vk_surface_create_storage) >=
 
2747
                 sizeof(VkWaylandSurfaceCreateInfoKHR),
 
2748
              "");
2733
2749
 
2734
2750
static void
2735
2751
kopperSetSurfaceCreateInfo(void *_draw, struct kopper_loader_info *out)
2736
2752
{
2737
 
    struct dri2_egl_surface *dri2_surf = _draw;
2738
 
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display);
2739
 
    VkWaylandSurfaceCreateInfoKHR *wlsci = (VkWaylandSurfaceCreateInfoKHR *)&out->bos;
 
2753
   struct dri2_egl_surface *dri2_surf = _draw;
 
2754
   struct dri2_egl_display *dri2_dpy =
 
2755
      dri2_egl_display(dri2_surf->base.Resource.Display);
 
2756
   VkWaylandSurfaceCreateInfoKHR *wlsci =
 
2757
      (VkWaylandSurfaceCreateInfoKHR *)&out->bos;
2740
2758
 
2741
 
    wlsci->sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
2742
 
    wlsci->pNext = NULL;
2743
 
    wlsci->flags = 0;
2744
 
    wlsci->display = dri2_dpy->wl_dpy;
2745
 
    wlsci->surface = dri2_surf->wl_surface_wrapper;
 
2759
   wlsci->sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
 
2760
   wlsci->pNext = NULL;
 
2761
   wlsci->flags = 0;
 
2762
   wlsci->display = dri2_dpy->wl_dpy;
 
2763
   wlsci->surface = dri2_surf->wl_surface_wrapper;
2746
2764
}
2747
2765
 
2748
2766
static const __DRIkopperLoaderExtension kopper_loader_extension = {
2749
 
    .base = { __DRI_KOPPER_LOADER, 1 },
 
2767
   .base = {__DRI_KOPPER_LOADER, 1},
2750
2768
 
2751
 
    .SetSurfaceCreateInfo   = kopperSetSurfaceCreateInfo,
 
2769
   .SetSurfaceCreateInfo = kopperSetSurfaceCreateInfo,
2752
2770
};
2753
2771
static const __DRIextension *swrast_loader_extensions[] = {
2754
2772
   &swrast_loader_extension.base,
2768
2786
      return _eglError(EGL_BAD_ALLOC, "eglInitialize");
2769
2787
 
2770
2788
   dri2_dpy->fd_render_gpu = -1;
2771
 
   disp->DriverData = (void *) dri2_dpy;
 
2789
   dri2_dpy->fd_display_gpu = -1;
 
2790
   disp->DriverData = (void *)dri2_dpy;
2772
2791
 
2773
2792
   if (dri2_wl_formats_init(&dri2_dpy->formats) < 0)
2774
2793
      goto cleanup;
2796
2815
   if (dri2_dpy->wl_dpy_wrapper == NULL)
2797
2816
      goto cleanup;
2798
2817
 
2799
 
   wl_proxy_set_queue((struct wl_proxy *) dri2_dpy->wl_dpy_wrapper,
 
2818
   wl_proxy_set_queue((struct wl_proxy *)dri2_dpy->wl_dpy_wrapper,
2800
2819
                      dri2_dpy->wl_queue);
2801
2820
 
2802
2821
   if (dri2_dpy->own_device)
2803
2822
      wl_display_dispatch_pending(dri2_dpy->wl_dpy);
2804
2823
 
2805
2824
   dri2_dpy->wl_registry = wl_display_get_registry(dri2_dpy->wl_dpy_wrapper);
2806
 
   wl_registry_add_listener(dri2_dpy->wl_registry,
2807
 
                            &registry_listener_swrast, dri2_dpy);
 
2825
   wl_registry_add_listener(dri2_dpy->wl_registry, &registry_listener_swrast,
 
2826
                            dri2_dpy);
2808
2827
 
2809
2828
   if (roundtrip(dri2_dpy) < 0 || dri2_dpy->wl_shm == NULL)
2810
2829
      goto cleanup;
2811
2830
 
2812
 
   if (roundtrip(dri2_dpy) < 0 || !BITSET_TEST_RANGE(dri2_dpy->formats.formats_bitmap,
2813
 
                                                     0, dri2_dpy->formats.num_formats))
 
2831
   if (roundtrip(dri2_dpy) < 0 ||
 
2832
       !BITSET_TEST_RANGE(dri2_dpy->formats.formats_bitmap, 0,
 
2833
                          dri2_dpy->formats.num_formats))
2814
2834
      goto cleanup;
2815
2835
 
2816
2836
   dri2_dpy->driver_name = strdup(disp->Options.Zink ? "zink" : "swrast");
2841
2861
 
2842
2862
   return EGL_TRUE;
2843
2863
 
2844
 
 cleanup:
 
2864
cleanup:
2845
2865
   dri2_display_destroy(disp);
2846
2866
   return EGL_FALSE;
2847
2867
}