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

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
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/ExecutionContext.h"
11
12 namespace blink {
13
14 typedef WTF::HashMap<uint64_t, Element*> ElementMap;
15 static ElementMap* gElementMap = 0;
16
17 typedef WTF::HashMap<Element*, uint64_t> ElementIdMap;
18 static ElementIdMap* gElementIdMap = 0;
19
20 static uint64_t nextCompositorProxyId()
21 {
22 static uint64_t s_nextId = 0;
23 return ++s_nextId;
24 }
25
26 static uint64_t compositorProxyIdForElement(Element* element)
27 {
28 ASSERT(gElementIdMap);
29 if (!gElementIdMap->contains(element))
30 gElementIdMap->add(element, nextCompositorProxyId());
31 return gElementIdMap->get(element);
32 }
33
34 static struct {
35 const char* name;
36 CompositorProxy::Attributes attribute;
37 } allowedAttributes[] = {
38 { "opacity", CompositorProxy::Attributes::OPACITY },
39 { "scrolltop", CompositorProxy::Attributes::SCROLL_TOP },
40 { "touch", CompositorProxy::Attributes::TOUCH },
41 { "transform", CompositorProxy::Attributes::TRANSFORM },
42 };
43
44 CompositorProxy* CompositorProxy::create(ExecutionContext* context, Element* ele ment, Vector<String>& attributeArray, ExceptionState& exceptionState)
45 {
46 if (!context->isDocument()) {
47 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp ositorProxy", "Can only be created from the main context."));
48 exceptionState.throwIfNeeded();
49 return nullptr;
50 }
51
52 uint32_t attributeFlags = 0;
53 for (const auto& attribute : attributeArray) {
54 Attributes currentAttribute = Attributes::NONE;
55 for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) {
56 if (attribute.lower() == allowedAttributes[i].name) {
57 currentAttribute = allowedAttributes[i].attribute;
58 }
59 }
60 if (currentAttribute == Attributes::NONE) {
61 exceptionState.throwTypeError("Unknown attribute'" + attribute + "'" );
62 exceptionState.throwIfNeeded();
63 return nullptr;
64 }
65 attributeFlags |= static_cast<uint32_t>(currentAttribute);
66 }
67
68 ASSERT(attributeFlags);
69 if (!gElementMap) {
70 ASSERT(!gElementIdMap);
71 gElementMap = new ElementMap;
72 gElementIdMap = new ElementIdMap;
73 } else {
74 ASSERT(gElementIdMap);
75 }
76 return new CompositorProxy(element, attributeFlags);
77 }
78
79 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeF lags)
80 {
81 ASSERT(!isMainThread());
82 #ifndef NDEBUG
83 uint32_t sanityCheckAttributes = attributeFlags;
84 for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) {
85 sanityCheckAttributes &= ~static_cast<uint32_t>(allowedAttributes[i].att ribute);
86 }
87 ASSERT(!sanityCheckAttributes);
88 #endif
89 return new CompositorProxy(elementId, attributeFlags);
90 }
91
92 CompositorProxy::CompositorProxy(Element* element, uint32_t attributeFlags)
93 : m_elementId(compositorProxyIdForElement(element))
94 , m_attributes(attributeFlags)
95 {
96 ASSERT(isMainThread());
97 ASSERT(gElementMap);
98 gElementMap->add(m_elementId, element);
99 }
100
101 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags)
102 : m_elementId(elementId)
103 , m_attributes(attributeFlags)
104 {
105 }
106
107 CompositorProxy::~CompositorProxy()
108 {
109 }
110
111 void CompositorProxy::notifyElementGone(Element* element)
112 {
113 ASSERT(isMainThread());
114 if (!gElementMap)
115 return;
116
117 gElementMap->remove(gElementIdMap->take(element));
118 }
119
120 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698