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/Float32ImageData.h" |
7 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
8 #include "core/html/HTMLVideoElement.h" | 9 #include "core/html/HTMLVideoElement.h" |
9 #include "core/html/ImageData.h" | 10 #include "core/html/ImageData.h" |
10 #include "core/offscreencanvas/OffscreenCanvas.h" | 11 #include "core/offscreencanvas/OffscreenCanvas.h" |
11 #include "platform/graphics/skia/SkiaUtils.h" | 12 #include "platform/graphics/skia/SkiaUtils.h" |
12 #include "platform/image-decoders/ImageDecoder.h" | 13 #include "platform/image-decoders/ImageDecoder.h" |
13 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
14 #include "third_party/skia/include/core/SkImageInfo.h" | 15 #include "third_party/skia/include/core/SkImageInfo.h" |
15 #include "third_party/skia/include/core/SkSurface.h" | 16 #include "third_party/skia/include/core/SkSurface.h" |
16 #include "wtf/CheckedNumeric.h" | 17 #include "wtf/CheckedNumeric.h" |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 resizedInfo, resizedPixels->data(), | 757 resizedInfo, resizedPixels->data(), |
757 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel()); | 758 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel()); |
758 skImage->scalePixels(pixmap, resizeQuality); | 759 skImage->scalePixels(pixmap, resizeQuality); |
759 return SkImage::MakeFromRaster(pixmap, | 760 return SkImage::MakeFromRaster(pixmap, |
760 [](const void*, void* pixels) { | 761 [](const void*, void* pixels) { |
761 static_cast<Uint8Array*>(pixels)->deref(); | 762 static_cast<Uint8Array*>(pixels)->deref(); |
762 }, | 763 }, |
763 resizedPixels.release().leakRef()); | 764 resizedPixels.release().leakRef()); |
764 } | 765 } |
765 | 766 |
| 767 // TODO(zakerinasab): Fix this and the constructor from Float32ImageData |
| 768 // when the CL for Float32ImageData landed. |
766 ImageBitmap::ImageBitmap(ImageData* data, | 769 ImageBitmap::ImageBitmap(ImageData* data, |
767 Optional<IntRect> cropRect, | 770 Optional<IntRect> cropRect, |
768 const ImageBitmapOptions& options) { | 771 const ImageBitmapOptions& options) { |
769 // TODO(xidachen): implement the resize option | 772 // TODO(xidachen): implement the resize option |
770 IntRect dataSrcRect = IntRect(IntPoint(), data->size()); | 773 IntRect dataSrcRect = IntRect(IntPoint(), data->size()); |
771 ParsedOptions parsedOptions = | 774 ParsedOptions parsedOptions = |
772 parseOptions(options, cropRect, data->bitmapSourceSize()); | 775 parseOptions(options, cropRect, data->bitmapSourceSize()); |
773 if (dstBufferSizeHasOverflow(parsedOptions)) | 776 if (dstBufferSizeHasOverflow(parsedOptions)) |
774 return; | 777 return; |
775 IntRect srcRect = cropRect ? intersection(parsedOptions.cropRect, dataSrcRect) | 778 IntRect srcRect = cropRect ? intersection(parsedOptions.cropRect, dataSrcRect) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 SkPaint paint; | 907 SkPaint paint; |
905 paint.setFilterQuality(parsedOptions.resizeQuality); | 908 paint.setFilterQuality(parsedOptions.resizeQuality); |
906 SkRect dstDrawRect = | 909 SkRect dstDrawRect = |
907 SkRect::MakeWH(parsedOptions.resizeWidth, parsedOptions.resizeHeight); | 910 SkRect::MakeWH(parsedOptions.resizeWidth, parsedOptions.resizeHeight); |
908 surface->getCanvas()->drawImageRect(skImage, dstDrawRect, &paint); | 911 surface->getCanvas()->drawImageRect(skImage, dstDrawRect, &paint); |
909 skImage = surface->makeImageSnapshot(); | 912 skImage = surface->makeImageSnapshot(); |
910 } | 913 } |
911 m_image = StaticBitmapImage::create(std::move(skImage)); | 914 m_image = StaticBitmapImage::create(std::move(skImage)); |
912 } | 915 } |
913 | 916 |
| 917 ImageBitmap::ImageBitmap(Float32ImageData* data, |
| 918 Optional<IntRect> cropRect, |
| 919 const ImageBitmapOptions& options) {} |
| 920 |
914 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, | 921 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, |
915 Optional<IntRect> cropRect, | 922 Optional<IntRect> cropRect, |
916 const ImageBitmapOptions& options) { | 923 const ImageBitmapOptions& options) { |
917 RefPtr<Image> input = bitmap->bitmapImage(); | 924 RefPtr<Image> input = bitmap->bitmapImage(); |
918 if (!input) | 925 if (!input) |
919 return; | 926 return; |
920 ParsedOptions parsedOptions = parseOptions(options, cropRect, input->size()); | 927 ParsedOptions parsedOptions = parseOptions(options, cropRect, input->size()); |
921 if (dstBufferSizeHasOverflow(parsedOptions)) | 928 if (dstBufferSizeHasOverflow(parsedOptions)) |
922 return; | 929 return; |
923 | 930 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 const ImageBitmapOptions& options) { | 995 const ImageBitmapOptions& options) { |
989 return new ImageBitmap(offscreenCanvas, cropRect, options); | 996 return new ImageBitmap(offscreenCanvas, cropRect, options); |
990 } | 997 } |
991 | 998 |
992 ImageBitmap* ImageBitmap::create(ImageData* data, | 999 ImageBitmap* ImageBitmap::create(ImageData* data, |
993 Optional<IntRect> cropRect, | 1000 Optional<IntRect> cropRect, |
994 const ImageBitmapOptions& options) { | 1001 const ImageBitmapOptions& options) { |
995 return new ImageBitmap(data, cropRect, options); | 1002 return new ImageBitmap(data, cropRect, options); |
996 } | 1003 } |
997 | 1004 |
| 1005 ImageBitmap* ImageBitmap::create(Float32ImageData* data, |
| 1006 Optional<IntRect> cropRect, |
| 1007 const ImageBitmapOptions& options) { |
| 1008 return new ImageBitmap(data, cropRect, options); |
| 1009 } |
| 1010 |
998 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, | 1011 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, |
999 Optional<IntRect> cropRect, | 1012 Optional<IntRect> cropRect, |
1000 const ImageBitmapOptions& options) { | 1013 const ImageBitmapOptions& options) { |
1001 return new ImageBitmap(bitmap, cropRect, options); | 1014 return new ImageBitmap(bitmap, cropRect, options); |
1002 } | 1015 } |
1003 | 1016 |
1004 ImageBitmap* ImageBitmap::create(PassRefPtr<StaticBitmapImage> image, | 1017 ImageBitmap* ImageBitmap::create(PassRefPtr<StaticBitmapImage> image, |
1005 Optional<IntRect> cropRect, | 1018 Optional<IntRect> cropRect, |
1006 const ImageBitmapOptions& options) { | 1019 const ImageBitmapOptions& options) { |
1007 return new ImageBitmap(std::move(image), cropRect, options); | 1020 return new ImageBitmap(std::move(image), cropRect, options); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, | 1114 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, |
1102 FloatRect* dstRect) const {} | 1115 FloatRect* dstRect) const {} |
1103 | 1116 |
1104 FloatSize ImageBitmap::elementSize(const FloatSize&) const { | 1117 FloatSize ImageBitmap::elementSize(const FloatSize&) const { |
1105 return FloatSize(width(), height()); | 1118 return FloatSize(width(), height()); |
1106 } | 1119 } |
1107 | 1120 |
1108 DEFINE_TRACE(ImageBitmap) {} | 1121 DEFINE_TRACE(ImageBitmap) {} |
1109 | 1122 |
1110 } // namespace blink | 1123 } // namespace blink |
OLD | NEW |