Render: free the last-frame texture after an idle second
An idle window keeps no copy of its last frame; the next change draws one full frame and partial frames follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
022615bcdf
commit
72f12cd098
@@ -130,6 +130,8 @@ typedef struct reaktor_damage {
|
||||
int kw, kh;
|
||||
struct nk_color clear;
|
||||
int checking;
|
||||
unsigned idle;
|
||||
Uint64 drawn;
|
||||
float peak;
|
||||
unsigned long partial, full, mismatched;
|
||||
} reaktor_damage;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#define LOOKAHEAD 32
|
||||
#define SERIAL "reaktor.serial"
|
||||
#define IDLE_MS 1000
|
||||
|
||||
typedef struct sink {
|
||||
reaktor_damage_list *l;
|
||||
@@ -587,11 +588,29 @@ drop(App *app)
|
||||
SDL_SetRenderScale(app->ren, app->render_scale, app->render_scale);
|
||||
}
|
||||
|
||||
/* K exists to draw the next frame over; an idle window does not need it. */
|
||||
static void
|
||||
idle_due(App *app, void *user)
|
||||
{
|
||||
reaktor_damage *d = &app->damage;
|
||||
Uint64 idle = SDL_GetTicks() - d->drawn;
|
||||
|
||||
(void)user;
|
||||
d->idle = 0;
|
||||
if (!d->k) return;
|
||||
if (idle < IDLE_MS)
|
||||
d->idle = reaktor_timer(app, (int)(IDLE_MS - idle), 0, idle_due, NULL);
|
||||
else
|
||||
drop(app);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_damage_free(App *app)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (app->damage.idle) reaktor_timer_stop(app->damage.idle);
|
||||
app->damage.idle = 0;
|
||||
if (app->ren) drop(app);
|
||||
for (i = 0; i < 2; i++) {
|
||||
SDL_free(app->damage.list[i].item);
|
||||
@@ -736,6 +755,8 @@ reaktor_damage_render(App *app)
|
||||
SDL_RenderTexture(app->ren, d->k, NULL, NULL);
|
||||
d->now = !d->now;
|
||||
d->clear = app->clear;
|
||||
d->drawn = SDL_GetTicks();
|
||||
if (!d->idle) d->idle = reaktor_timer(app, IDLE_MS, 0, idle_due, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -503,6 +503,17 @@ script(reaktor_test *t, void *user)
|
||||
for (i = 0; i < 30; i++) move(t, 4.0f + i * 6.0f, 14.0f);
|
||||
reaktor_test_check(t, d->partial > partial, "back at scale 1, partial frames again");
|
||||
|
||||
SDL_Delay(1300);
|
||||
reaktor_test_settle(t);
|
||||
reaktor_test_check(t, !d->k, "an idle second frees the last frame");
|
||||
partial = d->partial;
|
||||
full = d->full;
|
||||
move(t, 600.0f, 400.0f);
|
||||
move(t, 30.0f, 20.0f);
|
||||
move(t, 110.0f, 20.0f);
|
||||
reaktor_test_check(t, d->k && d->full == full + 1 && d->partial > partial,
|
||||
"after an idle second, one full frame and then partial ones");
|
||||
|
||||
SDL_snprintf(log, sizeof log, "%lu partial and %lu full frames compared",
|
||||
d->partial, d->full);
|
||||
reaktor_test_check(t, d->partial > 50, log);
|
||||
|
||||
Reference in New Issue
Block a user