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

Side by Side Diff: Source/core/paint/ViewDisplayList.cpp

Issue 697543002: First implementation of the paint slimming update algorithm (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address reviewer comments Created 6 years, 1 month 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 | Annotate | Revision Log
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 "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::findRepaintWithoutInvalidation(PaintList::i terator begin, const DisplayItem& displayItem)
chrishtr 2014/10/31 21:30:11 The name findRepaintWithoutInvalidation is not tha
pdr. 2014/11/01 05:23:23 Good idea. Done.
43 { 43 {
44 notImplemented(); 44 PaintList::iterator end = m_paintList.end();
45 return false; 45
46 if (wasInvalidated(displayItem))
47 return end;
48
49 if (displayItem.renderer() && !m_paintListRenderers.contains(displayItem.ren derer()))
50 return end;
51
52 for (PaintList::iterator it = begin; it != end; ++it) {
53 DisplayItem& existing = **it;
54 if (existing.idsEqual(displayItem))
55 return it;
56 }
57
58 // This should only occur for non-renderer display items.
59 // FIXME: figure out how to handle clips/etc.
60 ASSERT(!displayItem.renderer());
61 return end;
62 }
63
64 bool ViewDisplayList::wasInvalidated(const DisplayItem& displayItem) const
65 {
66 return displayItem.renderer() && m_invalidated.contains(displayItem.renderer ());
67 }
68
69 static void appendDisplayItem(PaintList& list, HashSet<const RenderObject*>& ren derers, WTF::PassOwnPtr<DisplayItem> displayItem)
70 {
71 if (RenderObject* renderer = displayItem->renderer())
72 renderers.add(renderer);
73 list.append(displayItem);
46 } 74 }
47 75
48 // Update the existing paintList by removing invalidated entries, updating repai nted existing ones, and 76 // Update the existing paintList by removing invalidated entries, updating repai nted existing ones, and
49 // appending new items. 77 // appending new items.
50 // 78 //
51 // The algorithm should be O(|existing paint list| + |newly painted list|). By u sing the ordering 79 // The algorithm should be O(|existing paint list| + |newly painted list|). By u sing the ordering
52 // implied by the existing paint list, extra treewalks are avoided. 80 // implied by the existing paint list, extra treewalks are avoided.
53 void ViewDisplayList::updatePaintList() 81 void ViewDisplayList::updatePaintList()
54 { 82 {
55 notImplemented(); 83 PaintList updatedList;
84 HashSet<const RenderObject*> updatedRenderers;
85
86 PaintList::iterator currentListIt = m_paintList.begin();
87 PaintList::iterator paintListEnd = m_paintList.end();
88 for (PaintList::iterator newIt = m_newPaints.begin(); newIt != m_newPaints.e nd(); ++newIt) {
89 PaintList::iterator repaintIt = findRepaintWithoutInvalidation(currentLi stIt, **newIt);
90 if (repaintIt != paintListEnd) {
91 // Copy all of the non-invalidated existing chunks over until we hit the repainted chunk.
92 for (; currentListIt != repaintIt; ++currentListIt) {
93 DisplayItem& displayItem = **currentListIt;
94 if (!wasInvalidated(displayItem))
95 appendDisplayItem(updatedList, updatedRenderers, currentList It->release());
96 }
97 currentListIt++;
98 }
99 // Copy over the new paint.
100 appendDisplayItem(updatedList, updatedRenderers, newIt->release());
101 }
102
103 // Copy over any remaining paints that were not invalidated.
104 for (; currentListIt != paintListEnd; ++currentListIt) {
105 if (!wasInvalidated(**currentListIt))
106 appendDisplayItem(updatedList, updatedRenderers, currentListIt->rele ase());
107 }
108
109 m_invalidated.clear();
110 m_newPaints.clear();
111 m_paintList.clear();
112 m_paintListRenderers.clear();
113 m_paintListRenderers.swap(updatedRenderers);
114 m_paintList.swap(updatedList);
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698