Skip to contentSkip to conversation

ui/cocoa: Fix stride resolution of pixman image

PATCH Superseded Akihiko Odaki 3 participants 7 messages Feb 21, 2021 – Feb 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/cocoa: Fix stride resolution of pixman image

---
 ui/cocoa.m | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
ui/cocoa.m +4 -4
index 0ef5fdf3b7a..2de72155dea 100644
@@ -450,19 +450,19 @@ - (void) drawRect:(NSRect) rect
         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,
Signature · 1 line
2.24.3 (Apple Git-128)
#1 lore raw
Quoted 2 lines · Akihiko Odaki

In what situations does this change make a difference? Obviously most of the time it works fine, or we'd have noticed before now.

(This is the kind of detail that it's useful to provide in the commit message.)

thanks
-- PMM

#2 lore raw

PATCH v2 1/1 ui/cocoa: Fix stride resolution of pixman image

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.

---
 ui/cocoa.m | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
ui/cocoa.m +4 -4
index 0ef5fdf3b7a..2de72155dea 100644
@@ -450,19 +450,19 @@ - (void) drawRect:(NSRect) rect
         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,
Signature · 1 line
2.24.3 (Apple Git-128)
#3 lore raw
Quoted 5 lines · Akihiko Odaki

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.

Probably not limited to virtio-gpu. Wayland rounds display framebuffers to the next multiple of 64, so when running -- for example -- 800x600 wayland will create an image 832 pixels wide. Other UIs had simliar issues.

Patch added to UI patch queue.

thanks,
Gerd

#4 lore raw
Quoted 8 lines · Gerd Hoffmann
Quoted 5 lines · Akihiko Odaki

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.

Quoted 6 lines

Probably not limited to virtio-gpu. Wayland rounds display framebuffers to the next multiple of 64, so when running -- for example -- 800x600 wayland will create an image 832 pixels wide. Other UIs had simliar issues.

Patch added to UI patch queue.

Could you add Akihiko's explanation to the commit message for the patch in your queue, please?

thanks
-- PMM

#5 lore raw
Quoted 14 lines · Peter Maydell
Quoted 13 lines · Gerd Hoffmann
Quoted 5 lines · Akihiko Odaki

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.

Probably not limited to virtio-gpu. Wayland rounds display framebuffers to the next multiple of 64, so when running -- for example -- 800x600 wayland will create an image 832 pixels wide. Other UIs had simliar issues.

Quoted 4 lines
Quoted 1 line

Patch added to UI patch queue.

Could you add Akihiko's explanation to the commit message for the patch in your queue, please?

That _is_ the (v2) commit message ;)

Akihiko: new versions of a patch should be sent as new thread, not as reply. It is less confusing for both people and tools like b4
(https://pypi.org/project/b4/) which help with patch processing.

take care,
Gerd

#6 lore raw

2021年2月25日(木) 17:02 Gerd Hoffmann <[email protected]>:

Quoted 18 lines · Peter Maydell
Quoted 16 lines · Gerd Hoffmann
Quoted 14 lines · Akihiko Odaki
Quoted 5 lines

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.

Probably not limited to virtio-gpu. Wayland rounds display framebuffers to the next multiple of 64, so when running -- for example -- 800x600 wayland will create an image 832 pixels wide. Other UIs had simliar issues.

Patch added to UI patch queue.

Quoted 8 lines
Quoted 2 lines

Could you add Akihiko's explanation to the commit message for the patch in your queue, please?

That _is_ the (v2) commit message ;)

Akihiko: new versions of a patch should be sent as new thread, not as reply. It is less confusing for both people and tools like b4
(https://pypi.org/project/b4/) which help with patch processing.

I didn't know that. Thanks for telling me that. I'll do so next time.

Regards,
Akihiko Odaki

Quoted 4 lines

take care,
Gerd