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

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

Issue 1024233002: compositor-worker: Introduce CompositorProxy. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/CompositorProxy.cpp
diff --git a/Source/core/dom/CompositorProxy.cpp b/Source/core/dom/CompositorProxy.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d2282b7cf1c09867e7af806042c66fc0f616e612
--- /dev/null
+++ b/Source/core/dom/CompositorProxy.cpp
@@ -0,0 +1,83 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/dom/CompositorProxy.h"
+
+#include "bindings/core/v8/ExceptionMessages.h"
+#include "bindings/core/v8/ExceptionState.h"
+#include "core/dom/ExecutionContext.h"
+#include "core/inspector/InspectorNodeIds.h"
+
+namespace blink {
+
+static struct {
+ const char* name;
+ CompositorProxy::Attributes attribute;
+} allowedAttributes[] = {
esprehn 2015/03/25 23:21:48 Lets declare the struct and the usage separately,
sadrul 2015/03/27 17:23:28 Done.
+ { "opacity", CompositorProxy::Attributes::OPACITY },
+ { "scrolltop", CompositorProxy::Attributes::SCROLL_TOP },
+ { "touch", CompositorProxy::Attributes::TOUCH },
+ { "transform", CompositorProxy::Attributes::TRANSFORM },
+};
+
+CompositorProxy* CompositorProxy::create(ExecutionContext* context, Element* element, Vector<String>& attributeArray, ExceptionState& exceptionState)
esprehn 2015/03/25 23:21:48 OwnPtr, this leaks when not in Oilpan mode.
+{
+ if (!context->isDocument()) {
+ exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("CompositorProxy", "Can only be created from the main context."));
+ exceptionState.throwIfNeeded();
+ return nullptr;
+ }
+
+ uint32_t attributeFlags = 0;
+ for (const auto& attribute : attributeArray) {
+ Attributes currentAttribute = Attributes::NONE;
+ for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) {
+ if (attribute.lower() == allowedAttributes[i].name) {
esprehn 2015/03/25 23:21:48 Call .lower() first and then use std::lower_bound
sadrul 2015/03/27 17:23:28 Done.
+ currentAttribute = allowedAttributes[i].attribute;
+ }
+ }
+ if (currentAttribute == Attributes::NONE) {
+ exceptionState.throwTypeError("Unknown attribute'" + attribute + "'");
+ exceptionState.throwIfNeeded();
+ return nullptr;
+ }
+ attributeFlags |= static_cast<uint32_t>(currentAttribute);
+ }
+
+ ASSERT(attributeFlags);
esprehn 2015/03/25 23:21:48 This assert should be in the constructor?
sadrul 2015/03/27 17:23:28 Done.
+ return new CompositorProxy(element, attributeFlags);
+}
+
+CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeFlags)
+{
+ ASSERT(!isMainThread());
esprehn 2015/03/25 23:21:48 Move this assert into the constructor.
sadrul 2015/03/27 17:23:28 Done.
+#ifndef NDEBUG
+ uint32_t sanityCheckAttributes = attributeFlags;
esprehn 2015/03/25 23:21:48 This assert block for sanity checking should be in
sadrul 2015/03/27 17:23:28 Done.
+ for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) {
+ sanityCheckAttributes &= ~static_cast<uint32_t>(allowedAttributes[i].attribute);
+ }
+ ASSERT(!sanityCheckAttributes);
+#endif
+ return new CompositorProxy(elementId, attributeFlags);
+}
+
+CompositorProxy::CompositorProxy(Element* element, uint32_t attributeFlags)
esprehn 2015/03/25 23:21:48 reference
sadrul 2015/03/27 17:23:28 Done.
+ : m_elementId(InspectorNodeIds::idForNode(element))
esprehn 2015/03/25 23:21:48 We should move InspectorNodeIds into code in a fir
sadrul 2015/03/27 17:23:28 Done. (https://codereview.chromium.org/997073004/)
+ , m_attributes(attributeFlags)
+{
+ ASSERT(isMainThread());
+}
+
+CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags)
+ : m_elementId(elementId)
+ , m_attributes(attributeFlags)
+{
+}
+
+CompositorProxy::~CompositorProxy()
+{
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698