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 "modules/offscreencanvas/OffscreenCanvas.h" | 5 #include "modules/offscreencanvas/OffscreenCanvas.h" |
6 | 6 |
| 7 #if !ENABLE(OILPAN) |
| 8 #include "core/frame/ImageBitmap.h" // So ~RefPtr can call unref() |
| 9 #endif |
7 #include "core/html/canvas/CanvasContextCreationAttributes.h" | 10 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
8 #include "modules/offscreencanvas/OffscreenCanvasRenderingContext.h" | 11 #include "modules/offscreencanvas/OffscreenCanvasRenderingContext.h" |
9 #include "modules/offscreencanvas/OffscreenCanvasRenderingContextFactory.h" | 12 #include "modules/offscreencanvas/OffscreenCanvasRenderingContextFactory.h" |
10 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" | 13 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" |
11 #include "wtf/MathExtras.h" | 14 #include "wtf/MathExtras.h" |
12 | 15 |
13 namespace blink { | 16 namespace blink { |
14 | 17 |
| 18 OffscreenCanvas::OffscreenCanvas(const IntSize& size) |
| 19 : m_size(size) |
| 20 { } |
| 21 |
| 22 OffscreenCanvas::~OffscreenCanvas() |
| 23 { } |
| 24 |
15 OffscreenCanvas* OffscreenCanvas::create(unsigned width, unsigned height) | 25 OffscreenCanvas* OffscreenCanvas::create(unsigned width, unsigned height) |
16 { | 26 { |
17 return new OffscreenCanvas(IntSize(clampTo<int>(width), clampTo<int>(height)
)); | 27 return new OffscreenCanvas(IntSize(clampTo<int>(width), clampTo<int>(height)
)); |
18 } | 28 } |
19 | 29 |
20 void OffscreenCanvas::setWidth(unsigned width) | 30 void OffscreenCanvas::setWidth(unsigned width) |
21 { | 31 { |
22 m_size.setWidth(clampTo<int>(width)); | 32 m_size.setWidth(clampTo<int>(width)); |
23 } | 33 } |
24 | 34 |
25 void OffscreenCanvas::setHeight(unsigned height) | 35 void OffscreenCanvas::setHeight(unsigned height) |
26 { | 36 { |
27 m_size.setHeight(clampTo<int>(height)); | 37 m_size.setHeight(clampTo<int>(height)); |
28 } | 38 } |
29 | 39 |
30 OffscreenCanvas::OffscreenCanvas(const IntSize& size) | |
31 : m_size(size) | |
32 { | |
33 } | |
34 | |
35 OffscreenCanvasRenderingContext2D* OffscreenCanvas::getContext(const String& id,
const CanvasContextCreationAttributes& attributes) | 40 OffscreenCanvasRenderingContext2D* OffscreenCanvas::getContext(const String& id,
const CanvasContextCreationAttributes& attributes) |
36 { | 41 { |
37 OffscreenCanvasRenderingContext::ContextType contextType = OffscreenCanvasRe
nderingContext::contextTypeFromId(id); | 42 OffscreenCanvasRenderingContext::ContextType contextType = OffscreenCanvasRe
nderingContext::contextTypeFromId(id); |
38 | 43 |
39 // Unknown type. | 44 // Unknown type. |
40 if (contextType == OffscreenCanvasRenderingContext::ContextTypeCount) | 45 if (contextType == OffscreenCanvasRenderingContext::ContextTypeCount) |
41 return nullptr; | 46 return nullptr; |
42 | 47 |
43 OffscreenCanvasRenderingContextFactory* factory = getRenderingContextFactory
(contextType); | 48 OffscreenCanvasRenderingContextFactory* factory = getRenderingContextFactory
(contextType); |
44 if (!factory) | 49 if (!factory) |
45 return nullptr; | 50 return nullptr; |
46 | 51 |
47 if (m_context) { | 52 if (m_context) { |
48 if (m_context->contextType() != contextType) { | 53 if (m_context->contextType() != contextType) { |
49 factory->onError(this, "OffscreenCanvas has an existing context of a
different type"); | 54 factory->onError(this, "OffscreenCanvas has an existing context of a
different type"); |
50 return nullptr; | 55 return nullptr; |
51 } | 56 } |
52 } else { | 57 } else { |
53 m_context = factory->create(this, attributes); | 58 m_context = factory->create(this, attributes); |
54 } | 59 } |
55 | 60 |
56 // TODO: When there're more than one context type implemented in the future, | 61 // TODO: When there're more than one context type implemented in the future, |
57 // the return type here should be changed to base class of all Offscreen | 62 // the return type here should be changed to base class of all Offscreen |
58 // context types. | 63 // context types. |
59 return static_cast<OffscreenCanvasRenderingContext2D*>(m_context.get()); | 64 return static_cast<OffscreenCanvasRenderingContext2D*>(m_context.get()); |
60 } | 65 } |
61 | 66 |
| 67 PassRefPtrWillBeRawPtr<ImageBitmap> OffscreenCanvas::transferToImageBitmap(Excep
tionState& exceptionState) |
| 68 { |
| 69 return m_context->transferToImageBitmap(exceptionState); |
| 70 } |
| 71 |
62 OffscreenCanvasRenderingContext2D* OffscreenCanvas::renderingContext() const | 72 OffscreenCanvasRenderingContext2D* OffscreenCanvas::renderingContext() const |
63 { | 73 { |
64 // TODO: When there're more than one context type implemented in the future, | 74 // TODO: When there're more than one context type implemented in the future, |
65 // the return type here should be changed to base class of all Offscreen | 75 // the return type here should be changed to base class of all Offscreen |
66 // context types. | 76 // context types. |
67 return static_cast<OffscreenCanvasRenderingContext2D*>(m_context.get()); | 77 return static_cast<OffscreenCanvasRenderingContext2D*>(m_context.get()); |
68 } | 78 } |
69 | 79 |
70 OffscreenCanvas::ContextFactoryVector& OffscreenCanvas::renderingContextFactorie
s() | 80 OffscreenCanvas::ContextFactoryVector& OffscreenCanvas::renderingContextFactorie
s() |
71 { | 81 { |
(...skipping 14 matching lines...) Expand all Loading... |
86 ASSERT(!renderingContextFactories()[type]); | 96 ASSERT(!renderingContextFactories()[type]); |
87 renderingContextFactories()[type] = renderingContextFactory; | 97 renderingContextFactories()[type] = renderingContextFactory; |
88 } | 98 } |
89 | 99 |
90 DEFINE_TRACE(OffscreenCanvas) | 100 DEFINE_TRACE(OffscreenCanvas) |
91 { | 101 { |
92 visitor->trace(m_context); | 102 visitor->trace(m_context); |
93 } | 103 } |
94 | 104 |
95 } // namespace blink | 105 } // namespace blink |
OLD | NEW |