| 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/page/ImageBitmap.h" | 6 #include "core/page/ImageBitmap.h" |
| 7 | 7 |
| 8 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
| 9 #include "core/html/HTMLImageElement.h" | 9 #include "core/html/HTMLImageElement.h" |
| 10 #include "core/html/HTMLVideoElement.h" | 10 #include "core/html/HTMLVideoElement.h" |
| 11 #include "core/html/ImageData.h" | 11 #include "core/html/ImageData.h" |
| 12 #include "core/html/canvas/CanvasRenderingContext.h" |
| 12 #include "core/platform/graphics/BitmapImage.h" | 13 #include "core/platform/graphics/BitmapImage.h" |
| 13 #include "core/platform/graphics/GraphicsContext.h" | 14 #include "core/platform/graphics/GraphicsContext.h" |
| 14 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
| 15 | 16 |
| 16 using namespace std; | 17 using namespace std; |
| 17 | 18 |
| 18 namespace WebCore { | 19 namespace WebCore { |
| 19 | 20 |
| 20 static inline IntRect normalizeRect(const IntRect& rect) | 21 static inline IntRect normalizeRect(const IntRect& rect) |
| 21 { | 22 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 72 |
| 72 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | 73 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) |
| 73 : m_cropRect(cropRect) | 74 : m_cropRect(cropRect) |
| 74 , m_imageElement(0) | 75 , m_imageElement(0) |
| 75 , m_bitmapOffset(IntPoint()) | 76 , m_bitmapOffset(IntPoint()) |
| 76 { | 77 { |
| 77 IntSize canvasSize = canvas->size(); | 78 IntSize canvasSize = canvas->size(); |
| 78 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvasSize)); | 79 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvasSize)); |
| 79 IntRect dstRect(IntPoint(), srcRect.size()); | 80 IntRect dstRect(IntPoint(), srcRect.size()); |
| 80 | 81 |
| 82 CanvasRenderingContext* sourceContext = canvas->renderingContext(); |
| 83 if (sourceContext && sourceContext->is3d()) |
| 84 sourceContext->paintRenderingResultsToCanvas(); |
| 85 |
| 81 m_buffer = ImageBuffer::create(canvasSize); | 86 m_buffer = ImageBuffer::create(canvasSize); |
| 82 m_buffer->context()->drawImageBuffer(canvas->buffer(), dstRect, srcRect); | 87 m_buffer->context()->drawImageBuffer(canvas->buffer(), dstRect, srcRect); |
| 83 m_bitmap = m_buffer->copyImage(DontCopyBackingStore); | 88 m_bitmap = m_buffer->copyImage(DontCopyBackingStore); |
| 84 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())
), srcRect.size()); | 89 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())
), srcRect.size()); |
| 85 | 90 |
| 86 ScriptWrappable::init(this); | 91 ScriptWrappable::init(this); |
| 87 } | 92 } |
| 88 | 93 |
| 89 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 94 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
| 90 : m_cropRect(cropRect) | 95 : m_cropRect(cropRect) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 191 |
| 187 PassRefPtr<Image> ImageBitmap::bitmapImage() const | 192 PassRefPtr<Image> ImageBitmap::bitmapImage() const |
| 188 { | 193 { |
| 189 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect
.height()) && (!m_imageElement || !m_bitmap)); | 194 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect
.height()) && (!m_imageElement || !m_bitmap)); |
| 190 if (m_imageElement) | 195 if (m_imageElement) |
| 191 return m_imageElement->cachedImage()->image(); | 196 return m_imageElement->cachedImage()->image(); |
| 192 return m_bitmap; | 197 return m_bitmap; |
| 193 } | 198 } |
| 194 | 199 |
| 195 } | 200 } |
| OLD | NEW |