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/html/canvas/OffscreenCanvas.h" | 5 #include "core/html/canvas/OffscreenCanvas.h" |
6 | 6 |
7 #include "core/html/canvas/CanvasContextCreationAttributes.h" | |
8 #include "core/html/canvas/OffscreenCanvasRenderingContext.h" | |
9 #include "core/html/canvas/OffscreenCanvasRenderingContextFactory.h" | |
7 #include "wtf/MathExtras.h" | 10 #include "wtf/MathExtras.h" |
8 | 11 |
9 namespace blink { | 12 namespace blink { |
10 | 13 |
11 OffscreenCanvas* OffscreenCanvas::create(unsigned width, unsigned height) | 14 OffscreenCanvas* OffscreenCanvas::create(unsigned width, unsigned height) |
12 { | 15 { |
13 return new OffscreenCanvas(IntSize(clampTo<int>(width), clampTo<int>(height) )); | 16 return new OffscreenCanvas(IntSize(clampTo<int>(width), clampTo<int>(height) )); |
14 } | 17 } |
15 | 18 |
16 void OffscreenCanvas::setWidth(unsigned width) | 19 void OffscreenCanvas::setWidth(unsigned width) |
17 { | 20 { |
18 m_size.setWidth(clampTo<int>(width)); | 21 m_size.setWidth(clampTo<int>(width)); |
19 } | 22 } |
20 | 23 |
21 void OffscreenCanvas::setHeight(unsigned height) | 24 void OffscreenCanvas::setHeight(unsigned height) |
22 { | 25 { |
23 m_size.setHeight(clampTo<int>(height)); | 26 m_size.setHeight(clampTo<int>(height)); |
24 } | 27 } |
25 | 28 |
26 OffscreenCanvas::OffscreenCanvas(const IntSize& size) | 29 OffscreenCanvas::OffscreenCanvas(const IntSize& size) |
27 : m_size(size) | 30 : m_size(size) |
28 { | 31 { |
29 } | 32 } |
30 | 33 |
34 OffscreenCanvasRenderingContext* OffscreenCanvas::getContext(const String& id, c onst CanvasContextCreationAttributes& attributes) | |
35 { | |
36 OffscreenCanvasRenderingContext::ContextType contextType = OffscreenCanvasRe nderingContext::contextTypeFromId(id); | |
37 | |
38 // Unknown type. | |
39 if (contextType == OffscreenCanvasRenderingContext::ContextTypeCount) | |
40 return nullptr; | |
41 | |
42 OffscreenCanvasRenderingContextFactory* factory = getRenderingContextFactory (contextType); | |
43 if (!factory) | |
44 return nullptr; | |
Justin Novosad
2016/03/02 15:41:50
This is correct, but it needs to be tested in a la
xlai (Olivia)
2016/03/03 22:50:06
Done for here and elsewhere.
| |
45 | |
46 if (m_context) { | |
47 if (m_context->contextType() == contextType) | |
48 return m_context.get(); | |
Justin Novosad
2016/03/02 15:41:50
This case needs to be covered in a layout test.
| |
49 | |
50 factory->onError(this, "OffscreenCanvas has an existing context of a dif ferent type"); | |
51 return nullptr; | |
Justin Novosad
2016/03/02 15:41:50
This case need to be covered in a layout test.
| |
52 } | |
53 | |
54 m_context = factory->create(this, attributes); | |
55 if (!m_context) | |
56 return nullptr; | |
Justin Novosad
2016/03/02 15:41:50
This is not necessary. The return statement below
| |
57 | |
58 return m_context.get(); | |
59 } | |
60 | |
61 OffscreenCanvas::ContextFactoryVector& OffscreenCanvas::renderingContextFactorie s() | |
62 { | |
63 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (OffscreenCanv asRenderingContext::ContextTypeCount)); | |
64 return s_contextFactories; | |
65 } | |
66 | |
67 OffscreenCanvasRenderingContextFactory* OffscreenCanvas::getRenderingContextFact ory(int type) | |
68 { | |
69 ASSERT(type < OffscreenCanvasRenderingContext::ContextTypeCount); | |
70 return renderingContextFactories()[type].get(); | |
71 } | |
72 | |
73 void OffscreenCanvas::registerRenderingContextFactory(PassOwnPtr<OffscreenCanvas RenderingContextFactory> renderingContextFactory) | |
74 { | |
75 OffscreenCanvasRenderingContext::ContextType type = renderingContextFactory- >contextType(); | |
76 ASSERT(type < OffscreenCanvasRenderingContext::ContextTypeCount); | |
77 ASSERT(!renderingContextFactories()[type]); | |
78 renderingContextFactories()[type] = renderingContextFactory; | |
79 } | |
80 | |
31 DEFINE_TRACE(OffscreenCanvas) | 81 DEFINE_TRACE(OffscreenCanvas) |
32 { | 82 { |
83 visitor->trace(m_context); | |
33 } | 84 } |
34 | 85 |
35 } // namespace blink | 86 } // namespace blink |
OLD | NEW |