OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "platform/graphics/paint/DisplayItemList.h" |
| 7 |
| 8 #include "platform/NotImplemented.h" |
| 9 #include "platform/RuntimeEnabledFeatures.h" |
| 10 #ifndef NDEBUG |
| 11 #include "platform/graphics/paint/DisplayItem.h" |
| 12 #include "wtf/text/StringBuilder.h" |
| 13 #endif |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 const PaintList& DisplayItemList::paintList() |
| 18 { |
| 19 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 20 |
| 21 updatePaintList(); |
| 22 return m_paintList; |
| 23 } |
| 24 |
| 25 void DisplayItemList::add(WTF::PassOwnPtr<DisplayItem> displayItem) |
| 26 { |
| 27 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 28 m_newPaints.append(displayItem); |
| 29 } |
| 30 |
| 31 void DisplayItemList::invalidate(DisplayItemClient renderer) |
| 32 { |
| 33 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
| 34 m_invalidated.add(renderer); |
| 35 } |
| 36 |
| 37 PaintList::iterator DisplayItemList::findDisplayItem(PaintList::iterator begin,
const DisplayItem& displayItem) |
| 38 { |
| 39 PaintList::iterator end = m_paintList.end(); |
| 40 if (displayItem.client() && !m_paintListRenderers.contains(displayItem.clien
t())) |
| 41 return end; |
| 42 |
| 43 for (PaintList::iterator it = begin; it != end; ++it) { |
| 44 DisplayItem& existing = **it; |
| 45 if (existing.idsEqual(displayItem)) |
| 46 return it; |
| 47 } |
| 48 |
| 49 // FIXME: Properly handle clips. |
| 50 ASSERT(!displayItem.client()); |
| 51 return end; |
| 52 } |
| 53 |
| 54 bool DisplayItemList::wasInvalidated(const DisplayItem& displayItem) const |
| 55 { |
| 56 // FIXME: Use a bit on DisplayItemClient instead of tracking m_invalidated. |
| 57 return displayItem.client() && m_invalidated.contains(displayItem.client()); |
| 58 } |
| 59 |
| 60 static void appendDisplayItem(PaintList& list, HashSet<DisplayItemClient>& rende
rers, WTF::PassOwnPtr<DisplayItem> displayItem) |
| 61 { |
| 62 if (DisplayItemClient renderer = displayItem->client()) |
| 63 renderers.add(renderer); |
| 64 list.append(displayItem); |
| 65 } |
| 66 |
| 67 // Update the existing paintList by removing invalidated entries, updating |
| 68 // repainted ones, and appending new items. |
| 69 // |
| 70 // The algorithm is O(|existing paint list| + |newly painted list|): by using |
| 71 // the ordering implied by the existing paint list, extra treewalks are avoided. |
| 72 void DisplayItemList::updatePaintList() |
| 73 { |
| 74 PaintList updatedList; |
| 75 HashSet<DisplayItemClient> updatedRenderers; |
| 76 |
| 77 if (int maxCapacity = m_newPaints.size() + std::max(0, (int)m_paintList.size
() - (int)m_invalidated.size())) |
| 78 updatedList.reserveCapacity(maxCapacity); |
| 79 |
| 80 PaintList::iterator paintListIt = m_paintList.begin(); |
| 81 PaintList::iterator paintListEnd = m_paintList.end(); |
| 82 |
| 83 for (OwnPtr<DisplayItem>& newDisplayItem : m_newPaints) { |
| 84 if (!wasInvalidated(*newDisplayItem)) { |
| 85 PaintList::iterator repaintIt = findDisplayItem(paintListIt, *newDis
playItem); |
| 86 if (repaintIt != paintListEnd) { |
| 87 // Copy all of the existing items over until we hit the repaint. |
| 88 for (; paintListIt != repaintIt; ++paintListIt) { |
| 89 if (!wasInvalidated(**paintListIt)) |
| 90 appendDisplayItem(updatedList, updatedRenderers, paintLi
stIt->release()); |
| 91 } |
| 92 paintListIt++; |
| 93 } |
| 94 } |
| 95 // Copy over the new item. |
| 96 appendDisplayItem(updatedList, updatedRenderers, newDisplayItem.release(
)); |
| 97 } |
| 98 |
| 99 // Copy over any remaining items that were not invalidated. |
| 100 for (; paintListIt != paintListEnd; ++paintListIt) { |
| 101 if (!wasInvalidated(**paintListIt)) |
| 102 appendDisplayItem(updatedList, updatedRenderers, paintListIt->releas
e()); |
| 103 } |
| 104 |
| 105 m_invalidated.clear(); |
| 106 m_newPaints.clear(); |
| 107 m_paintList.clear(); |
| 108 m_paintList.swap(updatedList); |
| 109 m_paintListRenderers.clear(); |
| 110 m_paintListRenderers.swap(updatedRenderers); |
| 111 } |
| 112 |
| 113 #ifndef NDEBUG |
| 114 |
| 115 static WTF::String paintListAsDebugString(const PaintList& list) |
| 116 { |
| 117 StringBuilder stringBuilder; |
| 118 bool isFirst = true; |
| 119 for (auto& displayItem : list) { |
| 120 if (!isFirst) |
| 121 stringBuilder.append(", "); |
| 122 isFirst = false; |
| 123 stringBuilder.append(displayItem->asDebugString()); |
| 124 } |
| 125 return stringBuilder.toString(); |
| 126 } |
| 127 |
| 128 void DisplayItemList::showDebugData() const |
| 129 { |
| 130 fprintf(stderr, "paint list: [%s]\n", paintListAsDebugString(m_paintList).ut
f8().data()); |
| 131 fprintf(stderr, "new paints: [%s]\n", paintListAsDebugString(m_newPaints).ut
f8().data()); |
| 132 } |
| 133 |
| 134 #endif |
| 135 |
| 136 } // namespace blink |
OLD | NEW |