Merge branch 'wip/chergert/gdk-remove-texture_from_surface' into 'master'

gl: remove unused texture_from_surface API

See merge request GNOME/gtk!2756
This commit is contained in:
Matthias Clasen 2020-10-29 15:50:01 +00:00
commit 931f130377
2 changed files with 0 additions and 258 deletions

View File

@ -49,10 +49,6 @@ struct _GdkGLContextClass
GError **error);
cairo_region_t * (* get_damage) (GdkGLContext *context);
gboolean (* texture_from_surface) (GdkGLContext *context,
cairo_surface_t *surface,
cairo_region_t *region);
};
typedef struct {

View File

@ -257,259 +257,6 @@ gdk_x11_gl_context_get_damage (GdkGLContext *context)
return GDK_GL_CONTEXT_CLASS (gdk_x11_gl_context_parent_class)->get_damage (context);
}
typedef struct {
Display *display;
GLXDrawable drawable;
gboolean y_inverted;
} GdkGLXPixmap;
static void
glx_pixmap_destroy (void *data)
{
GdkGLXPixmap *glx_pixmap = data;
glXDestroyPixmap (glx_pixmap->display, glx_pixmap->drawable);
g_slice_free (GdkGLXPixmap, glx_pixmap);
}
static GdkGLXPixmap *
glx_pixmap_get (cairo_surface_t *surface, guint texture_target)
{
Display *display = cairo_xlib_surface_get_display (surface);
Screen *screen = cairo_xlib_surface_get_screen (surface);
Visual *visual = cairo_xlib_surface_get_visual (surface);
GdkGLXPixmap *glx_pixmap;
GLXFBConfig *fbconfigs, config;
int nfbconfigs;
XVisualInfo *visinfo;
VisualID visualid;
int i, value;
gboolean y_inverted;
gboolean with_alpha;
guint target = 0;
guint format = 0;
int pixmap_attributes[] = {
GLX_TEXTURE_TARGET_EXT, 0,
GLX_TEXTURE_FORMAT_EXT, 0,
None
};
if (visual == NULL)
return NULL;
with_alpha = cairo_surface_get_content (surface) == CAIRO_CONTENT_COLOR_ALPHA;
y_inverted = FALSE;
fbconfigs = glXGetFBConfigs (display, XScreenNumberOfScreen (screen), &nfbconfigs);
for (i = 0; i < nfbconfigs; i++)
{
visinfo = glXGetVisualFromFBConfig (display, fbconfigs[i]);
if (!visinfo)
continue;
visualid = visinfo->visualid;
XFree (visinfo);
if (visualid != XVisualIDFromVisual (visual))
continue;
glXGetFBConfigAttrib (display, fbconfigs[i], GLX_DRAWABLE_TYPE, &value);
if (!(value & GLX_PIXMAP_BIT))
continue;
glXGetFBConfigAttrib (display, fbconfigs[i],
GLX_BIND_TO_TEXTURE_TARGETS_EXT,
&value);
if (texture_target == GL_TEXTURE_2D)
{
if (value & GLX_TEXTURE_2D_BIT_EXT)
target = GLX_TEXTURE_2D_EXT;
else
continue;
}
else if (texture_target == GL_TEXTURE_RECTANGLE_ARB)
{
if (value & GLX_TEXTURE_RECTANGLE_BIT_EXT)
target = GLX_TEXTURE_RECTANGLE_EXT;
else
continue;
}
else
continue;
if (!with_alpha)
{
glXGetFBConfigAttrib (display, fbconfigs[i],
GLX_BIND_TO_TEXTURE_RGB_EXT,
&value);
if (!value)
continue;
format = GLX_TEXTURE_FORMAT_RGB_EXT;
}
else
{
glXGetFBConfigAttrib (display, fbconfigs[i],
GLX_BIND_TO_TEXTURE_RGBA_EXT,
&value);
if (!value)
continue;
format = GLX_TEXTURE_FORMAT_RGBA_EXT;
}
glXGetFBConfigAttrib (display, fbconfigs[i],
GLX_Y_INVERTED_EXT,
&value);
if (value == TRUE)
y_inverted = TRUE;
config = fbconfigs[i];
break;
}
XFree (fbconfigs);
if (i == nfbconfigs)
return NULL;
pixmap_attributes[1] = target;
pixmap_attributes[3] = format;
glx_pixmap = g_slice_new0 (GdkGLXPixmap);
glx_pixmap->y_inverted = y_inverted;
glx_pixmap->display = display;
glx_pixmap->drawable = glXCreatePixmap (display, config,
cairo_xlib_surface_get_drawable (surface),
pixmap_attributes);
return glx_pixmap;
}
static gboolean
gdk_x11_gl_context_texture_from_surface (GdkGLContext *paint_context,
cairo_surface_t *cairo_surface,
cairo_region_t *region)
{
GdkGLXPixmap *glx_pixmap;
double device_x_offset, device_y_offset;
cairo_rectangle_int_t rect;
int n_rects, i;
GdkSurface *surface;
int unscaled_surface_height;
int surface_scale;
unsigned int texture_id;
gboolean use_texture_rectangle;
guint target;
double sx, sy;
float uscale, vscale;
GdkTexturedQuad *quads;
GdkX11Display *display_x11;
display_x11 = GDK_X11_DISPLAY (gdk_gl_context_get_display (paint_context));
if (!display_x11->has_glx_texture_from_pixmap)
return FALSE;
if (cairo_surface_get_type (cairo_surface) != CAIRO_SURFACE_TYPE_XLIB)
return FALSE;
use_texture_rectangle = gdk_gl_context_use_texture_rectangle (paint_context);
if (use_texture_rectangle)
target = GL_TEXTURE_RECTANGLE_ARB;
else
target = GL_TEXTURE_2D;
glx_pixmap = glx_pixmap_get (cairo_surface, target);
if (glx_pixmap == NULL)
return FALSE;
GDK_DISPLAY_NOTE (GDK_DISPLAY (display_x11), OPENGL, g_message ("Using GLX_EXT_texture_from_pixmap to draw surface"));
surface = gdk_gl_context_get_surface (paint_context);
surface_scale = gdk_surface_get_scale_factor (surface);
gdk_surface_get_unscaled_size (surface, NULL, &unscaled_surface_height);
sx = sy = 1;
cairo_surface_get_device_scale (cairo_surface, &sx, &sy);
cairo_surface_get_device_offset (cairo_surface, &device_x_offset, &device_y_offset);
/* Ensure all the X stuff are synced before we read it back via texture-from-pixmap */
glXWaitX();
glGenTextures (1, &texture_id);
glBindTexture (target, texture_id);
glTexParameteri (target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glXBindTexImageEXT (glx_pixmap->display, glx_pixmap->drawable,
GLX_FRONT_LEFT_EXT, NULL);
glEnable (GL_SCISSOR_TEST);
n_rects = cairo_region_num_rectangles (region);
quads = g_new (GdkTexturedQuad, n_rects);
#define FLIP_Y(_y) (unscaled_surface_height - (_y))
cairo_region_get_extents (region, &rect);
glScissor (rect.x * surface_scale, FLIP_Y((rect.y + rect.height) * surface_scale),
rect.width * surface_scale, rect.height * surface_scale);
for (i = 0; i < n_rects; i++)
{
int src_x, src_y, src_height, src_width;
cairo_region_get_rectangle (region, i, &rect);
src_x = rect.x * sx + device_x_offset;
src_y = rect.y * sy + device_y_offset;
src_width = rect.width * sx;
src_height = rect.height * sy;
if (use_texture_rectangle)
{
uscale = 1.0;
vscale = 1.0;
}
else
{
uscale = 1.0 / cairo_xlib_surface_get_width (cairo_surface);
vscale = 1.0 / cairo_xlib_surface_get_height (cairo_surface);
}
{
GdkTexturedQuad quad = {
rect.x * surface_scale, FLIP_Y(rect.y * surface_scale),
(rect.x + rect.width) * surface_scale, FLIP_Y((rect.y + rect.height) * surface_scale),
uscale * src_x, vscale * src_y,
uscale * (src_x + src_width), vscale * (src_y + src_height),
};
quads[i] = quad;
}
}
#undef FLIP_Y
gdk_gl_texture_quads (paint_context, target, n_rects, quads, FALSE);
g_free (quads);
glDisable (GL_SCISSOR_TEST);
glXReleaseTexImageEXT (glx_pixmap->display, glx_pixmap->drawable,
GLX_FRONT_LEFT_EXT);
glDeleteTextures (1, &texture_id);
glx_pixmap_destroy(glx_pixmap);
return TRUE;
}
static XVisualInfo *
find_xvisinfo_for_fbconfig (GdkDisplay *display,
GLXFBConfig config)
@ -972,7 +719,6 @@ gdk_x11_gl_context_class_init (GdkX11GLContextClass *klass)
context_class->realize = gdk_x11_gl_context_realize;
context_class->get_damage = gdk_x11_gl_context_get_damage;
context_class->texture_from_surface = gdk_x11_gl_context_texture_from_surface;
draw_context_class->end_frame = gdk_x11_gl_context_end_frame;