Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Side by Side Diff: third_party/WebKit/Source/core/html/canvas/OffscreenCanvas.cpp

Issue 1748163003: Add rendering context and rendering 2D context to OffscreenCanvas (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove CanvasRenderingContextBase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698