Index: third_party/WebKit/Source/core/dom/CompositorProxy.cpp |
diff --git a/third_party/WebKit/Source/core/dom/CompositorProxy.cpp b/third_party/WebKit/Source/core/dom/CompositorProxy.cpp |
index 3a5676c04a17110b9c455948d8abc3e5a1bff773..f3de05a6be0b0f4a82442df44afe09786edbc766 100644 |
--- a/third_party/WebKit/Source/core/dom/CompositorProxy.cpp |
+++ b/third_party/WebKit/Source/core/dom/CompositorProxy.cpp |
@@ -6,12 +6,17 @@ |
#include "bindings/core/v8/ExceptionMessages.h" |
#include "bindings/core/v8/ExceptionState.h" |
+#include "core/dom/CompositorProxyClient.h" |
#include "core/dom/DOMNodeIds.h" |
#include "core/dom/ExceptionCode.h" |
#include "core/dom/ExecutionContext.h" |
+#include "core/workers/WorkerClients.h" |
+#include "core/workers/WorkerGlobalScope.h" |
#include "platform/ThreadSafeFunctional.h" |
+#include "platform/TraceEvent.h" |
#include "public/platform/Platform.h" |
#include "public/platform/WebCompositorMutableProperties.h" |
+#include "public/platform/WebCompositorMutableState.h" |
#include "public/platform/WebTraceLocation.h" |
#include <algorithm> |
@@ -128,116 +133,147 @@ CompositorProxy* CompositorProxy::create(ExecutionContext* context, Element* ele |
return new CompositorProxy(*element, attributeArray); |
} |
-CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t compositorMutableProperties) |
+CompositorProxy* CompositorProxy::create(ExecutionContext* context, uint64_t elementId, uint32_t compositorMutableProperties) |
{ |
- return new CompositorProxy(elementId, compositorMutableProperties); |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::create"); |
+ WorkerClients* clients = toWorkerGlobalScope(context)->clients(); |
+ ASSERT(clients); |
+ CompositorProxyClient* client = CompositorProxyClient::from(clients); |
+ return new CompositorProxy(elementId, compositorMutableProperties, client); |
} |
CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attributeArray) |
: m_elementId(DOMNodeIds::idForNode(&element)) |
, m_compositorMutableProperties(compositorMutablePropertiesFromNames(attributeArray)) |
+ , m_client(nullptr) |
{ |
ASSERT(isMainThread()); |
ASSERT(m_compositorMutableProperties); |
ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::CompositorProxy (main)"); |
incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMutableProperties); |
} |
-CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableProperties) |
+CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableProperties, CompositorProxyClient* client) |
: m_elementId(elementId) |
, m_compositorMutableProperties(compositorMutableProperties) |
+ , m_client(client) |
{ |
ASSERT(isControlThread()); |
ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties)); |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::CompositorProxy (impl)"); |
Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId, m_compositorMutableProperties)); |
} |
CompositorProxy::~CompositorProxy() |
{ |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::~CompositorProxy"); |
if (m_connected) |
disconnect(); |
} |
bool CompositorProxy::supports(const String& attributeName) const |
{ |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::supports"); |
return !!(m_compositorMutableProperties & static_cast<uint32_t>(compositorMutablePropertyForName(attributeName))); |
} |
double CompositorProxy::opacity(ExceptionState& exceptionState) const |
{ |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::opacity"); |
if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
return 0.0; |
if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyOpacity), exceptionState)) |
return 0.0; |
- return m_opacity; |
+ if (!m_state.get()) |
+ return 0.0; |
+ return m_state->opacity(); |
} |
double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const |
{ |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::scrollLeft"); |
if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
return 0.0; |
if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyScrollLeft), exceptionState)) |
return 0.0; |
- return m_scrollLeft; |
+ if (!m_state.get()) |
+ return 0.0; |
+ return m_state->scrollLeft(); |
} |
double CompositorProxy::scrollTop(ExceptionState& exceptionState) const |
{ |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::scrollTop"); |
if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
return 0.0; |
if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyScrollTop), exceptionState)) |
return 0.0; |
- return m_scrollTop; |
+ if (!m_state.get()) |
+ return 0.0; |
+ return m_state->scrollTop(); |
} |
DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const |
{ |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::transform"); |
if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
return nullptr; |
if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyTransform), exceptionState)) |
return nullptr; |
- return m_transform; |
+ if (!m_state.get()) |
+ return DOMMatrix::create(); |
+ return DOMMatrix::create(m_state->transform()); |
} |
void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) |
{ |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::setOpacity"); |
if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
return; |
if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyOpacity), exceptionState)) |
return; |
- m_opacity = std::min(1., std::max(0., opacity)); |
- m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTransform); |
+ if (!m_state.get()) |
+ return; |
+ opacity = std::min(1., std::max(0., opacity)); |
+ m_state->setOpacity(opacity); |
} |
void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exceptionState) |
{ |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::setScrollLeft"); |
if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
return; |
if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyScrollLeft), exceptionState)) |
return; |
- m_scrollLeft = scrollLeft; |
- m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScrollLeft); |
+ if (!m_state.get()) |
+ return; |
+ m_state->setScrollLeft(scrollLeft); |
} |
void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionState) |
{ |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::setScrollTop"); |
if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
return; |
if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyScrollTop), exceptionState)) |
return; |
- m_scrollTop = scrollTop; |
- m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScrollTop); |
+ if (!m_state.get()) |
+ return; |
+ m_state->setScrollTop(scrollTop); |
} |
void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& exceptionState) |
{ |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::setTransform"); |
if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
return; |
if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyTransform), exceptionState)) |
return; |
- m_transform = transform; |
- m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTransform); |
+ if (!m_state.get()) |
+ return; |
+ m_state->setTransform(TransformationMatrix::toSkMatrix44(transform->matrix())); |
} |
bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionState& exceptionState) const |
@@ -249,13 +285,34 @@ bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta |
return true; |
} |
+void CompositorProxy::setNeedsSync() |
+{ |
+ if (m_needsSync) |
+ return; |
+ m_needsSync = true; |
+ if (m_client) |
+ m_client->requestSync(this); |
+} |
+ |
void CompositorProxy::disconnect() |
{ |
+ if (!m_connected) |
+ return; |
+ TRACE_EVENT0("compositor-worker", "CompositorProxy::disconnect"); |
m_connected = false; |
- if (isMainThread()) |
+ if (isMainThread()) { |
decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMutableProperties); |
- else |
- Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_elementId, m_compositorMutableProperties)); |
+ } else { |
+ Platform::current()->mainThread()->taskRunner()->postTask( |
+ BLINK_FROM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_elementId, m_compositorMutableProperties)); |
+ if (m_client) |
+ m_client->unregisterCompositorProxy(this); |
+ } |
+} |
+ |
+void CompositorProxy::takeCompositorMutableState(blink::WebCompositorMutableState* state) |
+{ |
+ m_state = adoptPtr(state); |
} |
} // namespace blink |