[gtk/import-dmabuf] wip: test client for dmabuf sharing
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/import-dmabuf] wip: test client for dmabuf sharing
- Date: Sat, 8 May 2021 17:13:15 +0000 (UTC)
commit b8c31511a02359d403511cfa5aa60d7549fd3009
Author: Matthias Clasen <mclasen redhat com>
Date: Sat May 8 09:52:21 2021 -0400
wip: test client for dmabuf sharing
tests/simple.c | 92 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 49 insertions(+), 43 deletions(-)
---
diff --git a/tests/simple.c b/tests/simple.c
index 062afdc9fa..3625240a7b 100644
--- a/tests/simple.c
+++ b/tests/simple.c
@@ -1,63 +1,69 @@
-/* simple.c
- * Copyright (C) 2017 Red Hat, Inc
- * Author: Benjamin Otte
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-#include "config.h"
#include <gtk/gtk.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <time.h>
-static void
-hello (void)
-{
- g_print ("hello world\n");
-}
+#include <X11/Xlib.h>
+#define GL_GLEXT_PROTOTYPES
+#include <GL/gl.h>
+#define EGL_EGLEXT_PROTOTYPES
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
-static void
-quit_cb (GtkWidget *widget,
- gpointer data)
+#include "socket.h"
+
+static GdkTexture *
+get_texture (GdkGLContext *context)
{
- gboolean *done = data;
+ const char *CLIENT_FILE = "/tmp/test_client";
+ struct texture_storage_metadata_t
+ {
+ int fourcc;
+ int offset;
+ int stride;
+ };
+
+ int texture_dmabuf_fd;
+ struct texture_storage_metadata_t texture_storage_metadata;
- *done = TRUE;
+ int sock = create_socket(CLIENT_FILE);
+ read_fd(sock, &texture_dmabuf_fd, &texture_storage_metadata, sizeof(texture_storage_metadata));
+ close(sock);
- g_main_context_wakeup (NULL);
+ return gdk_gl_context_import_dmabuf (context,
+ texture_dmabuf_fd,
+ texture_storage_metadata.fourcc,
+ 2,
+ 2,
+ texture_storage_metadata.offset,
+ texture_storage_metadata.stride);
+ close (texture_dmabuf_fd);
}
int
main (int argc, char *argv[])
{
- GtkWidget *window, *button;
+ GtkWidget *window, *image;
gboolean done = FALSE;
+ GdkGLContext *context;
+ GdkTexture *texture;
gtk_init ();
window = gtk_window_new ();
- gtk_window_set_title (GTK_WINDOW (window), "hello world");
- gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
- g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
-
- button = gtk_button_new ();
- gtk_button_set_label (GTK_BUTTON (button), "hello world");
- gtk_widget_set_margin_top (button, 10);
- gtk_widget_set_margin_bottom (button, 10);
- gtk_widget_set_margin_start (button, 10);
- gtk_widget_set_margin_end (button, 10);
- g_signal_connect (button, "clicked", G_CALLBACK (hello), NULL);
-
- gtk_window_set_child (GTK_WINDOW (window), button);
+
+ gtk_widget_realize (GTK_WIDGET (window));
+ context = gdk_surface_create_gl_context (gtk_native_get_surface (GTK_NATIVE (window)), NULL);
+ gdk_gl_context_set_use_es (context, TRUE);
+ gdk_gl_context_realize (context, NULL);
+
+ texture = get_texture (context);
+
+ image = gtk_image_new_from_paintable (GDK_PAINTABLE (texture));
+ gtk_window_set_child (GTK_WINDOW (window), image);
gtk_widget_show (window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]