The patch pasted in previous mail lost some indentations and spaces.
Sorry.

From 7921a69f106233ebc0ff9bdc29d7c6182160fc6f Mon Sep 17 00:00:00 2001
From: Chen Zhang <tgfb...@me.com>
Date: Thu, 24 Jan 2019 09:16:23 +0800
Subject: [PATCH] DMABuf: Blend cursor buf within a scaled viewport

Signed-off-by: Chen Zhang <tgfb...@me.com>
---
 include/ui/egl-helpers.h |  2 ++
 ui/egl-helpers.c         | 18 ++++++++++++++++++
 ui/gtk-egl.c             |  8 +++++---
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h
index 3fc656a..63ffc2d 100644
--- a/include/ui/egl-helpers.h
+++ b/include/ui/egl-helpers.h
@@ -28,6 +28,8 @@ void egl_fb_read(void *dst, egl_fb *src);
 void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip);
 void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
                        int x, int y);
+void egl_texture_blend2(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
+                        int x, int y, int w, int h);
 
 #ifdef CONFIG_OPENGL_DMABUF
 
diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
index 5e115b3..9dddee9 100644
--- a/ui/egl-helpers.c
+++ b/ui/egl-helpers.c
@@ -137,6 +137,24 @@ void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, 
egl_fb *src, bool flip,
     glDisable(GL_BLEND);
 }
 
+void egl_texture_blend2(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
+                        int x, int y, int w, int h)
+{
+    glBindFramebuffer(GL_FRAMEBUFFER_EXT, dst->framebuffer);
+    if (flip) {
+        glViewport(x, y, w, h);
+    } else {
+        glViewport(x, dst->height - h - y,
+                   w, h);
+    }
+    glEnable(GL_TEXTURE_2D);
+    glBindTexture(GL_TEXTURE_2D, src->texture);
+    glEnable(GL_BLEND);
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    qemu_gl_run_texture_blit(gls, flip);
+    glDisable(GL_BLEND);
+}
+
 /* ---------------------------------------------------------------------- */
 
 #ifdef CONFIG_OPENGL_DMABUF
diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index afd1714..afff0e1 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -276,9 +276,11 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl,
     if (vc->gfx.cursor_fb.texture) {
         egl_texture_blit(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.guest_fb,
                          vc->gfx.y0_top);
-        egl_texture_blend(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.cursor_fb,
-                          vc->gfx.y0_top,
-                          vc->gfx.cursor_x, vc->gfx.cursor_y);
+        egl_texture_blend2(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.cursor_fb,
+                           vc->gfx.y0_top,
+                           vc->gfx.cursor_x, vc->gfx.cursor_y,
+                           vc->gfx.scale_x * vc->gfx.cursor_fb.width,
+                           vc->gfx.scale_x * vc->gfx.cursor_fb.height);
     } else {
         egl_fb_blit(&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top);
     }
-- 
2.7.4


> On Jan 24, 2019, at 9:31 AM, Chen Zhang <tgfb...@me.com> wrote:
> 
> When a gtk-egl window (for gvt-g DMABuf) was zoomed, the cursor plane buffer 
> did not zoom covariantly, resulting in a mismatched cursor size. In this 
> patch, `egl_texture_blend()` is augmented with two extra parameters to convey 
> the size for a scaled viewport, as in `egl_texture_blend2()`. 
> 
> Signed-off-by: Chen Zhang <tgfb...@me.com>
> ---
> include/ui/egl-helpers.h | 2 ++
> ui/egl-helpers.c | 18 ++++++++++++++++++
> ui/gtk-egl.c | 8 +++++---
> 3 files changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h
> index 3fc656a..63ffc2d 100644
> --- a/include/ui/egl-helpers.h
> +++ b/include/ui/egl-helpers.h
> @@ -28,6 +28,8 @@ void egl_fb_read(void *dst, egl_fb *src);
> void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip);
> void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
> int x, int y);
> +void egl_texture_blend2(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool 
> flip,
> + int x, int y, int w, int h);
> 
> #ifdef CONFIG_OPENGL_DMABUF
> 
> diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
> index 5e115b3..9dddee9 100644
> --- a/ui/egl-helpers.c
> +++ b/ui/egl-helpers.c
> @@ -137,6 +137,24 @@ void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, 
> egl_fb *src, bool flip,
> glDisable(GL_BLEND);
> }
> 
> +void egl_texture_blend2(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool 
> flip,
> + int x, int y, int w, int h)
> +{
> + glBindFramebuffer(GL_FRAMEBUFFER_EXT, dst->framebuffer);
> + if (flip) {
> + glViewport(x, y, w, h);
> + } else {
> + glViewport(x, dst->height - h - y,
> + w, h);
> + }
> + glEnable(GL_TEXTURE_2D);
> + glBindTexture(GL_TEXTURE_2D, src->texture);
> + glEnable(GL_BLEND);
> + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
> + qemu_gl_run_texture_blit(gls, flip);
> + glDisable(GL_BLEND);
> +}
> +
> /* ---------------------------------------------------------------------- */
> 
> #ifdef CONFIG_OPENGL_DMABUF
> diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
> index afd1714..afff0e1 100644
> --- a/ui/gtk-egl.c
> +++ b/ui/gtk-egl.c
> @@ -276,9 +276,11 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl,
> if (vc->gfx.cursor_fb.texture) {
> egl_texture_blit(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.guest_fb,
> vc->gfx.y0_top);
> - egl_texture_blend(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.cursor_fb,
> - vc->gfx.y0_top,
> - vc->gfx.cursor_x, vc->gfx.cursor_y);
> + egl_texture_blend2(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.cursor_fb,
> + vc->gfx.y0_top,
> + vc->gfx.cursor_x, vc->gfx.cursor_y,
> + vc->gfx.scale_x * vc->gfx.cursor_fb.width,
> + vc->gfx.scale_x * vc->gfx.cursor_fb.height);
> } else {
> egl_fb_blit(&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top);
> }
> -- 
> 2.7.4

Reply via email to