| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/frame/ImageBitmap.h" | 6 #include "core/frame/ImageBitmap.h" |
| 7 | 7 |
| 8 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
| 9 #include "core/html/HTMLVideoElement.h" | 9 #include "core/html/HTMLVideoElement.h" |
| 10 #include "core/html/ImageData.h" | 10 #include "core/html/ImageData.h" |
| 11 #include "platform/graphics/BitmapImage.h" | 11 #include "platform/graphics/BitmapImage.h" |
| 12 #include "platform/graphics/GraphicsContext.h" | 12 #include "platform/graphics/GraphicsContext.h" |
| 13 #include "platform/graphics/ImageBuffer.h" | 13 #include "platform/graphics/ImageBuffer.h" |
| 14 #include "platform/graphics/paint/DisplayItemListContextRecorder.h" | |
| 15 #include "platform/graphics/paint/DrawingRecorder.h" | 14 #include "platform/graphics/paint/DrawingRecorder.h" |
| 15 #include "platform/graphics/paint/SkPictureBuilder.h" |
| 16 #include "wtf/RefPtr.h" | 16 #include "wtf/RefPtr.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 static inline IntRect normalizeRect(const IntRect& rect) | 20 static inline IntRect normalizeRect(const IntRect& rect) |
| 21 { | 21 { |
| 22 return IntRect(std::min(rect.x(), rect.maxX()), | 22 return IntRect(std::min(rect.x(), rect.maxX()), |
| 23 std::min(rect.y(), rect.maxY()), | 23 std::min(rect.y(), rect.maxY()), |
| 24 std::max(rect.width(), -rect.width()), | 24 std::max(rect.width(), -rect.width()), |
| 25 std::max(rect.height(), -rect.height())); | 25 std::max(rect.height(), -rect.height())); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 playerSize = video->webMediaPlayer()->naturalSize(); | 66 playerSize = video->webMediaPlayer()->naturalSize(); |
| 67 | 67 |
| 68 IntRect videoRect = IntRect(IntPoint(), playerSize); | 68 IntRect videoRect = IntRect(IntPoint(), playerSize); |
| 69 IntRect srcRect = intersection(cropRect, videoRect); | 69 IntRect srcRect = intersection(cropRect, videoRect); |
| 70 IntRect dstRect(IntPoint(), srcRect.size()); | 70 IntRect dstRect(IntPoint(), srcRect.size()); |
| 71 | 71 |
| 72 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(videoRect.size()); | 72 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(videoRect.size()); |
| 73 if (!buffer) | 73 if (!buffer) |
| 74 return; | 74 return; |
| 75 | 75 |
| 76 { | 76 buffer->canvas()->clipRect(dstRect); |
| 77 DisplayItemListContextRecorder contextRecorder(*buffer->context()); | 77 buffer->canvas()->translate(-srcRect.x(), -srcRect.y()); |
| 78 GraphicsContext& paintContext = contextRecorder.context(); | |
| 79 | |
| 80 DrawingRecorder recorder(paintContext, *buffer, DisplayItem::VideoBitmap
, videoRect); | |
| 81 if (!recorder.canUseCachedDrawing()) { | |
| 82 paintContext.clip(dstRect); | |
| 83 paintContext.translate(-srcRect.x(), -srcRect.y()); | |
| 84 } | |
| 85 } | |
| 86 | 78 |
| 87 video->paintCurrentFrame(buffer->canvas(), videoRect, nullptr); | 79 video->paintCurrentFrame(buffer->canvas(), videoRect, nullptr); |
| 88 m_bitmap = buffer->copyImage(DontCopyBackingStore); | 80 m_bitmap = buffer->copyImage(DontCopyBackingStore); |
| 89 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 81 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
| 90 } | 82 } |
| 91 | 83 |
| 92 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | 84 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) |
| 93 : m_imageElement(nullptr) | 85 : m_imageElement(nullptr) |
| 94 , m_cropRect(cropRect) | 86 , m_cropRect(cropRect) |
| 95 , m_bitmapOffset(IntPoint()) | 87 , m_bitmapOffset(IntPoint()) |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return FloatSize(width(), height()); | 220 return FloatSize(width(), height()); |
| 229 } | 221 } |
| 230 | 222 |
| 231 DEFINE_TRACE(ImageBitmap) | 223 DEFINE_TRACE(ImageBitmap) |
| 232 { | 224 { |
| 233 visitor->trace(m_imageElement); | 225 visitor->trace(m_imageElement); |
| 234 ImageLoaderClient::trace(visitor); | 226 ImageLoaderClient::trace(visitor); |
| 235 } | 227 } |
| 236 | 228 |
| 237 } // namespace blink | 229 } // namespace blink |
| OLD | NEW |