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

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, 12 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"
13 #include "public/platform/Platform.h" 17 #include "public/platform/Platform.h"
14 #include "public/platform/WebCompositorMutableProperties.h" 18 #include "public/platform/WebCompositorMutableProperties.h"
19 #include "public/platform/WebCompositorMutableState.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 struct MutablePropertyMapping { 25 struct MutablePropertyMapping {
21 const char* name; 26 const char* name;
22 unsigned length; 27 unsigned length;
23 WebCompositorMutableProperty property; 28 WebCompositorMutableProperty property;
24 }; 29 };
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 { 126 {
122 if (!context->isDocument()) { 127 if (!context->isDocument()) {
123 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp ositorProxy", "Can only be created from the main context.")); 128 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp ositorProxy", "Can only be created from the main context."));
124 exceptionState.throwIfNeeded(); 129 exceptionState.throwIfNeeded();
125 return nullptr; 130 return nullptr;
126 } 131 }
127 132
128 return new CompositorProxy(*element, attributeArray); 133 return new CompositorProxy(*element, attributeArray);
129 } 134 }
130 135
131 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t compositor MutableProperties) 136 CompositorProxy* CompositorProxy::create(ExecutionContext* context, uint64_t ele mentId, uint32_t compositorMutableProperties)
132 { 137 {
133 return new CompositorProxy(elementId, compositorMutableProperties); 138 TRACE_EVENT0("compositor-worker", "CompositorProxy::create");
139 WorkerClients* clients = toWorkerGlobalScope(context)->clients();
140 ASSERT(clients);
141 CompositorProxyClient* client = CompositorProxyClient::from(clients);
142 return new CompositorProxy(elementId, compositorMutableProperties, client);
134 } 143 }
135 144
136 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray) 145 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray)
137 : m_elementId(DOMNodeIds::idForNode(&element)) 146 : m_elementId(DOMNodeIds::idForNode(&element))
138 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu teArray)) 147 , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attribu teArray))
148 , m_client(nullptr)
139 { 149 {
140 ASSERT(isMainThread()); 150 ASSERT(isMainThread());
141 ASSERT(m_compositorMutableProperties); 151 ASSERT(m_compositorMutableProperties);
142 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); 152 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties));
143 153
154 TRACE_EVENT0("compositor-worker", "CompositorProxy::CompositorProxy (main)") ;
144 incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMuta bleProperties); 155 incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMuta bleProperties);
145 } 156 }
146 157
147 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP roperties) 158 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableP roperties, CompositorProxyClient* client)
148 : m_elementId(elementId) 159 : m_elementId(elementId)
149 , m_compositorMutableProperties(compositorMutableProperties) 160 , m_compositorMutableProperties(compositorMutableProperties)
161 , m_client(client)
150 { 162 {
151 ASSERT(isControlThread()); 163 ASSERT(isControlThread());
152 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); 164 ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties));
165 TRACE_EVENT0("compositor-worker", "CompositorProxy::CompositorProxy (impl)") ;
153 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, t hreadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId, m_co mpositorMutableProperties)); 166 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, t hreadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId, m_co mpositorMutableProperties));
154 } 167 }
155 168
156 CompositorProxy::~CompositorProxy() 169 CompositorProxy::~CompositorProxy()
157 { 170 {
171 TRACE_EVENT0("compositor-worker", "CompositorProxy::~CompositorProxy");
158 if (m_connected) 172 if (m_connected)
159 disconnect(); 173 disconnect();
160 } 174 }
161 175
162 bool CompositorProxy::supports(const String& attributeName) const 176 bool CompositorProxy::supports(const String& attributeName) const
163 { 177 {
178 TRACE_EVENT0("compositor-worker", "CompositorProxy::supports");
164 return !!(m_compositorMutableProperties & static_cast<uint32_t>(compositorMu tablePropertyForName(attributeName))); 179 return !!(m_compositorMutableProperties & static_cast<uint32_t>(compositorMu tablePropertyForName(attributeName)));
165 } 180 }
166 181
167 double CompositorProxy::opacity(ExceptionState& exceptionState) const 182 double CompositorProxy::opacity(ExceptionState& exceptionState) const
168 { 183 {
184 TRACE_EVENT0("compositor-worker", "CompositorProxy::opacity");
169 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 185 if (raiseExceptionIfMutationNotAllowed(exceptionState))
170 return 0.0; 186 return 0.0;
171 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyOpacity), exceptionState)) 187 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyOpacity), exceptionState))
172 return 0.0; 188 return 0.0;
173 return m_opacity; 189 if (!m_state.get())
190 return 0.0;
191 return m_state->opacity();
174 } 192 }
175 193
176 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const 194 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const
177 { 195 {
196 TRACE_EVENT0("compositor-worker", "CompositorProxy::scrollLeft");
178 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 197 if (raiseExceptionIfMutationNotAllowed(exceptionState))
179 return 0.0; 198 return 0.0;
180 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollLeft), exceptionState)) 199 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollLeft), exceptionState))
181 return 0.0; 200 return 0.0;
182 return m_scrollLeft; 201 if (!m_state.get())
202 return 0.0;
203 return m_state->scrollLeft();
183 } 204 }
184 205
185 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const 206 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const
186 { 207 {
208 TRACE_EVENT0("compositor-worker", "CompositorProxy::scrollTop");
187 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 209 if (raiseExceptionIfMutationNotAllowed(exceptionState))
188 return 0.0; 210 return 0.0;
189 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollTop), exceptionState)) 211 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollTop), exceptionState))
190 return 0.0; 212 return 0.0;
191 return m_scrollTop; 213 if (!m_state.get())
214 return 0.0;
215 return m_state->scrollTop();
192 } 216 }
193 217
194 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const 218 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const
195 { 219 {
220 TRACE_EVENT0("compositor-worker", "CompositorProxy::transform");
196 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 221 if (raiseExceptionIfMutationNotAllowed(exceptionState))
197 return nullptr; 222 return nullptr;
198 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyTransform), exceptionState)) 223 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyTransform), exceptionState))
199 return nullptr; 224 return nullptr;
200 return m_transform; 225 if (!m_state.get())
226 return DOMMatrix::create();
227 return DOMMatrix::create(m_state->transform());
201 } 228 }
202 229
203 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) 230 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState)
204 { 231 {
232 TRACE_EVENT0("compositor-worker", "CompositorProxy::setOpacity");
205 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 233 if (raiseExceptionIfMutationNotAllowed(exceptionState))
206 return; 234 return;
207 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyOpacity), exceptionState)) 235 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyOpacity), exceptionState))
208 return; 236 return;
209 m_opacity = std::min(1., std::max(0., opacity)); 237 if (!m_state.get())
210 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTra nsform); 238 return;
239 opacity = std::min(1., std::max(0., opacity));
240 m_state->setOpacity(opacity);
211 } 241 }
212 242
213 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception State) 243 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception State)
214 { 244 {
245 TRACE_EVENT0("compositor-worker", "CompositorProxy::setScrollLeft");
215 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 246 if (raiseExceptionIfMutationNotAllowed(exceptionState))
216 return; 247 return;
217 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollLeft), exceptionState)) 248 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollLeft), exceptionState))
218 return; 249 return;
219 m_scrollLeft = scrollLeft; 250 if (!m_state.get())
220 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScr ollLeft); 251 return;
252 m_state->setScrollLeft(scrollLeft);
221 } 253 }
222 254
223 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt ate) 255 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt ate)
224 { 256 {
257 TRACE_EVENT0("compositor-worker", "CompositorProxy::setScrollTop");
225 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 258 if (raiseExceptionIfMutationNotAllowed(exceptionState))
226 return; 259 return;
227 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollTop), exceptionState)) 260 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyScrollTop), exceptionState))
228 return; 261 return;
229 m_scrollTop = scrollTop; 262 if (!m_state.get())
230 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScr ollTop); 263 return;
264 m_state->setScrollTop(scrollTop);
231 } 265 }
232 266
233 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti onState) 267 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti onState)
234 { 268 {
269 TRACE_EVENT0("compositor-worker", "CompositorProxy::setTransform");
235 if (raiseExceptionIfMutationNotAllowed(exceptionState)) 270 if (raiseExceptionIfMutationNotAllowed(exceptionState))
236 return; 271 return;
237 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyTransform), exceptionState)) 272 if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePro pertyTransform), exceptionState))
238 return; 273 return;
239 m_transform = transform; 274 if (!m_state.get())
240 m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTra nsform); 275 return;
276 m_state->setTransform(TransformationMatrix::toSkMatrix44(transform->matrix() ));
241 } 277 }
242 278
243 bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta te& exceptionState) const 279 bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta te& exceptionState) const
244 { 280 {
245 if (m_connected && (m_compositorMutableProperties & property)) 281 if (m_connected && (m_compositorMutableProperties & property))
246 return false; 282 return false;
247 exceptionState.throwDOMException(NoModificationAllowedError, 283 exceptionState.throwDOMException(NoModificationAllowedError,
248 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted to mutate attribute on a disconnected proxy."); 284 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted to mutate attribute on a disconnected proxy.");
249 return true; 285 return true;
250 } 286 }
251 287
288 void CompositorProxy::setNeedsSync()
289 {
290 if (m_needsSync)
291 return;
292 m_needsSync = true;
293 if (m_client)
294 m_client->requestSync(this);
295 }
296
252 void CompositorProxy::disconnect() 297 void CompositorProxy::disconnect()
253 { 298 {
299 if (!m_connected)
300 return;
301 TRACE_EVENT0("compositor-worker", "CompositorProxy::disconnect");
254 m_connected = false; 302 m_connected = false;
255 if (isMainThread()) 303 if (isMainThread()) {
256 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties); 304 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties);
257 else 305 } else {
258 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HER E, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_elementId, m_compositorMutableProperties)); 306 Platform::current()->mainThread()->taskRunner()->postTask(
307 BLINK_FROM_HERE, threadSafeBind(&decrementCompositorProxiedPropertie sForElement, m_elementId, m_compositorMutableProperties));
308 if (m_client)
309 m_client->unregisterCompositorProxy(this);
310 }
311 }
312
313 void CompositorProxy::takeCompositorMutableState(blink::WebCompositorMutableStat e* state)
314 {
315 m_state = adoptPtr(state);
259 } 316 }
260 317
261 } // namespace blink 318 } // 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