Get the size from the shared buffer.
[WebKit-https.git] / WebCore / platform / graphics / cg / ImageSourceCG.cpp
index 59fc8d4..a8eaee4 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()), data->size(), kCFAllocatorNull);
+#endif
     CGImageSourceUpdateData(m_decoder, cfData, allDataReceived);
     CFRelease(cfData);
 }