From 527d1557ceda6165d4eb1158d7255860a8fb5b24 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Tue, 15 Nov 2022 16:00:21 +0100 Subject: [PATCH] (Fonts) Cleanups --- gfx/drivers_font/caca_font.c | 4 -- gfx/drivers_font/ctr_font.c | 2 - gfx/drivers_font/d3d10_font.c | 2 - gfx/drivers_font/d3d11_font.c | 2 - gfx/drivers_font/d3d12_font.c | 2 - gfx/drivers_font/gdi_font.c | 4 -- gfx/drivers_font/gl1_raster_font.c | 1 - gfx/drivers_font/gl2_raster_font.c | 1 - gfx/drivers_font/gl3_raster_font.c | 2 - gfx/drivers_font/metal_raster_font.m | 76 ++++++++++++--------------- gfx/drivers_font/ps2_font.c | 2 - gfx/drivers_font/rsx_font.c | 2 - gfx/drivers_font/sixel_font.c | 4 -- gfx/drivers_font/switch_font.c | 2 - gfx/drivers_font/vga_font.c | 4 -- gfx/drivers_font/vita2d_font.c | 2 - gfx/drivers_font/vulkan_raster_font.c | 1 - gfx/drivers_font/wiiu_font.c | 2 - 18 files changed, 33 insertions(+), 82 deletions(-) diff --git a/gfx/drivers_font/caca_font.c b/gfx/drivers_font/caca_font.c index b800a9bd96..95b4284b42 100644 --- a/gfx/drivers_font/caca_font.c +++ b/gfx/drivers_font/caca_font.c @@ -27,7 +27,6 @@ #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" typedef struct { @@ -50,10 +49,7 @@ static void *caca_font_init(void *data, if (!font_renderer_create_default( &font->font_driver, &font->font_data, font_path, font_size)) - { - RARCH_WARN("Couldn't initialize font renderer.\n"); return NULL; - } return font; } diff --git a/gfx/drivers_font/ctr_font.c b/gfx/drivers_font/ctr_font.c index 722bb1f675..e4c7dd6fc4 100644 --- a/gfx/drivers_font/ctr_font.c +++ b/gfx/drivers_font/ctr_font.c @@ -29,7 +29,6 @@ #include "../../ctr/gpu_old.h" #include "../../configuration.h" -#include "../../verbosity.h" typedef struct { @@ -58,7 +57,6 @@ static void* ctr_font_init(void* data, const char* font_path, &font->font_driver, &font->font_data, font_path, font_size)) { - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } diff --git a/gfx/drivers_font/d3d10_font.c b/gfx/drivers_font/d3d10_font.c index 9c849b5dc3..dbbb216069 100644 --- a/gfx/drivers_font/d3d10_font.c +++ b/gfx/drivers_font/d3d10_font.c @@ -25,7 +25,6 @@ #include "../common/d3d10_common.h" #include "../../configuration.h" -#include "../../verbosity.h" typedef struct { @@ -47,7 +46,6 @@ static void *d3d10_font_init(void* data, const char* font_path, if (!font_renderer_create_default( &font->font_driver, &font->font_data, font_path, font_size)) { - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } diff --git a/gfx/drivers_font/d3d11_font.c b/gfx/drivers_font/d3d11_font.c index 5613d960ff..95466501ba 100644 --- a/gfx/drivers_font/d3d11_font.c +++ b/gfx/drivers_font/d3d11_font.c @@ -24,7 +24,6 @@ #include "../common/d3d11_common.h" #include "../../configuration.h" -#include "../../verbosity.h" typedef struct { @@ -46,7 +45,6 @@ static void * d3d11_font_init(void* data, const char* font_path, if (!font_renderer_create_default( &font->font_driver, &font->font_data, font_path, font_size)) { - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } diff --git a/gfx/drivers_font/d3d12_font.c b/gfx/drivers_font/d3d12_font.c index 931b40b57e..4df205d0a2 100644 --- a/gfx/drivers_font/d3d12_font.c +++ b/gfx/drivers_font/d3d12_font.c @@ -24,7 +24,6 @@ #include "../common/d3d12_common.h" #include "../../configuration.h" -#include "../../verbosity.h" typedef struct { @@ -47,7 +46,6 @@ static void * d3d12_font_init(void* data, const char* font_path, &font->font_driver, &font->font_data, font_path, font_size)) { - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } diff --git a/gfx/drivers_font/gdi_font.c b/gfx/drivers_font/gdi_font.c index bc25cd7494..62c4b8455b 100644 --- a/gfx/drivers_font/gdi_font.c +++ b/gfx/drivers_font/gdi_font.c @@ -33,7 +33,6 @@ #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" typedef struct { @@ -56,10 +55,7 @@ static void *gdi_font_init(void *data, if (!font_renderer_create_default( &font->font_driver, &font->font_data, font_path, font_size)) - { - RARCH_WARN("Couldn't initialize font renderer.\n"); return NULL; - } return font; } diff --git a/gfx/drivers_font/gl1_raster_font.c b/gfx/drivers_font/gl1_raster_font.c index 8ecad6c4e6..b3feb291fd 100644 --- a/gfx/drivers_font/gl1_raster_font.c +++ b/gfx/drivers_font/gl1_raster_font.c @@ -24,7 +24,6 @@ #include "../common/gl1_common.h" #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" /* TODO: Move viewport side effects to the caller: it's a source of bugs. */ diff --git a/gfx/drivers_font/gl2_raster_font.c b/gfx/drivers_font/gl2_raster_font.c index 8a54b6ea3e..66ee707041 100644 --- a/gfx/drivers_font/gl2_raster_font.c +++ b/gfx/drivers_font/gl2_raster_font.c @@ -24,7 +24,6 @@ #include "../common/gl2_common.h" #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" /* TODO: Move viewport side effects to the caller: it's a source of bugs. */ diff --git a/gfx/drivers_font/gl3_raster_font.c b/gfx/drivers_font/gl3_raster_font.c index aa8dc6e263..8dcc1f9bb0 100644 --- a/gfx/drivers_font/gl3_raster_font.c +++ b/gfx/drivers_font/gl3_raster_font.c @@ -24,7 +24,6 @@ #include "../common/gl3_common.h" #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" /* TODO: Move viewport side effects to the caller: it's a source of bugs. */ @@ -111,7 +110,6 @@ static void *gl3_raster_font_init(void *data, &font->font_driver, &font->font_data, font_path, font_size)) { - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } diff --git a/gfx/drivers_font/metal_raster_font.m b/gfx/drivers_font/metal_raster_font.m index dcaf5d3a89..b89456615c 100644 --- a/gfx/drivers_font/metal_raster_font.m +++ b/gfx/drivers_font/metal_raster_font.m @@ -23,7 +23,6 @@ #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" @interface MetalRaster : NSObject { @@ -72,18 +71,15 @@ if (driver == nil) return nil; - _driver = driver; + _driver = driver; _context = driver.context; if (!font_renderer_create_default( &_font_driver, &_font_data, font_path, font_size)) - { - RARCH_WARN("Couldn't initialize font renderer.\n"); return nil; - } _uniforms.projectionMatrix = matrix_proj_ortho(0, 1, 0, 1); - _atlas = _font_driver->get_atlas(_font_data); + _atlas = _font_driver->get_atlas(_font_data); _stride = MTL_ALIGN_BUFFER(_atlas->width); if (_stride == _atlas->width) { @@ -102,7 +98,7 @@ else { int i; - _buffer = [_context.device newBufferWithLength:(NSUInteger)(_stride * _atlas->height) + _buffer = [_context.device newBufferWithLength:(NSUInteger)(_stride * _atlas->height) options:PLATFORM_METAL_RESOURCE_STORAGE_MODE]; void *dst = _buffer.contents; void *src = _atlas->buffer; @@ -122,15 +118,13 @@ height:_atlas->height mipmapped:NO]; - _texture = [_buffer newTextureWithDescriptor:td offset:0 bytesPerRow:_stride]; + _texture = [_buffer newTextureWithDescriptor:td offset:0 bytesPerRow:_stride]; _capacity = 12000; - _vert = [_context.device newBufferWithLength:sizeof(SpriteVertex) * + _vert = [_context.device newBufferWithLength:sizeof(SpriteVertex) * _capacity options:PLATFORM_METAL_RESOURCE_STORAGE_MODE]; if (![self _initializeState]) - { return nil; - } } return self; } @@ -138,46 +132,44 @@ - (bool)_initializeState { { - MTLVertexDescriptor *vd = [MTLVertexDescriptor new]; - vd.attributes[0].offset = 0; - vd.attributes[0].format = MTLVertexFormatFloat2; - vd.attributes[1].offset = offsetof(SpriteVertex, texCoord); - vd.attributes[1].format = MTLVertexFormatFloat2; - vd.attributes[2].offset = offsetof(SpriteVertex, color); - vd.attributes[2].format = MTLVertexFormatFloat4; - vd.layouts[0].stride = sizeof(SpriteVertex); + NSError *err; + MTLVertexDescriptor *vd = [MTLVertexDescriptor new]; + + vd.attributes[0].offset = 0; + vd.attributes[0].format = MTLVertexFormatFloat2; + vd.attributes[1].offset = offsetof(SpriteVertex, texCoord); + vd.attributes[1].format = MTLVertexFormatFloat2; + vd.attributes[2].offset = offsetof(SpriteVertex, color); + vd.attributes[2].format = MTLVertexFormatFloat4; + vd.layouts[0].stride = sizeof(SpriteVertex); vd.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex; MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new]; psd.label = @"font pipeline"; MTLRenderPipelineColorAttachmentDescriptor *ca = psd.colorAttachments[0]; - ca.pixelFormat = MTLPixelFormatBGRA8Unorm; - ca.blendingEnabled = YES; - ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha; - ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha; + ca.pixelFormat = MTLPixelFormatBGRA8Unorm; + ca.blendingEnabled = YES; + ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha; + ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha; ca.destinationAlphaBlendFactor = MTLBlendFactorOneMinusSourceAlpha; - ca.destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha; + ca.destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha; - psd.sampleCount = 1; - psd.vertexDescriptor = vd; - psd.vertexFunction = [_context.library newFunctionWithName:@"sprite_vertex"]; - psd.fragmentFunction = [_context.library newFunctionWithName:@"sprite_fragment_a8"]; + psd.sampleCount = 1; + psd.vertexDescriptor = vd; + psd.vertexFunction = [_context.library newFunctionWithName:@"sprite_vertex"]; + psd.fragmentFunction = [_context.library newFunctionWithName:@"sprite_fragment_a8"]; - NSError *err; - _state = [_context.device newRenderPipelineStateWithDescriptor:psd error:&err]; + _state = [_context.device newRenderPipelineStateWithDescriptor:psd error:&err]; if (err != nil) - { - RARCH_ERR("[MetalRaster]: error creating pipeline state: %s\n", err.localizedDescription.UTF8String); return NO; - } } { MTLSamplerDescriptor *sd = [MTLSamplerDescriptor new]; - sd.minFilter = MTLSamplerMinMagFilterLinear; - sd.magFilter = MTLSamplerMinMagFilterLinear; - _sampler = [_context.device newSamplerStateWithDescriptor:sd]; + sd.minFilter = MTLSamplerMinMagFilterLinear; + sd.magFilter = MTLSamplerMinMagFilterLinear; + _sampler = [_context.device newSamplerStateWithDescriptor:sd]; } return YES; } @@ -196,7 +188,7 @@ #if !defined(HAVE_COCOATOUCH) NSUInteger offset = glyph->atlas_offset_y; - NSUInteger len = glyph->height * _stride; + NSUInteger len = glyph->height * _stride; [_buffer didModifyRange:NSMakeRange(offset, len)]; #endif @@ -206,10 +198,11 @@ - (int)getWidthForMessage:(const char *)msg length:(NSUInteger)length scale:(float)scale { + NSUInteger i; int delta_x = 0; const struct font_glyph* glyph_q = _font_driver->get_glyph(_font_data, '?'); - for (NSUInteger i = 0; i < length; i++) + for (i = 0; i < length; i++) { const struct font_glyph *glyph; /* Do something smarter here ... */ @@ -231,10 +224,7 @@ const struct font_glyph *glyph = _font_driver->get_glyph((void *)_font_driver, code); if (glyph) - { [self updateGlyph:glyph]; - } - return glyph; } @@ -377,8 +367,8 @@ static INLINE void write_quad6(SpriteVertex *pv, struct font_line_metrics *line_metrics = NULL; /* If font line metrics are not supported just draw as usual */ - if (!_font_driver->get_line_metrics || - !_font_driver->get_line_metrics(_font_data, &line_metrics)) + if ( !_font_driver->get_line_metrics + || !_font_driver->get_line_metrics(_font_data, &line_metrics)) { [self _renderLine:msg length:strlen(msg) scale:scale color:color posX:posX posY:posY aligned:aligned]; return; diff --git a/gfx/drivers_font/ps2_font.c b/gfx/drivers_font/ps2_font.c index bd30edc5d2..64d8f5069d 100644 --- a/gfx/drivers_font/ps2_font.c +++ b/gfx/drivers_font/ps2_font.c @@ -27,7 +27,6 @@ #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" typedef struct { @@ -53,7 +52,6 @@ static void* ps2_font_init(void* data, const char* font_path, &font->font_driver, &font->font_data, font_path, font_size)) { - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } diff --git a/gfx/drivers_font/rsx_font.c b/gfx/drivers_font/rsx_font.c index e7f3fab46a..b299773c03 100644 --- a/gfx/drivers_font/rsx_font.c +++ b/gfx/drivers_font/rsx_font.c @@ -25,7 +25,6 @@ #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" #define RSX_FONT_EMIT(c, vx, vy) \ font_vertex[ 2 * (6 * i + c) + 0] = (x + (delta_x + off_x + vx * width) * scale) * inv_win_width; \ @@ -147,7 +146,6 @@ static void *rsx_font_init(void *data, &font->font_driver, &font->font_data, font_path, font_size)) { - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } diff --git a/gfx/drivers_font/sixel_font.c b/gfx/drivers_font/sixel_font.c index 8ed902e80c..73ea58a204 100644 --- a/gfx/drivers_font/sixel_font.c +++ b/gfx/drivers_font/sixel_font.c @@ -25,7 +25,6 @@ #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" #include "../common/sixel_common.h" typedef struct @@ -49,10 +48,7 @@ static void *sixel_font_init(void *data, if (!font_renderer_create_default( &font->font_driver, &font->font_data, font_path, font_size)) - { - RARCH_WARN("Couldn't initialize font renderer.\n"); return NULL; - } return font; } diff --git a/gfx/drivers_font/switch_font.c b/gfx/drivers_font/switch_font.c index 3c1187d2a0..8183b2173b 100644 --- a/gfx/drivers_font/switch_font.c +++ b/gfx/drivers_font/switch_font.c @@ -26,7 +26,6 @@ #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" #include "../common/switch_common.h" @@ -51,7 +50,6 @@ static void *switch_font_init(void *data, const char *font_path, if (!font_renderer_create_default(&font->font_driver, &font->font_data, font_path, font_size)) { - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } diff --git a/gfx/drivers_font/vga_font.c b/gfx/drivers_font/vga_font.c index e6e2699fdb..b12577d0d1 100644 --- a/gfx/drivers_font/vga_font.c +++ b/gfx/drivers_font/vga_font.c @@ -24,7 +24,6 @@ #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" #include "../common/vga_common.h" typedef struct @@ -50,10 +49,7 @@ static void *vga_font_init(void *data, if (!font_renderer_create_default( &font->font_driver, &font->font_data, font_path, font_size)) - { - RARCH_WARN("Couldn't initialize font renderer.\n"); return NULL; - } return font; } diff --git a/gfx/drivers_font/vita2d_font.c b/gfx/drivers_font/vita2d_font.c index 25dddb0dcb..9a17804b5e 100644 --- a/gfx/drivers_font/vita2d_font.c +++ b/gfx/drivers_font/vita2d_font.c @@ -23,7 +23,6 @@ #include "../font_driver.h" #include "../../configuration.h" -#include "../../verbosity.h" typedef struct { @@ -86,7 +85,6 @@ static void *vita2d_font_init(void *data, return font; error: - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } diff --git a/gfx/drivers_font/vulkan_raster_font.c b/gfx/drivers_font/vulkan_raster_font.c index b17d8c08af..9fdba9ce45 100644 --- a/gfx/drivers_font/vulkan_raster_font.c +++ b/gfx/drivers_font/vulkan_raster_font.c @@ -85,7 +85,6 @@ static void *vulkan_font_init(void *data, &font->font_driver, &font->font_data, font_path, font_size)) { - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } diff --git a/gfx/drivers_font/wiiu_font.c b/gfx/drivers_font/wiiu_font.c index 48e57abb63..3606f4a237 100644 --- a/gfx/drivers_font/wiiu_font.c +++ b/gfx/drivers_font/wiiu_font.c @@ -27,7 +27,6 @@ #include "../../wiiu/wiiu_dbg.h" #include "../../configuration.h" -#include "../../verbosity.h" typedef struct { @@ -51,7 +50,6 @@ static void* wiiu_font_init(void* data, const char* font_path, &font->font_driver, &font->font_data, font_path, font_size)) { - RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; }