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/fileapi/Blob.h" | 8 #include "core/fileapi/Blob.h" |
9 #include "core/html/ImageData.h" | 9 #include "core/html/ImageData.h" |
10 #include "core/html/canvas/CanvasAsyncBlobCreator.h" | 10 #include "core/html/canvas/CanvasAsyncBlobCreator.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 namespace blink { | 22 namespace blink { |
23 | 23 |
24 OffscreenCanvas::OffscreenCanvas(const IntSize& size) | 24 OffscreenCanvas::OffscreenCanvas(const IntSize& size) |
25 : m_size(size), m_originClean(true) {} | 25 : m_size(size), m_originClean(true) {} |
26 | 26 |
27 OffscreenCanvas* OffscreenCanvas::create(unsigned width, unsigned height) { | 27 OffscreenCanvas* OffscreenCanvas::create(unsigned width, unsigned height) { |
28 return new OffscreenCanvas( | 28 return new OffscreenCanvas( |
29 IntSize(clampTo<int>(width), clampTo<int>(height))); | 29 IntSize(clampTo<int>(width), clampTo<int>(height))); |
30 } | 30 } |
31 | 31 |
32 void OffscreenCanvas::setWidth(unsigned width, ExceptionState& exceptionState) { | 32 void OffscreenCanvas::setWidth(unsigned width) { |
33 // If this OffscreenCanvas is transferred control by an html canvas, | 33 IntSize newSize = m_size; |
34 // its size is determined by html canvas's size and cannot be resized. | 34 newSize.setWidth(clampTo<int>(width)); |
35 if (hasPlaceholderCanvas()) { | 35 setSize(newSize); |
36 exceptionState.throwDOMException(InvalidStateError, | |
37 "Resizing is not allowed on an " | |
38 "OffscreenCanvas that has been " | |
39 "transferred control from a canvas."); | |
40 return; | |
41 } | |
42 m_size.setWidth(clampTo<int>(width)); | |
43 } | 36 } |
44 | 37 |
45 void OffscreenCanvas::setHeight(unsigned height, | 38 void OffscreenCanvas::setHeight(unsigned height) { |
46 ExceptionState& exceptionState) { | 39 IntSize newSize = m_size; |
47 // Same comment as above. | 40 newSize.setHeight(clampTo<int>(height)); |
48 if (hasPlaceholderCanvas()) { | 41 setSize(newSize); |
49 exceptionState.throwDOMException(InvalidStateError, | 42 } |
50 "Resizing is not allowed on an " | 43 |
51 "OffscreenCanvas that has been " | 44 void OffscreenCanvas::setSize(const IntSize& size) { |
xidachen
2016/11/17 02:12:22
OK, I am a little confused here. The logic here so
| |
52 "transferred control from a canvas."); | 45 if (m_context) { |
53 return; | 46 if (m_context->is3d()) { |
47 if (size != m_size) | |
48 m_context->reshape(size.width(), size.height()); | |
49 } else if (m_context->is2d()) { | |
50 m_context->reset(); | |
51 } | |
54 } | 52 } |
55 m_size.setHeight(clampTo<int>(height)); | 53 m_size = size; |
56 } | 54 } |
57 | 55 |
58 void OffscreenCanvas::setNeutered() { | 56 void OffscreenCanvas::setNeutered() { |
59 ASSERT(!m_context); | 57 ASSERT(!m_context); |
60 m_isNeutered = true; | 58 m_isNeutered = true; |
61 m_size.setWidth(0); | 59 m_size.setWidth(0); |
62 m_size.setHeight(0); | 60 m_size.setHeight(0); |
63 } | 61 } |
64 | 62 |
65 ImageBitmap* OffscreenCanvas::transferToImageBitmap( | 63 ImageBitmap* OffscreenCanvas::transferToImageBitmap( |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 return resolver->promise(); | 235 return resolver->promise(); |
238 } | 236 } |
239 | 237 |
240 DEFINE_TRACE(OffscreenCanvas) { | 238 DEFINE_TRACE(OffscreenCanvas) { |
241 visitor->trace(m_context); | 239 visitor->trace(m_context); |
242 visitor->trace(m_executionContext); | 240 visitor->trace(m_executionContext); |
243 EventTarget::trace(visitor); | 241 EventTarget::trace(visitor); |
244 } | 242 } |
245 | 243 |
246 } // namespace blink | 244 } // namespace blink |
OLD | NEW |