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

Unified Diff: third_party/WebKit/Source/core/dom/CompositorProxy.cpp

Issue 1405993008: compositor-worker: plumb element id and mutable properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix rebase error. Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/CompositorProxy.h ('k') | third_party/WebKit/Source/core/dom/Element.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 371f3fb2e980bdaf081e92a47536b349c0d3d073..806f8b2f90f068c9be8327f2d223cabcaf3988a5 100644
--- a/third_party/WebKit/Source/core/dom/CompositorProxy.cpp
+++ b/third_party/WebKit/Source/core/dom/CompositorProxy.cpp
@@ -12,42 +12,44 @@
#include "core/dom/ExecutionContext.h"
#include "platform/ThreadSafeFunctional.h"
#include "public/platform/Platform.h"
+#include "public/platform/WebCompositorMutableProperties.h"
#include "public/platform/WebTraceLocation.h"
namespace blink {
-struct AttributeFlagMapping {
+struct MutablePropertyMapping {
const char* name;
unsigned length;
- CompositorProxy::Attributes attribute;
+ WebCompositorMutableProperty property;
};
-static AttributeFlagMapping allowedAttributes[] = {
- { "opacity", 7, CompositorProxy::Attributes::OPACITY },
- { "scrollleft", 10, CompositorProxy::Attributes::SCROLL_LEFT },
- { "scrolltop", 9, CompositorProxy::Attributes::SCROLL_TOP },
- { "touch", 5, CompositorProxy::Attributes::TOUCH },
- { "transform", 8, CompositorProxy::Attributes::TRANSFORM },
+// Warning: In order for std::lower_bound to work, the following must be in
+// alphabetical order.
+static MutablePropertyMapping allowedProperties[] = {
+ { "opacity", 7, WebCompositorMutablePropertyOpacity },
+ { "scrollleft", 10, WebCompositorMutablePropertyScrollLeft },
+ { "scrolltop", 9, WebCompositorMutablePropertyScrollTop },
+ { "transform", 9, WebCompositorMutablePropertyTransform },
};
-static bool CompareAttributeName(const AttributeFlagMapping& attribute, StringImpl* attributeLower)
+static bool comparePropertyName(const MutablePropertyMapping& mapping, StringImpl* propertyLower)
{
- ASSERT(attributeLower->is8Bit());
- return memcmp(attribute.name, attributeLower->characters8(), std::min(attribute.length, attributeLower->length())) < 0;
+ ASSERT(propertyLower->is8Bit());
+ return memcmp(mapping.name, propertyLower->characters8(), std::min(mapping.length, propertyLower->length())) < 0;
}
-static CompositorProxy::Attributes attributeFlagForName(const String& attributeName)
+static WebCompositorMutableProperty compositorMutablePropertyForName(const String& attributeName)
{
- CompositorProxy::Attributes attributeFlag = CompositorProxy::Attributes::NONE;
+ WebCompositorMutableProperty property = WebCompositorMutablePropertyNone;
const String attributeLower = attributeName.lower();
- const AttributeFlagMapping* start = allowedAttributes;
- const AttributeFlagMapping* end = allowedAttributes + WTF_ARRAY_LENGTH(allowedAttributes);
+ const MutablePropertyMapping* start = allowedProperties;
+ const MutablePropertyMapping* end = allowedProperties + WTF_ARRAY_LENGTH(allowedProperties);
if (attributeLower.impl()->is8Bit()) {
- const AttributeFlagMapping* match = std::lower_bound(start, end, attributeLower.impl(), CompareAttributeName);
- if (match != end)
- attributeFlag = match->attribute;
+ const MutablePropertyMapping* match = std::lower_bound(start, end, attributeLower.impl(), comparePropertyName);
+ if (match != end && equal(match->name, attributeLower.impl()))
+ property = match->property;
}
- return attributeFlag;
+ return property;
}
static bool isControlThread()
@@ -61,24 +63,24 @@ static bool isCallingCompositorFrameCallback()
return true;
}
-static void decrementCountForElement(uint64_t elementId)
+static void decrementCompositorProxiedPropertiesForElement(uint64_t elementId, uint32_t compositorMutableProperties)
{
ASSERT(isMainThread());
Node* node = DOMNodeIds::nodeForId(elementId);
if (!node)
return;
Element* element = toElement(node);
- element->decrementProxyCount();
+ element->decrementCompositorProxiedProperties(compositorMutableProperties);
}
-static void incrementProxyCountForElement(uint64_t elementId)
+static void incrementCompositorProxiedPropertiesForElement(uint64_t elementId, uint32_t compositorMutableProperties)
{
ASSERT(isMainThread());
Node* node = DOMNodeIds::nodeForId(elementId);
if (!node)
return;
Element* element = toElement(node);
- element->incrementProxyCount();
+ element->incrementCompositorProxiedProperties(compositorMutableProperties);
}
static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState)
@@ -94,23 +96,24 @@ static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState)
return false;
}
-static uint32_t attributesBitfieldFromNames(const Vector<String>& attributeArray)
+static uint32_t compositorMutablePropertiesFromNames(const Vector<String>& attributeArray)
{
- uint32_t attributesBitfield = 0;
+ uint32_t properties = 0;
for (const auto& attribute : attributeArray) {
- attributesBitfield |= static_cast<uint32_t>(attributeFlagForName(attribute));
+ properties |= static_cast<uint32_t>(compositorMutablePropertyForName(attribute));
}
- return attributesBitfield;
+ return properties;
}
#if ENABLE(ASSERT)
-static bool sanityCheckAttributeFlags(uint32_t attributeFlags)
+static bool sanityCheckMutableProperties(uint32_t properties)
{
- uint32_t sanityCheckAttributes = attributeFlags;
- for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) {
- sanityCheckAttributes &= ~static_cast<uint32_t>(allowedAttributes[i].attribute);
+ // Ensures that we only have bits set for valid mutable properties.
+ uint32_t sanityCheckProperties = properties;
+ for (unsigned i = 0; i < arraysize(allowedProperties); ++i) {
+ sanityCheckProperties &= ~static_cast<uint32_t>(allowedProperties[i].property);
}
- return !sanityCheckAttributes;
+ return !sanityCheckProperties;
}
#endif
@@ -125,29 +128,29 @@ CompositorProxy* CompositorProxy::create(ExecutionContext* context, Element* ele
return new CompositorProxy(*element, attributeArray);
}
-CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeFlags)
+CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t compositorMutableProperties)
{
- return new CompositorProxy(elementId, attributeFlags);
+ return new CompositorProxy(elementId, compositorMutableProperties);
}
CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attributeArray)
: m_elementId(DOMNodeIds::idForNode(&element))
- , m_bitfieldsSupported(attributesBitfieldFromNames(attributeArray))
+ , m_compositorMutableProperties(compositorMutablePropertiesFromNames(attributeArray))
{
ASSERT(isMainThread());
- ASSERT(m_bitfieldsSupported);
- ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported));
+ ASSERT(m_compositorMutableProperties);
+ ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties));
- incrementProxyCountForElement(m_elementId);
+ incrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMutableProperties);
}
-CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags)
+CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableProperties)
: m_elementId(elementId)
- , m_bitfieldsSupported(attributeFlags)
+ , m_compositorMutableProperties(compositorMutableProperties)
{
ASSERT(isControlThread());
- ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported));
- Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&incrementProxyCountForElement, m_elementId));
+ ASSERT(sanityCheckMutableProperties(m_compositorMutableProperties));
+ Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&incrementCompositorProxiedPropertiesForElement, m_elementId, m_compositorMutableProperties));
}
CompositorProxy::~CompositorProxy()
@@ -158,14 +161,14 @@ CompositorProxy::~CompositorProxy()
bool CompositorProxy::supports(const String& attributeName) const
{
- return !!(m_bitfieldsSupported & static_cast<uint32_t>(attributeFlagForName(attributeName)));
+ return !!(m_compositorMutableProperties & static_cast<uint32_t>(compositorMutablePropertyForName(attributeName)));
}
double CompositorProxy::opacity(ExceptionState& exceptionState) const
{
if (raiseExceptionIfMutationNotAllowed(exceptionState))
return 0.0;
- if (raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState))
+ if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyOpacity), exceptionState))
return 0.0;
return m_opacity;
}
@@ -174,7 +177,7 @@ double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const
{
if (raiseExceptionIfMutationNotAllowed(exceptionState))
return 0.0;
- if (raiseExceptionIfNotMutable(Attributes::SCROLL_LEFT, exceptionState))
+ if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyScrollLeft), exceptionState))
return 0.0;
return m_scrollLeft;
}
@@ -183,7 +186,7 @@ double CompositorProxy::scrollTop(ExceptionState& exceptionState) const
{
if (raiseExceptionIfMutationNotAllowed(exceptionState))
return 0.0;
- if (raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionState))
+ if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyScrollTop), exceptionState))
return 0.0;
return m_scrollTop;
}
@@ -192,7 +195,7 @@ DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const
{
if (raiseExceptionIfMutationNotAllowed(exceptionState))
return nullptr;
- if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState))
+ if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyTransform), exceptionState))
return nullptr;
return m_transform;
}
@@ -201,45 +204,45 @@ void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState)
{
if (raiseExceptionIfMutationNotAllowed(exceptionState))
return;
- if (raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState))
+ if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyOpacity), exceptionState))
return;
m_opacity = std::min(1., std::max(0., opacity));
- m_mutatedAttributes |= static_cast<uint32_t>(Attributes::OPACITY);
+ m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTransform);
}
void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exceptionState)
{
if (raiseExceptionIfMutationNotAllowed(exceptionState))
return;
- if (raiseExceptionIfNotMutable(Attributes::SCROLL_LEFT, exceptionState))
+ if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyScrollLeft), exceptionState))
return;
m_scrollLeft = scrollLeft;
- m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_LEFT);
+ m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScrollLeft);
}
void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionState)
{
if (raiseExceptionIfMutationNotAllowed(exceptionState))
return;
- if (raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionState))
+ if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyScrollTop), exceptionState))
return;
m_scrollTop = scrollTop;
- m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_TOP);
+ m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyScrollTop);
}
void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& exceptionState)
{
if (raiseExceptionIfMutationNotAllowed(exceptionState))
return;
- if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState))
+ if (raiseExceptionIfNotMutable(static_cast<uint32_t>(WebCompositorMutablePropertyTransform), exceptionState))
return;
m_transform = transform;
- m_mutatedAttributes |= static_cast<uint32_t>(Attributes::TRANSFORM);
+ m_mutatedProperties |= static_cast<uint32_t>(WebCompositorMutablePropertyTransform);
}
-bool CompositorProxy::raiseExceptionIfNotMutable(Attributes attribute, ExceptionState& exceptionState) const
+bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionState& exceptionState) const
{
- if (m_connected && (m_bitfieldsSupported & static_cast<uint32_t>(attribute)))
+ if (m_connected && (m_compositorMutableProperties & property))
return false;
exceptionState.throwDOMException(NoModificationAllowedError,
m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted to mutate attribute on a disconnected proxy.");
@@ -250,9 +253,9 @@ void CompositorProxy::disconnect()
{
m_connected = false;
if (isMainThread())
- decrementCountForElement(m_elementId);
+ decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositorMutableProperties);
else
- Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&decrementCountForElement, m_elementId));
+ Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_elementId, m_compositorMutableProperties));
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/dom/CompositorProxy.h ('k') | third_party/WebKit/Source/core/dom/Element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698