qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] ui/egl: use stride and y0_top


From: Gerd Hoffmann
Subject: [Qemu-devel] [PATCH] ui/egl: use stride and y0_top
Date: Thu, 18 Jun 2015 11:37:52 +0200

Signed-off-by: Gerd Hoffmann <address@hidden>
---
 Makefile                         |  4 +++-
 include/ui/egl-proto.h           |  2 ++
 qemu-eglview.c                   | 14 ++++++++++++--
 ui/egl.c                         |  4 ++++
 ui/shader/texture-blit-flip.vert | 10 ++++++++++
 5 files changed, 31 insertions(+), 3 deletions(-)
 create mode 100644 ui/shader/texture-blit-flip.vert

diff --git a/Makefile b/Makefile
index 67eb59a..d10133a 100644
--- a/Makefile
+++ b/Makefile
@@ -458,7 +458,9 @@ ui/console-gl.o: $(SRC_PATH)/ui/console-gl.c \
        ui/shader/texture-blit-vert.h ui/shader/texture-blit-frag.h
 
 qemu-eglview.o: $(SRC_PATH) qemu-eglview.c \
-       ui/shader/texture-blit-vert.h ui/shader/texture-blit-oes-frag.h
+       ui/shader/texture-blit-vert.h \
+       ui/shader/texture-blit-flip-vert.h \
+       ui/shader/texture-blit-oes-frag.h
 
 # documentation
 MAKEINFO=makeinfo
diff --git a/include/ui/egl-proto.h b/include/ui/egl-proto.h
index 1878224..3e149ed 100644
--- a/include/ui/egl-proto.h
+++ b/include/ui/egl-proto.h
@@ -24,7 +24,9 @@ typedef struct egl_msg {
         struct egl_newbuf {
             uint32_t width;
             uint32_t height;
+            uint32_t stride;
             uint32_t fourcc;
+            bool     y0_top;
         } newbuf;
         struct egl_ptr_set {
             uint32_t x;
diff --git a/qemu-eglview.c b/qemu-eglview.c
index efe992b..ed7bee0 100644
--- a/qemu-eglview.c
+++ b/qemu-eglview.c
@@ -42,10 +42,12 @@ static GIOChannel *ioc;
 
 static uint32_t buf_width;
 static uint32_t buf_height;
+static bool buf_y0_top;
 static EGLImageKHR buf_image = EGL_NO_IMAGE_KHR;
 static GLuint buf_tex_id;
 
 static GLint texture_blit_prog;
+static GLint texture_blit_flip_prog;
 
 #define GL_CHECK_ERROR() do {                                   \
         GLint err = glGetError();                               \
@@ -56,6 +58,7 @@ static GLint texture_blit_prog;
     } while (0)
 
 #include "ui/shader/texture-blit-vert.h"
+#include "ui/shader/texture-blit-flip-vert.h"
 #include "ui/shader/texture-blit-oes-frag.h"
 
 /* ---------------------------------------------------------------------- */
@@ -106,7 +109,11 @@ static gboolean egl_draw(GtkWidget *widget, cairo_t *cr, 
void *opaque)
     glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
     glClear(GL_COLOR_BUFFER_BIT);
 
-    qemu_gl_run_texture_blit(texture_blit_prog);
+    if (buf_y0_top) {
+        qemu_gl_run_texture_blit(texture_blit_flip_prog);
+    } else {
+        qemu_gl_run_texture_blit(texture_blit_prog);
+    }
     eglSwapBuffers(qemu_egl_display, egl_surface);
 
     return TRUE;
@@ -131,13 +138,14 @@ static void egl_newbuf(egl_msg *msg, int msgfd)
             msgfd, msg->u.newbuf.width, msg->u.newbuf.height);
     buf_width = msg->u.newbuf.width;
     buf_height = msg->u.newbuf.height;
+    buf_y0_top = msg->u.newbuf.y0_top;
 
     gtk_widget_set_size_request(draw, buf_width, buf_height);
 
     attrs[0] = EGL_DMA_BUF_PLANE0_FD_EXT;
     attrs[1] = msgfd;
     attrs[2] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
-    attrs[3] = buf_width * 4;
+    attrs[3] = msg->u.newbuf.stride;
     attrs[4] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
     attrs[5] = 0;
     attrs[6] = EGL_WIDTH;
@@ -420,6 +428,8 @@ int main(int argc, char *argv[])
     gtk_widget_set_double_buffered(draw, FALSE);
     texture_blit_prog = qemu_gl_create_compile_link_program
         (texture_blit_vert_src, texture_blit_oes_frag_src);
+    texture_blit_flip_prog = qemu_gl_create_compile_link_program
+        (texture_blit_flip_vert_src, texture_blit_oes_frag_src);
     if (!texture_blit_prog) {
         fprintf(stderr, "shader compile/link failure\n");
         exit(1);
diff --git a/ui/egl.c b/ui/egl.c
index e420beb..c63b453 100644
--- a/ui/egl.c
+++ b/ui/egl.c
@@ -293,7 +293,9 @@ static void egl_gfx_switch(DisplayChangeListener *dcl,
         edpy->newbuf.display = edpy->idx;
         edpy->newbuf.u.newbuf.width = surface_width(edpy->ds);
         edpy->newbuf.u.newbuf.height = surface_height(edpy->ds);
+        edpy->newbuf.u.newbuf.stride = stride;
         edpy->newbuf.u.newbuf.fourcc = fourcc;
+        edpy->newbuf.u.newbuf.y0_top = false;
 
         egl_send_all(edpy->egl, &edpy->newbuf, edpy->dmabuf_fd);
     }
@@ -344,7 +346,9 @@ static void egl_scanout(DisplayChangeListener *dcl,
     edpy->newbuf.display = edpy->idx;
     edpy->newbuf.u.newbuf.width = surface_width(edpy->ds);
     edpy->newbuf.u.newbuf.height = surface_height(edpy->ds);
+    edpy->newbuf.u.newbuf.stride = stride;
     edpy->newbuf.u.newbuf.fourcc = fourcc;
+    edpy->newbuf.u.newbuf.y0_top = backing_y_0_top;
 
     egl_send_all(edpy->egl, &edpy->newbuf, edpy->dmabuf_fd);
 }
diff --git a/ui/shader/texture-blit-flip.vert b/ui/shader/texture-blit-flip.vert
new file mode 100644
index 0000000..ba081fa
--- /dev/null
+++ b/ui/shader/texture-blit-flip.vert
@@ -0,0 +1,10 @@
+
+#version 300 es
+
+in vec2  in_position;
+out vec2 ex_tex_coord;
+
+void main(void) {
+    gl_Position = vec4(in_position, 0.0, 1.0);
+    ex_tex_coord = vec2(1.0 + in_position.x, 1.0 + in_position.y) * 0.5;
+}
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]