<div dir="ltr">Sorry, only remembered to change that to [PATCH v4] two seconds after pressing send. The commit message mentions v4.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 10, 2015 at 7:25 PM, Zach Reizner <span dir="ltr"><<a href="mailto:zachr@google.com" target="_blank">zachr@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Haixia Shi <<a href="mailto:hshi@chromium.org">hshi@chromium.org</a>><br>
<br>
The surfaceless platform is for off-screen rendering only. Render node support<br>
is required.<br>
<br>
Only consider the render nodes. Do not use normal nodes as they require<br>
auth hooks.<br>
<br>
v3: change platform_null to platform_surfaceless<br>
v4: make libdrm required for surfaceless<br>
<br>
Signed-off-by: Haixia Shi <<a href="mailto:hshi@chromium.org">hshi@chromium.org</a>><br>
Signed-off-by: Zach Reizner <<a href="mailto:zachr@google.com">zachr@google.com</a>><br>
---<br>
<a href="http://configure.ac" target="_blank">configure.ac</a> | 6 ++<br>
src/egl/drivers/dri2/Makefile.am | 5 +<br>
src/egl/drivers/dri2/egl_dri2.c | 11 +-<br>
src/egl/drivers/dri2/egl_dri2.h | 3 +<br>
src/egl/drivers/dri2/platform_surfaceless.c | 161 ++++++++++++++++++++++++++++<br>
src/egl/main/Makefile.am | 4 +<br>
src/egl/main/egldisplay.c | 3 +-<br>
src/egl/main/egldisplay.h | 1 +<br>
8 files changed, 191 insertions(+), 3 deletions(-)<br>
create mode 100644 src/egl/drivers/dri2/platform_surfaceless.c<br>
<br>
diff --git a/<a href="http://configure.ac" target="_blank">configure.ac</a> b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
index d32aa24..e7c7f87 100644<br>
--- a/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
@@ -1777,6 +1777,11 @@ for plat in $egl_platforms; do<br>
AC_MSG_ERROR([EGL platform drm requires libdrm >= $LIBDRM_REQUIRED])<br>
;;<br>
<br>
+ surfaceless)<br>
+ test "x$have_libdrm" != xyes &&<br>
+ AC_MSG_ERROR([EGL platform surfaceless requires libdrm >= $LIBDRM_REQUIRED])<br>
+ ;;<br>
+<br>
android|gdi|null)<br>
;;<br>
<br>
@@ -1806,6 +1811,7 @@ fi<br>
AM_CONDITIONAL(HAVE_EGL_PLATFORM_X11, echo "$egl_platforms" | grep -q 'x11')<br>
AM_CONDITIONAL(HAVE_EGL_PLATFORM_WAYLAND, echo "$egl_platforms" | grep -q 'wayland')<br>
AM_CONDITIONAL(HAVE_EGL_PLATFORM_DRM, echo "$egl_platforms" | grep -q 'drm')<br>
+AM_CONDITIONAL(HAVE_EGL_PLATFORM_SURFACELESS, echo "$egl_platforms" | grep -q 'surfaceless')<br>
AM_CONDITIONAL(HAVE_EGL_PLATFORM_NULL, echo "$egl_platforms" | grep -q 'null')<br>
<br>
AM_CONDITIONAL(HAVE_EGL_DRIVER_DRI2, test "x$HAVE_EGL_DRIVER_DRI2" != "x")<br>
diff --git a/src/egl/drivers/dri2/Makefile.am b/src/egl/drivers/dri2/Makefile.am<br>
index f589600..55be4a7 100644<br>
--- a/src/egl/drivers/dri2/Makefile.am<br>
+++ b/src/egl/drivers/dri2/Makefile.am<br>
@@ -65,4 +65,9 @@ libegl_dri2_la_SOURCES += platform_drm.c<br>
AM_CFLAGS += -DHAVE_DRM_PLATFORM<br>
endif<br>
<br>
+if HAVE_EGL_PLATFORM_SURFACELESS<br>
+libegl_dri2_la_SOURCES += platform_surfaceless.c<br>
+AM_CFLAGS += -DHAVE_SURFACELESS_PLATFORM<br>
+endif<br>
+<br>
EXTRA_DIST = SConscript<br>
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c<br>
index 82f8843..877cf70 100644<br>
--- a/src/egl/drivers/dri2/egl_dri2.c<br>
+++ b/src/egl/drivers/dri2/egl_dri2.c<br>
@@ -658,6 +658,13 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp)<br>
return EGL_FALSE;<br>
<br>
switch (disp->Platform) {<br>
+#ifdef HAVE_SURFACELESS_PLATFORM<br>
+ case _EGL_PLATFORM_SURFACELESS:<br>
+ if (disp->Options.TestOnly)<br>
+ return EGL_TRUE;<br>
+ return dri2_initialize_surfaceless(drv, disp);<br>
+#endif<br>
+<br>
#ifdef HAVE_X11_PLATFORM<br>
case _EGL_PLATFORM_X11:<br>
if (disp->Options.TestOnly)<br>
@@ -1604,7 +1611,7 @@ dri2_create_wayland_buffer_from_image(_EGLDriver *drv, _EGLDisplay *dpy,<br>
return dri2_dpy->vtbl->create_wayland_buffer_from_image(drv, dpy, img);<br>
}<br>
<br>
-#ifdef HAVE_LIBDRM<br>
+#if defined(HAVE_DRM_PLATFORM) || defined(HAVE_SURFACELESS_PLATFORM)<br>
static EGLBoolean<br>
dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs)<br>
{<br>
@@ -1862,7 +1869,7 @@ dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,<br>
case EGL_WAYLAND_BUFFER_WL:<br>
return dri2_create_image_wayland_wl_buffer(disp, ctx, buffer, attr_list);<br>
#endif<br>
-#ifdef HAVE_LIBDRM<br>
+#if defined(HAVE_DRM_PLATFORM) || defined(HAVE_SURFACELESS_PLATFORM)<br>
case EGL_LINUX_DMA_BUF_EXT:<br>
return dri2_create_image_dma_buf(disp, ctx, buffer, attr_list);<br>
#endif<br>
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h<br>
index adade3d..9985c49 100644<br>
--- a/src/egl/drivers/dri2/egl_dri2.h<br>
+++ b/src/egl/drivers/dri2/egl_dri2.h<br>
@@ -351,6 +351,9 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);<br>
EGLBoolean<br>
dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);<br>
<br>
+EGLBoolean<br>
+dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);<br>
+<br>
void<br>
dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw);<br>
<br>
diff --git a/src/egl/drivers/dri2/platform_surfaceless.c b/src/egl/drivers/dri2/platform_surfaceless.c<br>
new file mode 100644<br>
index 0000000..f8426bb<br>
--- /dev/null<br>
+++ b/src/egl/drivers/dri2/platform_surfaceless.c<br>
@@ -0,0 +1,161 @@<br>
+/*<br>
+ * Mesa 3-D graphics library<br>
+ *<br>
+ * Copyright (c) 2014 The Chromium OS Authors.<br>
+ * Copyright © 2011 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice shall be included<br>
+ * in all copies or substantial portions of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include <stdlib.h><br>
+#include <stdio.h><br>
+#include <string.h><br>
+#include <xf86drm.h><br>
+#include <dlfcn.h><br>
+#include <sys/types.h><br>
+#include <sys/stat.h><br>
+#include <fcntl.h><br>
+#include <unistd.h><br>
+<br>
+#include "egl_dri2.h"<br>
+#include "egl_dri2_fallbacks.h"<br>
+#include "loader.h"<br>
+<br>
+static struct dri2_egl_display_vtbl dri2_surfaceless_display_vtbl = {<br>
+ .create_pixmap_surface = dri2_fallback_create_pixmap_surface,<br>
+ .create_image = dri2_create_image_khr,<br>
+ .swap_interval = dri2_fallback_swap_interval,<br>
+ .swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage,<br>
+ .swap_buffers_region = dri2_fallback_swap_buffers_region,<br>
+ .post_sub_buffer = dri2_fallback_post_sub_buffer,<br>
+ .copy_buffers = dri2_fallback_copy_buffers,<br>
+ .query_buffer_age = dri2_fallback_query_buffer_age,<br>
+ .create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image,<br>
+ .get_sync_values = dri2_fallback_get_sync_values,<br>
+};<br>
+<br>
+static void<br>
+surfaceless_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate)<br>
+{<br>
+}<br>
+<br>
+static __DRIbuffer *<br>
+surfaceless_get_buffers_with_format(__DRIdrawable * driDrawable,<br>
+ int *width, int *height,<br>
+ unsigned int *attachments, int count,<br>
+ int *out_count, void *loaderPrivate)<br>
+{<br>
+ struct dri2_egl_surface *dri2_surf = loaderPrivate;<br>
+<br>
+ dri2_surf->buffer_count = 1;<br>
+ if (width)<br>
+ *width = dri2_surf->base.Width;<br>
+ if (height)<br>
+ *height = dri2_surf->base.Height;<br>
+ *out_count = dri2_surf->buffer_count;;<br>
+ return dri2_surf->buffers;<br>
+}<br>
+<br>
+#define DRM_RENDER_DEV_NAME "%s/renderD%d"<br>
+<br>
+EGLBoolean<br>
+dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp)<br>
+{<br>
+ struct dri2_egl_display *dri2_dpy;<br>
+ const char* err;<br>
+ int i;<br>
+ int driver_loaded = 0;<br>
+<br>
+ loader_set_logger(_eglLog);<br>
+<br>
+ dri2_dpy = calloc(1, sizeof *dri2_dpy);<br>
+ if (!dri2_dpy)<br>
+ return _eglError(EGL_BAD_ALLOC, "eglInitialize");<br>
+<br>
+ disp->DriverData = (void *) dri2_dpy;<br>
+<br>
+ const int limit = 64;<br>
+ const int base = 128;<br>
+ for (i = 0; i < limit; ++i) {<br>
+ char *card_path;<br>
+ if (asprintf(&card_path, DRM_RENDER_DEV_NAME, DRM_DIR_NAME, base + i) < 0)<br>
+ continue;<br>
+<br>
+ dri2_dpy->fd = open(card_path, O_RDWR);<br>
+ free(card_path);<br>
+ if (dri2_dpy->fd < 0)<br>
+ continue;<br>
+<br>
+ dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd, 0);<br>
+ if (dri2_dpy->driver_name) {<br>
+ if (dri2_load_driver(disp)) {<br>
+ driver_loaded = 1;<br>
+ break;<br>
+ }<br>
+ free(dri2_dpy->driver_name);<br>
+ }<br>
+ close(dri2_dpy->fd);<br>
+ }<br>
+<br>
+ if (!driver_loaded) {<br>
+ err = "DRI2: failed to load driver";<br>
+ goto cleanup_display;<br>
+ }<br>
+<br>
+ dri2_dpy-><a href="http://dri2_loader_extension.base.name" target="_blank">dri2_loader_extension.base.name</a> = __DRI_DRI2_LOADER;<br>
+ dri2_dpy->dri2_loader_extension.base.version = 3;<br>
+ dri2_dpy->dri2_loader_extension.getBuffers = NULL;<br>
+ dri2_dpy->dri2_loader_extension.flushFrontBuffer =<br>
+ surfaceless_flush_front_buffer;<br>
+ dri2_dpy->dri2_loader_extension.getBuffersWithFormat =<br>
+ surfaceless_get_buffers_with_format;<br>
+<br>
+ dri2_dpy->extensions[0] = &dri2_dpy->dri2_loader_extension.base;<br>
+ dri2_dpy->extensions[1] = &image_lookup_extension.base;<br>
+ dri2_dpy->extensions[2] = &use_invalidate.base;<br>
+ dri2_dpy->extensions[3] = NULL;<br>
+<br>
+ if (!dri2_create_screen(disp)) {<br>
+ err = "DRI2: failed to create screen";<br>
+ goto cleanup_driver;<br>
+ }<br>
+<br>
+ for (i = 0; dri2_dpy->driver_configs[i]; i++) {<br>
+ dri2_add_config(disp, dri2_dpy->driver_configs[i],<br>
+ i + 1, EGL_WINDOW_BIT, NULL, NULL);<br>
+ }<br>
+<br>
+ disp->Extensions.KHR_image_base = EGL_TRUE;<br>
+<br>
+ /* Fill vtbl last to prevent accidentally calling virtual function during<br>
+ * initialization.<br>
+ */<br>
+ dri2_dpy->vtbl = &dri2_surfaceless_display_vtbl;<br>
+<br>
+ return EGL_TRUE;<br>
+<br>
+cleanup_driver:<br>
+ dlclose(dri2_dpy->driver);<br>
+ free(dri2_dpy->driver_name);<br>
+ close(dri2_dpy->fd);<br>
+cleanup_display:<br>
+ free(dri2_dpy);<br>
+<br>
+ return _eglError(EGL_NOT_INITIALIZED, err);<br>
+}<br>
diff --git a/src/egl/main/Makefile.am b/src/egl/main/Makefile.am<br>
index b661736..9030d27 100644<br>
--- a/src/egl/main/Makefile.am<br>
+++ b/src/egl/main/Makefile.am<br>
@@ -68,6 +68,10 @@ if HAVE_EGL_PLATFORM_NULL<br>
AM_CFLAGS += -DHAVE_NULL_PLATFORM<br>
endif<br>
<br>
+if HAVE_EGL_PLATFORM_SURFACELESS<br>
+AM_CFLAGS += -DHAVE_SURFACELESS_PLATFORM<br>
+endif<br>
+<br>
if HAVE_EGL_DRIVER_DRI2<br>
AM_CFLAGS += -D_EGL_BUILT_IN_DRIVER_DRI2<br>
AM_CFLAGS += -DHAVE_XCB_DRI2<br>
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c<br>
index a3ecba8..24a0c7e 100644<br>
--- a/src/egl/main/egldisplay.c<br>
+++ b/src/egl/main/egldisplay.c<br>
@@ -71,7 +71,8 @@ static const struct {<br>
{ _EGL_PLATFORM_DRM, "drm" },<br>
{ _EGL_PLATFORM_NULL, "null" },<br>
{ _EGL_PLATFORM_ANDROID, "android" },<br>
- { _EGL_PLATFORM_HAIKU, "haiku" }<br>
+ { _EGL_PLATFORM_HAIKU, "haiku" },<br>
+ { _EGL_PLATFORM_SURFACELESS, "surfaceless" },<br>
};<br>
<br>
<br>
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h<br>
index 84cfbe1..0b50a36 100644<br>
--- a/src/egl/main/egldisplay.h<br>
+++ b/src/egl/main/egldisplay.h<br>
@@ -51,6 +51,7 @@ enum _egl_platform_type {<br>
_EGL_PLATFORM_NULL,<br>
_EGL_PLATFORM_ANDROID,<br>
_EGL_PLATFORM_HAIKU,<br>
+ _EGL_PLATFORM_SURFACELESS,<br>
<br>
_EGL_NUM_PLATFORMS,<br>
_EGL_INVALID_PLATFORM = -1<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.2.0.rc0.207.ga3a616c<br>
<br>
</font></span></blockquote></div><br></div>