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

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

Issue 1025893002: compositor-worker: Add mutable attributes to CompositorProxy. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . 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
« 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/dom/CompositorProxy.h" 6 #include "core/dom/CompositorProxy.h"
7 7
8 #include "bindings/core/v8/ExceptionMessages.h" 8 #include "bindings/core/v8/ExceptionMessages.h"
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "core/dom/DOMNodeIds.h" 10 #include "core/dom/DOMNodeIds.h"
11 #include "core/dom/ExceptionCode.h"
11 #include "core/dom/ExecutionContext.h" 12 #include "core/dom/ExecutionContext.h"
12 13
13 namespace blink { 14 namespace blink {
14 15
15 struct AttributeFlagMapping { 16 struct AttributeFlagMapping {
16 const char* name; 17 const char* name;
17 unsigned length; 18 unsigned length;
18 CompositorProxy::Attributes attribute; 19 CompositorProxy::Attributes attribute;
19 }; 20 };
20 21
(...skipping 18 matching lines...) Expand all
39 const AttributeFlagMapping* start = allowedAttributes; 40 const AttributeFlagMapping* start = allowedAttributes;
40 const AttributeFlagMapping* end = allowedAttributes + WTF_ARRAY_LENGTH(allow edAttributes); 41 const AttributeFlagMapping* end = allowedAttributes + WTF_ARRAY_LENGTH(allow edAttributes);
41 if (attributeLower.impl()->is8Bit()) { 42 if (attributeLower.impl()->is8Bit()) {
42 const AttributeFlagMapping* match = std::lower_bound(start, end, attribu teLower.impl(), CompareAttributeName); 43 const AttributeFlagMapping* match = std::lower_bound(start, end, attribu teLower.impl(), CompareAttributeName);
43 if (match != end) 44 if (match != end)
44 attributeFlag = match->attribute; 45 attributeFlag = match->attribute;
45 } 46 }
46 return attributeFlag; 47 return attributeFlag;
47 } 48 }
48 49
50 static bool isControlThread()
51 {
52 return !isMainThread();
53 }
54
55 static bool isCallingCompositorFrameCallback()
56 {
57 // TODO(sad): Check that the requestCompositorFrame callbacks are currently being called.
58 return true;
59 }
60
61 static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState)
62 {
63 if (!isControlThread()) {
64 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut ate a proxy attribute from the main page.");
65 return true;
66 }
67 if (!isCallingCompositorFrameCallback()) {
68 exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mut ate a proxy attribute outside of a requestCompositorFrame callback.");
69 return true;
70 }
71 return false;
72 }
73
49 static uint32_t attributesBitfieldFromNames(const Vector<String>& attributeArray ) 74 static uint32_t attributesBitfieldFromNames(const Vector<String>& attributeArray )
50 { 75 {
51 uint32_t attributesBitfield = 0; 76 uint32_t attributesBitfield = 0;
52 for (const auto& attribute : attributeArray) { 77 for (const auto& attribute : attributeArray) {
53 attributesBitfield |= static_cast<uint32_t>(attributeFlagForName(attribu te)); 78 attributesBitfield |= static_cast<uint32_t>(attributeFlagForName(attribu te));
54 } 79 }
55 return attributesBitfield; 80 return attributesBitfield;
56 } 81 }
57 82
58 #if ENABLE(ASSERT) 83 #if ENABLE(ASSERT)
(...skipping 29 matching lines...) Expand all
88 { 113 {
89 ASSERT(isMainThread()); 114 ASSERT(isMainThread());
90 ASSERT(m_bitfieldsSupported); 115 ASSERT(m_bitfieldsSupported);
91 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); 116 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported));
92 } 117 }
93 118
94 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags) 119 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags)
95 : m_elementId(elementId) 120 : m_elementId(elementId)
96 , m_bitfieldsSupported(attributeFlags) 121 , m_bitfieldsSupported(attributeFlags)
97 { 122 {
98 ASSERT(!isMainThread()); 123 ASSERT(isControlThread());
99 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported)); 124 ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported));
100 } 125 }
101 126
102 CompositorProxy::~CompositorProxy() 127 CompositorProxy::~CompositorProxy()
103 { 128 {
104 } 129 }
105 130
106 bool CompositorProxy::supports(const String& attributeName) const 131 bool CompositorProxy::supports(const String& attributeName) const
107 { 132 {
108 return !!(m_bitfieldsSupported & static_cast<uint32_t>(attributeFlagForName( attributeName))); 133 return !!(m_bitfieldsSupported & static_cast<uint32_t>(attributeFlagForName( attributeName)));
109 } 134 }
110 135
136 double CompositorProxy::opacity(ExceptionState& exceptionState) const
137 {
138 if (raiseExceptionIfMutationNotAllowed(exceptionState))
139 return 0.0;
140 if (raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState))
141 return 0.0;
142 return m_opacity;
143 }
144
145 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const
146 {
147 if (raiseExceptionIfMutationNotAllowed(exceptionState))
148 return 0.0;
149 if (raiseExceptionIfNotMutable(Attributes::SCROLL_LEFT, exceptionState))
150 return 0.0;
151 return m_scrollLeft;
152 }
153
154 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const
155 {
156 if (raiseExceptionIfMutationNotAllowed(exceptionState))
157 return 0.0;
158 if (raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionState))
159 return 0.0;
160 return m_scrollTop;
161 }
162
163 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const
164 {
165 if (raiseExceptionIfMutationNotAllowed(exceptionState))
166 return nullptr;
167 if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState))
168 return nullptr;
169 return m_transform;
170 }
171
172 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState)
173 {
174 if (raiseExceptionIfMutationNotAllowed(exceptionState))
175 return;
176 if (raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState))
177 return;
178 m_opacity = std::min(1., std::max(0., opacity));
179 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::OPACITY);
180 }
181
182 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception State)
183 {
184 if (raiseExceptionIfMutationNotAllowed(exceptionState))
185 return;
186 if (raiseExceptionIfNotMutable(Attributes::SCROLL_LEFT, exceptionState))
187 return;
188 m_scrollLeft = scrollLeft;
189 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_LEFT);
190 }
191
192 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt ate)
193 {
194 if (raiseExceptionIfMutationNotAllowed(exceptionState))
195 return;
196 if (raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionState))
197 return;
198 m_scrollTop = scrollTop;
199 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_TOP);
200 }
201
202 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti onState)
203 {
204 if (raiseExceptionIfMutationNotAllowed(exceptionState))
205 return;
206 if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState))
207 return;
208 m_transform = transform;
209 m_mutatedAttributes |= static_cast<uint32_t>(Attributes::TRANSFORM);
210 }
211
212 bool CompositorProxy::raiseExceptionIfNotMutable(Attributes attribute, Exception State& exceptionState) const
213 {
214 if (m_bitfieldsSupported & static_cast<uint32_t>(attribute))
215 return false;
216 exceptionState.throwDOMException(NoModificationAllowedError, "Attempted to m utate non-mutable attribute.");
217 return true;
218 }
219
111 } // namespace blink 220 } // 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