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/dom/CompositorProxy.h" | 5 #include "core/dom/CompositorProxy.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionMessages.h" | 7 #include "bindings/core/v8/ExceptionMessages.h" |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "core/dom/DOMNodeIds.h" | 9 #include "core/dom/DOMNodeIds.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
11 #include "core/dom/ExecutionContext.h" | 11 #include "core/dom/ExecutionContext.h" |
12 #include "core/workers/WorkerClients.h" | |
13 #include "core/workers/WorkerGlobalScope.h" | |
12 #include "platform/ThreadSafeFunctional.h" | 14 #include "platform/ThreadSafeFunctional.h" |
13 #include "platform/graphics/CompositorMutableProperties.h" | 15 #include "platform/graphics/CompositorMutableProperties.h" |
14 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
15 #include "public/platform/WebTraceLocation.h" | 17 #include "public/platform/WebTraceLocation.h" |
16 #include <algorithm> | 18 #include <algorithm> |
17 | 19 |
18 namespace blink { | 20 namespace blink { |
19 | 21 |
20 static const struct { | 22 static const struct { |
21 const char* name; | 23 const char* name; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 { | 107 { |
106 if (!context->isDocument()) { | 108 if (!context->isDocument()) { |
107 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp ositorProxy", "Can only be created from the main context.")); | 109 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp ositorProxy", "Can only be created from the main context.")); |
108 exceptionState.throwIfNeeded(); | 110 exceptionState.throwIfNeeded(); |
109 return nullptr; | 111 return nullptr; |
110 } | 112 } |
111 | 113 |
112 return new CompositorProxy(*element, attributeArray); | 114 return new CompositorProxy(*element, attributeArray); |
113 } | 115 } |
114 | 116 |
115 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t compositor MutableProperties) | 117 CompositorProxy* CompositorProxy::create(ExecutionContext* context, uint64_t ele mentId, uint32_t compositorMutableProperties) |
116 { | 118 { |
117 return new CompositorProxy(elementId, compositorMutableProperties); | 119 WorkerClients* clients = toWorkerGlobalScope(context)->clients(); |
jbroman
2016/06/08 14:45:34
Won't this crash if you postMessage a CompositorPr
majidvp
2016/06/09 20:34:21
Fixed. It is not safe and crashes!
Modified one of
| |
120 DCHECK(clients); | |
121 CompositorProxyClient* client = CompositorProxyClient::from(clients); | |
122 return new CompositorProxy(elementId, compositorMutableProperties, client); | |
118 } | 123 } |
119 | 124 |
120 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray) | 125 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray) |
121 : m_elementId(DOMNodeIds::idForNode(&element)) | 126 : m_elementId(DOMNodeIds::idForNode(&element)) |
122 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu teArray)) | 127 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu teArray)) |
128 , m_client(nullptr) | |
123 { | 129 { |
124 DCHECK(isMainThread()); | 130 DCHECK(isMainThread()); |
125 DCHECK(m_compositorMutableProperties); | 131 DCHECK(m_compositorMutableProperties); |
126 #if DCHECK_IS_ON() | 132 #if DCHECK_IS_ON() |
127 DCHECK(sanityCheckMutableProperties(m_compositorMutableProperties)); | 133 DCHECK(sanityCheckMutableProperties(m_compositorMutableProperties)); |
128 #endif | 134 #endif |
129 | 135 |
130 incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMuta bleProperties); | 136 incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMuta bleProperties); |
131 } | 137 } |
132 | 138 |
133 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP roperties) | 139 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP roperties, CompositorProxyClient* client) |
134 : m_elementId(elementId) | 140 : m_elementId(elementId) |
135 , m_compositorMutableProperties(compositorMutableProperties) | 141 , m_compositorMutableProperties(compositorMutableProperties) |
142 , m_client(client) | |
136 { | 143 { |
137 DCHECK(isControlThread()); | 144 DCHECK(isControlThread()); |
138 #if DCHECK_IS_ON() | 145 #if DCHECK_IS_ON() |
139 DCHECK(sanityCheckMutableProperties(m_compositorMutableProperties)); | 146 DCHECK(sanityCheckMutableProperties(m_compositorMutableProperties)); |
140 #endif | 147 #endif |
141 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, threadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId , m_compositorMutableProperties)); | 148 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, threadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId , m_compositorMutableProperties)); |
149 m_client->registerCompositorProxy(this); | |
150 ThreadState::current()->registerPreFinalizer(this); | |
142 } | 151 } |
143 | 152 |
144 CompositorProxy::~CompositorProxy() | 153 CompositorProxy::~CompositorProxy() |
145 { | 154 { |
146 if (m_connected) | 155 if (isMainThread()) |
147 disconnect(); | 156 disconnect(); |
haraken
2016/06/08 00:10:36
You don't need to call disconnect() because discon
majidvp
2016/06/09 20:34:21
Done.
| |
157 DCHECK(!m_connected); | |
158 } | |
159 | |
160 void CompositorProxy::dispose() | |
161 { | |
162 // On compositor worker thread, disconnecting requires unregistering from | |
163 // CompositorProxyClient which needs to be done in pre-finalizer. | |
164 disconnect(); | |
148 } | 165 } |
149 | 166 |
150 bool CompositorProxy::supports(const String& attributeName) const | 167 bool CompositorProxy::supports(const String& attributeName) const |
151 { | 168 { |
152 return m_compositorMutableProperties & compositorMutablePropertyForName(attr ibuteName); | 169 return m_compositorMutableProperties & compositorMutablePropertyForName(attr ibuteName); |
153 } | 170 } |
154 | 171 |
155 double CompositorProxy::opacity(ExceptionState& exceptionState) const | 172 double CompositorProxy::opacity(ExceptionState& exceptionState) const |
156 { | 173 { |
157 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 174 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 { | 249 { |
233 if (m_connected && (m_compositorMutableProperties & property)) | 250 if (m_connected && (m_compositorMutableProperties & property)) |
234 return false; | 251 return false; |
235 exceptionState.throwDOMException(NoModificationAllowedError, | 252 exceptionState.throwDOMException(NoModificationAllowedError, |
236 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted to mutate attribute on a disconnected proxy."); | 253 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted to mutate attribute on a disconnected proxy."); |
237 return true; | 254 return true; |
238 } | 255 } |
239 | 256 |
240 void CompositorProxy::disconnect() | 257 void CompositorProxy::disconnect() |
241 { | 258 { |
259 if (!m_connected) | |
260 return; | |
242 m_connected = false; | 261 m_connected = false; |
243 if (isMainThread()) | 262 if (isMainThread()) { |
244 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties); | 263 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties); |
245 else | 264 } else { |
246 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR OM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_eleme ntId, m_compositorMutableProperties)); | 265 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR OM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_eleme ntId, m_compositorMutableProperties)); |
266 if (m_client) | |
267 m_client->unregisterCompositorProxy(this); | |
268 } | |
247 } | 269 } |
248 | 270 |
249 } // namespace blink | 271 } // namespace blink |
OLD | NEW |