Mac slow bitmap drawing Mojave

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
72deluxe
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue May 20, 2008 10:55 pm

Mac slow bitmap drawing Mojave

Post by 72deluxe »

Hello

I am using a wxAutoBufferedPaintDC under wxWidgets 3.1.2 and am using dc.DrawBitmap to draw a 24bit bitmap with alpha to the DC. I am ensuring 24 bit because I have used wxDisplayDepth() to get the current display depth, based on the tip here: http://wxwidgets.10942.n7.nabble.com/Dr ... 90810.html

This drawing of this bitmap is very slow. I am drawing a bitmap as part of an animation, so speedy drawing is essential.

I have profiled it and got the following stack:

Code: Select all

6.56 s   56.3%	2.00 ms	 	 myThing::OnPaint(wxPaintEvent&)
5.83 s   50.0%	0 s	 	      wxGCDCImpl::DoDrawBitmap(wxBitmap const&, int, int, bool)
5.83 s   50.0%	0 s	 	       wxMacCoreGraphicsContext::DrawBitmap(wxBitmap const&, double, double, double, double)
5.83 s   50.0%	0 s	 	        wxOSXDrawNSImage(CGContext*, CGRect const*, NSImage*)
5.83 s   50.0%	0 s	 	         -[NSImage drawInRect:fromRect:operation:fraction:]
5.83 s   50.0%	0 s	 	          -[NSImage drawInRect:fromRect:operation:fraction:respectFlipped:hints:]
5.83 s   50.0%	0 s	 	           -[NSImage _usingBestRepresentationForRect:context:hints:body:]
5.83 s   50.0%	0 s	 	            __71-[NSImage drawInRect:fromRect:operation:fraction:respectFlipped:hints:]_block_invoke.1317
5.83 s   50.0%	0 s	 	             -[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:]
5.83 s   50.0%	0 s	 	              __74-[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:]_block_invoke
5.83 s   50.0%	0 s	 	               CGContextDrawImage
5.83 s   50.0%	0 s	 	                CGContextDrawImageWithOptions
5.83 s   50.0%	0 s	 	                 CGContextDelegateDrawImage
5.83 s   50.0%	0 s	 	                  backing_store_DrawImage.llvm.1028279097235270472
5.83 s   50.0%	0 s	 	                   backing_store_delegate
5.83 s   49.9%	0 s	 	                    __backing_store_DrawImage_block_invoke
5.83 s   49.9%	0 s	 	                     CGContextDelegateDrawImage
5.83 s   49.9%	0 s	 	                      ripc_DrawImage
5.82 s   49.9%	0 s	 	                       ripc_RenderImage
5.82 s   49.9%	0 s	 	                        RIPLayerBltImage
5.82 s   49.9%	0 s	 	                         ripl_Mark
5.82 s   49.9%	0 s	 	                          RGBAf16_image
5.82 s   49.9%	778.00 ms	                             RGBAf16_image_mark(BltDepth const*, BltOp const*, _ImgOp*, MODE)
5.04 s   43.2%	5.04 s	 	                            RGBAf16_sample_RGBAf_inner(_ImgOp const*, long, long, int)

Under High Sierra, this is not a problem at all, but on my Mojave Mac this is very slow indeed, as you can see.

Does anyone have any tips on how to improve the drawing speed for this? Or anything obvious I am missing about my bitmap construction?
All items I have found on the internet relating to this (eg. https://forums.developer.apple.com/thread/79474) seem to indicate pixel format of the bitmap but how do I control this in wxWidgets?
72deluxe
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue May 20, 2008 10:55 pm

Re: Mac slow bitmap drawing Mojave

Post by 72deluxe »

Replying to myself, I see that my High Sierra is running at 32 bit depth but my Mojave is running at 24 bit.
Looking in src/osx/core/bitmap.cpp, I see the comment that the bitmaps are ALWAYS 32 bit and wxBitmapRefData::Create sets m_depth to 32, although the overloaded constructor wxBitmapRefData::Create that takes a depth sets m_depth to what is passed in, but doesn't appear to actually use it??

If anyone has any tips on how to actually get a wxBitmap that is the same depth as the display in order to force OSX's CGContextDrawImage to NOT use RGBAf16_sample_RGBAf_inner (thereby avoiding resampling from 32 bit to the native depth, eg. 24 bit) then I would welcome any tips!

This is my guess what is happening anyway.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Mac slow bitmap drawing Mojave

Post by doublemax »

I think you should open a bug report for this: http://trac.wxwidgets.org
Use the source, Luke!
72deluxe
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue May 20, 2008 10:55 pm

Re: Mac slow bitmap drawing Mojave

Post by 72deluxe »

Thanks for the reply Max. I will.
72deluxe
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue May 20, 2008 10:55 pm

Re: Mac slow bitmap drawing Mojave

Post by 72deluxe »

I have opened this as https://trac.wxwidgets.org/ticket/18516 and will update this forum as/when anything changes. Thanks very much.
I have also mentioned this on StackOverflow to cast a wider net: https://stackoverflow.com/questions/58168080.

Suggestions are welcome in the interim!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Mac slow bitmap drawing Mojave

Post by ONEEYEMAN »

Hi,
Do you have any benchmarks to show?
If you do - please attach to the ticket as well as here and SO.

Thank you.
72deluxe
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue May 20, 2008 10:55 pm

Re: Mac slow bitmap drawing Mojave

Post by 72deluxe »

Thanks for the speedy reply. Traces are available here:
https://drive.google.com/open?id=14sh2d ... 6FOsTuVIKm

I will attach the two trace zip files to the ticket.

Traces are on Instruments on Sierra for the sierra.trace.zip, and from Instruments on Mojave for mojave.trace.zip.
Last edited by 72deluxe on Mon Sep 30, 2019 3:13 pm, edited 1 time in total.
72deluxe
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue May 20, 2008 10:55 pm

Re: Mac slow bitmap drawing Mojave

Post by 72deluxe »

I cannot post the traces to the ticket as the maximum upload size is 275.0 KB, so the Google Drive link will have to do. Sorry - hope that's alright?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Mac slow bitmap drawing Mojave

Post by ONEEYEMAN »

Hi,
By benchmarks I meant the actual time it takes to draw a bitmap on one system vs another.

The best way will probably be to add some logging in the drawing sample and attach them to the ticket.

Thank you.

P.S.: Just add some time logging before drawing bitmap and after drawing finished.

It just going to be 4 lines of text.
72deluxe
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue May 20, 2008 10:55 pm

Re: Mac slow bitmap drawing Mojave

Post by 72deluxe »

OK I will put one together, apologies
72deluxe
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue May 20, 2008 10:55 pm

Re: Mac slow bitmap drawing Mojave

Post by 72deluxe »

I've added a demo program on the support ticket (https://trac.wxwidgets.org/attachment/t ... 6/demo.cpp).
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Mac slow bitmap drawing Mojave

Post by doublemax »

Do you draw multiple bitmaps on top of each other or just one? In the latter case, you could use OpenGL as a workaround. Check gl_bitmap_panel.h from here:
viewtopic.php?p=183279#p183279
Use the source, Luke!
72deluxe
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue May 20, 2008 10:55 pm

Re: Mac slow bitmap drawing Mojave

Post by 72deluxe »

I draw a bitmap over other basic primitives (filled arcs, lines, a circle). It is an animated pie chart.

This openGL implementation looks very interesting though, thank you. I will try something shortly or just revert to using a graphics context every time if the screen depth != 32. It just seemed so wasteful to build a path a render it every time, hence me using a bitmap as blitting a bitmap should be fast.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Mac slow bitmap drawing Mojave

Post by doublemax »

I draw a bitmap over other basic primitives (filled arcs, lines, a circle). It is an animated pie chart.
In that case the code from that link won't help you.
Use the source, Luke!
72deluxe
Experienced Solver
Experienced Solver
Posts: 91
Joined: Tue May 20, 2008 10:55 pm

Re: Mac slow bitmap drawing Mojave

Post by 72deluxe »

For now, I have written my code to not draw the gradient'd bitmap that I was caching and drawing if the platform is greater than Sierra.
Most activity will likely continue on the bug report at https://trac.wxwidgets.org/ticket/18516 instead of here.

Thanks for the suggestions nonetheless.
Post Reply