Re: [systemd-devel] [RFC 11/12] gfx: add unbuilt GL test

2013-12-01 Thread David Herrmann
Hi

On Sun, Dec 1, 2013 at 6:21 AM, Zbigniew Jędrzejewski-Szmek
zbys...@in.waw.pl wrote:
 On Wed, Nov 27, 2013 at 07:48:46PM +0100, David Herrmann wrote:
 The test-gl helper shows how sd_gfx_card can be used to get a full OpenGL
 context on the device. It is not added to the build-tools as it requires
 mesa and might break on Khronos header-updates (yes, they break API *and*
 ABI compatibility often!).
 ---
  .gitignore   |   1 +
  Makefile.am  |  18 +++
  configure.ac |   3 +
  src/libsystemd-gfx/test-gl.c | 342 
 +++
  4 files changed, 364 insertions(+)
  create mode 100644 src/libsystemd-gfx/test-gl.c

 diff --git a/.gitignore b/.gitignore
 index a61f68d..c856412 100644
 --- a/.gitignore
 +++ b/.gitignore
 @@ -116,6 +116,7 @@
  /test-event
  /test-fileio
  /test-gfx
 +/test-gl
  /test-hashmap
  /test-hostname
  /test-id128
 diff --git a/Makefile.am b/Makefile.am
 index aa17876..1e8aeed 100644
 --- a/Makefile.am
 +++ b/Makefile.am
 @@ -3886,6 +3886,19 @@ test_gfx_LDADD = \
   libsystemd-shared.la \
   libsystemd-gfx.la

 +test_gl_SOURCES = \
 + src/libsystemd-gfx/test-gl.c
 +
 +test_gl_CFLAGS = \
 + $(AM_CFLAGS) \
 + $(GFX_GL_CFLAGS)
 +
 +test_gl_LDADD = \
 + $(GFX_GL_LIBS) \
 + libsystemd-bus-internal.la \
 + libsystemd-shared.la \
 + libsystemd-gfx.la
 +
  test_kbd_SOURCES = \
   src/libsystemd-gfx/test-kbd.c

 @@ -3903,6 +3916,11 @@ tests += \
   test-gfx \
   test-kbd

 +if HAVE_GFX_GL
 +# Uncomment this to enable test-gl builds
 +#tests += test-gl
 +endif
 Telling people to edit the makefile doesn't seem right. Maybe add a configure
 swith a la bd441fa27a? Then the GFX_GL switch below could be changed to 
 actually
 error out if any of those modules are not found.

Yeah, I think I will remove it entirely instead. It was just a
proof-of-concept that you can use sd_gfx_card with OpenGL. Doesn't
make much sense to keep it.

  src/libsystemd-gfx/unifont.bin: make-unifont.py 
 src/libsystemd-gfx/unifont.hex
   $(AM_V_GEN)cat $(top_srcdir)/src/libsystemd-gfx/unifont.hex | 
 $(PYTHON) $ $@
 src/libsystemd-gfx/unifont.bin: src/libsystemd-gfx/unifont.hex make-unifont.py
 $(AM_V_at)$(MKDIR_P) $(dir $@)
 $(AM_V_GEN)$(PYTHON) $+ $@

 ... and make make-unitfont.py accept an arg.
 mkdir -p is needed for out of tree builds.

Hm, make update-unifont should only be used by maintainers to update
the hex-file. You actually need to download the file and rename it to
src/libsystemd-gfx/unifont.hex for this to make sense. So is there any
reason to support out-of-tree builds for that? Doesn't make sense to
me, as you only want to call it if you check the result into git.

Argument seems fine, I will try to fix it up (if I only knew python better..).

 +r = sd_gfx_card_new(card, /dev/dri/card0, gl_fd, event);
 Maybe 'argv[1] ?: /dev/dri/card0' for manual testing?

The other tests already use udev, I should fix this either up or
remove it, yepp.

Thanks for reviewing!
David
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [RFC 11/12] gfx: add unbuilt GL test

2013-11-30 Thread Zbigniew Jędrzejewski-Szmek
On Wed, Nov 27, 2013 at 07:48:46PM +0100, David Herrmann wrote:
 The test-gl helper shows how sd_gfx_card can be used to get a full OpenGL
 context on the device. It is not added to the build-tools as it requires
 mesa and might break on Khronos header-updates (yes, they break API *and*
 ABI compatibility often!).
 ---
  .gitignore   |   1 +
  Makefile.am  |  18 +++
  configure.ac |   3 +
  src/libsystemd-gfx/test-gl.c | 342 
 +++
  4 files changed, 364 insertions(+)
  create mode 100644 src/libsystemd-gfx/test-gl.c
 
 diff --git a/.gitignore b/.gitignore
 index a61f68d..c856412 100644
 --- a/.gitignore
 +++ b/.gitignore
 @@ -116,6 +116,7 @@
  /test-event
  /test-fileio
  /test-gfx
 +/test-gl
  /test-hashmap
  /test-hostname
  /test-id128
 diff --git a/Makefile.am b/Makefile.am
 index aa17876..1e8aeed 100644
 --- a/Makefile.am
 +++ b/Makefile.am
 @@ -3886,6 +3886,19 @@ test_gfx_LDADD = \
   libsystemd-shared.la \
   libsystemd-gfx.la
  
 +test_gl_SOURCES = \
 + src/libsystemd-gfx/test-gl.c
 +
 +test_gl_CFLAGS = \
 + $(AM_CFLAGS) \
 + $(GFX_GL_CFLAGS)
 +
 +test_gl_LDADD = \
 + $(GFX_GL_LIBS) \
 + libsystemd-bus-internal.la \
 + libsystemd-shared.la \
 + libsystemd-gfx.la
 +
  test_kbd_SOURCES = \
   src/libsystemd-gfx/test-kbd.c
  
 @@ -3903,6 +3916,11 @@ tests += \
   test-gfx \
   test-kbd
  
 +if HAVE_GFX_GL
 +# Uncomment this to enable test-gl builds
 +#tests += test-gl
 +endif
Telling people to edit the makefile doesn't seem right. Maybe add a configure
swith a la bd441fa27a? Then the GFX_GL switch below could be changed to actually
error out if any of those modules are not found.

  src/libsystemd-gfx/unifont.bin: make-unifont.py 
 src/libsystemd-gfx/unifont.hex
   $(AM_V_GEN)cat $(top_srcdir)/src/libsystemd-gfx/unifont.hex | $(PYTHON) 
 $ $@
src/libsystemd-gfx/unifont.bin: src/libsystemd-gfx/unifont.hex make-unifont.py
$(AM_V_at)$(MKDIR_P) $(dir $@)
$(AM_V_GEN)$(PYTHON) $+ $@

... and make make-unitfont.py accept an arg.
mkdir -p is needed for out of tree builds.
  
 +r = sd_gfx_card_new(card, /dev/dri/card0, gl_fd, event);
Maybe 'argv[1] ?: /dev/dri/card0' for manual testing?

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [RFC 11/12] gfx: add unbuilt GL test

2013-11-27 Thread David Herrmann
The test-gl helper shows how sd_gfx_card can be used to get a full OpenGL
context on the device. It is not added to the build-tools as it requires
mesa and might break on Khronos header-updates (yes, they break API *and*
ABI compatibility often!).
---
 .gitignore   |   1 +
 Makefile.am  |  18 +++
 configure.ac |   3 +
 src/libsystemd-gfx/test-gl.c | 342 +++
 4 files changed, 364 insertions(+)
 create mode 100644 src/libsystemd-gfx/test-gl.c

diff --git a/.gitignore b/.gitignore
index a61f68d..c856412 100644
--- a/.gitignore
+++ b/.gitignore
@@ -116,6 +116,7 @@
 /test-event
 /test-fileio
 /test-gfx
+/test-gl
 /test-hashmap
 /test-hostname
 /test-id128
diff --git a/Makefile.am b/Makefile.am
index aa17876..1e8aeed 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3886,6 +3886,19 @@ test_gfx_LDADD = \
libsystemd-shared.la \
libsystemd-gfx.la
 
+test_gl_SOURCES = \
+   src/libsystemd-gfx/test-gl.c
+
+test_gl_CFLAGS = \
+   $(AM_CFLAGS) \
+   $(GFX_GL_CFLAGS)
+
+test_gl_LDADD = \
+   $(GFX_GL_LIBS) \
+   libsystemd-bus-internal.la \
+   libsystemd-shared.la \
+   libsystemd-gfx.la
+
 test_kbd_SOURCES = \
src/libsystemd-gfx/test-kbd.c
 
@@ -3903,6 +3916,11 @@ tests += \
test-gfx \
test-kbd
 
+if HAVE_GFX_GL
+# Uncomment this to enable test-gl builds
+#tests += test-gl
+endif
+
 src/libsystemd-gfx/unifont.bin: make-unifont.py src/libsystemd-gfx/unifont.hex
$(AM_V_GEN)cat $(top_srcdir)/src/libsystemd-gfx/unifont.hex | $(PYTHON) 
$ $@
 
diff --git a/configure.ac b/configure.ac
index b76a86d..bf3fce3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -299,8 +299,11 @@ if test x$enable_gfx != xno; then
 if test x$have_gfx = xno -a x$enable_gfx = xyes; then
 AC_MSG_ERROR([*** sd-gfx support requested, but libraries not 
found])
 fi
+PKG_CHECK_MODULES(GFX_GL, [ libdrm = 2.4.47 gbm = 9.2.3 egl glesv2 ],
+[AC_DEFINE(HAVE_GFX_GL, 1, [Define if sd-gfx GL examples are 
built]) have_gfx_gl=yes], have_gfx_gl=no)
 fi
 AM_CONDITIONAL(HAVE_GFX, [test $have_gfx = yes])
+AM_CONDITIONAL(HAVE_GFX_GL, [test $have_gfx_gl = yes])
 
 # 
--
 have_blkid=no
diff --git a/src/libsystemd-gfx/test-gl.c b/src/libsystemd-gfx/test-gl.c
new file mode 100644
index 000..733b451
--- /dev/null
+++ b/src/libsystemd-gfx/test-gl.c
@@ -0,0 +1,342 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2013 David Herrmann dh.herrm...@gmail.com
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see http://www.gnu.org/licenses/.
+***/
+
+#define EGL_EGLEXT_PROTOTYPES
+#define GL_GLEXT_PROTOTYPES
+
+#include errno.h
+#include fcntl.h
+#include inttypes.h
+#include stdlib.h
+#include string.h
+#include unistd.h
+
+#include drm.h
+#include drm_fourcc.h
+#include EGL/egl.h
+#include EGL/eglext.h
+#include gbm.h
+#include GLES2/gl2.h
+#include GLES2/gl2ext.h
+
+#include def.h
+#include log.h
+#include macro.h
+#include missing.h
+#include sd-event.h
+#include sd-gfx.h
+#include util.h
+
+struct plane {
+struct gbm_surface *gbm;
+EGLSurface egl;
+
+struct gbm_surface *t_gbm;
+EGLSurface t_egl;
+};
+
+static int gl_fd;
+static struct gbm_device *gl_device;
+static EGLDisplay gl_display;
+static EGLConfig gl_config;
+static EGLContext gl_context;
+
+static void err(const char *format, ...) {
+va_list args;
+
+fprintf(stderr, ERROR: );
+va_start(args, format);
+vfprintf(stderr, format, args);
+va_end(args);
+fprintf(stderr, \n);
+
+_exit(1);
+}
+
+static void fb_unlink(sd_gfx_fb *fb, void *fn_data) {
+struct gbm_bo *bo = fn_data;
+
+gbm_bo_set_user_data(bo, NULL, NULL);
+}
+
+static void fb_unpin(sd_gfx_fb *fb, void *fn_data) {
+struct gbm_bo *bo = fn_data;
+sd_gfx_plane *plane = sd_gfx_fb_get_plane(fb);
+struct plane *p = sd_gfx_plane_get_fn_data(plane);
+
+gbm_surface_release_buffer(p-gbm, bo);
+}
+
+static void fb_destroy(struct gbm_bo *bo, void *data) {
+sd_gfx_fb *fb = data;
+
+if (!fb)
+return;
+
+err(fb_destroy());
+}
+
+static sd_gfx_fb *bo_to_fb(sd_gfx_plane *plane, struct