From: Mateusz Majewski Date: Tue, 25 Jun 2024 10:58:02 +0000 (+0200) Subject: Stop leaking textures X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7d8221aeb6f234468ffadfdeb3f53710ba20bd1b;p=sdk%2Femulator%2Fqemu.git Stop leaking textures Change-Id: I3024cfac635dbb8a8af623da0afb6fceb02771a7 --- diff --git a/tizen/src/ui/qt5.c b/tizen/src/ui/qt5.c index e6d095fd74..f1739b5837 100644 --- a/tizen/src/ui/qt5.c +++ b/tizen/src/ui/qt5.c @@ -194,7 +194,11 @@ static void qt5_gl_refresh(DisplayChangeListener *dcl) 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); } @@ -274,7 +278,11 @@ static void qt5_gl_scanout_flush(DisplayChangeListener *dcl, 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); } diff --git a/tizen/src/ui/qt5_supplement.cpp b/tizen/src/ui/qt5_supplement.cpp index e2cbfe214e..35354c2cfa 100644 --- a/tizen/src/ui/qt5_supplement.cpp +++ b/tizen/src/ui/qt5_supplement.cpp @@ -615,9 +615,10 @@ void qt5_update_texture(void *dpy_item) 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; @@ -627,12 +628,13 @@ uint32_t qt5_gl_refresh_internal(uint32_t tex, uint32_t width, uint32_t height, 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; diff --git a/tizen/src/ui/qt5_supplement.h b/tizen/src/ui/qt5_supplement.h index 8c5878e0de..b5ec02a8c0 100644 --- a/tizen/src/ui/qt5_supplement.h +++ b/tizen/src/ui/qt5_supplement.h @@ -64,7 +64,7 @@ const char* qt5_get_version(void); 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);