5550f580a8073765e913e3810e7506734133de6a
[mesa.git] / src / egl / drivers / dri2 / platform_android.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright (C) 2010-2011 LunarG Inc.
6 *
7 * Based on platform_x11, which has
8 *
9 * Copyright © 2011 Intel Corporation
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
28 */
29
30 #include <errno.h>
31 #include <dlfcn.h>
32 #include <fcntl.h>
33 #include <xf86drm.h>
34 #include <stdbool.h>
35 #include <sync/sync.h>
36
37 #include "loader.h"
38 #include "egl_dri2.h"
39 #include "egl_dri2_fallbacks.h"
40 #include "gralloc_drm.h"
41
42 #define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1))
43
44 struct droid_yuv_format {
45 /* Lookup keys */
46 int native; /* HAL_PIXEL_FORMAT_ */
47 int is_ycrcb; /* 0 if chroma order is {Cb, Cr}, 1 if {Cr, Cb} */
48 int chroma_step; /* Distance in bytes between subsequent chroma pixels. */
49
50 /* Result */
51 int fourcc; /* __DRI_IMAGE_FOURCC_ */
52 };
53
54 /* The following table is used to look up a DRI image FourCC based
55 * on native format and information contained in android_ycbcr struct. */
56 static const struct droid_yuv_format droid_yuv_formats[] = {
57 /* Native format, YCrCb, Chroma step, DRI image FourCC */
58 { HAL_PIXEL_FORMAT_YCbCr_420_888, 0, 2, __DRI_IMAGE_FOURCC_NV12 },
59 { HAL_PIXEL_FORMAT_YCbCr_420_888, 0, 1, __DRI_IMAGE_FOURCC_YUV420 },
60 { HAL_PIXEL_FORMAT_YCbCr_420_888, 1, 1, __DRI_IMAGE_FOURCC_YVU420 },
61 { HAL_PIXEL_FORMAT_YV12, 1, 1, __DRI_IMAGE_FOURCC_YVU420 },
62 };
63
64 static int
65 get_fourcc_yuv(int native, int is_ycrcb, int chroma_step)
66 {
67 int i;
68
69 for (i = 0; i < ARRAY_SIZE(droid_yuv_formats); ++i)
70 if (droid_yuv_formats[i].native == native &&
71 droid_yuv_formats[i].is_ycrcb == is_ycrcb &&
72 droid_yuv_formats[i].chroma_step == chroma_step)
73 return droid_yuv_formats[i].fourcc;
74
75 return -1;
76 }
77
78 static bool
79 is_yuv(int native)
80 {
81 int i;
82
83 for (i = 0; i < ARRAY_SIZE(droid_yuv_formats); ++i)
84 if (droid_yuv_formats[i].native == native)
85 return true;
86
87 return false;
88 }
89
90 static int
91 get_format_bpp(int native)
92 {
93 int bpp;
94
95 switch (native) {
96 case HAL_PIXEL_FORMAT_RGBA_8888:
97 case HAL_PIXEL_FORMAT_RGBX_8888:
98 case HAL_PIXEL_FORMAT_BGRA_8888:
99 bpp = 4;
100 break;
101 case HAL_PIXEL_FORMAT_RGB_565:
102 bpp = 2;
103 break;
104 default:
105 bpp = 0;
106 break;
107 }
108
109 return bpp;
110 }
111
112 /* createImageFromFds requires fourcc format */
113 static int get_fourcc(int native)
114 {
115 switch (native) {
116 case HAL_PIXEL_FORMAT_RGB_565: return __DRI_IMAGE_FOURCC_RGB565;
117 case HAL_PIXEL_FORMAT_BGRA_8888: return __DRI_IMAGE_FOURCC_ARGB8888;
118 case HAL_PIXEL_FORMAT_RGBA_8888: return __DRI_IMAGE_FOURCC_ABGR8888;
119 case HAL_PIXEL_FORMAT_RGBX_8888: return __DRI_IMAGE_FOURCC_XBGR8888;
120 default:
121 _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", native);
122 }
123 return -1;
124 }
125
126 static int get_format(int format)
127 {
128 switch (format) {
129 case HAL_PIXEL_FORMAT_BGRA_8888: return __DRI_IMAGE_FORMAT_ARGB8888;
130 case HAL_PIXEL_FORMAT_RGB_565: return __DRI_IMAGE_FORMAT_RGB565;
131 case HAL_PIXEL_FORMAT_RGBA_8888: return __DRI_IMAGE_FORMAT_ABGR8888;
132 case HAL_PIXEL_FORMAT_RGBX_8888: return __DRI_IMAGE_FORMAT_XBGR8888;
133 default:
134 _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
135 }
136 return -1;
137 }
138
139 static int
140 get_native_buffer_fd(struct ANativeWindowBuffer *buf)
141 {
142 native_handle_t *handle = (native_handle_t *)buf->handle;
143 /*
144 * Various gralloc implementations exist, but the dma-buf fd tends
145 * to be first. Access it directly to avoid a dependency on specific
146 * gralloc versions.
147 */
148 return (handle && handle->numFds) ? handle->data[0] : -1;
149 }
150
151 static int
152 get_native_buffer_name(struct ANativeWindowBuffer *buf)
153 {
154 return gralloc_drm_get_gem_handle(buf->handle);
155 }
156
157 static EGLBoolean
158 droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
159 {
160 int fence_fd;
161
162 if (dri2_surf->window->dequeueBuffer(dri2_surf->window, &dri2_surf->buffer,
163 &fence_fd))
164 return EGL_FALSE;
165
166 /* If access to the buffer is controlled by a sync fence, then block on the
167 * fence.
168 *
169 * It may be more performant to postpone blocking until there is an
170 * immediate need to write to the buffer. But doing so would require adding
171 * hooks to the DRI2 loader.
172 *
173 * From the ANativeWindow::dequeueBuffer documentation:
174 *
175 * The libsync fence file descriptor returned in the int pointed to by
176 * the fenceFd argument will refer to the fence that must signal
177 * before the dequeued buffer may be written to. A value of -1
178 * indicates that the caller may access the buffer immediately without
179 * waiting on a fence. If a valid file descriptor is returned (i.e.
180 * any value except -1) then the caller is responsible for closing the
181 * file descriptor.
182 */
183 if (fence_fd >= 0) {
184 /* From the SYNC_IOC_WAIT documentation in <linux/sync.h>:
185 *
186 * Waits indefinitely if timeout < 0.
187 */
188 int timeout = -1;
189 sync_wait(fence_fd, timeout);
190 close(fence_fd);
191 }
192
193 dri2_surf->buffer->common.incRef(&dri2_surf->buffer->common);
194
195 /* Record all the buffers created by ANativeWindow and update back buffer
196 * for updating buffer's age in swap_buffers.
197 */
198 EGLBoolean updated = EGL_FALSE;
199 for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
200 if (!dri2_surf->color_buffers[i].buffer) {
201 dri2_surf->color_buffers[i].buffer = dri2_surf->buffer;
202 }
203 if (dri2_surf->color_buffers[i].buffer == dri2_surf->buffer) {
204 dri2_surf->back = &dri2_surf->color_buffers[i];
205 updated = EGL_TRUE;
206 break;
207 }
208 }
209
210 if (!updated) {
211 /* In case of all the buffers were recreated by ANativeWindow, reset
212 * the color_buffers
213 */
214 for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
215 dri2_surf->color_buffers[i].buffer = NULL;
216 dri2_surf->color_buffers[i].age = 0;
217 }
218 dri2_surf->color_buffers[0].buffer = dri2_surf->buffer;
219 dri2_surf->back = &dri2_surf->color_buffers[0];
220 }
221
222 return EGL_TRUE;
223 }
224
225 static EGLBoolean
226 droid_window_enqueue_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_surf)
227 {
228 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
229
230 /* To avoid blocking other EGL calls, release the display mutex before
231 * we enter droid_window_enqueue_buffer() and re-acquire the mutex upon
232 * return.
233 */
234 mtx_unlock(&disp->Mutex);
235
236 /* Queue the buffer without a sync fence. This informs the ANativeWindow
237 * that it may access the buffer immediately.
238 *
239 * From ANativeWindow::dequeueBuffer:
240 *
241 * The fenceFd argument specifies a libsync fence file descriptor for
242 * a fence that must signal before the buffer can be accessed. If
243 * the buffer can be accessed immediately then a value of -1 should
244 * be used. The caller must not use the file descriptor after it
245 * is passed to queueBuffer, and the ANativeWindow implementation
246 * is responsible for closing it.
247 */
248 int fence_fd = -1;
249 dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer,
250 fence_fd);
251
252 dri2_surf->buffer->common.decRef(&dri2_surf->buffer->common);
253 dri2_surf->buffer = NULL;
254 dri2_surf->back = NULL;
255
256 mtx_lock(&disp->Mutex);
257
258 if (dri2_surf->dri_image_back) {
259 dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
260 dri2_surf->dri_image_back = NULL;
261 }
262
263 return EGL_TRUE;
264 }
265
266 static void
267 droid_window_cancel_buffer(struct dri2_egl_surface *dri2_surf)
268 {
269 int ret;
270
271 ret = dri2_surf->window->cancelBuffer(dri2_surf->window, dri2_surf->buffer, -1);
272 if (ret < 0) {
273 _eglLog(_EGL_WARNING, "ANativeWindow::cancelBuffer failed");
274 dri2_surf->base.Lost = EGL_TRUE;
275 }
276 }
277
278 static __DRIbuffer *
279 droid_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
280 unsigned int att, unsigned int format)
281 {
282 struct dri2_egl_display *dri2_dpy =
283 dri2_egl_display(dri2_surf->base.Resource.Display);
284
285 if (att >= ARRAY_SIZE(dri2_surf->local_buffers))
286 return NULL;
287
288 if (!dri2_surf->local_buffers[att]) {
289 dri2_surf->local_buffers[att] =
290 dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen, att, format,
291 dri2_surf->base.Width, dri2_surf->base.Height);
292 }
293
294 return dri2_surf->local_buffers[att];
295 }
296
297 static void
298 droid_free_local_buffers(struct dri2_egl_surface *dri2_surf)
299 {
300 struct dri2_egl_display *dri2_dpy =
301 dri2_egl_display(dri2_surf->base.Resource.Display);
302 int i;
303
304 for (i = 0; i < ARRAY_SIZE(dri2_surf->local_buffers); i++) {
305 if (dri2_surf->local_buffers[i]) {
306 dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen,
307 dri2_surf->local_buffers[i]);
308 dri2_surf->local_buffers[i] = NULL;
309 }
310 }
311 }
312
313 static _EGLSurface *
314 droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
315 _EGLConfig *conf, void *native_window,
316 const EGLint *attrib_list)
317 {
318 __DRIcreateNewDrawableFunc createNewDrawable;
319 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
320 struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);
321 struct dri2_egl_surface *dri2_surf;
322 struct ANativeWindow *window = native_window;
323 const __DRIconfig *config;
324
325 dri2_surf = calloc(1, sizeof *dri2_surf);
326 if (!dri2_surf) {
327 _eglError(EGL_BAD_ALLOC, "droid_create_surface");
328 return NULL;
329 }
330
331 if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list))
332 goto cleanup_surface;
333
334 if (type == EGL_WINDOW_BIT) {
335 int format;
336
337 if (!window || window->common.magic != ANDROID_NATIVE_WINDOW_MAGIC) {
338 _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface");
339 goto cleanup_surface;
340 }
341 if (window->query(window, NATIVE_WINDOW_FORMAT, &format)) {
342 _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface");
343 goto cleanup_surface;
344 }
345
346 if (format != dri2_conf->base.NativeVisualID) {
347 _eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x",
348 format, dri2_conf->base.NativeVisualID);
349 }
350
351 window->query(window, NATIVE_WINDOW_WIDTH, &dri2_surf->base.Width);
352 window->query(window, NATIVE_WINDOW_HEIGHT, &dri2_surf->base.Height);
353 }
354
355 config = dri2_get_dri_config(dri2_conf, type,
356 dri2_surf->base.GLColorspace);
357 if (!config)
358 goto cleanup_surface;
359
360 if (dri2_dpy->image_driver)
361 createNewDrawable = dri2_dpy->image_driver->createNewDrawable;
362 else
363 createNewDrawable = dri2_dpy->dri2->createNewDrawable;
364
365 dri2_surf->dri_drawable = (*createNewDrawable)(dri2_dpy->dri_screen, config,
366 dri2_surf);
367 if (dri2_surf->dri_drawable == NULL) {
368 _eglError(EGL_BAD_ALLOC, "createNewDrawable");
369 goto cleanup_surface;
370 }
371
372 if (window) {
373 window->common.incRef(&window->common);
374 dri2_surf->window = window;
375 }
376
377 return &dri2_surf->base;
378
379 cleanup_surface:
380 free(dri2_surf);
381
382 return NULL;
383 }
384
385 static _EGLSurface *
386 droid_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
387 _EGLConfig *conf, void *native_window,
388 const EGLint *attrib_list)
389 {
390 return droid_create_surface(drv, disp, EGL_WINDOW_BIT, conf,
391 native_window, attrib_list);
392 }
393
394 static _EGLSurface *
395 droid_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp,
396 _EGLConfig *conf, const EGLint *attrib_list)
397 {
398 return droid_create_surface(drv, disp, EGL_PBUFFER_BIT, conf,
399 NULL, attrib_list);
400 }
401
402 static EGLBoolean
403 droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
404 {
405 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
406 struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
407
408 droid_free_local_buffers(dri2_surf);
409
410 if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
411 if (dri2_surf->buffer)
412 droid_window_cancel_buffer(dri2_surf);
413
414 dri2_surf->window->common.decRef(&dri2_surf->window->common);
415 }
416
417 if (dri2_surf->dri_image_back) {
418 _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, __LINE__);
419 dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
420 dri2_surf->dri_image_back = NULL;
421 }
422
423 if (dri2_surf->dri_image_front) {
424 _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, __LINE__);
425 dri2_dpy->image->destroyImage(dri2_surf->dri_image_front);
426 dri2_surf->dri_image_front = NULL;
427 }
428
429 dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
430
431 free(dri2_surf);
432
433 return EGL_TRUE;
434 }
435
436 static int
437 update_buffers(struct dri2_egl_surface *dri2_surf)
438 {
439 if (dri2_surf->base.Lost)
440 return -1;
441
442 if (dri2_surf->base.Type != EGL_WINDOW_BIT)
443 return 0;
444
445 /* try to dequeue the next back buffer */
446 if (!dri2_surf->buffer && !droid_window_dequeue_buffer(dri2_surf)) {
447 _eglLog(_EGL_WARNING, "Could not dequeue buffer from native window");
448 dri2_surf->base.Lost = EGL_TRUE;
449 return -1;
450 }
451
452 /* free outdated buffers and update the surface size */
453 if (dri2_surf->base.Width != dri2_surf->buffer->width ||
454 dri2_surf->base.Height != dri2_surf->buffer->height) {
455 droid_free_local_buffers(dri2_surf);
456 dri2_surf->base.Width = dri2_surf->buffer->width;
457 dri2_surf->base.Height = dri2_surf->buffer->height;
458 }
459
460 return 0;
461 }
462
463 static int
464 get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
465 {
466 struct dri2_egl_display *dri2_dpy =
467 dri2_egl_display(dri2_surf->base.Resource.Display);
468
469 if (dri2_surf->dri_image_front)
470 return 0;
471
472 if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
473 /* According current EGL spec, front buffer rendering
474 * for window surface is not supported now.
475 * and mesa doesn't have the implementation of this case.
476 * Add warning message, but not treat it as error.
477 */
478 _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for window surface");
479 } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
480 dri2_surf->dri_image_front =
481 dri2_dpy->image->createImage(dri2_dpy->dri_screen,
482 dri2_surf->base.Width,
483 dri2_surf->base.Height,
484 format,
485 0,
486 dri2_surf);
487 if (!dri2_surf->dri_image_front) {
488 _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
489 return -1;
490 }
491 }
492
493 return 0;
494 }
495
496 static int
497 get_back_bo(struct dri2_egl_surface *dri2_surf)
498 {
499 struct dri2_egl_display *dri2_dpy =
500 dri2_egl_display(dri2_surf->base.Resource.Display);
501 int fourcc, pitch;
502 int offset = 0, fd;
503
504 if (dri2_surf->dri_image_back)
505 return 0;
506
507 if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
508 if (!dri2_surf->buffer) {
509 _eglLog(_EGL_WARNING, "Could not get native buffer");
510 return -1;
511 }
512
513 fd = get_native_buffer_fd(dri2_surf->buffer);
514 if (fd < 0) {
515 _eglLog(_EGL_WARNING, "Could not get native buffer FD");
516 return -1;
517 }
518
519 fourcc = get_fourcc(dri2_surf->buffer->format);
520
521 pitch = dri2_surf->buffer->stride *
522 get_format_bpp(dri2_surf->buffer->format);
523
524 if (fourcc == -1 || pitch == 0) {
525 _eglLog(_EGL_WARNING, "Invalid buffer fourcc(%x) or pitch(%d)",
526 fourcc, pitch);
527 return -1;
528 }
529
530 dri2_surf->dri_image_back =
531 dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen,
532 dri2_surf->base.Width,
533 dri2_surf->base.Height,
534 fourcc,
535 &fd,
536 1,
537 &pitch,
538 &offset,
539 dri2_surf);
540 if (!dri2_surf->dri_image_back) {
541 _eglLog(_EGL_WARNING, "failed to create DRI image from FD");
542 return -1;
543 }
544 } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
545 /* The EGL 1.5 spec states that pbuffers are single-buffered. Specifically,
546 * the spec states that they have a back buffer but no front buffer, in
547 * contrast to pixmaps, which have a front buffer but no back buffer.
548 *
549 * Single-buffered surfaces with no front buffer confuse Mesa; so we deviate
550 * from the spec, following the precedent of Mesa's EGL X11 platform. The
551 * X11 platform correctly assigns pbuffers to single-buffered configs, but
552 * assigns the pbuffer a front buffer instead of a back buffer.
553 *
554 * Pbuffers in the X11 platform mostly work today, so let's just copy its
555 * behavior instead of trying to fix (and hence potentially breaking) the
556 * world.
557 */
558 _eglLog(_EGL_DEBUG, "DRI driver requested unsupported back buffer for pbuffer surface");
559 }
560
561 return 0;
562 }
563
564 /* Some drivers will pass multiple bits in buffer_mask.
565 * For such case, will go through all the bits, and
566 * will not return error when unsupported buffer is requested, only
567 * return error when the allocation for supported buffer failed.
568 */
569 static int
570 droid_image_get_buffers(__DRIdrawable *driDrawable,
571 unsigned int format,
572 uint32_t *stamp,
573 void *loaderPrivate,
574 uint32_t buffer_mask,
575 struct __DRIimageList *images)
576 {
577 struct dri2_egl_surface *dri2_surf = loaderPrivate;
578
579 images->image_mask = 0;
580 images->front = NULL;
581 images->back = NULL;
582
583 if (update_buffers(dri2_surf) < 0)
584 return 0;
585
586 if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
587 if (get_front_bo(dri2_surf, format) < 0)
588 return 0;
589
590 if (dri2_surf->dri_image_front) {
591 images->front = dri2_surf->dri_image_front;
592 images->image_mask |= __DRI_IMAGE_BUFFER_FRONT;
593 }
594 }
595
596 if (buffer_mask & __DRI_IMAGE_BUFFER_BACK) {
597 if (get_back_bo(dri2_surf) < 0)
598 return 0;
599
600 if (dri2_surf->dri_image_back) {
601 images->back = dri2_surf->dri_image_back;
602 images->image_mask |= __DRI_IMAGE_BUFFER_BACK;
603 }
604 }
605
606 return 1;
607 }
608
609 static EGLint
610 droid_query_buffer_age(_EGLDriver *drv,
611 _EGLDisplay *disp, _EGLSurface *surface)
612 {
613 struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surface);
614
615 if (update_buffers(dri2_surf) < 0) {
616 _eglError(EGL_BAD_ALLOC, "droid_query_buffer_age");
617 return -1;
618 }
619
620 return dri2_surf->back ? dri2_surf->back->age : 0;
621 }
622
623 static EGLBoolean
624 droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
625 {
626 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
627 struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
628
629 if (dri2_surf->base.Type != EGL_WINDOW_BIT)
630 return EGL_TRUE;
631
632 for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
633 if (dri2_surf->color_buffers[i].age > 0)
634 dri2_surf->color_buffers[i].age++;
635 }
636
637 /* "XXX: we don't use get_back_bo() since it causes regressions in
638 * several dEQP tests.
639 */
640 if (dri2_surf->back)
641 dri2_surf->back->age = 1;
642
643 dri2_flush_drawable_for_swapbuffers(disp, draw);
644
645 /* dri2_surf->buffer can be null even when no error has occured. For
646 * example, if the user has called no GL rendering commands since the
647 * previous eglSwapBuffers, then the driver may have not triggered
648 * a callback to ANativeWindow::dequeueBuffer, in which case
649 * dri2_surf->buffer remains null.
650 */
651 if (dri2_surf->buffer)
652 droid_window_enqueue_buffer(disp, dri2_surf);
653
654 dri2_dpy->flush->invalidate(dri2_surf->dri_drawable);
655
656 return EGL_TRUE;
657 }
658
659 #if ANDROID_API_LEVEL >= 23
660 static EGLBoolean
661 droid_set_damage_region(_EGLDriver *drv,
662 _EGLDisplay *disp,
663 _EGLSurface *draw, const EGLint* rects, EGLint n_rects)
664 {
665 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
666 struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
667 android_native_rect_t* droid_rects = NULL;
668 int ret;
669
670 if (n_rects == 0)
671 return EGL_TRUE;
672
673 droid_rects = malloc(n_rects * sizeof(android_native_rect_t));
674 if (droid_rects == NULL) {
675 _eglError(EGL_BAD_ALLOC, "eglSetDamageRegionKHR");
676 return EGL_FALSE;
677 }
678
679 for (EGLint num_drects = 0; num_drects < n_rects; num_drects++) {
680 EGLint i = num_drects * 4;
681 droid_rects[num_drects].left = rects[i];
682 droid_rects[num_drects].bottom = rects[i + 1];
683 droid_rects[num_drects].right = rects[i] + rects[i + 2];
684 droid_rects[num_drects].top = rects[i + 1] + rects[i + 3];
685 }
686
687 /*
688 * XXX/TODO: Need to check for other return values
689 */
690
691 ret = native_window_set_surface_damage(dri2_surf->window, droid_rects, n_rects);
692 free(droid_rects);
693
694 return ret == 0 ? EGL_TRUE : EGL_FALSE;
695 }
696 #endif
697
698 static _EGLImage *
699 droid_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
700 struct ANativeWindowBuffer *buf, int fd)
701 {
702 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
703 struct android_ycbcr ycbcr;
704 size_t offsets[3];
705 size_t pitches[3];
706 int is_ycrcb;
707 int fourcc;
708 int ret;
709
710 if (!dri2_dpy->gralloc->lock_ycbcr) {
711 _eglLog(_EGL_WARNING, "Gralloc does not support lock_ycbcr");
712 return NULL;
713 }
714
715 memset(&ycbcr, 0, sizeof(ycbcr));
716 ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle,
717 0, 0, 0, 0, 0, &ycbcr);
718 if (ret) {
719 _eglLog(_EGL_WARNING, "gralloc->lock_ycbcr failed: %d", ret);
720 return NULL;
721 }
722 dri2_dpy->gralloc->unlock(dri2_dpy->gralloc, buf->handle);
723
724 /* When lock_ycbcr's usage argument contains no SW_READ/WRITE flags
725 * it will return the .y/.cb/.cr pointers based on a NULL pointer,
726 * so they can be interpreted as offsets. */
727 offsets[0] = (size_t)ycbcr.y;
728 /* We assume here that all the planes are located in one DMA-buf. */
729 is_ycrcb = (size_t)ycbcr.cr < (size_t)ycbcr.cb;
730 if (is_ycrcb) {
731 offsets[1] = (size_t)ycbcr.cr;
732 offsets[2] = (size_t)ycbcr.cb;
733 } else {
734 offsets[1] = (size_t)ycbcr.cb;
735 offsets[2] = (size_t)ycbcr.cr;
736 }
737
738 /* .ystride is the line length (in bytes) of the Y plane,
739 * .cstride is the line length (in bytes) of any of the remaining
740 * Cb/Cr/CbCr planes, assumed to be the same for Cb and Cr for fully
741 * planar formats. */
742 pitches[0] = ycbcr.ystride;
743 pitches[1] = pitches[2] = ycbcr.cstride;
744
745 /* .chroma_step is the byte distance between the same chroma channel
746 * values of subsequent pixels, assumed to be the same for Cb and Cr. */
747 fourcc = get_fourcc_yuv(buf->format, is_ycrcb, ycbcr.chroma_step);
748 if (fourcc == -1) {
749 _eglLog(_EGL_WARNING, "unsupported YUV format, native = %x, is_ycrcb = %d, chroma_step = %d",
750 buf->format, is_ycrcb, ycbcr.chroma_step);
751 return NULL;
752 }
753
754 if (ycbcr.chroma_step == 2) {
755 /* Semi-planar Y + CbCr or Y + CrCb format. */
756 const EGLint attr_list_2plane[] = {
757 EGL_WIDTH, buf->width,
758 EGL_HEIGHT, buf->height,
759 EGL_LINUX_DRM_FOURCC_EXT, fourcc,
760 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
761 EGL_DMA_BUF_PLANE0_PITCH_EXT, pitches[0],
762 EGL_DMA_BUF_PLANE0_OFFSET_EXT, offsets[0],
763 EGL_DMA_BUF_PLANE1_FD_EXT, fd,
764 EGL_DMA_BUF_PLANE1_PITCH_EXT, pitches[1],
765 EGL_DMA_BUF_PLANE1_OFFSET_EXT, offsets[1],
766 EGL_NONE, 0
767 };
768
769 return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list_2plane);
770 } else {
771 /* Fully planar Y + Cb + Cr or Y + Cr + Cb format. */
772 const EGLint attr_list_3plane[] = {
773 EGL_WIDTH, buf->width,
774 EGL_HEIGHT, buf->height,
775 EGL_LINUX_DRM_FOURCC_EXT, fourcc,
776 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
777 EGL_DMA_BUF_PLANE0_PITCH_EXT, pitches[0],
778 EGL_DMA_BUF_PLANE0_OFFSET_EXT, offsets[0],
779 EGL_DMA_BUF_PLANE1_FD_EXT, fd,
780 EGL_DMA_BUF_PLANE1_PITCH_EXT, pitches[1],
781 EGL_DMA_BUF_PLANE1_OFFSET_EXT, offsets[1],
782 EGL_DMA_BUF_PLANE2_FD_EXT, fd,
783 EGL_DMA_BUF_PLANE2_PITCH_EXT, pitches[2],
784 EGL_DMA_BUF_PLANE2_OFFSET_EXT, offsets[2],
785 EGL_NONE, 0
786 };
787
788 return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list_3plane);
789 }
790 }
791
792 static _EGLImage *
793 droid_create_image_from_prime_fd(_EGLDisplay *disp, _EGLContext *ctx,
794 struct ANativeWindowBuffer *buf, int fd)
795 {
796 unsigned int pitch;
797
798 if (is_yuv(buf->format))
799 return droid_create_image_from_prime_fd_yuv(disp, ctx, buf, fd);
800
801 const int fourcc = get_fourcc(buf->format);
802 if (fourcc == -1) {
803 _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
804 return NULL;
805 }
806
807 pitch = buf->stride * get_format_bpp(buf->format);
808 if (pitch == 0) {
809 _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
810 return NULL;
811 }
812
813 const EGLint attr_list[] = {
814 EGL_WIDTH, buf->width,
815 EGL_HEIGHT, buf->height,
816 EGL_LINUX_DRM_FOURCC_EXT, fourcc,
817 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
818 EGL_DMA_BUF_PLANE0_PITCH_EXT, pitch,
819 EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
820 EGL_NONE, 0
821 };
822
823 return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list);
824 }
825
826 static _EGLImage *
827 droid_create_image_from_name(_EGLDisplay *disp, _EGLContext *ctx,
828 struct ANativeWindowBuffer *buf)
829 {
830 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
831 struct dri2_egl_image *dri2_img;
832 int name;
833 int format;
834
835 name = get_native_buffer_name(buf);
836 if (!name) {
837 _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
838 return NULL;
839 }
840
841 format = get_format(buf->format);
842 if (format == -1)
843 return NULL;
844
845 dri2_img = calloc(1, sizeof(*dri2_img));
846 if (!dri2_img) {
847 _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm");
848 return NULL;
849 }
850
851 if (!_eglInitImage(&dri2_img->base, disp)) {
852 free(dri2_img);
853 return NULL;
854 }
855
856 dri2_img->dri_image =
857 dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
858 buf->width,
859 buf->height,
860 format,
861 name,
862 buf->stride,
863 dri2_img);
864 if (!dri2_img->dri_image) {
865 free(dri2_img);
866 _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm");
867 return NULL;
868 }
869
870 return &dri2_img->base;
871 }
872
873 static EGLBoolean
874 droid_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
875 EGLint attribute, EGLint *value)
876 {
877 struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
878 switch (attribute) {
879 case EGL_WIDTH:
880 if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) {
881 dri2_surf->window->query(dri2_surf->window,
882 NATIVE_WINDOW_DEFAULT_WIDTH, value);
883 return EGL_TRUE;
884 }
885 break;
886 case EGL_HEIGHT:
887 if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) {
888 dri2_surf->window->query(dri2_surf->window,
889 NATIVE_WINDOW_DEFAULT_HEIGHT, value);
890 return EGL_TRUE;
891 }
892 break;
893 default:
894 break;
895 }
896 return _eglQuerySurface(drv, dpy, surf, attribute, value);
897 }
898
899 static _EGLImage *
900 dri2_create_image_android_native_buffer(_EGLDisplay *disp,
901 _EGLContext *ctx,
902 struct ANativeWindowBuffer *buf)
903 {
904 int fd;
905
906 if (ctx != NULL) {
907 /* From the EGL_ANDROID_image_native_buffer spec:
908 *
909 * * If <target> is EGL_NATIVE_BUFFER_ANDROID and <ctx> is not
910 * EGL_NO_CONTEXT, the error EGL_BAD_CONTEXT is generated.
911 */
912 _eglError(EGL_BAD_CONTEXT, "eglCreateEGLImageKHR: for "
913 "EGL_NATIVE_BUFFER_ANDROID, the context must be "
914 "EGL_NO_CONTEXT");
915 return NULL;
916 }
917
918 if (!buf || buf->common.magic != ANDROID_NATIVE_BUFFER_MAGIC ||
919 buf->common.version != sizeof(*buf)) {
920 _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
921 return NULL;
922 }
923
924 fd = get_native_buffer_fd(buf);
925 if (fd >= 0)
926 return droid_create_image_from_prime_fd(disp, ctx, buf, fd);
927
928 return droid_create_image_from_name(disp, ctx, buf);
929 }
930
931 static _EGLImage *
932 droid_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
933 _EGLContext *ctx, EGLenum target,
934 EGLClientBuffer buffer, const EGLint *attr_list)
935 {
936 switch (target) {
937 case EGL_NATIVE_BUFFER_ANDROID:
938 return dri2_create_image_android_native_buffer(disp, ctx,
939 (struct ANativeWindowBuffer *) buffer);
940 default:
941 return dri2_create_image_khr(drv, disp, ctx, target, buffer, attr_list);
942 }
943 }
944
945 static void
946 droid_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
947 {
948 }
949
950 static int
951 droid_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf,
952 unsigned int *attachments, int count)
953 {
954 int num_buffers = 0, i;
955
956 /* fill dri2_surf->buffers */
957 for (i = 0; i < count * 2; i += 2) {
958 __DRIbuffer *buf, *local;
959
960 assert(num_buffers < ARRAY_SIZE(dri2_surf->buffers));
961 buf = &dri2_surf->buffers[num_buffers];
962
963 switch (attachments[i]) {
964 case __DRI_BUFFER_BACK_LEFT:
965 if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
966 buf->attachment = attachments[i];
967 buf->name = get_native_buffer_name(dri2_surf->buffer);
968 buf->cpp = get_format_bpp(dri2_surf->buffer->format);
969 buf->pitch = dri2_surf->buffer->stride * buf->cpp;
970 buf->flags = 0;
971
972 if (buf->name)
973 num_buffers++;
974
975 break;
976 }
977 /* fall through for pbuffers */
978 case __DRI_BUFFER_DEPTH:
979 case __DRI_BUFFER_STENCIL:
980 case __DRI_BUFFER_ACCUM:
981 case __DRI_BUFFER_DEPTH_STENCIL:
982 case __DRI_BUFFER_HIZ:
983 local = droid_alloc_local_buffer(dri2_surf,
984 attachments[i], attachments[i + 1]);
985
986 if (local) {
987 *buf = *local;
988 num_buffers++;
989 }
990 break;
991 case __DRI_BUFFER_FRONT_LEFT:
992 case __DRI_BUFFER_FRONT_RIGHT:
993 case __DRI_BUFFER_FAKE_FRONT_LEFT:
994 case __DRI_BUFFER_FAKE_FRONT_RIGHT:
995 case __DRI_BUFFER_BACK_RIGHT:
996 default:
997 /* no front or right buffers */
998 break;
999 }
1000 }
1001
1002 return num_buffers;
1003 }
1004
1005 static __DRIbuffer *
1006 droid_get_buffers_with_format(__DRIdrawable * driDrawable,
1007 int *width, int *height,
1008 unsigned int *attachments, int count,
1009 int *out_count, void *loaderPrivate)
1010 {
1011 struct dri2_egl_surface *dri2_surf = loaderPrivate;
1012
1013 if (update_buffers(dri2_surf) < 0)
1014 return NULL;
1015
1016 dri2_surf->buffer_count =
1017 droid_get_buffers_parse_attachments(dri2_surf, attachments, count);
1018
1019 if (width)
1020 *width = dri2_surf->base.Width;
1021 if (height)
1022 *height = dri2_surf->base.Height;
1023
1024 *out_count = dri2_surf->buffer_count;
1025
1026 return dri2_surf->buffers;
1027 }
1028
1029 static EGLBoolean
1030 droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy)
1031 {
1032 struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
1033 static const struct {
1034 int format;
1035 unsigned int rgba_masks[4];
1036 } visuals[] = {
1037 { HAL_PIXEL_FORMAT_RGBA_8888, { 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 } },
1038 { HAL_PIXEL_FORMAT_RGBX_8888, { 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 } },
1039 { HAL_PIXEL_FORMAT_RGB_565, { 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000 } },
1040 { HAL_PIXEL_FORMAT_BGRA_8888, { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 } },
1041 };
1042 EGLint config_attrs[] = {
1043 EGL_NATIVE_VISUAL_ID, 0,
1044 EGL_NATIVE_VISUAL_TYPE, 0,
1045 EGL_FRAMEBUFFER_TARGET_ANDROID, EGL_TRUE,
1046 EGL_RECORDABLE_ANDROID, EGL_TRUE,
1047 EGL_NONE
1048 };
1049 unsigned int format_count[ARRAY_SIZE(visuals)] = { 0 };
1050 int count, i, j;
1051
1052 count = 0;
1053 for (i = 0; dri2_dpy->driver_configs[i]; i++) {
1054 const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT;
1055 struct dri2_egl_config *dri2_conf;
1056
1057 for (j = 0; j < ARRAY_SIZE(visuals); j++) {
1058 config_attrs[1] = visuals[j].format;
1059 config_attrs[3] = visuals[j].format;
1060
1061 dri2_conf = dri2_add_config(dpy, dri2_dpy->driver_configs[i],
1062 count + 1, surface_type, config_attrs, visuals[j].rgba_masks);
1063 if (dri2_conf) {
1064 count++;
1065 format_count[j]++;
1066 }
1067 }
1068 }
1069
1070 for (i = 0; i < ARRAY_SIZE(format_count); i++) {
1071 if (!format_count[i]) {
1072 _eglLog(_EGL_DEBUG, "No DRI config supports native format 0x%x",
1073 visuals[i].format);
1074 }
1075 }
1076
1077 return (count != 0);
1078 }
1079
1080 static int
1081 droid_open_device(struct dri2_egl_display *dri2_dpy)
1082 {
1083 int fd = -1, err = -EINVAL;
1084
1085 if (dri2_dpy->gralloc->perform)
1086 err = dri2_dpy->gralloc->perform(dri2_dpy->gralloc,
1087 GRALLOC_MODULE_PERFORM_GET_DRM_FD,
1088 &fd);
1089 if (err || fd < 0) {
1090 _eglLog(_EGL_WARNING, "fail to get drm fd");
1091 fd = -1;
1092 }
1093
1094 return (fd >= 0) ? fcntl(fd, F_DUPFD_CLOEXEC, 3) : -1;
1095 }
1096
1097 static const struct dri2_egl_display_vtbl droid_display_vtbl = {
1098 .authenticate = NULL,
1099 .create_window_surface = droid_create_window_surface,
1100 .create_pixmap_surface = dri2_fallback_create_pixmap_surface,
1101 .create_pbuffer_surface = droid_create_pbuffer_surface,
1102 .destroy_surface = droid_destroy_surface,
1103 .create_image = droid_create_image_khr,
1104 .swap_interval = dri2_fallback_swap_interval,
1105 .swap_buffers = droid_swap_buffers,
1106 .swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage,
1107 .swap_buffers_region = dri2_fallback_swap_buffers_region,
1108 #if ANDROID_API_LEVEL >= 23
1109 .set_damage_region = droid_set_damage_region,
1110 #else
1111 .set_damage_region = dri2_fallback_set_damage_region,
1112 #endif
1113 .post_sub_buffer = dri2_fallback_post_sub_buffer,
1114 .copy_buffers = dri2_fallback_copy_buffers,
1115 .query_buffer_age = droid_query_buffer_age,
1116 .query_surface = droid_query_surface,
1117 .create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image,
1118 .get_sync_values = dri2_fallback_get_sync_values,
1119 .get_dri_drawable = dri2_surface_get_dri_drawable,
1120 };
1121
1122 static const __DRIdri2LoaderExtension droid_dri2_loader_extension = {
1123 .base = { __DRI_DRI2_LOADER, 3 },
1124
1125 .getBuffers = NULL,
1126 .flushFrontBuffer = droid_flush_front_buffer,
1127 .getBuffersWithFormat = droid_get_buffers_with_format,
1128 };
1129
1130 static const __DRIimageLoaderExtension droid_image_loader_extension = {
1131 .base = { __DRI_IMAGE_LOADER, 1 },
1132
1133 .getBuffers = droid_image_get_buffers,
1134 .flushFrontBuffer = droid_flush_front_buffer,
1135 };
1136
1137 static const __DRIextension *droid_dri2_loader_extensions[] = {
1138 &droid_dri2_loader_extension.base,
1139 &image_lookup_extension.base,
1140 &use_invalidate.base,
1141 NULL,
1142 };
1143
1144 static const __DRIextension *droid_image_loader_extensions[] = {
1145 &droid_image_loader_extension.base,
1146 &image_lookup_extension.base,
1147 &use_invalidate.base,
1148 NULL,
1149 };
1150
1151 EGLBoolean
1152 dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
1153 {
1154 struct dri2_egl_display *dri2_dpy;
1155 const char *err;
1156 int ret;
1157
1158 loader_set_logger(_eglLog);
1159
1160 dri2_dpy = calloc(1, sizeof(*dri2_dpy));
1161 if (!dri2_dpy)
1162 return _eglError(EGL_BAD_ALLOC, "eglInitialize");
1163
1164 dri2_dpy->fd = -1;
1165 ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
1166 (const hw_module_t **)&dri2_dpy->gralloc);
1167 if (ret) {
1168 err = "DRI2: failed to get gralloc module";
1169 goto cleanup;
1170 }
1171
1172 dpy->DriverData = (void *) dri2_dpy;
1173
1174 dri2_dpy->fd = droid_open_device(dri2_dpy);
1175 if (dri2_dpy->fd < 0) {
1176 err = "DRI2: failed to open device";
1177 goto cleanup;
1178 }
1179
1180 dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd);
1181 if (dri2_dpy->driver_name == NULL) {
1182 err = "DRI2: failed to get driver name";
1183 goto cleanup;
1184 }
1185
1186 dri2_dpy->is_render_node = drmGetNodeTypeFromFd(dri2_dpy->fd) == DRM_NODE_RENDER;
1187
1188 /* render nodes cannot use Gem names, and thus do not support
1189 * the __DRI_DRI2_LOADER extension */
1190 if (!dri2_dpy->is_render_node) {
1191 dri2_dpy->loader_extensions = droid_dri2_loader_extensions;
1192 if (!dri2_load_driver(dpy)) {
1193 err = "DRI2: failed to load driver";
1194 goto cleanup;
1195 }
1196 } else {
1197 dri2_dpy->loader_extensions = droid_image_loader_extensions;
1198 if (!dri2_load_driver_dri3(dpy)) {
1199 err = "DRI3: failed to load driver";
1200 goto cleanup;
1201 }
1202 }
1203
1204 if (!dri2_create_screen(dpy)) {
1205 err = "DRI2: failed to create screen";
1206 goto cleanup;
1207 }
1208
1209 if (!dri2_setup_extensions(dpy))
1210 goto cleanup;
1211
1212 dri2_setup_screen(dpy);
1213
1214 if (!droid_add_configs_for_visuals(drv, dpy)) {
1215 err = "DRI2: failed to add configs";
1216 goto cleanup;
1217 }
1218
1219 dpy->Extensions.ANDROID_framebuffer_target = EGL_TRUE;
1220 dpy->Extensions.ANDROID_image_native_buffer = EGL_TRUE;
1221 dpy->Extensions.ANDROID_recordable = EGL_TRUE;
1222 dpy->Extensions.EXT_buffer_age = EGL_TRUE;
1223 #if ANDROID_API_LEVEL >= 23
1224 dpy->Extensions.KHR_partial_update = EGL_TRUE;
1225 #endif
1226
1227 /* Fill vtbl last to prevent accidentally calling virtual function during
1228 * initialization.
1229 */
1230 dri2_dpy->vtbl = &droid_display_vtbl;
1231
1232 return EGL_TRUE;
1233
1234 cleanup:
1235 dri2_display_destroy(dpy);
1236 return _eglError(EGL_NOT_INITIALIZED, err);
1237 }