| 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/image-decoders/ImageDecoder.h" | 10 #include "platform/image-decoders/ImageDecoder.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return nullptr; | 128 return nullptr; |
| 129 decoder->setData(image->data(), true); | 129 decoder->setData(image->data(), true); |
| 130 skiaImage = ImageBitmap::getSkImageFromDecoder(decoder.release()); | 130 skiaImage = ImageBitmap::getSkImageFromDecoder(decoder.release()); |
| 131 if (!skiaImage) | 131 if (!skiaImage) |
| 132 return nullptr; | 132 return nullptr; |
| 133 } | 133 } |
| 134 | 134 |
| 135 if (cropRect == srcRect) { | 135 if (cropRect == srcRect) { |
| 136 if (flipY) | 136 if (flipY) |
| 137 return StaticBitmapImage::create(flipSkImageVertically(skiaImage->ne
wSubset(srcRect), premultiplyAlpha ? PremultiplyAlpha : DontPremultiplyAlpha)); | 137 return StaticBitmapImage::create(flipSkImageVertically(skiaImage->ne
wSubset(srcRect), premultiplyAlpha ? PremultiplyAlpha : DontPremultiplyAlpha)); |
| 138 return StaticBitmapImage::create(adoptRef(skiaImage->newSubset(srcRect))
); | 138 SkImage* croppedSkImage = skiaImage->newSubset(srcRect); |
| 139 if (cropRect == imgRect) { |
| 140 // Call readPixels to trigger image decoding. Only read 1*1 subregio
n to be efficient. |
| 141 SkImageInfo info = SkImageInfo::MakeN32(1, 1, premultiplyAlpha ? kPr
emul_SkAlphaType : kUnpremul_SkAlphaType); |
| 142 OwnPtr<uint8_t[]> imagePixels = adoptArrayPtr(new uint8_t[info.bytes
PerPixel()]); |
| 143 croppedSkImage->readPixels(info, imagePixels.get(), info.bytesPerPix
el(), 0, 0); |
| 144 } |
| 145 return StaticBitmapImage::create(adoptRef(croppedSkImage)); |
| 139 } | 146 } |
| 140 | 147 |
| 141 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(cropRect.
width(), cropRect.height())); | 148 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(cropRect.
width(), cropRect.height())); |
| 142 if (!surface) | 149 if (!surface) |
| 143 return nullptr; | 150 return nullptr; |
| 144 if (srcRect.isEmpty()) | 151 if (srcRect.isEmpty()) |
| 145 return StaticBitmapImage::create(adoptRef(surface->newImageSnapshot())); | 152 return StaticBitmapImage::create(adoptRef(surface->newImageSnapshot())); |
| 146 | 153 |
| 147 SkScalar dstLeft = std::min(0, -cropRect.x()); | 154 SkScalar dstLeft = std::min(0, -cropRect.x()); |
| 148 SkScalar dstTop = std::min(0, -cropRect.y()); | 155 SkScalar dstTop = std::min(0, -cropRect.y()); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 FloatSize ImageBitmap::elementSize(const FloatSize&) const | 453 FloatSize ImageBitmap::elementSize(const FloatSize&) const |
| 447 { | 454 { |
| 448 return FloatSize(width(), height()); | 455 return FloatSize(width(), height()); |
| 449 } | 456 } |
| 450 | 457 |
| 451 DEFINE_TRACE(ImageBitmap) | 458 DEFINE_TRACE(ImageBitmap) |
| 452 { | 459 { |
| 453 } | 460 } |
| 454 | 461 |
| 455 } // namespace blink | 462 } // namespace blink |
| OLD | NEW |