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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/PaintController.cpp

Issue 1497873002: Make DisplayItemClient an interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile Created 5 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "platform/graphics/paint/PaintController.h" 6 #include "platform/graphics/paint/PaintController.h"
7 7
8 #include "platform/NotImplemented.h" 8 #include "platform/NotImplemented.h"
9 #include "platform/TraceEvent.h" 9 #include "platform/TraceEvent.h"
10 #include "platform/graphics/GraphicsLayer.h" 10 #include "platform/graphics/GraphicsLayer.h"
(...skipping 23 matching lines...) Expand all
34 return lastDisplayItem.isBegin() && !lastDisplayItem.drawsContent(); 34 return lastDisplayItem.isBegin() && !lastDisplayItem.drawsContent();
35 } 35 }
36 36
37 void PaintController::removeLastDisplayItem() 37 void PaintController::removeLastDisplayItem()
38 { 38 {
39 if (m_newDisplayItemList.isEmpty()) 39 if (m_newDisplayItemList.isEmpty())
40 return; 40 return;
41 41
42 #if ENABLE(ASSERT) 42 #if ENABLE(ASSERT)
43 // Also remove the index pointing to the removed display item. 43 // Also remove the index pointing to the removed display item.
44 DisplayItemIndicesByClientMap::iterator it = m_newDisplayItemIndicesByClient .find(m_newDisplayItemList.last().client()); 44 DisplayItemIndicesByClientMap::iterator it = m_newDisplayItemIndicesByClient .find(&m_newDisplayItemList.last().client());
45 if (it != m_newDisplayItemIndicesByClient.end()) { 45 if (it != m_newDisplayItemIndicesByClient.end()) {
46 Vector<size_t>& indices = it->value; 46 Vector<size_t>& indices = it->value;
47 if (!indices.isEmpty() && indices.last() == (m_newDisplayItemList.size() - 1)) 47 if (!indices.isEmpty() && indices.last() == (m_newDisplayItemList.size() - 1))
48 indices.removeLast(); 48 indices.removeLast();
49 } 49 }
50 #endif 50 #endif
51 m_newDisplayItemList.removeLast(); 51 m_newDisplayItemList.removeLast();
52 52
53 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 53 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
54 m_newPaintChunks.decrementDisplayItemIndex(); 54 m_newPaintChunks.decrementDisplayItemIndex();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 m_scopeStack.append(m_nextScope++); 110 m_scopeStack.append(m_nextScope++);
111 beginSkippingCache(); 111 beginSkippingCache();
112 } 112 }
113 113
114 void PaintController::endScope() 114 void PaintController::endScope()
115 { 115 {
116 m_scopeStack.removeLast(); 116 m_scopeStack.removeLast();
117 endSkippingCache(); 117 endSkippingCache();
118 } 118 }
119 119
120 void PaintController::invalidate(const DisplayItemClientWrapper& client, PaintIn validationReason paintInvalidationReason, const IntRect* visualRect) 120 void PaintController::invalidate(const DisplayItemClient& client, PaintInvalidat ionReason paintInvalidationReason, const IntRect* visualRect)
121 { 121 {
122 invalidateClient(client); 122 invalidateClient(client);
123 123
124 if (visualRect) { 124 if (visualRect) {
125 // TODO(wkorman): cache visualRect for the client. 125 // TODO(wkorman): cache visualRect for the client.
126 } 126 }
127 } 127 }
128 128
129 void PaintController::invalidateClient(const DisplayItemClientWrapper& client) 129 void PaintController::invalidateClient(const DisplayItemClient& client)
130 { 130 {
131 #if ENABLE(ASSERT) 131 #if ENABLE(ASSERT)
132 // Slimming paint v1 CompositedLayerMapping may invalidate client on extra l ayers. 132 // Slimming paint v1 CompositedLayerMapping may invalidate client on extra l ayers.
133 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() || clientCacheIsValid(c lient.displayItemClient())) 133 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() || clientCacheIsValid(c lient))
134 m_invalidations.append(client.debugName()); 134 m_invalidations.append(client.debugName());
135 #endif 135 #endif
136 136
137 invalidateUntracked(client.displayItemClient()); 137 invalidateUntracked(client);
138 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && m_trackedPaintInvali dationObjects) 138 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && m_trackedPaintInvali dationObjects)
139 m_trackedPaintInvalidationObjects->append(client.debugName()); 139 m_trackedPaintInvalidationObjects->append(client.debugName());
140 } 140 }
141 141
142 void PaintController::invalidateUntracked(DisplayItemClient client) 142 void PaintController::invalidateUntracked(const DisplayItemClient& client)
143 { 143 {
144 // This can be called during painting, but we can't invalidate already paint ed clients. 144 // This can be called during painting, but we can't invalidate already paint ed clients.
145 ASSERT(!m_newDisplayItemIndicesByClient.contains(client)); 145 ASSERT(!m_newDisplayItemIndicesByClient.contains(&client));
146 updateValidlyCachedClientsIfNeeded(); 146 updateValidlyCachedClientsIfNeeded();
147 m_validlyCachedClients.remove(client); 147 m_validlyCachedClients.remove(&client);
148 } 148 }
149 149
150 void PaintController::invalidateAll() 150 void PaintController::invalidateAll()
151 { 151 {
152 // Can only be called during layout/paintInvalidation, not during painting. 152 // Can only be called during layout/paintInvalidation, not during painting.
153 ASSERT(m_newDisplayItemList.isEmpty()); 153 ASSERT(m_newDisplayItemList.isEmpty());
154 m_currentPaintArtifact.reset(); 154 m_currentPaintArtifact.reset();
155 m_validlyCachedClients.clear(); 155 m_validlyCachedClients.clear();
156 m_validlyCachedClientsDirty = false; 156 m_validlyCachedClientsDirty = false;
157 157
158 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && m_trackedPaintInvali dationObjects) 158 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && m_trackedPaintInvali dationObjects)
159 m_trackedPaintInvalidationObjects->append("##ALL##"); 159 m_trackedPaintInvalidationObjects->append("##ALL##");
160 } 160 }
161 161
162 bool PaintController::clientCacheIsValid(DisplayItemClient client) const 162 bool PaintController::clientCacheIsValid(const DisplayItemClient& client) const
163 { 163 {
164 if (skippingCache()) 164 if (skippingCache())
165 return false; 165 return false;
166 updateValidlyCachedClientsIfNeeded(); 166 updateValidlyCachedClientsIfNeeded();
167 return m_validlyCachedClients.contains(client); 167 return m_validlyCachedClients.contains(&client);
168 } 168 }
169 169
170 void PaintController::invalidatePaintOffset(const DisplayItemClientWrapper& clie nt) 170 void PaintController::invalidatePaintOffset(const DisplayItemClient& client)
171 { 171 {
172 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()); 172 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled());
173 invalidateClient(client); 173 invalidateClient(client);
174 174
175 #if ENABLE(ASSERT) 175 #if ENABLE(ASSERT)
176 ASSERT(!paintOffsetWasInvalidated(client.displayItemClient())); 176 ASSERT(!paintOffsetWasInvalidated(client));
177 m_clientsWithPaintOffsetInvalidations.add(client.displayItemClient()); 177 m_clientsWithPaintOffsetInvalidations.add(&client);
178 #endif 178 #endif
179 } 179 }
180 180
181 #if ENABLE(ASSERT) 181 #if ENABLE(ASSERT)
182 bool PaintController::paintOffsetWasInvalidated(DisplayItemClient client) const 182 bool PaintController::paintOffsetWasInvalidated(const DisplayItemClient& client) const
183 { 183 {
184 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()); 184 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled());
185 return m_clientsWithPaintOffsetInvalidations.contains(client); 185 return m_clientsWithPaintOffsetInvalidations.contains(&client);
186 } 186 }
187 #endif 187 #endif
188 188
189 size_t PaintController::findMatchingItemFromIndex(const DisplayItem::Id& id, con st DisplayItemIndicesByClientMap& displayItemIndicesByClient, const DisplayItemL ist& list) 189 size_t PaintController::findMatchingItemFromIndex(const DisplayItem::Id& id, con st DisplayItemIndicesByClientMap& displayItemIndicesByClient, const DisplayItemL ist& list)
190 { 190 {
191 DisplayItemIndicesByClientMap::const_iterator it = displayItemIndicesByClien t.find(id.client); 191 DisplayItemIndicesByClientMap::const_iterator it = displayItemIndicesByClien t.find(&id.client);
192 if (it == displayItemIndicesByClient.end()) 192 if (it == displayItemIndicesByClient.end())
193 return kNotFound; 193 return kNotFound;
194 194
195 const Vector<size_t>& indices = it->value; 195 const Vector<size_t>& indices = it->value;
196 for (size_t index : indices) { 196 for (size_t index : indices) {
197 const DisplayItem& existingItem = list[index]; 197 const DisplayItem& existingItem = list[index];
198 ASSERT(!existingItem.isValid() || existingItem.client() == id.client); 198 ASSERT(!existingItem.isValid() || existingItem.client() == id.client);
199 if (existingItem.isValid() && id.matches(existingItem)) 199 if (existingItem.isValid() && id.matches(existingItem))
200 return index; 200 return index;
201 } 201 }
202 202
203 return kNotFound; 203 return kNotFound;
204 } 204 }
205 205
206 void PaintController::addItemToIndexIfNeeded(const DisplayItem& displayItem, siz e_t index, DisplayItemIndicesByClientMap& displayItemIndicesByClient) 206 void PaintController::addItemToIndexIfNeeded(const DisplayItem& displayItem, siz e_t index, DisplayItemIndicesByClientMap& displayItemIndicesByClient)
207 { 207 {
208 if (!displayItem.isCacheable()) 208 if (!displayItem.isCacheable())
209 return; 209 return;
210 210
211 DisplayItemIndicesByClientMap::iterator it = displayItemIndicesByClient.find (displayItem.client()); 211 DisplayItemIndicesByClientMap::iterator it = displayItemIndicesByClient.find (&displayItem.client());
212 Vector<size_t>& indices = it == displayItemIndicesByClient.end() ? 212 Vector<size_t>& indices = it == displayItemIndicesByClient.end() ?
213 displayItemIndicesByClient.add(displayItem.client(), Vector<size_t>()).s toredValue->value : it->value; 213 displayItemIndicesByClient.add(&displayItem.client(), Vector<size_t>()). storedValue->value : it->value;
214 indices.append(index); 214 indices.append(index);
215 } 215 }
216 216
217 struct PaintController::OutOfOrderIndexContext { 217 struct PaintController::OutOfOrderIndexContext {
218 STACK_ALLOCATED(); 218 STACK_ALLOCATED();
219 OutOfOrderIndexContext(DisplayItemList::iterator begin) : nextItemToIndex(be gin) { } 219 OutOfOrderIndexContext(DisplayItemList::iterator begin) : nextItemToIndex(be gin) { }
220 220
221 DisplayItemList::iterator nextItemToIndex; 221 DisplayItemList::iterator nextItemToIndex;
222 DisplayItemIndicesByClientMap displayItemIndicesByClient; 222 DisplayItemIndicesByClientMap displayItemIndicesByClient;
223 }; 223 };
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 } 428 }
429 429
430 void PaintController::updateValidlyCachedClientsIfNeeded() const 430 void PaintController::updateValidlyCachedClientsIfNeeded() const
431 { 431 {
432 if (!m_validlyCachedClientsDirty) 432 if (!m_validlyCachedClientsDirty)
433 return; 433 return;
434 434
435 m_validlyCachedClients.clear(); 435 m_validlyCachedClients.clear();
436 m_validlyCachedClientsDirty = false; 436 m_validlyCachedClientsDirty = false;
437 437
438 DisplayItemClient lastAddedClient = nullptr; 438 const DisplayItemClient* lastAddedClient = nullptr;
439 for (const DisplayItem& displayItem : m_currentPaintArtifact.displayItemList ()) { 439 for (const DisplayItem& displayItem : m_currentPaintArtifact.displayItemList ()) {
440 if (displayItem.client() == lastAddedClient) 440 if (&displayItem.client() == lastAddedClient)
441 continue; 441 continue;
442 if (displayItem.isCacheable()) { 442 if (displayItem.isCacheable()) {
443 lastAddedClient = displayItem.client(); 443 lastAddedClient = &displayItem.client();
444 m_validlyCachedClients.add(lastAddedClient); 444 m_validlyCachedClients.add(lastAddedClient);
445 } 445 }
446 } 446 }
447 } 447 }
448 448
449 #if ENABLE(ASSERT) 449 #if ENABLE(ASSERT)
450 450
451 void PaintController::checkUnderInvalidation(DisplayItemList::iterator& newIt, D isplayItemList::iterator& currentIt) 451 void PaintController::checkUnderInvalidation(DisplayItemList::iterator& newIt, D isplayItemList::iterator& currentIt)
452 { 452 {
453 ASSERT(RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled ()); 453 ASSERT(RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled ());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 { 502 {
503 ASSERT(RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled ()); 503 ASSERT(RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled ());
504 ASSERT(!newItem.isCached()); 504 ASSERT(!newItem.isCached());
505 ASSERT(!oldItem.isCached()); 505 ASSERT(!oldItem.isCached());
506 506
507 if (newItem.skippedCache()) { 507 if (newItem.skippedCache()) {
508 showUnderInvalidationError(messagePrefix, "ERROR: under-invalidation: sk ipped-cache in cached subsequence", &newItem, &oldItem); 508 showUnderInvalidationError(messagePrefix, "ERROR: under-invalidation: sk ipped-cache in cached subsequence", &newItem, &oldItem);
509 ASSERT_NOT_REACHED(); 509 ASSERT_NOT_REACHED();
510 } 510 }
511 511
512 if (newItem.isCacheable() && !m_validlyCachedClients.contains(newItem.client ())) { 512 if (newItem.isCacheable() && !m_validlyCachedClients.contains(&newItem.clien t())) {
513 showUnderInvalidationError(messagePrefix, "ERROR: under-invalidation: in validated in cached subsequence", &newItem, &oldItem); 513 showUnderInvalidationError(messagePrefix, "ERROR: under-invalidation: in validated in cached subsequence", &newItem, &oldItem);
514 ASSERT_NOT_REACHED(); 514 ASSERT_NOT_REACHED();
515 } 515 }
516 516
517 if (newItem.equals(oldItem)) 517 if (newItem.equals(oldItem))
518 return; 518 return;
519 519
520 showUnderInvalidationError(messagePrefix, "ERROR: under-invalidation: displa y item changed", &newItem, &oldItem); 520 showUnderInvalidationError(messagePrefix, "ERROR: under-invalidation: displa y item changed", &newItem, &oldItem);
521 521
522 #ifndef NDEBUG 522 #ifndef NDEBUG
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 569
570 void PaintController::showDebugData() const 570 void PaintController::showDebugData() const
571 { 571 {
572 WTFLogAlways("current display item list: [%s]\n", displayItemListAsDebugStri ng(m_currentPaintArtifact.displayItemList()).utf8().data()); 572 WTFLogAlways("current display item list: [%s]\n", displayItemListAsDebugStri ng(m_currentPaintArtifact.displayItemList()).utf8().data());
573 WTFLogAlways("new display item list: [%s]\n", displayItemListAsDebugString(m _newDisplayItemList).utf8().data()); 573 WTFLogAlways("new display item list: [%s]\n", displayItemListAsDebugString(m _newDisplayItemList).utf8().data());
574 } 574 }
575 575
576 #endif // ifndef NDEBUG 576 #endif // ifndef NDEBUG
577 577
578 } // namespace blink 578 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698