OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/graphics/paint/PaintChunker.h" | 5 #include "platform/graphics/paint/PaintChunker.h" |
6 | 6 |
7 #include "platform/RuntimeEnabledFeatures.h" | 7 #include "platform/RuntimeEnabledFeatures.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 PaintChunker::PaintChunker() | 11 PaintChunker::PaintChunker() |
12 { | 12 { |
13 } | 13 } |
14 | 14 |
15 PaintChunker::~PaintChunker() | 15 PaintChunker::~PaintChunker() |
16 { | 16 { |
17 } | 17 } |
18 | 18 |
19 void PaintChunker::updateCurrentPaintChunkProperties(const PaintChunkProperties&
properties) | 19 void PaintChunker::updateCurrentPaintChunkProperties(const PaintChunk::Id* chunk
Id, const PaintChunkProperties& properties) |
20 { | 20 { |
21 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 21 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
22 | 22 |
| 23 m_currentChunkId = WTF::nullopt; |
| 24 if (chunkId) |
| 25 m_currentChunkId.emplace(*chunkId); |
23 m_currentProperties = properties; | 26 m_currentProperties = properties; |
24 } | 27 } |
25 | 28 |
26 void PaintChunker::incrementDisplayItemIndex(ItemBehavior behavior) | 29 void PaintChunker::incrementDisplayItemIndex(const DisplayItem& item) |
27 { | 30 { |
28 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 31 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
29 | 32 |
| 33 ItemBehavior behavior; |
| 34 Optional<PaintChunk::Id> newChunkId; |
| 35 if (DisplayItem::isForeignLayerType(item.getType())) { |
| 36 behavior = RequiresSeparateChunk; |
| 37 // Use null chunkId if we are skipping cache, so that the chunk will not |
| 38 // match any old chunk and will be treated as brand new. |
| 39 if (!item.skippedCache()) |
| 40 newChunkId.emplace(item.getId()); |
| 41 |
| 42 // Clear m_currentChunkId so that any display items after the foreign la
yer |
| 43 // without a new chunk id will be treated as having no id to avoid the c
hunk |
| 44 // from using the same id as the chunk before the foreign layer chunk. |
| 45 m_currentChunkId = WTF::nullopt; |
| 46 } else { |
| 47 behavior = DefaultBehavior; |
| 48 if (!item.skippedCache() && m_currentChunkId) |
| 49 newChunkId.emplace(*m_currentChunkId); |
| 50 } |
| 51 |
30 if (m_chunks.isEmpty()) { | 52 if (m_chunks.isEmpty()) { |
31 PaintChunk newChunk(0, 1, m_currentProperties); | 53 PaintChunk newChunk(0, 1, newChunkId ? &*newChunkId : nullptr, m_current
Properties); |
32 m_chunks.append(newChunk); | 54 m_chunks.append(newChunk); |
33 m_chunkBehavior.append(behavior); | 55 m_chunkBehavior.append(behavior); |
34 return; | 56 return; |
35 } | 57 } |
36 | 58 |
37 auto& lastChunk = m_chunks.last(); | 59 auto& lastChunk = m_chunks.last(); |
38 bool canContinueChunk = m_currentProperties == lastChunk.properties | 60 bool canContinueChunk = m_currentProperties == lastChunk.properties |
39 && behavior != RequiresSeparateChunk | 61 && behavior != RequiresSeparateChunk |
40 && m_chunkBehavior.last() != RequiresSeparateChunk; | 62 && m_chunkBehavior.last() != RequiresSeparateChunk; |
41 if (canContinueChunk) { | 63 if (canContinueChunk) { |
42 lastChunk.endIndex++; | 64 lastChunk.endIndex++; |
43 return; | 65 return; |
44 } | 66 } |
45 | 67 |
46 PaintChunk newChunk(lastChunk.endIndex, lastChunk.endIndex + 1, m_currentPro
perties); | 68 PaintChunk newChunk(lastChunk.endIndex, lastChunk.endIndex + 1, newChunkId ?
&*newChunkId : nullptr, m_currentProperties); |
47 m_chunks.append(newChunk); | 69 m_chunks.append(newChunk); |
48 m_chunkBehavior.append(behavior); | 70 m_chunkBehavior.append(behavior); |
49 } | 71 } |
50 | 72 |
51 void PaintChunker::decrementDisplayItemIndex() | 73 void PaintChunker::decrementDisplayItemIndex() |
52 { | 74 { |
53 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 75 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
54 ASSERT(!m_chunks.isEmpty()); | 76 ASSERT(!m_chunks.isEmpty()); |
55 | 77 |
56 auto& lastChunk = m_chunks.last(); | 78 auto& lastChunk = m_chunks.last(); |
57 if ((lastChunk.endIndex - lastChunk.beginIndex) > 1) { | 79 if ((lastChunk.endIndex - lastChunk.beginIndex) > 1) { |
58 lastChunk.endIndex--; | 80 lastChunk.endIndex--; |
59 } else { | 81 } else { |
60 m_chunks.removeLast(); | 82 m_chunks.removeLast(); |
61 m_chunkBehavior.removeLast(); | 83 m_chunkBehavior.removeLast(); |
62 } | 84 } |
63 } | 85 } |
64 | 86 |
65 void PaintChunker::clear() | 87 void PaintChunker::clear() |
66 { | 88 { |
67 m_chunks.clear(); | 89 m_chunks.clear(); |
68 m_chunkBehavior.clear(); | 90 m_chunkBehavior.clear(); |
| 91 m_currentChunkId = WTF::nullopt; |
69 m_currentProperties = PaintChunkProperties(); | 92 m_currentProperties = PaintChunkProperties(); |
70 } | 93 } |
71 | 94 |
72 Vector<PaintChunk> PaintChunker::releasePaintChunks() | 95 Vector<PaintChunk> PaintChunker::releasePaintChunks() |
73 { | 96 { |
74 Vector<PaintChunk> chunks; | 97 Vector<PaintChunk> chunks; |
75 chunks.swap(m_chunks); | 98 chunks.swap(m_chunks); |
76 m_chunkBehavior.clear(); | 99 m_chunkBehavior.clear(); |
| 100 m_currentChunkId = WTF::nullopt; |
77 m_currentProperties = PaintChunkProperties(); | 101 m_currentProperties = PaintChunkProperties(); |
78 return chunks; | 102 return chunks; |
79 } | 103 } |
80 | 104 |
81 } // namespace blink | 105 } // namespace blink |
OLD | NEW |