Skip to contentSkip to conversation

gtk-egl: Blend cursor buffer within a scaled viewport

PATCH In review Chen Zhang 2 participants 5 messages Jan 24, 2019

lore
Share & tools
lore

Chen Zhang

author
#0 lore raw

PATCH 1/1 gtk-egl: Blend cursor buffer within a scaled viewport

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().

---
include/ui/egl-helpers.h | 2 ++
ui/egl-helpers.c | 18 ++++++++++++++++++
ui/gtk-egl.c | 8 +++++---

3 files changed, 25 insertions(+), 3 deletions(-)
include/ui/egl-helpers.h +0 -0
index 3fc656a..63ffc2d 100644
@@ -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

ui/egl-helpers.c +0 -0
index 5e115b3..9dddee9 100644
@@ -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

ui/gtk-egl.c +0 -0
index afd1714..afff0e1 100644
@@ -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); }

Signature · 1 line
2.7.4
author
#1 lore raw

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

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

---
 include/ui/egl-helpers.h |  2 ++
 ui/egl-helpers.c         | 18 ++++++++++++++++++
 ui/gtk-egl.c             |  8 +++++---
 3 files changed, 25 insertions(+), 3 deletions(-)
include/ui/egl-helpers.h +2 -0
index 3fc656a..63ffc2d 100644
@@ -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
 
ui/egl-helpers.c +18 -0
index 5e115b3..9dddee9 100644
@@ -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
ui/gtk-egl.c +5 -3
index afd1714..afff0e1 100644
@@ -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);
     }
Signature · 1 line
2.7.4
Quoted 74 lines · Chen Zhang

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().

---
include/ui/egl-helpers.h | 2 ++
ui/egl-helpers.c | 18 ++++++++++++++++++
ui/gtk-egl.c | 8 +++++---

3 files changed, 25 insertions(+), 3 deletions(-)
include/ui/egl-helpers.h +2 -0
index 3fc656a..63ffc2d 100644
@@ -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
 
ui/egl-helpers.c +18 -0
index 5e115b3..9dddee9 100644
@@ -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
ui/gtk-egl.c +5 -3
index afd1714..afff0e1 100644
@@ -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);
 }
Signature · 1 line
2.7.4
#2 lore raw

include/ui/egl-helpers.h void egl_fb_read(void *dst, egl_fb *src); · line 32

Quoted 10 lines
include/ui/egl-helpers.h +2 -0
index 3fc656a..63ffc2d 100644
@@ -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);

Why do you add egl_texture_blend2()?
How about adding scale_{x,y} parameters to egl_texture_blend() instead?

include/ui/egl-helpers.h void egl_fb_read(void *dst, egl_fb *src); · line 34

Quoted 2 lines
include/ui/egl-helpers.h +2 -0
+                           vc->gfx.scale_x * vc->gfx.cursor_fb.width,
+                           vc->gfx.scale_x * vc->gfx.cursor_fb.height);

^ this should be y I guess ?

cheers,
Gerd

author
#3 lore raw

Hi,

Quoted 15 lines · Gerd Hoffmann

include/ui/egl-helpers.h void egl_fb_read(void *dst, egl_fb *src); · line 32

Quoted 11 lines
include/ui/egl-helpers.h +2 -0
index 3fc656a..63ffc2d 100644
@@ -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);

Why do you add egl_texture_blend2()?
How about adding scale_{x,y} parameters to egl_texture_blend() instead?

It is valid to augment parameter list of egl_texture_blend(), however, there are two other callers: namely, spicy-display and egl-headless, neither of which seems to scale any underlying viewports. In that case, default scales (1.0, 1.0) shall be provided.

Quoted 4 lines

include/ui/egl-helpers.h void egl_fb_read(void *dst, egl_fb *src); · line 34

Quoted 3 lines
include/ui/egl-helpers.h +2 -0
+                           vc->gfx.scale_x * vc->gfx.cursor_fb.width,
+                           vc->gfx.scale_x * vc->gfx.cursor_fb.height);

^ this should be y I guess ?

Sorry for this typo.

Quoted 4 lines

cheers,
Gerd

Best regards,

#4 lore raw
Quoted 17 lines · Chen Zhang

Hi,

Quoted 15 lines · Gerd Hoffmann

include/ui/egl-helpers.h void egl_fb_read(void *dst, egl_fb *src); · line 32

Quoted 11 lines
include/ui/egl-helpers.h +2 -0
index 3fc656a..63ffc2d 100644
@@ -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);

Why do you add egl_texture_blend2()?
How about adding scale_{x,y} parameters to egl_texture_blend() instead?

Quoted 4 lines

It is valid to augment parameter list of egl_texture_blend(), however, there are two other callers: namely, spicy-display and egl-headless, neither of which seems to scale any underlying viewports. In that case, default scales (1.0, 1.0) shall be provided.

Yes, these callers can simply set scale_x and scale_y to 1.

cheers,
Gerd