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

Side by Side Diff: third_party/WebKit/Source/modules/offscreencanvas/OffscreenCanvas.cpp

Issue 1862033002: Make OffscreenCanvas Transferable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no need to register, taking the same approach as extractTransferables Created 4 years, 8 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 "modules/offscreencanvas/OffscreenCanvas.h" 5 #include "modules/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 "modules/offscreencanvas/OffscreenCanvasRenderingContext.h" 9 #include "modules/offscreencanvas/OffscreenCanvasRenderingContext.h"
10 #include "modules/offscreencanvas/OffscreenCanvasRenderingContextFactory.h" 10 #include "modules/offscreencanvas/OffscreenCanvasRenderingContextFactory.h"
(...skipping 17 matching lines...) Expand all
28 void OffscreenCanvas::setWidth(unsigned width) 28 void OffscreenCanvas::setWidth(unsigned width)
29 { 29 {
30 m_size.setWidth(clampTo<int>(width)); 30 m_size.setWidth(clampTo<int>(width));
31 } 31 }
32 32
33 void OffscreenCanvas::setHeight(unsigned height) 33 void OffscreenCanvas::setHeight(unsigned height)
34 { 34 {
35 m_size.setHeight(clampTo<int>(height)); 35 m_size.setHeight(clampTo<int>(height));
36 } 36 }
37 37
38 OffscreenCanvasRenderingContext2D* OffscreenCanvas::getContext(const String& id, const CanvasContextCreationAttributes& attributes) 38 void OffscreenCanvas::setNeutered()
39 { 39 {
40 ASSERT(!m_context);
41 m_isNeutered = true;
42 m_size.setWidth(0);
43 m_size.setHeight(0);
44 }
45
46 OffscreenCanvasRenderingContext2D* OffscreenCanvas::getContext(const String& id, const CanvasContextCreationAttributes& attributes, ExceptionState& exceptionSta te)
47 {
48 if (m_isNeutered) {
49 exceptionState.throwDOMException(InvalidStateError, "Cannot get context of a neutered OffscreenCanvas");
50 return nullptr;
51 }
52
40 OffscreenCanvasRenderingContext::ContextType contextType = OffscreenCanvasRe nderingContext::contextTypeFromId(id); 53 OffscreenCanvasRenderingContext::ContextType contextType = OffscreenCanvasRe nderingContext::contextTypeFromId(id);
41 54
42 // Unknown type. 55 // Unknown type.
43 if (contextType == OffscreenCanvasRenderingContext::ContextTypeCount) 56 if (contextType == OffscreenCanvasRenderingContext::ContextTypeCount)
44 return nullptr; 57 return nullptr;
45 58
46 OffscreenCanvasRenderingContextFactory* factory = getRenderingContextFactory (contextType); 59 OffscreenCanvasRenderingContextFactory* factory = getRenderingContextFactory (contextType);
47 if (!factory) 60 if (!factory)
48 return nullptr; 61 return nullptr;
49 62
50 if (m_context) { 63 if (m_context) {
51 if (m_context->getContextType() != contextType) { 64 if (m_context->getContextType() != contextType) {
52 factory->onError(this, "OffscreenCanvas has an existing context of a different type"); 65 factory->onError(this, "OffscreenCanvas has an existing context of a different type");
53 return nullptr; 66 return nullptr;
54 } 67 }
55 } else { 68 } else {
56 m_context = factory->create(this, attributes); 69 m_context = factory->create(this, attributes);
57 } 70 }
58 71
59 // TODO: When there're more than one context type implemented in the future, 72 // TODO: When there're more than one context type implemented in the future,
60 // the return type here should be changed to base class of all Offscreen 73 // the return type here should be changed to base class of all Offscreen
61 // context types. 74 // context types.
62 return static_cast<OffscreenCanvasRenderingContext2D*>(m_context.get()); 75 return static_cast<OffscreenCanvasRenderingContext2D*>(m_context.get());
63 } 76 }
64 77
65 ImageBitmap* OffscreenCanvas::transferToImageBitmap(ExceptionState& exceptionSta te) 78 ImageBitmap* OffscreenCanvas::transferToImageBitmap(ExceptionState& exceptionSta te)
66 { 79 {
80 if (m_isNeutered) {
81 exceptionState.throwDOMException(InvalidStateError, "Cannot transfer an ImageBitmap from a neutered OffscreenCanvas");
82 return nullptr;
83 }
67 if (!m_context) { 84 if (!m_context) {
68 exceptionState.throwDOMException(InvalidStateError, "Cannot transfer an ImageBitmap from an OffscreenCanvas with no context"); 85 exceptionState.throwDOMException(InvalidStateError, "Cannot transfer an ImageBitmap from an OffscreenCanvas with no context");
69 return nullptr; 86 return nullptr;
70 } 87 }
71 ImageBitmap* image = m_context->transferToImageBitmap(exceptionState); 88 ImageBitmap* image = m_context->transferToImageBitmap(exceptionState);
72 if (!image) { 89 if (!image) {
73 // Undocumented exception (not in spec) 90 // Undocumented exception (not in spec)
74 exceptionState.throwDOMException(V8GeneralError, "Out of memory"); 91 exceptionState.throwDOMException(V8GeneralError, "Out of memory");
75 } 92 }
76 return image; 93 return image;
77 } 94 }
78 95
79 OffscreenCanvasRenderingContext2D* OffscreenCanvas::renderingContext() const 96 OffscreenCanvasRenderingContext2D* OffscreenCanvas::renderingContext() const
80 { 97 {
98 ASSERT(!m_isNeutered);
81 // TODO: When there're more than one context type implemented in the future, 99 // TODO: When there're more than one context type implemented in the future,
82 // the return type here should be changed to base class of all Offscreen 100 // the return type here should be changed to base class of all Offscreen
83 // context types. 101 // context types.
84 return static_cast<OffscreenCanvasRenderingContext2D*>(m_context.get()); 102 return static_cast<OffscreenCanvasRenderingContext2D*>(m_context.get());
85 } 103 }
86 104
87 OffscreenCanvas::ContextFactoryVector& OffscreenCanvas::renderingContextFactorie s() 105 OffscreenCanvas::ContextFactoryVector& OffscreenCanvas::renderingContextFactorie s()
88 { 106 {
89 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (OffscreenCanv asRenderingContext::ContextTypeCount)); 107 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (OffscreenCanv asRenderingContext::ContextTypeCount));
90 return s_contextFactories; 108 return s_contextFactories;
91 } 109 }
92 110
93 OffscreenCanvasRenderingContextFactory* OffscreenCanvas::getRenderingContextFact ory(int type) 111 OffscreenCanvasRenderingContextFactory* OffscreenCanvas::getRenderingContextFact ory(int type)
94 { 112 {
95 ASSERT(type < OffscreenCanvasRenderingContext::ContextTypeCount); 113 ASSERT(type < OffscreenCanvasRenderingContext::ContextTypeCount);
96 return renderingContextFactories()[type].get(); 114 return renderingContextFactories()[type].get();
97 } 115 }
98 116
99 void OffscreenCanvas::registerRenderingContextFactory(PassOwnPtr<OffscreenCanvas RenderingContextFactory> renderingContextFactory) 117 void OffscreenCanvas::registerRenderingContextFactory(PassOwnPtr<OffscreenCanvas RenderingContextFactory> renderingContextFactory)
100 { 118 {
101 OffscreenCanvasRenderingContext::ContextType type = renderingContextFactory- >getContextType(); 119 OffscreenCanvasRenderingContext::ContextType type = renderingContextFactory- >getContextType();
102 ASSERT(type < OffscreenCanvasRenderingContext::ContextTypeCount); 120 ASSERT(type < OffscreenCanvasRenderingContext::ContextTypeCount);
103 ASSERT(!renderingContextFactories()[type]); 121 ASSERT(!renderingContextFactories()[type]);
104 renderingContextFactories()[type] = renderingContextFactory; 122 renderingContextFactories()[type] = renderingContextFactory;
105 } 123 }
106 124
107 DEFINE_TRACE(OffscreenCanvas) 125 DEFINE_TRACE(OffscreenCanvas)
108 { 126 {
109 visitor->trace(m_context); 127 visitor->trace(m_context);
110 visitor->trace(m_canvas);
111 } 128 }
112 129
113 } // namespace blink 130 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698