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

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

Issue 2016043002: Avoid copy pixel data in texImage2D(ImageBitmap) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: initialize to nullptr Created 4 years, 7 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/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 5948ce5b57be0f025f050f34ee7b3af099b128b6..5e0a92a56132185f54c78438a83a28d84867fbd4 100644
--- a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
+++ b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
@@ -91,6 +91,13 @@ static PassRefPtr<SkImage> premulSkImageToUnPremul(SkImage* input)
return newSkImageFromRaster(info, std::move(dstPixels), input->width() * info.bytesPerPixel());
}
+static PassRefPtr<SkImage> unPremulSkImageToPremul(SkImage* input)
+{
+ SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_SkColorType, kPremul_SkAlphaType);
+ OwnPtr<uint8_t[]> dstPixels = copySkImageData(input, info);
+ return newSkImageFromRaster(info, std::move(dstPixels), input->width() * info.bytesPerPixel());
+}
+
PassRefPtr<SkImage> ImageBitmap::getSkImageFromDecoder(PassOwnPtr<ImageDecoder> decoder)
{
if (!decoder->frameCount())
@@ -140,6 +147,9 @@ static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop
if (flipY)
return StaticBitmapImage::create(flipSkImageVertically(skiaImage->newSubset(srcRect), premultiplyAlpha ? PremultiplyAlpha : DontPremultiplyAlpha));
SkImage* croppedSkImage = skiaImage->newSubset(srcRect);
+ // Special case: The first parameter image is unpremul but we need to turn it into premul.
+ if (premultiplyAlpha && imageFormat == PremultiplyAlpha)
Justin Novosad 2016/05/27 14:16:18 Unless I am misreading this, I think you mean "pre
xidachen 2016/05/27 15:10:13 Made changes so that imageFormat == DontPremultipl
+ return StaticBitmapImage::create(unPremulSkImageToPremul(croppedSkImage));
// Call preroll to trigger image decoding.
croppedSkImage->preroll();
return StaticBitmapImage::create(adoptRef(croppedSkImage));
@@ -162,8 +172,11 @@ static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop
skiaImage = flipSkImageVertically(surface->newImageSnapshot(), PremultiplyAlpha);
else
skiaImage = adoptRef(surface->newImageSnapshot());
- if (premultiplyAlpha)
+ if (premultiplyAlpha) {
+ if (imageFormat == PremultiplyAlpha)
+ return StaticBitmapImage::create(unPremulSkImageToPremul(skiaImage.get()));
return StaticBitmapImage::create(skiaImage.release());
+ }
return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get()));
}
@@ -179,6 +192,15 @@ ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, Docum
m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, premultiplyAlpha, DontPremultiplyAlpha, ImageDecoder::GammaAndColorProfileApplied);
if (!m_image)
return;
+ // In the case where the source image is lazy-decoded, m_image may not be in
+ // a decoded state, we trigger it here.
+ RefPtr<SkImage> skImage = m_image->imageForCurrentFrame();
+ SkPixmap pixmap;
+ if (!skImage->peekPixels(&pixmap)) {
Justin Novosad 2016/05/27 14:16:18 This condition will force an immediate readback of
xidachen 2016/05/27 15:10:13 Double checked with fmalita@, peekPixels() will no
Justin Novosad 2016/05/27 16:13:47 That is not what I meant. I was not referring to t
xidachen 2016/05/27 17:14:56 Yes, that makes sense, changed.
+ sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height());
+ surface->getCanvas()->drawImage(skImage.get(), 0, 0);
+ m_image = StaticBitmapImage::create(adoptRef(surface->newImageSnapshot()));
+ }
m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin()));
m_image->setPremultiplied(premultiplyAlpha);
}

Powered by Google App Engine
This is Rietveld 408576698