Chromium Code Reviews| 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 "platform/graphics/AcceleratedStaticBitmapImage.h" | 10 #include "platform/graphics/AcceleratedStaticBitmapImage.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 | 35 |
| 36 // The following two functions are helpers used in cropImage | 36 // The following two functions are helpers used in cropImage |
| 37 static inline IntRect normalizeRect(const IntRect& rect) | 37 static inline IntRect normalizeRect(const IntRect& rect) |
| 38 { | 38 { |
| 39 return IntRect(std::min(rect.x(), rect.maxX()), | 39 return IntRect(std::min(rect.x(), rect.maxX()), |
| 40 std::min(rect.y(), rect.maxY()), | 40 std::min(rect.y(), rect.maxY()), |
| 41 std::max(rect.width(), -rect.width()), | 41 std::max(rect.width(), -rect.width()), |
| 42 std::max(rect.height(), -rect.height())); | 42 std::max(rect.height(), -rect.height())); |
| 43 } | 43 } |
| 44 | 44 |
| 45 static bool frameIsValid(const SkBitmap& frameBitmap) | |
| 46 { | |
| 47 ASSERT(!frameBitmap.isNull() && !frameBitmap.empty() && frameBitmap.isImmuta ble()); | |
| 48 return frameBitmap.colorType() == kN32_SkColorType; | |
| 49 } | |
| 50 | |
| 51 ParsedOptions parseOptions(const ImageBitmapOptions& options, Optional<IntRect> cropRect, IntSize sourceSize) | 45 ParsedOptions parseOptions(const ImageBitmapOptions& options, Optional<IntRect> cropRect, IntSize sourceSize) |
| 52 { | 46 { |
| 53 ParsedOptions parsedOptions; | 47 ParsedOptions parsedOptions; |
| 54 if (options.imageOrientation() == imageOrientationFlipY) { | 48 if (options.imageOrientation() == imageOrientationFlipY) { |
| 55 parsedOptions.flipY = true; | 49 parsedOptions.flipY = true; |
| 56 } else { | 50 } else { |
| 57 parsedOptions.flipY = false; | 51 parsedOptions.flipY = false; |
| 58 DCHECK(options.imageOrientation() == imageBitmapOptionNone); | 52 DCHECK(options.imageOrientation() == imageBitmapOptionNone); |
| 59 } | 53 } |
| 60 if (options.premultiplyAlpha() == imageBitmapOptionNone) { | 54 if (options.premultiplyAlpha() == imageBitmapOptionNone) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 return newSkImageFromRaster(info, std::move(dstPixels), input->width() * inf o.bytesPerPixel()); | 167 return newSkImageFromRaster(info, std::move(dstPixels), input->width() * inf o.bytesPerPixel()); |
| 174 } | 168 } |
| 175 | 169 |
| 176 PassRefPtr<SkImage> ImageBitmap::getSkImageFromDecoder(std::unique_ptr<ImageDeco der> decoder) | 170 PassRefPtr<SkImage> ImageBitmap::getSkImageFromDecoder(std::unique_ptr<ImageDeco der> decoder) |
| 177 { | 171 { |
| 178 if (!decoder->frameCount()) | 172 if (!decoder->frameCount()) |
| 179 return nullptr; | 173 return nullptr; |
| 180 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 174 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
| 181 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) | 175 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) |
| 182 return nullptr; | 176 return nullptr; |
| 183 SkBitmap bitmap = frame->bitmap(); | 177 DCHECK(!frame->bitmap().isNull() && !frame->bitmap().empty()); |
| 184 if (!frameIsValid(bitmap)) | 178 if (frame->bitmap().colorType() != kN32_SkColorType) |
|
Peter Kasting
2016/09/22 21:44:08
So, what I meant by "is this safe" was not so much
aleksandar.stojiljkovic
2016/09/27 18:08:28
I didn't see how it could happen with current set
| |
| 185 return nullptr; | 179 return nullptr; |
| 186 return fromSkSp(SkImage::MakeFromBitmap(bitmap)); | 180 return fromSkSp(frame->finalizePixelsAndGetImage()); |
|
Peter Kasting
2016/09/22 21:44:08
Nit: Shorter:
return (frame->bitmap().colorType
aleksandar.stojiljkovic
2016/09/27 18:08:28
Done.
| |
| 187 } | 181 } |
| 188 | 182 |
| 189 bool ImageBitmap::isResizeOptionValid(const ImageBitmapOptions& options, Excepti onState& exceptionState) | 183 bool ImageBitmap::isResizeOptionValid(const ImageBitmapOptions& options, Excepti onState& exceptionState) |
| 190 { | 184 { |
| 191 if ((options.hasResizeWidth() && options.resizeWidth() == 0) || (options.has ResizeHeight() && options.resizeHeight() == 0)) { | 185 if ((options.hasResizeWidth() && options.resizeWidth() == 0) || (options.has ResizeHeight() && options.resizeHeight() == 0)) { |
| 192 exceptionState.throwDOMException(InvalidStateError, "The resizeWidth or/ and resizeHeight is equal to 0."); | 186 exceptionState.throwDOMException(InvalidStateError, "The resizeWidth or/ and resizeHeight is equal to 0."); |
| 193 return false; | 187 return false; |
| 194 } | 188 } |
| 195 return true; | 189 return true; |
| 196 } | 190 } |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 FloatSize ImageBitmap::elementSize(const FloatSize&) const | 646 FloatSize ImageBitmap::elementSize(const FloatSize&) const |
| 653 { | 647 { |
| 654 return FloatSize(width(), height()); | 648 return FloatSize(width(), height()); |
| 655 } | 649 } |
| 656 | 650 |
| 657 DEFINE_TRACE(ImageBitmap) | 651 DEFINE_TRACE(ImageBitmap) |
| 658 { | 652 { |
| 659 } | 653 } |
| 660 | 654 |
| 661 } // namespace blink | 655 } // namespace blink |
| OLD | NEW |