Skip to content

Commit

Permalink
ui/cocoa: add zoom-interpolation display option
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
carwynellis authored and philmd committed Mar 5, 2024
1 parent 52e7db4 commit e28a909
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion qapi/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -1428,14 +1428,18 @@
# 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',
'data': {
'*left-command-key': 'bool',
'*full-grab': 'bool',
'*swap-opt-cmd': 'bool',
'*zoom-to-fit': 'bool'
'*zoom-to-fit': 'bool',
'*zoom-interpolation': 'bool'
} }

##
Expand Down
21 changes: 20 additions & 1 deletion ui/cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e28a909

Please sign in to comment.