Re: Extremely low fps during transparent NSWindow resize
Re: Extremely low fps during transparent NSWindow resize
- Subject: Re: Extremely low fps during transparent NSWindow resize
- From: Andrea3000 <email@hidden>
- Date: Sun, 04 Nov 2012 11:52:00 +0100
> On Nov 1, 2012, at 6:48 AM, Andrea3000 wrote:
>
>> I'm trying to address a performance problem regarding transparent NSWindows during resize.
>
>> This way I have a borderless NSWindow which is transparent with a NSView that draws an opaque NSRect with rounded corners.
>> Therefore it gives me a NSWindow which appears opaque but with rounded corners.
>> The problem, though, is that when the window has a size above (let's say) 1280x800 pixels and I start to perform a resize, the resize animation becomes sluggish with an overall refresh rate which is below 20fps (as measured by Quartz Debug).
>> If I comment out the line "[self setOpaque:NO]", the window is no more transparent and therefore I lose the rounded corners but the resize animation is again smooth with a refresh rate always above 45 fps.
>>
>> I have then sampled the app with Time Profiler with both transparent and opaque NSWindows.
>> To do that I have recorded (with UI Recorder) a 30 seconds resize in which I have exploited both slow and fast resizes, and I have applied this record to the two versions of the app.
>>
>> What I've found is that the CPU time required by every functions is equal in percentage between the transparent and the opaque NSWindow (i.e.: aa_render from CoreGraphics takes around 31% of the total CPU time with both transparent and opaque NSWindow, CGSColorMaskCopyARGB8888 from CoreGraphics takes around 22.0%, etc..)
>>
>> The strage fact is that the total CPU time of the opaque window version is more than TWICE of that of the transparent window version...and this seems to be a nonsense since the opaque version is much faster and more smooth than the transparent version.
>
> This suggests that the limiting factor is the GPU and/or the window server's throttling of the refresh rate. So, the process isn't using much CPU time because it's blocked waiting for the GPU or window server to recomposite the window into the screen image.
>
> If you take a time profile and enable "All Thread States" in the instrument configuration, it will show the time your process spends waiting on the GPU or window server and there should definitely be a difference between the transparent and opaque window scenarios.
Thank you for the answer.
I have just tested it with both Instruments and OpenGL Driver Monitor and it seems that the "CPU wait for GPU" time is equal between the two version.
>> How is it possible to obtain the same refresh rate as with the opaque window?
>
> You might try the techniques outlined in this technote:
> https://developer.apple.com/library/mac/#technotes/tn2133/
>
> In particular, try disabling beam synchronization in Quartz Debug to see if that affects the behavior. If it does, you can try adding the key CGDisableCoalescedUpdates to your Info.plist, but that should be considered a last resort.
Disabling beam synchronization unfortunately does not affect the behavior, fps are quite the same. In fact I see no changes when I set CGDisableCoalescedUpdates to true.
>>> Maybe a better approach would be to use Core Animation layers. Those can
>>> have rounded corners and that may allow the system to update them in a better
>>> manner.
>>
>> I'm curious, what you mean by that, how would that work?
>
> I'm not sure it would. Hence "maybe".
>
>> You need to host layers in a view in a transparent window, no? Wouldn't you end up having the exact same problem? Or are you suggesting putting a layer hosting custom view as replacement content view of the window?
>
> Yes, I was suggesting making the content view layer-hosting. I don't think it needs to be a custom view or even a replacement. I think you can just -setLayer: and -setWantsLayer:YES on the default content view.
>
> With layers, you can give more control over to the system. It can automatically resize them, including the redraw (e.g. kCAGravityResize* and contentsCenter). It will draw the rounded corners, and it may have an optimization for that. Etc. It's worth a try.
I'll try this CALayer approach and see if it will improve the performance. I'm not experienced with CALayer therefore there is something I'm not getting.
With a regular NSWindow without layers, even if I override the content view, I still need to set the window transparent in order to have rounded corners. Is it different with CALayer?
I'll try to implement it and I'll report back to you.
Thank you
Regards
Andrea
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden