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 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 void DisplayItemList::add(WTF::PassOwnPtr<DisplayItem> displayItem) | 25 void DisplayItemList::add(WTF::PassOwnPtr<DisplayItem> displayItem) |
26 { | 26 { |
27 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 27 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
28 m_newPaints.append(displayItem); | 28 m_newPaints.append(displayItem); |
29 } | 29 } |
30 | 30 |
31 void DisplayItemList::invalidate(DisplayItemClient client) | 31 void DisplayItemList::invalidate(DisplayItemClient client) |
32 { | 32 { |
33 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 33 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
34 m_cachedClients.remove(client); | 34 // Can only be called during layout/paintInvalidation, not during painting. |
35 ASSERT(m_newPaints.isEmpty()); | |
36 m_cachedDisplayItemsInfoByClient.remove(client); | |
35 } | 37 } |
36 | 38 |
37 void DisplayItemList::invalidateAll() | 39 void DisplayItemList::invalidateAll() |
38 { | 40 { |
39 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); | 41 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); |
40 // Can only be called during layout/paintInvalidation, not during painting. | 42 // Can only be called during layout/paintInvalidation, not during painting. |
41 ASSERT(m_newPaints.isEmpty()); | 43 ASSERT(m_newPaints.isEmpty()); |
42 m_paintList.clear(); | 44 m_paintList.clear(); |
43 m_cachedClients.clear(); | 45 m_cachedDisplayItemsInfoByClient.clear(); |
44 } | 46 } |
45 | 47 |
46 bool DisplayItemList::clientCacheIsValid(DisplayItemClient client) const | 48 size_t DisplayItemList::findNextMatchingCachedItem(const DisplayItem& displayIte m) |
47 { | 49 { |
48 return RuntimeEnabledFeatures::slimmingPaintDisplayItemCacheEnabled() && m_c achedClients.contains(client); | 50 ASSERT(displayItem.isCached()); |
51 ASSERT(clientCacheIsValid(displayItem.client())); | |
52 | |
53 DisplayItemsInfo& info = m_cachedDisplayItemsInfoByClient.find(displayItem.c lient())->value; | |
54 size_t offset = info.updateOffset; | |
55 while (offset < info.displayItemIndexes.size() && !m_paintList[info.displayI temIndexes[offset]]->idsEqual(displayItem)) | |
56 ++offset; | |
57 // FIXME: We should assert index < info.displayItemIndexes.size(), but curre ntly | |
58 // our paint invalidation doesn't always invalidate all objects needing repa int. | |
59 // We should fix them before enabling the assert. crbug.com/450725. | |
60 if (offset >= info.displayItemIndexes.size()) { | |
61 // The object needed repaint but wasn't invalidated. Should remove this condition | |
62 // after we fix all invalidation issues. | |
63 return kNotFound; | |
64 } | |
65 info.updateOffset = offset + 1; | |
66 return info.displayItemIndexes[offset]; | |
49 } | 67 } |
50 | 68 |
51 PaintList::iterator DisplayItemList::findNextMatchingCachedItem(PaintList::itera tor begin, const DisplayItem& displayItem) | 69 void DisplayItemList::appendDisplayItem(PaintList& list, DisplayItemList::Displa yItemsInfoByClientMap& displayItemsInfoByClient, WTF::PassOwnPtr<DisplayItem> di splayItem) |
52 { | 70 { |
53 PaintList::iterator end = m_paintList.end(); | 71 DisplayItemsInfoByClientMap::iterator it = displayItemsInfoByClient.find(dis playItem->client()); |
54 | 72 if (it != displayItemsInfoByClient.end()) { |
55 if (!clientCacheIsValid(displayItem.client())) | 73 it->value.displayItemIndexes.append(list.size()); |
56 return end; | 74 } else { |
57 | 75 DisplayItemsInfo info; |
58 for (PaintList::iterator it = begin; it != end; ++it) { | 76 info.updateOffset = 0; |
chrishtr
2015/01/22 22:17:21
Put this in the constructor instead.
Xianzhu
2015/01/22 23:50:59
Done.
| |
59 DisplayItem& existing = **it; | 77 info.displayItemIndexes.append(list.size()); |
60 if (existing.idsEqual(displayItem)) | 78 displayItemsInfoByClient.add(displayItem->client(), info); |
61 return it; | |
62 } | 79 } |
63 | |
64 ASSERT_NOT_REACHED(); | |
65 return end; | |
66 } | |
67 | |
68 static void appendDisplayItem(PaintList& list, HashSet<DisplayItemClient>& clien ts, WTF::PassOwnPtr<DisplayItem> displayItem) | |
69 { | |
70 clients.add(displayItem->client()); | |
71 list.append(displayItem); | 80 list.append(displayItem); |
72 } | 81 } |
73 | 82 |
74 // Update the existing paintList by removing invalidated entries, updating | 83 // Update the existing paintList by removing invalidated entries, updating |
75 // repainted ones, and appending new items. | 84 // repainted ones, and appending new items. |
76 // | 85 // |
77 // The algorithm is O(|existing paint list| + |newly painted list|): by using | 86 // The algorithm is O(|existing paint list| + |newly painted list|): by using |
78 // the ordering implied by the existing paint list, extra treewalks are avoided. | 87 // the ordering implied by the existing paint list, extra treewalks are avoided. |
79 void DisplayItemList::updatePaintList() | 88 void DisplayItemList::updatePaintList() |
80 { | 89 { |
81 if (!RuntimeEnabledFeatures::slimmingPaintDisplayItemCacheEnabled()) { | |
82 m_paintList.clear(); | |
83 m_paintList.swap(m_newPaints); | |
84 m_cachedClients.clear(); | |
85 return; | |
86 } | |
87 | |
88 PaintList updatedList; | 90 PaintList updatedList; |
89 HashSet<DisplayItemClient> newCachedClients; | 91 DisplayItemsInfoByClientMap newCachedDisplayItemsInfoByClient; |
90 | |
91 PaintList::iterator paintListIt = m_paintList.begin(); | |
92 PaintList::iterator paintListEnd = m_paintList.end(); | |
93 | 92 |
94 for (OwnPtr<DisplayItem>& newDisplayItem : m_newPaints) { | 93 for (OwnPtr<DisplayItem>& newDisplayItem : m_newPaints) { |
95 PaintList::iterator cachedItemIt = findNextMatchingCachedItem(paintListI t, *newDisplayItem); | 94 if (!newDisplayItem->isCached()) { |
96 if (cachedItemIt != paintListEnd) { | 95 // Copy over the new item. |
97 // Copy all of the existing items over until we hit the matching cac hed item. | 96 appendDisplayItem(updatedList, newCachedDisplayItemsInfoByClient, ne wDisplayItem.release()); |
98 for (; paintListIt != cachedItemIt; ++paintListIt) { | 97 continue; |
99 if (clientCacheIsValid((*paintListIt)->client())) | 98 } |
100 appendDisplayItem(updatedList, newCachedClients, paintListIt ->release()); | |
101 } | |
102 | 99 |
103 // Use the cached item for the new display item. | 100 // Use the cached item for the new display item. |
104 appendDisplayItem(updatedList, newCachedClients, cachedItemIt->relea se()); | 101 size_t index = findNextMatchingCachedItem(*newDisplayItem); |
105 ++paintListIt; | 102 if (index == kNotFound) { |
106 } else { | 103 // FIXME: The object needed repaint but wasn't invalidated. Should r emove this condition |
107 // If the new display item is a cached placeholder, we should have f ound | 104 // after we fix all invalidation issues. crbug.com/450725. |
108 // the cached display item. | 105 WTF_LOG_ERROR("Object needed repaint but wasn't invalidated."); |
109 ASSERT(!newDisplayItem->isCached()); | 106 #ifndef NDEBUG |
110 | 107 WTF_LOG_ERROR("displayItem=%s", newDisplayItem->asDebugString().utf8 ().data()); |
111 // Copy over the new item. | 108 // Append the CachedDisplayItem which will visually show error indic ator. |
112 appendDisplayItem(updatedList, newCachedClients, newDisplayItem.rele ase()); | 109 appendDisplayItem(updatedList, newCachedDisplayItemsInfoByClient, ne wDisplayItem.release()); |
110 #endif | |
111 continue; | |
113 } | 112 } |
114 } | 113 appendDisplayItem(updatedList, newCachedDisplayItemsInfoByClient, m_pain tList[index].release()); |
chrishtr
2015/01/22 22:17:21
How about replacing 94-113 with:
if (newDisplayIt
Xianzhu
2015/01/22 23:50:59
Just discussed a related issue with trchen@. We no
Xianzhu
2015/01/23 23:52:45
Sorry I was wrong about your suggested code which
| |
115 | |
116 // Copy over any remaining items that are validly cached. | |
117 for (; paintListIt != paintListEnd; ++paintListIt) { | |
118 if (clientCacheIsValid((*paintListIt)->client())) | |
119 appendDisplayItem(updatedList, newCachedClients, paintListIt->releas e()); | |
120 } | 114 } |
121 | 115 |
122 m_newPaints.clear(); | 116 m_newPaints.clear(); |
123 m_paintList.clear(); | 117 m_paintList.clear(); |
124 m_paintList.swap(updatedList); | 118 m_paintList.swap(updatedList); |
125 m_cachedClients.clear(); | 119 m_cachedDisplayItemsInfoByClient.clear(); |
126 m_cachedClients.swap(newCachedClients); | 120 m_cachedDisplayItemsInfoByClient.swap(newCachedDisplayItemsInfoByClient); |
127 } | 121 } |
128 | 122 |
129 #ifndef NDEBUG | 123 #ifndef NDEBUG |
130 | 124 |
131 WTF::String DisplayItemList::paintListAsDebugString(const PaintList& list) const | 125 WTF::String DisplayItemList::paintListAsDebugString(const PaintList& list) const |
132 { | 126 { |
133 StringBuilder stringBuilder; | 127 StringBuilder stringBuilder; |
134 bool isFirst = true; | 128 for (size_t i = 0; i < list.size(); ++i) { |
135 for (auto& displayItem : list) { | 129 const OwnPtr<DisplayItem>& displayItem = list[i]; |
136 if (!isFirst) | 130 if (i) |
137 stringBuilder.append(",\n"); | 131 stringBuilder.append(",\n"); |
138 isFirst = false; | 132 if (!displayItem) { |
139 stringBuilder.append('{'); | 133 stringBuilder.append("null"); |
134 continue; | |
135 } | |
136 stringBuilder.append(String::format("{index: %d, ", (int)i)); | |
140 displayItem->dumpPropertiesAsDebugString(stringBuilder); | 137 displayItem->dumpPropertiesAsDebugString(stringBuilder); |
141 stringBuilder.append(", cacheIsValid: "); | 138 stringBuilder.append(", cacheIsValid: "); |
142 stringBuilder.append(clientCacheIsValid(displayItem->client()) ? "true" : "false"); | 139 stringBuilder.append(clientCacheIsValid(displayItem->client()) ? "true" : "false"); |
143 stringBuilder.append('}'); | 140 stringBuilder.append('}'); |
144 } | 141 } |
145 return stringBuilder.toString(); | 142 return stringBuilder.toString(); |
146 } | 143 } |
147 | 144 |
145 WTF::String DisplayItemList::cachedDisplayItemsInfoByClientAsDebugString() const | |
146 { | |
147 StringBuilder stringBuilder; | |
148 bool isFirst = true; | |
149 for (auto& item : m_cachedDisplayItemsInfoByClient) { | |
150 if (!isFirst) | |
151 stringBuilder.append(",\n"); | |
152 isFirst = false; | |
153 stringBuilder.append(String::format("{client:%p, mergeIndex:%d, displayI temIndexes:[", item.key, (int)item.value.updateOffset)); | |
chrishtr
2015/01/22 22:17:21
s/mergeIndex/updateOffset/. Or better yet, just AS
Xianzhu
2015/01/22 23:50:59
Done.
| |
154 for (size_t i = 0; i < item.value.displayItemIndexes.size(); ++i) { | |
155 if (i) | |
156 stringBuilder.append(','); | |
157 stringBuilder.append(String::format("%d", (int)item.value.displayIte mIndexes[i])); | |
158 } | |
159 stringBuilder.append("]}"); | |
160 } | |
161 return stringBuilder.toString(); | |
162 } | |
163 | |
148 void DisplayItemList::showDebugData() const | 164 void DisplayItemList::showDebugData() const |
149 { | 165 { |
150 fprintf(stderr, "paint list: [%s]\n", paintListAsDebugString(m_paintList).ut f8().data()); | 166 fprintf(stderr, "paint list: [%s]\n", paintListAsDebugString(m_paintList).ut f8().data()); |
151 fprintf(stderr, "new paints: [%s]\n", paintListAsDebugString(m_newPaints).ut f8().data()); | 167 fprintf(stderr, "new paints: [%s]\n", paintListAsDebugString(m_newPaints).ut f8().data()); |
168 fprintf(stderr, "cachedDisplayItemsInfo: [%s]\n", cachedDisplayItemsInfoByCl ientAsDebugString().utf8().data()); | |
152 } | 169 } |
153 | 170 |
154 #endif | 171 #endif // ifndef NDEBUG |
155 | 172 |
156 void DisplayItemList::replay(GraphicsContext* context) | 173 void DisplayItemList::replay(GraphicsContext* context) |
157 { | 174 { |
158 updatePaintList(); | 175 updatePaintList(); |
159 for (auto& displayItem : m_paintList) | 176 for (auto& displayItem : m_paintList) |
160 displayItem->replay(context); | 177 displayItem->replay(context); |
161 } | 178 } |
162 | 179 |
163 } // namespace blink | 180 } // namespace blink |
OLD | NEW |