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 "platform/ThreadSafeFunctional.h" | 12 #include "platform/ThreadSafeFunctional.h" |
| 13 #include "platform/graphics/CompositorMutableProperties.h" |
13 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
14 #include "public/platform/WebCompositorMutableProperties.h" | |
15 #include "public/platform/WebTraceLocation.h" | 15 #include "public/platform/WebTraceLocation.h" |
16 #include <algorithm> | 16 #include <algorithm> |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 static const struct { | 20 static const struct { |
21 const char* name; | 21 const char* name; |
22 WebCompositorMutableProperty property; | 22 uint32_t property; |
23 } allowedProperties[] = { | 23 } allowedProperties[] = { |
24 { "opacity", WebCompositorMutablePropertyOpacity }, | 24 { "opacity", CompositorMutableProperty::kOpacity }, |
25 { "scrollleft", WebCompositorMutablePropertyScrollLeft }, | 25 { "scrollleft", CompositorMutableProperty::kScrollLeft }, |
26 { "scrolltop", WebCompositorMutablePropertyScrollTop }, | 26 { "scrolltop", CompositorMutableProperty::kScrollTop }, |
27 { "transform", WebCompositorMutablePropertyTransform }, | 27 { "transform", CompositorMutableProperty::kTransform }, |
28 }; | 28 }; |
29 | 29 |
30 static WebCompositorMutableProperty compositorMutablePropertyForName(const Strin
g& attributeName) | 30 static uint32_t compositorMutablePropertyForName(const String& attributeName) |
31 { | 31 { |
32 for (const auto& mapping : allowedProperties) { | 32 for (const auto& mapping : allowedProperties) { |
33 if (equalIgnoringCase(mapping.name, attributeName)) | 33 if (equalIgnoringCase(mapping.name, attributeName)) |
34 return mapping.property; | 34 return mapping.property; |
35 } | 35 } |
36 return WebCompositorMutablePropertyNone; | 36 return CompositorMutableProperty::kNone; |
37 } | 37 } |
38 | 38 |
39 static bool isControlThread() | 39 static bool isControlThread() |
40 { | 40 { |
41 return !isMainThread(); | 41 return !isMainThread(); |
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. |
(...skipping 30 matching lines...) Expand all Loading... |
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 |= static_cast<uint32_t>(compositorMutablePropertyForName(att
ribute)); | 87 properties |= compositorMutablePropertyForName(attribute); |
88 } | 88 } |
89 return properties; | 89 return properties; |
90 } | 90 } |
91 | 91 |
92 #if ENABLE(ASSERT) | 92 #if ENABLE(ASSERT) |
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) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 138 } |
139 | 139 |
140 CompositorProxy::~CompositorProxy() | 140 CompositorProxy::~CompositorProxy() |
141 { | 141 { |
142 if (m_connected) | 142 if (m_connected) |
143 disconnect(); | 143 disconnect(); |
144 } | 144 } |
145 | 145 |
146 bool CompositorProxy::supports(const String& attributeName) const | 146 bool CompositorProxy::supports(const String& attributeName) const |
147 { | 147 { |
148 return !!(m_compositorMutableProperties & static_cast<uint32_t>(compositorMu
tablePropertyForName(attributeName))); | 148 return m_compositorMutableProperties & compositorMutablePropertyForName(attr
ibuteName); |
149 } | 149 } |
150 | 150 |
151 double CompositorProxy::opacity(ExceptionState& exceptionState) const | 151 double CompositorProxy::opacity(ExceptionState& exceptionState) const |
152 { | 152 { |
153 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 153 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
154 return 0.0; | 154 return 0.0; |
155 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro
pertyOpacity), exceptionState)) | 155 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kOpacity, exceptio
nState)) |
156 return 0.0; | 156 return 0.0; |
157 return m_opacity; | 157 return m_opacity; |
158 } | 158 } |
159 | 159 |
160 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const | 160 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const |
161 { | 161 { |
162 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 162 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
163 return 0.0; | 163 return 0.0; |
164 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro
pertyScrollLeft), exceptionState)) | 164 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollLeft, excep
tionState)) |
165 return 0.0; | 165 return 0.0; |
166 return m_scrollLeft; | 166 return m_scrollLeft; |
167 } | 167 } |
168 | 168 |
169 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const | 169 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const |
170 { | 170 { |
171 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 171 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
172 return 0.0; | 172 return 0.0; |
173 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro
pertyScrollTop), exceptionState)) | 173 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollTop, except
ionState)) |
174 return 0.0; | 174 return 0.0; |
175 return m_scrollTop; | 175 return m_scrollTop; |
176 } | 176 } |
177 | 177 |
178 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const | 178 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const |
179 { | 179 { |
180 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 180 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
181 return nullptr; | 181 return nullptr; |
182 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro
pertyTransform), exceptionState)) | 182 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kTransform, except
ionState)) |
183 return nullptr; | 183 return nullptr; |
184 return m_transform; | 184 return m_transform; |
185 } | 185 } |
186 | 186 |
187 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) | 187 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) |
188 { | 188 { |
189 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 189 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
190 return; | 190 return; |
191 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro
pertyOpacity), exceptionState)) | 191 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kOpacity, exceptio
nState)) |
192 return; | 192 return; |
193 m_opacity = std::min(1., std::max(0., opacity)); | 193 m_opacity = std::min(1., std::max(0., opacity)); |
194 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTra
nsform); | 194 m_mutatedProperties |= CompositorMutableProperty::kTransform; |
195 } | 195 } |
196 | 196 |
197 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception
State) | 197 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception
State) |
198 { | 198 { |
199 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 199 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
200 return; | 200 return; |
201 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro
pertyScrollLeft), exceptionState)) | 201 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollLeft, excep
tionState)) |
202 return; | 202 return; |
203 m_scrollLeft = scrollLeft; | 203 m_scrollLeft = scrollLeft; |
204 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScr
ollLeft); | 204 m_mutatedProperties |= CompositorMutableProperty::kScrollLeft; |
205 } | 205 } |
206 | 206 |
207 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt
ate) | 207 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt
ate) |
208 { | 208 { |
209 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 209 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
210 return; | 210 return; |
211 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro
pertyScrollTop), exceptionState)) | 211 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollTop, except
ionState)) |
212 return; | 212 return; |
213 m_scrollTop = scrollTop; | 213 m_scrollTop = scrollTop; |
214 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScr
ollTop); | 214 m_mutatedProperties |= CompositorMutableProperty::kScrollTop; |
215 } | 215 } |
216 | 216 |
217 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti
onState) | 217 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti
onState) |
218 { | 218 { |
219 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 219 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
220 return; | 220 return; |
221 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro
pertyTransform), exceptionState)) | 221 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kTransform, except
ionState)) |
222 return; | 222 return; |
223 m_transform = transform; | 223 m_transform = transform; |
224 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTra
nsform); | 224 m_mutatedProperties |= CompositorMutableProperty::kTransform; |
225 } | 225 } |
226 | 226 |
227 bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta
te& exceptionState) const | 227 bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta
te& exceptionState) const |
228 { | 228 { |
229 if (m_connected && (m_compositorMutableProperties & property)) | 229 if (m_connected && (m_compositorMutableProperties & property)) |
230 return false; | 230 return false; |
231 exceptionState.throwDOMException(NoModificationAllowedError, | 231 exceptionState.throwDOMException(NoModificationAllowedError, |
232 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted
to mutate attribute on a disconnected proxy."); | 232 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted
to mutate attribute on a disconnected proxy."); |
233 return true; | 233 return true; |
234 } | 234 } |
235 | 235 |
236 void CompositorProxy::disconnect() | 236 void CompositorProxy::disconnect() |
237 { | 237 { |
238 m_connected = false; | 238 m_connected = false; |
239 if (isMainThread()) | 239 if (isMainThread()) |
240 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor
MutableProperties); | 240 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor
MutableProperties); |
241 else | 241 else |
242 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HER
E, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_elementId,
m_compositorMutableProperties)); | 242 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HER
E, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_elementId,
m_compositorMutableProperties)); |
243 } | 243 } |
244 | 244 |
245 } // namespace blink | 245 } // namespace blink |
OLD | NEW |