Fixed missing retain of image property data.
authorrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Nov 2004 20:29:17 +0000 (20:29 +0000)
committerrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Nov 2004 20:29:17 +0000 (20:29 +0000)
        Reviewed by John.

        * WebCoreSupport.subproj/WebImageData.h:
        * WebCoreSupport.subproj/WebImageData.m:
        (-[WebImageData dealloc]):
        (-[WebImageData _invalidateImages]):
        (-[WebImageData imageAtIndex:]):
        (-[WebImageData propertiesAtIndex:]):
        (-[WebImageData _frameDuration]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8009 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/WebCoreSupport.subproj/WebImageData.h
WebKit/WebCoreSupport.subproj/WebImageData.m

index a789643..b91083b 100644 (file)
@@ -1,5 +1,19 @@
 2004-11-15  Richard Williamson   <rjw@apple.com>
 
+       Fixed missing retain of image property data.
+
+        Reviewed by John.
+
+        * WebCoreSupport.subproj/WebImageData.h:
+        * WebCoreSupport.subproj/WebImageData.m:
+        (-[WebImageData dealloc]):
+        (-[WebImageData _invalidateImages]):
+        (-[WebImageData imageAtIndex:]):
+        (-[WebImageData propertiesAtIndex:]):
+        (-[WebImageData _frameDuration]):
+
+2004-11-15  Richard Williamson   <rjw@apple.com>
+
        Cache image properties and frame durations.
        Create NSImage and TIFF representations from CGImage, lazily, as needed for
        dragging and element info dictionary.
index 77013c6..1e230b6 100644 (file)
@@ -12,6 +12,7 @@
 
 @interface WebImageData : NSObject <NSCopying>
 {
+    size_t imagesSize;
     CGImageRef *images;
     CGImageSourceRef imageSource;
 
     
     CFMutableDictionaryRef animatingRenderers;
     NSTimer *frameTimer;
+
+    size_t frameDurationsSize;
     float *frameDurations;
     
+    size_t imagePropertiesSize;
     CFDictionaryRef *imageProperties;
 
     size_t currentFrame;
index 76f31d8..66450c7 100644 (file)
@@ -48,7 +48,7 @@ static CFDictionaryRef imageSourceOptions;
     size_t i, num;
     
     num = [self numberOfImages];
-    for (i = 0; i < num; i++) {
+    for (i = 0; i < imagePropertiesSize; i++) {
         CFRelease (imageProperties[i]);
     }
     free (imageProperties);
@@ -93,8 +93,8 @@ static CFDictionaryRef imageSourceOptions;
 - (void)_invalidateImages
 {
     if (images) {
-        size_t i, count = [self numberOfImages];
-        for (i = 0; i < count; i++) {
+        size_t i;
+        for (i = 0; i < imagesSize; i++) {
             if (images[i])
                 CFRelease (images[i]);
         }
@@ -105,6 +105,11 @@ static CFDictionaryRef imageSourceOptions;
 
 - (CGImageRef)imageAtIndex:(size_t)index
 {
+    size_t num = [self numberOfImages];
+    
+    if (imagesSize && num > imagesSize)
+        [self _invalidateImages];
+        
     if (imageSource) {
         if (index > [self numberOfImages])
             return 0;
@@ -125,6 +130,7 @@ static CFDictionaryRef imageSourceOptions;
         //if (imageStatus < kCGImageStatusIncomplete)
         //    return 0;
 
+        imagesSize = [self numberOfImages];
         if (!images) {
             images = (CGImageRef *)calloc ([self numberOfImages], sizeof(CGImageRef *));
         }
@@ -323,12 +329,27 @@ CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
 {
     size_t num = [self numberOfImages];
     
+    // Number of images changed!
+    if (imagePropertiesSize && num > imagePropertiesSize) {
+        // Clear cache.
+        size_t i;
+        for (i = 0; i < imagePropertiesSize; i++) {
+            CFRelease (imageProperties[i]);
+        }
+        free (imageProperties);
+        imageProperties = 0;
+        imagePropertiesSize = 0;
+    }
+    
     if (imageProperties == 0 && num) {
         imageProperties = (CFDictionaryRef *)malloc (num * sizeof(CFDictionaryRef));
         size_t i;
         for (i = 0; i < num; i++) {
             imageProperties[i] = CGImageSourceGetPropertiesAtIndex (imageSource, i, 0);
+            if (imageProperties[i])
+                CFRetain (imageProperties[i]);
         }
+        imagePropertiesSize = num;
     }
     
     if (index < num) {
@@ -336,6 +357,8 @@ CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
         // get them before enough data was available in the header.
         if (imageProperties[index] == 0) {
             imageProperties[index] = CGImageSourceGetPropertiesAtIndex (imageSource, index, 0);
+            if (imageProperties[index])
+                CFRetain (imageProperties[index]);
         }
         
         return imageProperties[index];
@@ -386,6 +409,13 @@ CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
 
 - (float)_frameDuration
 {
+    size_t num = [self numberOfImages];
+    if (frameDurationsSize && num > frameDurationsSize) {
+        free (frameDurations);
+        frameDurations = 0;
+        frameDurationsSize = 0;
+    }
+    
     if (!frameDurations) {
         size_t i, num = [self numberOfImages];
 
@@ -393,6 +423,7 @@ CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
         for (i = 0; i < num; i++) {
             frameDurations[i] = [self _frameDurationAt:i];
         }
+        frameDurationsSize = num;
     }
     else if (frameDurations[currentFrame] == 0.f) {
             frameDurations[currentFrame] = [self _frameDurationAt:currentFrame];