Merge font_renderer_driver.c and font_driver.c

This commit is contained in:
twinaphex 2015-12-05 12:07:22 +01:00
parent 7246d219b6
commit df1c6344be
29 changed files with 172 additions and 226 deletions

View File

@ -182,7 +182,6 @@ OBJ += frontend/frontend.o \
libretro-common/gfx/scaler/scaler_int.o \
libretro-common/gfx/scaler/scaler_filter.o \
gfx/font_driver.o \
gfx/font_renderer_driver.o \
gfx/video_filter.o \
audio/audio_resampler_driver.o \
audio/audio_dsp_filter.o \

View File

@ -27,7 +27,7 @@
#include "libretro_private.h"
#include "gfx/font_renderer_driver.h"
#include "gfx/font_driver.h"
#include "camera/camera_driver.h"
#include "location/location_driver.h"

View File

@ -32,7 +32,7 @@
#include "../../general.h"
#include "../../verbosity.h"
#include "../font_renderer_driver.h"
#include "../font_driver.h"
#include "../video_common.h"
#include "../video_context_driver.h"
#include "../video_shader_driver.h"

View File

@ -52,7 +52,6 @@
#endif
#include "../font_driver.h"
#include "../font_renderer_driver.h"
#include "../video_context_driver.h"
#include "../common/d3d_common.h"
#include "render_chain_driver.h"

View File

@ -25,7 +25,7 @@
#include "../../general.h"
#include "../../retroarch.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"
#include "../font_driver.h"
struct dispmanx_page
{

View File

@ -35,7 +35,7 @@
#include "../../general.h"
#include "../../retroarch.h"
#include "../../runloop.h"
#include "../font_renderer_driver.h"
#include "../font_driver.h"
/* TODO: Honor these properties: vsync, menu rotation, menu alpha, aspect ratio change */

View File

@ -40,7 +40,7 @@
#include "../../retroarch.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"
#include "../font_driver.h"
typedef struct omapfb_page
{

View File

@ -28,7 +28,7 @@
#include "../../performance.h"
#include "../../verbosity.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"
#include "../font_driver.h"
#ifdef HAVE_X11
#include "../common/x11_common.h"
@ -100,7 +100,7 @@ static void sdl2_init_font(sdl2_video_t *vid, const char *font_path,
if (!settings->video.font_enable)
return;
if (!font_renderer_create_default(&vid->font_driver, &vid->font_data,
if (!font_renderer_create_default((const void**)&vid->font_driver, &vid->font_data,
*font_path ? font_path : NULL, font_size))
{
RARCH_WARN("[SDL]: Could not initialize fonts.\n");

View File

@ -25,7 +25,7 @@
#include "../../general.h"
#include "../../performance.h"
#include "../video_context_driver.h"
#include "../font_renderer_driver.h"
#include "../font_driver.h"
#ifdef HAVE_X11
#include "../common/x11_common.h"

View File

@ -25,7 +25,7 @@
#include "../../general.h"
#include "../../retroarch.h"
#include "../font_renderer_driver.h"
#include "../font_driver.h"
#define NUMPAGES 2

View File

@ -30,7 +30,7 @@
#include "../../retroarch.h"
#include "../../driver.h"
#include "../../performance.h"
#include "../font_renderer_driver.h"
#include "../font_driver.h"
#include "../../content.h"
#include "../../runloop.h"
#include "../../verbosity.h"

View File

@ -28,7 +28,7 @@
#include "../../driver.h"
#include "../../general.h"
#include "../font_renderer_driver.h"
#include "../font_driver.h"
#include "../common/x11_common.h"
typedef struct xshm

View File

@ -32,7 +32,7 @@
#include "../../driver.h"
#include "../../general.h"
#include "../../verbosity.h"
#include "../font_renderer_driver.h"
#include "../font_driver.h"
#include "../common/x11_common.h"
@ -120,7 +120,7 @@ static void xv_init_font(xv_t *xv, const char *font_path, unsigned font_size)
if (!settings->video.font_enable)
return;
if (font_renderer_create_default(&xv->font_driver,
if (font_renderer_create_default((const void**)&xv->font_driver,
&xv->font, *settings->video.font_path
? settings->video.font_path : NULL, settings->video.font_size))
{

View File

@ -144,7 +144,7 @@ static void *gl_raster_font_init_font(void *data,
font->gl = (gl_t*)data;
if (!font_renderer_create_default(&font->font_driver,
if (!font_renderer_create_default((const void**)&font->font_driver,
&font->font_data, font_path, font_size))
{
RARCH_WARN("Couldn't initialize font renderer.\n");

View File

@ -29,7 +29,6 @@
#define DbgFontExit cellDbgFontExit
#endif
#include "../font_renderer_driver.h"
#include "../font_driver.h"
static void *libdbg_font_init_font(void *gl_data, const char *font_path, float font_size)

View File

@ -16,7 +16,6 @@
#include <vita2d.h>
#include "../font_renderer_driver.h"
#include "../font_driver.h"
const unsigned char stockfont[] = {

View File

@ -20,7 +20,7 @@
#include <boolean.h>
#include "../font_renderer_driver.h"
#include "../font_driver.h"
#include "bitmap.h"
#define BMP_ATLAS_COLS 16

View File

@ -25,7 +25,7 @@
#include <ApplicationServices/ApplicationServices.h>
#endif
#include "../font_renderer_driver.h"
#include "../font_driver.h"
#include "../../general.h"
#define CT_ATLAS_ROWS 16

View File

@ -19,10 +19,12 @@
#include <string.h>
#include <ft2build.h>
#include <file/file_path.h>
#include FT_FREETYPE_H
#include "../font_renderer_driver.h"
#include <file/file_path.h>
#include "../font_driver.h"
#include "../../general.h"
#define FT_ATLAS_ROWS 16

View File

@ -18,7 +18,7 @@
#include <file/file_path.h>
#include "../font_renderer_driver.h"
#include "../font_driver.h"
#include "../../general.h"
#include "../../verbosity.h"
#include "../../file_ops.h"

View File

@ -17,6 +17,67 @@
#include "font_driver.h"
#include "video_thread_wrapper.h"
#include "../general.h"
#include "../verbosity.h"
static const font_renderer_driver_t *font_backends[] = {
#ifdef HAVE_FREETYPE
&freetype_font_renderer,
#endif
#if defined(__APPLE__) && defined(HAVE_CORETEXT)
&coretext_font_renderer,
#endif
#ifdef HAVE_STB_FONT
&stb_font_renderer,
#endif
&bitmap_font_renderer,
NULL
};
int font_renderer_get_message_width(const char *msg, float scale)
{
driver_t *driver = driver_get_ptr();
const struct font_renderer *font_driver = driver ? driver->font_osd_driver : NULL;
if (!font_driver || !font_driver->get_message_width)
return 0;
return font_driver->get_message_width(driver->font_osd_data, msg, strlen(msg), scale);
}
int font_renderer_create_default(const void **data, void **handle,
const char *font_path, unsigned font_size)
{
unsigned i;
const font_renderer_driver_t **drv = (const font_renderer_driver_t**)data;
for (i = 0; font_backends[i]; i++)
{
const char *path = font_path;
if (!path)
path = font_backends[i]->get_default_font();
if (!path)
continue;
*handle = font_backends[i]->init(path, font_size);
if (*handle)
{
RARCH_LOG("Using font rendering backend: %s.\n",
font_backends[i]->ident);
*drv = font_backends[i];
return 1;
}
else
RARCH_ERR("Failed to create rendering backend: %s.\n",
font_backends[i]->ident);
}
*drv = NULL;
*handle = NULL;
return 0;
}
#ifdef HAVE_D3D
static const font_renderer_t *d3d_font_backends[] = {

View File

@ -18,8 +18,8 @@
#define __FONT_DRIVER_H__
#include <stdint.h>
#include <boolean.h>
#include "../driver.h"
#ifdef __cplusplus
extern "C" {
@ -40,6 +40,55 @@ enum text_alignment
TEXT_ALIGN_CENTER
};
/* All coordinates and offsets are top-left oriented.
*
* This is a texture-atlas approach which allows text to
* be drawn in a single draw call.
*
* It is up to the code using this interface to actually
* generate proper vertex buffers and upload the atlas texture to GPU. */
struct font_glyph
{
unsigned width;
unsigned height;
/* Texel coordinate offset for top-left pixel of this glyph. */
unsigned atlas_offset_x;
unsigned atlas_offset_y;
/* When drawing this glyph, apply an offset to
* current X/Y draw coordinate. */
int draw_offset_x;
int draw_offset_y;
/* Advance X/Y draw coordinates after drawing this glyph. */
int advance_x;
int advance_y;
};
struct font_atlas
{
uint8_t *buffer; /* Alpha channel. */
unsigned width;
unsigned height;
};
typedef struct font_renderer
{
void *(*init)(void *data, const char *font_path, float font_size);
void (*free)(void *data);
void (*render_msg)(void *data, const char *msg,
const void *params);
const char *ident;
const struct font_glyph *(*get_glyph)(void *data, uint32_t code);
void (*bind_block)(void *data, void *block);
void (*flush)(void *data);
int (*get_message_width)(void *data, const char *msg, unsigned msg_len_full, float scale);
} font_renderer_t;
struct font_params
{
float x;
@ -56,6 +105,30 @@ struct font_params
enum text_alignment text_align;
};
typedef struct font_renderer_driver
{
void *(*init)(const char *font_path, float font_size);
const struct font_atlas *(*get_atlas)(void *data);
/* Returns NULL if no glyph for this code is found. */
const struct font_glyph *(*get_glyph)(void *data, uint32_t code);
void (*free)(void *data);
const char *(*get_default_font)(void);
const char *ident;
int (*get_line_height)(void* data);
} font_renderer_driver_t;
/* font_path can be NULL for default font. */
int font_renderer_create_default(const void **driver,
void **handle, const char *font_path, unsigned font_size);
int font_renderer_get_message_width(const char *msg, float scale);
bool font_init_first(
const void **font_driver, void **font_handle,
void *video_data, const char *font_path, float font_size,
@ -73,6 +146,18 @@ bool font_driver_init_first(const void **font_driver, void *font_handle,
void *data, const char *font_path, float font_size,
bool threading_hint, enum font_driver_render_api api);
extern font_renderer_t gl_raster_font;
extern font_renderer_t libdbg_font;
extern font_renderer_t d3d_xbox360_font;
extern font_renderer_t d3d_xdk1_font;
extern font_renderer_t d3d_win32_font;
extern font_renderer_t vita2d_vita_font;
extern font_renderer_driver_t stb_font_renderer;
extern font_renderer_driver_t freetype_font_renderer;
extern font_renderer_driver_t coretext_font_renderer;
extern font_renderer_driver_t bitmap_font_renderer;
#ifdef __cplusplus
}
#endif

View File

@ -1,80 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../general.h"
#include "../verbosity.h"
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
static const font_renderer_driver_t *font_backends[] = {
#ifdef HAVE_FREETYPE
&freetype_font_renderer,
#endif
#if defined(__APPLE__) && defined(HAVE_CORETEXT)
&coretext_font_renderer,
#endif
#ifdef HAVE_STB_FONT
&stb_font_renderer,
#endif
&bitmap_font_renderer,
NULL
};
int font_renderer_get_message_width(const char *msg, float scale)
{
driver_t *driver = driver_get_ptr();
const struct font_renderer *font_driver = driver ? driver->font_osd_driver : NULL;
if (!font_driver || !font_driver->get_message_width)
return 0;
return font_driver->get_message_width(driver->font_osd_data, msg, strlen(msg), scale);
}
bool font_renderer_create_default(
const font_renderer_driver_t **drv, void **handle,
const char *font_path, unsigned font_size)
{
unsigned i;
for (i = 0; font_backends[i]; i++)
{
const char *path = font_path;
if (!path)
path = font_backends[i]->get_default_font();
if (!path)
continue;
*handle = font_backends[i]->init(path, font_size);
if (*handle)
{
RARCH_LOG("Using font rendering backend: %s.\n",
font_backends[i]->ident);
*drv = font_backends[i];
return true;
}
else
RARCH_ERR("Failed to create rendering backend: %s.\n",
font_backends[i]->ident);
}
*drv = NULL;
*handle = NULL;
return false;
}

View File

@ -1,117 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RARCH_FONTS_H
#define __RARCH_FONTS_H
#include <stdint.h>
#include <boolean.h>
#ifdef __cplusplus
extern "C" {
#endif
/* All coordinates and offsets are top-left oriented.
*
* This is a texture-atlas approach which allows text to
* be drawn in a single draw call.
*
* It is up to the code using this interface to actually
* generate proper vertex buffers and upload the atlas texture to GPU. */
struct font_glyph
{
unsigned width;
unsigned height;
/* Texel coordinate offset for top-left pixel of this glyph. */
unsigned atlas_offset_x;
unsigned atlas_offset_y;
/* When drawing this glyph, apply an offset to
* current X/Y draw coordinate. */
int draw_offset_x;
int draw_offset_y;
/* Advance X/Y draw coordinates after drawing this glyph. */
int advance_x;
int advance_y;
};
struct font_atlas
{
uint8_t *buffer; /* Alpha channel. */
unsigned width;
unsigned height;
};
typedef struct font_renderer
{
void *(*init)(void *data, const char *font_path, float font_size);
void (*free)(void *data);
void (*render_msg)(void *data, const char *msg,
const void *params);
const char *ident;
const struct font_glyph *(*get_glyph)(void *data, uint32_t code);
void (*bind_block)(void *data, void *block);
void (*flush)(void *data);
int (*get_message_width)(void *data, const char *msg, unsigned msg_len_full, float scale);
} font_renderer_t;
extern font_renderer_t gl_raster_font;
extern font_renderer_t libdbg_font;
extern font_renderer_t d3d_xbox360_font;
extern font_renderer_t d3d_xdk1_font;
extern font_renderer_t d3d_win32_font;
extern font_renderer_t vita2d_vita_font;
typedef struct font_renderer_driver
{
void *(*init)(const char *font_path, float font_size);
const struct font_atlas *(*get_atlas)(void *data);
/* Returns NULL if no glyph for this code is found. */
const struct font_glyph *(*get_glyph)(void *data, uint32_t code);
void (*free)(void *data);
const char *(*get_default_font)(void);
const char *ident;
int (*get_line_height)(void* data);
} font_renderer_driver_t;
extern font_renderer_driver_t stb_font_renderer;
extern font_renderer_driver_t freetype_font_renderer;
extern font_renderer_driver_t coretext_font_renderer;
extern font_renderer_driver_t bitmap_font_renderer;
/* font_path can be NULL for default font. */
bool font_renderer_create_default(const font_renderer_driver_t **driver,
void **handle, const char *font_path, unsigned font_size);
int font_renderer_get_message_width(const char *msg, float scale);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -272,7 +272,6 @@ VIDEO DRIVER
FONTS
============================================================ */
#include "../gfx/font_renderer_driver.c"
#include "../gfx/drivers_font_renderer/bitmapfont.c"
#include "../gfx/font_driver.c"

View File

@ -18,7 +18,7 @@
#include <gfx/math/matrix_4x4.h>
#include "../../config.def.h"
#include "../../gfx/font_renderer_driver.h"
#include "../../gfx/font_driver.h"
#include "../../gfx/video_context_driver.h"
#include "../../gfx/video_texture.h"
#include "../../gfx/d3d/d3d.h"

View File

@ -16,7 +16,7 @@
#include <retro_miscellaneous.h>
#include "../../config.def.h"
#include "../../gfx/font_renderer_driver.h"
#include "../../gfx/font_driver.h"
#include "../../gfx/video_context_driver.h"
#include "../../gfx/video_texture.h"
#include "../../gfx/common/gl_common.h"

View File

@ -19,7 +19,7 @@
#include <retro_miscellaneous.h>
#include "../../config.def.h"
#include "../../gfx/font_renderer_driver.h"
#include "../../gfx/font_driver.h"
#include "../../gfx/video_context_driver.h"
#include "../../gfx/video_texture.h"

View File

@ -22,7 +22,7 @@
#include "../gfx/video_texture.h"
#include "../gfx/video_context_driver.h"
#include "../gfx/font_renderer_driver.h"
#include "../gfx/font_driver.h"
#include "../gfx/video_common.h"
#ifdef __cplusplus