Chromium Code Reviews| 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..ad4e950e2755cc187d96b94a5ce8637c2d749e0d 100644 |
| --- a/third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp |
| +++ b/third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp |
| @@ -29,26 +29,38 @@ 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; |
| + } |
|
f(malita)
2016/03/16 20:12:36
nit: no braces for single-line/statement condition
robertphillips
2016/03/16 20:31:50
Done.
|
| + |
| + m_pixelStorage.reset(size); // this will throw on failure |
| + |
| + SkPixmap pixmap(info, m_pixelStorage.get(), rowBytes); |
| + |
| + if (!m_image->readPixels(pixmap, 0, 0)) { |
| + m_pixelStorage.free(); |
|
f(malita)
2016/03/16 20:12:36
ImagePixelLockers are locally scoped, so freeing u
robertphillips
2016/03/16 20:30:50
Done - removed.
|
| return; |
| } |
| - m_pixels = m_pixelStorage.addr(); |
| + m_pixels = m_pixelStorage.get(); |
| } |
| } // namespace blink |