mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
Defer pool cleanup only for layers still in use
This commit is contained in:
1 parent
31ee95250c
commit
97a998a3b9
1 file changed
+18
-17
@@ -176,6 +176,7 @@ struct layer {
|
||||
int votes_rate;
|
||||
float fps_applied;
|
||||
int recreate_pending;
|
||||
int pending_callbacks;
|
||||
|
||||
int32_t ds_applied;
|
||||
|
||||
@@ -298,6 +299,8 @@ static void on_complete(void *context, ASurfaceTransactionStats *stats) {
|
||||
}
|
||||
}
|
||||
if (g_pending_cb > 0) g_pending_cb--;
|
||||
if (ctx->layer >= 0 && ctx->layer < SC_LAYER_COUNT && g_layers[ctx->layer].pending_callbacks > 0)
|
||||
g_layers[ctx->layer].pending_callbacks--;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
if (ctx->prev_token) {
|
||||
int fd = (stats && ctx->sc) ? api.prevReleaseFence(stats, ctx->sc) : -1;
|
||||
@@ -320,6 +323,7 @@ static int add_complete_on(ASurfaceTransaction *tx, struct layer *l, ASurfaceCon
|
||||
ctx->prev_token = prev_token; ctx->retire = retire;
|
||||
pthread_mutex_lock(&g_lock);
|
||||
g_pending_cb++;
|
||||
l->pending_callbacks++;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
api.setOnComplete(tx, ctx, on_complete);
|
||||
return 0;
|
||||
@@ -427,38 +431,35 @@ static void retire_sc(struct layer *l) {
|
||||
|
||||
static void drain_and_free_pools(void) {
|
||||
int64_t deadline = now_ns() + 300000000LL;
|
||||
int pending;
|
||||
do {
|
||||
for (;;) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
pending = g_pending_cb;
|
||||
int pending = g_pending_cb;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
if (!pending || now_ns() > deadline) break;
|
||||
usleep(2000);
|
||||
} while (1);
|
||||
if (pending) {
|
||||
droiddeck_log("layer", "pool drain deferred while %d SurfaceControl callbacks are pending", pending);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < SC_LAYER_COUNT; i++) {
|
||||
if (g_layers[i].sc) {
|
||||
droiddeck_log("layer", "pool drain deferred while %s still owns a SurfaceControl", g_layers[i].name);
|
||||
return;
|
||||
struct layer *l = &g_layers[i];
|
||||
pthread_mutex_lock(&g_lock);
|
||||
const int pending = l->pending_callbacks;
|
||||
if (pending || l->sc) {
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
droiddeck_log("layer", "pool drain deferred for %s (%s)", l->name,
|
||||
pending ? "SurfaceControl callbacks are pending" : "SurfaceControl retirement is deferred");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
pthread_mutex_lock(&g_lock);
|
||||
for (int i = 0; i < SC_LAYER_COUNT; i++) {
|
||||
for (int j = 0; j < POOL_MAX; j++) {
|
||||
struct slot *s = &g_layers[i].slots[j];
|
||||
struct slot *s = &l->slots[j];
|
||||
if (s->release_fd >= 0) { struct pollfd p = {.fd = s->release_fd, .events = POLLIN}; poll(&p, 1, 100); close(s->release_fd); }
|
||||
if (s->img) vkp_image_destroy(s->img);
|
||||
if (s->ahb) AHardwareBuffer_release(s->ahb);
|
||||
memset(s, 0, sizeof(*s));
|
||||
s->release_fd = -1;
|
||||
}
|
||||
g_layers[i].first_logged = 0;
|
||||
g_layers[i].logged_w = g_layers[i].logged_h = 0;
|
||||
l->first_logged = 0;
|
||||
l->logged_w = l->logged_h = 0;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
|
||||
static int sniff_modifier(const struct droiddeck_native_handle *h, uint64_t *mod) {
|
||||
|
||||
Reference in new issue
Block a user