Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTK: make OSD scalable #769

Merged
merged 9 commits into from
Feb 14, 2024
13 changes: 2 additions & 11 deletions desmume/src/frontend/modules/osd/agg/aggdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ static void Agg_init_fonts()

AggDraw_Desmume aggDraw;

#if defined(WIN32) || defined(HOST_LINUX)
T_AGG_RGBA agg_targetScreen(0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 1024);
#else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this now read 256*aggDraw.screenBytesPerPixel instead of 1024 ?

oh, actually if bpp == 2, it should return T_AGG_RGB555 instead of T_AGG_RGBA

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The problem is it's not a function, it's global object. Made a cheap workaround. Ideally this object should be allocated dynamically, but it can severely break other frontends.

T_AGG_RGB555 agg_targetScreen(0, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 512);
#endif

static std::vector<u32> luaBuffer(GPU_FRAMEBUFFER_NATIVE_WIDTH*GPU_FRAMEBUFFER_NATIVE_HEIGHT*2);
T_AGG_RGBA agg_targetLua((u8*)luaBuffer.data(), GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT*2, 1024);
Expand All @@ -139,6 +135,7 @@ static AggDrawTarget* targets[] = {
void Agg_init()
{
Agg_init_fonts();
aggDraw.screenBytesPerPixel = 4;
aggDraw.screen = targets[0];
aggDraw.hud = targets[1];
aggDraw.lua = targets[2];
Expand Down Expand Up @@ -167,13 +164,7 @@ void Agg_setCustomSize(int w, int h)
hudBuffer.resize(w*h);
luaBuffer.resize(w*h);
if(aggDraw.screen)
{
#if defined(WIN32) || defined(HOST_LINUX)
aggDraw.screen->setDrawTargetDims(0, w, h, w*4);
#else
aggDraw.screen->setDrawTargetDims(0, w, h, w*2);
#endif
}
aggDraw.screen->setDrawTargetDims(0, w, h, w*aggDraw.screenBytesPerPixel);
if(aggDraw.hud)
aggDraw.hud->setDrawTargetDims((u8*)hudBuffer.data(), w, h, w*4);
if(aggDraw.lua)
Expand Down
1 change: 1 addition & 0 deletions desmume/src/frontend/modules/osd/agg/aggdraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ class AggDraw_Desmume : public AggDraw
//void composite(void* dest);

AggDrawTarget *screen, *hud, *lua;
int screenBytesPerPixel;
};

extern AggDraw_Desmume aggDraw;
Expand Down
11 changes: 6 additions & 5 deletions desmume/src/frontend/posix/gtk/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <SDL.h>
#include <X11/Xlib.h>
#include <vector>
#ifdef HAVE_LIBAGG
#ifdef AGG2D_USE_VECTORFONTS
#include <fontconfig/fontconfig.h>
#endif

Expand Down Expand Up @@ -130,10 +130,8 @@ enum {
SUB_OBJ
};

#ifdef HAVE_LIBAGG
#ifdef AGG2D_USE_VECTORFONTS
#define VECTOR_FONT_BASE_SIZE 16
#endif

static FcConfig* fontConfig;
static std::string vectorFontFile;
Expand Down Expand Up @@ -3167,6 +3165,9 @@ common_gtk_main(GApplication *app, gpointer user_data)
else
osd->useVectorFonts=false;
#endif
SDL_DisplayMode cur_mode;
if(!SDL_GetCurrentDisplayMode(0, &cur_mode))
aggDraw.screenBytesPerPixel = SDL_BYTESPERPIXEL(cur_mode.format);
Agg_setCustomSize(real_framebuffer_width, real_framebuffer_height*2);
osd->scale=gpu_scale_factor;
HudLoadLayout();
Expand Down Expand Up @@ -3750,7 +3751,7 @@ handle_open(GApplication *application,
common_gtk_main(application, user_data);
}

#ifdef HAVE_LIBAGG
#ifdef AGG2D_USE_VECTORFONTS

static std::string FindFontFile(const char* fontName, bool bold)
{
Expand Down Expand Up @@ -3784,7 +3785,7 @@ int main (int argc, char *argv[])
{
configured_features my_config;

#ifdef HAVE_LIBAGG
#ifdef AGG2D_USE_VECTORFONTS
fontConfig = FcInitLoadConfigAndFonts();
vectorFontFile = FindFontFile("mono", true);
if(!vectorFontFile.size())
Expand Down
5 changes: 0 additions & 5 deletions desmume/src/frontend/posix/gtk/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ dep_x11 = dependency('x11')

gtk_dependencies = dependencies + [dep_gtk3, dep_x11]

if dep_agg.found()
dep_fontconfig = dependency('fontconfig')
gtk_dependencies = gtk_dependencies + [dep_fontconfig]
endif

gnome = import('gnome')

gresource = gnome.compile_resources(
Expand Down
6 changes: 3 additions & 3 deletions desmume/src/frontend/posix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ project('desmume',
license: 'GPL2+',
)

add_global_arguments('-DHOST_LINUX', language: ['c', 'cpp'])

dep_glib2 = dependency('glib-2.0')
dep_sdl = dependency('sdl2')
dep_pcap = dependency('pcap')
Expand All @@ -22,6 +20,7 @@ dep_openal = dependency('openal', required: get_option('openal'))
dep_alsa = dependency('alsa', required: false)
dep_soundtouch = dependency('soundtouch', required: false)
dep_agg = dependency('libagg', required: false)
dep_fontconfig = dependency('fontconfig', required: false)

# XXX: something wrong with this one.
#dep_lua = dependency('lua-5.1', required: false)
Expand Down Expand Up @@ -205,7 +204,8 @@ endif
if dep_agg.found()
dependencies += dep_agg
add_global_arguments('-DHAVE_LIBAGG', language: ['c', 'cpp'])
if get_option('frontend-gtk')
if dep_fontconfig.found()
dependencies += dep_fontconfig
add_global_arguments('-DAGG2D_USE_VECTORFONTS', language: ['c', 'cpp'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you add this unconditionally, so i wonder if it still compiles if not set. also how does it look like if not set ?

Copy link
Contributor Author

@thesourcehim thesourcehim Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to add meson option to use vector fonts then? On the other hand compiling without this define causes HUD to use only default raster font (as before) which exactly same thing that happens if application fails to locate vector font (monospace or sans) in the system. So maybe this define/check is not needed anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd enable it unconditionally if fontconfig lib is found

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd enable it unconditionally if fontconfig lib is found

Done

add_global_link_arguments('-laggfontfreetype', language: ['c', 'cpp'])
endif
Expand Down
Loading