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 7c0de1e9e10b593f496e058d70579b981bd201f8..43712ac7eae04c778685a372ea827e0843f35a31 100644 |
--- a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp |
+++ b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp |
@@ -258,8 +258,20 @@ ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect, con |
m_image->setPremultiplied(premultiplyAlpha); |
} |
-// The last two parameters are used for structure-cloning. |
-ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect, const ImageBitmapOptions& options, const bool& isImageDataPremultiplied, const bool& isImageDataOriginClean) |
+// This constructor is called by structured-cloning an ImageBitmap. |
+// isImageBitmapPremultiplied indicates whether the original ImageBitmap is premultiplied or not. |
jbroman
2016/06/28 18:50:22
Comments like this normally go in the header, sinc
xidachen
2016/06/29 12:58:35
Done.
|
+// isImageBitmapOriginClean indicates whether the original ImageBitmap is origin clean or not. |
+ImageBitmap::ImageBitmap(std::unique_ptr<uint8_t[]> data, uint32_t width, uint32_t height, bool isImageBitmapPremultiplied, bool isImageBitmapOriginClean) |
+{ |
+ SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, isImageBitmapPremultiplied ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); |
+ swizzleImageData(data.get(), height, info.bytesPerPixel() * width, false); |
jbroman
2016/06/28 18:50:22
What's the purpose of this swizzling? Why aren't w
xidachen
2016/06/29 12:58:35
Done.
|
+ m_image = StaticBitmapImage::create(fromSkSp(SkImage::MakeRasterCopy(SkPixmap(info, data.get(), info.bytesPerPixel() * width)))); |
+ swizzleImageData(data.get(), height, info.bytesPerPixel() * width, false); |
jbroman
2016/06/28 18:50:22
Why unswizzle the data when we're about to delete
xidachen
2016/06/29 12:58:35
Done.
|
+ m_image->setPremultiplied(isImageBitmapPremultiplied); |
+ m_image->setOriginClean(isImageBitmapOriginClean); |
+} |
+ |
+ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect, const ImageBitmapOptions& options) |
{ |
bool flipY; |
bool premultiplyAlpha; |
@@ -273,11 +285,7 @@ ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect, const ImageBi |
int dstHeight = cropRect.height(); |
// TODO (xidachen): skia doesn't support SkImage::NewRasterCopy from a kRGBA color type. |
// For now, we swap R and B channel and uses kBGRA color type. |
- SkImageInfo info; |
- if (!isImageDataPremultiplied) |
- info = SkImageInfo::Make(cropRect.width(), dstHeight, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType); |
- else |
- info = SkImageInfo::Make(cropRect.width(), dstHeight, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
+ SkImageInfo info = SkImageInfo::Make(cropRect.width(), dstHeight, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType); |
int srcPixelBytesPerRow = info.bytesPerPixel() * data->size().width(); |
int dstPixelBytesPerRow = info.bytesPerPixel() * cropRect.width(); |
if (cropRect == IntRect(IntPoint(), data->size())) { |
@@ -317,7 +325,6 @@ ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect, const ImageBi |
m_image = StaticBitmapImage::create(newSkImageFromRaster(info, std::move(copiedDataBuffer), dstPixelBytesPerRow)); |
} |
m_image->setPremultiplied(premultiplyAlpha); |
- m_image->setOriginClean(isImageDataOriginClean); |
return; |
} |
@@ -405,10 +412,10 @@ ImageBitmap* ImageBitmap::create(HTMLCanvasElement* canvas, const IntRect& cropR |
return new ImageBitmap(canvas, normalizedCropRect, options); |
} |
-ImageBitmap* ImageBitmap::create(ImageData* data, const IntRect& cropRect, const ImageBitmapOptions& options, const bool& isImageDataPremultiplied, const bool& isImageDataOriginClean) |
+ImageBitmap* ImageBitmap::create(ImageData* data, const IntRect& cropRect, const ImageBitmapOptions& options) |
{ |
IntRect normalizedCropRect = normalizeRect(cropRect); |
- return new ImageBitmap(data, normalizedCropRect, options, isImageDataPremultiplied, isImageDataOriginClean); |
+ return new ImageBitmap(data, normalizedCropRect, options); |
} |
ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, const IntRect& cropRect, const ImageBitmapOptions& options) |
@@ -433,6 +440,11 @@ ImageBitmap* ImageBitmap::create(WebExternalTextureMailbox& mailbox) |
return new ImageBitmap(mailbox); |
} |
+ImageBitmap* ImageBitmap::create(std::unique_ptr<uint8_t[]> data, uint32_t width, uint32_t height, bool isImageBitmapPremultiplied, bool isImageBitmapOriginClean) |
+{ |
+ return new ImageBitmap(std::move(data), width, height, isImageBitmapPremultiplied, isImageBitmapOriginClean); |
+} |
+ |
void ImageBitmap::close() |
{ |
if (!m_image || m_isNeutered) |