Hi,
I'm trying to address a performance problem regarding transparent NSWindows
during resize.
I have created a new Cocoa Application from Xcode's templates, overriding both
NSWindow and NSView as follows:
////////////////////////////////////////////////////////////////////////////
@implementation MyWindow
- (id) initWithContentRect: (NSRect) contentRect
styleMask: (NSUInteger) aStyle
backing: (NSBackingStoreType) bufferingType
defer: (BOOL) flag
{
if (self = [super initWithContentRect: contentRect
styleMask: NSBorderlessWindowMask
backing: bufferingType
defer: flag])
{
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
}
return self;
}
-(BOOL) canBecomeKeyWindow { return YES;}
-(BOOL) canBecomeMainWindow { return YES;}
-(BOOL) acceptsFirstResponder { return YES; }
- (void)mouseDragged:(NSEvent *)theEvent
{
// manual resize implementation
// .....
// .....
// .....
// set new size
[self setFrame:windowFrame display:YES animate:NO];
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
@implementation MyView
- (void)drawRect:(NSRect)rect
{
NSBezierPath* thePath = [NSBezierPath bezierPath];
[thePath appendBezierPathWithRoundedRect:rect xRadius:8 yRadius:8];
[thePath fill];
}
////////////////////////////////////////////////////////////////////////////
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 led me to think that the problem could be that in the case of transparent
NSWindow the -drawRect method gets called with a rate which is less than half
of that of the opaque window and this may also explain why the fps of the
transparent version are less than half of those measured with the opaque
version.
To verify this I have counted the number of -drawRect calls and my hypothesis
holds true; in the opaque version that method gets called more than twice as
frequently than the transparent version.
How is it possible to obtain the same refresh rate as with the opaque window? I
know that, since the window is transparent, it backs up to the first opaque
ancestor during the redraw, but quick time player x is fast and smooth during
resize even though it has rounded corners (and therefore has transparent
corners).
Is there a way to make the NSWindow to be partially opaque and partially
transparent? I've tried to play with
-(void)displayRectIgnoringOpacity:(NSRect)aRect but without success.
Thank you
Andrea
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]