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

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: update 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..945da6181378fee60b6225c45094b6c43a116bba 100644
--- a/third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp
+++ b/third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp
@@ -29,26 +29,35 @@ 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;
+
+ m_pixelStorage.reset(size); // this will throw on failure
+
+ SkPixmap pixmap(info, m_pixelStorage.get(), rowBytes);
+
+ if (!m_image->readPixels(pixmap, 0, 0))
return;
- }
- m_pixels = m_pixelStorage.addr();
+ m_pixels = m_pixelStorage.get();
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698