Skip to content

Commit

Permalink
Defer creation of engine text until it's actually being rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 2, 2024
1 parent 6b5e9a2 commit cf93483
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
7 changes: 7 additions & 0 deletions src/SDL_renderer_textengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,13 @@ bool TTF_DrawRendererText(TTF_Text *text, float x, float y)
return SDL_InvalidParamError("text");
}

// Make sure the engine text is up to date
TTF_TextEngine *engine = text->internal->engine;
if (!text->internal->engine_text &&
!engine->CreateText(engine->userdata, text)) {
return false;
}

renderer = ((TTF_RendererTextEngineData *)text->internal->engine->userdata)->renderer;
data = (TTF_RendererTextEngineTextData *)text->internal->engine_text;
AtlasDrawSequence *sequence = data->draw_sequence;
Expand Down
7 changes: 7 additions & 0 deletions src/SDL_surface_textengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ bool TTF_DrawSurfaceText(TTF_Text *text, int x, int y, SDL_Surface *surface)
return SDL_InvalidParamError("surface");
}

// Make sure the engine text is up to date
TTF_TextEngine *engine = text->internal->engine;
if (!text->internal->engine_text &&
!engine->CreateText(engine->userdata, text)) {
return false;
}

data = (TTF_SurfaceTextEngineTextData *)text->internal->engine_text;

if (text->color.r != data->fcolor.r ||
Expand Down
13 changes: 2 additions & 11 deletions src/SDL_ttf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3856,15 +3856,6 @@ static void DestroyEngineText(TTF_Text *text)
}
}

static bool CreateEngineText(TTF_Text *text)
{
TTF_TextEngine *engine = text->internal->engine;
if (engine && engine->CreateText && text->font && text->text) {
return engine->CreateText(engine->userdata, text);
}
return true;
}

static bool TTF_UpdateText(TTF_Text *text)
{
DestroyEngineText(text);
Expand All @@ -3889,7 +3880,7 @@ static bool TTF_UpdateText(TTF_Text *text)
}
}

return CreateEngineText(text);
return true;
}

SDL_PropertiesID TTF_GetTextProperties(TTF_Text *text)
Expand Down Expand Up @@ -3919,7 +3910,7 @@ bool TTF_SetTextEngine(TTF_Text *text, TTF_TextEngine *engine)

text->internal->engine = engine;

return CreateEngineText(text);
return true;
}

bool TTF_SetTextFont(TTF_Text *text, TTF_Font *font)
Expand Down

0 comments on commit cf93483

Please sign in to comment.