| 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" | |
| 8 #include "core/html/HTMLCanvasElement.h" | 7 #include "core/html/HTMLCanvasElement.h" |
| 9 #include "core/html/HTMLVideoElement.h" | 8 #include "core/html/HTMLVideoElement.h" |
| 10 #include "core/html/ImageData.h" | 9 #include "core/html/ImageData.h" |
| 11 #include "core/offscreencanvas/OffscreenCanvas.h" | 10 #include "core/offscreencanvas/OffscreenCanvas.h" |
| 12 #include "platform/graphics/skia/SkiaUtils.h" | 11 #include "platform/graphics/skia/SkiaUtils.h" |
| 13 #include "platform/image-decoders/ImageDecoder.h" | 12 #include "platform/image-decoders/ImageDecoder.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkImageInfo.h" | 14 #include "third_party/skia/include/core/SkImageInfo.h" |
| 16 #include "third_party/skia/include/core/SkSurface.h" | 15 #include "third_party/skia/include/core/SkSurface.h" |
| 17 #include "wtf/CheckedNumeric.h" | 16 #include "wtf/CheckedNumeric.h" |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 resizedInfo, resizedPixels->data(), | 750 resizedInfo, resizedPixels->data(), |
| 752 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel()); | 751 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel()); |
| 753 skImage->scalePixels(pixmap, resizeQuality); | 752 skImage->scalePixels(pixmap, resizeQuality); |
| 754 return SkImage::MakeFromRaster(pixmap, | 753 return SkImage::MakeFromRaster(pixmap, |
| 755 [](const void*, void* pixels) { | 754 [](const void*, void* pixels) { |
| 756 static_cast<Uint8Array*>(pixels)->deref(); | 755 static_cast<Uint8Array*>(pixels)->deref(); |
| 757 }, | 756 }, |
| 758 resizedPixels.release().leakRef()); | 757 resizedPixels.release().leakRef()); |
| 759 } | 758 } |
| 760 | 759 |
| 761 // TODO(zakerinasab): Fix this and the constructor from Float32ImageData | |
| 762 // when the CL for Float32ImageData landed. | |
| 763 ImageBitmap::ImageBitmap(ImageData* data, | 760 ImageBitmap::ImageBitmap(ImageData* data, |
| 764 Optional<IntRect> cropRect, | 761 Optional<IntRect> cropRect, |
| 765 const ImageBitmapOptions& options) { | 762 const ImageBitmapOptions& options) { |
| 766 // TODO(xidachen): implement the resize option | 763 // TODO(xidachen): implement the resize option |
| 767 IntRect dataSrcRect = IntRect(IntPoint(), data->size()); | 764 IntRect dataSrcRect = IntRect(IntPoint(), data->size()); |
| 768 ParsedOptions parsedOptions = | 765 ParsedOptions parsedOptions = |
| 769 parseOptions(options, cropRect, data->bitmapSourceSize()); | 766 parseOptions(options, cropRect, data->bitmapSourceSize()); |
| 770 if (dstBufferSizeHasOverflow(parsedOptions)) | 767 if (dstBufferSizeHasOverflow(parsedOptions)) |
| 771 return; | 768 return; |
| 772 IntRect srcRect = cropRect ? intersection(parsedOptions.cropRect, dataSrcRect) | 769 IntRect srcRect = cropRect ? intersection(parsedOptions.cropRect, dataSrcRect) |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 SkPaint paint; | 898 SkPaint paint; |
| 902 paint.setFilterQuality(parsedOptions.resizeQuality); | 899 paint.setFilterQuality(parsedOptions.resizeQuality); |
| 903 SkRect dstDrawRect = | 900 SkRect dstDrawRect = |
| 904 SkRect::MakeWH(parsedOptions.resizeWidth, parsedOptions.resizeHeight); | 901 SkRect::MakeWH(parsedOptions.resizeWidth, parsedOptions.resizeHeight); |
| 905 surface->getCanvas()->drawImageRect(skImage, dstDrawRect, &paint); | 902 surface->getCanvas()->drawImageRect(skImage, dstDrawRect, &paint); |
| 906 skImage = surface->makeImageSnapshot(); | 903 skImage = surface->makeImageSnapshot(); |
| 907 } | 904 } |
| 908 m_image = StaticBitmapImage::create(std::move(skImage)); | 905 m_image = StaticBitmapImage::create(std::move(skImage)); |
| 909 } | 906 } |
| 910 | 907 |
| 911 ImageBitmap::ImageBitmap(Float32ImageData* data, | |
| 912 Optional<IntRect> cropRect, | |
| 913 const ImageBitmapOptions& options) {} | |
| 914 | |
| 915 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, | 908 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, |
| 916 Optional<IntRect> cropRect, | 909 Optional<IntRect> cropRect, |
| 917 const ImageBitmapOptions& options) { | 910 const ImageBitmapOptions& options) { |
| 918 RefPtr<Image> input = bitmap->bitmapImage(); | 911 RefPtr<Image> input = bitmap->bitmapImage(); |
| 919 if (!input) | 912 if (!input) |
| 920 return; | 913 return; |
| 921 ParsedOptions parsedOptions = parseOptions(options, cropRect, input->size()); | 914 ParsedOptions parsedOptions = parseOptions(options, cropRect, input->size()); |
| 922 if (dstBufferSizeHasOverflow(parsedOptions)) | 915 if (dstBufferSizeHasOverflow(parsedOptions)) |
| 923 return; | 916 return; |
| 924 | 917 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 ImageBitmap* ImageBitmap::create(OffscreenCanvas* offscreenCanvas, | 980 ImageBitmap* ImageBitmap::create(OffscreenCanvas* offscreenCanvas, |
| 988 Optional<IntRect> cropRect, | 981 Optional<IntRect> cropRect, |
| 989 const ImageBitmapOptions& options) { | 982 const ImageBitmapOptions& options) { |
| 990 return new ImageBitmap(offscreenCanvas, cropRect, options); | 983 return new ImageBitmap(offscreenCanvas, cropRect, options); |
| 991 } | 984 } |
| 992 | 985 |
| 993 ImageBitmap* ImageBitmap::create(ImageData* data, | 986 ImageBitmap* ImageBitmap::create(ImageData* data, |
| 994 Optional<IntRect> cropRect, | 987 Optional<IntRect> cropRect, |
| 995 const ImageBitmapOptions& options) { | 988 const ImageBitmapOptions& options) { |
| 996 return new ImageBitmap(data, cropRect, options); | 989 return new ImageBitmap(data, cropRect, options); |
| 997 } | |
| 998 | |
| 999 ImageBitmap* ImageBitmap::create(Float32ImageData* data, | |
| 1000 Optional<IntRect> cropRect, | |
| 1001 const ImageBitmapOptions& options) { | |
| 1002 return new ImageBitmap(data, cropRect, options); | |
| 1003 } | 990 } |
| 1004 | 991 |
| 1005 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, | 992 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, |
| 1006 Optional<IntRect> cropRect, | 993 Optional<IntRect> cropRect, |
| 1007 const ImageBitmapOptions& options) { | 994 const ImageBitmapOptions& options) { |
| 1008 return new ImageBitmap(bitmap, cropRect, options); | 995 return new ImageBitmap(bitmap, cropRect, options); |
| 1009 } | 996 } |
| 1010 | 997 |
| 1011 ImageBitmap* ImageBitmap::create(PassRefPtr<StaticBitmapImage> image, | 998 ImageBitmap* ImageBitmap::create(PassRefPtr<StaticBitmapImage> image, |
| 1012 Optional<IntRect> cropRect, | 999 Optional<IntRect> cropRect, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, | 1095 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, |
| 1109 FloatRect* dstRect) const {} | 1096 FloatRect* dstRect) const {} |
| 1110 | 1097 |
| 1111 FloatSize ImageBitmap::elementSize(const FloatSize&) const { | 1098 FloatSize ImageBitmap::elementSize(const FloatSize&) const { |
| 1112 return FloatSize(width(), height()); | 1099 return FloatSize(width(), height()); |
| 1113 } | 1100 } |
| 1114 | 1101 |
| 1115 DEFINE_TRACE(ImageBitmap) {} | 1102 DEFINE_TRACE(ImageBitmap) {} |
| 1116 | 1103 |
| 1117 } // namespace blink | 1104 } // namespace blink |
| OLD | NEW |