Changeset 1175

Show
Ignore:
Timestamp:
02/25/2010 09:45:06 AM (2 years ago)
Author:
gbooker
Message:

Reduce instantaneous memory usage by not creating images until they are going to be displayed. Hopefully reduce the swapping that occurs during large imports.

Location:
branches/PlayerFramework/SapphireFrappliance/MetaDataImporting
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/PlayerFramework/SapphireFrappliance/MetaDataImporting/SapphirePosterChooser.h

    r1017 r1175  
    3131 */ 
    3232@interface SapphirePosterChooser : SapphireMediaMenuController <BRIconSourceProtocol, BRMenuListItemProvider, SapphireLayoutDelegate, SapphireChooser> { 
     33        BOOL                                    displayed;              /*!< @brief YES if currently displayed, NO otherwise*/ 
    3334        NSMutableArray                  *posters;               /*!< @brief The array of poster urls and after loaded, the NSImages*/ 
    3435        NSMutableArray                  *posterLayers;  /*!< @brief The image layers of posters*/ 
     36        NSMutableArray                  *posterData;    /*!< @brief The data for the poster images*/ 
    3537        NSString                                *fileName;              /*!< @brief The movie filename*/ 
    3638        NSString                                *movieTitle;    /*!< @brief The title of the movie*/ 
  • branches/PlayerFramework/SapphireFrappliance/MetaDataImporting/SapphirePosterChooser.m

    r1038 r1175  
    4242- (BRBlurryImageLayer *)getPosterLayerForData:(NSData *)thePosterData; 
    4343- (void)loadPoster:(int)index; 
     44- (void)reloadPosterWithData:(NSData *)data atIndex:(int)intIndex; 
    4445@end 
    4546 
     
    9394        [posters release]; 
    9495        [posterLayers release]; 
     96        [posterData release]; 
    9597        [fileName release]; 
    9698        [movieTitle release]; 
     
    187189        int i, count = [posters count]; 
    188190        posterLayers = [posters mutableCopy]; 
     191        posterData = [[NSMutableArray alloc] initWithCapacity:[posters count]]; 
     192        NSNull *nsnull = [NSNull null]; 
     193        for(i=0; i<count; i++) 
     194                [posterData addObject:nsnull]; 
    189195        for(i=0; i<count; i++) 
    190196                [self loadPoster:i]; 
     
    202208        NSString *posterURL = [posters objectAtIndex:index]; 
    203209        [posterLayers replaceObjectAtIndex:index withObject:[self getPosterLayerForData:nil]]; 
    204         [[SapphireApplianceController urlLoader] loadDataURL:posterURL withTarget:self selector:@selector(reloadPosterWithData:atIndex:) object:[NSNumber numberWithInt:index] withPriority:YES]; 
    205 } 
    206  
    207 - (void)reloadPosterWithData:(NSData *)data atIndex:(NSNumber *)index; 
    208 { 
    209         int intIndex = [index intValue]; 
     210        [[SapphireApplianceController urlLoader] loadDataURL:posterURL withTarget:self selector:@selector(gotPosterData:atIndex:) object:[NSNumber numberWithInt:index] withPriority:YES]; 
     211} 
     212 
     213- (void)gotPosterData:(NSData *)data atIndex:(NSNumber *)index; 
     214{ 
     215        if(displayed) 
     216                [self reloadPosterWithData:data atIndex:[index intValue]]; 
     217        else 
     218                [posterData replaceObjectAtIndex:[index intValue] withObject:data]; 
     219} 
     220 
     221- (void)reloadPosterWithData:(NSData *)data atIndex:(int)intIndex; 
     222{ 
    210223        [posterLayers replaceObjectAtIndex:intIndex withObject:[self getPosterLayerForData:data]]; 
    211224        NSImage *image = [[NSImage alloc] initWithData:data]; 
     
    539552        [[self list] reload]; 
    540553        [super wasPushed]; 
     554        displayed = YES; 
     555        int i, count = [posterData count]; 
     556        for(i=0; i<count; i++) 
     557        { 
     558                id obj = [posterData objectAtIndex:i]; 
     559                if([obj isKindOfClass:[NSData class]]) 
     560                        [self reloadPosterWithData:obj atIndex:i]; 
     561        } 
    541562} 
    542563