| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 | 43 |
| 44 static bool isCallingCompositorFrameCallback() | 44 static bool isCallingCompositorFrameCallback() |
| 45 { | 45 { |
| 46 // TODO(sad): Check that the requestCompositorFrame callbacks are currently
being called. | 46 // TODO(sad): Check that the requestCompositorFrame callbacks are currently
being called. |
| 47 return true; | 47 return true; |
| 48 } | 48 } |
| 49 | 49 |
| 50 static void decrementCompositorProxiedPropertiesForElement(uint64_t elementId, u
int32_t compositorMutableProperties) | 50 static void decrementCompositorProxiedPropertiesForElement(uint64_t elementId, u
int32_t compositorMutableProperties) |
| 51 { | 51 { |
| 52 ASSERT(isMainThread()); | 52 DCHECK(isMainThread()); |
| 53 Node* node = DOMNodeIds::nodeForId(elementId); | 53 Node* node = DOMNodeIds::nodeForId(elementId); |
| 54 if (!node) | 54 if (!node) |
| 55 return; | 55 return; |
| 56 Element* element = toElement(node); | 56 Element* element = toElement(node); |
| 57 element->decrementCompositorProxiedProperties(compositorMutableProperties); | 57 element->decrementCompositorProxiedProperties(compositorMutableProperties); |
| 58 } | 58 } |
| 59 | 59 |
| 60 static void incrementCompositorProxiedPropertiesForElement(uint64_t elementId, u
int32_t compositorMutableProperties) | 60 static void incrementCompositorProxiedPropertiesForElement(uint64_t elementId, u
int32_t compositorMutableProperties) |
| 61 { | 61 { |
| 62 ASSERT(isMainThread()); | 62 DCHECK(isMainThread()); |
| 63 Node* node = DOMNodeIds::nodeForId(elementId); | 63 Node* node = DOMNodeIds::nodeForId(elementId); |
| 64 if (!node) | 64 if (!node) |
| 65 return; | 65 return; |
| 66 Element* element = toElement(node); | 66 Element* element = toElement(node); |
| 67 element->incrementCompositorProxiedProperties(compositorMutableProperties); | 67 element->incrementCompositorProxiedProperties(compositorMutableProperties); |
| 68 } | 68 } |
| 69 | 69 |
| 70 static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState) | 70 static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState) |
| 71 { | 71 { |
| 72 if (!isControlThread()) { | 72 if (!isControlThread()) { |
| 73 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut
ate a proxy attribute from the main page."); | 73 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut
ate a proxy attribute from the main page."); |
| 74 return true; | 74 return true; |
| 75 } | 75 } |
| 76 if (!isCallingCompositorFrameCallback()) { | 76 if (!isCallingCompositorFrameCallback()) { |
| 77 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut
ate a proxy attribute outside of a requestCompositorFrame callback."); | 77 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut
ate a proxy attribute outside of a requestCompositorFrame callback."); |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 return false; | 80 return false; |
| 81 } | 81 } |
| 82 | 82 |
| 83 static uint32_t compositorMutablePropertiesFromNames(const Vector<String>& attri
buteArray) | 83 static uint32_t compositorMutablePropertiesFromNames(const Vector<String>& attri
buteArray) |
| 84 { | 84 { |
| 85 uint32_t properties = 0; | 85 uint32_t properties = 0; |
| 86 for (const auto& attribute : attributeArray) { | 86 for (const auto& attribute : attributeArray) { |
| 87 properties |= compositorMutablePropertyForName(attribute); | 87 properties |= compositorMutablePropertyForName(attribute); |
| 88 } | 88 } |
| 89 return properties; | 89 return properties; |
| 90 } | 90 } |
| 91 | 91 |
| 92 #if ENABLE(ASSERT) | 92 #if DCHECK_IS_ON() |
| 93 static bool sanityCheckMutableProperties(uint32_t properties) | 93 static bool sanityCheckMutableProperties(uint32_t properties) |
| 94 { | 94 { |
| 95 // Ensures that we only have bits set for valid mutable properties. | 95 // Ensures that we only have bits set for valid mutable properties. |
| 96 uint32_t sanityCheckProperties = properties; | 96 uint32_t sanityCheckProperties = properties; |
| 97 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(allowedProperties); ++i) { | 97 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(allowedProperties); ++i) { |
| 98 sanityCheckProperties &= ~static_cast<uint32_t>(allowedProperties[i].pro
perty); | 98 sanityCheckProperties &= ~static_cast<uint32_t>(allowedProperties[i].pro
perty); |
| 99 } | 99 } |
| 100 return !sanityCheckProperties; | 100 return !sanityCheckProperties; |
| 101 } | 101 } |
| 102 #endif | 102 #endif |
| (...skipping 11 matching lines...) Expand all Loading... |
| 114 | 114 |
| 115 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t compositor
MutableProperties) | 115 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t compositor
MutableProperties) |
| 116 { | 116 { |
| 117 return new CompositorProxy(elementId, compositorMutableProperties); | 117 return new CompositorProxy(elementId, compositorMutableProperties); |
| 118 } | 118 } |
| 119 | 119 |
| 120 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu
teArray) | 120 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu
teArray) |
| 121 : m_elementId(DOMNodeIds::idForNode(&element)) | 121 : m_elementId(DOMNodeIds::idForNode(&element)) |
| 122 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu
teArray)) | 122 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu
teArray)) |
| 123 { | 123 { |
| 124 ASSERT(isMainThread()); | 124 DCHECK(isMainThread()); |
| 125 ASSERT(m_compositorMutableProperties); | 125 DCHECK(m_compositorMutableProperties); |
| 126 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); | 126 #if DCHECK_IS_ON() |
| 127 DCHECK(sanityCheckMutableProperties(m_compositorMutableProperties)); |
| 128 #endif |
| 127 | 129 |
| 128 incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMuta
bleProperties); | 130 incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMuta
bleProperties); |
| 129 } | 131 } |
| 130 | 132 |
| 131 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP
roperties) | 133 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP
roperties) |
| 132 : m_elementId(elementId) | 134 : m_elementId(elementId) |
| 133 , m_compositorMutableProperties(compositorMutableProperties) | 135 , m_compositorMutableProperties(compositorMutableProperties) |
| 134 { | 136 { |
| 135 ASSERT(isControlThread()); | 137 DCHECK(isControlThread()); |
| 136 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); | 138 #if DCHECK_IS_ON() |
| 139 DCHECK(sanityCheckMutableProperties(m_compositorMutableProperties)); |
| 140 #endif |
| 137 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, threadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId
, m_compositorMutableProperties)); | 141 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, threadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId
, m_compositorMutableProperties)); |
| 138 } | 142 } |
| 139 | 143 |
| 140 CompositorProxy::~CompositorProxy() | 144 CompositorProxy::~CompositorProxy() |
| 141 { | 145 { |
| 142 if (m_connected) | 146 if (m_connected) |
| 143 disconnect(); | 147 disconnect(); |
| 144 } | 148 } |
| 145 | 149 |
| 146 bool CompositorProxy::supports(const String& attributeName) const | 150 bool CompositorProxy::supports(const String& attributeName) const |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 void CompositorProxy::disconnect() | 240 void CompositorProxy::disconnect() |
| 237 { | 241 { |
| 238 m_connected = false; | 242 m_connected = false; |
| 239 if (isMainThread()) | 243 if (isMainThread()) |
| 240 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor
MutableProperties); | 244 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor
MutableProperties); |
| 241 else | 245 else |
| 242 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_eleme
ntId, m_compositorMutableProperties)); | 246 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_eleme
ntId, m_compositorMutableProperties)); |
| 243 } | 247 } |
| 244 | 248 |
| 245 } // namespace blink | 249 } // namespace blink |
| OLD | NEW |