Chromium Code Reviews| 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 5efe36d700f3086ad7703144f1c644e6524496b2..17588768c78a2c1319ac2e0a949a344e040f8734 100644 |
| --- a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp |
| +++ b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp |
| @@ -28,6 +28,8 @@ struct ParsedOptions { |
| bool shouldScaleInput = false; |
| unsigned resizeWidth = 0; |
| unsigned resizeHeight = 0; |
| + float scaleRatioX = 1; |
| + float scaleRatioY = 1; |
| IntRect cropRect; |
| SkFilterQuality resizeQuality = kLow_SkFilterQuality; |
| }; |
| @@ -47,7 +49,7 @@ static bool frameIsValid(const SkBitmap& frameBitmap) |
| return frameBitmap.colorType() == kN32_SkColorType; |
| } |
| -ParsedOptions parseOptions(const ImageBitmapOptions& options, Optional<IntRect> cropRect, IntSize sourceSize) |
| +ParsedOptions parseOptions(const ImageBitmapOptions& options, Optional<IntRect> cropRect, IntSize sourceSize, bool shouldCalculateRatio) |
| { |
| ParsedOptions parsedOptions; |
| if (options.imageOrientation() == imageOrientationFlipY) { |
| @@ -88,6 +90,10 @@ ParsedOptions parseOptions(const ImageBitmapOptions& options, Optional<IntRect> |
| return parsedOptions; |
| } |
| parsedOptions.shouldScaleInput = true; |
| + if (shouldCalculateRatio) { |
| + parsedOptions.scaleRatioX = static_cast<float>(parsedOptions.resizeWidth) / parsedOptions.cropRect.width(); |
| + parsedOptions.scaleRatioY = static_cast<float>(parsedOptions.resizeHeight) / parsedOptions.cropRect.height(); |
| + } |
| if (options.resizeQuality() == "high") |
| parsedOptions.resizeQuality = kHigh_SkFilterQuality; |
| @@ -282,7 +288,7 @@ static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const ParsedOptions |
| ImageBitmap::ImageBitmap(HTMLImageElement* image, Optional<IntRect> cropRect, Document* document, const ImageBitmapOptions& options) |
| { |
| RefPtr<Image> input = image->cachedImage()->getImage(); |
| - ParsedOptions parsedOptions = parseOptions(options, cropRect, image->bitmapSourceSize()); |
| + ParsedOptions parsedOptions = parseOptions(options, cropRect, image->bitmapSourceSize(), false); |
| if (options.colorSpaceConversion() == "none") |
| m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, ImageDecoder::GammaAndColorProfileIgnored); |
| @@ -308,13 +314,11 @@ ImageBitmap::ImageBitmap(HTMLVideoElement* video, Optional<IntRect> cropRect, Do |
| IntSize playerSize; |
| if (video->webMediaPlayer()) |
| playerSize = video->webMediaPlayer()->naturalSize(); |
| - |
| - // TODO(xidachen); implement the resize option. |
| - ParsedOptions parsedOptions = parseOptions(options, cropRect, video->bitmapSourceSize()); |
| + ParsedOptions parsedOptions = parseOptions(options, cropRect, video->bitmapSourceSize(), true); |
| IntRect videoRect = IntRect(IntPoint(), playerSize); |
| IntRect srcRect = intersection(parsedOptions.cropRect, videoRect); |
| - std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(parsedOptions.cropRect.size(), NonOpaque, DoNotInitializeImagePixels); |
| + std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(IntSize(parsedOptions.resizeWidth, parsedOptions.resizeHeight), NonOpaque, DoNotInitializeImagePixels); |
| if (!buffer) |
| return; |
| @@ -323,7 +327,14 @@ ImageBitmap::ImageBitmap(HTMLVideoElement* video, Optional<IntRect> cropRect, Do |
| buffer->canvas()->scale(1, -1); |
| } |
| IntPoint dstPoint = IntPoint(std::max(0, -parsedOptions.cropRect.x()), std::max(0, -parsedOptions.cropRect.y())); |
| - video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size()), nullptr); |
| + IntSize dstSize = srcRect.size(); |
| + SkPaint paint; |
| + if (parsedOptions.shouldScaleInput) { |
| + dstPoint.scale(parsedOptions.scaleRatioX, parsedOptions.scaleRatioY); |
|
Justin Novosad
2016/07/29 15:08:52
putting the scaleRAtion in parsedOptions is overki
xidachen
2016/07/29 17:22:10
Yes, that makes perfect sense. Changed in the new
|
| + paint.setFilterQuality(parsedOptions.resizeQuality); |
| + dstSize.scale(parsedOptions.scaleRatioX, parsedOptions.scaleRatioY); |
| + } |
| + video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, dstSize), parsedOptions.shouldScaleInput ? &paint : nullptr); |
| RefPtr<SkImage> skiaImage = buffer->newSkImageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown); |
| if (!parsedOptions.premultiplyAlpha) |
| @@ -337,7 +348,7 @@ ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, Optional<IntRect> cropRect, |
| { |
| ASSERT(canvas->isPaintable()); |
| RefPtr<Image> input = canvas->copiedImage(BackBuffer, PreferAcceleration); |
| - ParsedOptions parsedOptions = parseOptions(options, cropRect, canvas->bitmapSourceSize()); |
| + ParsedOptions parsedOptions = parseOptions(options, cropRect, canvas->bitmapSourceSize(), false); |
| bool isPremultiplyAlphaReverted = false; |
| if (!parsedOptions.premultiplyAlpha) { |
| @@ -379,7 +390,7 @@ ImageBitmap::ImageBitmap(ImageData* data, Optional<IntRect> cropRect, const Imag |
| { |
| // TODO(xidachen): implement the resize option |
| IntRect dataSrcRect = IntRect(IntPoint(), data->size()); |
| - ParsedOptions parsedOptions = parseOptions(options, cropRect, data->bitmapSourceSize()); |
| + ParsedOptions parsedOptions = parseOptions(options, cropRect, data->bitmapSourceSize(), false); |
| IntRect srcRect = cropRect ? intersection(parsedOptions.cropRect, dataSrcRect) : dataSrcRect; |
| // treat non-premultiplyAlpha as a special case |
| @@ -480,7 +491,7 @@ ImageBitmap::ImageBitmap(ImageBitmap* bitmap, Optional<IntRect> cropRect, const |
| RefPtr<Image> input = bitmap->bitmapImage(); |
| if (!input) |
| return; |
| - ParsedOptions parsedOptions = parseOptions(options, cropRect, input->size()); |
| + ParsedOptions parsedOptions = parseOptions(options, cropRect, input->size(), false); |
| m_image = cropImage(input.get(), parsedOptions, bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha); |
| if (!m_image) |
| @@ -493,7 +504,7 @@ ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image, Optional<IntRect> |
| { |
| bool originClean = image->originClean(); |
| RefPtr<Image> input = image; |
| - ParsedOptions parsedOptions = parseOptions(options, cropRect, input->size()); |
| + ParsedOptions parsedOptions = parseOptions(options, cropRect, input->size(), false); |
| m_image = cropImage(input.get(), parsedOptions, DontPremultiplyAlpha); |
| if (!m_image) |