All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Akihiko Odaki <akihiko.odaki@gmail.com>
Cc: qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [PATCH] ui/cocoa: Set UI information
Date: Fri, 4 Feb 2022 16:19:47 +0000	[thread overview]
Message-ID: <CAFEAcA8LFt5NpsVTE1dYpA3rW0RsjS1Nf9Q3iS307kaHjVS=1g@mail.gmail.com> (raw)
In-Reply-To: <20210616141910.54188-1-akihiko.odaki@gmail.com>

On Wed, 16 Jun 2021 at 15:19, Akihiko Odaki <akihiko.odaki@gmail.com> wrote:
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
> ---
>  ui/cocoa.m | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)

Hi; I was looking at the cocoa.m code to see about maybe deleting the
unnecessary autorelease pools, and I ran into some code I was a bit
unsure about that was added in this patch.

In particular I'm wondering about the interactions across threads here.

> +- (void) updateUIInfo
> +{
> +    NSSize frameSize;
> +    QemuUIInfo info;
> +
> +    if (!qemu_console_is_graphic(dcl.con)) {
> +        return;
> +    }
> +
> +    if ([self window]) {
> +        NSDictionary *description = [[[self window] screen] deviceDescription];
> +        CGDirectDisplayID display = [[description objectForKey:@"NSScreenNumber"] unsignedIntValue];
> +        NSSize screenSize = [[[self window] screen] frame].size;
> +        CGSize screenPhysicalSize = CGDisplayScreenSize(display);
> +
> +        frameSize = isFullscreen ? screenSize : [self frame].size;
> +        info.width_mm = frameSize.width / screenSize.width * screenPhysicalSize.width;
> +        info.height_mm = frameSize.height / screenSize.height * screenPhysicalSize.height;
> +    } else {
> +        frameSize = [self frame].size;
> +        info.width_mm = 0;
> +        info.height_mm = 0;
> +    }
> +
> +    info.xoff = 0;
> +    info.yoff = 0;
> +    info.width = frameSize.width;
> +    info.height = frameSize.height;
> +
> +    dpy_set_ui_info(dcl.con, &info);

This function makes some cocoa calls, and it also calls a QEMU
UI layer function, dpy_set_ui_info().

> +- (void)windowDidChangeScreen:(NSNotification *)notification
> +{
> +    [cocoaView updateUIInfo];

We call it from the cocoa UI thread in callbacks like this.

>  /* Called when the user clicks on a window's close button */
>  - (BOOL)windowShouldClose:(id)sender
>  {
> @@ -1936,6 +1983,8 @@ static void cocoa_switch(DisplayChangeListener *dcl,
>
>      COCOA_DEBUG("qemu_cocoa: cocoa_switch\n");
>
> +    [cocoaView updateUIInfo];

We also call it from the QEMU thread, when the QEMU thread calls
this cocoa_switch callback function.

(1) A question for Akihiko:
Are all the cocoa calls we make in updateUIInfo safe to
make from a non-UI thread? Would it be preferable for this
call in cocoa_switch() to be moved inside the dispatch_async block?
(Moving it would mean that I wouldn't have to think about whether
any of the code in it needs to have an autorelease pool :-))

(2) A question for Gerd:
Is it safe to call dpy_set_ui_info() from a non-QEMU-main-thread?
It doesn't appear to do any locking that would protect against
multiple threads calling it simultaneously.

thanks
-- PMM


  parent reply	other threads:[~2022-02-04 16:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16 14:19 [PATCH] ui/cocoa: Set UI information Akihiko Odaki
2021-06-23 12:43 ` Gerd Hoffmann
2022-02-04 16:19 ` Peter Maydell [this message]
2022-02-05  2:06   ` Akihiko Odaki
2022-02-08 18:07     ` Peter Maydell
2022-02-09 11:32       ` Akihiko Odaki
2022-02-14 10:27   ` Gerd Hoffmann
2022-02-14 10:43     ` Peter Maydell
2022-02-14 11:51       ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFEAcA8LFt5NpsVTE1dYpA3rW0RsjS1Nf9Q3iS307kaHjVS=1g@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=akihiko.odaki@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.