All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix non-blanked display window if guest never uses it
@ 2013-12-24  2:51 Peter Maydell
  2013-12-24  2:51 ` [Qemu-devel] [PATCH 1/2] ui/cocoa: Redraw at correct size when switching surface Peter Maydell
  2013-12-24  2:51 ` [Qemu-devel] [PATCH 2/2] ui/cocoa: Draw black rectangle if we have no data yet Peter Maydell
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2013-12-24  2:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber, patches

This patch series fixes a couple of bugs in drawing the display
which are only really visible if you run guests with no graphics
device or which never get round to using the graphics device.

The first is a fix for a bug in the order in which we handled
surface switching which meant that if the surface was resized
from 640x480 to 1024x768 we would draw the new data at the old
size and then resize the window (which on MacOSX doesn't
provoke a redraw). So we wouldn't update the display properly
until the next time the guest updated the framebuffer.

The second patch just says "if we're asked to draw and there's
nothing from the guest yet, draw black"; this means that if
the guest has no graphics device we have a black window rather
than a white one, which is more in line with behaviour of
other UI frontends.

NB: the changes to switchSurface were to some extent made
by trial and error and googling of documentation, so ideally
they could use code review from somebody who understands
Cocoa better than I do.

Peter Maydell (2):
  ui/cocoa: Redraw at correct size when switching surface
  ui/cocoa: Draw black rectangle if we have no data yet

 ui/cocoa.m | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

-- 
1.7.11.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH 1/2] ui/cocoa: Redraw at correct size when switching surface
  2013-12-24  2:51 [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix non-blanked display window if guest never uses it Peter Maydell
@ 2013-12-24  2:51 ` Peter Maydell
  2013-12-24  2:51 ` [Qemu-devel] [PATCH 2/2] ui/cocoa: Draw black rectangle if we have no data yet Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2013-12-24  2:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber, patches

If the surface switch involved a resize, we were doing the redraw
at the old size rather than the new, because the update of
screen.width and screen.height was being done after the setFrame
method calls which triggered a redraw. Normally this isn't very
noticeable because typically after the guest triggers the window
resize it also draws something to it, which will in turn cause
us to redraw. However, the combination of a guest which never
draws to the display and a command line setting of a screen size
larger than the default can reveal odd effects.

Move most of the handling of resizes to the top of the method,
and guard it with a check that the surface size actually changed,
to avoid unnecessary operations (including some user visible ones
like "recenter the window on the screen") if the surface is the
same size as the old one.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 ui/cocoa.m | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 94bf729..9e22d21 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -406,6 +406,17 @@ QemuCocoaView *cocoaView;
 
     int w = surface_width(surface);
     int h = surface_height(surface);
+    bool isResize = (w != screen.width || h != screen.height);
+
+    int oldh = screen.height;
+    if (isResize) {
+        // Resize before we trigger the redraw, or we'll redraw at the wrong size
+        COCOA_DEBUG("switchSurface: new size %d x %d\n", w, h);
+        screen.width = w;
+        screen.height = h;
+        [self setContentDimensions];
+        [self setFrame:NSMakeRect(cx, cy, cw, ch)];
+    }
 
     // update screenBuffer
     if (dataProviderRef)
@@ -420,17 +431,16 @@ QemuCocoaView *cocoaView;
     // update windows
     if (isFullscreen) {
         [[fullScreenWindow contentView] setFrame:[[NSScreen mainScreen] frame]];
-        [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [normalWindow frame].origin.y - h + screen.height, w, h + [normalWindow frame].size.height - screen.height) display:NO animate:NO];
+        [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [normalWindow frame].origin.y - h + oldh, w, h + [normalWindow frame].size.height - oldh) display:NO animate:NO];
     } else {
         if (qemu_name)
             [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s", qemu_name]];
-        [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [normalWindow frame].origin.y - h + screen.height, w, h + [normalWindow frame].size.height - screen.height) display:YES animate:NO];
+        [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [normalWindow frame].origin.y - h + oldh, w, h + [normalWindow frame].size.height - oldh) display:YES animate:NO];
+    }
+
+    if (isResize) {
+        [normalWindow center];
     }
-    screen.width = w;
-    screen.height = h;
-	[normalWindow center];
-    [self setContentDimensions];
-    [self setFrame:NSMakeRect(cx, cy, cw, ch)];
 }
 
 - (void) toggleFullScreen:(id)sender
-- 
1.7.11.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH 2/2] ui/cocoa: Draw black rectangle if we have no data yet
  2013-12-24  2:51 [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix non-blanked display window if guest never uses it Peter Maydell
  2013-12-24  2:51 ` [Qemu-devel] [PATCH 1/2] ui/cocoa: Redraw at correct size when switching surface Peter Maydell
@ 2013-12-24  2:51 ` Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2013-12-24  2:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber, patches

If our redraw method is called before we have any data from the guest,
then draw a black rectangle rather than leaving the window empty.
This mostly only matters when the guest machine has no framebuffer
device, but it is more in line with the behaviour of other QEMU UIs.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 ui/cocoa.m | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 9e22d21..39c62ad 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -322,7 +322,12 @@ QemuCocoaView *cocoaView;
     CGContextSetShouldAntialias (viewContextRef, NO);
 
     // draw screen bitmap directly to Core Graphics context
-    if (dataProviderRef) {
+    if (!dataProviderRef) {
+        // Draw request before any guest device has set up a framebuffer:
+        // just draw an opaque black rectangle
+        CGContextSetRGBFillColor(viewContextRef, 0, 0, 0, 1.0);
+        CGContextFillRect(viewContextRef, NSRectToCGRect(rect));
+    } else {
         CGImageRef imageRef = CGImageCreate(
             screen.width, //width
             screen.height, //height
-- 
1.7.11.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-12-24  2:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-24  2:51 [Qemu-devel] [PATCH 0/2] ui/cocoa: Fix non-blanked display window if guest never uses it Peter Maydell
2013-12-24  2:51 ` [Qemu-devel] [PATCH 1/2] ui/cocoa: Redraw at correct size when switching surface Peter Maydell
2013-12-24  2:51 ` [Qemu-devel] [PATCH 2/2] ui/cocoa: Draw black rectangle if we have no data yet Peter Maydell

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.