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 "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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 } | 65 } |
| 65 | 66 |
| 66 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | 67 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) |
| 67 : m_cropRect(cropRect) | 68 : m_cropRect(cropRect) |
| 68 , m_imageElement(0) | 69 , m_imageElement(0) |
| 69 { | 70 { |
| 70 IntSize canvasSize = canvas->size(); | 71 IntSize canvasSize = canvas->size(); |
| 71 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvasSize)); | 72 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvasSize)); |
| 72 IntRect dstRect(IntPoint(), srcRect.size()); | 73 IntRect dstRect(IntPoint(), srcRect.size()); |
| 73 | 74 |
| 75 CanvasRenderingContext* sourceContext = canvas->renderingContext(); | |
| 76 if (!sourceContext || !sourceContext->isAccelerated() || !sourceContext->is2 d()) | |
|
Justin Novosad
2013/08/19 20:20:51
Do we really need to call makeRenderingResultsAvai
| |
| 77 canvas->makeRenderingResultsAvailable(); | |
| 78 | |
| 74 m_buffer = ImageBuffer::create(canvasSize); | 79 m_buffer = ImageBuffer::create(canvasSize); |
| 75 m_buffer->context()->drawImageBuffer(canvas->buffer(), dstRect, srcRect); | 80 m_buffer->context()->drawImageBuffer(canvas->buffer(), dstRect, srcRect); |
| 76 m_bitmap = m_buffer->copyImage(DontCopyBackingStore); | 81 m_bitmap = m_buffer->copyImage(DontCopyBackingStore); |
| 77 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); | 82 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); |
| 78 | 83 |
| 79 ScriptWrappable::init(this); | 84 ScriptWrappable::init(this); |
| 80 } | 85 } |
| 81 | 86 |
| 82 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 87 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
| 83 : m_cropRect(cropRect) | 88 : m_cropRect(cropRect) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 167 |
| 163 PassRefPtr<Image> ImageBitmap::bitmapImage() const | 168 PassRefPtr<Image> ImageBitmap::bitmapImage() const |
| 164 { | 169 { |
| 165 ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap)); | 170 ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap)); |
| 166 if (m_imageElement) | 171 if (m_imageElement) |
| 167 return cropImage(m_imageElement->cachedImage()->image(), m_cropRect); | 172 return cropImage(m_imageElement->cachedImage()->image(), m_cropRect); |
| 168 return m_bitmap; | 173 return m_bitmap; |
| 169 } | 174 } |
| 170 | 175 |
| 171 } | 176 } |
| OLD | NEW |