Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 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 | |
Robert Foss | c7bb821 | 2018-04-18 17:27:40 +0200 | [diff] [blame] | 30 | #include <cutils/properties.h> |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 31 | #include <errno.h> |
Robert Foss | c7bb821 | 2018-04-18 17:27:40 +0200 | [diff] [blame] | 32 | #include <dirent.h> |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 33 | #include <dlfcn.h> |
Matt Whitlock | c8fd7d0 | 2016-10-01 23:49:41 -0400 | [diff] [blame] | 34 | #include <fcntl.h> |
Rob Herring | d45884e | 2016-04-28 15:37:28 -0500 | [diff] [blame] | 35 | #include <xf86drm.h> |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 36 | #include <stdbool.h> |
Robert Foss | c7bb821 | 2018-04-18 17:27:40 +0200 | [diff] [blame] | 37 | #include <stdio.h> |
Chad Versace | bfe28b8 | 2012-12-20 14:16:50 -0800 | [diff] [blame] | 38 | #include <sync/sync.h> |
Robert Foss | c7bb821 | 2018-04-18 17:27:40 +0200 | [diff] [blame] | 39 | #include <sys/types.h> |
Chad Versace | bfe28b8 | 2012-12-20 14:16:50 -0800 | [diff] [blame] | 40 | |
Emil Velikov | 8d4357b | 2014-01-11 04:52:48 +0000 | [diff] [blame] | 41 | #include "loader.h" |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 42 | #include "egl_dri2.h" |
Chad Versace | 8b9298a | 2014-01-28 12:34:19 -0800 | [diff] [blame] | 43 | #include "egl_dri2_fallbacks.h" |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 44 | |
| 45 | #ifdef HAVE_DRM_GRALLOC |
| 46 | #include <gralloc_drm_handle.h> |
Tapani Pälli | 4070295 | 2013-01-24 09:56:47 +0200 | [diff] [blame] | 47 | #include "gralloc_drm.h" |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 48 | #endif /* HAVE_DRM_GRALLOC */ |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 49 | |
Tomasz Figa | 3723e98 | 2016-08-02 20:07:54 +0900 | [diff] [blame] | 50 | #define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1)) |
| 51 | |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 52 | struct droid_yuv_format { |
| 53 | /* Lookup keys */ |
| 54 | int native; /* HAL_PIXEL_FORMAT_ */ |
| 55 | int is_ycrcb; /* 0 if chroma order is {Cb, Cr}, 1 if {Cr, Cb} */ |
| 56 | int chroma_step; /* Distance in bytes between subsequent chroma pixels. */ |
| 57 | |
| 58 | /* Result */ |
| 59 | int fourcc; /* __DRI_IMAGE_FOURCC_ */ |
| 60 | }; |
| 61 | |
| 62 | /* The following table is used to look up a DRI image FourCC based |
| 63 | * on native format and information contained in android_ycbcr struct. */ |
| 64 | static const struct droid_yuv_format droid_yuv_formats[] = { |
| 65 | /* Native format, YCrCb, Chroma step, DRI image FourCC */ |
| 66 | { HAL_PIXEL_FORMAT_YCbCr_420_888, 0, 2, __DRI_IMAGE_FOURCC_NV12 }, |
| 67 | { HAL_PIXEL_FORMAT_YCbCr_420_888, 0, 1, __DRI_IMAGE_FOURCC_YUV420 }, |
| 68 | { HAL_PIXEL_FORMAT_YCbCr_420_888, 1, 1, __DRI_IMAGE_FOURCC_YVU420 }, |
| 69 | { HAL_PIXEL_FORMAT_YV12, 1, 1, __DRI_IMAGE_FOURCC_YVU420 }, |
Tomasz Figa | 5364e73 | 2017-12-04 19:22:39 +0100 | [diff] [blame] | 70 | /* HACK: See droid_create_image_from_prime_fd() and |
| 71 | * https://issuetracker.google.com/32077885. */ |
| 72 | { HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, 0, 2, __DRI_IMAGE_FOURCC_NV12 }, |
| 73 | { HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, 0, 1, __DRI_IMAGE_FOURCC_YUV420 }, |
| 74 | { HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, 1, 1, __DRI_IMAGE_FOURCC_YVU420 }, |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | static int |
| 78 | get_fourcc_yuv(int native, int is_ycrcb, int chroma_step) |
| 79 | { |
Chad Versace | 0945512 | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 80 | for (int i = 0; i < ARRAY_SIZE(droid_yuv_formats); ++i) |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 81 | if (droid_yuv_formats[i].native == native && |
| 82 | droid_yuv_formats[i].is_ycrcb == is_ycrcb && |
| 83 | droid_yuv_formats[i].chroma_step == chroma_step) |
| 84 | return droid_yuv_formats[i].fourcc; |
| 85 | |
| 86 | return -1; |
| 87 | } |
| 88 | |
| 89 | static bool |
| 90 | is_yuv(int native) |
| 91 | { |
Chad Versace | 0945512 | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 92 | for (int i = 0; i < ARRAY_SIZE(droid_yuv_formats); ++i) |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 93 | if (droid_yuv_formats[i].native == native) |
| 94 | return true; |
| 95 | |
| 96 | return false; |
| 97 | } |
| 98 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 99 | static int |
| 100 | get_format_bpp(int native) |
| 101 | { |
| 102 | int bpp; |
| 103 | |
| 104 | switch (native) { |
| 105 | case HAL_PIXEL_FORMAT_RGBA_8888: |
Tomasz Figa | 5364e73 | 2017-12-04 19:22:39 +0100 | [diff] [blame] | 106 | case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: |
| 107 | /* |
| 108 | * HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack. |
| 109 | * TODO: Remove this once https://issuetracker.google.com/32077885 is fixed. |
| 110 | */ |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 111 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 112 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 113 | bpp = 4; |
| 114 | break; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 115 | case HAL_PIXEL_FORMAT_RGB_565: |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 116 | bpp = 2; |
| 117 | break; |
| 118 | default: |
| 119 | bpp = 0; |
| 120 | break; |
| 121 | } |
| 122 | |
| 123 | return bpp; |
| 124 | } |
| 125 | |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 126 | /* createImageFromFds requires fourcc format */ |
Tomasz Figa | 7dfb1a4 | 2016-08-02 20:07:53 +0900 | [diff] [blame] | 127 | static int get_fourcc(int native) |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 128 | { |
Tomasz Figa | 7dfb1a4 | 2016-08-02 20:07:53 +0900 | [diff] [blame] | 129 | switch (native) { |
| 130 | case HAL_PIXEL_FORMAT_RGB_565: return __DRI_IMAGE_FOURCC_RGB565; |
| 131 | case HAL_PIXEL_FORMAT_BGRA_8888: return __DRI_IMAGE_FOURCC_ARGB8888; |
| 132 | case HAL_PIXEL_FORMAT_RGBA_8888: return __DRI_IMAGE_FOURCC_ABGR8888; |
Tomasz Figa | 5364e73 | 2017-12-04 19:22:39 +0100 | [diff] [blame] | 133 | case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: |
| 134 | /* |
| 135 | * HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack. |
| 136 | * TODO: Remove this once https://issuetracker.google.com/32077885 is fixed. |
| 137 | */ |
Tomasz Figa | 7dfb1a4 | 2016-08-02 20:07:53 +0900 | [diff] [blame] | 138 | case HAL_PIXEL_FORMAT_RGBX_8888: return __DRI_IMAGE_FOURCC_XBGR8888; |
| 139 | default: |
| 140 | _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", native); |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 141 | } |
| 142 | return -1; |
| 143 | } |
| 144 | |
Rob Herring | dfaccf2 | 2016-04-28 15:37:29 -0500 | [diff] [blame] | 145 | static int get_format(int format) |
| 146 | { |
| 147 | switch (format) { |
| 148 | case HAL_PIXEL_FORMAT_BGRA_8888: return __DRI_IMAGE_FORMAT_ARGB8888; |
| 149 | case HAL_PIXEL_FORMAT_RGB_565: return __DRI_IMAGE_FORMAT_RGB565; |
| 150 | case HAL_PIXEL_FORMAT_RGBA_8888: return __DRI_IMAGE_FORMAT_ABGR8888; |
Tomasz Figa | 5364e73 | 2017-12-04 19:22:39 +0100 | [diff] [blame] | 151 | case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: |
| 152 | /* |
| 153 | * HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack. |
| 154 | * TODO: Revert this once https://issuetracker.google.com/32077885 is fixed. |
| 155 | */ |
Rob Herring | dfaccf2 | 2016-04-28 15:37:29 -0500 | [diff] [blame] | 156 | case HAL_PIXEL_FORMAT_RGBX_8888: return __DRI_IMAGE_FORMAT_XBGR8888; |
Rob Herring | dfaccf2 | 2016-04-28 15:37:29 -0500 | [diff] [blame] | 157 | default: |
| 158 | _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format); |
| 159 | } |
| 160 | return -1; |
| 161 | } |
Tomasz Figa | 7dfb1a4 | 2016-08-02 20:07:53 +0900 | [diff] [blame] | 162 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 163 | static int |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 164 | get_native_buffer_fd(struct ANativeWindowBuffer *buf) |
| 165 | { |
| 166 | native_handle_t *handle = (native_handle_t *)buf->handle; |
| 167 | /* |
| 168 | * Various gralloc implementations exist, but the dma-buf fd tends |
| 169 | * to be first. Access it directly to avoid a dependency on specific |
| 170 | * gralloc versions. |
| 171 | */ |
| 172 | return (handle && handle->numFds) ? handle->data[0] : -1; |
| 173 | } |
| 174 | |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 175 | #ifdef HAVE_DRM_GRALLOC |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 176 | static int |
Chia-I Wu | 75cc24c | 2011-11-25 11:59:02 +0800 | [diff] [blame] | 177 | get_native_buffer_name(struct ANativeWindowBuffer *buf) |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 178 | { |
Tapani Pälli | 4070295 | 2013-01-24 09:56:47 +0200 | [diff] [blame] | 179 | return gralloc_drm_get_gem_handle(buf->handle); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 180 | } |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 181 | #endif /* HAVE_DRM_GRALLOC */ |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 182 | |
| 183 | static EGLBoolean |
| 184 | droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf) |
| 185 | { |
Chad Versace | bfe28b8 | 2012-12-20 14:16:50 -0800 | [diff] [blame] | 186 | int fence_fd; |
| 187 | |
| 188 | if (dri2_surf->window->dequeueBuffer(dri2_surf->window, &dri2_surf->buffer, |
| 189 | &fence_fd)) |
| 190 | return EGL_FALSE; |
| 191 | |
| 192 | /* If access to the buffer is controlled by a sync fence, then block on the |
| 193 | * fence. |
| 194 | * |
| 195 | * It may be more performant to postpone blocking until there is an |
| 196 | * immediate need to write to the buffer. But doing so would require adding |
| 197 | * hooks to the DRI2 loader. |
| 198 | * |
| 199 | * From the ANativeWindow::dequeueBuffer documentation: |
| 200 | * |
| 201 | * The libsync fence file descriptor returned in the int pointed to by |
| 202 | * the fenceFd argument will refer to the fence that must signal |
| 203 | * before the dequeued buffer may be written to. A value of -1 |
| 204 | * indicates that the caller may access the buffer immediately without |
| 205 | * waiting on a fence. If a valid file descriptor is returned (i.e. |
| 206 | * any value except -1) then the caller is responsible for closing the |
| 207 | * file descriptor. |
| 208 | */ |
| 209 | if (fence_fd >= 0) { |
| 210 | /* From the SYNC_IOC_WAIT documentation in <linux/sync.h>: |
| 211 | * |
| 212 | * Waits indefinitely if timeout < 0. |
| 213 | */ |
| 214 | int timeout = -1; |
| 215 | sync_wait(fence_fd, timeout); |
| 216 | close(fence_fd); |
| 217 | } |
| 218 | |
| 219 | dri2_surf->buffer->common.incRef(&dri2_surf->buffer->common); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 220 | |
Xiaosong Wei | 2acc69d | 2017-02-08 10:46:02 +0800 | [diff] [blame] | 221 | /* Record all the buffers created by ANativeWindow and update back buffer |
| 222 | * for updating buffer's age in swap_buffers. |
| 223 | */ |
| 224 | EGLBoolean updated = EGL_FALSE; |
| 225 | for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { |
| 226 | if (!dri2_surf->color_buffers[i].buffer) { |
| 227 | dri2_surf->color_buffers[i].buffer = dri2_surf->buffer; |
| 228 | } |
| 229 | if (dri2_surf->color_buffers[i].buffer == dri2_surf->buffer) { |
| 230 | dri2_surf->back = &dri2_surf->color_buffers[i]; |
| 231 | updated = EGL_TRUE; |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | if (!updated) { |
| 237 | /* In case of all the buffers were recreated by ANativeWindow, reset |
| 238 | * the color_buffers |
| 239 | */ |
| 240 | for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { |
| 241 | dri2_surf->color_buffers[i].buffer = NULL; |
| 242 | dri2_surf->color_buffers[i].age = 0; |
| 243 | } |
| 244 | dri2_surf->color_buffers[0].buffer = dri2_surf->buffer; |
| 245 | dri2_surf->back = &dri2_surf->color_buffers[0]; |
| 246 | } |
| 247 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 248 | return EGL_TRUE; |
| 249 | } |
| 250 | |
| 251 | static EGLBoolean |
Haixia Shi | 1ea233c | 2016-06-02 12:48:23 -0700 | [diff] [blame] | 252 | droid_window_enqueue_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_surf) |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 253 | { |
Tomasz Figa | 9e1248d | 2016-07-15 16:53:50 +0900 | [diff] [blame] | 254 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 255 | |
Haixia Shi | 1ea233c | 2016-06-02 12:48:23 -0700 | [diff] [blame] | 256 | /* To avoid blocking other EGL calls, release the display mutex before |
| 257 | * we enter droid_window_enqueue_buffer() and re-acquire the mutex upon |
| 258 | * return. |
| 259 | */ |
| 260 | mtx_unlock(&disp->Mutex); |
| 261 | |
Zhongmin Wu | 7343d27 | 2017-09-15 18:32:43 +0100 | [diff] [blame] | 262 | /* Queue the buffer with stored out fence fd. The ANativeWindow or buffer |
| 263 | * consumer may choose to wait for the fence to signal before accessing |
| 264 | * it. If fence fd value is -1, buffer can be accessed by consumer |
| 265 | * immediately. Consumer or application shouldn't rely on timestamp |
| 266 | * associated with fence if the fence fd is -1. |
Chad Versace | bfe28b8 | 2012-12-20 14:16:50 -0800 | [diff] [blame] | 267 | * |
Zhongmin Wu | 7343d27 | 2017-09-15 18:32:43 +0100 | [diff] [blame] | 268 | * Ownership of fd is transferred to consumer after queueBuffer and the |
| 269 | * consumer is responsible for closing it. Caller must not use the fd |
| 270 | * after passing it to queueBuffer. |
Chad Versace | bfe28b8 | 2012-12-20 14:16:50 -0800 | [diff] [blame] | 271 | */ |
Zhongmin Wu | 7343d27 | 2017-09-15 18:32:43 +0100 | [diff] [blame] | 272 | int fence_fd = dri2_surf->out_fence_fd; |
| 273 | dri2_surf->out_fence_fd = -1; |
Chad Versace | bfe28b8 | 2012-12-20 14:16:50 -0800 | [diff] [blame] | 274 | dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer, |
| 275 | fence_fd); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 276 | |
| 277 | dri2_surf->buffer->common.decRef(&dri2_surf->buffer->common); |
| 278 | dri2_surf->buffer = NULL; |
Xiaosong Wei | 2acc69d | 2017-02-08 10:46:02 +0800 | [diff] [blame] | 279 | dri2_surf->back = NULL; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 280 | |
Haixia Shi | 1ea233c | 2016-06-02 12:48:23 -0700 | [diff] [blame] | 281 | mtx_lock(&disp->Mutex); |
Tomasz Figa | 9e1248d | 2016-07-15 16:53:50 +0900 | [diff] [blame] | 282 | |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 283 | if (dri2_surf->dri_image_back) { |
| 284 | dri2_dpy->image->destroyImage(dri2_surf->dri_image_back); |
| 285 | dri2_surf->dri_image_back = NULL; |
Tomasz Figa | 9e1248d | 2016-07-15 16:53:50 +0900 | [diff] [blame] | 286 | } |
| 287 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 288 | return EGL_TRUE; |
| 289 | } |
| 290 | |
| 291 | static void |
Chad Versace | 0212db3 | 2017-05-04 17:46:33 -0700 | [diff] [blame] | 292 | droid_window_cancel_buffer(struct dri2_egl_surface *dri2_surf) |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 293 | { |
Chad Versace | 0212db3 | 2017-05-04 17:46:33 -0700 | [diff] [blame] | 294 | int ret; |
Zhongmin Wu | 7343d27 | 2017-09-15 18:32:43 +0100 | [diff] [blame] | 295 | int fence_fd = dri2_surf->out_fence_fd; |
Chad Versace | 0212db3 | 2017-05-04 17:46:33 -0700 | [diff] [blame] | 296 | |
Zhongmin Wu | 7343d27 | 2017-09-15 18:32:43 +0100 | [diff] [blame] | 297 | dri2_surf->out_fence_fd = -1; |
| 298 | ret = dri2_surf->window->cancelBuffer(dri2_surf->window, |
| 299 | dri2_surf->buffer, fence_fd); |
Chad Versace | 0212db3 | 2017-05-04 17:46:33 -0700 | [diff] [blame] | 300 | if (ret < 0) { |
| 301 | _eglLog(_EGL_WARNING, "ANativeWindow::cancelBuffer failed"); |
Nicolas Boichat | 63b12b0 | 2017-05-05 10:43:50 +0800 | [diff] [blame] | 302 | dri2_surf->base.Lost = EGL_TRUE; |
Chad Versace | 0212db3 | 2017-05-04 17:46:33 -0700 | [diff] [blame] | 303 | } |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 304 | } |
| 305 | |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame^] | 306 | static bool |
| 307 | droid_set_shared_buffer_mode(_EGLDisplay *disp, _EGLSurface *surf, bool mode) |
| 308 | { |
| 309 | #if ANDROID_API_LEVEL >= 24 |
| 310 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 311 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 312 | struct ANativeWindow *window = dri2_surf->window; |
| 313 | |
| 314 | assert(surf->Type == EGL_WINDOW_BIT); |
| 315 | assert(_eglSurfaceHasMutableRenderBuffer(&dri2_surf->base)); |
| 316 | |
| 317 | _eglLog(_EGL_DEBUG, "%s: mode=%d", __func__, mode); |
| 318 | |
| 319 | if (native_window_set_shared_buffer_mode(window, mode)) { |
| 320 | _eglLog(_EGL_WARNING, "failed native_window_set_shared_buffer_mode" |
| 321 | "(window=%p, mode=%d)", window, mode); |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | return true; |
| 326 | #else |
| 327 | _eglLog(_EGL_FATAL, "%s:%d: internal error: unreachable", __FILE__, __LINE__); |
| 328 | return false; |
| 329 | #endif |
| 330 | } |
| 331 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 332 | static _EGLSurface * |
| 333 | droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 334 | _EGLConfig *conf, void *native_window, |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 335 | const EGLint *attrib_list) |
| 336 | { |
Emil Velikov | acf125e | 2017-05-08 18:39:12 +0100 | [diff] [blame] | 337 | __DRIcreateNewDrawableFunc createNewDrawable; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 338 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 339 | struct dri2_egl_config *dri2_conf = dri2_egl_config(conf); |
| 340 | struct dri2_egl_surface *dri2_surf; |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 341 | struct ANativeWindow *window = native_window; |
Marek Olšák | c2c2e9a | 2015-06-10 02:49:29 +0200 | [diff] [blame] | 342 | const __DRIconfig *config; |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 343 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 344 | dri2_surf = calloc(1, sizeof *dri2_surf); |
| 345 | if (!dri2_surf) { |
| 346 | _eglError(EGL_BAD_ALLOC, "droid_create_surface"); |
| 347 | return NULL; |
| 348 | } |
| 349 | |
Zhongmin Wu | 7343d27 | 2017-09-15 18:32:43 +0100 | [diff] [blame] | 350 | if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, true)) |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 351 | goto cleanup_surface; |
| 352 | |
| 353 | if (type == EGL_WINDOW_BIT) { |
| 354 | int format; |
| 355 | |
Emil Velikov | 92b2368 | 2017-08-05 00:25:47 +0100 | [diff] [blame] | 356 | if (window->common.magic != ANDROID_NATIVE_WINDOW_MAGIC) { |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 357 | _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface"); |
| 358 | goto cleanup_surface; |
| 359 | } |
| 360 | if (window->query(window, NATIVE_WINDOW_FORMAT, &format)) { |
| 361 | _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface"); |
| 362 | goto cleanup_surface; |
| 363 | } |
| 364 | |
| 365 | if (format != dri2_conf->base.NativeVisualID) { |
| 366 | _eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x", |
| 367 | format, dri2_conf->base.NativeVisualID); |
| 368 | } |
| 369 | |
| 370 | window->query(window, NATIVE_WINDOW_WIDTH, &dri2_surf->base.Width); |
| 371 | window->query(window, NATIVE_WINDOW_HEIGHT, &dri2_surf->base.Height); |
| 372 | } |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 373 | |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 374 | config = dri2_get_dri_config(dri2_conf, type, |
Marek Olšák | c2c2e9a | 2015-06-10 02:49:29 +0200 | [diff] [blame] | 375 | dri2_surf->base.GLColorspace); |
Tapani Pälli | affe63b | 2018-05-04 08:28:50 +0300 | [diff] [blame] | 376 | if (!config) { |
| 377 | _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); |
Tomasz Figa | 94282b6 | 2016-07-15 16:53:48 +0900 | [diff] [blame] | 378 | goto cleanup_surface; |
Tapani Pälli | affe63b | 2018-05-04 08:28:50 +0300 | [diff] [blame] | 379 | } |
Marek Olšák | c2c2e9a | 2015-06-10 02:49:29 +0200 | [diff] [blame] | 380 | |
Emil Velikov | acf125e | 2017-05-08 18:39:12 +0100 | [diff] [blame] | 381 | if (dri2_dpy->image_driver) |
| 382 | createNewDrawable = dri2_dpy->image_driver->createNewDrawable; |
| 383 | else |
| 384 | createNewDrawable = dri2_dpy->dri2->createNewDrawable; |
| 385 | |
| 386 | dri2_surf->dri_drawable = (*createNewDrawable)(dri2_dpy->dri_screen, config, |
| 387 | dri2_surf); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 388 | if (dri2_surf->dri_drawable == NULL) { |
Emil Velikov | acf125e | 2017-05-08 18:39:12 +0100 | [diff] [blame] | 389 | _eglError(EGL_BAD_ALLOC, "createNewDrawable"); |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 390 | goto cleanup_surface; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 391 | } |
| 392 | |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 393 | if (window) { |
| 394 | window->common.incRef(&window->common); |
| 395 | dri2_surf->window = window; |
| 396 | } |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 397 | |
| 398 | return &dri2_surf->base; |
| 399 | |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 400 | cleanup_surface: |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 401 | free(dri2_surf); |
| 402 | |
| 403 | return NULL; |
| 404 | } |
| 405 | |
| 406 | static _EGLSurface * |
| 407 | droid_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 408 | _EGLConfig *conf, void *native_window, |
| 409 | const EGLint *attrib_list) |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 410 | { |
| 411 | return droid_create_surface(drv, disp, EGL_WINDOW_BIT, conf, |
Chad Versace | 6d1f83e | 2014-01-07 14:54:51 -0800 | [diff] [blame] | 412 | native_window, attrib_list); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static _EGLSurface * |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 416 | droid_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp, |
| 417 | _EGLConfig *conf, const EGLint *attrib_list) |
| 418 | { |
Chia-I Wu | 93d5963 | 2011-08-27 00:00:18 +0800 | [diff] [blame] | 419 | return droid_create_surface(drv, disp, EGL_PBUFFER_BIT, conf, |
| 420 | NULL, attrib_list); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static EGLBoolean |
| 424 | droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) |
| 425 | { |
| 426 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 427 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 428 | |
Gwan-gyeong Mun | 640b6e6 | 2017-08-05 00:16:11 +0900 | [diff] [blame] | 429 | dri2_egl_surface_free_local_buffers(dri2_surf); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 430 | |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 431 | if (dri2_surf->base.Type == EGL_WINDOW_BIT) { |
| 432 | if (dri2_surf->buffer) |
Chad Versace | 0212db3 | 2017-05-04 17:46:33 -0700 | [diff] [blame] | 433 | droid_window_cancel_buffer(dri2_surf); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 434 | |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 435 | dri2_surf->window->common.decRef(&dri2_surf->window->common); |
| 436 | } |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 437 | |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 438 | if (dri2_surf->dri_image_back) { |
| 439 | _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, __LINE__); |
| 440 | dri2_dpy->image->destroyImage(dri2_surf->dri_image_back); |
| 441 | dri2_surf->dri_image_back = NULL; |
| 442 | } |
| 443 | |
| 444 | if (dri2_surf->dri_image_front) { |
| 445 | _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, __LINE__); |
| 446 | dri2_dpy->image->destroyImage(dri2_surf->dri_image_front); |
| 447 | dri2_surf->dri_image_front = NULL; |
| 448 | } |
| 449 | |
Boyan Ding | 868ae3e | 2015-11-25 13:27:02 +0800 | [diff] [blame] | 450 | dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 451 | |
Zhongmin Wu | e013ce8 | 2017-09-15 18:32:42 +0100 | [diff] [blame] | 452 | dri2_fini_surface(surf); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 453 | free(dri2_surf); |
| 454 | |
| 455 | return EGL_TRUE; |
| 456 | } |
| 457 | |
Wu, Zhongmin | 5fc21c6 | 2018-01-18 15:39:22 +0800 | [diff] [blame] | 458 | static EGLBoolean |
| 459 | droid_swap_interval(_EGLDriver *drv, _EGLDisplay *dpy, |
| 460 | _EGLSurface *surf, EGLint interval) |
| 461 | { |
| 462 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 463 | struct ANativeWindow *window = dri2_surf->window; |
| 464 | |
| 465 | if (window->setSwapInterval(window, interval)) |
| 466 | return EGL_FALSE; |
| 467 | |
| 468 | surf->SwapInterval = interval; |
| 469 | return EGL_TRUE; |
| 470 | } |
| 471 | |
Rob Herring | 81a6fff | 2016-04-28 15:37:30 -0500 | [diff] [blame] | 472 | static int |
| 473 | update_buffers(struct dri2_egl_surface *dri2_surf) |
| 474 | { |
Chad Versace | e5eace5 | 2017-05-04 17:46:34 -0700 | [diff] [blame] | 475 | if (dri2_surf->base.Lost) |
| 476 | return -1; |
| 477 | |
Rob Herring | 81a6fff | 2016-04-28 15:37:30 -0500 | [diff] [blame] | 478 | if (dri2_surf->base.Type != EGL_WINDOW_BIT) |
| 479 | return 0; |
| 480 | |
| 481 | /* try to dequeue the next back buffer */ |
Tomasz Figa | 565fa6b | 2016-07-15 16:53:49 +0900 | [diff] [blame] | 482 | if (!dri2_surf->buffer && !droid_window_dequeue_buffer(dri2_surf)) { |
| 483 | _eglLog(_EGL_WARNING, "Could not dequeue buffer from native window"); |
Nicolas Boichat | 63b12b0 | 2017-05-05 10:43:50 +0800 | [diff] [blame] | 484 | dri2_surf->base.Lost = EGL_TRUE; |
Rob Herring | 81a6fff | 2016-04-28 15:37:30 -0500 | [diff] [blame] | 485 | return -1; |
Tomasz Figa | 565fa6b | 2016-07-15 16:53:49 +0900 | [diff] [blame] | 486 | } |
Rob Herring | 81a6fff | 2016-04-28 15:37:30 -0500 | [diff] [blame] | 487 | |
| 488 | /* free outdated buffers and update the surface size */ |
| 489 | if (dri2_surf->base.Width != dri2_surf->buffer->width || |
| 490 | dri2_surf->base.Height != dri2_surf->buffer->height) { |
Gwan-gyeong Mun | 640b6e6 | 2017-08-05 00:16:11 +0900 | [diff] [blame] | 491 | dri2_egl_surface_free_local_buffers(dri2_surf); |
Rob Herring | 81a6fff | 2016-04-28 15:37:30 -0500 | [diff] [blame] | 492 | dri2_surf->base.Width = dri2_surf->buffer->width; |
| 493 | dri2_surf->base.Height = dri2_surf->buffer->height; |
| 494 | } |
| 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 499 | static int |
Liu Zhiquan | e2610bf | 2016-12-09 19:29:56 +0800 | [diff] [blame] | 500 | get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format) |
| 501 | { |
| 502 | struct dri2_egl_display *dri2_dpy = |
| 503 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 504 | |
| 505 | if (dri2_surf->dri_image_front) |
| 506 | return 0; |
| 507 | |
| 508 | if (dri2_surf->base.Type == EGL_WINDOW_BIT) { |
| 509 | /* According current EGL spec, front buffer rendering |
| 510 | * for window surface is not supported now. |
| 511 | * and mesa doesn't have the implementation of this case. |
| 512 | * Add warning message, but not treat it as error. |
| 513 | */ |
| 514 | _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for window surface"); |
| 515 | } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) { |
| 516 | dri2_surf->dri_image_front = |
| 517 | dri2_dpy->image->createImage(dri2_dpy->dri_screen, |
| 518 | dri2_surf->base.Width, |
| 519 | dri2_surf->base.Height, |
| 520 | format, |
| 521 | 0, |
| 522 | dri2_surf); |
| 523 | if (!dri2_surf->dri_image_front) { |
| 524 | _eglLog(_EGL_WARNING, "dri2_image_front allocation failed"); |
| 525 | return -1; |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static int |
Chad Versace | 22d6b08 | 2017-05-23 17:26:52 -0700 | [diff] [blame] | 533 | get_back_bo(struct dri2_egl_surface *dri2_surf) |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 534 | { |
| 535 | struct dri2_egl_display *dri2_dpy = |
| 536 | dri2_egl_display(dri2_surf->base.Resource.Display); |
Emil Velikov | fb65364 | 2016-05-01 09:35:56 +0100 | [diff] [blame] | 537 | int fourcc, pitch; |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 538 | int offset = 0, fd; |
| 539 | |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 540 | if (dri2_surf->dri_image_back) |
| 541 | return 0; |
Tomasz Figa | 9e1248d | 2016-07-15 16:53:50 +0900 | [diff] [blame] | 542 | |
Liu Zhiquan | e2610bf | 2016-12-09 19:29:56 +0800 | [diff] [blame] | 543 | if (dri2_surf->base.Type == EGL_WINDOW_BIT) { |
| 544 | if (!dri2_surf->buffer) { |
| 545 | _eglLog(_EGL_WARNING, "Could not get native buffer"); |
| 546 | return -1; |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 547 | } |
| 548 | |
Liu Zhiquan | e2610bf | 2016-12-09 19:29:56 +0800 | [diff] [blame] | 549 | fd = get_native_buffer_fd(dri2_surf->buffer); |
| 550 | if (fd < 0) { |
| 551 | _eglLog(_EGL_WARNING, "Could not get native buffer FD"); |
| 552 | return -1; |
| 553 | } |
| 554 | |
| 555 | fourcc = get_fourcc(dri2_surf->buffer->format); |
| 556 | |
| 557 | pitch = dri2_surf->buffer->stride * |
| 558 | get_format_bpp(dri2_surf->buffer->format); |
| 559 | |
| 560 | if (fourcc == -1 || pitch == 0) { |
| 561 | _eglLog(_EGL_WARNING, "Invalid buffer fourcc(%x) or pitch(%d)", |
| 562 | fourcc, pitch); |
| 563 | return -1; |
| 564 | } |
| 565 | |
| 566 | dri2_surf->dri_image_back = |
| 567 | dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen, |
| 568 | dri2_surf->base.Width, |
| 569 | dri2_surf->base.Height, |
| 570 | fourcc, |
| 571 | &fd, |
| 572 | 1, |
| 573 | &pitch, |
| 574 | &offset, |
| 575 | dri2_surf); |
| 576 | if (!dri2_surf->dri_image_back) { |
| 577 | _eglLog(_EGL_WARNING, "failed to create DRI image from FD"); |
| 578 | return -1; |
| 579 | } |
| 580 | } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) { |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 581 | /* The EGL 1.5 spec states that pbuffers are single-buffered. Specifically, |
| 582 | * the spec states that they have a back buffer but no front buffer, in |
| 583 | * contrast to pixmaps, which have a front buffer but no back buffer. |
| 584 | * |
| 585 | * Single-buffered surfaces with no front buffer confuse Mesa; so we deviate |
| 586 | * from the spec, following the precedent of Mesa's EGL X11 platform. The |
| 587 | * X11 platform correctly assigns pbuffers to single-buffered configs, but |
| 588 | * assigns the pbuffer a front buffer instead of a back buffer. |
| 589 | * |
| 590 | * Pbuffers in the X11 platform mostly work today, so let's just copy its |
| 591 | * behavior instead of trying to fix (and hence potentially breaking) the |
| 592 | * world. |
Tomasz Figa | 217af75 | 2016-08-02 20:07:50 +0900 | [diff] [blame] | 593 | */ |
Liu Zhiquan | e2610bf | 2016-12-09 19:29:56 +0800 | [diff] [blame] | 594 | _eglLog(_EGL_DEBUG, "DRI driver requested unsupported back buffer for pbuffer surface"); |
| 595 | } |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 596 | |
Liu Zhiquan | e2610bf | 2016-12-09 19:29:56 +0800 | [diff] [blame] | 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | /* Some drivers will pass multiple bits in buffer_mask. |
| 601 | * For such case, will go through all the bits, and |
| 602 | * will not return error when unsupported buffer is requested, only |
| 603 | * return error when the allocation for supported buffer failed. |
| 604 | */ |
| 605 | static int |
| 606 | droid_image_get_buffers(__DRIdrawable *driDrawable, |
| 607 | unsigned int format, |
| 608 | uint32_t *stamp, |
| 609 | void *loaderPrivate, |
| 610 | uint32_t buffer_mask, |
| 611 | struct __DRIimageList *images) |
| 612 | { |
| 613 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 614 | |
| 615 | images->image_mask = 0; |
| 616 | images->front = NULL; |
| 617 | images->back = NULL; |
| 618 | |
| 619 | if (update_buffers(dri2_surf) < 0) |
| 620 | return 0; |
| 621 | |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame^] | 622 | if (_eglSurfaceInSharedBufferMode(&dri2_surf->base)) { |
| 623 | if (get_back_bo(dri2_surf) < 0) |
| 624 | return 0; |
| 625 | |
| 626 | /* We have dri_image_back because this is a window surface and |
| 627 | * get_back_bo() succeeded. |
| 628 | */ |
| 629 | assert(dri2_surf->dri_image_back); |
| 630 | images->back = dri2_surf->dri_image_back; |
| 631 | images->image_mask |= __DRI_IMAGE_BUFFER_SHARED; |
| 632 | |
| 633 | /* There exists no accompanying back nor front buffer. */ |
| 634 | return 1; |
| 635 | } |
| 636 | |
Liu Zhiquan | e2610bf | 2016-12-09 19:29:56 +0800 | [diff] [blame] | 637 | if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) { |
| 638 | if (get_front_bo(dri2_surf, format) < 0) |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 639 | return 0; |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 640 | |
Liu Zhiquan | e2610bf | 2016-12-09 19:29:56 +0800 | [diff] [blame] | 641 | if (dri2_surf->dri_image_front) { |
| 642 | images->front = dri2_surf->dri_image_front; |
| 643 | images->image_mask |= __DRI_IMAGE_BUFFER_FRONT; |
| 644 | } |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 645 | } |
| 646 | |
Tomasz Figa | 217af75 | 2016-08-02 20:07:50 +0900 | [diff] [blame] | 647 | if (buffer_mask & __DRI_IMAGE_BUFFER_BACK) { |
Chad Versace | 22d6b08 | 2017-05-23 17:26:52 -0700 | [diff] [blame] | 648 | if (get_back_bo(dri2_surf) < 0) |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 649 | return 0; |
Liu Zhiquan | b663753 | 2016-11-16 10:11:28 +0800 | [diff] [blame] | 650 | |
Liu Zhiquan | e2610bf | 2016-12-09 19:29:56 +0800 | [diff] [blame] | 651 | if (dri2_surf->dri_image_back) { |
| 652 | images->back = dri2_surf->dri_image_back; |
| 653 | images->image_mask |= __DRI_IMAGE_BUFFER_BACK; |
| 654 | } |
Tomasz Figa | 217af75 | 2016-08-02 20:07:50 +0900 | [diff] [blame] | 655 | } |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 656 | |
| 657 | return 1; |
| 658 | } |
| 659 | |
Xiaosong Wei | 2acc69d | 2017-02-08 10:46:02 +0800 | [diff] [blame] | 660 | static EGLint |
| 661 | droid_query_buffer_age(_EGLDriver *drv, |
| 662 | _EGLDisplay *disp, _EGLSurface *surface) |
| 663 | { |
| 664 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surface); |
| 665 | |
| 666 | if (update_buffers(dri2_surf) < 0) { |
| 667 | _eglError(EGL_BAD_ALLOC, "droid_query_buffer_age"); |
Tapani Pälli | 8fac894 | 2017-06-08 12:24:24 +0300 | [diff] [blame] | 668 | return -1; |
Xiaosong Wei | 2acc69d | 2017-02-08 10:46:02 +0800 | [diff] [blame] | 669 | } |
| 670 | |
Tapani Pälli | 8fac894 | 2017-06-08 12:24:24 +0300 | [diff] [blame] | 671 | return dri2_surf->back ? dri2_surf->back->age : 0; |
Xiaosong Wei | 2acc69d | 2017-02-08 10:46:02 +0800 | [diff] [blame] | 672 | } |
| 673 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 674 | static EGLBoolean |
| 675 | droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) |
| 676 | { |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 677 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 678 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 679 | |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 680 | if (dri2_surf->base.Type != EGL_WINDOW_BIT) |
| 681 | return EGL_TRUE; |
| 682 | |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame^] | 683 | const bool has_mutable_rb = _eglSurfaceHasMutableRenderBuffer(draw); |
| 684 | |
| 685 | /* From the EGL_KHR_mutable_render_buffer spec (v12): |
| 686 | * |
| 687 | * If surface is a single-buffered window, pixmap, or pbuffer surface |
| 688 | * for which there is no pending change to the EGL_RENDER_BUFFER |
| 689 | * attribute, eglSwapBuffers has no effect. |
| 690 | */ |
| 691 | if (has_mutable_rb && |
| 692 | draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER && |
| 693 | draw->ActiveRenderBuffer == EGL_SINGLE_BUFFER) { |
| 694 | _eglLog(_EGL_DEBUG, "%s: remain in shared buffer mode", __func__); |
| 695 | return EGL_TRUE; |
| 696 | } |
| 697 | |
Xiaosong Wei | 2acc69d | 2017-02-08 10:46:02 +0800 | [diff] [blame] | 698 | for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { |
| 699 | if (dri2_surf->color_buffers[i].age > 0) |
| 700 | dri2_surf->color_buffers[i].age++; |
| 701 | } |
Tapani Pälli | f347bac | 2017-05-18 10:21:59 +0300 | [diff] [blame] | 702 | |
| 703 | /* "XXX: we don't use get_back_bo() since it causes regressions in |
| 704 | * several dEQP tests. |
| 705 | */ |
| 706 | if (dri2_surf->back) |
| 707 | dri2_surf->back->age = 1; |
Xiaosong Wei | 2acc69d | 2017-02-08 10:46:02 +0800 | [diff] [blame] | 708 | |
Eric Anholt | 70e8ccc | 2014-12-21 11:51:33 -0800 | [diff] [blame] | 709 | dri2_flush_drawable_for_swapbuffers(disp, draw); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 710 | |
Chad Versace | e5eace5 | 2017-05-04 17:46:34 -0700 | [diff] [blame] | 711 | /* dri2_surf->buffer can be null even when no error has occured. For |
| 712 | * example, if the user has called no GL rendering commands since the |
| 713 | * previous eglSwapBuffers, then the driver may have not triggered |
| 714 | * a callback to ANativeWindow::dequeueBuffer, in which case |
| 715 | * dri2_surf->buffer remains null. |
| 716 | */ |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 717 | if (dri2_surf->buffer) |
Haixia Shi | 1ea233c | 2016-06-02 12:48:23 -0700 | [diff] [blame] | 718 | droid_window_enqueue_buffer(disp, dri2_surf); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 719 | |
Boyan Ding | 868ae3e | 2015-11-25 13:27:02 +0800 | [diff] [blame] | 720 | dri2_dpy->flush->invalidate(dri2_surf->dri_drawable); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 721 | |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame^] | 722 | /* Update the shared buffer mode */ |
| 723 | if (has_mutable_rb && |
| 724 | draw->ActiveRenderBuffer != draw->RequestedRenderBuffer) { |
| 725 | bool mode = (draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER); |
| 726 | _eglLog(_EGL_DEBUG, "%s: change to shared buffer mode %d", |
| 727 | __func__, mode); |
| 728 | |
| 729 | if (!droid_set_shared_buffer_mode(disp, draw, mode)) |
| 730 | return EGL_FALSE; |
| 731 | draw->ActiveRenderBuffer = draw->RequestedRenderBuffer; |
| 732 | } |
| 733 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 734 | return EGL_TRUE; |
| 735 | } |
| 736 | |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 737 | #if ANDROID_API_LEVEL >= 23 |
| 738 | static EGLBoolean |
| 739 | droid_set_damage_region(_EGLDriver *drv, |
| 740 | _EGLDisplay *disp, |
| 741 | _EGLSurface *draw, const EGLint* rects, EGLint n_rects) |
| 742 | { |
| 743 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 744 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
| 745 | android_native_rect_t* droid_rects = NULL; |
| 746 | int ret; |
| 747 | |
| 748 | if (n_rects == 0) |
| 749 | return EGL_TRUE; |
| 750 | |
| 751 | droid_rects = malloc(n_rects * sizeof(android_native_rect_t)); |
Emil Velikov | c58af5c | 2017-06-20 15:40:28 +0100 | [diff] [blame] | 752 | if (droid_rects == NULL) |
| 753 | return _eglError(EGL_BAD_ALLOC, "eglSetDamageRegionKHR"); |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 754 | |
| 755 | for (EGLint num_drects = 0; num_drects < n_rects; num_drects++) { |
| 756 | EGLint i = num_drects * 4; |
| 757 | droid_rects[num_drects].left = rects[i]; |
| 758 | droid_rects[num_drects].bottom = rects[i + 1]; |
| 759 | droid_rects[num_drects].right = rects[i] + rects[i + 2]; |
| 760 | droid_rects[num_drects].top = rects[i + 1] + rects[i + 3]; |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | * XXX/TODO: Need to check for other return values |
| 765 | */ |
| 766 | |
| 767 | ret = native_window_set_surface_damage(dri2_surf->window, droid_rects, n_rects); |
| 768 | free(droid_rects); |
| 769 | |
| 770 | return ret == 0 ? EGL_TRUE : EGL_FALSE; |
| 771 | } |
| 772 | #endif |
| 773 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 774 | static _EGLImage * |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 775 | droid_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx, |
| 776 | struct ANativeWindowBuffer *buf, int fd) |
Tomasz Figa | e77b493 | 2016-08-02 20:07:52 +0900 | [diff] [blame] | 777 | { |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 778 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 779 | struct android_ycbcr ycbcr; |
| 780 | size_t offsets[3]; |
| 781 | size_t pitches[3]; |
| 782 | int is_ycrcb; |
| 783 | int fourcc; |
| 784 | int ret; |
Tomasz Figa | e77b493 | 2016-08-02 20:07:52 +0900 | [diff] [blame] | 785 | |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 786 | if (!dri2_dpy->gralloc->lock_ycbcr) { |
| 787 | _eglLog(_EGL_WARNING, "Gralloc does not support lock_ycbcr"); |
| 788 | return NULL; |
| 789 | } |
| 790 | |
| 791 | memset(&ycbcr, 0, sizeof(ycbcr)); |
| 792 | ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle, |
| 793 | 0, 0, 0, 0, 0, &ycbcr); |
| 794 | if (ret) { |
Tomasz Figa | 5364e73 | 2017-12-04 19:22:39 +0100 | [diff] [blame] | 795 | /* HACK: See droid_create_image_from_prime_fd() and |
| 796 | * https://issuetracker.google.com/32077885.*/ |
| 797 | if (buf->format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) |
| 798 | return NULL; |
| 799 | |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 800 | _eglLog(_EGL_WARNING, "gralloc->lock_ycbcr failed: %d", ret); |
| 801 | return NULL; |
| 802 | } |
| 803 | dri2_dpy->gralloc->unlock(dri2_dpy->gralloc, buf->handle); |
| 804 | |
| 805 | /* When lock_ycbcr's usage argument contains no SW_READ/WRITE flags |
| 806 | * it will return the .y/.cb/.cr pointers based on a NULL pointer, |
| 807 | * so they can be interpreted as offsets. */ |
| 808 | offsets[0] = (size_t)ycbcr.y; |
| 809 | /* We assume here that all the planes are located in one DMA-buf. */ |
Tapani Pälli | 0a2dcd3 | 2017-02-02 14:05:46 +0200 | [diff] [blame] | 810 | is_ycrcb = (size_t)ycbcr.cr < (size_t)ycbcr.cb; |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 811 | if (is_ycrcb) { |
| 812 | offsets[1] = (size_t)ycbcr.cr; |
| 813 | offsets[2] = (size_t)ycbcr.cb; |
| 814 | } else { |
| 815 | offsets[1] = (size_t)ycbcr.cb; |
| 816 | offsets[2] = (size_t)ycbcr.cr; |
| 817 | } |
| 818 | |
| 819 | /* .ystride is the line length (in bytes) of the Y plane, |
| 820 | * .cstride is the line length (in bytes) of any of the remaining |
| 821 | * Cb/Cr/CbCr planes, assumed to be the same for Cb and Cr for fully |
| 822 | * planar formats. */ |
| 823 | pitches[0] = ycbcr.ystride; |
| 824 | pitches[1] = pitches[2] = ycbcr.cstride; |
| 825 | |
| 826 | /* .chroma_step is the byte distance between the same chroma channel |
| 827 | * values of subsequent pixels, assumed to be the same for Cb and Cr. */ |
| 828 | fourcc = get_fourcc_yuv(buf->format, is_ycrcb, ycbcr.chroma_step); |
Tomasz Figa | 3723e98 | 2016-08-02 20:07:54 +0900 | [diff] [blame] | 829 | if (fourcc == -1) { |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 830 | _eglLog(_EGL_WARNING, "unsupported YUV format, native = %x, is_ycrcb = %d, chroma_step = %d", |
| 831 | buf->format, is_ycrcb, ycbcr.chroma_step); |
Tomasz Figa | 3723e98 | 2016-08-02 20:07:54 +0900 | [diff] [blame] | 832 | return NULL; |
| 833 | } |
| 834 | |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 835 | if (ycbcr.chroma_step == 2) { |
Robert Foss | a4d3371 | 2017-06-15 16:47:53 -0400 | [diff] [blame] | 836 | /* Semi-planar Y + CbCr or Y + CrCb format. */ |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 837 | const EGLint attr_list_2plane[] = { |
| 838 | EGL_WIDTH, buf->width, |
| 839 | EGL_HEIGHT, buf->height, |
| 840 | EGL_LINUX_DRM_FOURCC_EXT, fourcc, |
| 841 | EGL_DMA_BUF_PLANE0_FD_EXT, fd, |
| 842 | EGL_DMA_BUF_PLANE0_PITCH_EXT, pitches[0], |
| 843 | EGL_DMA_BUF_PLANE0_OFFSET_EXT, offsets[0], |
| 844 | EGL_DMA_BUF_PLANE1_FD_EXT, fd, |
| 845 | EGL_DMA_BUF_PLANE1_PITCH_EXT, pitches[1], |
| 846 | EGL_DMA_BUF_PLANE1_OFFSET_EXT, offsets[1], |
| 847 | EGL_NONE, 0 |
| 848 | }; |
Tomasz Figa | 3723e98 | 2016-08-02 20:07:54 +0900 | [diff] [blame] | 849 | |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 850 | return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list_2plane); |
| 851 | } else { |
| 852 | /* Fully planar Y + Cb + Cr or Y + Cr + Cb format. */ |
| 853 | const EGLint attr_list_3plane[] = { |
Tomasz Figa | 3723e98 | 2016-08-02 20:07:54 +0900 | [diff] [blame] | 854 | EGL_WIDTH, buf->width, |
| 855 | EGL_HEIGHT, buf->height, |
| 856 | EGL_LINUX_DRM_FOURCC_EXT, fourcc, |
| 857 | EGL_DMA_BUF_PLANE0_FD_EXT, fd, |
| 858 | EGL_DMA_BUF_PLANE0_PITCH_EXT, pitches[0], |
| 859 | EGL_DMA_BUF_PLANE0_OFFSET_EXT, offsets[0], |
| 860 | EGL_DMA_BUF_PLANE1_FD_EXT, fd, |
| 861 | EGL_DMA_BUF_PLANE1_PITCH_EXT, pitches[1], |
| 862 | EGL_DMA_BUF_PLANE1_OFFSET_EXT, offsets[1], |
| 863 | EGL_DMA_BUF_PLANE2_FD_EXT, fd, |
| 864 | EGL_DMA_BUF_PLANE2_PITCH_EXT, pitches[2], |
| 865 | EGL_DMA_BUF_PLANE2_OFFSET_EXT, offsets[2], |
| 866 | EGL_NONE, 0 |
| 867 | }; |
| 868 | |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 869 | return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list_3plane); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | static _EGLImage * |
| 874 | droid_create_image_from_prime_fd(_EGLDisplay *disp, _EGLContext *ctx, |
| 875 | struct ANativeWindowBuffer *buf, int fd) |
| 876 | { |
| 877 | unsigned int pitch; |
| 878 | |
Tomasz Figa | 5364e73 | 2017-12-04 19:22:39 +0100 | [diff] [blame] | 879 | if (is_yuv(buf->format)) { |
| 880 | _EGLImage *image; |
| 881 | |
| 882 | image = droid_create_image_from_prime_fd_yuv(disp, ctx, buf, fd); |
| 883 | /* |
| 884 | * HACK: https://issuetracker.google.com/32077885 |
| 885 | * There is no API available to properly query the IMPLEMENTATION_DEFINED |
| 886 | * format. As a workaround we rely here on gralloc allocating either |
| 887 | * an arbitrary YCbCr 4:2:0 or RGBX_8888, with the latter being recognized |
| 888 | * by lock_ycbcr failing. |
| 889 | */ |
| 890 | if (image || buf->format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) |
| 891 | return image; |
| 892 | } |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 893 | |
| 894 | const int fourcc = get_fourcc(buf->format); |
| 895 | if (fourcc == -1) { |
| 896 | _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR"); |
| 897 | return NULL; |
| 898 | } |
| 899 | |
| 900 | pitch = buf->stride * get_format_bpp(buf->format); |
| 901 | if (pitch == 0) { |
| 902 | _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR"); |
| 903 | return NULL; |
Tomasz Figa | 3723e98 | 2016-08-02 20:07:54 +0900 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | const EGLint attr_list[] = { |
Tomasz Figa | e77b493 | 2016-08-02 20:07:52 +0900 | [diff] [blame] | 907 | EGL_WIDTH, buf->width, |
| 908 | EGL_HEIGHT, buf->height, |
| 909 | EGL_LINUX_DRM_FOURCC_EXT, fourcc, |
| 910 | EGL_DMA_BUF_PLANE0_FD_EXT, fd, |
Tomasz Figa | 51727b1 | 2016-11-10 16:55:53 +0900 | [diff] [blame] | 911 | EGL_DMA_BUF_PLANE0_PITCH_EXT, pitch, |
Tomasz Figa | e77b493 | 2016-08-02 20:07:52 +0900 | [diff] [blame] | 912 | EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, |
| 913 | EGL_NONE, 0 |
| 914 | }; |
| 915 | |
Tomasz Figa | e77b493 | 2016-08-02 20:07:52 +0900 | [diff] [blame] | 916 | return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list); |
| 917 | } |
| 918 | |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 919 | #ifdef HAVE_DRM_GRALLOC |
Tomasz Figa | e77b493 | 2016-08-02 20:07:52 +0900 | [diff] [blame] | 920 | static _EGLImage * |
| 921 | droid_create_image_from_name(_EGLDisplay *disp, _EGLContext *ctx, |
| 922 | struct ANativeWindowBuffer *buf) |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 923 | { |
| 924 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| 925 | struct dri2_egl_image *dri2_img; |
Tomasz Figa | e77b493 | 2016-08-02 20:07:52 +0900 | [diff] [blame] | 926 | int name; |
Emil Velikov | fb65364 | 2016-05-01 09:35:56 +0100 | [diff] [blame] | 927 | int format; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 928 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 929 | name = get_native_buffer_name(buf); |
| 930 | if (!name) { |
| 931 | _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR"); |
| 932 | return NULL; |
| 933 | } |
| 934 | |
Emil Velikov | fb65364 | 2016-05-01 09:35:56 +0100 | [diff] [blame] | 935 | format = get_format(buf->format); |
| 936 | if (format == -1) |
| 937 | return NULL; |
| 938 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 939 | dri2_img = calloc(1, sizeof(*dri2_img)); |
| 940 | if (!dri2_img) { |
| 941 | _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm"); |
| 942 | return NULL; |
| 943 | } |
| 944 | |
Emil Velikov | d42b095 | 2017-06-20 15:22:39 +0100 | [diff] [blame] | 945 | _eglInitImage(&dri2_img->base, disp); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 946 | |
| 947 | dri2_img->dri_image = |
| 948 | dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, |
| 949 | buf->width, |
| 950 | buf->height, |
Emil Velikov | fb65364 | 2016-05-01 09:35:56 +0100 | [diff] [blame] | 951 | format, |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 952 | name, |
| 953 | buf->stride, |
| 954 | dri2_img); |
| 955 | if (!dri2_img->dri_image) { |
| 956 | free(dri2_img); |
| 957 | _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm"); |
| 958 | return NULL; |
| 959 | } |
| 960 | |
| 961 | return &dri2_img->base; |
| 962 | } |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 963 | #endif /* HAVE_DRM_GRALLOC */ |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 964 | |
Haixia Shi | a7c6993 | 2016-07-28 10:51:12 -0700 | [diff] [blame] | 965 | static EGLBoolean |
| 966 | droid_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, |
| 967 | EGLint attribute, EGLint *value) |
| 968 | { |
| 969 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
| 970 | switch (attribute) { |
| 971 | case EGL_WIDTH: |
| 972 | if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) { |
| 973 | dri2_surf->window->query(dri2_surf->window, |
| 974 | NATIVE_WINDOW_DEFAULT_WIDTH, value); |
| 975 | return EGL_TRUE; |
| 976 | } |
| 977 | break; |
| 978 | case EGL_HEIGHT: |
| 979 | if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) { |
| 980 | dri2_surf->window->query(dri2_surf->window, |
| 981 | NATIVE_WINDOW_DEFAULT_HEIGHT, value); |
| 982 | return EGL_TRUE; |
| 983 | } |
| 984 | break; |
| 985 | default: |
| 986 | break; |
| 987 | } |
| 988 | return _eglQuerySurface(drv, dpy, surf, attribute, value); |
| 989 | } |
| 990 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 991 | static _EGLImage * |
Tomasz Figa | e77b493 | 2016-08-02 20:07:52 +0900 | [diff] [blame] | 992 | dri2_create_image_android_native_buffer(_EGLDisplay *disp, |
| 993 | _EGLContext *ctx, |
| 994 | struct ANativeWindowBuffer *buf) |
| 995 | { |
| 996 | int fd; |
| 997 | |
| 998 | if (ctx != NULL) { |
| 999 | /* From the EGL_ANDROID_image_native_buffer spec: |
| 1000 | * |
| 1001 | * * If <target> is EGL_NATIVE_BUFFER_ANDROID and <ctx> is not |
| 1002 | * EGL_NO_CONTEXT, the error EGL_BAD_CONTEXT is generated. |
| 1003 | */ |
| 1004 | _eglError(EGL_BAD_CONTEXT, "eglCreateEGLImageKHR: for " |
| 1005 | "EGL_NATIVE_BUFFER_ANDROID, the context must be " |
| 1006 | "EGL_NO_CONTEXT"); |
| 1007 | return NULL; |
| 1008 | } |
| 1009 | |
| 1010 | if (!buf || buf->common.magic != ANDROID_NATIVE_BUFFER_MAGIC || |
| 1011 | buf->common.version != sizeof(*buf)) { |
| 1012 | _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR"); |
| 1013 | return NULL; |
| 1014 | } |
| 1015 | |
| 1016 | fd = get_native_buffer_fd(buf); |
| 1017 | if (fd >= 0) |
| 1018 | return droid_create_image_from_prime_fd(disp, ctx, buf, fd); |
| 1019 | |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 1020 | #ifdef HAVE_DRM_GRALLOC |
Tomasz Figa | e77b493 | 2016-08-02 20:07:52 +0900 | [diff] [blame] | 1021 | return droid_create_image_from_name(disp, ctx, buf); |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 1022 | #else |
| 1023 | return NULL; |
| 1024 | #endif |
Tomasz Figa | e77b493 | 2016-08-02 20:07:52 +0900 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | static _EGLImage * |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1028 | droid_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
| 1029 | _EGLContext *ctx, EGLenum target, |
| 1030 | EGLClientBuffer buffer, const EGLint *attr_list) |
| 1031 | { |
| 1032 | switch (target) { |
| 1033 | case EGL_NATIVE_BUFFER_ANDROID: |
Emil Velikov | 9b3c748 | 2016-05-01 12:42:54 +0100 | [diff] [blame] | 1034 | return dri2_create_image_android_native_buffer(disp, ctx, |
Chia-I Wu | 75cc24c | 2011-11-25 11:59:02 +0800 | [diff] [blame] | 1035 | (struct ANativeWindowBuffer *) buffer); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1036 | default: |
| 1037 | return dri2_create_image_khr(drv, disp, ctx, target, buffer, attr_list); |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | static void |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1042 | droid_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) |
| 1043 | { |
| 1044 | } |
| 1045 | |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 1046 | #ifdef HAVE_DRM_GRALLOC |
Chia-I Wu | 384f228 | 2011-08-26 23:49:04 +0800 | [diff] [blame] | 1047 | static int |
| 1048 | droid_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf, |
| 1049 | unsigned int *attachments, int count) |
| 1050 | { |
Chad Versace | 0945512 | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 1051 | int num_buffers = 0; |
Chia-I Wu | 384f228 | 2011-08-26 23:49:04 +0800 | [diff] [blame] | 1052 | |
| 1053 | /* fill dri2_surf->buffers */ |
Chad Versace | 0945512 | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 1054 | for (int i = 0; i < count * 2; i += 2) { |
Chia-I Wu | 384f228 | 2011-08-26 23:49:04 +0800 | [diff] [blame] | 1055 | __DRIbuffer *buf, *local; |
| 1056 | |
| 1057 | assert(num_buffers < ARRAY_SIZE(dri2_surf->buffers)); |
| 1058 | buf = &dri2_surf->buffers[num_buffers]; |
| 1059 | |
| 1060 | switch (attachments[i]) { |
| 1061 | case __DRI_BUFFER_BACK_LEFT: |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 1062 | if (dri2_surf->base.Type == EGL_WINDOW_BIT) { |
| 1063 | buf->attachment = attachments[i]; |
| 1064 | buf->name = get_native_buffer_name(dri2_surf->buffer); |
| 1065 | buf->cpp = get_format_bpp(dri2_surf->buffer->format); |
| 1066 | buf->pitch = dri2_surf->buffer->stride * buf->cpp; |
| 1067 | buf->flags = 0; |
Chia-I Wu | 384f228 | 2011-08-26 23:49:04 +0800 | [diff] [blame] | 1068 | |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 1069 | if (buf->name) |
| 1070 | num_buffers++; |
Chia-I Wu | 93d5963 | 2011-08-27 00:00:18 +0800 | [diff] [blame] | 1071 | |
| 1072 | break; |
Chia-I Wu | c8e18f8 | 2011-08-26 22:09:56 +0800 | [diff] [blame] | 1073 | } |
Chia-I Wu | 93d5963 | 2011-08-27 00:00:18 +0800 | [diff] [blame] | 1074 | /* fall through for pbuffers */ |
Chia-I Wu | 384f228 | 2011-08-26 23:49:04 +0800 | [diff] [blame] | 1075 | case __DRI_BUFFER_DEPTH: |
| 1076 | case __DRI_BUFFER_STENCIL: |
| 1077 | case __DRI_BUFFER_ACCUM: |
| 1078 | case __DRI_BUFFER_DEPTH_STENCIL: |
| 1079 | case __DRI_BUFFER_HIZ: |
Gwan-gyeong Mun | 640b6e6 | 2017-08-05 00:16:11 +0900 | [diff] [blame] | 1080 | local = dri2_egl_surface_alloc_local_buffer(dri2_surf, |
Chia-I Wu | 384f228 | 2011-08-26 23:49:04 +0800 | [diff] [blame] | 1081 | attachments[i], attachments[i + 1]); |
| 1082 | |
| 1083 | if (local) { |
| 1084 | *buf = *local; |
| 1085 | num_buffers++; |
| 1086 | } |
| 1087 | break; |
| 1088 | case __DRI_BUFFER_FRONT_LEFT: |
| 1089 | case __DRI_BUFFER_FRONT_RIGHT: |
| 1090 | case __DRI_BUFFER_FAKE_FRONT_LEFT: |
| 1091 | case __DRI_BUFFER_FAKE_FRONT_RIGHT: |
| 1092 | case __DRI_BUFFER_BACK_RIGHT: |
| 1093 | default: |
| 1094 | /* no front or right buffers */ |
| 1095 | break; |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | return num_buffers; |
| 1100 | } |
| 1101 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1102 | static __DRIbuffer * |
| 1103 | droid_get_buffers_with_format(__DRIdrawable * driDrawable, |
| 1104 | int *width, int *height, |
| 1105 | unsigned int *attachments, int count, |
| 1106 | int *out_count, void *loaderPrivate) |
| 1107 | { |
| 1108 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1109 | |
Rob Herring | 81a6fff | 2016-04-28 15:37:30 -0500 | [diff] [blame] | 1110 | if (update_buffers(dri2_surf) < 0) |
| 1111 | return NULL; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1112 | |
Gwan-gyeong Mun | 3f6cc93 | 2017-07-18 17:12:26 +0900 | [diff] [blame] | 1113 | *out_count = droid_get_buffers_parse_attachments(dri2_surf, attachments, count); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1114 | |
| 1115 | if (width) |
| 1116 | *width = dri2_surf->base.Width; |
| 1117 | if (height) |
| 1118 | *height = dri2_surf->base.Height; |
| 1119 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1120 | return dri2_surf->buffers; |
| 1121 | } |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 1122 | #endif /* HAVE_DRM_GRALLOC */ |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1123 | |
Marek Olšák | 1bf703e | 2017-07-28 17:30:34 +0200 | [diff] [blame] | 1124 | static unsigned |
| 1125 | droid_get_capability(void *loaderPrivate, enum dri_loader_cap cap) |
| 1126 | { |
| 1127 | /* Note: loaderPrivate is _EGLDisplay* */ |
| 1128 | switch (cap) { |
| 1129 | case DRI_LOADER_CAP_RGBA_ORDERING: |
| 1130 | return 1; |
| 1131 | default: |
| 1132 | return 0; |
| 1133 | } |
| 1134 | } |
| 1135 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1136 | static EGLBoolean |
| 1137 | droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy) |
| 1138 | { |
| 1139 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); |
Emil Velikov | 4472b6e | 2016-08-25 12:08:07 +0100 | [diff] [blame] | 1140 | static const struct { |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1141 | int format; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1142 | unsigned int rgba_masks[4]; |
| 1143 | } visuals[] = { |
Chad Versace | 0bcdceb | 2017-05-23 15:50:13 -0700 | [diff] [blame] | 1144 | { HAL_PIXEL_FORMAT_RGBA_8888, { 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 } }, |
| 1145 | { HAL_PIXEL_FORMAT_RGBX_8888, { 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 } }, |
| 1146 | { HAL_PIXEL_FORMAT_RGB_565, { 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000 } }, |
| 1147 | { HAL_PIXEL_FORMAT_BGRA_8888, { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 } }, |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1148 | }; |
Chad Versace | 0945512 | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 1149 | |
Emil Velikov | acd35c8 | 2016-08-25 14:28:48 +0100 | [diff] [blame] | 1150 | unsigned int format_count[ARRAY_SIZE(visuals)] = { 0 }; |
Chad Versace | ffbf50b | 2017-06-22 11:00:41 -0700 | [diff] [blame] | 1151 | int config_count = 0; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1152 | |
Chad Versace | 5e88435 | 2017-06-16 19:11:21 -0700 | [diff] [blame] | 1153 | /* The nesting of loops is significant here. Also significant is the order |
| 1154 | * of the HAL pixel formats. Many Android apps (such as Google's official |
| 1155 | * NDK GLES2 example app), and even portions the core framework code (such |
| 1156 | * as SystemServiceManager in Nougat), incorrectly choose their EGLConfig. |
| 1157 | * They neglect to match the EGLConfig's EGL_NATIVE_VISUAL_ID against the |
| 1158 | * window's native format, and instead choose the first EGLConfig whose |
| 1159 | * channel sizes match those of the native window format while ignoring the |
| 1160 | * channel *ordering*. |
| 1161 | * |
| 1162 | * We can detect such buggy clients in logcat when they call |
| 1163 | * eglCreateSurface, by detecting the mismatch between the EGLConfig's |
| 1164 | * format and the window's format. |
| 1165 | * |
| 1166 | * As a workaround, we generate EGLConfigs such that all EGLConfigs for HAL |
| 1167 | * pixel format i precede those for HAL pixel format i+1. In my |
| 1168 | * (chadversary) testing on Android Nougat, this was good enough to pacify |
| 1169 | * the buggy clients. |
| 1170 | */ |
Chad Versace | 0945512 | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 1171 | for (int i = 0; i < ARRAY_SIZE(visuals); i++) { |
| 1172 | for (int j = 0; dri2_dpy->driver_configs[j]; j++) { |
| 1173 | const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT; |
Tapani Pälli | d58ca43 | 2012-08-13 16:47:52 +0300 | [diff] [blame] | 1174 | |
Chad Versace | bd78909 | 2017-06-22 11:00:41 -0700 | [diff] [blame] | 1175 | const EGLint config_attrs[] = { |
| 1176 | EGL_NATIVE_VISUAL_ID, visuals[i].format, |
| 1177 | EGL_NATIVE_VISUAL_TYPE, visuals[i].format, |
| 1178 | EGL_FRAMEBUFFER_TARGET_ANDROID, EGL_TRUE, |
| 1179 | EGL_RECORDABLE_ANDROID, EGL_TRUE, |
| 1180 | EGL_NONE |
| 1181 | }; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1182 | |
Chad Versace | 0945512 | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 1183 | struct dri2_egl_config *dri2_conf = |
| 1184 | dri2_add_config(dpy, dri2_dpy->driver_configs[j], |
Chad Versace | ffbf50b | 2017-06-22 11:00:41 -0700 | [diff] [blame] | 1185 | config_count + 1, surface_type, config_attrs, |
Chad Versace | 0945512 | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 1186 | visuals[i].rgba_masks); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1187 | if (dri2_conf) { |
Chad Versace | ffbf50b | 2017-06-22 11:00:41 -0700 | [diff] [blame] | 1188 | if (dri2_conf->base.ConfigID == config_count + 1) |
| 1189 | config_count++; |
Chad Versace | 5e88435 | 2017-06-16 19:11:21 -0700 | [diff] [blame] | 1190 | format_count[i]++; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1191 | } |
| 1192 | } |
Emil Velikov | acd35c8 | 2016-08-25 14:28:48 +0100 | [diff] [blame] | 1193 | } |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1194 | |
Chad Versace | 0945512 | 2017-06-22 11:00:40 -0700 | [diff] [blame] | 1195 | for (int i = 0; i < ARRAY_SIZE(format_count); i++) { |
Emil Velikov | acd35c8 | 2016-08-25 14:28:48 +0100 | [diff] [blame] | 1196 | if (!format_count[i]) { |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1197 | _eglLog(_EGL_DEBUG, "No DRI config supports native format 0x%x", |
Emil Velikov | acd35c8 | 2016-08-25 14:28:48 +0100 | [diff] [blame] | 1198 | visuals[i].format); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | |
Chad Versace | ffbf50b | 2017-06-22 11:00:41 -0700 | [diff] [blame] | 1202 | return (config_count != 0); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1203 | } |
| 1204 | |
Mauro Rossi | 73b342c | 2018-08-14 15:10:54 +0200 | [diff] [blame] | 1205 | #ifdef HAVE_DRM_GRALLOC |
| 1206 | static int |
| 1207 | droid_open_device_drm_gralloc(struct dri2_egl_display *dri2_dpy) |
| 1208 | { |
| 1209 | int fd = -1, err = -EINVAL; |
| 1210 | |
| 1211 | if (dri2_dpy->gralloc->perform) |
| 1212 | err = dri2_dpy->gralloc->perform(dri2_dpy->gralloc, |
| 1213 | GRALLOC_MODULE_PERFORM_GET_DRM_FD, |
| 1214 | &fd); |
| 1215 | if (err || fd < 0) { |
| 1216 | _eglLog(_EGL_WARNING, "fail to get drm fd"); |
| 1217 | fd = -1; |
| 1218 | } |
| 1219 | |
| 1220 | return (fd >= 0) ? fcntl(fd, F_DUPFD_CLOEXEC, 3) : -1; |
| 1221 | } |
| 1222 | #endif /* HAVE_DRM_GRALLOC */ |
| 1223 | |
Emil Velikov | 79d1fb9 | 2017-05-15 16:14:17 +0100 | [diff] [blame] | 1224 | static const struct dri2_egl_display_vtbl droid_display_vtbl = { |
Chad Versace | 90502b1 | 2014-01-28 11:41:46 -0800 | [diff] [blame] | 1225 | .authenticate = NULL, |
Chad Versace | 0a0c881 | 2014-01-28 16:39:09 -0800 | [diff] [blame] | 1226 | .create_window_surface = droid_create_window_surface, |
Adrian Negreanu | 6980cae | 2014-06-06 12:16:10 +0300 | [diff] [blame] | 1227 | .create_pixmap_surface = dri2_fallback_create_pixmap_surface, |
Chad Versace | bf20076 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1228 | .create_pbuffer_surface = droid_create_pbuffer_surface, |
Chad Versace | 958dd80 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1229 | .destroy_surface = droid_destroy_surface, |
Chad Versace | eef68a9 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1230 | .create_image = droid_create_image_khr, |
Chad Versace | ad173bc | 2014-01-28 16:21:21 -0800 | [diff] [blame] | 1231 | .swap_buffers = droid_swap_buffers, |
Emil Velikov | 61e99ce | 2017-10-16 17:10:42 +0100 | [diff] [blame] | 1232 | .swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage, /* Android implements the function */ |
Chad Versace | 75d398e | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1233 | .swap_buffers_region = dri2_fallback_swap_buffers_region, |
Wu, Zhongmin | 5fc21c6 | 2018-01-18 15:39:22 +0800 | [diff] [blame] | 1234 | .swap_interval = droid_swap_interval, |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1235 | #if ANDROID_API_LEVEL >= 23 |
| 1236 | .set_damage_region = droid_set_damage_region, |
| 1237 | #else |
| 1238 | .set_damage_region = dri2_fallback_set_damage_region, |
| 1239 | #endif |
Chad Versace | 688a0e8 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1240 | .post_sub_buffer = dri2_fallback_post_sub_buffer, |
Chad Versace | bc2cbc0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1241 | .copy_buffers = dri2_fallback_copy_buffers, |
Xiaosong Wei | 2acc69d | 2017-02-08 10:46:02 +0800 | [diff] [blame] | 1242 | .query_buffer_age = droid_query_buffer_age, |
Haixia Shi | a7c6993 | 2016-07-28 10:51:12 -0700 | [diff] [blame] | 1243 | .query_surface = droid_query_surface, |
Chad Versace | eadd5e0 | 2014-01-28 17:03:03 -0800 | [diff] [blame] | 1244 | .create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image, |
Sarah Sharp | c524f3e | 2014-05-06 12:10:57 -0700 | [diff] [blame] | 1245 | .get_sync_values = dri2_fallback_get_sync_values, |
Boyan Ding | a25df54 | 2015-07-21 23:43:59 +0800 | [diff] [blame] | 1246 | .get_dri_drawable = dri2_surface_get_dri_drawable, |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame^] | 1247 | .set_shared_buffer_mode = droid_set_shared_buffer_mode, |
Chad Versace | 90502b1 | 2014-01-28 11:41:46 -0800 | [diff] [blame] | 1248 | }; |
| 1249 | |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 1250 | #ifdef HAVE_DRM_GRALLOC |
Emil Velikov | 6a8fe32 | 2016-08-16 17:23:23 +0100 | [diff] [blame] | 1251 | static const __DRIdri2LoaderExtension droid_dri2_loader_extension = { |
Marek Olšák | 1bf703e | 2017-07-28 17:30:34 +0200 | [diff] [blame] | 1252 | .base = { __DRI_DRI2_LOADER, 4 }, |
Emil Velikov | 6a8fe32 | 2016-08-16 17:23:23 +0100 | [diff] [blame] | 1253 | |
| 1254 | .getBuffers = NULL, |
| 1255 | .flushFrontBuffer = droid_flush_front_buffer, |
| 1256 | .getBuffersWithFormat = droid_get_buffers_with_format, |
Rob Herring | be5773f | 2017-07-31 09:32:10 -0500 | [diff] [blame] | 1257 | .getCapability = droid_get_capability, |
Emil Velikov | 6a8fe32 | 2016-08-16 17:23:23 +0100 | [diff] [blame] | 1258 | }; |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 1259 | #endif /* HAVE_DRM_GRALLOC */ |
Emil Velikov | 6a8fe32 | 2016-08-16 17:23:23 +0100 | [diff] [blame] | 1260 | |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 1261 | static const __DRIimageLoaderExtension droid_image_loader_extension = { |
Marek Olšák | 1bf703e | 2017-07-28 17:30:34 +0200 | [diff] [blame] | 1262 | .base = { __DRI_IMAGE_LOADER, 2 }, |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 1263 | |
| 1264 | .getBuffers = droid_image_get_buffers, |
| 1265 | .flushFrontBuffer = droid_flush_front_buffer, |
Marek Olšák | 1bf703e | 2017-07-28 17:30:34 +0200 | [diff] [blame] | 1266 | .getCapability = droid_get_capability, |
Rob Herring | 34ddef3 | 2016-05-01 09:35:28 +0100 | [diff] [blame] | 1267 | }; |
| 1268 | |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 1269 | #ifdef HAVE_DRM_GRALLOC |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 1270 | static const __DRIextension *droid_dri2_loader_extensions[] = { |
| 1271 | &droid_dri2_loader_extension.base, |
| 1272 | &image_lookup_extension.base, |
| 1273 | &use_invalidate.base, |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame^] | 1274 | /* No __DRI_MUTABLE_RENDER_BUFFER_LOADER because it requires |
| 1275 | * __DRI_IMAGE_LOADER. |
| 1276 | */ |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 1277 | NULL, |
| 1278 | }; |
Rob Herring | 3f7bca4 | 2018-04-26 16:02:01 +0200 | [diff] [blame] | 1279 | #endif /* HAVE_DRM_GRALLOC */ |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 1280 | |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame^] | 1281 | static void |
| 1282 | droid_display_shared_buffer(__DRIdrawable *driDrawable, int fence_fd, |
| 1283 | void *loaderPrivate) |
| 1284 | { |
| 1285 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
| 1286 | struct ANativeWindowBuffer *old_buffer UNUSED = dri2_surf->buffer; |
| 1287 | |
| 1288 | if (!_eglSurfaceInSharedBufferMode(&dri2_surf->base)) { |
| 1289 | _eglLog(_EGL_WARNING, "%s: internal error: buffer is not shared", |
| 1290 | __func__); |
| 1291 | return; |
| 1292 | } |
| 1293 | |
| 1294 | if (fence_fd >= 0) { |
| 1295 | /* The driver's fence is more recent than the surface's out fence, if it |
| 1296 | * exists at all. So use the driver's fence. |
| 1297 | */ |
| 1298 | if (dri2_surf->out_fence_fd >= 0) { |
| 1299 | close(dri2_surf->out_fence_fd); |
| 1300 | dri2_surf->out_fence_fd = -1; |
| 1301 | } |
| 1302 | } else if (dri2_surf->out_fence_fd >= 0) { |
| 1303 | fence_fd = dri2_surf->out_fence_fd; |
| 1304 | dri2_surf->out_fence_fd = -1; |
| 1305 | } |
| 1306 | |
| 1307 | if (dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer, |
| 1308 | fence_fd)) { |
| 1309 | _eglLog(_EGL_WARNING, "%s: ANativeWindow::queueBuffer failed", __func__); |
| 1310 | close(fence_fd); |
| 1311 | return; |
| 1312 | } |
| 1313 | |
| 1314 | fence_fd = -1; |
| 1315 | |
| 1316 | if (dri2_surf->window->dequeueBuffer(dri2_surf->window, &dri2_surf->buffer, |
| 1317 | &fence_fd)) { |
| 1318 | /* Tear down the surface because it no longer has a back buffer. */ |
| 1319 | struct dri2_egl_display *dri2_dpy = |
| 1320 | dri2_egl_display(dri2_surf->base.Resource.Display); |
| 1321 | |
| 1322 | _eglLog(_EGL_WARNING, "%s: ANativeWindow::dequeueBuffer failed", __func__); |
| 1323 | |
| 1324 | dri2_surf->base.Lost = true; |
| 1325 | dri2_surf->buffer = NULL; |
| 1326 | dri2_surf->back = NULL; |
| 1327 | |
| 1328 | if (dri2_surf->dri_image_back) { |
| 1329 | dri2_dpy->image->destroyImage(dri2_surf->dri_image_back); |
| 1330 | dri2_surf->dri_image_back = NULL; |
| 1331 | } |
| 1332 | |
| 1333 | dri2_dpy->flush->invalidate(dri2_surf->dri_drawable); |
| 1334 | return; |
| 1335 | } |
| 1336 | |
| 1337 | if (fence_fd < 0) |
| 1338 | return; |
| 1339 | |
| 1340 | /* Access to the buffer is controlled by a sync fence. Block on it. |
| 1341 | * |
| 1342 | * Ideally, we would submit the fence to the driver, and the driver would |
| 1343 | * postpone command execution until it signalled. But DRI lacks API for |
| 1344 | * that (as of 2018-04-11). |
| 1345 | * |
| 1346 | * SYNC_IOC_WAIT waits forever if timeout < 0 |
| 1347 | */ |
| 1348 | sync_wait(fence_fd, -1); |
| 1349 | close(fence_fd); |
| 1350 | } |
| 1351 | |
| 1352 | static const __DRImutableRenderBufferLoaderExtension droid_mutable_render_buffer_extension = { |
| 1353 | .base = { __DRI_MUTABLE_RENDER_BUFFER_LOADER, 1 }, |
| 1354 | .displaySharedBuffer = droid_display_shared_buffer, |
| 1355 | }; |
| 1356 | |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 1357 | static const __DRIextension *droid_image_loader_extensions[] = { |
| 1358 | &droid_image_loader_extension.base, |
| 1359 | &image_lookup_extension.base, |
| 1360 | &use_invalidate.base, |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame^] | 1361 | &droid_mutable_render_buffer_extension.base, |
Emil Velikov | f871946 | 2016-08-24 23:32:27 +0100 | [diff] [blame] | 1362 | NULL, |
| 1363 | }; |
| 1364 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1365 | EGLBoolean |
Robert Foss | c7bb821 | 2018-04-18 17:27:40 +0200 | [diff] [blame] | 1366 | droid_load_driver(_EGLDisplay *disp) |
| 1367 | { |
| 1368 | struct dri2_egl_display *dri2_dpy = disp->DriverData; |
| 1369 | const char *err; |
| 1370 | |
| 1371 | dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd); |
| 1372 | if (dri2_dpy->driver_name == NULL) |
| 1373 | return false; |
| 1374 | |
| 1375 | dri2_dpy->is_render_node = drmGetNodeTypeFromFd(dri2_dpy->fd) == DRM_NODE_RENDER; |
| 1376 | |
| 1377 | if (!dri2_dpy->is_render_node) { |
| 1378 | #ifdef HAVE_DRM_GRALLOC |
| 1379 | /* Handle control nodes using __DRI_DRI2_LOADER extension and GEM names |
| 1380 | * for backwards compatibility with drm_gralloc. (Do not use on new |
| 1381 | * systems.) */ |
| 1382 | dri2_dpy->loader_extensions = droid_dri2_loader_extensions; |
| 1383 | if (!dri2_load_driver(disp)) { |
| 1384 | err = "DRI2: failed to load driver"; |
| 1385 | goto error; |
| 1386 | } |
| 1387 | #else |
| 1388 | err = "DRI2: handle is not for a render node"; |
| 1389 | goto error; |
| 1390 | #endif |
| 1391 | } else { |
| 1392 | dri2_dpy->loader_extensions = droid_image_loader_extensions; |
| 1393 | if (!dri2_load_driver_dri3(disp)) { |
| 1394 | err = "DRI3: failed to load driver"; |
| 1395 | goto error; |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | return true; |
| 1400 | |
| 1401 | error: |
| 1402 | free(dri2_dpy->driver_name); |
| 1403 | dri2_dpy->driver_name = NULL; |
| 1404 | return false; |
| 1405 | } |
| 1406 | |
| 1407 | static bool |
| 1408 | droid_probe_driver(int fd) |
| 1409 | { |
| 1410 | char *driver_name; |
| 1411 | |
| 1412 | driver_name = loader_get_driver_for_fd(fd); |
| 1413 | if (driver_name == NULL) |
| 1414 | return false; |
| 1415 | |
| 1416 | free(driver_name); |
| 1417 | return true; |
| 1418 | } |
| 1419 | |
| 1420 | typedef enum { |
| 1421 | probe_fail = -1, |
| 1422 | probe_success = 0, |
| 1423 | probe_filtered_out = 1, |
| 1424 | } probe_ret_t; |
| 1425 | |
| 1426 | static probe_ret_t |
| 1427 | droid_probe_device(_EGLDisplay *disp, int fd, const char *vendor) |
| 1428 | { |
| 1429 | int ret; |
| 1430 | |
| 1431 | drmVersionPtr ver = drmGetVersion(fd); |
| 1432 | if (!ver) |
| 1433 | return probe_fail; |
| 1434 | |
| 1435 | if (!ver->name) { |
| 1436 | ret = probe_fail; |
| 1437 | goto cleanup; |
| 1438 | } |
| 1439 | |
| 1440 | if (vendor && strncmp(vendor, ver->name, PROPERTY_VALUE_MAX) != 0) { |
| 1441 | ret = probe_filtered_out; |
| 1442 | goto cleanup; |
| 1443 | } |
| 1444 | |
| 1445 | if (!droid_probe_driver(fd)) { |
| 1446 | ret = probe_fail; |
| 1447 | goto cleanup; |
| 1448 | } |
| 1449 | |
| 1450 | ret = probe_success; |
| 1451 | |
| 1452 | cleanup: |
| 1453 | drmFreeVersion(ver); |
| 1454 | return ret; |
| 1455 | } |
| 1456 | |
| 1457 | static int |
| 1458 | droid_open_device(_EGLDisplay *disp) |
| 1459 | { |
| 1460 | const int MAX_DRM_DEVICES = 32; |
| 1461 | int prop_set, num_devices; |
| 1462 | int fd = -1, fallback_fd = -1; |
| 1463 | |
| 1464 | char *vendor_name = NULL; |
| 1465 | char vendor_buf[PROPERTY_VALUE_MAX]; |
| 1466 | |
| 1467 | if (property_get("drm.gpu.vendor_name", vendor_buf, NULL) > 0) |
| 1468 | vendor_name = vendor_buf; |
| 1469 | |
| 1470 | const char *drm_dir_name = "/dev/dri"; |
| 1471 | DIR *sysdir = opendir(drm_dir_name); |
| 1472 | |
| 1473 | if (!sysdir) |
| 1474 | return -errno; |
| 1475 | |
| 1476 | struct dirent *dent; |
| 1477 | while ((dent = readdir(sysdir))) { |
| 1478 | char dev_path[128]; |
| 1479 | const char render_dev_prefix[] = "renderD"; |
| 1480 | size_t prefix_len = sizeof(render_dev_prefix) - 1; |
| 1481 | |
| 1482 | if (strncmp(render_dev_prefix, dent->d_name, prefix_len) != 0) |
| 1483 | continue; |
| 1484 | |
| 1485 | snprintf(dev_path, sizeof(dev_path), "%s/%s", drm_dir_name, dent->d_name); |
| 1486 | fd = loader_open_device(dev_path); |
| 1487 | if (fd < 0) { |
| 1488 | _eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s", |
| 1489 | __func__, dev_path); |
| 1490 | continue; |
| 1491 | } |
| 1492 | |
| 1493 | int ret = droid_probe_device(disp, fd, vendor_name); |
| 1494 | switch (ret) { |
| 1495 | case probe_success: |
| 1496 | goto success; |
| 1497 | case probe_filtered_out: |
| 1498 | /* Set as fallback */ |
| 1499 | if (fallback_fd == -1) |
| 1500 | fallback_fd = fd; |
| 1501 | break; |
| 1502 | case probe_fail: |
| 1503 | break; |
| 1504 | } |
| 1505 | |
| 1506 | if (fallback_fd != fd) |
| 1507 | close(fd); |
| 1508 | fd = -1; |
| 1509 | } |
| 1510 | |
| 1511 | success: |
| 1512 | closedir(sysdir); |
| 1513 | |
| 1514 | if (fallback_fd < 0 && fd < 0) { |
| 1515 | _eglLog(_EGL_WARNING, "Failed to open any DRM device"); |
| 1516 | return -1; |
| 1517 | } |
| 1518 | |
| 1519 | if (fd < 0) { |
| 1520 | _eglLog(_EGL_WARNING, "Failed to open desired DRM device, using fallback"); |
| 1521 | return fallback_fd; |
| 1522 | } |
| 1523 | |
| 1524 | close(fallback_fd); |
| 1525 | return fd; |
| 1526 | } |
| 1527 | |
| 1528 | EGLBoolean |
Rob Herring | aa187fe | 2018-01-03 10:16:23 -0600 | [diff] [blame] | 1529 | dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp) |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1530 | { |
| 1531 | struct dri2_egl_display *dri2_dpy; |
| 1532 | const char *err; |
Tomasz Figa | 859d0b0 | 2016-11-10 16:55:52 +0900 | [diff] [blame] | 1533 | int ret; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1534 | |
Eric Engestrom | 2f42165 | 2017-12-20 15:53:08 +0000 | [diff] [blame] | 1535 | /* Not supported yet */ |
Eric Engestrom | 81cea66 | 2017-12-20 15:53:09 +0000 | [diff] [blame] | 1536 | if (disp->Options.ForceSoftware) |
Eric Engestrom | 2f42165 | 2017-12-20 15:53:08 +0000 | [diff] [blame] | 1537 | return EGL_FALSE; |
| 1538 | |
Emil Velikov | 8d4357b | 2014-01-11 04:52:48 +0000 | [diff] [blame] | 1539 | loader_set_logger(_eglLog); |
| 1540 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1541 | dri2_dpy = calloc(1, sizeof(*dri2_dpy)); |
| 1542 | if (!dri2_dpy) |
| 1543 | return _eglError(EGL_BAD_ALLOC, "eglInitialize"); |
| 1544 | |
Emil Velikov | 898d785 | 2017-05-11 17:18:13 +0100 | [diff] [blame] | 1545 | dri2_dpy->fd = -1; |
Tomasz Figa | 859d0b0 | 2016-11-10 16:55:52 +0900 | [diff] [blame] | 1546 | ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, |
| 1547 | (const hw_module_t **)&dri2_dpy->gralloc); |
| 1548 | if (ret) { |
| 1549 | err = "DRI2: failed to get gralloc module"; |
Emil Velikov | 898d785 | 2017-05-11 17:18:13 +0100 | [diff] [blame] | 1550 | goto cleanup; |
Tomasz Figa | 859d0b0 | 2016-11-10 16:55:52 +0900 | [diff] [blame] | 1551 | } |
| 1552 | |
Rob Herring | aa187fe | 2018-01-03 10:16:23 -0600 | [diff] [blame] | 1553 | disp->DriverData = (void *) dri2_dpy; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1554 | |
Mauro Rossi | 73b342c | 2018-08-14 15:10:54 +0200 | [diff] [blame] | 1555 | #ifdef HAVE_DRM_GRALLOC |
| 1556 | dri2_dpy->fd = droid_open_device_drm_gralloc(dri2_dpy); |
| 1557 | #else |
Robert Foss | c7bb821 | 2018-04-18 17:27:40 +0200 | [diff] [blame] | 1558 | dri2_dpy->fd = droid_open_device(disp); |
Mauro Rossi | 73b342c | 2018-08-14 15:10:54 +0200 | [diff] [blame] | 1559 | #endif |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1560 | if (dri2_dpy->fd < 0) { |
| 1561 | err = "DRI2: failed to open device"; |
Emil Velikov | 898d785 | 2017-05-11 17:18:13 +0100 | [diff] [blame] | 1562 | goto cleanup; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1563 | } |
| 1564 | |
Robert Foss | c7bb821 | 2018-04-18 17:27:40 +0200 | [diff] [blame] | 1565 | if (!droid_load_driver(disp)) { |
| 1566 | err = "DRI2: failed to load driver"; |
Emil Velikov | 898d785 | 2017-05-11 17:18:13 +0100 | [diff] [blame] | 1567 | goto cleanup; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1568 | } |
| 1569 | |
Rob Herring | aa187fe | 2018-01-03 10:16:23 -0600 | [diff] [blame] | 1570 | if (!dri2_create_screen(disp)) { |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1571 | err = "DRI2: failed to create screen"; |
Emil Velikov | 898d785 | 2017-05-11 17:18:13 +0100 | [diff] [blame] | 1572 | goto cleanup; |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1573 | } |
| 1574 | |
Rob Herring | aa187fe | 2018-01-03 10:16:23 -0600 | [diff] [blame] | 1575 | if (!dri2_setup_extensions(disp)) { |
Tomasz Figa | 0ede0f9 | 2017-07-05 23:56:51 +0900 | [diff] [blame] | 1576 | err = "DRI2: failed to setup extensions"; |
Emil Velikov | 2c341f2 | 2017-05-11 16:20:04 +0100 | [diff] [blame] | 1577 | goto cleanup; |
Tomasz Figa | 0ede0f9 | 2017-07-05 23:56:51 +0900 | [diff] [blame] | 1578 | } |
Emil Velikov | 2c341f2 | 2017-05-11 16:20:04 +0100 | [diff] [blame] | 1579 | |
Rob Herring | aa187fe | 2018-01-03 10:16:23 -0600 | [diff] [blame] | 1580 | dri2_setup_screen(disp); |
Emil Velikov | 2c341f2 | 2017-05-11 16:20:04 +0100 | [diff] [blame] | 1581 | |
Wu, Zhongmin | 5fc21c6 | 2018-01-18 15:39:22 +0800 | [diff] [blame] | 1582 | /* We set the maximum swap interval as 1 for Android platform, since it is |
| 1583 | * the maximum value supported by Android according to the value of |
| 1584 | * ANativeWindow::maxSwapInterval. |
| 1585 | */ |
| 1586 | dri2_setup_swap_interval(disp, 1); |
| 1587 | |
Rob Herring | aa187fe | 2018-01-03 10:16:23 -0600 | [diff] [blame] | 1588 | disp->Extensions.ANDROID_framebuffer_target = EGL_TRUE; |
| 1589 | disp->Extensions.ANDROID_image_native_buffer = EGL_TRUE; |
| 1590 | disp->Extensions.ANDROID_recordable = EGL_TRUE; |
| 1591 | disp->Extensions.EXT_buffer_age = EGL_TRUE; |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1592 | #if ANDROID_API_LEVEL >= 23 |
Rob Herring | aa187fe | 2018-01-03 10:16:23 -0600 | [diff] [blame] | 1593 | disp->Extensions.KHR_partial_update = EGL_TRUE; |
Harish Krupo | 9827547 | 2017-06-09 20:13:34 +0530 | [diff] [blame] | 1594 | #endif |
Rob Herring | aa187fe | 2018-01-03 10:16:23 -0600 | [diff] [blame] | 1595 | disp->Extensions.KHR_image = EGL_TRUE; |
Chad Versace | ed7c694 | 2018-04-30 22:35:17 -0700 | [diff] [blame^] | 1596 | #if ANDROID_API_LEVEL >= 24 |
| 1597 | if (dri2_dpy->mutable_render_buffer && |
| 1598 | dri2_dpy->loader_extensions == droid_image_loader_extensions) { |
| 1599 | disp->Extensions.KHR_mutable_render_buffer = EGL_TRUE; |
| 1600 | } |
| 1601 | #endif |
| 1602 | |
| 1603 | /* Create configs *after* enabling extensions because presence of DRI |
| 1604 | * driver extensions can affect the capabilities of EGLConfigs. |
| 1605 | */ |
| 1606 | if (!droid_add_configs_for_visuals(drv, disp)) { |
| 1607 | err = "DRI2: failed to add configs"; |
| 1608 | goto cleanup; |
| 1609 | } |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1610 | |
Chad Versace | 90502b1 | 2014-01-28 11:41:46 -0800 | [diff] [blame] | 1611 | /* Fill vtbl last to prevent accidentally calling virtual function during |
| 1612 | * initialization. |
| 1613 | */ |
| 1614 | dri2_dpy->vtbl = &droid_display_vtbl; |
| 1615 | |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1616 | return EGL_TRUE; |
| 1617 | |
Emil Velikov | 898d785 | 2017-05-11 17:18:13 +0100 | [diff] [blame] | 1618 | cleanup: |
Rob Herring | aa187fe | 2018-01-03 10:16:23 -0600 | [diff] [blame] | 1619 | dri2_display_destroy(disp); |
Chia-I Wu | 9779f6f | 2011-08-05 14:39:18 +0900 | [diff] [blame] | 1620 | return _eglError(EGL_NOT_INITIALIZED, err); |
| 1621 | } |