[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/12] ui/cocoa: add zoom-interpolation display option
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 01/12] ui/cocoa: add zoom-interpolation display option |
Date: |
Tue, 5 Mar 2024 12:05:56 +0100 |
From: Carwyn Ellis <carwynellis@gmail.com>
Provides a new display option, zoom-interpolation, that enables
interpolation of the scaled display when zoom-to-fit is enabled.
Also provides a corresponding view menu item to allow this to be toggled
as required.
Signed-off-by: Carwyn Ellis <carwynellis@gmail.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-ID: <20231110161729.36822-2-carwynellis@gmail.com>
[PMD: QAPI @zoom-interpolation since 9.0]
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
qapi/ui.json | 6 +++++-
ui/cocoa.m | 21 ++++++++++++++++++++-
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/qapi/ui.json b/qapi/ui.json
index e3999b7c07..096a2ad26f 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1428,6 +1428,9 @@
# turned off the host window will be resized instead. Defaults to
# "off". (Since 8.2)
#
+# @zoom-interpolation: Apply interpolation to smooth output when
+# zoom-to-fit is enabled. Defaults to "off". (Since 9.0)
+#
# Since: 7.0
##
{ 'struct': 'DisplayCocoa',
@@ -1435,7 +1438,8 @@
'*left-command-key': 'bool',
'*full-grab': 'bool',
'*swap-opt-cmd': 'bool',
- '*zoom-to-fit': 'bool'
+ '*zoom-to-fit': 'bool',
+ '*zoom-interpolation': 'bool'
} }
##
diff --git a/ui/cocoa.m b/ui/cocoa.m
index eb99064bee..b7ca0ed94b 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -105,6 +105,7 @@ static void cocoa_switch(DisplayChangeListener *dcl,
static bool swap_opt_cmd;
static bool stretch_video;
+static CGInterpolationQuality zoom_interpolation = kCGInterpolationNone;
static NSTextField *pauseLabel;
static bool allow_events;
@@ -455,7 +456,7 @@ - (void) drawRect:(NSRect) rect
// get CoreGraphic context
CGContextRef viewContextRef = [[NSGraphicsContext currentContext]
CGContext];
- CGContextSetInterpolationQuality (viewContextRef, kCGInterpolationNone);
+ CGContextSetInterpolationQuality (viewContextRef, zoom_interpolation);
CGContextSetShouldAntialias (viewContextRef, NO);
// draw screen bitmap directly to Core Graphics context
@@ -1411,6 +1412,17 @@ - (void)zoomToFit:(id) sender
}
}
+- (void)toggleZoomInterpolation:(id) sender
+{
+ if (zoom_interpolation == kCGInterpolationNone) {
+ zoom_interpolation = kCGInterpolationLow;
+ [sender setState: NSControlStateValueOn];
+ } else {
+ zoom_interpolation = kCGInterpolationNone;
+ [sender setState: NSControlStateValueOff];
+ }
+}
+
/* Displays the console on the screen */
- (void)displayConsole:(id)sender
{
@@ -1673,6 +1685,9 @@ static void create_initial_menus(void)
menuItem = [[[NSMenuItem alloc] initWithTitle:@"Zoom To Fit"
action:@selector(zoomToFit:) keyEquivalent:@""] autorelease];
[menuItem setState: stretch_video ? NSControlStateValueOn :
NSControlStateValueOff];
[menu addItem: menuItem];
+ menuItem = [[[NSMenuItem alloc] initWithTitle:@"Zoom Interpolation"
action:@selector(toggleZoomInterpolation:) keyEquivalent:@""] autorelease];
+ [menuItem setState: zoom_interpolation == kCGInterpolationLow ?
NSControlStateValueOn : NSControlStateValueOff];
+ [menu addItem: menuItem];
menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil
keyEquivalent:@""] autorelease];
[menuItem setSubmenu:menu];
[[NSApp mainMenu] addItem:menuItem];
@@ -2070,6 +2085,10 @@ static void cocoa_display_init(DisplayState *ds,
DisplayOptions *opts)
stretch_video = true;
}
+ if (opts->u.cocoa.has_zoom_interpolation &&
opts->u.cocoa.zoom_interpolation) {
+ zoom_interpolation = kCGInterpolationLow;
+ }
+
create_initial_menus();
/*
* Create the menu entries which depend on QEMU state (for consoles
--
2.41.0
- [PULL 00/12] Cocoa patches for 2024-03-05, Philippe Mathieu-Daudé, 2024/03/05
- [PULL 02/12] ui/cocoa: Fix window clipping on macOS 14, Philippe Mathieu-Daudé, 2024/03/05
- [PULL 03/12] ui/cocoa: Split [-QemuCocoaView handleEventLocked:], Philippe Mathieu-Daudé, 2024/03/05
- [PULL 06/12] ui/cocoa: Scale with NSView instead of Core Graphics, Philippe Mathieu-Daudé, 2024/03/05
- [PULL 04/12] ui/cocoa: Immediately call [-QemuCocoaView handleMouseEvent:buttons:], Philippe Mathieu-Daudé, 2024/03/05
- [PULL 01/12] ui/cocoa: add zoom-interpolation display option,
Philippe Mathieu-Daudé <=
- [PULL 07/12] ui/cocoa: Fix pause label coordinates, Philippe Mathieu-Daudé, 2024/03/05
- [PULL 05/12] ui/cocoa: Release specific mouse buttons, Philippe Mathieu-Daudé, 2024/03/05
- [PULL 08/12] ui/cocoa: Let the platform toggle fullscreen, Philippe Mathieu-Daudé, 2024/03/05
- [PULL 09/12] ui/cocoa: Remove normalWindow, Philippe Mathieu-Daudé, 2024/03/05
- [PULL 10/12] ui/cocoa: Make window resizable, Philippe Mathieu-Daudé, 2024/03/05
- [PULL 11/12] ui/cocoa: Call console_select() with the BQL, Philippe Mathieu-Daudé, 2024/03/05
- [PULL 12/12] ui/cocoa: Remove stretch_video flag, Philippe Mathieu-Daudé, 2024/03/05
- Re: [PULL 00/12] Cocoa patches for 2024-03-05, Peter Maydell, 2024/03/05
- Re: [PULL 00/12] Cocoa patches for 2024-03-05, Peter Maydell, 2024/03/09