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

Side by Side Diff: Source/core/dom/CompositorProxy.cpp

Issue 1024233002: compositor-worker: Introduce CompositorProxy. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: ctrl-z-bitfields Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/dom/CompositorProxy.h"
7
8 #include "bindings/core/v8/ExceptionMessages.h"
9 #include "bindings/core/v8/ExceptionState.h"
10 #include "core/dom/DOMNodeIds.h"
11 #include "core/dom/ExecutionContext.h"
12
13 namespace blink {
14
15 struct AttributeFlagMapping {
16 const char* name;
17 unsigned length;
18 CompositorProxy::Attributes attribute;
19 };
20
21 static AttributeFlagMapping allowedAttributes[] = {
22 { "opacity", 7, CompositorProxy::Attributes::OPACITY },
23 { "scrollleft", 10, CompositorProxy::Attributes::SCROLL_LEFT },
24 { "scrolltop", 9, CompositorProxy::Attributes::SCROLL_TOP },
25 { "touch", 5, CompositorProxy::Attributes::TOUCH },
26 { "transform", 8, CompositorProxy::Attributes::TRANSFORM },
27 };
28
29 static bool CompareAttributeName(const AttributeFlagMapping& attribute, StringIm pl* attributeLower)
30 {
31 ASSERT(attributeLower->is8Bit());
32 return memcmp(attribute.name, attributeLower->characters8(), std::min(attrib ute.length, attributeLower->length())) < 0;
33 }
34
35 static CompositorProxy::Attributes attributeFlagForName(const String& attributeN ame)
36 {
37 CompositorProxy::Attributes attributeFlag = CompositorProxy::Attributes::NON E;
38 const String attributeLower = attributeName.lower();
39 const AttributeFlagMapping* start = allowedAttributes;
40 const AttributeFlagMapping* end = allowedAttributes + WTF_ARRAY_LENGTH(allow edAttributes);
41 if (attributeLower.impl()->is8Bit()) {
42 const AttributeFlagMapping* match = std::lower_bound(start, end, attribu teLower.impl(), CompareAttributeName);
43 if (match != end)
44 attributeFlag = match->attribute;
45 }
46 return attributeFlag;
47 }
48
49 static uint32_t attributesBitfieldFromNames(const Vector<String>& attributeArray )
50 {
51 uint32_t attributesBitfield = 0;
52 for (const auto& attribute : attributeArray) {
53 attributesBitfield |= static_cast<uint32_t>(attributeFlagForName(attribu te));
54 }
55 return attributesBitfield;
56 }
57
58 #if ENABLE(ASSERT)
59 static bool sanityCheckAttributeFlags(uint32_t attributeFlags)
60 {
61 uint32_t sanityCheckAttributes = attributeFlags;
62 for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) {
63 sanityCheckAttributes &= ~static_cast<uint32_t>(allowedAttributes[i].att ribute);
64 }
65 return !sanityCheckAttributes;
66 }
67 #endif
68
69 CompositorProxy* CompositorProxy::create(ExecutionContext* context, Element* ele ment, const Vector<String>& attributeArray, ExceptionState& exceptionState)
70 {
71 if (!context->isDocument()) {
72 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp ositorProxy", "Can only be created from the main context."));
73 exceptionState.throwIfNeeded();
74 return nullptr;
75 }
76
77 return new CompositorProxy(*element, attributeArray);
78 }
79
80 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeF lags)
81 {
82 return new CompositorProxy(elementId, attributeFlags);
83 }
84
85 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray)
86 : m_elementId(DOMNodeIds::idForNode(&element))
87 , m_bitfieldsSupported(attributesBitfieldFromNames(attributeArray))
88 {
89 ASSERT(isMainThread());
90 ASSERT(m_bitfieldsSupported);
91 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported));
92 }
93
94 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags)
95 : m_elementId(elementId)
96 , m_bitfieldsSupported(attributeFlags)
97 {
98 ASSERT(!isMainThread());
99 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported));
100 }
101
102 CompositorProxy::~CompositorProxy()
103 {
104 }
105
106 bool CompositorProxy::supports(const String& attributeName) const
107 {
108 return !!(m_bitfieldsSupported & static_cast<uint32_t>(attributeFlagForName( attributeName)));
109 }
110
111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698