| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/offscreencanvas/OffscreenCanvas.h" | 5 #include "core/offscreencanvas/OffscreenCanvas.h" |
| 6 | 6 |
| 7 #include "core/dom/ExceptionCode.h" | 7 #include "core/dom/ExceptionCode.h" |
| 8 #include "core/html/canvas/CanvasContextCreationAttributes.h" | 8 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
| 9 #include "core/html/canvas/CanvasRenderingContext.h" | 9 #include "core/html/canvas/CanvasRenderingContext.h" |
| 10 #include "core/html/canvas/CanvasRenderingContextFactory.h" | 10 #include "core/html/canvas/CanvasRenderingContextFactory.h" |
| 11 #include "platform/graphics/ImageBuffer.h" | 11 #include "platform/graphics/ImageBuffer.h" |
| 12 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" | |
| 13 #include "wtf/MathExtras.h" | 12 #include "wtf/MathExtras.h" |
| 14 #include <memory> | 13 #include <memory> |
| 15 | 14 |
| 16 namespace blink { | 15 namespace blink { |
| 17 | 16 |
| 18 OffscreenCanvas::OffscreenCanvas(const IntSize& size) | 17 OffscreenCanvas::OffscreenCanvas(const IntSize& size) |
| 19 : m_size(size) | 18 : m_size(size) |
| 20 , m_originClean(true) | 19 , m_originClean(true) |
| 21 { | 20 { |
| 22 } | 21 } |
| 23 | 22 |
| 24 OffscreenCanvas* OffscreenCanvas::create(unsigned width, unsigned height) | 23 OffscreenCanvas* OffscreenCanvas::create(unsigned width, unsigned height) |
| 25 { | 24 { |
| 26 return new OffscreenCanvas(IntSize(clampTo<int>(width), clampTo<int>(height)
)); | 25 return new OffscreenCanvas(IntSize(clampTo<int>(width), clampTo<int>(height)
)); |
| 27 } | 26 } |
| 28 | 27 |
| 29 void OffscreenCanvas::setWidth(unsigned width) | 28 void OffscreenCanvas::setWidth(unsigned width) |
| 30 { | 29 { |
| 31 // If this OffscreenCanvas is transferred control by an html canvas, | |
| 32 // its size is determined by html canvas's size and cannot be resized. | |
| 33 if (m_canvasId >= 0) | |
| 34 return; | |
| 35 m_size.setWidth(clampTo<int>(width)); | 30 m_size.setWidth(clampTo<int>(width)); |
| 36 } | 31 } |
| 37 | 32 |
| 38 void OffscreenCanvas::setHeight(unsigned height) | 33 void OffscreenCanvas::setHeight(unsigned height) |
| 39 { | 34 { |
| 40 // Same comment as above. | |
| 41 if (m_canvasId >= 0) | |
| 42 return; | |
| 43 m_size.setHeight(clampTo<int>(height)); | 35 m_size.setHeight(clampTo<int>(height)); |
| 44 } | 36 } |
| 45 | 37 |
| 46 void OffscreenCanvas::setNeutered() | 38 void OffscreenCanvas::setNeutered() |
| 47 { | 39 { |
| 48 ASSERT(!m_context); | 40 ASSERT(!m_context); |
| 49 m_isNeutered = true; | 41 m_isNeutered = true; |
| 50 m_size.setWidth(0); | 42 m_size.setWidth(0); |
| 51 m_size.setHeight(0); | 43 m_size.setHeight(0); |
| 52 } | 44 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return m_originClean && !m_disableReadingFromCanvas; | 127 return m_originClean && !m_disableReadingFromCanvas; |
| 136 } | 128 } |
| 137 | 129 |
| 138 bool OffscreenCanvas::isPaintable() const | 130 bool OffscreenCanvas::isPaintable() const |
| 139 { | 131 { |
| 140 if (!m_context) | 132 if (!m_context) |
| 141 return ImageBuffer::canCreateImageBuffer(m_size); | 133 return ImageBuffer::canCreateImageBuffer(m_size); |
| 142 return m_context->isPaintable(); | 134 return m_context->isPaintable(); |
| 143 } | 135 } |
| 144 | 136 |
| 145 OffscreenCanvasFrameDispatcher* OffscreenCanvas::getOrCreateFrameDispatcher() | |
| 146 { | |
| 147 if (!m_frameDispatcher) | |
| 148 m_frameDispatcher = wrapUnique(new OffscreenCanvasFrameDispatcherImpl(m_
clientId, m_localId, m_nonce, width(), height())); | |
| 149 return m_frameDispatcher.get(); | |
| 150 } | |
| 151 | |
| 152 DEFINE_TRACE(OffscreenCanvas) | 137 DEFINE_TRACE(OffscreenCanvas) |
| 153 { | 138 { |
| 154 visitor->trace(m_context); | 139 visitor->trace(m_context); |
| 155 } | 140 } |
| 156 | 141 |
| 157 } // namespace blink | 142 } // namespace blink |
| OLD | NEW |