| OLD | NEW |
| 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/DisplayItemList.h" | 6 #include "platform/graphics/paint/DisplayItemList.h" |
| 7 | 7 |
| 8 #include "platform/NotImplemented.h" | 8 #include "platform/NotImplemented.h" |
| 9 #include "platform/RuntimeEnabledFeatures.h" | 9 #include "platform/RuntimeEnabledFeatures.h" |
| 10 #ifndef NDEBUG | 10 #ifndef NDEBUG |
| 11 #include "platform/graphics/paint/DisplayItem.h" | 11 #include "platform/graphics/paint/DisplayItem.h" |
| 12 #include "wtf/text/StringBuilder.h" | 12 #include "wtf/text/StringBuilder.h" |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 const PaintList& DisplayItemList::paintList() | 18 const PaintList& DisplayItemList::paintList() |
| 19 { | 19 { |
| 20 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 20 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 21 | 21 ASSERT(m_newPaints.isEmpty()); |
| 22 updatePaintList(); | |
| 23 return m_paintList; | 22 return m_paintList; |
| 24 } | 23 } |
| 25 | 24 |
| 26 void DisplayItemList::add(WTF::PassOwnPtr<DisplayItem> displayItem) | 25 void DisplayItemList::add(WTF::PassOwnPtr<DisplayItem> displayItem) |
| 27 { | 26 { |
| 28 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 27 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 29 m_newPaints.append(displayItem); | 28 m_newPaints.append(displayItem); |
| 30 } | 29 } |
| 31 | 30 |
| 32 void DisplayItemList::invalidate(DisplayItemClient client) | 31 void DisplayItemList::invalidate(DisplayItemClient client) |
| 33 { | 32 { |
| 34 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 33 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 35 m_cachedClients.remove(client); | 34 m_cachedClients.remove(client); |
| 36 } | 35 } |
| 37 | 36 |
| 38 void DisplayItemList::invalidateAll() | 37 void DisplayItemList::invalidateAll() |
| 39 { | 38 { |
| 40 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 39 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 41 // Can only be called during layout/paintInvalidation, not during painting. | 40 // Can only be called during layout/paintInvalidation, not during painting. |
| 42 ASSERT(m_newPaints.isEmpty()); | 41 ASSERT(m_newPaints.isEmpty()); |
| 43 m_paintList.clear(); | 42 m_paintList.clear(); |
| 44 m_cachedClients.clear(); | 43 m_cachedClients.clear(); |
| 45 } | 44 } |
| 46 | 45 |
| 46 bool DisplayItemList::clientCacheIsValid(DisplayItemClient client) const |
| 47 { |
| 48 return RuntimeEnabledFeatures::slimmingPaintDisplayItemCacheEnabled() && m_c
achedClients.contains(client); |
| 49 } |
| 50 |
| 47 PaintList::iterator DisplayItemList::findNextMatchingCachedItem(PaintList::itera
tor begin, const DisplayItem& displayItem) | 51 PaintList::iterator DisplayItemList::findNextMatchingCachedItem(PaintList::itera
tor begin, const DisplayItem& displayItem) |
| 48 { | 52 { |
| 49 PaintList::iterator end = m_paintList.end(); | 53 PaintList::iterator end = m_paintList.end(); |
| 50 | 54 |
| 51 if (!clientCacheIsValid(displayItem.client())) | 55 if (!clientCacheIsValid(displayItem.client())) |
| 52 return end; | 56 return end; |
| 53 | 57 |
| 54 for (PaintList::iterator it = begin; it != end; ++it) { | 58 for (PaintList::iterator it = begin; it != end; ++it) { |
| 55 DisplayItem& existing = **it; | 59 DisplayItem& existing = **it; |
| 56 if (existing.idsEqual(displayItem)) | 60 if (existing.idsEqual(displayItem)) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 67 list.append(displayItem); | 71 list.append(displayItem); |
| 68 } | 72 } |
| 69 | 73 |
| 70 // Update the existing paintList by removing invalidated entries, updating | 74 // Update the existing paintList by removing invalidated entries, updating |
| 71 // repainted ones, and appending new items. | 75 // repainted ones, and appending new items. |
| 72 // | 76 // |
| 73 // The algorithm is O(|existing paint list| + |newly painted list|): by using | 77 // The algorithm is O(|existing paint list| + |newly painted list|): by using |
| 74 // the ordering implied by the existing paint list, extra treewalks are avoided. | 78 // the ordering implied by the existing paint list, extra treewalks are avoided. |
| 75 void DisplayItemList::updatePaintList() | 79 void DisplayItemList::updatePaintList() |
| 76 { | 80 { |
| 81 if (!RuntimeEnabledFeatures::slimmingPaintDisplayItemCacheEnabled()) { |
| 82 m_paintList.clear(); |
| 83 m_paintList.swap(m_newPaints); |
| 84 m_cachedClients.clear(); |
| 85 return; |
| 86 } |
| 87 |
| 77 PaintList updatedList; | 88 PaintList updatedList; |
| 78 HashSet<DisplayItemClient> newCachedClients; | 89 HashSet<DisplayItemClient> newCachedClients; |
| 79 | 90 |
| 80 PaintList::iterator paintListIt = m_paintList.begin(); | 91 PaintList::iterator paintListIt = m_paintList.begin(); |
| 81 PaintList::iterator paintListEnd = m_paintList.end(); | 92 PaintList::iterator paintListEnd = m_paintList.end(); |
| 82 | 93 |
| 83 for (OwnPtr<DisplayItem>& newDisplayItem : m_newPaints) { | 94 for (OwnPtr<DisplayItem>& newDisplayItem : m_newPaints) { |
| 84 PaintList::iterator cachedItemIt = findNextMatchingCachedItem(paintListI
t, *newDisplayItem); | 95 PaintList::iterator cachedItemIt = findNextMatchingCachedItem(paintListI
t, *newDisplayItem); |
| 85 if (cachedItemIt != paintListEnd) { | 96 if (cachedItemIt != paintListEnd) { |
| 86 // Copy all of the existing items over until we hit the matching cac
hed item. | 97 // Copy all of the existing items over until we hit the matching cac
hed item. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 #endif | 154 #endif |
| 144 | 155 |
| 145 void DisplayItemList::replay(GraphicsContext* context) | 156 void DisplayItemList::replay(GraphicsContext* context) |
| 146 { | 157 { |
| 147 updatePaintList(); | 158 updatePaintList(); |
| 148 for (auto& displayItem : m_paintList) | 159 for (auto& displayItem : m_paintList) |
| 149 displayItem->replay(context); | 160 displayItem->replay(context); |
| 150 } | 161 } |
| 151 | 162 |
| 152 } // namespace blink | 163 } // namespace blink |
| OLD | NEW |