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 "core/offscreencanvas/OffscreenCanvas.h" |
10 #include "platform/graphics/skia/SkiaUtils.h" | 11 #include "platform/graphics/skia/SkiaUtils.h" |
11 #include "platform/image-decoders/ImageDecoder.h" | 12 #include "platform/image-decoders/ImageDecoder.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
13 #include "third_party/skia/include/core/SkSurface.h" | 14 #include "third_party/skia/include/core/SkSurface.h" |
14 #include "wtf/CheckedNumeric.h" | 15 #include "wtf/CheckedNumeric.h" |
15 #include "wtf/PtrUtil.h" | 16 #include "wtf/PtrUtil.h" |
16 #include "wtf/RefPtr.h" | 17 #include "wtf/RefPtr.h" |
17 #include <memory> | 18 #include <memory> |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 m_image = StaticBitmapImage::create(premulSkImageToUnPremul( | 503 m_image = StaticBitmapImage::create(premulSkImageToUnPremul( |
503 m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()) | 504 m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()) |
504 .get())); | 505 .get())); |
505 } | 506 } |
506 if (!m_image) | 507 if (!m_image) |
507 return; | 508 return; |
508 m_image->setOriginClean(canvas->originClean()); | 509 m_image->setOriginClean(canvas->originClean()); |
509 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); | 510 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); |
510 } | 511 } |
511 | 512 |
| 513 ImageBitmap::ImageBitmap(OffscreenCanvas* offscreenCanvas, |
| 514 Optional<IntRect> cropRect, |
| 515 const ImageBitmapOptions& options) { |
| 516 SourceImageStatus status; |
| 517 RefPtr<Image> input = offscreenCanvas->getSourceImageForCanvas( |
| 518 &status, PreferNoAcceleration, CreateImageBitmapSnapshotReason, |
| 519 FloatSize(offscreenCanvas->size())); |
| 520 if (status != NormalSourceImageStatus) |
| 521 return; |
| 522 ParsedOptions parsedOptions = |
| 523 parseOptions(options, cropRect, IntSize(input->width(), input->height())); |
| 524 if (dstBufferSizeHasOverflow(parsedOptions)) |
| 525 return; |
| 526 |
| 527 bool isPremultiplyAlphaReverted = false; |
| 528 if (!parsedOptions.premultiplyAlpha) { |
| 529 parsedOptions.premultiplyAlpha = true; |
| 530 isPremultiplyAlphaReverted = true; |
| 531 } |
| 532 m_image = cropImage(input.get(), parsedOptions, PremultiplyAlpha, |
| 533 ColorBehavior::transformToGlobalTarget()); |
| 534 if (!m_image) |
| 535 return; |
| 536 if (isPremultiplyAlphaReverted) { |
| 537 parsedOptions.premultiplyAlpha = false; |
| 538 m_image = StaticBitmapImage::create( |
| 539 premulSkImageToUnPremul(m_image->imageForCurrentFrame().get())); |
| 540 } |
| 541 if (!m_image) |
| 542 return; |
| 543 m_image->setOriginClean(offscreenCanvas->originClean()); |
| 544 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); |
| 545 } |
| 546 |
512 ImageBitmap::ImageBitmap(const void* pixelData, | 547 ImageBitmap::ImageBitmap(const void* pixelData, |
513 uint32_t width, | 548 uint32_t width, |
514 uint32_t height, | 549 uint32_t height, |
515 bool isImageBitmapPremultiplied, | 550 bool isImageBitmapPremultiplied, |
516 bool isImageBitmapOriginClean) { | 551 bool isImageBitmapOriginClean) { |
517 SkImageInfo info = SkImageInfo::MakeN32( | 552 SkImageInfo info = SkImageInfo::MakeN32( |
518 width, height, | 553 width, height, |
519 isImageBitmapPremultiplied ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); | 554 isImageBitmapPremultiplied ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); |
520 SkPixmap pixmap(info, pixelData, info.bytesPerPixel() * width); | 555 SkPixmap pixmap(info, pixelData, info.bytesPerPixel() * width); |
521 m_image = StaticBitmapImage::create(SkImage::MakeRasterCopy(pixmap)); | 556 m_image = StaticBitmapImage::create(SkImage::MakeRasterCopy(pixmap)); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 const ImageBitmapOptions& options) { | 795 const ImageBitmapOptions& options) { |
761 return new ImageBitmap(video, cropRect, document, options); | 796 return new ImageBitmap(video, cropRect, document, options); |
762 } | 797 } |
763 | 798 |
764 ImageBitmap* ImageBitmap::create(HTMLCanvasElement* canvas, | 799 ImageBitmap* ImageBitmap::create(HTMLCanvasElement* canvas, |
765 Optional<IntRect> cropRect, | 800 Optional<IntRect> cropRect, |
766 const ImageBitmapOptions& options) { | 801 const ImageBitmapOptions& options) { |
767 return new ImageBitmap(canvas, cropRect, options); | 802 return new ImageBitmap(canvas, cropRect, options); |
768 } | 803 } |
769 | 804 |
| 805 ImageBitmap* ImageBitmap::create(OffscreenCanvas* offscreenCanvas, |
| 806 Optional<IntRect> cropRect, |
| 807 const ImageBitmapOptions& options) { |
| 808 return new ImageBitmap(offscreenCanvas, cropRect, options); |
| 809 } |
| 810 |
770 ImageBitmap* ImageBitmap::create(ImageData* data, | 811 ImageBitmap* ImageBitmap::create(ImageData* data, |
771 Optional<IntRect> cropRect, | 812 Optional<IntRect> cropRect, |
772 const ImageBitmapOptions& options) { | 813 const ImageBitmapOptions& options) { |
773 return new ImageBitmap(data, cropRect, options); | 814 return new ImageBitmap(data, cropRect, options); |
774 } | 815 } |
775 | 816 |
776 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, | 817 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, |
777 Optional<IntRect> cropRect, | 818 Optional<IntRect> cropRect, |
778 const ImageBitmapOptions& options) { | 819 const ImageBitmapOptions& options) { |
779 return new ImageBitmap(bitmap, cropRect, options); | 820 return new ImageBitmap(bitmap, cropRect, options); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, | 920 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, |
880 FloatRect* dstRect) const {} | 921 FloatRect* dstRect) const {} |
881 | 922 |
882 FloatSize ImageBitmap::elementSize(const FloatSize&) const { | 923 FloatSize ImageBitmap::elementSize(const FloatSize&) const { |
883 return FloatSize(width(), height()); | 924 return FloatSize(width(), height()); |
884 } | 925 } |
885 | 926 |
886 DEFINE_TRACE(ImageBitmap) {} | 927 DEFINE_TRACE(ImageBitmap) {} |
887 | 928 |
888 } // namespace blink | 929 } // namespace blink |
OLD | NEW |