Skip to content

macOS: (in window example) redundant redraw request during resizing #4517

Description

@Random-Scientist

Description

First off, you can observe this bug in the window example, but it probably applies to any consumer that requests a redraw on SurfaceResized. I noticed it while working on a different PR.
I think this might be because our drawRect override sends a redraw request every time the window bounds change, but so does the application after receiving WindowEvent::SurfaceResized. or AppKit just calls drawRect twice for some reason.

macOS version

ProductName:    macOS
ProductVersion: 12.7.6
BuildVersion:   21H1320

Winit version

master (0b6b794)

Activity

  1. madsmtm commented on Mar 17, 2026

    @madsmtm
    Member

    Yup, I've recently found this too in rust-windowing/softbuffer#343 (comment).

    I'm still unsure of the right way to fix it - possibly drawRect: should just call window.request_redraw(), and not try to handle the redraw directly? I can't quite remember why we even try to, possibly to make resizing work more smoothly.

  2. Random-Scientist commented on Mar 17, 2026

    @Random-Scientist
    ContributorAuthor

    Question is whether there is ever a case where we need to respect drawRect, to which I think the answer is no because all of the rendering is driven through the user anyways e.g. by SurfaceResized or the previous turn of a redraw loop

  3. madsmtm commented on Mar 17, 2026

    @madsmtm
    Member

    See also #2640.

    I think I was originally motivated by #1605 that drawRect: + setNeedsDisplay was the right approach. I'm less convinced of this nowadays, I think there's a bunch of overhead from drawRect: that we'd rather avoid if we could (e.g. by setting wantsUpdateLayer instead).

    Ideally, I tend to think we should have like 3 different rendering modes that the user must choose between somehow:

    • Render on each frame, we schedule this using CADisplayLink (this is the only way to get 90 fps with ProMotion IIUC, drawRect: can't give you that).
    • Render only when request_redraw is called. Unsure when the best time to call this is? Definitely before about_to_wait (because stuff is sent to the compositor just before the end of the runloop (this is what causes Must call request_redraw in about_to_wait #4501)).
    • Render using drawRect: (to properly support drawing with CGContext).

    (Scattered thoughts, been a while since I looked into this).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B - bugDang, that shouldn't have happenedDS - appkitAffects the AppKit/macOS backend

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions