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 { |
119 if (context->isCompositorWorkerGlobalScope()) { | |
120 WorkerClients* clients = toWorkerGlobalScope(context)->clients(); | |
121 DCHECK(clients); | |
122 CompositorProxyClient* client = CompositorProxyClient::from(clients); | |
123 return new CompositorProxy(elementId, compositorMutableProperties, clien t); | |
124 } | |
125 | |
117 return new CompositorProxy(elementId, compositorMutableProperties); | 126 return new CompositorProxy(elementId, compositorMutableProperties); |
118 } | 127 } |
119 | 128 |
120 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray) | 129 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP roperties) |
121 : m_elementId(DOMNodeIds::idForNode(&element)) | 130 : m_elementId(elementId) |
122 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu teArray)) | 131 , m_compositorMutableProperties(compositorMutableProperties) |
132 , m_client(nullptr) | |
123 { | 133 { |
124 DCHECK(isMainThread()); | |
125 DCHECK(m_compositorMutableProperties); | 134 DCHECK(m_compositorMutableProperties); |
126 #if DCHECK_IS_ON() | 135 #if DCHECK_IS_ON() |
127 DCHECK(sanityCheckMutableProperties(m_compositorMutableProperties)); | 136 DCHECK(sanityCheckMutableProperties(m_compositorMutableProperties)); |
128 #endif | 137 #endif |
129 | 138 |
130 incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMuta bleProperties); | 139 if (isMainThread()) { |
140 incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties); | |
141 } else { | |
142 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR OM_HERE, threadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_eleme ntId, m_compositorMutableProperties)); | |
143 } | |
131 } | 144 } |
132 | 145 |
133 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP roperties) | 146 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray) |
134 : m_elementId(elementId) | 147 : CompositorProxy(DOMNodeIds::idForNode(&element), compositorMutableProperti esFromNames(attributeArray)) |
135 , m_compositorMutableProperties(compositorMutableProperties) | |
136 { | 148 { |
149 DCHECK(isMainThread()); | |
150 } | |
151 | |
152 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP roperties, CompositorProxyClient* client) | |
153 : CompositorProxy(elementId, compositorMutableProperties) | |
154 { | |
155 m_client = client; | |
156 DCHECK(m_client); | |
137 DCHECK(isControlThread()); | 157 DCHECK(isControlThread()); |
138 #if DCHECK_IS_ON() | 158 m_client->registerCompositorProxy(this); |
139 DCHECK(sanityCheckMutableProperties(m_compositorMutableProperties)); | |
140 #endif | |
141 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, threadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId , m_compositorMutableProperties)); | |
142 } | 159 } |
143 | 160 |
144 CompositorProxy::~CompositorProxy() | 161 CompositorProxy::~CompositorProxy() |
145 { | 162 { |
146 if (m_connected) | 163 disconnectInternal(); |
147 disconnect(); | 164 DCHECK(!m_connected); |
jbroman
2016/06/10 19:29:33
Mind a quick comment here explaining why you don't
majidvp
2016/06/10 20:56:30
Done.
| |
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 disconnectInternal(); | |
260 if (m_client) | |
261 m_client->unregisterCompositorProxy(this); | |
262 } | |
263 | |
264 void CompositorProxy::disconnectInternal() | |
265 { | |
266 if (!m_connected) | |
267 return; | |
242 m_connected = false; | 268 m_connected = false; |
243 if (isMainThread()) | 269 if (isMainThread()) { |
244 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties); | 270 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties); |
245 else | 271 } else { |
246 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR OM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_eleme ntId, m_compositorMutableProperties)); | 272 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR OM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_eleme ntId, m_compositorMutableProperties)); |
273 } | |
247 } | 274 } |
248 | 275 |
249 } // namespace blink | 276 } // namespace blink |
OLD | NEW |