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

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: . 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/CompositorProxy.h ('k') | Source/core/dom/CompositorProxy.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 CompositorProxy::AttributesBitfield attributesBitfieldFromNames(const Vec tor<String>& attributeArray)
50 {
51 CompositorProxy::AttributesBitfield attributesBitfield(0);
52 for (const auto& attribute : attributeArray) {
53 switch (attributeFlagForName(attribute)) {
54 case CompositorProxy::Attributes::OPACITY:
55 attributesBitfield.m_attributes.m_opacity = true;
esprehn 2015/03/27 23:48:42 Hmm this is a bit worse I guess since you need all
sadrul 2015/03/28 02:12:39 Done.
56 break;
57 case CompositorProxy::Attributes::SCROLL_LEFT:
58 attributesBitfield.m_attributes.m_scrollLeft = true;
59 break;
60 case CompositorProxy::Attributes::SCROLL_TOP:
61 attributesBitfield.m_attributes.m_scrollTop = true;
62 break;
63 case CompositorProxy::Attributes::TOUCH:
64 attributesBitfield.m_attributes.m_touch = true;
65 break;
66 case CompositorProxy::Attributes::TRANSFORM:
67 attributesBitfield.m_attributes.m_transform = true;
68 break;
69 case CompositorProxy::Attributes::NONE:
70 break;
71 }
72 }
73 return attributesBitfield;
74 }
75
76 #if ENABLE(ASSERT)
77 static bool sanityCheckAttributeFlags(uint32_t attributeFlags)
78 {
79 uint32_t sanityCheckAttributes = attributeFlags;
80 for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) {
81 sanityCheckAttributes &= ~static_cast<uint32_t>(allowedAttributes[i].att ribute);
82 }
83 return !sanityCheckAttributes;
84 }
85 #endif
86
87 CompositorProxy* CompositorProxy::create(ExecutionContext* context, Element* ele ment, const Vector<String>& attributeArray, ExceptionState& exceptionState)
88 {
89 if (!context->isDocument()) {
90 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp ositorProxy", "Can only be created from the main context."));
91 exceptionState.throwIfNeeded();
92 return nullptr;
93 }
94
95 return new CompositorProxy(*element, attributeArray);
96 }
97
98 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeF lags)
99 {
100 return new CompositorProxy(elementId, attributeFlags);
101 }
102
103 CompositorProxy::CompositorProxy(Element& element, const Vector<String>& attribu teArray)
104 : m_elementId(DOMNodeIds::idForNode(&element))
105 , m_bitfieldsSupported(attributesBitfieldFromNames(attributeArray))
106 {
107 ASSERT(isMainThread());
108 ASSERT(m_bitfieldsSupported.m_flags);
109 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported.m_flags));
110 }
111
112 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags)
113 : m_elementId(elementId)
114 , m_bitfieldsSupported(attributeFlags)
115 {
116 ASSERT(!isMainThread());
117 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported.m_flags));
118 }
119
120 CompositorProxy::~CompositorProxy()
121 {
122 }
123
124 bool CompositorProxy::supports(const String& attributeName) const
125 {
126 switch (attributeFlagForName(attributeName)) {
127 case CompositorProxy::Attributes::OPACITY:
128 return m_bitfieldsSupported.m_attributes.m_opacity;
129 case CompositorProxy::Attributes::SCROLL_LEFT:
130 return m_bitfieldsSupported.m_attributes.m_scrollLeft;
131 case CompositorProxy::Attributes::SCROLL_TOP:
132 return m_bitfieldsSupported.m_attributes.m_scrollTop;
133 case CompositorProxy::Attributes::TOUCH:
134 return m_bitfieldsSupported.m_attributes.m_touch;
135 case CompositorProxy::Attributes::TRANSFORM:
136 return m_bitfieldsSupported.m_attributes.m_transform;
137 case CompositorProxy::Attributes::NONE:
138 break;
139 }
140 return false;
141 }
142
143 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/CompositorProxy.h ('k') | Source/core/dom/CompositorProxy.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698