[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373
aroben at apple.com
aroben at apple.com
Thu Apr 8 01:44:02 UTC 2010
The following commit has been merged in the webkit-1.2 branch:
commit 759a37de4e89a7204df41abf698dd736a19ec21d
Author: aroben at apple.com <aroben at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Feb 10 21:05:55 2010 +0000
Optimize ImageBuffer::toDataURL's CG implementation
There was some unused code that could have been removed in r31830 when
this function was changed not to flip the CG image anymore.
Fixes <http://webkit.org/b/34808> ImageBuffer::toDataURL allocates
unnecessary memory under CoreGraphics
Reviewed by Sam Weinig.
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::toDataURL): Don't allocate an unused CGImageRef
and buffer, and switch to the new overload of base64Encode that
doesn't require us to copy all the image data into a Vector first.
* platform/text/Base64.cpp:
(WebCore::base64Encode):
* platform/text/Base64.h:
Added an overload that takes a raw data pointer and length, just like
we have for base64Decode. The overload that takes a Vector as input
just calls through to the new overload.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54616 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 637c47a..15aec1a 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,27 @@
+2010-02-10 Adam Roben <aroben at apple.com>
+
+ Optimize ImageBuffer::toDataURL's CG implementation
+
+ There was some unused code that could have been removed in r31830 when
+ this function was changed not to flip the CG image anymore.
+
+ Fixes <http://webkit.org/b/34808> ImageBuffer::toDataURL allocates
+ unnecessary memory under CoreGraphics
+
+ Reviewed by Sam Weinig.
+
+ * platform/graphics/cg/ImageBufferCG.cpp:
+ (WebCore::ImageBuffer::toDataURL): Don't allocate an unused CGImageRef
+ and buffer, and switch to the new overload of base64Encode that
+ doesn't require us to copy all the image data into a Vector first.
+
+ * platform/text/Base64.cpp:
+ (WebCore::base64Encode):
+ * platform/text/Base64.h:
+ Added an overload that takes a raw data pointer and length, just like
+ we have for base64Decode. The overload that takes a Vector as input
+ just calls through to the new overload.
+
2010-02-10 Dan Bernstein <mitz at apple.com>
Reviewed by Dave Hyatt.
diff --git a/WebCore/platform/graphics/cg/ImageBufferCG.cpp b/WebCore/platform/graphics/cg/ImageBufferCG.cpp
index b1896f8..0dc7a53 100644
--- a/WebCore/platform/graphics/cg/ImageBufferCG.cpp
+++ b/WebCore/platform/graphics/cg/ImageBufferCG.cpp
@@ -280,34 +280,19 @@ String ImageBuffer::toDataURL(const String& mimeType) const
if (!image)
return "data:,";
- size_t width = CGImageGetWidth(image.get());
- size_t height = CGImageGetHeight(image.get());
-
- OwnArrayPtr<uint32_t> imageData(new uint32_t[width * height]);
- if (!imageData)
- return "data:,";
-
- RetainPtr<CGImageRef> transformedImage(AdoptCF, CGBitmapContextCreateImage(context()->platformContext()));
- if (!transformedImage)
+ RetainPtr<CFMutableDataRef> data(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, 0));
+ if (!data)
return "data:,";
- RetainPtr<CFMutableDataRef> transformedImageData(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, 0));
- if (!transformedImageData)
+ RetainPtr<CGImageDestinationRef> destination(AdoptCF, CGImageDestinationCreateWithData(data.get(), utiFromMIMEType(mimeType).get(), 1, 0));
+ if (!destination)
return "data:,";
- RetainPtr<CGImageDestinationRef> imageDestination(AdoptCF, CGImageDestinationCreateWithData(transformedImageData.get(),
- utiFromMIMEType(mimeType).get(), 1, 0));
- if (!imageDestination)
- return "data:,";
-
- CGImageDestinationAddImage(imageDestination.get(), transformedImage.get(), 0);
- CGImageDestinationFinalize(imageDestination.get());
-
- Vector<char> in;
- in.append(CFDataGetBytePtr(transformedImageData.get()), CFDataGetLength(transformedImageData.get()));
+ CGImageDestinationAddImage(destination.get(), image.get(), 0);
+ CGImageDestinationFinalize(destination.get());
Vector<char> out;
- base64Encode(in, out);
+ base64Encode(reinterpret_cast<const char*>(CFDataGetBytePtr(data.get())), CFDataGetLength(data.get()), out);
out.append('\0');
return String::format("data:%s;base64,%s", mimeType.utf8().data(), out.data());
diff --git a/WebCore/platform/text/Base64.cpp b/WebCore/platform/text/Base64.cpp
index be19164..82ec9fa 100644
--- a/WebCore/platform/text/Base64.cpp
+++ b/WebCore/platform/text/Base64.cpp
@@ -62,21 +62,24 @@ static const char base64DecMap[128] = {
void base64Encode(const Vector<char>& in, Vector<char>& out, bool insertLFs)
{
+ base64Encode(in.data(), in.size(), out, insertLFs);
+}
+
+void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insertLFs)
+{
out.clear();
- if (in.isEmpty())
+ if (!len)
return;
// If the input string is pathologically large, just return nothing.
// Note: Keep this in sync with the "out_len" computation below.
// Rather than being perfectly precise, this is a bit conservative.
const unsigned maxInputBufferSize = UINT_MAX / 77 * 76 / 4 * 3 - 2;
- if (in.size() > maxInputBufferSize)
+ if (len > maxInputBufferSize)
return;
unsigned sidx = 0;
unsigned didx = 0;
- const char* data = in.data();
- const unsigned len = in.size();
unsigned out_len = ((len + 2) / 3) * 4;
diff --git a/WebCore/platform/text/Base64.h b/WebCore/platform/text/Base64.h
index 0b176e6..53b29b0 100644
--- a/WebCore/platform/text/Base64.h
+++ b/WebCore/platform/text/Base64.h
@@ -31,6 +31,7 @@
namespace WebCore {
void base64Encode(const Vector<char>&, Vector<char>&, bool insertLFs = false);
+void base64Encode(const char*, unsigned, Vector<char>&, bool insertLFs = false);
// this decoder is not general purpose - it returns an error if it encounters a linefeed, as needed for window.atob
bool base64Decode(const Vector<char>&, Vector<char>&);
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list