Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Side by Side Diff: third_party/WebKit/Source/core/dom/CompositorProxy.cpp

Issue 1547893003: WIP - compositor worker mega patch. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
16 #include "platform/TraceEvent.h"
17 #include "platform/graphics/CompositorMutableProperties.h"
18 #include "platform/graphics/CompositorMutableState.h"
13 #include "public/platform/Platform.h" 19 #include "public/platform/Platform.h"
14 #include "public/platform/WebCompositorMutableProperties.h"
15 #include "public/platform/WebTraceLocation.h" 20 #include "public/platform/WebTraceLocation.h"
16 #include <algorithm> 21 #include <algorithm>
17 22
18 namespace blink { 23 namespace blink {
19 24
20 static const struct { 25 static const struct {
21 const char* name; 26 const char* name;
22 WebCompositorMutableProperty property; 27 CompositorMutableProperty property;
23 } allowedProperties[] = { 28 } allowedProperties[] = {
24 { "opacity", WebCompositorMutablePropertyOpacity }, 29 { "opacity", CompositorMutablePropertyOpacity },
25 { "scrollleft", WebCompositorMutablePropertyScrollLeft }, 30 { "scrollleft", CompositorMutablePropertyScrollLeft },
26 { "scrolltop", WebCompositorMutablePropertyScrollTop }, 31 { "scrolltop", CompositorMutablePropertyScrollTop },
27 { "transform", WebCompositorMutablePropertyTransform }, 32 { "transform", CompositorMutablePropertyTransform },
28 }; 33 };
29 34
30 static WebCompositorMutableProperty compositorMutablePropertyForName(const Strin g& attributeName) 35 static CompositorMutableProperty compositorMutablePropertyForName(const String& attributeName)
31 { 36 {
32 for (const auto& mapping : allowedProperties) { 37 for (const auto& mapping : allowedProperties) {
33 if (equalIgnoringCase(mapping.name, attributeName)) 38 if (equalIgnoringCase(mapping.name, attributeName))
34 return mapping.property; 39 return mapping.property;
35 } 40 }
36 return WebCompositorMutablePropertyNone; 41 return CompositorMutablePropertyNone;
37 } 42 }
38 43
39 static bool isControlThread() 44 static bool isControlThread()
40 { 45 {
41 return !isMainThread(); 46 return !isMainThread();
42 } 47 }
43 48
44 static bool isCallingCompositorFrameCallback() 49 static bool isCallingCompositorFrameCallback()
45 { 50 {
46 // TODO(sad): Check that the requestCompositorFrame callbacks are currently being called. 51 // TODO(sad): Check that the requestCompositorFrame callbacks are currently being called.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 { 110 {
106 if (!context->isDocument()) { 111 if (!context->isDocument()) {
107 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp ositorProxy", "Can only be created from the main context.")); 112 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp ositorProxy", "Can only be created from the main context."));
108 exceptionState.throwIfNeeded(); 113 exceptionState.throwIfNeeded();
109 return nullptr; 114 return nullptr;
110 } 115 }
111 116
112 return new CompositorProxy(*element, attributeArray); 117 return new CompositorProxy(*element, attributeArray);
113 } 118 }
114 119
115 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t compositor MutableProperties) 120 CompositorProxy* CompositorProxy::create(ExecutionContext* context, uint64_t ele mentId, uint32_t compositorMutableProperties)
116 { 121 {
117 return new CompositorProxy(elementId, compositorMutableProperties); 122 TRACE_EVENT0("compositor-worker", "CompositorProxy::create");
123 WorkerClients* clients = toWorkerGlobalScope(context)->clients();
124 ASSERT(clients);
125 CompositorProxyClient* client = CompositorProxyClient::from(clients);
126 return new CompositorProxy(elementId, compositorMutableProperties, client);
118 } 127 }
119 128
120 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray) 129 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray)
121 : m_elementId(DOMNodeIds::idForNode(&element)) 130 : m_elementId(DOMNodeIds::idForNode(&element))
122 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu teArray)) 131 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu teArray))
132 , m_client(nullptr)
123 { 133 {
124 ASSERT(isMainThread()); 134 ASSERT(isMainThread());
125 ASSERT(m_compositorMutableProperties); 135 ASSERT(m_compositorMutableProperties);
126 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); 136 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties));
127 137
138 TRACE_EVENT0("compositor-worker", "CompositorProxy::CompositorProxy (main)") ;
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));
149 TRACE_EVENT0("compositor-worker", "CompositorProxy::CompositorProxy (impl)") ;
137 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, t hreadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId, m_co mpositorMutableProperties)); 150 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, t hreadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId, m_co mpositorMutableProperties));
151 m_client->registerCompositorProxy(this);
138 } 152 }
139 153
140 CompositorProxy::~CompositorProxy() 154 CompositorProxy::~CompositorProxy()
141 { 155 {
156 TRACE_EVENT0("compositor-worker", "CompositorProxy::~CompositorProxy");
142 if (m_connected) 157 if (m_connected)
143 disconnect(); 158 disconnect();
144 } 159 }
145 160
146 bool CompositorProxy::supports(const String& attributeName) const 161 bool CompositorProxy::supports(const String& attributeName) const
147 { 162 {
163 TRACE_EVENT0("compositor-worker", "CompositorProxy::supports");
148 return !!(m_compositorMutableProperties & static_cast<uint32_t>(compositorMu tablePropertyForName(attributeName))); 164 return !!(m_compositorMutableProperties & static_cast<uint32_t>(compositorMu tablePropertyForName(attributeName)));
149 } 165 }
150 166
151 double CompositorProxy::opacity(ExceptionState& exceptionState) const 167 double CompositorProxy::opacity(ExceptionState& exceptionState) const
152 { 168 {
153 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 169 double value = 0.0;
154 return 0.0; 170 TRACE_EVENT0("compositor-worker", "CompositorProxy::opacity");
155 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyOpacity), exceptionState)) 171 if (!raiseExceptionIfMutationNotAllowed(exceptionState) &&
156 return 0.0; 172 !raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePrope rtyOpacity), exceptionState) &&
157 return m_opacity; 173 m_state.get()) {
174 value = m_state->opacity();
175 }
176 TRACE_EVENT1("compositor-worker", "CompositorProxy::opacity", "value", value );
177 return value;
158 } 178 }
159 179
160 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const 180 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const
161 { 181 {
162 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 182 double value = 0.0;
163 return 0.0; 183 if (!raiseExceptionIfMutationNotAllowed(exceptionState) &&
164 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollLeft), exceptionState)) 184 !raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePrope rtyScrollLeft), exceptionState) &&
165 return 0.0; 185 m_state.get()) {
166 return m_scrollLeft; 186 value = m_state->scrollLeft();
187 }
188 TRACE_EVENT1("compositor-worker", "CompositorProxy::scrollLeft", "value", va lue);
189 return value;
167 } 190 }
168 191
169 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const 192 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const
170 { 193 {
171 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 194 double value = 0.0;
172 return 0.0; 195 TRACE_EVENT0("compositor-worker", "CompositorProxy::scrollTop");
173 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollTop), exceptionState)) 196 if (!raiseExceptionIfMutationNotAllowed(exceptionState) &&
174 return 0.0; 197 !raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePrope rtyScrollTop), exceptionState) &&
175 return m_scrollTop; 198 m_state.get()) {
199 value = m_state->scrollTop();
200 }
201 TRACE_EVENT1("compositor-worker", "CompositorProxy::scrollTop", "value", val ue);
202 return value;
176 } 203 }
177 204
178 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const 205 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const
179 { 206 {
207 TRACE_EVENT0("compositor-worker", "CompositorProxy::transform");
180 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 208 if (raiseExceptionIfMutationNotAllowed(exceptionState))
181 return nullptr; 209 return nullptr;
182 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyTransform), exceptionState)) 210 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutableProper tyTransform), exceptionState))
183 return nullptr; 211 return nullptr;
184 return m_transform; 212 if (!m_state.get())
213 return DOMMatrix::create();
214 return DOMMatrix::create(m_state->transform());
185 } 215 }
186 216
187 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) 217 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState)
188 { 218 {
219 TRACE_EVENT0("compositor-worker", "CompositorProxy::setOpacity");
189 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 220 if (raiseExceptionIfMutationNotAllowed(exceptionState))
190 return; 221 return;
191 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyOpacity), exceptionState)) 222 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutableProper tyOpacity), exceptionState))
192 return; 223 return;
193 m_opacity = std::min(1., std::max(0., opacity)); 224 if (!m_state.get())
194 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTra nsform); 225 return;
226 opacity = std::min(1., std::max(0., opacity));
227 m_state->setOpacity(opacity);
195 } 228 }
196 229
197 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception State) 230 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception State)
198 { 231 {
232 TRACE_EVENT0("compositor-worker", "CompositorProxy::setScrollLeft");
199 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 233 if (raiseExceptionIfMutationNotAllowed(exceptionState))
200 return; 234 return;
201 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollLeft), exceptionState)) 235 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutableProper tyScrollLeft), exceptionState))
202 return; 236 return;
203 m_scrollLeft = scrollLeft; 237 if (!m_state.get())
204 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScr ollLeft); 238 return;
239 m_state->setScrollLeft(scrollLeft);
205 } 240 }
206 241
207 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt ate) 242 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt ate)
208 { 243 {
244 TRACE_EVENT0("compositor-worker", "CompositorProxy::setScrollTop");
209 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 245 if (raiseExceptionIfMutationNotAllowed(exceptionState))
210 return; 246 return;
211 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollTop), exceptionState)) 247 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutableProper tyScrollTop), exceptionState))
212 return; 248 return;
213 m_scrollTop = scrollTop; 249 if (!m_state.get())
214 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScr ollTop); 250 return;
251 m_state->setScrollTop(scrollTop);
215 } 252 }
216 253
217 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti onState) 254 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti onState)
218 { 255 {
256 TRACE_EVENT0("compositor-worker", "CompositorProxy::setTransform");
219 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 257 if (raiseExceptionIfMutationNotAllowed(exceptionState))
220 return; 258 return;
221 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyTransform), exceptionState)) 259 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutableProper tyTransform), exceptionState))
222 return; 260 return;
223 m_transform = transform; 261 if (!m_state.get())
224 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTra nsform); 262 return;
263 m_state->setTransform(TransformationMatrix::toSkMatrix44(transform->matrix() ));
225 } 264 }
226 265
227 bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta te& exceptionState) const 266 bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta te& exceptionState) const
228 { 267 {
229 if (m_connected && (m_compositorMutableProperties & property)) 268 if (m_connected && (m_compositorMutableProperties & property))
230 return false; 269 return false;
231 exceptionState.throwDOMException(NoModificationAllowedError, 270 exceptionState.throwDOMException(NoModificationAllowedError,
232 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted to mutate attribute on a disconnected proxy."); 271 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted to mutate attribute on a disconnected proxy.");
233 return true; 272 return true;
234 } 273 }
235 274
275 void CompositorProxy::setNeedsSync()
276 {
277 if (m_needsSync)
278 return;
279 m_needsSync = true;
280 if (m_client)
281 m_client->requestSync(this);
282 }
283
236 void CompositorProxy::disconnect() 284 void CompositorProxy::disconnect()
237 { 285 {
286 if (!m_connected)
287 return;
288 TRACE_EVENT0("compositor-worker", "CompositorProxy::disconnect");
238 m_connected = false; 289 m_connected = false;
239 if (isMainThread()) 290 if (isMainThread()) {
240 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties); 291 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties);
241 else 292 } else {
242 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HER E, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_elementId, m_compositorMutableProperties)); 293 Platform::current()->mainThread()->taskRunner()->postTask(
294 BLINK_FROM_HERE, threadSafeBind(&decrementCompositorProxiedPropertie sForElement, m_elementId, m_compositorMutableProperties));
295 if (m_client)
296 m_client->unregisterCompositorProxy(this);
297 }
298 }
299
300 void CompositorProxy::takeCompositorMutableState(PassOwnPtr<CompositorMutableSta te> state)
301 {
302 m_state = state;
243 } 303 }
244 304
245 } // namespace blink 305 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/CompositorProxy.h ('k') | third_party/WebKit/Source/core/dom/CompositorProxy.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698