]> Git Repo - qemu.git/commitdiff
ui/cocoa: Fix stride resolution of pixman image
authorAkihiko Odaki <[email protected]>
Mon, 22 Feb 2021 14:40:12 +0000 (23:40 +0900)
committerGerd Hoffmann <[email protected]>
Thu, 4 Mar 2021 08:35:03 +0000 (09:35 +0100)
A display can receive an image which its stride is greater than its
width. In fact, when a guest requests virtio-gpu to scan out a
smaller part of an image, virtio-gpu passes it to a display as an
image which its width represents the one of the part and its stride
equals to the one of the whole image.

This change makes ui/cocoa to cover such cases.

Signed-off-by: Akihiko Odaki <[email protected]>
Message-Id: <20210222144012[email protected]>
Signed-off-by: Gerd Hoffmann <[email protected]>
ui/cocoa.m

index 5ad44b84aaaf8df6fb90edd9c0de49134734b2cf..6a59f87316b832f8b117d8a00db00d65befa2bec 100644 (file)
@@ -450,19 +450,19 @@ QemuCocoaView *cocoaView;
         int w = pixman_image_get_width(pixman_image);
         int h = pixman_image_get_height(pixman_image);
         int bitsPerPixel = PIXMAN_FORMAT_BPP(pixman_image_get_format(pixman_image));
-        int bitsPerComponent = DIV_ROUND_UP(bitsPerPixel, 8) * 2;
+        int stride = pixman_image_get_stride(pixman_image);
         CGDataProviderRef dataProviderRef = CGDataProviderCreateWithData(
             NULL,
             pixman_image_get_data(pixman_image),
-            w * 4 * h,
+            stride * h,
             NULL
         );
         CGImageRef imageRef = CGImageCreate(
             w, //width
             h, //height
-            bitsPerComponent, //bitsPerComponent
+            DIV_ROUND_UP(bitsPerPixel, 8) * 2, //bitsPerComponent
             bitsPerPixel, //bitsPerPixel
-            (w * (bitsPerComponent/2)), //bytesPerRow
+            stride, //bytesPerRow
 #ifdef __LITTLE_ENDIAN__
             CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), //colorspace for OS X >= 10.4
             kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst,
This page took 0.029484 seconds and 4 git commands to generate.