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 "core/paint/ViewDisplayList.h" | 6 #include "core/paint/ViewDisplayList.h" |
7 | 7 |
8 #include "platform/NotImplemented.h" | 8 #include "platform/NotImplemented.h" |
9 #include "platform/RuntimeEnabledFeatures.h" | 9 #include "platform/RuntimeEnabledFeatures.h" |
10 | 10 |
11 #ifndef NDEBUG | 11 #ifndef NDEBUG |
12 #include "core/rendering/RenderObject.h" | 12 #include "core/rendering/RenderObject.h" |
13 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
14 #endif | 14 #endif |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 // DisplayItem types must be kept in sync with PaintPhase. | 18 // DisplayItem types must be kept in sync with PaintPhase. |
19 COMPILE_ASSERT((unsigned)DisplayItem::DrawingPaintPhaseBlockBackground == (unsig ned)PaintPhaseBlockBackground, DisplayItem_Type_should_stay_in_sync); | 19 COMPILE_ASSERT((unsigned)DisplayItem::DrawingPaintPhaseBlockBackground == (unsig ned)PaintPhaseBlockBackground, DisplayItem_Type_should_stay_in_sync); |
20 COMPILE_ASSERT((unsigned)DisplayItem::DrawingPaintPhaseClippingMask == (unsigned )PaintPhaseClippingMask, DisplayItem_Type_should_stay_in_sync); | 20 COMPILE_ASSERT((unsigned)DisplayItem::DrawingPaintPhaseClippingMask == (unsigned )PaintPhaseClippingMask, DisplayItem_Type_should_stay_in_sync); |
21 | 21 |
22 const PaintList& ViewDisplayList::paintList() | 22 const PaintList& ViewDisplayList::paintList() |
23 { | 23 { |
24 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 24 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
25 | 25 |
26 updatePaintList(); | 26 updatePaintList(); |
27 return m_newPaints; | 27 return m_paintList; |
28 } | 28 } |
29 | 29 |
30 void ViewDisplayList::add(WTF::PassOwnPtr<DisplayItem> displayItem) | 30 void ViewDisplayList::add(WTF::PassOwnPtr<DisplayItem> displayItem) |
31 { | 31 { |
32 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 32 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
33 m_newPaints.append(displayItem); | 33 m_newPaints.append(displayItem); |
34 } | 34 } |
35 | 35 |
36 void ViewDisplayList::invalidate(const RenderObject* renderer) | 36 void ViewDisplayList::invalidate(const RenderObject* renderer) |
37 { | 37 { |
38 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 38 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
39 m_invalidated.add(renderer); | 39 m_invalidated.add(renderer); |
40 } | 40 } |
41 | 41 |
42 bool ViewDisplayList::isRepaint(PaintList::iterator begin, const DisplayItem& di splayItem) | 42 PaintList::iterator ViewDisplayList::findDisplayItem(PaintList::iterator begin, const DisplayItem& displayItem) |
43 { | 43 { |
44 notImplemented(); | 44 PaintList::iterator end = m_paintList.end(); |
45 return false; | 45 if (displayItem.renderer() && !m_paintListRenderers.contains(displayItem.ren derer())) |
46 return end; | |
47 | |
48 for (PaintList::iterator it = begin; it != end; ++it) { | |
49 DisplayItem& existing = **it; | |
50 if (existing.idsEqual(displayItem)) | |
51 return it; | |
52 } | |
53 | |
54 // FIXME: Figure out how to handle clips. | |
55 ASSERT(!displayItem.renderer()); | |
56 return end; | |
46 } | 57 } |
47 | 58 |
48 // Update the existing paintList by removing invalidated entries, updating repai nted existing ones, and | 59 bool ViewDisplayList::wasInvalidated(const DisplayItem& displayItem) const |
leviw_travelin_and_unemployed
2014/11/03 18:04:53
FIXME: should use a bit on RenderObject.
| |
49 // appending new items. | 60 { |
61 return displayItem.renderer() && m_invalidated.contains(displayItem.renderer ()); | |
62 } | |
63 | |
64 static void appendDisplayItem(PaintList& list, HashSet<const RenderObject*>& ren derers, WTF::PassOwnPtr<DisplayItem> displayItem) | |
65 { | |
66 if (const RenderObject* renderer = displayItem->renderer()) | |
67 renderers.add(renderer); | |
68 list.append(displayItem); | |
69 } | |
70 | |
71 // Update the existing paintList by removing invalidated entries, updating | |
72 // repainted ones, and appending new items. | |
50 // | 73 // |
51 // The algorithm should be O(|existing paint list| + |newly painted list|). By u sing the ordering | 74 // The algorithm is O(|existing paint list| + |newly painted list|): by using |
52 // implied by the existing paint list, extra treewalks are avoided. | 75 // the ordering implied by the existing paint list, extra treewalks are avoided. |
53 void ViewDisplayList::updatePaintList() | 76 void ViewDisplayList::updatePaintList() |
54 { | 77 { |
55 notImplemented(); | 78 PaintList updatedList; |
79 HashSet<const RenderObject*> updatedRenderers; | |
80 | |
81 if (int maxCapacity = m_newPaints.size() + std::max(0, (int)m_paintList.size () - (int)m_invalidated.size())) | |
82 updatedList.reserveCapacity(maxCapacity); | |
83 | |
84 PaintList::iterator paintListIt = m_paintList.begin(); | |
85 PaintList::iterator paintListEnd = m_paintList.end(); | |
86 | |
87 for (OwnPtr<DisplayItem>& newDisplayItem : m_newPaints) { | |
88 if (!wasInvalidated(*newDisplayItem)) { | |
89 PaintList::iterator repaintIt = findDisplayItem(paintListIt, *newDis playItem); | |
90 if (repaintIt != paintListEnd) { | |
91 // Copy all of the existing items over until we hit the repaint. | |
92 for (; paintListIt != repaintIt; ++paintListIt) { | |
93 if (!wasInvalidated(**paintListIt)) | |
94 appendDisplayItem(updatedList, updatedRenderers, paintLi stIt->release()); | |
95 } | |
96 paintListIt++; | |
97 } | |
98 } | |
99 // Copy over the new item. | |
100 appendDisplayItem(updatedList, updatedRenderers, newDisplayItem.release( )); | |
101 } | |
102 | |
103 // Copy over any remaining items that were not invalidated. | |
104 for (; paintListIt != paintListEnd; ++paintListIt) { | |
105 if (!wasInvalidated(**paintListIt)) | |
106 appendDisplayItem(updatedList, updatedRenderers, paintListIt->releas e()); | |
107 } | |
108 | |
109 m_invalidated.clear(); | |
110 m_newPaints.clear(); | |
111 m_paintList.clear(); | |
112 m_paintList.swap(updatedList); | |
113 m_paintListRenderers.clear(); | |
114 m_paintListRenderers.swap(updatedRenderers); | |
56 } | 115 } |
57 | 116 |
58 #ifndef NDEBUG | 117 #ifndef NDEBUG |
59 WTF::String DisplayItem::typeAsDebugString(DisplayItem::Type type) | 118 WTF::String DisplayItem::typeAsDebugString(DisplayItem::Type type) |
60 { | 119 { |
61 switch (type) { | 120 switch (type) { |
62 case DisplayItem::DrawingPaintPhaseBlockBackground: return "DrawingPaintPhas eBlockBackground"; | 121 case DisplayItem::DrawingPaintPhaseBlockBackground: return "DrawingPaintPhas eBlockBackground"; |
63 case DisplayItem::DrawingPaintPhaseChildBlockBackground: return "DrawingPain tPhaseChildBlockBackground"; | 122 case DisplayItem::DrawingPaintPhaseChildBlockBackground: return "DrawingPain tPhaseChildBlockBackground"; |
64 case DisplayItem::DrawingPaintPhaseChildBlockBackgrounds: return "DrawingPai ntPhaseChildBlockBackgrounds"; | 123 case DisplayItem::DrawingPaintPhaseChildBlockBackgrounds: return "DrawingPai ntPhaseChildBlockBackgrounds"; |
65 case DisplayItem::DrawingPaintPhaseFloat: return "DrawingPaintPhaseFloat"; | 124 case DisplayItem::DrawingPaintPhaseFloat: return "DrawingPaintPhaseFloat"; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 } | 177 } |
119 | 178 |
120 void ViewDisplayList::showDebugData() const | 179 void ViewDisplayList::showDebugData() const |
121 { | 180 { |
122 fprintf(stderr, "paint list: [%s]\n", paintListAsDebugString(m_paintList).ut f8().data()); | 181 fprintf(stderr, "paint list: [%s]\n", paintListAsDebugString(m_paintList).ut f8().data()); |
123 fprintf(stderr, "new paints: [%s]\n", paintListAsDebugString(m_newPaints).ut f8().data()); | 182 fprintf(stderr, "new paints: [%s]\n", paintListAsDebugString(m_newPaints).ut f8().data()); |
124 } | 183 } |
125 #endif | 184 #endif |
126 | 185 |
127 } // namespace blink | 186 } // namespace blink |
OLD | NEW |