Re: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize

2023-12-16 Thread Marek Glogowski
Hi

I think I may have found a small error 
 
> if (opts->u.cocoa.has_zoom_to_fit && opts->u.cocoa.zoom_to_fit) {
+[normalWindow setStyleMask:[normalWindow styleMask] & 
~NSWindowStyleMaskResizable];

it should probably be so, because the window never goes into a good mode 
 [normalWindow setStyleMask:[normalWindow styleMask] | 
NSWindowStyleMaskResizable];
 
and the zoom to fit option will never be checked end enable

  menuItem = [[[NSMenuItem alloc] initWithTitle:@"Zoom To Fit" 
action:@selector(zoomToFit:) keyEquivalent:@""] autorelease];
 [menuItem setState: [normalWindow styleMask] & NSWindowStyleMaskResizable ? 
NSControlStateValueOn : NSControlStateValueOff];


Re: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize

2023-12-13 Thread BALATON Zoltan

On Wed, 13 Dec 2023, Akihiko Odaki wrote:

On 2023/12/13 0:38, Rene Engel wrote:


--- Ursprüngliche Nachricht ---
Von: Akihiko Odaki 
Datum: 11.12.2023 06:39:35
An: Peter Maydell ,  Philippe Mathieu-Daudé 
,  Gerd Hoffmann ,  Marc-André Lureau 


Betreff: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize

Tested-by:


Thanks for testing.



This patch works very well on MacOs Sonoma with the Qemu Cocoa output. 
Thanks


Since you are dealing with the Cocoa output under MacOs, I have a request 
for you. Is it possible to use the Cocoa output with zoom to fit in full 
screen mode like it is possible with the GTK output with "-display 
gtk,zoom-to-fit=on -full-screen"? >
I mainly start Qemu using a start script that immediately puts Qemu into 
full screen.



It should be possible, at least with this patch. Recently, Carwyn Ellis added 
the support for the command line option (commit 5ec0898b0579 ("ui/cocoa: add 
zoom-to-fit display option")) so your script can utilize it.


Looks like commit 5ec0898b0579 missed to update documentation so this 
option does not show up in 
https://www.qemu.org/docs/master/system/invocation.html#hxtool-3

Should this be added to qemu-options.hx?

By the way is there a way to get those options from the command line? 
I've tried this but got an error:


$ qemu-system-ppc -display sdl,help
qemu-system-ppc: -display sdl,help: Help is not available for this option

Regards,
BALATON Zoltan

Re: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize

2023-12-12 Thread Akihiko Odaki

On 2023/12/13 0:38, Rene Engel wrote:


--- Ursprüngliche Nachricht ---
Von: Akihiko Odaki 
Datum: 11.12.2023 06:39:35
An: Peter Maydell ,  Philippe Mathieu-Daudé ,  
Gerd Hoffmann ,  Marc-André Lureau 
Betreff: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize

Tested-by:


Thanks for testing.



This patch works very well on MacOs Sonoma with the Qemu Cocoa output. Thanks

Since you are dealing with the Cocoa output under MacOs, I have a request for you. Is it 
possible to use the Cocoa output with zoom to fit in full screen mode like it is possible 
with the GTK output with "-display gtk,zoom-to-fit=on -full-screen"? >
I mainly start Qemu using a start script that immediately puts Qemu into full 
screen.



It should be possible, at least with this patch. Recently, Carwyn Ellis 
added the support for the command line option (commit 5ec0898b0579 
("ui/cocoa: add zoom-to-fit display option")) so your script can utilize it.


Regards,
Akihiko Odaki



Re: Inconsistent qemu-system-ppc speed on Apple M1 (was: Re: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize)

2023-12-12 Thread BALATON Zoltan

On Tue, 12 Dec 2023, Peter Maydell wrote:

On Tue, 12 Dec 2023 at 18:46, BALATON Zoltan  wrote:


On Tue, 12 Dec 2023, Marek Glogowski wrote:

Additionally, how can I use this message on qemu-devel.
It has a post for people who use Macos or Asahi Linux. Verify random qemu
sessions under Macos .Some are faster others are slow.
The topic is posted on qemu-disc...@nongnu.org (I don't know if developers
look there often)

https://lists.nongnu.org/archive/html/qemu-discuss/2023-12/msg8.html

The program posted there was prepared by one of the maintainers of ppc qemu
machines "BALATON Zoltan".

We are starting to gather as much information as possible for it.
I hope nobody will be offended about this information in this topic. I do
not want to start a topic and litter other lists


It's better to do that in a separate thead, I've changed the subject
accordingly. I only came up with the idea and scripted it but the actual
test case comes from Marek and the original report from Rene Engel.

This problem was first seen running AmigaOS with qemu-system-ppc but then
we also reproduced it with Linux guest with the test in the qemu-discuss
messgage linked above. The runs are not exactly random but there seem to
be slow and fast sessions with the slow one about half the expected speed.
If we get a fast or slow session seems to be random. This was seen on
Apple M1 and Apple M1 Max under macOS but could not reproduce on x86_64
host under Linux or Apple M2 host under Linux so it may either be related
to Apple M1 or macOS host.


Is this possibly related to https://gitlab.com/qemu-project/qemu/-/issues/334
where App Nap is reported as causing QEMU to slow down when the window
doesn't have focus, or does it happen even when the QEMU window has
focus the whole time the benchmark is running ?


Yes, the original test which found it was running Quake timedemo on 
AmgiaOS with QEMU running in foreground and that does a lot of what is 
listed to prevent App Nap such as playing sound and doing graphics. Also 
the sessions are either fast or slow from the start, they don't start fast 
then become slow but sometimes run fast while most of the time they are 
slow and this happens randomly when starting the same command multiple 
times in a row as the scripted test that runs lame to encode mp3 with 
Linux guest does. So this does not seem related to App Nap to me. It did 
not seem to happen on Linux host even on Apple M2 but more testing with 
those might be needed to confirm that.


Regards,
BALATON Zoltan



Re: Inconsistent qemu-system-ppc speed on Apple M1 (was: Re: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize)

2023-12-12 Thread Peter Maydell
On Tue, 12 Dec 2023 at 18:46, BALATON Zoltan  wrote:
>
> On Tue, 12 Dec 2023, Marek Glogowski wrote:
> > Additionally, how can I use this message on qemu-devel.
> > It has a post for people who use Macos or Asahi Linux. Verify random qemu
> > sessions under Macos .Some are faster others are slow.
> > The topic is posted on qemu-disc...@nongnu.org (I don't know if developers
> > look there often)
> >
> > https://lists.nongnu.org/archive/html/qemu-discuss/2023-12/msg8.html
> >
> > The program posted there was prepared by one of the maintainers of ppc qemu
> > machines "BALATON Zoltan".
> >
> > We are starting to gather as much information as possible for it.
> > I hope nobody will be offended about this information in this topic. I do
> > not want to start a topic and litter other lists
>
> It's better to do that in a separate thead, I've changed the subject
> accordingly. I only came up with the idea and scripted it but the actual
> test case comes from Marek and the original report from Rene Engel.
>
> This problem was first seen running AmigaOS with qemu-system-ppc but then
> we also reproduced it with Linux guest with the test in the qemu-discuss
> messgage linked above. The runs are not exactly random but there seem to
> be slow and fast sessions with the slow one about half the expected speed.
> If we get a fast or slow session seems to be random. This was seen on
> Apple M1 and Apple M1 Max under macOS but could not reproduce on x86_64
> host under Linux or Apple M2 host under Linux so it may either be related
> to Apple M1 or macOS host.

Is this possibly related to https://gitlab.com/qemu-project/qemu/-/issues/334
where App Nap is reported as causing QEMU to slow down when the window
doesn't have focus, or does it happen even when the QEMU window has
focus the whole time the benchmark is running ?

thanks
-- PMM



Inconsistent qemu-system-ppc speed on Apple M1 (was: Re: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize)

2023-12-12 Thread BALATON Zoltan

On Tue, 12 Dec 2023, Marek Glogowski wrote:

Additionally, how can I use this message on qemu-devel.
It has a post for people who use Macos or Asahi Linux. Verify random qemu
sessions under Macos .Some are faster others are slow.
The topic is posted on qemu-disc...@nongnu.org (I don't know if developers
look there often)

https://lists.nongnu.org/archive/html/qemu-discuss/2023-12/msg8.html

The program posted there was prepared by one of the maintainers of ppc qemu
machines "BALATON Zoltan".

We are starting to gather as much information as possible for it.
I hope nobody will be offended about this information in this topic. I do
not want to start a topic and litter other lists


It's better to do that in a separate thead, I've changed the subject 
accordingly. I only came up with the idea and scripted it but the actual 
test case comes from Marek and the original report from Rene Engel.


This problem was first seen running AmigaOS with qemu-system-ppc but then 
we also reproduced it with Linux guest with the test in the qemu-discuss 
messgage linked above. The runs are not exactly random but there seem to 
be slow and fast sessions with the slow one about half the expected speed. 
If we get a fast or slow session seems to be random. This was seen on 
Apple M1 and Apple M1 Max under macOS but could not reproduce on x86_64 
host under Linux or Apple M2 host under Linux so it may either be related 
to Apple M1 or macOS host.


What could be tested to narrow it further may be trying the test on Apple 
M1 under Linux or Apple M2 under macOS. (And maybe trying some other 
qemu-system target on Apple M1 macOS to see if it's specific to 
qemu-system-ppc.) Then the question is what might cause it. Marek tested 
that these always run on Performance cores and also experimented with 
taskpolicy -B but that does not seem to change anything. Lacking a better 
idea I could think of frequency scaling maybe but I don't know how to 
check that under macOS. Or maybe something about how macOS schedules QEMU 
thread? Does anybody have an idea how to debug this further?


Thank you,
BALATON Zoltan



Re: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize

2023-12-12 Thread Marek Glogowski
Thank you for the information.
I know you're busy so I appreciate you taking the time to do a quick check
:-)

Marek Głogowski

wt., 12 gru 2023 o 09:28 Akihiko Odaki 
napisał(a):

> On 2023/12/12 17:04, Marek Glogowski wrote:
> > Hi
> >
> > I checked on the emulation "qemu-system-ppc -machine pegasos".
> > Full-screen seems to work fine. The screen is correctly initialised in
> > full-screen mode and there are no problems with closing the window when
> > the session is suspended.
> > With this series of patches, there is also the option "Move to", which
> > makes it possible to move the screen to an external device such as an
> IPad.
> > Thank you for the ui/cocoa acumen
> >
> > Additionally, how can I use this message on qemu-devel.
> > It has a post for people who use Macos or Asahi Linux. Verify random
> > qemu sessions under Macos .Some are faster others are slow.
> > The topic is posted on qemu-disc...@nongnu.org
> >  (I don't know if developers look there
> > often)
> >
> > https://lists.nongnu.org/archive/html/qemu-discuss/2023-12/msg8.html
> > <
> https://lists.nongnu.org/archive/html/qemu-discuss/2023-12/msg8.html>
> >
> > The program posted there was prepared by one of the maintainers of ppc
> > qemu machines "BALATON Zoltan".
> > We are starting to gather as much information as possible for it.
> > I hope nobody will be offended about this information in this topic. I
> > do not want to start a topic and litter other lists
> >
> > Best regards
> > Marek Głogowski
>
> Hi,
>
> I have confirmed the tests run in about 25 seconds for each trial on
> Asahi Linux (Arch Linux ARM) on M2 MacBook Air so it may be specific to
> macOS. It needs some serious debugging but I don't have free time to do
> that these days.
>
> Regards,
> Akihiko Odaki
>


Re: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize

2023-12-12 Thread Marek Glogowski
Hi

I checked on the emulation "qemu-system-ppc -machine pegasos".
Full-screen seems to work fine. The screen is correctly initialised in
full-screen mode and there are no problems with closing the window when the
session is suspended.
With this series of patches, there is also the option "Move to", which
makes it possible to move the screen to an external device such as an IPad.
Thank you for the ui/cocoa acumen

Additionally, how can I use this message on qemu-devel.
It has a post for people who use Macos or Asahi Linux. Verify random qemu
sessions under Macos .Some are faster others are slow.
The topic is posted on qemu-disc...@nongnu.org (I don't know if developers
look there often)

https://lists.nongnu.org/archive/html/qemu-discuss/2023-12/msg8.html

The program posted there was prepared by one of the maintainers of ppc qemu
machines "BALATON Zoltan".
We are starting to gather as much information as possible for it.
I hope nobody will be offended about this information in this topic. I do
not want to start a topic and litter other lists

Best regards
Marek Głogowski


wt., 12 gru 2023 o 00:09 Akihiko Odaki 
napisał(a):

> This change brings two new features:
> - The window will be resizable if "Zoom To Fit" is eanbled
> - The window can be made full screen by clicking full screen button
>   provided by the platform. (The left-top green button.)
>
> Signed-off-by: Akihiko Odaki 
> ---
> V5 -> V6:
>   Rebased.
> ---
>  ui/cocoa.m | 542
> +
>  1 file changed, 258 insertions(+), 284 deletions(-)
>
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index cd069da696..302e4f76be 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -99,12 +99,10 @@ static void cocoa_switch(DisplayChangeListener *dcl,
>  static DisplayChangeListener dcl = {
>  .ops = _ops,
>  };
> -static int last_buttons;
>  static int cursor_hide = 1;
>  static int left_command_key_enabled = 1;
>  static bool swap_opt_cmd;
>
> -static bool stretch_video;
>  static NSTextField *pauseLabel;
>
>  static bool allow_events;
> @@ -304,20 +302,17 @@ static void handleAnyDeviceErrors(Error * err)
>  */
>  @interface QemuCocoaView : NSView
>  {
> +NSTrackingArea *trackingArea;
>  QEMUScreen screen;
> -NSWindow *fullScreenWindow;
> -float cx,cy,cw,ch,cdx,cdy;
>  pixman_image_t *pixman_image;
>  QKbdState *kbd;
>  BOOL isMouseGrabbed;
> -BOOL isFullscreen;
>  BOOL isAbsoluteEnabled;
>  CFMachPortRef eventsTap;
>  }
>  - (void) switchSurface:(pixman_image_t *)image;
>  - (void) grabMouse;
>  - (void) ungrabMouse;
> -- (void) toggleFullScreen:(id)sender;
>  - (void) setFullGrab:(id)sender;
>  - (void) handleMonitorInput:(NSEvent *)event;
>  - (bool) handleEvent:(NSEvent *)event;
> @@ -333,8 +328,6 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
>   */
>  - (BOOL) isMouseGrabbed;
>  - (BOOL) isAbsoluteEnabled;
> -- (float) cdx;
> -- (float) cdy;
>  - (QEMUScreen) gscreen;
>  - (void) raiseAllKeys;
>  @end
> @@ -392,46 +385,43 @@ - (BOOL) isOpaque
>  return YES;
>  }
>
> -- (BOOL) screenContainsPoint:(NSPoint) p
> +- (void) removeTrackingRect
>  {
> -return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y <
> screen.height);
> +if (trackingArea) {
> +[self removeTrackingArea:trackingArea];
> +[trackingArea release];
> +trackingArea = nil;
> +}
>  }
>
> -/* Get location of event and convert to virtual screen coordinate */
> -- (CGPoint) screenLocationOfEvent:(NSEvent *)ev
> +- (void) frameUpdated
>  {
> -NSWindow *eventWindow = [ev window];
> -// XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10
> -CGRect r = CGRectZero;
> -r.origin = [ev locationInWindow];
> -if (!eventWindow) {
> -if (!isFullscreen) {
> -return [[self window] convertRectFromScreen:r].origin;
> -} else {
> -CGPoint locationInSelfWindow = [[self window]
> convertRectFromScreen:r].origin;
> -CGPoint loc = [self convertPoint:locationInSelfWindow
> fromView:nil];
> -if (stretch_video) {
> -loc.x /= cdx;
> -loc.y /= cdy;
> -}
> -return loc;
> -}
> -} else if ([[self window] isEqual:eventWindow]) {
> -if (!isFullscreen) {
> -return r.origin;
> -} else {
> -CGPoint loc = [self convertPoint:r.origin fromView:nil];
> -if (stretch_video) {
> -loc.x /= cdx;
> -loc.y /= cdy;
> -}
> -return loc;
> -}
> -} else {
> -return [[self window] convertRectFromScreen:[eventWindow
> convertRectToScreen:r]].origin;
> +[self removeTrackingRect];
> +
> +if ([self window]) {
> +NSTrackingAreaOptions options = NSTrackingActiveInKeyWindow |
> +NSTrackingMouseEnteredAndExited |
> +

Re: [PATCH v6] ui/cocoa: Use NSWindow's ability to resize

2023-12-12 Thread Akihiko Odaki

On 2023/12/12 17:04, Marek Glogowski wrote:

Hi

I checked on the emulation "qemu-system-ppc -machine pegasos".
Full-screen seems to work fine. The screen is correctly initialised in 
full-screen mode and there are no problems with closing the window when 
the session is suspended.
With this series of patches, there is also the option "Move to", which 
makes it possible to move the screen to an external device such as an IPad.

Thank you for the ui/cocoa acumen

Additionally, how can I use this message on qemu-devel.
It has a post for people who use Macos or Asahi Linux. Verify random 
qemu sessions under Macos .Some are faster others are slow.
The topic is posted on qemu-disc...@nongnu.org 
 (I don't know if developers look there 
often)


https://lists.nongnu.org/archive/html/qemu-discuss/2023-12/msg8.html 



The program posted there was prepared by one of the maintainers of ppc 
qemu machines "BALATON Zoltan".

We are starting to gather as much information as possible for it.
I hope nobody will be offended about this information in this topic. I 
do not want to start a topic and litter other lists


Best regards
Marek Głogowski


Hi,

I have confirmed the tests run in about 25 seconds for each trial on 
Asahi Linux (Arch Linux ARM) on M2 MacBook Air so it may be specific to 
macOS. It needs some serious debugging but I don't have free time to do 
that these days.


Regards,
Akihiko Odaki



[PATCH v6] ui/cocoa: Use NSWindow's ability to resize

2023-12-10 Thread Akihiko Odaki
This change brings two new features:
- The window will be resizable if "Zoom To Fit" is eanbled
- The window can be made full screen by clicking full screen button
  provided by the platform. (The left-top green button.)

Signed-off-by: Akihiko Odaki 
---
V5 -> V6:
  Rebased.
---
 ui/cocoa.m | 542 +
 1 file changed, 258 insertions(+), 284 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index cd069da696..302e4f76be 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -99,12 +99,10 @@ static void cocoa_switch(DisplayChangeListener *dcl,
 static DisplayChangeListener dcl = {
 .ops = _ops,
 };
-static int last_buttons;
 static int cursor_hide = 1;
 static int left_command_key_enabled = 1;
 static bool swap_opt_cmd;
 
-static bool stretch_video;
 static NSTextField *pauseLabel;
 
 static bool allow_events;
@@ -304,20 +302,17 @@ static void handleAnyDeviceErrors(Error * err)
 */
 @interface QemuCocoaView : NSView
 {
+NSTrackingArea *trackingArea;
 QEMUScreen screen;
-NSWindow *fullScreenWindow;
-float cx,cy,cw,ch,cdx,cdy;
 pixman_image_t *pixman_image;
 QKbdState *kbd;
 BOOL isMouseGrabbed;
-BOOL isFullscreen;
 BOOL isAbsoluteEnabled;
 CFMachPortRef eventsTap;
 }
 - (void) switchSurface:(pixman_image_t *)image;
 - (void) grabMouse;
 - (void) ungrabMouse;
-- (void) toggleFullScreen:(id)sender;
 - (void) setFullGrab:(id)sender;
 - (void) handleMonitorInput:(NSEvent *)event;
 - (bool) handleEvent:(NSEvent *)event;
@@ -333,8 +328,6 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
  */
 - (BOOL) isMouseGrabbed;
 - (BOOL) isAbsoluteEnabled;
-- (float) cdx;
-- (float) cdy;
 - (QEMUScreen) gscreen;
 - (void) raiseAllKeys;
 @end
@@ -392,46 +385,43 @@ - (BOOL) isOpaque
 return YES;
 }
 
-- (BOOL) screenContainsPoint:(NSPoint) p
+- (void) removeTrackingRect
 {
-return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height);
+if (trackingArea) {
+[self removeTrackingArea:trackingArea];
+[trackingArea release];
+trackingArea = nil;
+}
 }
 
-/* Get location of event and convert to virtual screen coordinate */
-- (CGPoint) screenLocationOfEvent:(NSEvent *)ev
+- (void) frameUpdated
 {
-NSWindow *eventWindow = [ev window];
-// XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10
-CGRect r = CGRectZero;
-r.origin = [ev locationInWindow];
-if (!eventWindow) {
-if (!isFullscreen) {
-return [[self window] convertRectFromScreen:r].origin;
-} else {
-CGPoint locationInSelfWindow = [[self window] 
convertRectFromScreen:r].origin;
-CGPoint loc = [self convertPoint:locationInSelfWindow 
fromView:nil];
-if (stretch_video) {
-loc.x /= cdx;
-loc.y /= cdy;
-}
-return loc;
-}
-} else if ([[self window] isEqual:eventWindow]) {
-if (!isFullscreen) {
-return r.origin;
-} else {
-CGPoint loc = [self convertPoint:r.origin fromView:nil];
-if (stretch_video) {
-loc.x /= cdx;
-loc.y /= cdy;
-}
-return loc;
-}
-} else {
-return [[self window] convertRectFromScreen:[eventWindow 
convertRectToScreen:r]].origin;
+[self removeTrackingRect];
+
+if ([self window]) {
+NSTrackingAreaOptions options = NSTrackingActiveInKeyWindow |
+NSTrackingMouseEnteredAndExited |
+NSTrackingMouseMoved;
+trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame]
+options:options
+  owner:self
+   userInfo:nil];
+[self addTrackingArea:trackingArea];
+[self updateUIInfo];
 }
 }
 
+- (void) viewDidMoveToWindow
+{
+[self resizeWindow];
+[self frameUpdated];
+}
+
+- (void) viewWillMoveToWindow:(NSWindow *)newWindow
+{
+[self removeTrackingRect];
+}
+
 - (void) hideCursor
 {
 if (!cursor_hide) {
@@ -494,13 +484,14 @@ - (void) drawRect:(NSRect) rect
 int i;
 CGImageRef clipImageRef;
 CGRect clipRect;
+CGFloat d = (CGFloat)h / [self frame].size.height;
 
 [self getRectsBeingDrawn: count:];
 for (i = 0; i < rectCount; i++) {
-clipRect.origin.x = rectList[i].origin.x / cdx;
-clipRect.origin.y = (float)h - (rectList[i].origin.y + 
rectList[i].size.height) / cdy;
-clipRect.size.width = rectList[i].size.width / cdx;
-clipRect.size.height = rectList[i].size.height / cdy;
+clipRect.origin.x = rectList[i].origin.x * d;
+clipRect.origin.y = (float)h - (rectList[i].origin.y + 
rectList[i].size.height) * d;
+clipRect.size.width