| 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 f45d7ccd873781ab03c0e2647bde0a0d21b72021..86177e2a5d59ae8170c4cad3226015a3982e7252 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 "platform/graphics/CompositorMutableProperties.h"
|
| +#include "platform/graphics/CompositorMutableState.h"
|
| #include "public/platform/Platform.h"
|
| -#include "public/platform/WebCompositorMutableProperties.h"
|
| #include "public/platform/WebTraceLocation.h"
|
| #include <algorithm>
|
|
|
| @@ -19,21 +24,21 @@ namespace blink {
|
|
|
| static const struct {
|
| const char* name;
|
| - WebCompositorMutableProperty property;
|
| + CompositorMutableProperty property;
|
| } allowedProperties[] = {
|
| - { "opacity", WebCompositorMutablePropertyOpacity },
|
| - { "scrollleft", WebCompositorMutablePropertyScrollLeft },
|
| - { "scrolltop", WebCompositorMutablePropertyScrollTop },
|
| - { "transform", WebCompositorMutablePropertyTransform },
|
| + { "opacity", CompositorMutablePropertyOpacity },
|
| + { "scrollleft", CompositorMutablePropertyScrollLeft },
|
| + { "scrolltop", CompositorMutablePropertyScrollTop },
|
| + { "transform", CompositorMutablePropertyTransform },
|
| };
|
|
|
| -static WebCompositorMutableProperty compositorMutablePropertyForName(const String& attributeName)
|
| +static CompositorMutableProperty compositorMutablePropertyForName(const String& attributeName)
|
| {
|
| for (const auto& mapping : allowedProperties) {
|
| if (equalIgnoringCase(mapping.name, attributeName))
|
| return mapping.property;
|
| }
|
| - return WebCompositorMutablePropertyNone;
|
| + return CompositorMutablePropertyNone;
|
| }
|
|
|
| static bool isControlThread()
|
| @@ -112,116 +117,150 @@ 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));
|
| + m_client->registerCompositorProxy(this);
|
| }
|
|
|
| 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
|
| {
|
| - if (raiseExceptionIfMutationNotAllowed(exceptionState))
|
| - return 0.0;
|
| - if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyOpacity), exceptionState))
|
| - return 0.0;
|
| - return m_opacity;
|
| + double value = 0.0;
|
| + TRACE_EVENT0("compositor-worker", "CompositorProxy::opacity");
|
| + if (!raiseExceptionIfMutationNotAllowed(exceptionState) &&
|
| + !raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePropertyOpacity), exceptionState) &&
|
| + m_state.get()) {
|
| + value = m_state->opacity();
|
| + }
|
| + TRACE_EVENT1("compositor-worker", "CompositorProxy::opacity", "value", value);
|
| + return value;
|
| }
|
|
|
| double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const
|
| {
|
| - if (raiseExceptionIfMutationNotAllowed(exceptionState))
|
| - return 0.0;
|
| - if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyScrollLeft), exceptionState))
|
| - return 0.0;
|
| - return m_scrollLeft;
|
| + double value = 0.0;
|
| + if (!raiseExceptionIfMutationNotAllowed(exceptionState) &&
|
| + !raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePropertyScrollLeft), exceptionState) &&
|
| + m_state.get()) {
|
| + value = m_state->scrollLeft();
|
| + }
|
| + TRACE_EVENT1("compositor-worker", "CompositorProxy::scrollLeft", "value", value);
|
| + return value;
|
| }
|
|
|
| double CompositorProxy::scrollTop(ExceptionState& exceptionState) const
|
| {
|
| - if (raiseExceptionIfMutationNotAllowed(exceptionState))
|
| - return 0.0;
|
| - if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyScrollTop), exceptionState))
|
| - return 0.0;
|
| - return m_scrollTop;
|
| + double value = 0.0;
|
| + TRACE_EVENT0("compositor-worker", "CompositorProxy::scrollTop");
|
| + if (!raiseExceptionIfMutationNotAllowed(exceptionState) &&
|
| + !raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePropertyScrollTop), exceptionState) &&
|
| + m_state.get()) {
|
| + value = m_state->scrollTop();
|
| + }
|
| + TRACE_EVENT1("compositor-worker", "CompositorProxy::scrollTop", "value", value);
|
| + return value;
|
| }
|
|
|
| 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))
|
| + if (raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePropertyTransform), 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))
|
| + if (raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePropertyOpacity), exceptionState))
|
| + return;
|
| + if (!m_state.get())
|
| return;
|
| - m_opacity = std::min(1., std::max(0., opacity));
|
| - m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTransform);
|
| + 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))
|
| + if (raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePropertyScrollLeft), exceptionState))
|
| + return;
|
| + if (!m_state.get())
|
| return;
|
| - m_scrollLeft = scrollLeft;
|
| - m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScrollLeft);
|
| + 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))
|
| + if (raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePropertyScrollTop), 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))
|
| + if (raiseExceptionIfNotMutable(static_cast<uint32_t>(CompositorMutablePropertyTransform), exceptionState))
|
| + return;
|
| + if (!m_state.get())
|
| return;
|
| - m_transform = transform;
|
| - m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTransform);
|
| + m_state->setTransform(TransformationMatrix::toSkMatrix44(transform->matrix()));
|
| }
|
|
|
| bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionState& exceptionState) const
|
| @@ -233,13 +272,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(PassOwnPtr<CompositorMutableState> state)
|
| +{
|
| + m_state = state;
|
| }
|
|
|
| } // namespace blink
|
|
|