OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/frame/ImageBitmap.h" | 5 #include "core/frame/ImageBitmap.h" |
6 | 6 |
7 #include "core/html/HTMLCanvasElement.h" | 7 #include "core/html/HTMLCanvasElement.h" |
8 #include "core/html/HTMLVideoElement.h" | 8 #include "core/html/HTMLVideoElement.h" |
9 #include "core/html/ImageData.h" | 9 #include "core/html/ImageData.h" |
10 #include "platform/graphics/skia/SkiaUtils.h" | 10 #include "platform/graphics/skia/SkiaUtils.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 } | 301 } |
302 m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin
())); | 302 m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin
())); |
303 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); | 303 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); |
304 } | 304 } |
305 | 305 |
306 ImageBitmap::ImageBitmap(HTMLVideoElement* video, Optional<IntRect> cropRect, Do
cument* document, const ImageBitmapOptions& options) | 306 ImageBitmap::ImageBitmap(HTMLVideoElement* video, Optional<IntRect> cropRect, Do
cument* document, const ImageBitmapOptions& options) |
307 { | 307 { |
308 IntSize playerSize; | 308 IntSize playerSize; |
309 if (video->webMediaPlayer()) | 309 if (video->webMediaPlayer()) |
310 playerSize = video->webMediaPlayer()->naturalSize(); | 310 playerSize = video->webMediaPlayer()->naturalSize(); |
311 | |
312 // TODO(xidachen); implement the resize option. | |
313 ParsedOptions parsedOptions = parseOptions(options, cropRect, video->bitmapS
ourceSize()); | 311 ParsedOptions parsedOptions = parseOptions(options, cropRect, video->bitmapS
ourceSize()); |
314 | 312 |
315 IntRect videoRect = IntRect(IntPoint(), playerSize); | 313 IntRect videoRect = IntRect(IntPoint(), playerSize); |
316 IntRect srcRect = intersection(parsedOptions.cropRect, videoRect); | 314 IntRect srcRect = intersection(parsedOptions.cropRect, videoRect); |
317 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(parsedOptions.crop
Rect.size(), NonOpaque, DoNotInitializeImagePixels); | 315 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(IntSize(parsedOpti
ons.resizeWidth, parsedOptions.resizeHeight), NonOpaque, DoNotInitializeImagePix
els); |
318 if (!buffer) | 316 if (!buffer) |
319 return; | 317 return; |
320 | 318 |
321 if (parsedOptions.flipY) { | 319 if (parsedOptions.flipY) { |
322 buffer->canvas()->translate(0, buffer->size().height()); | 320 buffer->canvas()->translate(0, buffer->size().height()); |
323 buffer->canvas()->scale(1, -1); | 321 buffer->canvas()->scale(1, -1); |
324 } | 322 } |
325 IntPoint dstPoint = IntPoint(std::max(0, -parsedOptions.cropRect.x()), std::
max(0, -parsedOptions.cropRect.y())); | 323 IntPoint dstPoint = IntPoint(std::max(0, -parsedOptions.cropRect.x()), std::
max(0, -parsedOptions.cropRect.y())); |
326 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size())
, nullptr); | 324 IntSize dstSize = srcRect.size(); |
| 325 SkPaint paint; |
| 326 if (parsedOptions.shouldScaleInput) { |
| 327 float scaleRatioX = static_cast<float>(parsedOptions.resizeWidth) / pars
edOptions.cropRect.width(); |
| 328 float scaleRatioY = static_cast<float>(parsedOptions.resizeHeight) / par
sedOptions.cropRect.height(); |
| 329 dstPoint.scale(scaleRatioX, scaleRatioY); |
| 330 paint.setFilterQuality(parsedOptions.resizeQuality); |
| 331 dstSize.scale(scaleRatioX, scaleRatioY); |
| 332 } |
| 333 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, dstSize), parse
dOptions.shouldScaleInput ? &paint : nullptr); |
327 | 334 |
328 RefPtr<SkImage> skiaImage = buffer->newSkImageSnapshot(PreferNoAcceleration,
SnapshotReasonUnknown); | 335 RefPtr<SkImage> skiaImage = buffer->newSkImageSnapshot(PreferNoAcceleration,
SnapshotReasonUnknown); |
329 if (!parsedOptions.premultiplyAlpha) | 336 if (!parsedOptions.premultiplyAlpha) |
330 skiaImage = premulSkImageToUnPremul(skiaImage.get()); | 337 skiaImage = premulSkImageToUnPremul(skiaImage.get()); |
331 m_image = StaticBitmapImage::create(skiaImage.release()); | 338 m_image = StaticBitmapImage::create(skiaImage.release()); |
332 m_image->setOriginClean(!video->wouldTaintOrigin(document->getSecurityOrigin
())); | 339 m_image->setOriginClean(!video->wouldTaintOrigin(document->getSecurityOrigin
())); |
333 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); | 340 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); |
334 } | 341 } |
335 | 342 |
336 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, Optional<IntRect> cropRect,
const ImageBitmapOptions& options) | 343 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, Optional<IntRect> cropRect,
const ImageBitmapOptions& options) |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 FloatSize ImageBitmap::elementSize(const FloatSize&) const | 648 FloatSize ImageBitmap::elementSize(const FloatSize&) const |
642 { | 649 { |
643 return FloatSize(width(), height()); | 650 return FloatSize(width(), height()); |
644 } | 651 } |
645 | 652 |
646 DEFINE_TRACE(ImageBitmap) | 653 DEFINE_TRACE(ImageBitmap) |
647 { | 654 { |
648 } | 655 } |
649 | 656 |
650 } // namespace blink | 657 } // namespace blink |
OLD | NEW |