graphic_hw_update(dcl->con);
if (con->surface && !con->is_scanout && con->updated) {
- con->surface->texture = qt5_gl_refresh_internal(con->surface->texture, surface_width(con->surface), surface_height(con->surface), con->gen);
+ bool should_free;
+ con->surface->texture = qt5_gl_refresh_internal(con->surface->texture, surface_width(con->surface), surface_height(con->surface), con->gen, &should_free);
+ if (should_free) {
+ surface_gl_destroy_texture(con->gls, con->surface);
+ }
if (con->surface->texture == 0) {
surface_gl_create_texture(con->gls, con->surface);
}
0, 0, surface_width(con->surface), surface_height(con->surface),
GL_COLOR_BUFFER_BIT, GL_NEAREST);
- con->surface->texture = qt5_gl_refresh_internal(con->surface->texture, surface_width(con->surface), surface_height(con->surface), con->gen);
+ bool should_free;
+ con->surface->texture = qt5_gl_refresh_internal(con->surface->texture, surface_width(con->surface), surface_height(con->surface), con->gen, &should_free);
+ if (should_free) {
+ surface_gl_destroy_texture(con->gls, con->surface);
+ }
if (con->surface->texture == 0) {
surface_gl_create_texture(con->gls, con->surface);
}
static dpy_item dpy_item_pool[DPY_ITEM_NO];
static uint64_t dpy_item_gen[DPY_ITEM_NO];
-uint32_t qt5_gl_refresh_internal(uint32_t tex, uint32_t width, uint32_t height, uint64_t gen)
+uint32_t qt5_gl_refresh_internal(uint32_t tex, uint32_t width, uint32_t height, uint64_t gen, bool *should_free)
{
uint32_t ret = tex;
+ *should_free = false;
if (mainwindow) {
int item_id = 0;
qemu_mutex_lock(&item->mutex);
bool ok = dpy_item_gen[item_id] == 0 || item->available;
if (ok) {
- if (dpy_item_gen[item_id] == gen && /* HACK HACK HACK */ item->tex >= 25) {
- ret = item->tex;
- } else {
- // TODO: we will leak a texture soon!
+ ret = item->tex;
+ if (dpy_item_gen[item_id] != gen || /* HACK HACK HACK */ item->tex < 25) {
+ /* This tells the caller that the texture should not be used anymore.
+ * Preferably we could handle this right here, but the caller can do it
+ * conveniently and I couldn't get compilation to work. */
dpy_item_gen[item_id] = gen;
- ret = 0;
+ *should_free = true;
}
item->tex = tex;
item->width = width;
void qt5_set_force_legacy(bool isLegacy);
#ifdef CONFIG_OPENGL
-uint32_t qt5_gl_refresh_internal(uint32_t tex, uint32_t width, uint32_t height, uint64_t gen);
+uint32_t qt5_gl_refresh_internal(uint32_t tex, uint32_t width, uint32_t height, uint64_t gen, bool *should_free);
void *qt5_gl_create_context_internal(int major, int minor);
void qt5_gl_destroy_context_internal(void *);
int qt5_gl_make_context_current_internal(void *_ctx);