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

Unified Diff: third_party/WebKit/Source/core/frame/ImageBitmap.cpp

Issue 1800153003: Force image-decoding before resolving createImageBitmap promise (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: read a 1*1 pixel subregion to be efficient 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/frame/ImageBitmap.cpp
diff --git a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
index 70e44f107e18ca2162b7060aabdb147d64a335cb..43aef5b8c295b9b34c440ad02f9e1da93974852e 100644
--- a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
+++ b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
@@ -135,7 +135,14 @@ static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop
if (cropRect == srcRect) {
if (flipY)
return StaticBitmapImage::create(flipSkImageVertically(skiaImage->newSubset(srcRect), premultiplyAlpha ? PremultiplyAlpha : DontPremultiplyAlpha));
- return StaticBitmapImage::create(adoptRef(skiaImage->newSubset(srcRect)));
+ SkImage* croppedSkImage = skiaImage->newSubset(srcRect);
+ if (cropRect == imgRect) {
+ // Call readPixels to trigger image decoding. Only read 1*1 subregion to be efficient.
+ SkImageInfo info = SkImageInfo::MakeN32(1, 1, premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType);
+ OwnPtr<uint8_t[]> imagePixels = adoptArrayPtr(new uint8_t[info.bytesPerPixel()]);
+ croppedSkImage->readPixels(info, imagePixels.get(), info.bytesPerPixel(), 0, 0);
+ }
+ return StaticBitmapImage::create(adoptRef(croppedSkImage));
}
RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(cropRect.width(), cropRect.height()));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698