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

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

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

Powered by Google App Engine
This is Rietveld 408576698