/** * gdk_gl_drawable_get_current: * * Returns the current #GdkGLDrawable. * * Return value: (transfer none): the current #GdkGLDrawable or NULL if there is no current drawable. **/ GdkGLDrawable* gdk_gl_drawable_get_current (void) { GDK_GL_NOTE_FUNC (); GdkGLContext* glcontext = gdk_gl_context_get_current (); if (!glcontext) return NULL; return gdk_gl_context_get_gl_drawable (glcontext); }
QEMUGLContext gd_gl_area_get_current_context(DisplayChangeListener *dcl) { return gdk_gl_context_get_current(); }
/* This is always called with the paint context current */ void gdk_gl_texture_from_surface (cairo_surface_t *surface, cairo_region_t *region) { GdkGLContext *paint_context; cairo_surface_t *image; double device_x_offset, device_y_offset; cairo_rectangle_int_t rect, e; int n_rects, i; GdkWindow *window; int unscaled_window_height; unsigned int texture_id; int window_scale; double sx, sy; float umax, vmax; gboolean use_texture_rectangle; guint target; paint_context = gdk_gl_context_get_current (); if ((_gdk_gl_flags & GDK_GL_SOFTWARE_DRAW_SURFACE) == 0 && paint_context && GDK_GL_CONTEXT_GET_CLASS (paint_context)->texture_from_surface && GDK_GL_CONTEXT_GET_CLASS (paint_context)->texture_from_surface (paint_context, surface, region)) return; /* Software fallback */ use_texture_rectangle = gdk_gl_context_use_texture_rectangle (paint_context); window = gdk_gl_context_get_window (paint_context); window_scale = gdk_window_get_scale_factor (window); gdk_window_get_unscaled_size (window, NULL, &unscaled_window_height); sx = sy = 1; cairo_surface_get_device_scale (window->current_paint.surface, &sx, &sy); cairo_surface_get_device_offset (surface, &device_x_offset, &device_y_offset); glGenTextures (1, &texture_id); if (use_texture_rectangle) target = GL_TEXTURE_RECTANGLE_ARB; else target = GL_TEXTURE_2D; glBindTexture (target, texture_id); glEnable (GL_SCISSOR_TEST); 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); n_rects = cairo_region_num_rectangles (region); #define FLIP_Y(_y) (unscaled_window_height - (_y)) for (i = 0; i < n_rects; i++) { cairo_region_get_rectangle (region, i, &rect); glScissor (rect.x * window_scale, FLIP_Y ((rect.y + rect.height) * window_scale), rect.width * window_scale, rect.height * window_scale); e = rect; e.x *= sx; e.y *= sy; e.x += (int)device_x_offset; e.y += (int)device_y_offset; e.width *= sx; e.height *= sy; image = cairo_surface_map_to_image (surface, &e); gdk_gl_context_upload_texture (paint_context, image, e.width, e.height, target); cairo_surface_unmap_image (surface, image); if (use_texture_rectangle) { umax = rect.width * sx; vmax = rect.height * sy; } else { umax = 1.0; vmax = 1.0; } { GdkTexturedQuad quad = { rect.x * window_scale, FLIP_Y(rect.y * window_scale), (rect.x + rect.width) * window_scale, FLIP_Y((rect.y + rect.height) * window_scale), 0, 0, umax, vmax, }; /* We don't want to combine the quads here, because they have different textures. * And we don't want to upload the unused source areas to make it one texture. */ gdk_gl_texture_quads (paint_context, target, 1, &quad); } } #undef FLIP_Y glDisable (GL_SCISSOR_TEST); glDeleteTextures (1, &texture_id); }