Get the size from the shared buffer.
[WebKit-https.git] / WebCore / platform / graphics / cg / ImageSourceCG.cpp
index 88f1ff0..a8eaee4 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "config.h"
 #include "ImageSource.h"
+#include "SharedBuffer.h"
 
 #if PLATFORM(CG)
 
@@ -71,11 +72,21 @@ bool ImageSource::initialized() const
     return m_decoder;
 }
 
-void ImageSource::setData(NativeBytePtr data, bool allDataReceived)
+void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
 {
     if (!m_decoder)
         m_decoder = CGImageSourceCreateIncremental(NULL);
-    CGImageSourceUpdateData(m_decoder, data, allDataReceived);
+#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()), data->size(), kCFAllocatorNull);
+#endif
+    CGImageSourceUpdateData(m_decoder, cfData, allDataReceived);
+    CFRelease(cfData);
 }
 
 bool ImageSource::isSizeAvailable()