From 82b4a0bd6ed673d1dd1b148207ae471330132d77 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 16 Mar 2009 20:46:22 +0000 Subject: [PATCH] Attempting to deal with memory footprint. --- Library.mm | 61 ++++++++++++++++++++++++++++++++++++------------------ control | 2 +- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Library.mm b/Library.mm index 2a4483a..796ffb9 100644 --- a/Library.mm +++ b/Library.mm @@ -62,6 +62,7 @@ #import #import #import +#import #import #import #import @@ -105,6 +106,7 @@ Class $SBIconController; Class $SBIconLabel; Class $SBIconList; Class $SBIconModel; +//Class $SBImageCache; Class $SBStatusBarContentsView; Class $SBStatusBarController; Class $SBStatusBarOperatorNameView; @@ -305,27 +307,42 @@ static NSString *$pathForIcon$(SBApplication *self) { @end -MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) { - _SBIconModel$cacheImageForIcon$(self, sel, icon); - NSString *key([icon displayIdentifier]); +UIImage *$cacheForImage$(UIImage *image) { + CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB()); + CGRect rect = {CGPointMake(1, 1), [image size]}; + CGSize size = {rect.size.width + 2, rect.size.height + 2}; - if (UIImage *image = [icon icon]) { - CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB()); - CGRect rect = {CGPointMake(1, 1), [image size]}; - CGSize size = {rect.size.width + 2, rect.size.height + 2}; + CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst)); + CGColorSpaceRelease(space); - CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst)); - CGColorSpaceRelease(space); + CGContextDrawImage(context, rect, [image CGImage]); + CGImageRef ref(CGBitmapContextCreateImage(context)); + CGContextRelease(context); - CGContextDrawImage(context, rect, [image CGImage]); - CGImageRef ref(CGBitmapContextCreateImage(context)); - CGContextRelease(context); + UIImage *cache([UIImage imageWithCGImage:ref]); + CGImageRelease(ref); - UIImage *image([UIImage imageWithCGImage:ref]); - CGImageRelease(ref); + return cache; +} + +/*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) { + //if ([name isEqualToString:@"icons"]) return nil; + return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity); +}*/ + +MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) { + NSString *key([icon displayIdentifier]); - [Cache_ setObject:image forKey:key]; + if (UIImage *image = [icon icon]) { + CGSize size = [image size]; + if (size.width > 59 || size.height > 60) { + UIImage *cache($cacheForImage$(image)); + [Cache_ setObject:cache forKey:key]; + return; + } } + + _SBIconModel$cacheImageForIcon$(self, sel, icon); } MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) { @@ -1105,7 +1122,6 @@ MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool NSString *path = [NSString stringWithUTF8String:a1]; if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) { NSString *file = [path substringFromIndex:31]; - NSLog(@"%@", file); for (NSString *theme in themes_) { NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]); if ([Manager_ fileExistsAtPath:path]) { @@ -1262,10 +1278,12 @@ extern "C" void WBInitialize() { Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain]; for (NSString *theme in themes_) - if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) + if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) { + [info autorelease]; for (NSString *key in [info allKeys]) if ([Info_ objectForKey:key] == nil) [Info_ setObject:[info objectForKey:key] forKey:key]; + } if ([identifier isEqualToString:@"com.apple.MobileSMS"]) { Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController"); @@ -1296,6 +1314,7 @@ extern "C" void WBInitialize() { $SBIconLabel = objc_getClass("SBIconLabel"); $SBIconList = objc_getClass("SBIconList"); $SBIconModel = objc_getClass("SBIconModel"); + //$SBImageCache = objc_getClass("SBImageCache"); $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView"); $SBStatusBarController = objc_getClass("SBStatusBarController"); $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView"); @@ -1323,6 +1342,8 @@ extern "C" void WBInitialize() { WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$); WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$); + //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$); + WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$); WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview); WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$); @@ -1332,12 +1353,12 @@ extern "C" void WBInitialize() { WBRename(SBStatusBarTimeView, drawRect:, drawRect$); English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"]; - if (English_ != nil) - English_ = [English_ retain]; - Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64]; } + [pool release]; + return; + Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain]; if ([Info_ objectForKey:@"UndockedIconLabels"] == nil) diff --git a/control b/control index 47766a9..ec52d6c 100644 --- a/control +++ b/control @@ -3,7 +3,7 @@ Priority: optional Section: System Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 0.9.2696-1 +Version: 0.9.2794-1 Description: more powerful, open-source SummerBoard Name: WinterBoard Depends: mobilesubstrate (>= 0.9.2660-1) -- 2.45.2