Make sure to use CFDataCreateWithBytesNoCopy where we can.
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Mar 2007 08:49:55 +0000 (08:49 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Mar 2007 08:49:55 +0000 (08:49 +0000)
        Reviewed by andersca

        * platform/graphics/cg/ImageSourceCG.cpp:
        (WebCore::ImageSource::setData):
        * platform/graphics/cg/PDFDocumentImage.cpp:
        (WebCore::PDFDocumentImage::dataChanged):

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

WebCore/ChangeLog
WebCore/platform/graphics/cg/ImageSourceCG.cpp
WebCore/platform/graphics/cg/PDFDocumentImage.cpp

index c5a7495..0677087 100644 (file)
@@ -1,3 +1,14 @@
+2007-03-14  David Hyatt  <hyatt@apple.com>
+
+        Make sure to use CFDataCreateWithBytesNoCopy where we can.
+
+        Reviewed by andersca
+
+        * platform/graphics/cg/ImageSourceCG.cpp:
+        (WebCore::ImageSource::setData):
+        * platform/graphics/cg/PDFDocumentImage.cpp:
+        (WebCore::PDFDocumentImage::dataChanged):
+
 2007-03-13  David Hyatt  <hyatt@apple.com>
 
         Fix for bugzilla bug 13050 and also radar p1 5050645.
index 59fc8d4..fc854fb 100644 (file)
@@ -76,8 +76,15 @@ void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
 {
     if (!m_decoder)
         m_decoder = CGImageSourceCreateIncremental(NULL);
-        
+#if PLATFORM(MAC)
+    // On Mac the NSData inside the SharedBuffer can be secretly appended to without the SharedBuffer's knowledge.  We use SharedBuffer's ability
+    // to wrap itself in an NSData to get around this, ensuring that ImageIO is really looking at the SharedBuffer.
     CFDataRef cfData = (CFDataRef)data->createNSData();
+#else
+    // If no NSData is available, then we know SharedBuffer will always just be a vector.  That means no secret changes can occur to it behind the
+    // scenes.  We use CFDataCreateWithBytesNoCopy in that case.
+    CFDataRef cfData = CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data->data()), length, kCFAllocatorNull);
+#endif
     CGImageSourceUpdateData(m_decoder, cfData, allDataReceived);
     CFRelease(cfData);
 }
index f3c12aa..a797ac8 100644 (file)
@@ -56,7 +56,15 @@ IntSize PDFDocumentImage::size() const
 bool PDFDocumentImage::dataChanged(bool allDataReceived)
 {
     if (allDataReceived && !m_document) {
+#if PLATFORM(MAC)
+        // On Mac the NSData inside the SharedBuffer can be secretly appended to without the SharedBuffer's knowledge.  We use SharedBuffer's ability
+        // to wrap itself in an NSData to get around this, ensuring that ImageIO is really looking at the SharedBuffer.
         CFDataRef data = (CFDataRef)m_data->createNSData();
+#else
+        // If no NSData is available, then we know SharedBuffer will always just be a vector.  That means no secret changes can occur to it behind the
+        // scenes.  We use CFDataCreateWithBytesNoCopy in that case.
+        CFDataRef data = CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(m_data->data()), length, kCFAllocatorNull);
+#endif
         CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data);
         CFRelease(data);
         m_document = CGPDFDocumentCreateWithProvider(dataProvider);