Patches backported from trunk.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_stable_20070311@25587 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2007-11-17 16:05:47 +00:00
parent 99c6b7e28e
commit bad8642e29
18 changed files with 1207 additions and 874 deletions

View file

@ -27,6 +27,7 @@
*/
#include <AppKit/NSAnimation.h>
#include <GNUstepBase/GSLock.h>
#include <Foundation/NSNotification.h>
#include <Foundation/NSValue.h>
#include <Foundation/NSException.h>
@ -115,9 +116,10 @@ _GSRationalBezierEval (_GSRationalBezierDesc *rb, float t)
static inline float
_GSRationalBezierDerivEval (_GSRationalBezierDesc *rb, float t)
{
float h;
if (!rb->areBezierDescComputed)
_GSRationalBezierComputeBezierDesc (rb);
float h = _GSBezierEval (&(rb->d),t);
h = _GSBezierEval (&(rb->d),t);
return ( _GSBezierDerivEval(&(rb->n),t) * h
- _GSBezierEval (&(rb->n),t) * _GSBezierDerivEval(&(rb->d),t) )
/ (h*h);
@ -176,22 +178,36 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
return (NSComparisonResult)(diff / fabs (diff));
}
/* Thread locking/unlocking support macros.
* _isThreaded flag is an ivar that records whether the
* NSAnimation is running in thread mode.
* __gs_isLocked flag is local to each method and records
* whether the thread is locked and must be locked before
* the method exits.
* Both are needed because _isThreaded is reset when the
* NSAnimation stops : that may happen at any time between
* a lock/unlock pair.
*/
#define _NSANIMATION_LOCKING_SETUP \
BOOL __gs_isLocked = NO;
#define _NSANIMATION_LOCK \
BOOL __gs_isLocked = NO; \
if (_isThreaded) \
{ \
__gs_isLocked = YES; \
NSAssert(__gs_isLocked == NO, NSInternalInconsistencyException); \
NSDebugFLLog(@"NSAnimationLock",\
@"%@ LOCK %@",self,[NSThread currentThread]);\
[_isAnimatingLock lock]; \
}
__gs_isLocked = YES; \
}
#define _NSANIMATION_UNLOCK \
if (__gs_isLocked) \
{ \
__gs_isLocked = YES; \
/* NSAssert(__gs_isLocked == YES, NSInternalInconsistencyException); */ \
NSDebugFLLog(@"NSAnimationLock",\
@"%@ UNLOCK %@",self,[NSThread currentThread]);\
__gs_isLocked = NO; \
[_isAnimatingLock unlock]; \
}
@ -212,11 +228,13 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) addProgressMark: (NSAnimationProgress)progress
{
_NSANIMATION_LOCKING_SETUP;
if (progress < 0.0) progress = 0.0;
if (progress > 1.0) progress = 1.0;
_NSANIMATION_LOCK;
_NSANIMATION_LOCK;
if (GSIArrayCount(_progressMarks) == 0)
{ // First mark
GSIArrayAddItem (_progressMarks,progress);
@ -248,6 +266,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (NSAnimationBlockingMode) animationBlockingMode
{
NSAnimationBlockingMode m;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
m = _blockingMode;
_NSANIMATION_UNLOCK;
@ -257,6 +277,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (NSAnimationCurve) animationCurve
{
NSAnimationCurve c;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
c = _curve;
_NSANIMATION_UNLOCK;
@ -265,6 +287,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) clearStartAnimation
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
[[NSNotificationCenter defaultCenter]
removeObserver: self
@ -277,6 +301,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) clearStopAnimation
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
[[NSNotificationCenter defaultCenter]
removeObserver: self
@ -290,6 +316,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (NSAnimationProgress) currentProgress
{
NSAnimationProgress p;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
p = _currentProgress;
_NSANIMATION_UNLOCK;
@ -299,6 +327,7 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (float) currentValue
{
float value;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
@ -344,6 +373,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (id) delegate
{
id d;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
d = (_delegate == nil)? nil : GS_GC_UNHIDE (_delegate);
_NSANIMATION_UNLOCK;
@ -353,6 +384,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (NSTimeInterval) duration
{
NSTimeInterval d;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
d = _duration;
_NSANIMATION_UNLOCK;
@ -362,6 +395,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (float) frameRate
{
float f;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
f = _frameRate;
_NSANIMATION_UNLOCK;
@ -410,7 +445,7 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
(BOOL (*)(id,SEL,NSAnimation*)) NULL;
_isThreaded = NO;
_isAnimatingLock = [[NSRecursiveLock alloc] init];
_isAnimatingLock = [GSLazyRecursiveLock new];
}
return self;
}
@ -447,6 +482,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (BOOL) isAnimating
{
BOOL f;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
f = (_animator != nil)? [_animator isAnimationRunning] : NO;
_NSANIMATION_UNLOCK;
@ -456,10 +493,12 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (NSArray*) progressMarks
{
NSNumber **cpmn;
unsigned count;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
unsigned count = GSIArrayCount (_progressMarks);
count = GSIArrayCount (_progressMarks);
if (!_isCachedProgressMarkNumbersValid)
{
@ -494,9 +533,12 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) removeProgressMark: (NSAnimationProgress)progress
{
unsigned index;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
unsigned index = GSIArraySearch (_progressMarks,progress,nsanimation_progressMarkSorter);
index = GSIArraySearch (_progressMarks,progress,nsanimation_progressMarkSorter);
if ( index < GSIArrayCount(_progressMarks)
&& progress == GSIArrayItemAtIndex (_progressMarks,index) )
{
@ -518,6 +560,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) setAnimationBlockingMode: (NSAnimationBlockingMode)mode
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
_isANewAnimatorNeeded |= (_blockingMode != mode);
_blockingMode = mode;
@ -526,6 +570,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) setAnimationCurve: (NSAnimationCurve)curve
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
if (_currentProgress <= 0.0f || _currentProgress >= 1.0f)
@ -589,6 +635,7 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
{
BOOL needSearchNextMark = NO;
NSAnimationProgress markedProgress;
_NSANIMATION_LOCKING_SETUP;
if (progress < 0.0) progress = 0.0;
if (progress > 1.0) progress = 1.0;
@ -636,6 +683,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) setDelegate: (id)delegate
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
_delegate = (delegate == nil)? nil : GS_GC_HIDE (delegate);
_NSANIMATION_UNLOCK;
@ -643,6 +692,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) setDuration: (NSTimeInterval)duration
{
_NSANIMATION_LOCKING_SETUP;
if (duration<=0.0)
[NSException raise: NSInvalidArgumentException
format: @"%@ Duration must be > 0.0 (passed: %f)",self,duration];
@ -653,6 +704,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) setFrameRate: (float)fps
{
_NSANIMATION_LOCKING_SETUP;
if (fps<0.0)
[NSException raise: NSInvalidArgumentException
format: @"%@ Framerate must be >= 0.0 (passed: %f)",self,fps];
@ -670,6 +723,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) setProgressMarks: (NSArray*)marks
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
GSIArrayEmpty (_progressMarks);
_nextMark = 0;
@ -685,12 +740,13 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) startAnimation
{
unsigned i;
if ([self isAnimating])
return;
NSDebugFLLog (@"NSAnimationStart",@"%@",self);
unsigned i;
for (i=0; i<GSIArrayCount(_progressMarks); i++)
NSDebugFLLog (@"NSAnimationMark",
@"%@ Mark #%d : %f",
@ -707,10 +763,11 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
if (_delegate != nil)
{
id delegate;
NSDebugFLLog (@"NSAnimationDelegate",
@"%@ Cache delegation methods",self);
// delegation methods are cached while the animation is running
id delegate;
delegate = GS_GC_UNHIDE (_delegate);
_delegate_animationDidReachProgressMark =
([delegate respondsToSelector: @selector (animation:didReachProgressMark:)]) ?
@ -807,6 +864,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) startWhenAnimation: (NSAnimation*)animation
reachesProgress: (NSAnimationProgress)start
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
_startAnimation = animation;
@ -825,6 +884,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) stopAnimation
{
_NSANIMATION_LOCKING_SETUP;
if ([self isAnimating])
{
_NSANIMATION_LOCK;
@ -836,6 +897,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) stopWhenAnimation: (NSAnimation*)animation
reachesProgress: (NSAnimationProgress)stop
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
_stopAnimation = animation;
@ -868,11 +931,13 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) animatorDidStart
{
id delegate;
_NSANIMATION_LOCKING_SETUP;
NSDebugFLLog (@"NSAnimationAnimator",@"%@",self);
_NSANIMATION_LOCK;
id delegate;
delegate = GS_GC_UNHIDE (_currentDelegate);
if (_delegate_animationShouldStart) // method is cached (the animation is running)
@ -887,11 +952,13 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) animatorDidStop
{
id delegate;
_NSANIMATION_LOCKING_SETUP;
NSDebugFLLog (@"NSAnimationAnimator",@"%@ Progress = %f",self,_currentProgress);
_NSANIMATION_LOCK;
id delegate;
delegate = GS_GC_UNHIDE (_currentDelegate);
if (_currentProgress < 1.0)
{
@ -916,11 +983,14 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) animatorStep: (NSTimeInterval) elapsedTime;
{
NSAnimationProgress progress;
_NSANIMATION_LOCKING_SETUP;
NSDebugFLLog (@"NSAnimationAnimator",@"%@ Elapsed time : %f",self,elapsedTime);
_NSANIMATION_LOCK;
NSAnimationProgress progress = (elapsedTime / _duration);
progress = (elapsedTime / _duration);
{ // have some marks been passed ?
// NOTE: the case where progress == markedProgress is
@ -945,14 +1015,17 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) _gs_startAnimationReachesProgressMark: (NSNotification*)notification
{
NSAnimation *animation = [notification object];
NSAnimationProgress mark
= [[[notification userInfo] objectForKey: NSAnimationProgressMark] floatValue];
NSAnimation *animation;
NSAnimationProgress mark;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
animation = [notification object];
mark = [[[notification userInfo] objectForKey: NSAnimationProgressMark] floatValue];
NSDebugFLLog (@"NSAnimationMark",
@"%@ Start Animation %@ reaches %f",self,animation,mark);
_NSANIMATION_LOCK;
if ( animation == _startAnimation && mark == _startMark)
{
// [self clearStartAnimation];
@ -962,15 +1035,20 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
_NSANIMATION_UNLOCK;
}
- (void) _gs_stopAnimationReachesProgressMark: (NSNotification*)notification
{
NSAnimation *animation = [notification object];
NSAnimationProgress mark
= [[[notification userInfo] objectForKey: NSAnimationProgressMark] floatValue];
NSAnimation *animation;
NSAnimationProgress mark;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
animation = [notification object];
mark = [[[notification userInfo] objectForKey: NSAnimationProgressMark] floatValue];
NSDebugFLLog (@"NSAnimationMark",
@"%@ Stop Animation %@ reaches %f",self,animation,mark);
_NSANIMATION_LOCK;
if ( animation == _stopAnimation && mark == _stopMark)
{
@ -987,6 +1065,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) _gs_didReachProgressMark: (NSAnimationProgress) progress
{
_NSANIMATION_LOCKING_SETUP;
NSDebugFLLog (@"NSAnimationMark",@"%@ progress %f",self, progress);
_NSANIMATION_LOCK;
@ -1074,6 +1154,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (unsigned int) frameCount
{
unsigned c;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
c = (_animator != nil)? [_animator frameCount] : 0;
_NSANIMATION_UNLOCK;
@ -1082,6 +1164,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (void) resetCounters
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
if (_animator != nil) [_animator resetCounters];
_NSANIMATION_UNLOCK;
@ -1090,6 +1174,8 @@ nsanimation_progressMarkSorter ( NSAnimationProgress first,NSAnimationProgress s
- (float) actualFrameRate;
{
float r;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
r = (_animator != nil)? [_animator frameRate] : 0.0;
_NSANIMATION_UNLOCK;
@ -1314,6 +1400,8 @@ NSString *NSViewAnimationFadeOutEffect = @"NSViewAnimationFadeOutEffect";
- (void) setViewAnimations: (NSArray*)animations
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
if (_viewAnimations != animations)
DESTROY (_viewAnimationDesc);
@ -1324,6 +1412,8 @@ NSString *NSViewAnimationFadeOutEffect = @"NSViewAnimationFadeOutEffect";
- (NSArray*) viewAnimations
{
NSArray *a;
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
a = _viewAnimations;
_NSANIMATION_UNLOCK;
@ -1332,6 +1422,8 @@ NSString *NSViewAnimationFadeOutEffect = @"NSViewAnimationFadeOutEffect";
- (void) startAnimation
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
if (_viewAnimationDesc == nil)
{
@ -1351,6 +1443,8 @@ NSString *NSViewAnimationFadeOutEffect = @"NSViewAnimationFadeOutEffect";
- (void) stopAnimation
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
[super stopAnimation];
[self setCurrentProgress: 1.0];
@ -1371,6 +1465,8 @@ NSString *NSViewAnimationFadeOutEffect = @"NSViewAnimationFadeOutEffect";
- (void) setCurrentProgress: (NSAnimationProgress)progress
{
_NSANIMATION_LOCKING_SETUP;
_NSANIMATION_LOCK;
[super setCurrentProgress: progress];
[self performSelectorOnMainThread: @selector (_gs_updateViewsWithValue:)