mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use reusable temporary buffer in Win32FontCache. (#12666)
This avoids allocating and deleting a temporary buffer for every glyph that is rendered into a sprite.pull/12692/head
parent
4940b6ff0b
commit
c85481564f
|
@ -10,7 +10,6 @@
|
||||||
#include "../../stdafx.h"
|
#include "../../stdafx.h"
|
||||||
#include "../../debug.h"
|
#include "../../debug.h"
|
||||||
#include "../../blitter/factory.hpp"
|
#include "../../blitter/factory.hpp"
|
||||||
#include "../../core/alloc_func.hpp"
|
|
||||||
#include "../../core/math_func.hpp"
|
#include "../../core/math_func.hpp"
|
||||||
#include "../../core/mem_func.hpp"
|
#include "../../core/mem_func.hpp"
|
||||||
#include "../../error_func.h"
|
#include "../../error_func.h"
|
||||||
|
@ -209,7 +208,7 @@ void Win32FontCache::ClearFontCache()
|
||||||
if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
|
if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
|
||||||
|
|
||||||
/* Call GetGlyphOutline again with size to actually render the glyph. */
|
/* Call GetGlyphOutline again with size to actually render the glyph. */
|
||||||
uint8_t *bmp = new uint8_t[size];
|
uint8_t *bmp = this->render_buffer.Allocate(size);
|
||||||
GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
|
GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
|
||||||
|
|
||||||
/* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
|
/* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
|
||||||
|
@ -259,8 +258,6 @@ void Win32FontCache::ClearFontCache()
|
||||||
|
|
||||||
this->SetGlyphPtr(key, &new_glyph);
|
this->SetGlyphPtr(key, &new_glyph);
|
||||||
|
|
||||||
delete[] bmp;
|
|
||||||
|
|
||||||
return new_glyph.sprite;
|
return new_glyph.sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#ifndef FONT_WIN32_H
|
#ifndef FONT_WIN32_H
|
||||||
#define FONT_WIN32_H
|
#define FONT_WIN32_H
|
||||||
|
|
||||||
|
#include "../../core/alloc_type.hpp"
|
||||||
#include "../../fontcache/truetypefontcache.h"
|
#include "../../fontcache/truetypefontcache.h"
|
||||||
#include "win32.h"
|
#include "win32.h"
|
||||||
|
|
||||||
|
@ -25,6 +26,8 @@ private:
|
||||||
SIZE glyph_size; ///< Maximum size of regular glyphs.
|
SIZE glyph_size; ///< Maximum size of regular glyphs.
|
||||||
std::string fontname; ///< Cached copy of loaded font facename
|
std::string fontname; ///< Cached copy of loaded font facename
|
||||||
|
|
||||||
|
ReusableBuffer<uint8_t> render_buffer; ///< Temporary buffer for rendering glyphs.
|
||||||
|
|
||||||
void SetFontSize(int pixels);
|
void SetFontSize(int pixels);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in New Issue