Revision: 12272
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=12272&view=rev
Author: amaxwell
Date: 2008-01-05 09:28:51 -0800 (Sat, 05 Jan 2008)
Log Message:
-----------
Hold the lock in the PDF icon while it's rendering, so needsRenderForSize: will
return NO during that time. This avoids a race where renderOffscreen could be
sent twice.
Use a BOOL flag to accomplish the same thing for text and image icons. It may
be better just to hold the lock for the text icon as well.
Modified Paths:
--------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageIcon.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageIcon.m
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageIcon.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageIcon.h 2008-01-05
17:24:35 UTC (rev 12271)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageIcon.h 2008-01-05
17:28:51 UTC (rev 12272)
@@ -49,6 +49,7 @@
CGImageRef _fullImageRef;
NSSize _fullSize;
FVIconType _iconType;
+ BOOL _isRendering;
BOOL _inDiskCache;
char *_diskCacheName;
BOOL _drawsLinkBadge;
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageIcon.m 2008-01-05
17:24:35 UTC (rev 12271)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVCGImageIcon.m 2008-01-05
17:28:51 UTC (rev 12272)
@@ -67,6 +67,8 @@
_thumbnailRef = NULL;
_diskCacheName = FVCreateDiskCacheNameWithURL(_fileURL);
_inDiskCache = NO;
+ _isRendering = NO;
+
NSInteger rc = pthread_mutex_init(&_mutex, NULL);
_drawsLinkBadge = [[self class] _shouldDrawBadgeForURL:aURL];
@@ -123,9 +125,9 @@
BOOL needsRender = NO;
if (pthread_mutex_trylock(&_mutex) == 0) {
if (size.height > _thumbnailSize.height)
- needsRender = (NULL == _fullImageRef);
+ needsRender = (NULL == _fullImageRef && NO == _isRendering);
else
- needsRender = (NULL == _thumbnailRef);
+ needsRender = (NULL == _thumbnailRef && NO == _isRendering);
pthread_mutex_unlock(&_mutex);
}
return needsRender;
@@ -173,6 +175,8 @@
return;
}
}
+
+ _isRendering = YES;
pthread_mutex_unlock(&_mutex);
CGImageSourceRef src;
@@ -189,8 +193,9 @@
src = CGImageSourceCreateWithURL((CFURLRef)_fileURL, __imsrcOptions);
}
+ pthread_mutex_lock(&_mutex);
+
if (src) {
- pthread_mutex_lock(&_mutex);
CGImageRelease(_thumbnailRef);
CGImageRelease(_fullImageRef);
CGImageRef bigImage = CGImageSourceCreateImageAtIndex(src, 0,
__imsrcOptions);
@@ -207,9 +212,11 @@
_thumbnailRef = CGImageSourceCreateThumbnailAtIndex(src, 0,
__imsrcOptions);
_thumbnailSize = _thumbnailRef ?
NSMakeSize(CGImageGetWidth(_thumbnailRef), CGImageGetHeight(_thumbnailRef)) :
NSZeroSize;
_fullSize = _fullImageRef ? NSMakeSize(CGImageGetWidth(_fullImageRef),
CGImageGetHeight(_fullImageRef)) : NSZeroSize;
- pthread_mutex_unlock(&_mutex);
CFRelease(src);
}
+
+ _isRendering = NO;
+ pthread_mutex_unlock(&_mutex);
}
- (void)fastDrawInRect:(NSRect)dstRect inCGContext:(CGContextRef)context;
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m 2008-01-05
17:24:35 UTC (rev 12271)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m 2008-01-05
17:28:51 UTC (rev 12272)
@@ -288,7 +288,6 @@
if (NULL == _thumbnailRef) {
- pthread_mutex_unlock(&_mutex);
CGContextRef ctxt =
FVIconBitmapContextCreateWithSize(_thumbnailSize.width, _thumbnailSize.height);
// set a white page background
@@ -297,8 +296,6 @@
CGContextClipToRect(ctxt, pageRect);
CGContextFillRect(ctxt, pageRect);
- // now hold the lock until we finish
- pthread_mutex_lock(&_mutex);
if (_pdfPage) {
// always downscaling, so CGPDFPageGetDrawingTransform is okay to
use here
CGAffineTransform t = CGPDFPageGetDrawingTransform(_pdfPage,
kCGPDFCropBox, pageRect, 0, true);
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h 2008-01-05
17:24:35 UTC (rev 12271)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h 2008-01-05
17:28:51 UTC (rev 12272)
@@ -50,6 +50,7 @@
NSURL *_fileURL;
BOOL _inDiskCache;
char *_diskCacheName;
+ BOOL _isRendering;
BOOL _drawsLinkBadge;
pthread_mutex_t _mutex;
}
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m 2008-01-05
17:24:35 UTC (rev 12271)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m 2008-01-05
17:28:51 UTC (rev 12272)
@@ -158,6 +158,7 @@
_thumbnailRef = NULL;
_inDiskCache = NO;
_diskCacheName = FVCreateDiskCacheNameWithURL(_fileURL);
+ _isRendering = NO;
NSInteger rc = pthread_mutex_init(&_mutex, NULL);
if (rc)
@@ -183,9 +184,9 @@
// if we can't lock we're already rendering, which will give us both icons
(so no render required)
if (pthread_mutex_trylock(&_mutex) == 0) {
if (size.height < _thumbnailSize.height * 1.2)
- needsRender = (NULL == _thumbnailRef);
+ needsRender = (NULL == _thumbnailRef && NO == _isRendering);
else
- needsRender = (NULL == _fullImageRef);
+ needsRender = (NULL == _fullImageRef && NO == _isRendering);
pthread_mutex_unlock(&_mutex);
}
return needsRender;
@@ -249,6 +250,9 @@
return;
}
}
+
+ // set a flag instead of holding the lock the entire time, since we don't
use mutable ivars until later
+ _isRendering = YES;
pthread_mutex_unlock(&_mutex);
// definitely use the context cache for this, since these bitmaps are
pretty huge
@@ -359,9 +363,7 @@
// reset size while we have the lock, since it may be different now that
we've read the string
_fullSize = paperSize;
_thumbnailSize = NSMakeSize(_fullSize.width / 2, _fullSize.height / 2);
-
- pthread_mutex_unlock(&_mutex);
-
+
// now restore our cached bitmap context and push it back into the cache
CGContextRestoreGState(ctxt);
[FVBitmapContextCache disposeOfBitmapContext:ctxt];
@@ -377,19 +379,17 @@
stringRect.origin = NSZeroPoint;
stringRect.size = _thumbnailSize;
- pthread_mutex_lock(&_mutex);
if (_fullImageRef) {
CGContextDrawImage(ctxt, *(CGRect *)&stringRect, _fullImageRef);
CGImageRelease(_thumbnailRef);
_thumbnailRef = CGBitmapContextCreateImage(ctxt);
}
- pthread_mutex_unlock(&_mutex);
CGContextRestoreGState(ctxt);
[FVBitmapContextCache disposeOfBitmapContext:ctxt];
}
-
-
+ _isRendering = NO;
+ pthread_mutex_unlock(&_mutex);
}
@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit