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" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 return nullptr; | 67 return nullptr; |
68 } | 68 } |
69 ImageBitmap* image = m_context->transferToImageBitmap(exceptionState); | 69 ImageBitmap* image = m_context->transferToImageBitmap(exceptionState); |
70 if (!image) { | 70 if (!image) { |
71 // Undocumented exception (not in spec) | 71 // Undocumented exception (not in spec) |
72 exceptionState.throwDOMException(V8Error, "Out of memory"); | 72 exceptionState.throwDOMException(V8Error, "Out of memory"); |
73 } | 73 } |
74 return image; | 74 return image; |
75 } | 75 } |
76 | 76 |
77 PassRefPtr<Image> OffscreenCanvas::getSourceImageForCanvas(SourceImageStatus* st
atus, AccelerationHint hint, SnapshotReason reason, const FloatSize&) const | 77 PassRefPtr<Image> OffscreenCanvas::getSourceImageForCanvas(SourceImageStatus* st
atus, AccelerationHint hint, SnapshotReason reason, const FloatSize& size) const |
78 { | 78 { |
79 if (!m_context) { | 79 if (!m_context) { |
80 *status = InvalidSourceImageStatus; | 80 *status = InvalidSourceImageStatus; |
81 return nullptr; | 81 return nullptr; |
82 } | 82 } |
83 *status = NormalSourceImageStatus; | 83 if (!size.width() || !size.height()) { |
84 return m_context->getImage(hint, reason); | 84 *status = ZeroSizeCanvasSourceImageStatus; |
| 85 return nullptr; |
| 86 } |
| 87 RefPtr<Image> image = m_context->getImage(hint, reason); |
| 88 if (!image) { |
| 89 *status = InvalidSourceImageStatus; |
| 90 } else { |
| 91 *status = NormalSourceImageStatus; |
| 92 } |
| 93 return image.release(); |
85 } | 94 } |
86 | 95 |
87 bool OffscreenCanvas::isOpaque() const | 96 bool OffscreenCanvas::isOpaque() const |
88 { | 97 { |
89 if (!m_context) | 98 if (!m_context) |
90 return false; | 99 return false; |
91 return !m_context->creationAttributes().hasAlpha(); | 100 return !m_context->creationAttributes().hasAlpha(); |
92 } | 101 } |
93 | 102 |
94 CanvasRenderingContext* OffscreenCanvas::getCanvasRenderingContext(ScriptState*
scriptState, const String& id, const CanvasContextCreationAttributes& attributes
) | 103 CanvasRenderingContext* OffscreenCanvas::getCanvasRenderingContext(ScriptState*
scriptState, const String& id, const CanvasContextCreationAttributes& attributes
) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 166 } |
158 return m_frameDispatcher.get(); | 167 return m_frameDispatcher.get(); |
159 } | 168 } |
160 | 169 |
161 DEFINE_TRACE(OffscreenCanvas) | 170 DEFINE_TRACE(OffscreenCanvas) |
162 { | 171 { |
163 visitor->trace(m_context); | 172 visitor->trace(m_context); |
164 } | 173 } |
165 | 174 |
166 } // namespace blink | 175 } // namespace blink |
OLD | NEW |