Revert "Free font data inside gfx/font_driver.c's free function"

This reverts commit b3f1bbc15e8f8c08531c3661041d0ded9bfeca51.
This commit is contained in:
twinaphex 2017-01-14 21:02:30 +01:00
parent a73a90b701
commit c875d95f7a
10 changed files with 144 additions and 138 deletions

View File

@ -59,6 +59,7 @@ static void *caca_init_font(void *data,
static void caca_render_free_font(void *data)
{
}
static int caca_get_message_width(void *data, const char *msg,

View File

@ -109,6 +109,7 @@ static void ctr_font_free_font(void* data)
#else
linearFree(font->texture.data);
#endif
free(font);
}
static int ctr_font_get_message_width(void* data, const char* msg,

View File

@ -88,6 +88,9 @@ static void d3dfonts_w32_free_font(void *data)
if (d3dfonts->font)
d3dfonts->font->Release();
d3dfonts->font = NULL;
free(d3dfonts);
d3dfonts = NULL;
}
static void d3dfonts_w32_render_msg(void *data, const char *msg,

View File

@ -57,6 +57,8 @@ typedef struct
video_font_raster_block_t *block;
} gl_raster_t;
static void gl_raster_font_free_font(void *data);
static bool gl_raster_font_upload_atlas(gl_raster_t *font)
{
unsigned i, j;
@ -142,21 +144,6 @@ static bool gl_raster_font_upload_atlas(gl_raster_t *font)
return true;
}
static void gl_raster_font_free_font(void *data)
{
gl_raster_t *font = (gl_raster_t*)data;
if (!font)
return;
if (font->font_driver && font->font_data)
font->font_driver->free(font->font_data);
if (video_driver_is_threaded())
video_context_driver_make_current(true);
glDeleteTextures(1, &font->tex);
}
static void *gl_raster_font_init_font(void *data,
const char *font_path, float font_size)
{
@ -169,7 +156,11 @@ static void *gl_raster_font_init_font(void *data,
if (!font_renderer_create_default((const void**)&font->font_driver,
&font->font_data, font_path, font_size))
goto error;
{
RARCH_WARN("Couldn't initialize font renderer.\n");
free(font);
return NULL;
}
if (video_driver_is_threaded())
video_context_driver_make_current(false);
@ -195,13 +186,28 @@ static void *gl_raster_font_init_font(void *data,
return font;
error:
RARCH_WARN("Couldn't initialize font renderer.\n");
gl_raster_font_free_font(font);
free(font);
font = NULL;
return NULL;
}
static void gl_raster_font_free_font(void *data)
{
gl_raster_t *font = (gl_raster_t*)data;
if (!font)
return;
if (font->font_driver && font->font_data)
font->font_driver->free(font->font_data);
if (video_driver_is_threaded())
video_context_driver_make_current(true);
glDeleteTextures(1, &font->tex);
free(font);
}
static int gl_get_message_width(void *data, const char *msg,
unsigned msg_len, float scale)

View File

@ -98,6 +98,8 @@ static void vita2d_font_free_font(void *data)
vita2d_wait_rendering_done();
#endif
vita2d_free_texture(font->texture);
free(font);
}
static int vita2d_font_get_message_width(void *data, const char *msg,

View File

@ -85,6 +85,8 @@ static void vulkan_raster_font_free_font(void *data)
vkQueueWaitIdle(font->vk->context->queue);
vulkan_destroy_texture(
font->vk->context->device, &font->texture);
free(font);
}
static int vulkan_get_message_width(void *data, const char *msg,

View File

@ -55,6 +55,12 @@ static void *xfonts_init_font(void *video_data,
static void xfonts_free_font(void *data)
{
xfonts_t *font = (xfonts_t*)data;
if (font)
free(font);
font = NULL;
}
static void xfonts_render_msg(void *data, const char *msg,

View File

@ -58,18 +58,18 @@ enum
class PackedResource
{
protected:
BYTE* m_pSysMemData; /* Allocated memory for resource headers etc. */
BYTE* m_pSysMemData; // Alloc'ed memory for resource headers etc.
DWORD m_dwSysMemDataSize;
BYTE* m_pVidMemData; /* Allocated memory for resource data, etc. */
BYTE* m_pVidMemData; // Alloc'ed memory for resource data, etc.
DWORD m_dwVidMemDataSize;
XBRESOURCE* m_pResourceTags; /* Tags to associate names with the resources */
DWORD m_dwNumResourceTags; /* Number of resource tags */
BOOL m_bInitialized; /* Resource is fully initialized */
XBRESOURCE* m_pResourceTags; // Tags to associate names with the resources
DWORD m_dwNumResourceTags; // Number of resource tags
BOOL m_bInitialized; // Resource is fully initialized
public:
/* Loads the resources out of the specified bundle */
// Loads the resources out of the specified bundle
#if defined(_XBOX1)
HRESULT Create( const char *strFilename, DWORD dwNumResourceTags = 0L,
XBRESOURCE* pResourceTags = NULL );
@ -82,21 +82,20 @@ class PackedResource
BOOL Initialized() const;
#ifdef _XBOX360
/* Retrieves the resource tags */
// Retrieves the resource tags
void GetResourceTags( DWORD* pdwNumResourceTags, XBRESOURCE** ppResourceTags );
#endif
/* Helper function to make sure a resource is registered */
// Helper function to make sure a resource is registered
LPDIRECT3DRESOURCE RegisterResource( LPDIRECT3DRESOURCE pResource ) const
{
#ifdef _XBOX1
/* Register the resource, if it has not yet been registered. We mark
* a resource as registered by upping it's reference count. */
// Register the resource, if it has not yet been registered. We mark
// a resource as registered by upping it's reference count.
if( pResource && ( pResource->Common & D3DCOMMON_REFCOUNT_MASK ) == 1 )
{
/* Special case CPU-copy push buffers (which live in system memory) */
if( ( pResource->Common & D3DCOMMON_TYPE_PUSHBUFFER ) &&
// Special case CPU-copy push buffers (which live in system memory)
if( ( pResource->Common & D3DCOMMON_TYPE_PUSHBUFFER ) &&
( pResource->Common & D3DPUSHBUFFER_RUN_USING_CPU_COPY ) )
pResource->Data += (DWORD)m_pSysMemData;
else
@ -108,46 +107,32 @@ class PackedResource
return pResource;
}
/* Functions to retrieve resources by their offset */
// Functions to retrieve resources by their offset
void *GetData( DWORD dwOffset ) const
{
return &m_pSysMemData[dwOffset];
}
{ return &m_pSysMemData[dwOffset]; }
LPDIRECT3DRESOURCE GetResource( DWORD dwOffset ) const
{
return RegisterResource( (LPDIRECT3DRESOURCE)GetData(dwOffset) );
}
{ return RegisterResource( (LPDIRECT3DRESOURCE)GetData(dwOffset) ); }
LPDIRECT3DTEXTURE GetTexture( DWORD dwOffset ) const
{
return (LPDIRECT3DTEXTURE)GetResource( dwOffset );
}
{ return (LPDIRECT3DTEXTURE)GetResource( dwOffset ); }
LPDIRECT3DVERTEXBUFFER GetVertexBuffer( DWORD dwOffset ) const
{
return (LPDIRECT3DVERTEXBUFFER)GetResource( dwOffset );
}
{ return (LPDIRECT3DVERTEXBUFFER)GetResource( dwOffset ); }
/* Functions to retrieve resources by their name */
// Functions to retrieve resources by their name
void *GetData( const char* strName ) const;
LPDIRECT3DRESOURCE GetResource( const char* strName ) const
{
return RegisterResource( (LPDIRECT3DRESOURCE)GetData(strName));
}
{ return RegisterResource( (LPDIRECT3DRESOURCE)GetData( strName ) ); }
LPDIRECT3DTEXTURE GetTexture( const char* strName ) const
{
return (LPDIRECT3DTEXTURE)GetResource( strName );
}
{ return (LPDIRECT3DTEXTURE)GetResource( strName ); }
LPDIRECT3DVERTEXBUFFER GetVertexBuffer( const char* strName ) const
{
return (LPDIRECT3DVERTEXBUFFER)GetResource( strName );
}
{ return (LPDIRECT3DVERTEXBUFFER)GetResource( strName ); }
/* Constructor/destructor */
// Constructor/destructor
PackedResource();
~PackedResource();
};
@ -158,13 +143,13 @@ class PackedResource
PackedResource::PackedResource()
{
m_pSysMemData = NULL;
m_dwSysMemDataSize = 0L;
m_pVidMemData = NULL;
m_dwVidMemDataSize = 0L;
m_pResourceTags = NULL;
m_pSysMemData = NULL;
m_dwSysMemDataSize = 0L;
m_pVidMemData = NULL;
m_dwVidMemDataSize = 0L;
m_pResourceTags = NULL;
m_dwNumResourceTags = 0L;
m_bInitialized = FALSE;
m_bInitialized = FALSE;
}
@ -250,8 +235,8 @@ HRESULT PackedResource::Create(const char *strFilename)
XPR_HEADER xprh;
bool retval;
#ifdef _XBOX1
char strResourcePath[512];
BOOL bHasResourceOffsetsTable = FALSE;
char strResourcePath[512];
if (FAILED(FindMediaFile(strResourcePath, strFilename, sizeof(strResourcePath))))
return E_FAIL;
@ -285,7 +270,7 @@ HRESULT PackedResource::Create(const char *strFilename)
return E_FAIL;
}
/* Compute memory requirements */
// Compute memory requirements
#if defined(_XBOX1)
m_dwSysMemDataSize = xprh.dwHeaderSize - sizeof(XPR_HEADER);
m_dwVidMemDataSize = xprh.dwTotalSize - xprh.dwHeaderSize;
@ -294,7 +279,7 @@ HRESULT PackedResource::Create(const char *strFilename)
m_dwVidMemDataSize = xprh.dwDataSize;
#endif
/* Allocate memory */
// Allocate memory
m_pSysMemData = (BYTE*)malloc(m_dwSysMemDataSize);
if (m_pSysMemData == NULL)
{
@ -319,7 +304,7 @@ HRESULT PackedResource::Create(const char *strFilename)
return E_FAIL;
}
/* Read in the data from the file */
// Read in the data from the file
if( !ReadFile( hFile, m_pSysMemData, m_dwSysMemDataSize, &dwNumBytesRead, NULL) ||
!ReadFile( hFile, m_pVidMemData, m_dwVidMemDataSize, &dwNumBytesRead, NULL))
{
@ -327,7 +312,7 @@ HRESULT PackedResource::Create(const char *strFilename)
return E_FAIL;
}
/* Done with the file */
// Done with the file
CloseHandle( hFile);
#ifdef _XBOX1
@ -386,17 +371,16 @@ void PackedResource::GetResourceTags(DWORD* pdwNumResourceTags,
void PackedResource::Destroy()
{
free(m_pSysMemData);
m_pSysMemData = NULL;
m_dwSysMemDataSize = 0L;
if (m_pVidMemData)
if (m_pVidMemData != NULL)
FreeContiguousMemory(m_pVidMemData);
m_pSysMemData = NULL;
m_dwSysMemDataSize = 0L;
m_pVidMemData = NULL;
m_dwVidMemDataSize = 0L;
m_pVidMemData = NULL;
m_dwVidMemDataSize = 0L;
m_pResourceTags = NULL;
m_pResourceTags = NULL;
m_dwNumResourceTags = 0L;
m_bInitialized = FALSE;
@ -546,6 +530,8 @@ static void *xdk360_init_font(void *video_data,
if (!font)
return NULL;
(void)font_size;
font->d3d = (d3d_video_t*)video_data;
font->m_pFontTexture = NULL;
@ -613,10 +599,10 @@ static void xdk360_free_font(void *data)
return;
/* Destroy the font */
font->m_pFontTexture = NULL;
font->m_dwNumGlyphs = 0L;
font->m_Glyphs = NULL;
font->m_cMaxGlyph = 0;
font->m_pFontTexture = NULL;
font->m_dwNumGlyphs = 0L;
font->m_Glyphs = NULL;
font->m_cMaxGlyph = 0;
font->m_TranslatorTable = NULL;
if (font->s_FontLocals.m_pFontPixelShader)
@ -626,12 +612,15 @@ static void xdk360_free_font(void *data)
if (font->s_FontLocals.m_pFontVertexDecl)
font->s_FontLocals.m_pFontVertexDecl->Release();
font->s_FontLocals.m_pFontPixelShader = NULL;
font->s_FontLocals.m_pFontPixelShader = NULL;
font->s_FontLocals.m_pFontVertexShader = NULL;
font->s_FontLocals.m_pFontVertexDecl = NULL;
font->s_FontLocals.m_pFontVertexDecl = NULL;
if (m_xprResource.Initialized())
m_xprResource.Destroy();
free(font);
font = NULL;
}
static void xdk360_render_msg_post(xdk360_video_font_t * font)
@ -655,7 +644,7 @@ static void xdk360_render_msg_pre(xdk360_video_font_t * font)
d3dr->GetRenderState( D3DRS_VIEWPORTENABLE, (DWORD*)&font->m_dwSavedState );
/* Set the texture scaling factor as a vertex shader constant. */
D3DTexture_GetLevelDesc(font->m_pFontTexture, 0, &TextureDesc); /* Get the description */
D3DTexture_GetLevelDesc(font->m_pFontTexture, 0, &TextureDesc); // Get the description
/* Set render state. */
d3d_set_texture(d3dr, 0, font->m_pFontTexture);
@ -696,11 +685,11 @@ static void xdk360_draw_text(xdk360_video_font_t *font,
* the vColor array. */
d3dr->SetVertexShaderConstantF(1, vColor, 1);
m_fCursorX = floorf(x);
m_fCursorY = floorf(y);
m_fCursorX = floorf(x);
m_fCursorY = floorf(y);
/* Adjust for padding. */
y -= font->m_fFontTopPadding;
y -= font->m_fFontTopPadding;
/* Begin drawing the vertices
* Declared as volatile to force writing in ascending
@ -710,7 +699,7 @@ static void xdk360_draw_text(xdk360_video_font_t *font,
* memory.
*/
dwNumChars = wcslen(strText);
dwNumChars = wcslen(strText);
d3dr->BeginVertices(D3DPT_QUADLIST, 4 * dwNumChars,
sizeof(XMFLOAT4), (void**)&pVertex);
@ -721,8 +710,8 @@ static void xdk360_draw_text(xdk360_video_font_t *font,
#ifdef MSB_FIRST
uint32_t tu1, tu2, tv1, tv2;
#endif
const GLYPH_ATTR *pGlyph = NULL;
wchar_t letter = *strText++; /* Get the current letter in the string */
const GLYPH_ATTR *pGlyph;
wchar_t letter = *strText++; /* Get the current letter in the string */
/* Handle the newline character. */
if (letter == L'\n')
@ -743,16 +732,16 @@ static void xdk360_draw_text(xdk360_video_font_t *font,
fWidth = FONT_SCALE(font->d3d) * (float)pGlyph->wWidth;
fHeight = FONT_SCALE(font->d3d) * font->m_fFontHeight;
m_fCursorX += fOffset;
m_fCursorX += fOffset;
/* Add the vertices to draw this glyph. */
#ifdef MSB_FIRST
/* Convert shorts to 32 bit longs for in register merging */
tu1 = pGlyph->tu1;
tv1 = pGlyph->tv1;
tu2 = pGlyph->tu2;
tv2 = pGlyph->tv2;
tu1 = pGlyph->tu1;
tv1 = pGlyph->tv1;
tu2 = pGlyph->tu2;
tv2 = pGlyph->tv2;
#endif
/* NOTE: The vertexes are 2 floats for the screen coordinates,
@ -771,27 +760,27 @@ static void xdk360_draw_text(xdk360_video_font_t *font,
/* Setup the vertex/screen coordinates */
pVertex[0] = m_fCursorX;
pVertex[1] = m_fCursorY;
pVertex[3] = 0;
pVertex[4] = m_fCursorX + fWidth;
pVertex[5] = m_fCursorY;
pVertex[7] = 0;
pVertex[8] = m_fCursorX + fWidth;
pVertex[9] = m_fCursorY + fHeight;
pVertex[11] = 0;
pVertex[12] = m_fCursorX;
pVertex[13] = m_fCursorY + fHeight;
pVertex[0] = m_fCursorX;
pVertex[1] = m_fCursorY;
pVertex[3] = 0;
pVertex[4] = m_fCursorX + fWidth;
pVertex[5] = m_fCursorY;
pVertex[7] = 0;
pVertex[8] = m_fCursorX + fWidth;
pVertex[9] = m_fCursorY + fHeight;
pVertex[11] = 0;
pVertex[12] = m_fCursorX;
pVertex[13] = m_fCursorY + fHeight;
#ifdef MSB_FIRST
((volatile uint32_t *)pVertex)[2] = (tu1 << 16) | tv1; /* Merged using big endian rules */
((volatile uint32_t *)pVertex)[6] = (tu2 << 16) | tv1; /* Merged using big endian rules */
((volatile uint32_t*)pVertex)[10] = (tu2 << 16) | tv2; /* Merged using big endian rules */
((volatile uint32_t*)pVertex)[14] = (tu1 << 16) | tv2; /* Merged using big endian rules */
((volatile uint32_t *)pVertex)[2] = (tu1 << 16) | tv1; // Merged using big endian rules
((volatile uint32_t *)pVertex)[6] = (tu2 << 16) | tv1; // Merged using big endian rules
((volatile uint32_t*)pVertex)[10] = (tu2 << 16) | tv2; // Merged using big endian rules
((volatile uint32_t*)pVertex)[14] = (tu1 << 16) | tv2; // Merged using big endian rules
#endif
pVertex[15] = 0;
pVertex[15] = 0;
pVertex += 16;
pVertex += 16;
m_fCursorX += fAdvance;
m_fCursorX += fAdvance;
dwNumChars--;
}

View File

@ -14,10 +14,6 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string/stdstring.h>
#include "font_driver.h"
#include "video_thread_wrapper.h"
@ -28,6 +24,8 @@
#include "../config.h"
#endif
#include <stdlib.h>
static const font_renderer_driver_t *font_backends[] = {
#ifdef HAVE_FREETYPE
&freetype_font_renderer,
@ -194,8 +192,7 @@ static bool vulkan_font_init_first(
for (i = 0; vulkan_font_backends[i]; i++)
{
void *data = vulkan_font_backends[i]->init(
video_data, font_path, font_size);
void *data = vulkan_font_backends[i]->init(video_data, font_path, font_size);
if (!data)
continue;
@ -356,9 +353,6 @@ void font_driver_free(void *font_data)
if (font->renderer && font->renderer->free)
font->renderer->free(font->renderer_data);
if (font->renderer_data)
free(font->renderer_data);
font->renderer = NULL;
font->renderer_data = NULL;
@ -370,9 +364,9 @@ font_data_t *font_driver_init_first(
void *video_data, const char *font_path, float font_size,
bool threading_hint, enum font_driver_render_api api)
{
const void *font_driver = NULL;
void *font_handle = NULL;
bool ok = false;
const void *font_driver;
void *font_handle;
bool ok = false;
#ifdef HAVE_THREADS
if (threading_hint
@ -401,15 +395,12 @@ font_data_t *font_driver_init_first(
void font_driver_init_osd(void *video_data, bool threading_hint, enum font_driver_render_api api)
{
settings_t *settings = config_get_ptr();
const char *path = settings->path.font;
if (video_font_driver)
return;
video_font_driver = font_driver_init_first(video_data,
(!string_is_empty(path)) ? path : NULL,
settings->video.font_size,
threading_hint, api);
*settings->path.font ? settings->path.font : NULL,
settings->video.font_size, threading_hint, api);
if (!video_font_driver)
RARCH_ERR("[font]: Failed to initialize OSD font.\n");

View File

@ -1482,10 +1482,14 @@ void video_driver_set_viewport_core(void)
/* Fallback to 1:1 pixel ratio if none provided */
if (geom->aspect_ratio > 0.0f)
{
aspectratio_lut[ASPECT_RATIO_CORE].value = geom->aspect_ratio;
}
else
{
aspectratio_lut[ASPECT_RATIO_CORE].value =
(float)geom->base_width / geom->base_height;
}
}
void video_driver_reset_custom_viewport(void)
@ -1648,7 +1652,8 @@ bool video_driver_find_driver(void)
else
{
unsigned d;
RARCH_ERR("Couldn't find any video driver named \"%s\"\n", settings->video.driver);
RARCH_ERR("Couldn't find any video driver named \"%s\"\n",
settings->video.driver);
RARCH_LOG_OUTPUT("Available video drivers are:\n");
for (d = 0; video_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", video_driver_find_ident(d));
@ -1964,7 +1969,7 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp,
* geometry for the "normal" case. */
struct retro_system_av_info *av_info =
video_viewport_get_system_av_info();
unsigned base_height = 0;
unsigned base_height = 0;
if (av_info)
base_height = av_info->geometry.base_height;
@ -2225,20 +2230,20 @@ bool video_driver_translate_coord_viewport(
if (scaled_screen_y < -0x7fff || scaled_screen_y > 0x7fff)
scaled_screen_y = -0x8000; /* OOB */
mouse_x -= vp->x;
mouse_y -= vp->y;
mouse_x -= vp->x;
mouse_y -= vp->y;
scaled_x = (2 * mouse_x * 0x7fff) / norm_full_vp_width - 0x7fff;
scaled_y = (2 * mouse_y * 0x7fff) / norm_full_vp_height - 0x7fff;
scaled_x = (2 * mouse_x * 0x7fff) / norm_full_vp_width - 0x7fff;
scaled_y = (2 * mouse_y * 0x7fff) / norm_full_vp_height - 0x7fff;
if (scaled_x < -0x7fff || scaled_x > 0x7fff)
scaled_x = -0x8000; /* OOB */
scaled_x = -0x8000; /* OOB */
if (scaled_y < -0x7fff || scaled_y > 0x7fff)
scaled_y = -0x8000; /* OOB */
scaled_y = -0x8000; /* OOB */
*res_x = scaled_x;
*res_y = scaled_y;
*res_screen_x = scaled_screen_x;
*res_screen_y = scaled_screen_y;
*res_x = scaled_x;
*res_y = scaled_y;
*res_screen_x = scaled_screen_x;
*res_screen_y = scaled_screen_y;
return true;
}