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 // We do not explicitly unregister from client here. The client has a weak |
147 disconnect(); | 164 // reference to us which gets collected on its own. This way we avoid using |
| 165 // a pre-finalizer. |
| 166 disconnectInternal(); |
| 167 DCHECK(!m_connected); |
148 } | 168 } |
149 | 169 |
150 bool CompositorProxy::supports(const String& attributeName) const | 170 bool CompositorProxy::supports(const String& attributeName) const |
151 { | 171 { |
152 return m_compositorMutableProperties & compositorMutablePropertyForName(attr
ibuteName); | 172 return m_compositorMutableProperties & compositorMutablePropertyForName(attr
ibuteName); |
153 } | 173 } |
154 | 174 |
155 double CompositorProxy::opacity(ExceptionState& exceptionState) const | 175 double CompositorProxy::opacity(ExceptionState& exceptionState) const |
156 { | 176 { |
157 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 177 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 { | 252 { |
233 if (m_connected && (m_compositorMutableProperties & property)) | 253 if (m_connected && (m_compositorMutableProperties & property)) |
234 return false; | 254 return false; |
235 exceptionState.throwDOMException(NoModificationAllowedError, | 255 exceptionState.throwDOMException(NoModificationAllowedError, |
236 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted
to mutate attribute on a disconnected proxy."); | 256 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted
to mutate attribute on a disconnected proxy."); |
237 return true; | 257 return true; |
238 } | 258 } |
239 | 259 |
240 void CompositorProxy::disconnect() | 260 void CompositorProxy::disconnect() |
241 { | 261 { |
| 262 disconnectInternal(); |
| 263 if (m_client) |
| 264 m_client->unregisterCompositorProxy(this); |
| 265 } |
| 266 |
| 267 void CompositorProxy::disconnectInternal() |
| 268 { |
| 269 if (!m_connected) |
| 270 return; |
242 m_connected = false; | 271 m_connected = false; |
243 if (isMainThread()) | 272 if (isMainThread()) { |
244 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor
MutableProperties); | 273 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor
MutableProperties); |
245 else | 274 } else { |
246 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_eleme
ntId, m_compositorMutableProperties)); | 275 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_eleme
ntId, m_compositorMutableProperties)); |
| 276 } |
247 } | 277 } |
248 | 278 |
249 } // namespace blink | 279 } // namespace blink |
OLD | NEW |