| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/dom/CompositorProxy.h" | 6 #include "core/dom/CompositorProxy.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionMessages.h" | 8 #include "bindings/core/v8/ExceptionMessages.h" |
| 9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 | 25 |
| 26 static uint64_t compositorProxyIdForElement(Element* element) | 26 static uint64_t compositorProxyIdForElement(Element* element) |
| 27 { | 27 { |
| 28 ASSERT(gElementIdMap); | 28 ASSERT(gElementIdMap); |
| 29 if (!gElementIdMap->contains(element)) | 29 if (!gElementIdMap->contains(element)) |
| 30 gElementIdMap->add(element, nextCompositorProxyId()); | 30 gElementIdMap->add(element, nextCompositorProxyId()); |
| 31 return gElementIdMap->get(element); | 31 return gElementIdMap->get(element); |
| 32 } | 32 } |
| 33 | 33 |
| 34 static bool isControlThread() |
| 35 { |
| 36 return !isMainThread(); |
| 37 } |
| 38 |
| 39 static bool isCallingCompositorFrameCallback() |
| 40 { |
| 41 // TODO(sad): |
| 42 return true; |
| 43 } |
| 44 |
| 45 static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState) |
| 46 { |
| 47 if (!isControlThread()) { |
| 48 exceptionState.throwTypeError("Cannot mutate a proxy attribute from the
main page."); |
| 49 return true; |
| 50 } |
| 51 if (!isCallingCompositorFrameCallback()) { |
| 52 exceptionState.throwTypeError("Cannot mutate a proxy attribute outside o
f a requestCompositorFrame callback."); |
| 53 return true; |
| 54 } |
| 55 return false; |
| 56 } |
| 57 |
| 34 static struct { | 58 static struct { |
| 35 const char* name; | 59 const char* name; |
| 36 CompositorProxy::Attributes attribute; | 60 CompositorProxy::Attributes attribute; |
| 37 } allowedAttributes[] = { | 61 } allowedAttributes[] = { |
| 38 { "opacity", CompositorProxy::Attributes::OPACITY }, | 62 { "opacity", CompositorProxy::Attributes::OPACITY }, |
| 39 { "scrolltop", CompositorProxy::Attributes::SCROLL_TOP }, | 63 { "scrolltop", CompositorProxy::Attributes::SCROLL_TOP }, |
| 40 { "touch", CompositorProxy::Attributes::TOUCH }, | 64 { "touch", CompositorProxy::Attributes::TOUCH }, |
| 41 { "transform", CompositorProxy::Attributes::TRANSFORM }, | 65 { "transform", CompositorProxy::Attributes::TRANSFORM }, |
| 42 }; | 66 }; |
| 43 | 67 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 71 gElementMap = new ElementMap; | 95 gElementMap = new ElementMap; |
| 72 gElementIdMap = new ElementIdMap; | 96 gElementIdMap = new ElementIdMap; |
| 73 } else { | 97 } else { |
| 74 ASSERT(gElementIdMap); | 98 ASSERT(gElementIdMap); |
| 75 } | 99 } |
| 76 return new CompositorProxy(element, attributeFlags); | 100 return new CompositorProxy(element, attributeFlags); |
| 77 } | 101 } |
| 78 | 102 |
| 79 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeF
lags) | 103 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeF
lags) |
| 80 { | 104 { |
| 81 ASSERT(!isMainThread()); | 105 ASSERT(isControlThread()); |
| 82 #ifndef NDEBUG | 106 #ifndef NDEBUG |
| 83 uint32_t sanityCheckAttributes = attributeFlags; | 107 uint32_t sanityCheckAttributes = attributeFlags; |
| 84 for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) { | 108 for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) { |
| 85 sanityCheckAttributes &= ~static_cast<uint32_t>(allowedAttributes[i].att
ribute); | 109 sanityCheckAttributes &= ~static_cast<uint32_t>(allowedAttributes[i].att
ribute); |
| 86 } | 110 } |
| 87 ASSERT(!sanityCheckAttributes); | 111 ASSERT(!sanityCheckAttributes); |
| 88 #endif | 112 #endif |
| 89 return new CompositorProxy(elementId, attributeFlags); | 113 return new CompositorProxy(elementId, attributeFlags); |
| 90 } | 114 } |
| 91 | 115 |
| 92 CompositorProxy::CompositorProxy(Element* element, uint32_t attributeFlags) | 116 CompositorProxy::CompositorProxy(Element* element, uint32_t attributeFlags) |
| 93 : m_elementId(compositorProxyIdForElement(element)) | 117 : m_elementId(compositorProxyIdForElement(element)) |
| 94 , m_attributes(attributeFlags) | 118 , m_mutableAttributes(attributeFlags) |
| 119 , m_mutatedAttributes(0) |
| 95 { | 120 { |
| 96 ASSERT(isMainThread()); | 121 ASSERT(isMainThread()); |
| 97 ASSERT(gElementMap); | 122 ASSERT(gElementMap); |
| 98 gElementMap->add(m_elementId, element); | 123 gElementMap->add(m_elementId, element); |
| 99 } | 124 } |
| 100 | 125 |
| 101 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags) | 126 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags) |
| 102 : m_elementId(elementId) | 127 : m_elementId(elementId) |
| 103 , m_attributes(attributeFlags) | 128 , m_mutableAttributes(attributeFlags) |
| 129 , m_mutatedAttributes(0) |
| 104 { | 130 { |
| 105 } | 131 } |
| 106 | 132 |
| 107 CompositorProxy::~CompositorProxy() | 133 CompositorProxy::~CompositorProxy() |
| 108 { | 134 { |
| 109 } | 135 } |
| 110 | 136 |
| 111 void CompositorProxy::notifyElementGone(Element* element) | 137 void CompositorProxy::notifyElementGone(Element* element) |
| 112 { | 138 { |
| 113 ASSERT(isMainThread()); | 139 ASSERT(isMainThread()); |
| 114 if (!gElementMap) | 140 if (!gElementMap) |
| 115 return; | 141 return; |
| 116 | 142 |
| 117 gElementMap->remove(gElementIdMap->take(element)); | 143 gElementMap->remove(gElementIdMap->take(element)); |
| 118 } | 144 } |
| 119 | 145 |
| 146 double CompositorProxy::opacity(ExceptionState& exceptionState) const |
| 147 { |
| 148 if (UNLIKELY(raiseExceptionIfMutationNotAllowed(exceptionState))) |
| 149 return 0.0; |
| 150 return m_opacity; |
| 151 } |
| 152 |
| 153 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const |
| 154 { |
| 155 if (UNLIKELY(raiseExceptionIfMutationNotAllowed(exceptionState))) |
| 156 return 0.0; |
| 157 return m_scrollTop; |
| 158 } |
| 159 |
| 160 Vector<double> CompositorProxy::transform(ExceptionState& exceptionState) const |
| 161 { |
| 162 if (UNLIKELY(raiseExceptionIfMutationNotAllowed(exceptionState))) |
| 163 return Vector<double>(); |
| 164 return Vector<double>(m_transform); |
| 165 } |
| 166 |
| 167 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) |
| 168 { |
| 169 if (UNLIKELY(raiseExceptionIfMutationNotAllowed(exceptionState))) |
| 170 return; |
| 171 if (UNLIKELY(raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState)
)) |
| 172 return; |
| 173 m_opacity = opacity; |
| 174 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::OPACITY); |
| 175 } |
| 176 |
| 177 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt
ate) |
| 178 { |
| 179 if (UNLIKELY(raiseExceptionIfMutationNotAllowed(exceptionState))) |
| 180 return; |
| 181 if (UNLIKELY(raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionSta
te))) |
| 182 return; |
| 183 m_scrollTop = scrollTop; |
| 184 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_TOP); |
| 185 } |
| 186 |
| 187 void CompositorProxy::setTransform(const Vector<double>& transform, ExceptionSta
te& exceptionState) |
| 188 { |
| 189 if (UNLIKELY(raiseExceptionIfMutationNotAllowed(exceptionState))) |
| 190 return; |
| 191 if (UNLIKELY(raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionStat
e))) |
| 192 return; |
| 193 if (UNLIKELY(transform.size() != m_transform.size())) { |
| 194 exceptionState.throwTypeError("Incorrect size of the transform array."); |
| 195 return; |
| 196 } |
| 197 m_transform = transform; |
| 198 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::TRANSFORM); |
| 199 } |
| 200 |
| 201 bool CompositorProxy::raiseExceptionIfNotMutable(Attributes attribute, Exception
State& exceptionState) const |
| 202 { |
| 203 if (m_mutableAttributes & static_cast<uint32_t>(attribute)) |
| 204 return false; |
| 205 exceptionState.throwTypeError("Attempted to mutate non-mutable attribute."); |
| 206 return true; |
| 207 } |
| 208 |
| 120 } // namespace blink | 209 } // namespace blink |
| OLD | NEW |