| 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 PaintChunk::Id* chunk
Id, const PaintChunkProperties& properties) | 19 void PaintChunker::updateCurrentPaintChunkProperties(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); | |
| 26 m_currentProperties = properties; | 23 m_currentProperties = properties; |
| 27 } | 24 } |
| 28 | 25 |
| 29 void PaintChunker::incrementDisplayItemIndex(const DisplayItem& item) | 26 void PaintChunker::incrementDisplayItemIndex(ItemBehavior behavior) |
| 30 { | 27 { |
| 31 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 28 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
| 32 | 29 |
| 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 | |
| 52 if (m_chunks.isEmpty()) { | 30 if (m_chunks.isEmpty()) { |
| 53 PaintChunk newChunk(0, 1, newChunkId ? &*newChunkId : nullptr, m_current
Properties); | 31 PaintChunk newChunk(0, 1, m_currentProperties); |
| 54 m_chunks.append(newChunk); | 32 m_chunks.append(newChunk); |
| 55 m_chunkBehavior.append(behavior); | 33 m_chunkBehavior.append(behavior); |
| 56 return; | 34 return; |
| 57 } | 35 } |
| 58 | 36 |
| 59 auto& lastChunk = m_chunks.last(); | 37 auto& lastChunk = m_chunks.last(); |
| 60 bool canContinueChunk = m_currentProperties == lastChunk.properties | 38 bool canContinueChunk = m_currentProperties == lastChunk.properties |
| 61 && behavior != RequiresSeparateChunk | 39 && behavior != RequiresSeparateChunk |
| 62 && m_chunkBehavior.last() != RequiresSeparateChunk; | 40 && m_chunkBehavior.last() != RequiresSeparateChunk; |
| 63 if (canContinueChunk) { | 41 if (canContinueChunk) { |
| 64 lastChunk.endIndex++; | 42 lastChunk.endIndex++; |
| 65 return; | 43 return; |
| 66 } | 44 } |
| 67 | 45 |
| 68 PaintChunk newChunk(lastChunk.endIndex, lastChunk.endIndex + 1, newChunkId ?
&*newChunkId : nullptr, m_currentProperties); | 46 PaintChunk newChunk(lastChunk.endIndex, lastChunk.endIndex + 1, m_currentPro
perties); |
| 69 m_chunks.append(newChunk); | 47 m_chunks.append(newChunk); |
| 70 m_chunkBehavior.append(behavior); | 48 m_chunkBehavior.append(behavior); |
| 71 } | 49 } |
| 72 | 50 |
| 73 void PaintChunker::decrementDisplayItemIndex() | 51 void PaintChunker::decrementDisplayItemIndex() |
| 74 { | 52 { |
| 75 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 53 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
| 76 ASSERT(!m_chunks.isEmpty()); | 54 ASSERT(!m_chunks.isEmpty()); |
| 77 | 55 |
| 78 auto& lastChunk = m_chunks.last(); | 56 auto& lastChunk = m_chunks.last(); |
| 79 if ((lastChunk.endIndex - lastChunk.beginIndex) > 1) { | 57 if ((lastChunk.endIndex - lastChunk.beginIndex) > 1) { |
| 80 lastChunk.endIndex--; | 58 lastChunk.endIndex--; |
| 81 } else { | 59 } else { |
| 82 m_chunks.removeLast(); | 60 m_chunks.removeLast(); |
| 83 m_chunkBehavior.removeLast(); | 61 m_chunkBehavior.removeLast(); |
| 84 } | 62 } |
| 85 } | 63 } |
| 86 | 64 |
| 87 void PaintChunker::clear() | 65 void PaintChunker::clear() |
| 88 { | 66 { |
| 89 m_chunks.clear(); | 67 m_chunks.clear(); |
| 90 m_chunkBehavior.clear(); | 68 m_chunkBehavior.clear(); |
| 91 m_currentChunkId = WTF::nullopt; | |
| 92 m_currentProperties = PaintChunkProperties(); | 69 m_currentProperties = PaintChunkProperties(); |
| 93 } | 70 } |
| 94 | 71 |
| 95 Vector<PaintChunk> PaintChunker::releasePaintChunks() | 72 Vector<PaintChunk> PaintChunker::releasePaintChunks() |
| 96 { | 73 { |
| 97 Vector<PaintChunk> chunks; | 74 Vector<PaintChunk> chunks; |
| 98 chunks.swap(m_chunks); | 75 chunks.swap(m_chunks); |
| 99 m_chunkBehavior.clear(); | 76 m_chunkBehavior.clear(); |
| 100 m_currentChunkId = WTF::nullopt; | |
| 101 m_currentProperties = PaintChunkProperties(); | 77 m_currentProperties = PaintChunkProperties(); |
| 102 return chunks; | 78 return chunks; |
| 103 } | 79 } |
| 104 | 80 |
| 105 } // namespace blink | 81 } // namespace blink |
| OLD | NEW |