Chromium Code Reviews| 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 void DisplayItemList::beginNewPaints() | |
| 19 { | |
| 20 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | |
| 21 ASSERT(!m_newPaints.size()); | |
| 22 ASSERT(!m_doingNewPaints); | |
| 23 m_doingNewPaints = true; | |
| 24 } | |
| 25 | |
| 26 void DisplayItemList::endNewPaints() | |
| 27 { | |
| 28 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | |
| 29 ASSERT(m_doingNewPaints); | |
| 30 m_doingNewPaints = false; | |
| 31 updatePaintList(); | |
| 32 } | |
| 33 | |
| 18 const PaintList& DisplayItemList::paintList() | 34 const PaintList& DisplayItemList::paintList() |
| 19 { | 35 { |
| 20 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 36 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 21 | 37 ASSERT(!m_doingNewPaints); |
| 22 updatePaintList(); | |
| 23 return m_paintList; | 38 return m_paintList; |
| 24 } | 39 } |
| 25 | 40 |
| 26 void DisplayItemList::add(WTF::PassOwnPtr<DisplayItem> displayItem) | 41 void DisplayItemList::add(WTF::PassOwnPtr<DisplayItem> displayItem) |
| 27 { | 42 { |
| 28 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 43 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 29 m_newPaints.append(displayItem); | 44 m_newPaints.append(displayItem); |
| 30 } | 45 } |
| 31 | 46 |
| 32 void DisplayItemList::invalidate(DisplayItemClient client) | 47 void DisplayItemList::invalidate(DisplayItemClient client) |
| 33 { | 48 { |
| 34 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 49 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 35 m_cachedClients.remove(client); | 50 m_cachedClients.remove(client); |
| 36 } | 51 } |
| 37 | 52 |
| 38 void DisplayItemList::invalidateAll() | 53 void DisplayItemList::invalidateAll() |
| 39 { | 54 { |
| 40 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 55 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 41 // Can only be called during layout/paintInvalidation, not during painting. | 56 // Can only be called during layout/paintInvalidation, not during painting. |
| 42 ASSERT(m_newPaints.isEmpty()); | 57 ASSERT(!m_doingNewPaints && m_newPaints.isEmpty()); |
|
chrishtr
2015/01/20 23:18:53
Looks like m_doingNewPaints is only used in ASSERT
Xianzhu
2015/01/20 23:48:11
It was to ensure beginNewPaints() and endNewPaints
| |
| 43 m_paintList.clear(); | 58 m_paintList.clear(); |
| 44 m_cachedClients.clear(); | 59 m_cachedClients.clear(); |
| 45 } | 60 } |
| 46 | 61 |
| 62 bool DisplayItemList::clientCacheIsValid(DisplayItemClient client) const | |
| 63 { | |
| 64 return RuntimeEnabledFeatures::slimmingPaintDisplayItemCacheEnabled() && m_c achedClients.contains(client); | |
| 65 } | |
| 66 | |
| 47 PaintList::iterator DisplayItemList::findNextMatchingCachedItem(PaintList::itera tor begin, const DisplayItem& displayItem) | 67 PaintList::iterator DisplayItemList::findNextMatchingCachedItem(PaintList::itera tor begin, const DisplayItem& displayItem) |
| 48 { | 68 { |
| 49 PaintList::iterator end = m_paintList.end(); | 69 PaintList::iterator end = m_paintList.end(); |
| 50 | 70 |
| 51 if (!clientCacheIsValid(displayItem.client())) | 71 if (!clientCacheIsValid(displayItem.client())) |
| 52 return end; | 72 return end; |
| 53 | 73 |
| 54 for (PaintList::iterator it = begin; it != end; ++it) { | 74 for (PaintList::iterator it = begin; it != end; ++it) { |
| 55 DisplayItem& existing = **it; | 75 DisplayItem& existing = **it; |
| 56 if (existing.idsEqual(displayItem)) | 76 if (existing.idsEqual(displayItem)) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 67 list.append(displayItem); | 87 list.append(displayItem); |
| 68 } | 88 } |
| 69 | 89 |
| 70 // Update the existing paintList by removing invalidated entries, updating | 90 // Update the existing paintList by removing invalidated entries, updating |
| 71 // repainted ones, and appending new items. | 91 // repainted ones, and appending new items. |
| 72 // | 92 // |
| 73 // The algorithm is O(|existing paint list| + |newly painted list|): by using | 93 // 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. | 94 // the ordering implied by the existing paint list, extra treewalks are avoided. |
| 75 void DisplayItemList::updatePaintList() | 95 void DisplayItemList::updatePaintList() |
| 76 { | 96 { |
| 97 if (!RuntimeEnabledFeatures::slimmingPaintDisplayItemCacheEnabled()) { | |
| 98 m_paintList.clear(); | |
| 99 m_paintList.swap(m_newPaints); | |
| 100 m_cachedClients.clear(); | |
| 101 return; | |
| 102 } | |
| 103 | |
| 77 PaintList updatedList; | 104 PaintList updatedList; |
| 78 HashSet<DisplayItemClient> newCachedClients; | 105 HashSet<DisplayItemClient> newCachedClients; |
| 79 | 106 |
| 80 PaintList::iterator paintListIt = m_paintList.begin(); | 107 PaintList::iterator paintListIt = m_paintList.begin(); |
| 81 PaintList::iterator paintListEnd = m_paintList.end(); | 108 PaintList::iterator paintListEnd = m_paintList.end(); |
| 82 | 109 |
| 83 for (OwnPtr<DisplayItem>& newDisplayItem : m_newPaints) { | 110 for (OwnPtr<DisplayItem>& newDisplayItem : m_newPaints) { |
| 84 PaintList::iterator cachedItemIt = findNextMatchingCachedItem(paintListI t, *newDisplayItem); | 111 PaintList::iterator cachedItemIt = findNextMatchingCachedItem(paintListI t, *newDisplayItem); |
| 85 if (cachedItemIt != paintListEnd) { | 112 if (cachedItemIt != paintListEnd) { |
| 86 // Copy all of the existing items over until we hit the matching cac hed item. | 113 // 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 | 170 #endif |
| 144 | 171 |
| 145 void DisplayItemList::replay(GraphicsContext* context) | 172 void DisplayItemList::replay(GraphicsContext* context) |
| 146 { | 173 { |
| 147 updatePaintList(); | 174 updatePaintList(); |
| 148 for (auto& displayItem : m_paintList) | 175 for (auto& displayItem : m_paintList) |
| 149 displayItem->replay(context); | 176 displayItem->replay(context); |
| 150 } | 177 } |
| 151 | 178 |
| 152 } // namespace blink | 179 } // namespace blink |
| OLD | NEW |