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/SkImageInfo.h" | 14 #include "third_party/skia/include/core/SkImageInfo.h" |
14 #include "third_party/skia/include/core/SkSurface.h" | 15 #include "third_party/skia/include/core/SkSurface.h" |
15 #include "wtf/CheckedNumeric.h" | 16 #include "wtf/CheckedNumeric.h" |
16 #include "wtf/PtrUtil.h" | 17 #include "wtf/PtrUtil.h" |
17 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
18 #include <memory> | 19 #include <memory> |
19 | 20 |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 m_image = StaticBitmapImage::create(premulSkImageToUnPremul( | 681 m_image = StaticBitmapImage::create(premulSkImageToUnPremul( |
681 m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()) | 682 m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()) |
682 .get())); | 683 .get())); |
683 } | 684 } |
684 if (!m_image) | 685 if (!m_image) |
685 return; | 686 return; |
686 m_image->setOriginClean(canvas->originClean()); | 687 m_image->setOriginClean(canvas->originClean()); |
687 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); | 688 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); |
688 } | 689 } |
689 | 690 |
| 691 ImageBitmap::ImageBitmap(OffscreenCanvas* offscreenCanvas, |
| 692 Optional<IntRect> cropRect, |
| 693 const ImageBitmapOptions& options) { |
| 694 SourceImageStatus status; |
| 695 RefPtr<Image> input = offscreenCanvas->getSourceImageForCanvas( |
| 696 &status, PreferNoAcceleration, SnapshotReasonCreateImageBitmap, |
| 697 FloatSize(offscreenCanvas->size())); |
| 698 if (status != NormalSourceImageStatus) |
| 699 return; |
| 700 ParsedOptions parsedOptions = |
| 701 parseOptions(options, cropRect, IntSize(input->width(), input->height())); |
| 702 if (dstBufferSizeHasOverflow(parsedOptions)) |
| 703 return; |
| 704 |
| 705 bool isPremultiplyAlphaReverted = false; |
| 706 if (!parsedOptions.premultiplyAlpha) { |
| 707 parsedOptions.premultiplyAlpha = true; |
| 708 isPremultiplyAlphaReverted = true; |
| 709 } |
| 710 m_image = cropImageAndApplyColorSpaceConversion( |
| 711 input.get(), parsedOptions, PremultiplyAlpha, |
| 712 ColorBehavior::transformToGlobalTarget()); |
| 713 if (!m_image) |
| 714 return; |
| 715 if (isPremultiplyAlphaReverted) { |
| 716 parsedOptions.premultiplyAlpha = false; |
| 717 m_image = StaticBitmapImage::create(premulSkImageToUnPremul( |
| 718 m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()) |
| 719 .get())); |
| 720 } |
| 721 if (!m_image) |
| 722 return; |
| 723 m_image->setOriginClean(offscreenCanvas->originClean()); |
| 724 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); |
| 725 } |
| 726 |
690 ImageBitmap::ImageBitmap(const void* pixelData, | 727 ImageBitmap::ImageBitmap(const void* pixelData, |
691 uint32_t width, | 728 uint32_t width, |
692 uint32_t height, | 729 uint32_t height, |
693 bool isImageBitmapPremultiplied, | 730 bool isImageBitmapPremultiplied, |
694 bool isImageBitmapOriginClean) { | 731 bool isImageBitmapOriginClean) { |
695 SkImageInfo info = SkImageInfo::MakeN32( | 732 SkImageInfo info = SkImageInfo::MakeN32( |
696 width, height, | 733 width, height, |
697 isImageBitmapPremultiplied ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); | 734 isImageBitmapPremultiplied ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); |
698 SkPixmap pixmap(info, pixelData, info.bytesPerPixel() * width); | 735 SkPixmap pixmap(info, pixelData, info.bytesPerPixel() * width); |
699 m_image = StaticBitmapImage::create(SkImage::MakeRasterCopy(pixmap)); | 736 m_image = StaticBitmapImage::create(SkImage::MakeRasterCopy(pixmap)); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 const ImageBitmapOptions& options) { | 976 const ImageBitmapOptions& options) { |
940 return new ImageBitmap(video, cropRect, document, options); | 977 return new ImageBitmap(video, cropRect, document, options); |
941 } | 978 } |
942 | 979 |
943 ImageBitmap* ImageBitmap::create(HTMLCanvasElement* canvas, | 980 ImageBitmap* ImageBitmap::create(HTMLCanvasElement* canvas, |
944 Optional<IntRect> cropRect, | 981 Optional<IntRect> cropRect, |
945 const ImageBitmapOptions& options) { | 982 const ImageBitmapOptions& options) { |
946 return new ImageBitmap(canvas, cropRect, options); | 983 return new ImageBitmap(canvas, cropRect, options); |
947 } | 984 } |
948 | 985 |
| 986 ImageBitmap* ImageBitmap::create(OffscreenCanvas* offscreenCanvas, |
| 987 Optional<IntRect> cropRect, |
| 988 const ImageBitmapOptions& options) { |
| 989 return new ImageBitmap(offscreenCanvas, cropRect, options); |
| 990 } |
| 991 |
949 ImageBitmap* ImageBitmap::create(ImageData* data, | 992 ImageBitmap* ImageBitmap::create(ImageData* data, |
950 Optional<IntRect> cropRect, | 993 Optional<IntRect> cropRect, |
951 const ImageBitmapOptions& options) { | 994 const ImageBitmapOptions& options) { |
952 return new ImageBitmap(data, cropRect, options); | 995 return new ImageBitmap(data, cropRect, options); |
953 } | 996 } |
954 | 997 |
955 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, | 998 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, |
956 Optional<IntRect> cropRect, | 999 Optional<IntRect> cropRect, |
957 const ImageBitmapOptions& options) { | 1000 const ImageBitmapOptions& options) { |
958 return new ImageBitmap(bitmap, cropRect, options); | 1001 return new ImageBitmap(bitmap, cropRect, options); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, | 1101 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, |
1059 FloatRect* dstRect) const {} | 1102 FloatRect* dstRect) const {} |
1060 | 1103 |
1061 FloatSize ImageBitmap::elementSize(const FloatSize&) const { | 1104 FloatSize ImageBitmap::elementSize(const FloatSize&) const { |
1062 return FloatSize(width(), height()); | 1105 return FloatSize(width(), height()); |
1063 } | 1106 } |
1064 | 1107 |
1065 DEFINE_TRACE(ImageBitmap) {} | 1108 DEFINE_TRACE(ImageBitmap) {} |
1066 | 1109 |
1067 } // namespace blink | 1110 } // namespace blink |
OLD | NEW |