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 25 matching lines...) Expand all Loading... |
36 static inline IntRect normalizeRect(const IntRect& rect) | 36 static inline IntRect normalizeRect(const IntRect& rect) |
37 { | 37 { |
38 return IntRect(std::min(rect.x(), rect.maxX()), | 38 return IntRect(std::min(rect.x(), rect.maxX()), |
39 std::min(rect.y(), rect.maxY()), | 39 std::min(rect.y(), rect.maxY()), |
40 std::max(rect.width(), -rect.width()), | 40 std::max(rect.width(), -rect.width()), |
41 std::max(rect.height(), -rect.height())); | 41 std::max(rect.height(), -rect.height())); |
42 } | 42 } |
43 | 43 |
44 static bool frameIsValid(const SkBitmap& frameBitmap) | 44 static bool frameIsValid(const SkBitmap& frameBitmap) |
45 { | 45 { |
46 ASSERT(!frameBitmap.isNull() && !frameBitmap.empty()); | 46 ASSERT(!frameBitmap.isNull() && !frameBitmap.empty() && frameBitmap.isImmuta
ble()); |
47 return frameBitmap.isImmutable() | 47 return frameBitmap.colorType() == kN32_SkColorType; |
48 && frameBitmap.colorType() == kN32_SkColorType; | |
49 } | 48 } |
50 | 49 |
51 static SkImage* flipSkImageVertically(SkImage* input) | 50 static SkImage* flipSkImageVertically(SkImage* input) |
52 { | 51 { |
53 int width = input->width(); | 52 int width = input->width(); |
54 int height = input->height(); | 53 int height = input->height(); |
55 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 54 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
56 OwnPtr<uint8_t[]> imagePixels = adoptArrayPtr(new uint8_t[width * height * i
nfo.bytesPerPixel()]); | 55 OwnPtr<uint8_t[]> imagePixels = adoptArrayPtr(new uint8_t[width * height * i
nfo.bytesPerPixel()]); |
57 int imageRowBytes = info.bytesPerPixel() * width; | 56 int imageRowBytes = info.bytesPerPixel() * width; |
58 input->readPixels(info, imagePixels.get(), imageRowBytes, 0, 0); | 57 input->readPixels(info, imagePixels.get(), imageRowBytes, 0, 0); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return nullptr; | 96 return nullptr; |
98 decoder->setData(image->data(), true); | 97 decoder->setData(image->data(), true); |
99 if (!decoder->frameCount()) | 98 if (!decoder->frameCount()) |
100 return nullptr; | 99 return nullptr; |
101 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 100 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
102 if (!frame || frame->status() != ImageFrame::FrameComplete) | 101 if (!frame || frame->status() != ImageFrame::FrameComplete) |
103 return nullptr; | 102 return nullptr; |
104 SkBitmap bitmap = frame->bitmap(); | 103 SkBitmap bitmap = frame->bitmap(); |
105 if (!frameIsValid(bitmap)) | 104 if (!frameIsValid(bitmap)) |
106 return nullptr; | 105 return nullptr; |
107 ASSERT(bitmap.isImmutable()); | |
108 skiaImage = adoptRef(SkImage::NewFromBitmap(bitmap)); | 106 skiaImage = adoptRef(SkImage::NewFromBitmap(bitmap)); |
109 } | 107 } |
110 | 108 |
111 if (cropRect == srcRect) { | 109 if (cropRect == srcRect) { |
112 if (flipYEnabled) | 110 if (flipYEnabled) |
113 return StaticBitmapImage::create(adoptRef(flipSkImageVertically(skia
Image->newSubset(srcRect)))); | 111 return StaticBitmapImage::create(adoptRef(flipSkImageVertically(skia
Image->newSubset(srcRect)))); |
114 return StaticBitmapImage::create(adoptRef(skiaImage->newSubset(srcRect))
); | 112 return StaticBitmapImage::create(adoptRef(skiaImage->newSubset(srcRect))
); |
115 } | 113 } |
116 | 114 |
117 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(cropRect.
width(), cropRect.height())); | 115 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(cropRect.
width(), cropRect.height())); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 { | 354 { |
357 return FloatSize(width(), height()); | 355 return FloatSize(width(), height()); |
358 } | 356 } |
359 | 357 |
360 DEFINE_TRACE(ImageBitmap) | 358 DEFINE_TRACE(ImageBitmap) |
361 { | 359 { |
362 ImageLoaderClient::trace(visitor); | 360 ImageLoaderClient::trace(visitor); |
363 } | 361 } |
364 | 362 |
365 } // namespace blink | 363 } // namespace blink |
OLD | NEW |