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
Merged

GTK: make OSD scalable #769

merged 9 commits into from
Feb 14, 2024

Conversation

thesourcehim
Copy link
Contributor

My previous PR (implement GPU scale factor for GTK) created a problem with OSD: it is drawn without scaling, so when scale factor is > 1, OSD becomes small. I implemented OSD scaling. Scaling most elements like rectangles and ellipses seems trivial, but I could not figure out how to scale raster fonts. So instead I used vector fonts. Most of the code to work with vector fonts was already in AGG OSD files, I only added some missing functions and made using vector fonts optional via flag. By default vector fonts are disabled to keep other frontends working as before. It is frontend's job to provide a font file and set this flag. In GTK frontend I use fontconfig to locate monospace font file in the system. Also for vector fonts I could not figure out how to set background, so I made outlines instead.

Things to do:
Properly save OSD layout upon editing, restore on start.

Screenshot with OSD rendered at 4x:
scaled_osd_screenshot

@rofl0r
Copy link
Collaborator

rofl0r commented Feb 1, 2024

nice work, though the amount of changes is rather excessive, wouldn't it be possible (and much easier, even preserving the ability to use pixel fonts) to just make the OSD code render to a transparent SDL_Texture or equivalent at 1x, and then just make SDL2 blit it using its own scaler over the renderer texture ?

@thesourcehim
Copy link
Contributor Author

nice work, though the amount of changes is rather excessive, wouldn't it be possible (and much easier, even preserving the ability to use pixel fonts) to just make the OSD code render to a transparent SDL_Texture or equivalent at 1x, and then just make SDL2 blit it using its own scaler over the renderer texture ?

I can try that, but I suspect the result will be the same as just settings scale to 1 and scaling entire image to window: HUD becomes blurry, while this scaling draws nice pad and other elements. But maybe I should use raster fonts when not scaling - they look nicer on low resolution.

vector font size close to raster one, make OSDCLASS::scale floating point
@thesourcehim
Copy link
Contributor Author

I added saving and loading layout. Also played around with fonts some more: definitely prefer raster font on native resolution - looks much nicer, and choose vector font size close to raster one for consistency.

Screenshot with latest modifications (4x rendering)
Screenshot_20240202_185337

@thesourcehim thesourcehim changed the title [WIP] GTK: make OSD scalable GTK: make OSD scalable Feb 3, 2024
@thesourcehim
Copy link
Contributor Author

I think I finished this one, but I recommend someone else to test it under linux to make sure fonts load properly, though I used two very common ones, so there should not be any problem.

#if defined(WIN32) || defined(HOST_LINUX)
aggDraw.screen->setDrawTargetDims(0, w, h, w*4);
#else
aggDraw.screen->setDrawTargetDims(0, w, h, w*2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the difference between linux/win and everything else here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See also line 121, was not added by me, I only mimiced this in Agg_setCustomSize. If neither WIN32 nor HOST_LINUX is defined than screen buffer is for some reason assumed to be 16bit, which causes HUD to be drawn incorrectly. I don't know what original author ment by this, for which device. May be it's better to use define to specify buffer bitness instead of checking for some platforms?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sounds reasonable. we can store byteperpixel used to initialize SDL2, and use it for math rather than hardcoding numbers nobody knows what they mean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added bytes per pixel detection, defaults to 4 (at start and in case SDL call fails for some reason).

@@ -10,6 +10,8 @@ project('desmume',
license: 'GPL2+',
)

add_global_arguments('-DHOST_LINUX', 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.

is it wise to set this for everyone using meson / gtk3 version ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can be removed if screen buffer bitness is set by other means that checking for platform, see above comment.

@@ -203,6 +205,10 @@ endif
if dep_agg.found()
dependencies += dep_agg
add_global_arguments('-DHAVE_LIBAGG', language: ['c', 'cpp'])
if get_option('frontend-gtk')
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

AGG2D_USE_VECTORFONTS if fontconfig is found.
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.

@rofl0r rofl0r merged commit 45738be into TASEmulators:master Feb 14, 2024
9 checks passed
getItemFromBlock pushed a commit to getItemFromBlock/AM64DS_DeSmuME that referenced this pull request Feb 28, 2024
* gtk: make OSD scalable

* Scale save slot indicator (oops), make text outlines look smoother, use
larger font when not scaling

* Save and load HUD layout, prefer raster font on low resolution, select
vector font size close to raster one, make OSDCLASS::scale floating point

* Build fix

* Add reset HUD layout action, only require fontconfig if libagg is found.

* Try another font in case we could not locate monospace

* Detect screen bytes per pixel instead of hardcoding it, define
AGG2D_USE_VECTORFONTS if fontconfig is found.

* Different pixel formats are handled by different draw target
implementations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants