Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(713)

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmap.cpp

Issue 2802813002: Adds SVGImageElement as a ImageBitmapSource (Closed)
Patch Set: test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "core/offscreencanvas/OffscreenCanvas.h"
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 surface->getCanvas()->drawImage(skImage, 0, 0); 584 surface->getCanvas()->drawImage(skImage, 0, 0);
585 m_image = StaticBitmapImage::create(surface->makeImageSnapshot()); 585 m_image = StaticBitmapImage::create(surface->makeImageSnapshot());
586 } 586 }
587 if (!m_image) 587 if (!m_image)
588 return; 588 return;
589 m_image->setOriginClean( 589 m_image->setOriginClean(
590 !image->wouldTaintOrigin(document->getSecurityOrigin())); 590 !image->wouldTaintOrigin(document->getSecurityOrigin()));
591 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); 591 m_image->setPremultiplied(parsedOptions.premultiplyAlpha);
592 } 592 }
593 593
594 ImageBitmap::ImageBitmap(SVGImageElement* image,
595 Optional<IntRect> cropRect,
596 Document* document,
597 const ImageBitmapOptions& options) {
598 RefPtr<Image> input = image->cachedImage()->getImage();
599 ParsedOptions parsedOptions =
600 parseOptions(options, cropRect, image->bitmapSourceSize());
fs 2017/04/06 16:48:12 Given all the interfaces that's defined for this,
fserb 2017/04/06 20:06:16 fixed
601 if (dstBufferSizeHasOverflow(parsedOptions))
602 return;
603
604 if (options.colorSpaceConversion() == kImageBitmapOptionNone) {
605 m_image = cropImageAndApplyColorSpaceConversion(
606 input.get(), parsedOptions, PremultiplyAlpha, ColorBehavior::ignore());
607 } else {
608 m_image = cropImageAndApplyColorSpaceConversion(
609 input.get(), parsedOptions, PremultiplyAlpha,
610 ColorBehavior::transformToGlobalTarget());
611 }
612
613 if (!m_image)
614 return;
615 // In the case where the source image is lazy-decoded, m_image may not be in
616 // a decoded state, we trigger it here.
617 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame();
618 SkPixmap pixmap;
619 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) {
620 SkImageInfo imageInfo = SkImageInfo::Make(
621 skImage->width(), skImage->height(), parsedOptions.dstColorType,
622 kPremul_SkAlphaType, parsedOptions.dstColorSpace);
623 sk_sp<SkSurface> surface = SkSurface::MakeRaster(imageInfo);
624 surface->getCanvas()->drawImage(skImage, 0, 0);
625 m_image = StaticBitmapImage::create(surface->makeImageSnapshot());
626 }
627 if (!m_image)
628 return;
629 m_image->setOriginClean(
630 !image->wouldTaintOrigin(document->getSecurityOrigin()));
631 m_image->setPremultiplied(parsedOptions.premultiplyAlpha);
632 }
633
594 ImageBitmap::ImageBitmap(HTMLVideoElement* video, 634 ImageBitmap::ImageBitmap(HTMLVideoElement* video,
595 Optional<IntRect> cropRect, 635 Optional<IntRect> cropRect,
596 Document* document, 636 Document* document,
597 const ImageBitmapOptions& options) { 637 const ImageBitmapOptions& options) {
598 IntSize playerSize; 638 IntSize playerSize;
599 if (video->webMediaPlayer()) 639 if (video->webMediaPlayer())
600 playerSize = video->webMediaPlayer()->naturalSize(); 640 playerSize = video->webMediaPlayer()->naturalSize();
601 ParsedOptions parsedOptions = 641 ParsedOptions parsedOptions =
602 parseOptions(options, cropRect, video->bitmapSourceSize()); 642 parseOptions(options, cropRect, video->bitmapSourceSize());
603 if (dstBufferSizeHasOverflow(parsedOptions)) 643 if (dstBufferSizeHasOverflow(parsedOptions))
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 1023
984 ImageBitmap::~ImageBitmap() {} 1024 ImageBitmap::~ImageBitmap() {}
985 1025
986 ImageBitmap* ImageBitmap::create(HTMLImageElement* image, 1026 ImageBitmap* ImageBitmap::create(HTMLImageElement* image,
987 Optional<IntRect> cropRect, 1027 Optional<IntRect> cropRect,
988 Document* document, 1028 Document* document,
989 const ImageBitmapOptions& options) { 1029 const ImageBitmapOptions& options) {
990 return new ImageBitmap(image, cropRect, document, options); 1030 return new ImageBitmap(image, cropRect, document, options);
991 } 1031 }
992 1032
1033 ImageBitmap* ImageBitmap::create(SVGImageElement* image,
1034 Optional<IntRect> cropRect,
1035 Document* document,
1036 const ImageBitmapOptions& options) {
1037 return new ImageBitmap(image, cropRect, document, options);
1038 }
1039
993 ImageBitmap* ImageBitmap::create(HTMLVideoElement* video, 1040 ImageBitmap* ImageBitmap::create(HTMLVideoElement* video,
994 Optional<IntRect> cropRect, 1041 Optional<IntRect> cropRect,
995 Document* document, 1042 Document* document,
996 const ImageBitmapOptions& options) { 1043 const ImageBitmapOptions& options) {
997 return new ImageBitmap(video, cropRect, document, options); 1044 return new ImageBitmap(video, cropRect, document, options);
998 } 1045 }
999 1046
1000 ImageBitmap* ImageBitmap::create(HTMLCanvasElement* canvas, 1047 ImageBitmap* ImageBitmap::create(HTMLCanvasElement* canvas,
1001 Optional<IntRect> cropRect, 1048 Optional<IntRect> cropRect,
1002 const ImageBitmapOptions& options) { 1049 const ImageBitmapOptions& options) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, 1172 void ImageBitmap::adjustDrawRects(FloatRect* srcRect,
1126 FloatRect* dstRect) const {} 1173 FloatRect* dstRect) const {}
1127 1174
1128 FloatSize ImageBitmap::elementSize(const FloatSize&) const { 1175 FloatSize ImageBitmap::elementSize(const FloatSize&) const {
1129 return FloatSize(width(), height()); 1176 return FloatSize(width(), height());
1130 } 1177 }
1131 1178
1132 DEFINE_TRACE(ImageBitmap) {} 1179 DEFINE_TRACE(ImageBitmap) {}
1133 1180
1134 } // namespace blink 1181 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698