Previous r1170 SDL_GetWindowSizeInPixels()

Started by pomosapien, September 17, 2022, 05:51:59 AM

Previous topic - Next topic

pomosapien

Hi @andreas_g , I synced softfloat to build on macOS, this call doesn't resolve and I don't see it in the SDL doc.  New code from Hatari?

Replaced that region to see what different dimension get calls provide.


    //SDL_GetWindowSizeInPixels(sdlWindow, &nWindowWidth, &nWindowHeight);
    // TODO where does the above call come from? Is it really from SDL?

    SDL_GetWindowSize(sdlWindow, &nWindowWidth, &nWindowHeight);

    int outputWidth, outputHeight;
    int drawableWidth, drawableHeight;
    SDL_GetRendererOutputSize(sdlRenderer, &outputWidth, &outputHeight);
    SDL_GL_GetDrawableSize(sdlWindow, &drawableWidth, &drawableHeight);

    fprintf(stderr, "%d %d %d %d %d %d %d %d\n",
        width, height,
        nWindowWidth, nWindowHeight,
        outputWidth, outputHeight,
        drawableWidth, drawableHeight
    );

    if (nWindowWidth > 0) {
        // dpiFactor = (float)width / nWindowWidth;
        dpiFactor = (float)width / drawableWidth;
        fprintf(stderr,"SDL screen scale: %.3f\n", dpiFactor);
    } else {
        fprintf(stderr,"Failed to set screen scale\n");
        dpiFactor = 1.0;
    }


Some output:


ray@metal build % src/Previous.app/Contents/MacOS/Previous
SDL screen request: 1120 x 856 (windowed)
1120 856 1120 856 70097780 1 2240 1712
SDL screen scale: 0.500
Init680x0() called
68040 MMU: TC=0000 enabled=0 page8k=0 PC=00000000
CPU cycleunit: 256 (0.500)
1872 CPU functions


So here SDL_GL_GetDrawableSize() is useful.  I am set for "Default Scaling" and might try what different user settings give...

pomosapien

Only height varies between scaling settings, probably because of cutoff.

ray@metal build % src/Previous.app/Contents/MacOS/Previous
SDL screen request: 1120 x 856 (windowed)
1120 856 1120 856 70097780 1 2240 1712
SDL screen scale: 0.500
Init680x0() called
68040 MMU: TC=0000 enabled=0 page8k=0 PC=00000000
CPU cycleunit: 256 (0.500)
1872 CPU functions
[Sound] Initializing output device (resume).
[Sound] Uninitializing output device (pause).
[Sound] Initializing output device (resume).
ray@metal build %
ray@metal build % src/Previous.app/Contents/MacOS/Previous
SDL screen request: 1120 x 856 (windowed)
1120 856 1120 856 45538164 1 2240 1712
SDL screen scale: 0.500
Init680x0() called
68040 MMU: TC=0000 enabled=0 page8k=0 PC=00000000
CPU cycleunit: 256 (0.500)
1872 CPU functions
[Sound] Initializing output device (resume).
[Sound] Uninitializing output device (pause).
[Sound] Initializing output device (resume).
ray@metal build % src/Previous.app/Contents/MacOS/Previous
SDL screen request: 1120 x 856 (windowed)
1120 856 1120 815 81959796 1 2240 1630
SDL screen scale: 0.500
Init680x0() called
68040 MMU: TC=0000 enabled=0 page8k=0 PC=00000000
CPU cycleunit: 256 (0.500)
1872 CPU functions
[Sound] Initializing output device (resume).
[Sound] Uninitializing output device (pause).
[Sound] Initializing output device (resume).


This might be fine!  The user settings might be a transform post-GL to the physical display and we might not care about that here even though we generally care about hiDPI.
Stranger things probably happen in GTK/GNOME etc.

andreas_g

SDL_GetWindowSizeInPixels() will be available in SDL2 v2.26.0. You can either use the last release version of Previous (trunk), use the latest development version of SDL2 or replace the function with SDL_GetRendererOutputSize() and move it after renderer initialization.

The next release version of Previous will require SDL v2.26.0.