| 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/CompositorProxyClient.h" |
| 9 #include "core/dom/DOMNodeIds.h" | 10 #include "core/dom/DOMNodeIds.h" |
| 10 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 11 #include "core/dom/ExecutionContext.h" | 12 #include "core/dom/ExecutionContext.h" |
| 13 #include "core/workers/WorkerClients.h" |
| 14 #include "core/workers/WorkerGlobalScope.h" |
| 12 #include "platform/ThreadSafeFunctional.h" | 15 #include "platform/ThreadSafeFunctional.h" |
| 13 #include "platform/graphics/CompositorMutableProperties.h" | 16 #include "platform/graphics/CompositorMutableProperties.h" |
| 17 #include "platform/graphics/CompositorMutableState.h" |
| 14 #include "public/platform/Platform.h" | 18 #include "public/platform/Platform.h" |
| 15 #include "public/platform/WebTraceLocation.h" | 19 #include "public/platform/WebTraceLocation.h" |
| 16 #include <algorithm> | 20 #include <algorithm> |
| 17 | 21 |
| 18 namespace blink { | 22 namespace blink { |
| 19 | 23 |
| 24 // When adding to this list, make sure to update |
| 25 // LayoutTests/virtual/threaded/fast/compositorworker/compositor-proxy-supports.
html. |
| 26 |
| 20 static const struct { | 27 static const struct { |
| 21 const char* name; | 28 const char* name; |
| 22 uint32_t property; | 29 uint32_t property; |
| 23 } allowedProperties[] = { | 30 } allowedProperties[] = { |
| 24 { "opacity", CompositorMutableProperty::kOpacity }, | 31 { "opacity", CompositorMutableProperty::kOpacity }, |
| 25 { "scrollleft", CompositorMutableProperty::kScrollLeft }, | 32 { "scrollleft", CompositorMutableProperty::kScrollLeft }, |
| 26 { "scrolltop", CompositorMutableProperty::kScrollTop }, | 33 { "scrolltop", CompositorMutableProperty::kScrollTop }, |
| 27 { "transform", CompositorMutableProperty::kTransform }, | 34 { "transform", CompositorMutableProperty::kTransform }, |
| 28 }; | 35 }; |
| 29 | 36 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 { | 112 { |
| 106 if (!context->isDocument()) { | 113 if (!context->isDocument()) { |
| 107 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp
ositorProxy", "Can only be created from the main context.")); | 114 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp
ositorProxy", "Can only be created from the main context.")); |
| 108 exceptionState.throwIfNeeded(); | 115 exceptionState.throwIfNeeded(); |
| 109 return nullptr; | 116 return nullptr; |
| 110 } | 117 } |
| 111 | 118 |
| 112 return new CompositorProxy(*element, attributeArray); | 119 return new CompositorProxy(*element, attributeArray); |
| 113 } | 120 } |
| 114 | 121 |
| 115 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t compositor
MutableProperties) | 122 CompositorProxy* CompositorProxy::create(ExecutionContext* context, uint64_t ele
mentId, uint32_t compositorMutableProperties) |
| 116 { | 123 { |
| 117 return new CompositorProxy(elementId, compositorMutableProperties); | 124 WorkerClients* clients = toWorkerGlobalScope(context)->clients(); |
| 125 ASSERT(clients); |
| 126 CompositorProxyClient* client = CompositorProxyClient::from(clients); |
| 127 return new CompositorProxy(elementId, compositorMutableProperties, client); |
| 118 } | 128 } |
| 119 | 129 |
| 120 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu
teArray) | 130 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu
teArray) |
| 121 : m_elementId(DOMNodeIds::idForNode(&element)) | 131 : m_elementId(DOMNodeIds::idForNode(&element)) |
| 122 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu
teArray)) | 132 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu
teArray)) |
| 133 , m_client(nullptr) |
| 123 { | 134 { |
| 124 ASSERT(isMainThread()); | 135 ASSERT(isMainThread()); |
| 125 ASSERT(m_compositorMutableProperties); | 136 ASSERT(m_compositorMutableProperties); |
| 126 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); | 137 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); |
| 127 | 138 |
| 128 incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMuta
bleProperties); | 139 incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMuta
bleProperties); |
| 129 } | 140 } |
| 130 | 141 |
| 131 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP
roperties) | 142 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP
roperties, CompositorProxyClient* client) |
| 132 : m_elementId(elementId) | 143 : m_elementId(elementId) |
| 133 , m_compositorMutableProperties(compositorMutableProperties) | 144 , m_compositorMutableProperties(compositorMutableProperties) |
| 145 , m_client(client) |
| 134 { | 146 { |
| 135 ASSERT(isControlThread()); | 147 ASSERT(isControlThread()); |
| 136 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); | 148 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); |
| 137 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, t
hreadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId, m_co
mpositorMutableProperties)); | 149 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, t
hreadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId, m_co
mpositorMutableProperties)); |
| 150 m_client->registerCompositorProxy(this); |
| 138 } | 151 } |
| 139 | 152 |
| 140 CompositorProxy::~CompositorProxy() | 153 CompositorProxy::~CompositorProxy() |
| 141 { | 154 { |
| 142 if (m_connected) | 155 if (m_connected) |
| 143 disconnect(); | 156 disconnect(); |
| 144 } | 157 } |
| 145 | 158 |
| 146 bool CompositorProxy::supports(const String& attributeName) const | 159 bool CompositorProxy::supports(const String& attributeName) const |
| 147 { | 160 { |
| 148 return m_compositorMutableProperties & compositorMutablePropertyForName(attr
ibuteName); | 161 return m_compositorMutableProperties & compositorMutablePropertyForName(attr
ibuteName); |
| 149 } | 162 } |
| 150 | 163 |
| 151 double CompositorProxy::opacity(ExceptionState& exceptionState) const | 164 double CompositorProxy::opacity(ExceptionState& exceptionState) const |
| 152 { | 165 { |
| 153 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 166 double value = 0.0; |
| 154 return 0.0; | 167 if (!raiseExceptionIfMutationNotAllowed(exceptionState) |
| 155 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kOpacity, exceptio
nState)) | 168 && !raiseExceptionIfNotMutable(CompositorMutableProperty::kOpacity, exce
ptionState) |
| 156 return 0.0; | 169 && m_state.get()) { |
| 157 return m_opacity; | 170 value = m_state->opacity(); |
| 171 } |
| 172 return value; |
| 158 } | 173 } |
| 159 | 174 |
| 160 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const | 175 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const |
| 161 { | 176 { |
| 162 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 177 double value = 0.0; |
| 163 return 0.0; | 178 if (!raiseExceptionIfMutationNotAllowed(exceptionState) |
| 164 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollLeft, excep
tionState)) | 179 && !raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollLeft, e
xceptionState) |
| 165 return 0.0; | 180 && m_state.get()) { |
| 166 return m_scrollLeft; | 181 value = m_state->scrollLeft(); |
| 182 } |
| 183 return value; |
| 167 } | 184 } |
| 168 | 185 |
| 169 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const | 186 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const |
| 170 { | 187 { |
| 171 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 188 double value = 0.0; |
| 172 return 0.0; | 189 if (!raiseExceptionIfMutationNotAllowed(exceptionState) |
| 173 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollTop, except
ionState)) | 190 && !raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollTop, ex
ceptionState) |
| 174 return 0.0; | 191 && m_state.get()) { |
| 175 return m_scrollTop; | 192 value = m_state->scrollTop(); |
| 193 } |
| 194 return value; |
| 176 } | 195 } |
| 177 | 196 |
| 178 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const | 197 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const |
| 179 { | 198 { |
| 180 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 199 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| 181 return nullptr; | 200 return nullptr; |
| 182 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kTransform, except
ionState)) | 201 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kTransform, except
ionState)) |
| 183 return nullptr; | 202 return nullptr; |
| 184 return m_transform; | 203 if (!m_state.get()) |
| 204 return DOMMatrix::create(); |
| 205 return DOMMatrix::create(m_state->transform()); |
| 185 } | 206 } |
| 186 | 207 |
| 187 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) | 208 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) |
| 188 { | 209 { |
| 189 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 210 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| 190 return; | 211 return; |
| 191 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kOpacity, exceptio
nState)) | 212 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kOpacity, exceptio
nState)) |
| 192 return; | 213 return; |
| 193 m_opacity = std::min(1., std::max(0., opacity)); | 214 if (!m_state.get()) |
| 194 m_mutatedProperties |= CompositorMutableProperty::kTransform; | 215 return; |
| 216 opacity = std::min(1., std::max(0., opacity)); |
| 217 m_state->setOpacity(opacity); |
| 195 } | 218 } |
| 196 | 219 |
| 197 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception
State) | 220 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception
State) |
| 198 { | 221 { |
| 199 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 222 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| 200 return; | 223 return; |
| 201 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollLeft, excep
tionState)) | 224 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollLeft, excep
tionState)) |
| 202 return; | 225 return; |
| 203 m_scrollLeft = scrollLeft; | 226 if (!m_state.get()) |
| 204 m_mutatedProperties |= CompositorMutableProperty::kScrollLeft; | 227 return; |
| 228 m_state->setScrollLeft(scrollLeft); |
| 205 } | 229 } |
| 206 | 230 |
| 207 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt
ate) | 231 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt
ate) |
| 208 { | 232 { |
| 209 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 233 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| 210 return; | 234 return; |
| 211 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollTop, except
ionState)) | 235 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollTop, except
ionState)) |
| 212 return; | 236 return; |
| 213 m_scrollTop = scrollTop; | 237 if (!m_state.get()) |
| 214 m_mutatedProperties |= CompositorMutableProperty::kScrollTop; | 238 return; |
| 239 m_state->setScrollTop(scrollTop); |
| 215 } | 240 } |
| 216 | 241 |
| 217 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti
onState) | 242 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti
onState) |
| 218 { | 243 { |
| 219 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 244 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
| 220 return; | 245 return; |
| 221 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kTransform, except
ionState)) | 246 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kTransform, except
ionState)) |
| 222 return; | 247 return; |
| 223 m_transform = transform; | 248 if (!m_state.get()) |
| 224 m_mutatedProperties |= CompositorMutableProperty::kTransform; | 249 return; |
| 250 m_state->setTransform(TransformationMatrix::toSkMatrix44(transform->matrix()
)); |
| 225 } | 251 } |
| 226 | 252 |
| 227 bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta
te& exceptionState) const | 253 bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta
te& exceptionState) const |
| 228 { | 254 { |
| 229 if (m_connected && (m_compositorMutableProperties & property)) | 255 if (m_connected && (m_compositorMutableProperties & property)) |
| 230 return false; | 256 return false; |
| 231 exceptionState.throwDOMException(NoModificationAllowedError, | 257 exceptionState.throwDOMException(NoModificationAllowedError, |
| 232 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted
to mutate attribute on a disconnected proxy."); | 258 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted
to mutate attribute on a disconnected proxy."); |
| 233 return true; | 259 return true; |
| 234 } | 260 } |
| 235 | 261 |
| 236 void CompositorProxy::disconnect() | 262 void CompositorProxy::disconnect() |
| 237 { | 263 { |
| 264 if (!m_connected) |
| 265 return; |
| 238 m_connected = false; | 266 m_connected = false; |
| 239 if (isMainThread()) | 267 if (isMainThread()) { |
| 240 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor
MutableProperties); | 268 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor
MutableProperties); |
| 241 else | 269 } else { |
| 242 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HER
E, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_elementId,
m_compositorMutableProperties)); | 270 Platform::current()->mainThread()->taskRunner()->postTask( |
| 271 BLINK_FROM_HERE, threadSafeBind(&decrementCompositorProxiedPropertie
sForElement, m_elementId, m_compositorMutableProperties)); |
| 272 if (m_client) |
| 273 m_client->unregisterCompositorProxy(this); |
| 274 } |
| 275 } |
| 276 |
| 277 void CompositorProxy::takeCompositorMutableState(PassOwnPtr<CompositorMutableSta
te> state) |
| 278 { |
| 279 m_state = state; |
| 243 } | 280 } |
| 244 | 281 |
| 245 } // namespace blink | 282 } // namespace blink |
| OLD | NEW |