Revision: 12210
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=12210&view=rev
Author:   amaxwell
Date:     2008-01-02 19:11:10 -0800 (Wed, 02 Jan 2008)

Log Message:
-----------
Pass updated icons in update callback from the rendering thread.  This allows
the view to only redraw regions that have changed, which gives a nice
performance improvement in drawing.

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconQueue.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconQueue.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconQueue.m     2008-01-03 
02:10:16 UTC (rev 12209)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconQueue.m     2008-01-03 
03:11:10 UTC (rev 12210)
@@ -137,10 +137,11 @@
         NSUInteger i = 0, iMax = [taskQueue count], length = MIN((iMax - i), 
(NSUInteger)5);
         while (length) {
             NSRange r = NSMakeRange(i, length);
-            [[taskQueue subarrayWithRange:r] 
makeObjectsPerformSelector:@selector(renderOffscreen)];
+            NSArray *toRender = [taskQueue subarrayWithRange:r];
+            [toRender makeObjectsPerformSelector:@selector(renderOffscreen)];
             
             // using waitUntilDone:YES keeps the app much more responsive; 
otherwise we end up with too many drawing updates and repetitive rendering 
requests
-            [target performSelectorOnMainThread:@selector(iconQueueUpdated) 
withObject:nil waitUntilDone:YES modes:modes];
+            [target performSelectorOnMainThread:@selector(iconQueueUpdated:) 
withObject:toRender waitUntilDone:YES modes:modes];
             i = NSMaxRange(r);
             length = MIN((iMax - i), (NSUInteger)5);
         }

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.m        2008-01-03 
02:10:16 UTC (rev 12209)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.m        2008-01-03 
03:11:10 UTC (rev 12210)
@@ -729,9 +729,36 @@
         [[FVIconQueue sharedQueue] enqueueRenderIcons:icons forObject:self];
 }
 
-- (void)iconQueueUpdated;
+- (void)iconQueueUpdated:(NSArray *)updatedIcons;
 {
-    [self setNeedsDisplay:YES];
+    // Only iterate icons in the visible range, since we know the overall 
geometry
+    NSRange rowRange, columnRange;
+    [self _getRangeOfRows:&rowRange columns:&columnRange inRect:[self 
visibleRect]];
+    
+    NSUInteger iMin, iMax = [self numberOfIcons];
+    
+    // _indexForGridRow:column: returns NSNotFound if we're in a short row 
(empty column)
+    iMin = [self _indexForGridRow:rowRange.location 
column:columnRange.location];
+    if (NSNotFound == iMin)
+        iMin = [self numberOfIcons];
+    else
+        iMax = MIN([self numberOfIcons], iMin + rowRange.length * [self 
numberOfColumns]);
+    
+    NSArray *visibleIcons = [self iconsAtIndexes:[NSIndexSet 
indexSetWithIndexesInRange:NSMakeRange(iMin, iMax - iMin)]];
+    NSUInteger i;
+    NSSet *updatedIconSet = [[NSSet alloc] initWithArray:updatedIcons];
+    CGFloat padding = 3.0 * [self iconScale];
+    
+    // If an icon isn't visible, there's no need to redisplay anything.  
Similarly, if 20 icons are displayed and only 5 updated, there's no need to 
redraw all 20.  Geometry calculations are much faster than redrawing, in 
general.
+    for (i = iMin; i < iMax; i++) {
+        
+        if ([updatedIconSet containsObject:[visibleIcons objectAtIndex:(i - 
iMin)]]) {
+            NSUInteger r, c;
+            if ([self _getGridRow:&r column:&c ofIndex:i])
+                [self setNeedsDisplayInRect:NSInsetRect([self 
_rectOfIconInRow:r column:c], -padding, -padding)];
+        }
+    }
+    [updatedIconSet release];
 }
 
 // drawRect: uses -releaseResources on icons that aren't visible but present 
in the datasource, so we just need a way to cull icons that are cached but not 
currently in the datasource


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
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to