Skip to content

Commit 753fffe

Browse files
committed
spice-display: support GL_TEXTURE_RECTANGLE_ANGLE
On macOS with CGL rendering backend, IOSurface only supports rectangle texture targets. On iOS, EAGL, and Metal rendering backends IOSurface only supports 2D texture targets.
1 parent e19e3cb commit 753fffe

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

include/ui/egl-helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ typedef struct egl_fb {
2020
int width;
2121
int height;
2222
GLuint texture;
23+
GLenum texture_target;
2324
GLuint framebuffer;
2425
bool delete_texture;
2526
} egl_fb;
2627

2728
void egl_fb_destroy(egl_fb *fb);
2829
void egl_fb_setup_default(egl_fb *fb, int width, int height);
30+
void egl_fb_setup_for_tex_target(egl_fb *fb, int width, int height,
31+
GLuint texture, GLenum target, bool delete);
2932
void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
3033
GLuint texture, bool delete);
34+
void egl_fb_setup_new_tex_target(egl_fb *fb, int width, int height, GLenum target);
3135
void egl_fb_setup_new_tex(egl_fb *fb, int width, int height);
3236
void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip);
3337
void egl_fb_read(DisplaySurface *dst, egl_fb *src);

ui/egl-helpers.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,46 @@ void egl_fb_setup_default(egl_fb *fb, int width, int height)
5858
fb->framebuffer = 0; /* default framebuffer */
5959
}
6060

61-
void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
62-
GLuint texture, bool delete)
61+
void egl_fb_setup_for_tex_target(egl_fb *fb, int width, int height,
62+
GLuint texture, GLenum target, bool delete)
6363
{
6464
egl_fb_delete_texture(fb);
6565

6666
fb->width = width;
6767
fb->height = height;
6868
fb->texture = texture;
69+
fb->texture_target = target;
6970
fb->delete_texture = delete;
7071
if (!fb->framebuffer) {
7172
glGenFramebuffers(1, &fb->framebuffer);
7273
}
7374

7475
glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb->framebuffer);
7576
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
76-
GL_TEXTURE_2D, fb->texture, 0);
77+
fb->texture_target, fb->texture, 0);
7778
}
7879

79-
void egl_fb_setup_new_tex(egl_fb *fb, int width, int height)
80+
void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
81+
GLuint texture, bool delete)
82+
{
83+
egl_fb_setup_for_tex_target(fb, width, height, texture, GL_TEXTURE_2D, delete);
84+
}
85+
86+
void egl_fb_setup_new_tex_target(egl_fb *fb, int width, int height, GLenum target)
8087
{
8188
GLuint texture;
8289

8390
glGenTextures(1, &texture);
84-
glBindTexture(GL_TEXTURE_2D, texture);
85-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,
91+
glBindTexture(target, texture);
92+
glTexImage2D(target, 0, GL_RGBA, width, height,
8693
0, GL_BGRA, GL_UNSIGNED_BYTE, 0);
8794

88-
egl_fb_setup_for_tex(fb, width, height, texture, true);
95+
egl_fb_setup_for_tex_target(fb, width, height, texture, target, true);
96+
}
97+
98+
void egl_fb_setup_new_tex(egl_fb *fb, int width, int height)
99+
{
100+
egl_fb_setup_new_tex_target(fb, width, height, GL_TEXTURE_2D);
89101
}
90102

91103
void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip)
@@ -115,7 +127,7 @@ void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip)
115127
glBindFramebuffer(GL_FRAMEBUFFER_EXT, dst->framebuffer);
116128
glViewport(0, 0, dst->width, dst->height);
117129
glEnable(GL_TEXTURE_2D);
118-
glBindTexture(GL_TEXTURE_2D, src->texture);
130+
glBindTexture(src->texture_target, src->texture);
119131
qemu_gl_run_texture_blit(gls, flip);
120132
}
121133

@@ -131,7 +143,7 @@ void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
131143
glViewport(x, dst->height - h - y, w, h);
132144
}
133145
glEnable(GL_TEXTURE_2D);
134-
glBindTexture(GL_TEXTURE_2D, src->texture);
146+
glBindTexture(src->texture_target, src->texture);
135147
glEnable(GL_BLEND);
136148
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
137149
qemu_gl_run_texture_blit(gls, flip);

ui/spice-display.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#ifdef CONFIG_IOSURFACE
2828
#include <TargetConditionals.h>
2929
#endif
30+
#ifdef CONFIG_ANGLE
31+
#include <GLES2/gl2.h>
32+
#include <GLES2/gl2ext.h>
33+
#endif
3034

3135
#include "ui/spice-display.h"
3236

@@ -825,11 +829,29 @@ static int spice_iosurface_create(SimpleSpiceDisplay *ssd, int width, int height
825829
}
826830

827831
#if defined(CONFIG_ANGLE)
832+
EGLint target = 0;
833+
GLenum tex_target = 0;
834+
if (eglGetConfigAttrib(qemu_egl_display,
835+
qemu_egl_config,
836+
EGL_BIND_TO_TEXTURE_TARGET_ANGLE,
837+
&target) != EGL_TRUE) {
838+
error_report("spice_iosurface_create: eglGetConfigAttrib failed");
839+
return 0;
840+
}
841+
if (target == EGL_TEXTURE_2D) {
842+
tex_target = GL_TEXTURE_2D;
843+
} else if (target == EGL_TEXTURE_RECTANGLE_ANGLE) {
844+
tex_target = GL_TEXTURE_RECTANGLE_ANGLE;
845+
} else {
846+
error_report("spice_iosurface_create: unsupported texture target");
847+
return 0;
848+
}
849+
828850
const EGLint attribs[] = {
829851
EGL_WIDTH, width,
830852
EGL_HEIGHT, height,
831853
EGL_IOSURFACE_PLANE_ANGLE, 0,
832-
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
854+
EGL_TEXTURE_TARGET, target,
833855
EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, GL_BGRA_EXT,
834856
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
835857
EGL_TEXTURE_TYPE_ANGLE, GL_UNSIGNED_BYTE,
@@ -845,7 +867,7 @@ static int spice_iosurface_create(SimpleSpiceDisplay *ssd, int width, int height
845867
goto gl_error;
846868
}
847869

848-
egl_fb_setup_new_tex(&ssd->iosurface_fb, width, height);
870+
egl_fb_setup_new_tex_target(&ssd->iosurface_fb, width, height, tex_target);
849871

850872
return 1;
851873
gl_error:
@@ -909,14 +931,14 @@ static int spice_iosurface_create_fd(SimpleSpiceDisplay *ssd, int *fourcc)
909931

910932
static void spice_iosurface_blit(SimpleSpiceDisplay *ssd, GLuint src_texture, bool flip)
911933
{
912-
egl_fb tmp_fb = { .texture = src_texture };
934+
egl_fb tmp_fb = { .texture = src_texture, .texture_target = GL_TEXTURE_2D };
913935
if (!ssd->iosurface) {
914936
return;
915937
}
916938

917939
#if defined(CONFIG_ANGLE)
918940
eglMakeCurrent(qemu_egl_display, ssd->esurface, ssd->esurface, spice_gl_ctx);
919-
glBindTexture(GL_TEXTURE_2D, ssd->iosurface_fb.texture);
941+
glBindTexture(ssd->iosurface_fb.texture_target, ssd->iosurface_fb.texture);
920942
eglBindTexImage(qemu_egl_display, ssd->esurface, EGL_BACK_BUFFER);
921943
egl_texture_blit(ssd->gls, &ssd->iosurface_fb, &tmp_fb, flip);
922944
#endif

0 commit comments

Comments
 (0)