Revision: 25375 http://sourceforge.net/p/bibdesk/svn/25375 Author: hofman Date: 2021-01-12 22:33:11 +0000 (Tue, 12 Jan 2021) Log Message: ----------- Pass desired size for icon in render method rather than keeping it in an ivar
Modified Paths: -------------- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderIcon.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.h trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconOperation.h trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconOperation.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.h trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMIMEIcon.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.h trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.h trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVScaledImageView.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.h trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m trunk/bibdesk_vendorsrc/amaxwell/FileView/Notes Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -1881,7 +1881,7 @@ for (i = 0; i < iMax; i++) { icon = [icons objectAtIndex:i]; if ([icon needsRenderForSize:size]) { - FVRenderOperation *op = [[FVRenderOperation alloc] initWithIcon:icon view:self]; + FVRenderOperation *op = [[FVRenderOperation alloc] initWithIcon:icon view:self size:size]; [op setQueuePriority:priority]; [operations addObject:op]; [op release]; @@ -2285,7 +2285,7 @@ } if ([unusedIndexes count]) { - // Since the same FVIcon instance is returned for duplicate URLs, the same icon instance may receive -renderOffscreen and -releaseResources in the same pass if it represents a visible icon and a hidden icon. + // Since the same FVIcon instance is returned for duplicate URLs, the same icon instance may receive -renderOffscreenForSize; and -releaseResources in the same pass if it represents a visible icon and a hidden icon. NSSet *renderSet = [[NSSet alloc] initWithArray:iconsToRender]; NSMutableArray *unusedIcons = [[self iconsAtIndexes:unusedIndexes] mutableCopy]; NSUInteger i = [unusedIcons count]; @@ -3018,7 +3018,7 @@ NSSize size = [self respondsToSelector:@selector(convertSizeToBacking:)] ? [self convertSizeToBacking:_iconSize] : _iconSize; // render immediately so the placeholder path doesn't draw if ([anIcon needsRenderForSize:size]) - [anIcon renderOffscreen]; + [anIcon renderOffscreenForSize:size]; [self _setNeedsDisplayForIconInRow:r column:c]; } } Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderIcon.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderIcon.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderIcon.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -114,7 +114,7 @@ return NO; } -- (void)renderOffscreen +- (void)renderOffscreenForSize:(NSSize)size { // no-op } Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.h =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.h 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.h 2021-01-12 22:33:11 UTC (rev 25375) @@ -43,7 +43,7 @@ FVIcon is a class cluster. You should typically never receive an instance of FVIcon from its initializer, but will instead get an instance of a concrete subclass that correctly handles a given URL scheme or file type. - The iconWithURL: factory method is designed to be cheap, in that it does no rendering, should will require very little memory or disk access just for initialization. Only after calling renderOffscreen will memory usage increase substantially, as data is cached and bitmaps created. Icons that won't be displayed for some time (scrolled out of sight) should be sent a releaseResources message by the view in order to free up (some) of the cached data. Subsequent calls to renderOffscreen should be substantially less expensive, since data will be read from the disk cache. + The iconWithURL: factory method is designed to be cheap, in that it does no rendering, should will require very little memory or disk access just for initialization. Only after calling renderOffscreenForSize: will memory usage increase substantially, as data is cached and bitmaps created. Icons that won't be displayed for some time (scrolled out of sight) should be sent a releaseResources message by the view in order to free up (some) of the cached data. Subsequent calls to renderOffscreenForSize: should be substantially less expensive, since data will be read from the disk cache. This class is thread safe, but it is not reentrant. You can abuse it to create deadlocks. Don't do that. */ @interface FVIcon : FVObject @@ -52,8 +52,11 @@ Draws the icon into an offscreen bitmap context. Subclasses must override this. - This is typically the most expensive call for an FVIcon subclass. In general it should be called from a dedicated thread after needsRenderForSize: has been called, unless you're planning to draw synchronously. This is required for correct drawing, since a placeholder will typically be drawn if the bitmap is not available. */ -- (void)renderOffscreen; + This is typically the most expensive call for an FVIcon subclass. In general it should be called from a dedicated thread after needsRenderForSize: has been called, unless you're planning to draw synchronously. This is required for correct drawing, since a placeholder will typically be drawn if the bitmap is not available. + + @param size The desired icon size in pixels. Subclasses are free to ignore this. +*/ +- (void)renderOffscreenForSize:(NSSize)size; /** Primitive drawing method. @@ -64,8 +67,8 @@ \li \c any changes to the CGContextRef are wrapped by CGContextSaveGState/CGContextRestoreGState \li \c specific compositing operations should be set in the context before calling this method \li \c shadow will be respected (the clip path is only changed when rendering text) - \li \c needsRenderForSize: and renderOffscreen must be called first, to check/set size - \li \c a placeholder icon will be drawn if renderOffscreen has not been called or finished working + \li \c needsRenderForSize: and renderOffscreenForSize: must be called first, to check/set size + \li \c a placeholder icon will be drawn if renderOffscreenForSize: has not been called or finished working @param dstRect Destination rect for drawing in the passed-in context's coordinate space. @param context CGContext for drawing content. */ @@ -85,9 +88,9 @@ @return NO if releaseResources will be a no-op or otherwise is not possible. */ - (BOOL)canReleaseResources; -/** Determine if renderOffscreen is required. +/** Determine if renderOffscreenForSize: is required. - Clients (i.e. FileView) calls this in order to see if renderOffscreen should be called. If it returns YES, this method sets the desired size in the case of Finder icons, and the caller should then send renderOffscreen. By the same token, if this returns NO, don't waste time on renderOffscreen. + Clients (i.e. FileView) calls this in order to see if renderOffscreenForSize: should be called. If it returns YES, this method sets the desired size in the case of Finder icons, and the caller should then send renderOffscreenForSize:. By the same token, if this returns NO, don't waste time on renderOffscreenForSize:. @param size The desired icon size in pixels. Subclasses are free to ignore this. @return NO if the icon already has a cached version for this size. */ @@ -102,7 +105,7 @@ /** Purge bitmap caches. - Optional override. Get rid of any cached representations; next time the icon is redrawn, its data will be recreated in renderOffscreen. */ + Optional override. Get rid of any cached representations; next time the icon is redrawn, its data will be recreated in renderOffscreenForSize:. */ - (void)recache; @end @@ -121,22 +124,22 @@ /** Increments the internal page index. - This does not redisplay the icon; needsRenderForSize: and renderOffscreen must be called to redraw. */ + This does not redisplay the icon; needsRenderForSize: and renderOffscreenForSize: must be called to redraw. */ - (void)showNextPage; /** Decrements the internal page index. - This does not redisplay the icon; needsRenderForSize: and renderOffscreen must be called to redraw. */ + This does not redisplay the icon; needsRenderForSize: and renderOffscreenForSize: must be called to redraw. */ - (void)showPreviousPage; /** Set the internal page index to 1. - This does not redisplay the icon; needsRenderForSize: and renderOffscreen must be called to redraw. */ + This does not redisplay the icon; needsRenderForSize: and renderOffscreenForSize: must be called to redraw. */ - (void)showFirstPage; /** Set the internal page index to the last page. - This does not redisplay the icon; needsRenderForSize: and renderOffscreen must be called to redraw. */ + This does not redisplay the icon; needsRenderForSize: and renderOffscreenForSize: must be called to redraw. */ - (void)showLastPage; @end Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -80,7 +80,7 @@ // these methods are all required - (void)drawInRect:(NSRect)dstRect ofContext:(CGContextRef)context { [self doesNotRecognizeSelector:_cmd]; } -- (void)renderOffscreen { [self doesNotRecognizeSelector:_cmd]; } +- (void)renderOffscreenForSize:(NSSize)size { [self doesNotRecognizeSelector:_cmd]; } @end Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconOperation.h =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconOperation.h 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconOperation.h 2021-01-12 22:33:11 UTC (rev 25375) @@ -57,4 +57,12 @@ @end @interface FVRenderOperation : FVIconOperation +{ +@protected; + NSSize _desiredSize; +} + +// designated initializer; uses @selector(iconUpdated:) as callback (sent to view with icon as argument) +- (id)initWithIcon:(FVIcon *)icon view:(FVFileView *)view size:(NSSize)size; + @end Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconOperation.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconOperation.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconOperation.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -116,11 +116,20 @@ @implementation FVRenderOperation +- (id)initWithIcon:(FVIcon *)icon view:(FVFileView *)view size:(NSSize)size; +{ + self = [super initWithIcon:icon view:view]; + if (self) { + _desiredSize = size; + } + return self; +} + - (void)main; { if (NO == [self isCancelled]) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; - [_icon renderOffscreen]; + [_icon renderOffscreenForSize:_desiredSize]; FVIconUpdateOperation *op = [[FVIconUpdateOperation alloc] initWithIcon:_icon view:_view]; [[FVOperationQueue mainQueue] addOperation:op]; [op release]; Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.h =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.h 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.h 2021-01-12 22:33:11 UTC (rev 25375) @@ -45,7 +45,6 @@ CGImageRef _thumbnail; NSSize _thumbnailSize; CGImageRef _fullImage; - NSSize _desiredSize; BOOL _loadFailed; FVIcon *_fallbackIcon; } Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -129,7 +129,6 @@ needsRender = (NULL == _fullImage); else needsRender = (NULL == _thumbnail); - _desiredSize = size; [self unlock]; } return needsRender; @@ -141,7 +140,7 @@ return (CFDataRef)[[NSData allocWithZone:FVDefaultZone()] initWithContentsOfURL:_fileURL options:NSUncachedRead error:NULL]; } -- (void)renderOffscreen +- (void)renderOffscreenForSize:(NSSize)size { [[self class] _startRenderingForKey:_cacheKey]; @@ -150,11 +149,11 @@ if ([NSThread instancesRespondToSelector:@selector(setName:)] && pthread_main_np() == 0) [[NSThread currentThread] setName:[_fileURL path]]; - [_fallbackIcon renderOffscreen]; + [_fallbackIcon renderOffscreenForSize:size]; // !!! early returns here after a cache check if (NULL != _fullImage && NULL != _thumbnail) { - // may be non-NULL if we were added to the FVOperationQueue multiple times before renderOffscreen was actually called + // may be non-NULL if we were added to the FVOperationQueue multiple times before renderOffscreenForSize: was actually called [self unlock]; [[self class] _stopRenderingForKey:_cacheKey]; return; @@ -173,7 +172,7 @@ NSParameterAssert(NSEqualSizes(_thumbnailSize, NSZeroSize) == NO); - if (FVShouldDrawFullImageWithThumbnailSize(_desiredSize, _thumbnailSize) && NULL == _fullImage) { + if (FVShouldDrawFullImageWithThumbnailSize(size, _thumbnailSize) && NULL == _fullImage) { _fullImage = [FVCGImageCache newImageForKey:_cacheKey]; if (_fullImage) { [self unlock]; @@ -232,7 +231,7 @@ } // dispose of this immediately if we're not going to draw it; we can read from the cache if it's needed later - if (FVShouldDrawFullImageWithThumbnailSize(_desiredSize, _thumbnailSize) == NO) { + if (FVShouldDrawFullImageWithThumbnailSize(size, _thumbnailSize) == NO) { CGImageRelease(_fullImage); _fullImage = NULL; } Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMIMEIcon.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMIMEIcon.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMIMEIcon.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -90,7 +90,7 @@ - (void)lock { /* do nothing */ } - (void)unlock { /* do nothing */ } -- (void)renderOffscreen { /* no-op */ } +- (void)renderOffscreenForSize:(NSSize)size { /* no-op */ } - (NSSize)size { return FVDefaultThumbnailSize(); } Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.h =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.h 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.h 2021-01-12 22:33:11 UTC (rev 25375) @@ -48,7 +48,6 @@ NSSize _fullSize; CGImageRef _thumbnail; NSSize _thumbnailSize; - NSSize _desiredSize; NSUInteger _currentPage; NSUInteger _pageCount; } Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -137,7 +137,6 @@ _isMapped = NO; _pdfPage = NULL; _thumbnail = NULL; - _desiredSize = NSZeroSize; // must be > 1 to be valid _currentPage = 1; @@ -310,7 +309,7 @@ CGContextDrawLayerInRect(ctxt, lockRect, layer); } -- (void)renderOffscreen +- (void)renderOffscreenForSize:(NSSize)size { [[self class] _startRenderingForKey:_cacheKey]; // hold the lock while initializing these variables, so we don't waste time trying to render again, since we may be returning YES from needsRender @@ -321,7 +320,7 @@ // only the first page is cached to disk; ignore this branch if we should be drawing a later page or if the size has changed - // handle the case where multiple render tasks were pushed into the queue before renderOffscreen was called + // handle the case where multiple render tasks were pushed into the queue before renderOffscreenForSize: was called if ((NULL != _thumbnail || NULL != _pdfDoc) && 1 == _currentPage) { BOOL exitEarly; @@ -328,7 +327,7 @@ // if _thumbnail is non-NULL, we're guaranteed that _thumbnailSize has been initialized correctly // always want _thumbnail for the fast drawing path - if (FVShouldDrawFullImageWithThumbnailSize(_desiredSize, _thumbnailSize)) + if (FVShouldDrawFullImageWithThumbnailSize(size, _thumbnailSize)) exitEarly = (NULL != _pdfDoc && NULL != _pdfPage && NULL != _thumbnail); else exitEarly = (NULL != _thumbnail); @@ -358,7 +357,7 @@ } [desc release]; NSParameterAssert(_thumbnailSize.width > 0 && _thumbnailSize.height > 0); - exitEarly = NO == FVShouldDrawFullImageWithThumbnailSize(_desiredSize, _thumbnailSize) && _pageCount > 0; + exitEarly = NO == FVShouldDrawFullImageWithThumbnailSize(size, _thumbnailSize) && _pageCount > 0; } // !!! early return @@ -462,9 +461,6 @@ [[self class] _removeIconForMappedRelease:self]; BOOL needsRender = NO; if ([self tryLock]) { - // tells the render method if work is needed - _desiredSize = size; - // If we're drawing full size, don't bother loading the thumbnail if we have a PDFPage. It can be quicker just to draw the page if the document is already loaded, rather than loading the thumbnail from cache. if (FVShouldDrawFullImageWithThumbnailSize(size, _thumbnailSize)) needsRender = (NULL == _pdfPage); Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.h =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.h 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.h 2021-01-12 22:33:11 UTC (rev 25375) @@ -45,7 +45,6 @@ CGImageRef _fullImage; CGImageRef _thumbnail; NSSize _thumbnailSize; - NSSize _desiredSize; FVIcon *_fallbackIcon; BOOL _quickLookFailed; CGColorRef _backgroundColor; Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -91,7 +91,6 @@ _fallbackIcon = [FVFinderIcon newWithURL:aURL drawsLinkBadge:drawsLinkBadge]; _fullImage = NULL; _thumbnailSize = NSZeroSize; - _desiredSize = NSZeroSize; _quickLookFailed = NO; CGFloat color[4]; if ([[self class] _getBackgroundColor:color forURL:_fileURL]) @@ -151,13 +150,12 @@ else { needsRender = [_fallbackIcon needsRenderForSize:size]; } - _desiredSize = size; [self unlock]; } return needsRender; } -- (void)renderOffscreen +- (void)renderOffscreenForSize:(NSSize)size { [self lock]; @@ -178,15 +176,15 @@ // always initialize sizes _thumbnailSize = _thumbnail ? FVCGImageSize(_thumbnail) : NSZeroSize; - if (NSEqualSizes(NSZeroSize, _thumbnailSize) == NO && FVShouldDrawFullImageWithThumbnailSize(_desiredSize, _thumbnailSize)) { + if (NSEqualSizes(NSZeroSize, _thumbnailSize) == NO && FVShouldDrawFullImageWithThumbnailSize(size, _thumbnailSize)) { - if (NULL != _fullImage && __FVQLShouldDrawFullImageWithSize(_desiredSize, FVCGImageSize(_fullImage))) { + if (NULL != _fullImage && __FVQLShouldDrawFullImageWithSize(size, FVCGImageSize(_fullImage))) { CGImageRelease(_fullImage); _fullImage = NULL; } if (NULL == _fullImage) { - requestedSize = NSSizeToCGSize(_desiredSize); + requestedSize = NSSizeToCGSize(size); _fullImage = QLThumbnailImageCreate(NULL, (CFURLRef)_fileURL, requestedSize, NULL); } @@ -197,8 +195,8 @@ // preceding calls may have set the failure flag if (_quickLookFailed) { - if ([_fallbackIcon needsRenderForSize:_desiredSize]) - [_fallbackIcon renderOffscreen]; + if ([_fallbackIcon needsRenderForSize:size]) + [_fallbackIcon renderOffscreenForSize:size]; } [self unlock]; Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVScaledImageView.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVScaledImageView.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVScaledImageView.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -153,7 +153,7 @@ CGContextRef ctxt = [[NSGraphicsContext currentContext] graphicsPort]; NSSize size = [self respondsToSelector:@selector(convertSizeToBacking:)] ? [self convertSizeToBacking:aRect.size] : aRect.size; if ([_icon needsRenderForSize:size]) - [_icon renderOffscreen]; + [_icon renderOffscreenForSize:size]; aRect = NSInsetRect([self bounds], 25, 25); NSRect iconRect = aRect; Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h 2021-01-12 22:33:11 UTC (rev 25375) @@ -46,7 +46,6 @@ NSSize _fullSize; CGImageRef _thumbnail; NSSize _thumbnailSize; - NSSize _desiredSize; BOOL _isPlainText; } Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -159,7 +159,6 @@ _thumbnailSize = FVDefaultPaperSize(); // first approximation FVIconLimitThumbnailSize(&_thumbnailSize); - _desiredSize = NSZeroSize; _fullImage = NULL; _thumbnail = NULL; _isPlainText = isPlainText; @@ -185,7 +184,6 @@ BOOL needsRender = NO; // if we can't lock we're already rendering, which will give us both icons (so no render required) if ([self tryLock]) { - _desiredSize = size; if (FVShouldDrawFullImageWithThumbnailSize(size, _thumbnailSize)) needsRender = (NULL == _fullImage); else @@ -347,7 +345,7 @@ return image; } -- (void)renderOffscreen +- (void)renderOffscreenForSize:(NSSize)size { [[self class] _startRenderingForKey:_cacheKey]; @@ -360,7 +358,7 @@ // !!! two early returns here after a cache check if (NULL != _fullImage) { - // note that _fullImage may be non-NULL if we were added to the FVOperationQueue multiple times before renderOffscreen was called + // note that _fullImage may be non-NULL if we were added to the FVOperationQueue multiple times before renderOffscreenForSize: was called [self unlock]; [[self class] _stopRenderingForKey:_cacheKey]; return; @@ -374,7 +372,7 @@ if (NULL != _thumbnail) { - if (FVShouldDrawFullImageWithThumbnailSize(_desiredSize, _thumbnailSize)) { + if (FVShouldDrawFullImageWithThumbnailSize(size, _thumbnailSize)) { _fullImage = [FVCGImageCache newImageForKey:_cacheKey]; if (NULL != _fullImage) { [self unlock]; @@ -458,7 +456,7 @@ _thumbnailSize = FVCGImageSize(_thumbnail); // get rid of this to save memory if we aren't drawing it right away - if (FVShouldDrawFullImageWithThumbnailSize(_desiredSize, _thumbnailSize) == NO) { + if (FVShouldDrawFullImageWithThumbnailSize(size, _thumbnailSize) == NO) { CGImageRelease(_fullImage); _fullImage = NULL; } Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.h =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.h 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.h 2021-01-12 22:33:11 UTC (rev 25375) @@ -52,7 +52,6 @@ NSSize _thumbnailSize; FVIcon *_fallbackIcon; NSURL *_httpURL; - NSSize _desiredSize; WebView *_webView; NSCountedSet *_redirectedFrames; id _cacheKey; Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m 2021-01-12 22:33:11 UTC (rev 25375) @@ -134,7 +134,6 @@ _fullImageSize = _thumbnailSize = [[self class] _webViewSize]; FVIconLimitThumbnailSize(&_thumbnailSize); FVIconLimitFullImageSize(&_fullImageSize); - _desiredSize = NSZeroSize; _cacheKey = [FVCGImageCache newKeyForURL:_httpURL]; _condLock = [[NSConditionLock allocWithZone:[self zone]] initWithCondition:IDLE]; @@ -285,7 +284,7 @@ // currently a noop [_fallbackIcon releaseResources]; - // reset condition so -renderOffscreen will complete if it's called again + // reset condition so -renderOffscreenForSize: will complete if it's called again [_condLock unlockWithCondition:IDLE]; } @@ -323,7 +322,6 @@ 2) if we're drawing a large icon and the web view hasn't failed (yet), we depend on _fullImage (which may be in disk cache) 3) if we're drawing a small icon and the web view hasn't failed (yet), we depend on _thumbnail (so webview needs to load) */ - _desiredSize = size; if (_loadFailed) needsRender = [_fallbackIcon needsRenderForSize:size]; @@ -354,7 +352,7 @@ // condition should always be LOADING, but -releaseResources may have the lock if ([_condLock tryLockWhenCondition:LOADING]) { - // return to -renderOffscreen to handle the failure + // return to -renderOffscreenForSize: to handle the failure [_condLock unlockWithCondition:LOADED]; } } @@ -427,7 +425,7 @@ [self _releaseWebView]; [_condLock unlockWithCondition:LOADED]; - // return to -renderOffscreen for scaling and caching + // return to -renderOffscreenForSize: for scaling and caching } } @@ -558,7 +556,7 @@ return [NSString stringWithFormat:@"%@: { \n\tURL = %@\n\tWebView = %@\n\tFull image = %@\n\tThumbnail = %@\n }", [self description], _httpURL, _webView, _fullImage, _thumbnail]; } -- (void)renderOffscreen +- (void)renderOffscreenForSize:(NSSize)size { [[self class] _startRenderingForKey:_cacheKey]; @@ -569,8 +567,8 @@ // check the disk cache first - // note that _fullImage may be non-NULL if we were added to the FVOperationQueue multiple times before renderOffscreen was called - if (NULL == _fullImage && FVShouldDrawFullImageWithThumbnailSize(_desiredSize, [self _thumbnailSize])) + // note that _fullImage may be non-NULL if we were added to the FVOperationQueue multiple times before renderOffscreenForSize: was called + if (NULL == _fullImage && FVShouldDrawFullImageWithThumbnailSize(size, [self _thumbnailSize])) _fullImage = [FVCGImageCache newImageForKey:_cacheKey]; // always load for the fast drawing path @@ -581,7 +579,7 @@ if (NULL == _thumbnail && NULL == _fullImage) { - // make sure needsRenderForSize: knows that we're actively rendering, so renderOffscreen doesn't get called again + // make sure needsRenderForSize: knows that we're actively rendering, so renderOffscreenForSize: doesn't get called again [_condLock unlockWithCondition:LOADING]; [self performSelectorOnMainThread:@selector(_startWebView) withObject:nil waitUntilDone:NO modes:[NSArray arrayWithObject:(id)kCFRunLoopCommonModes]]; [_condLock lockWhenCondition:LOADED]; @@ -614,7 +612,7 @@ thumbnail = CGImageRetain(_thumbnail); // dispose of this immediately if we're not going to draw it; we can read from the cache if it's needed later - if (FVShouldDrawFullImageWithThumbnailSize(_desiredSize, _thumbnailSize) == NO) { + if (FVShouldDrawFullImageWithThumbnailSize(size, _thumbnailSize) == NO) { CGImageRelease(_fullImage); _fullImage = NULL; } Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/Notes =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/Notes 2021-01-12 17:27:16 UTC (rev 25374) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/Notes 2021-01-12 22:33:11 UTC (rev 25375) @@ -14,4 +14,4 @@ Page-based FVIcon instances (PDF/PS/text) may use an on-disk cache (FVIconCache) for storing rendered CGImageRef data for fast reinitialization of large bitmaps. This was a big performance win, especially for PDF files, where the bitmap data may be 14 MB of ARGB data. These are never removed, so the cache can grow without bound. Up to 500 PDF files, cache sizes are under 20 MB with the zlib compression I'm using, so I'm not too concerned about it. -FVIcon is designed to be thread safe, and still fairly lightweight. Most drawing to offscreen bitmap contexts should be performed asynchronously in a thread, since rendering in the offscreen bitmap context will block. If you need synchronous rendering, call the renderOffscreen method, wait until it's done, then draw the icon. Some classes will draw a blank "page" while working in the thread; non page-based types don't do this. The FVIconQueue handles all of this transparently, using a single thread shared amongst all FileView instances in an application. +FVIcon is designed to be thread safe, and still fairly lightweight. Most drawing to offscreen bitmap contexts should be performed asynchronously in a thread, since rendering in the offscreen bitmap context will block. If you need synchronous rendering, call the renderOffscreenForSize: method, wait until it's done, then draw the icon. Some classes will draw a blank "page" while working in the thread; non page-based types don't do this. The FVIconQueue handles all of this transparently, using a single thread shared amongst all FileView instances in an application. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit