Skip to content

sokol_app/gfx.h: better deal with fully obscured window / no swapchain-drawable available. #1446

@floooh

Description

@floooh

Two things:

  • sokol_app.h should provide a function sapp_visible() which returns true if at least part of the window is currently visible, idea being that the frame callback may decide to skip certain things when the window is fully obscured or minified. This is an 'optional' feature, some platforms may always return true. It should be legal to skip the entire frame when sapp_visible() returns false, most importantly the application isn't required to call sg_commit() (but only when it didn't call any other sokol-gfx functions except maybe creating and destroying resources):

    void frame(void) {
        if (!sapp_visible()) {
            return;
        }
        // ... regular frame code
        sg_commit();
    }
  • sokol_gfx.h: sg_swapchain should get an .invalid boolean. When this is true all rendering in the pass should be silently skipped. This is for situations where the swapchain system cannot provide a valid drawable for the current frame.

After this is implemented:

  • in sokol_app.h macos+metal:
    • don't call nextDrawable when window is obscured or minified (e.g. when the CADisplayLink is deactivated)
    • sapp_visible() returns false when window is obscured or minifed (e.g. when CADisplayLink is deactivated)
    • reduce the 'obscured frame rate' from 60Hz to smth like 10Hz
  • in the Vulkan backend: implement the error code path for vkAcquireNextImage failure (this should set sg_swapchain.invalid to true so that the next render frame is skipped)
  • in chips-test: fully deactivate the emulator when sapp_visible() returns false (e.g. skip the entire frame callback)
  • ...?

Metadata

Metadata

Assignees

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions