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

Unified Diff: third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp

Issue 2155973002: Save a bitmap copy when advancing to dependent GIF and WebP animation frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK m_status in ImageFrame. Shortened commit message. Thanks kbr@. Created 4 years, 3 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/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..48ec40b3442b59706b04d0c9c0ed014b62766c07 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,27 @@ 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_EQ(FrameComplete, other->m_status);
+ DCHECK_EQ(FrameEmpty, m_status);
+ 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;
+ return true;
+}
+
bool ImageFrame::setSizeAndColorProfile(int newWidth, int newHeight, const ICCProfile& newIccProfile)
{
// setSizeAndColorProfile() should only be called once, it leaks memory otherwise.
@@ -124,6 +138,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 +157,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.
}
}

Powered by Google App Engine
This is Rietveld 408576698