gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSView caching of isFlipped


From: Quentin Mathé
Subject: Re: NSView caching of isFlipped
Date: Sat, 31 Jul 2010 02:08:22 +0200

Hi Derek,

Le 31 juil. 2010 à 00:10, Derek Fawcus a écrit :

I came across an interesting effect due to the above,  namely a
flipped view with the incorrect behaviour.

This was in part defined as:

@interface TextView: NSView
{
       BOOL _flipped;
        /* other fields ... */
}
- (id) initWithFrame:(NSRect)frameRect andStorage:(NSTextStorage *) storage isFlipped:(BOOL)flipped;
@end

@implementation TextView
- (BOOL)isFlipped
{
       return _flipped;
}

- (id)initWithFrame:(NSRect)frameRect
        andStorage:(NSTextStorage *)storage
        isFlipped:(BOOL)flipped
{
       if (![super initWithFrame:(NSRect)frameRect])
               return nil;

       _flipped = flipped;

        /* other stuff ... */
}

Then due to the effect of +alloc (zeros memory) and the above,
any view which was supposed to be flipped was not.
After spending quite a bit of time trying to figure out why the
program did not operate correctly on GS,  whereas it did no OSX
and OPENSTEP,  the workaround was eventually simple,  namely to
move the assignment before the [super initWithFrame].

You could alternatively call the private methods - _invalidateCoordinates then -_rebuildCoordinates. But that's not better I admit. To support -setFlipped: method or similar that changes the flipping on the fly, there is no other way though.

Here is the not-so-pretty trick I use:
- (BOOL) isFlipped
{
#ifdef GNUSTEP
        return _rFlags.flipped_view;
#else /* Mac OS X */
        return _flipped;
#endif
}

- (void) setFlipped: (BOOL)flag
{
#ifdef GNUSTEP
        _rFlags.flipped_view = flag;
        [self _invalidateCoordinates];
        [self _rebuildCoordinates];
#else /* Mac OS X */
        _flipped = flag;
#endif
}

So - how much of a performance gain do we get from caching the
flipped status in NSView?  If it is significant,  then is there
any way that the value could be sampled upon the first message
sent _after_ init?  Or should the caching simply be removed?

I submitted a patch (which needs improvements iirc) a while ago about this -isFlipped issue: http://savannah.gnu.org/patch/?6630 I'm in favor of removing the caching completely since there is nothing in Cocoa doc that states -isFlipped return value must be constant. In my tests, Mac OS X reacts transparently to -isFlipped value change at any time.

I don't know what the performance impact would be. But I have been writing drawing code that abuses message sending a lot and it isn't that slow on GNUstep. Although GNUstep drawing is a lot slower than Cocoa and I don't know why precisely.

In future, libobjc2 and clang should also be able to easily inline methods such as -isFlipped.

Cheers,
Quentin.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]