Chromium Code Reviews| Index: third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp |
| diff --git a/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp b/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp |
| index a2557d32a1be7f1a5346eb73c22afc603ee544f5..e1a4f53c0d1dd032e3e87eab871cce0b4766671e 100644 |
| --- a/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp |
| +++ b/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp |
| @@ -27,6 +27,7 @@ |
| #include "platform/image-decoders/ImageFrame.h" |
| #include "platform/RuntimeEnabledFeatures.h" |
| +#include "platform/graphics/skia/SkiaUtils.h" |
| #include "platform/image-decoders/ImageDecoder.h" |
| namespace blink { |
| @@ -88,14 +89,25 @@ void ImageFrame::zeroFillPixelData() |
| bool ImageFrame::copyBitmapData(const ImageFrame& other) |
| { |
| - if (this == &other) |
| - return true; |
| - |
| + DCHECK_NE(this, &other); |
| m_hasAlpha = other.m_hasAlpha; |
| m_bitmap.reset(); |
| return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); |
| } |
| +bool ImageFrame::takeBitmapDataIfWritable(ImageFrame* other) |
| +{ |
| + DCHECK(other); |
| + DCHECK_NE(this, other); |
| + if (other->m_bitmap.isImmutable()) |
| + return false; |
| + m_hasAlpha = other->m_hasAlpha; |
| + m_bitmap.reset(); |
| + m_bitmap.swap(other->m_bitmap); |
| + other->m_status = FrameEmpty; |
|
Ken Russell (switch to Gerrit)
2016/09/29 00:40:04
What about all of the other fields of this ImageFr
aleksandar.stojiljkovic
2016/09/29 08:03:53
For both clients, GIF and WebP right after this ca
|
| + return true; |
| +} |
| + |
| bool ImageFrame::setSizeAndColorProfile(int newWidth, int newHeight, const ICCProfile& newIccProfile) |
| { |
| // setSizeAndColorProfile() should only be called once, it leaks memory otherwise. |
| @@ -124,6 +136,13 @@ bool ImageFrame::hasAlpha() const |
| return m_hasAlpha; |
| } |
| +sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage() |
| +{ |
| + DCHECK_EQ(FrameComplete, m_status); |
| + m_bitmap.setImmutable(); |
| + return SkImage::MakeFromBitmap(m_bitmap); |
| +} |
| + |
| void ImageFrame::setHasAlpha(bool alpha) |
| { |
| m_hasAlpha = alpha; |
| @@ -136,10 +155,13 @@ void ImageFrame::setStatus(Status status) |
| m_status = status; |
| if (m_status == FrameComplete) { |
| m_bitmap.setAlphaType(computeAlphaType()); |
| - // Send pending pixels changed notifications now, because we can't do this after |
| - // the bitmap has been marked immutable. |
| + // Send pending pixels changed notifications now, because we can't do |
| + // this after the bitmap has been marked immutable. We don't set the |
| + // bitmap immutable here because it would defeat |
| + // takeBitmapDataIfWritable(). Instead we let the bitmap stay mutable |
| + // until someone calls finalizePixelsAndGetImage() to actually get the |
| + // SkImage. |
| notifyBitmapIfPixelsChanged(); |
| - m_bitmap.setImmutable(); // Tell the bitmap it's done. |
| } |
| } |