Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(976)

Unified Diff: third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp

Issue 1813483002: ImagePixelLocker now manually allocates SkPixmap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp b/third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp
index 59298ac27d31877319c7572b323dc3081519e780..7be09cd8512a156f980c583bc891fb45e2e6add7 100644
--- a/third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp
+++ b/third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp
@@ -29,26 +29,50 @@ ImagePixelLocker::ImagePixelLocker(PassRefPtr<const SkImage> image, SkAlphaType
: m_image(image)
{
SkImageInfo info;
- size_t imageRowBytes;
+ size_t rowBytes;
// If the image has in-RAM pixels and their format matches, use them directly.
// TODO(fmalita): All current clients expect packed pixel rows. Maybe we could update them
// to support arbitrary rowBytes, and relax the check below.
- m_pixels = m_image->peekPixels(&info, &imageRowBytes);
+ m_pixels = m_image->peekPixels(&info, &rowBytes);
if (m_pixels
&& infoIsCompatible(info, alphaType, colorType)
- && imageRowBytes == info.minRowBytes()) {
+ && rowBytes == info.minRowBytes()) {
return;
}
+ m_pixels = nullptr;
+
// No luck, we need to read the pixels into our local buffer.
info = SkImageInfo::Make(m_image->width(), m_image->height(), colorType, alphaType);
- if (!m_pixelStorage.tryAlloc(info) || !m_image->readPixels(m_pixelStorage, 0, 0)) {
- m_pixels = nullptr;
+ rowBytes = info.minRowBytes();
+ size_t size = info.getSafeSize(rowBytes);
+ if (0 == size) {
+ return;
+ }
+
+ void* pixels = sk_malloc_flags(size, 0);
f(malita) 2016/03/16 19:28:29 Would it make sense to use a separate SkAutoMalloc
robertphillips 2016/03/16 19:59:10 Done.
+ if (!pixels) {
+ return;
+ }
+
+ m_pixelStorage.reset(info, pixels, rowBytes);
+
+ if (!m_image->readPixels(m_pixelStorage, 0, 0)) {
+ sk_free(pixels);
+ m_pixelStorage.reset();
return;
}
m_pixels = m_pixelStorage.addr();
}
+ImagePixelLocker::~ImagePixelLocker()
+{
+ if (m_pixels == m_pixelStorage.addr()) {
+ // We had to make our own copy in the constructor
+ sk_free(const_cast<void*>(m_pixelStorage.addr()));
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698