| 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/DisplayItemClient.h" | 5 #include "platform/graphics/paint/DisplayItemClient.h" |
| 6 | 6 |
| 7 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 7 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
| 8 #include "wtf/HashMap.h" | 8 #include "wtf/HashMap.h" |
| 9 #include "wtf/HashSet.h" | 9 #include "wtf/HashSet.h" |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 DisplayItemCacheGeneration::Generation DisplayItemCacheGeneration::s_nextGenerat
ion = 1; | 14 DisplayItemCacheGeneration::Generation DisplayItemCacheGeneration::s_nextGenerat
ion = 1; |
| 15 | 15 |
| 16 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 16 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
| 17 | 17 |
| 18 HashSet<const DisplayItemClient*>* liveDisplayItemClients = nullptr; | 18 HashSet<const DisplayItemClient*>* liveDisplayItemClients = nullptr; |
| 19 HashMap<const DisplayItemClient*, String>* displayItemClientsShouldKeepAlive = n
ullptr; | 19 HashMap<const void*, HashMap<const DisplayItemClient*, String>>* displayItemClie
ntsShouldKeepAlive = nullptr; |
| 20 | 20 |
| 21 DisplayItemClient::DisplayItemClient() | 21 DisplayItemClient::DisplayItemClient() |
| 22 { | 22 { |
| 23 CHECK(!displayItemClientsShouldKeepAlive || !displayItemClientsShouldKeepAli
ve->contains(this)); | 23 if (displayItemClientsShouldKeepAlive) { |
| 24 for (auto item : *displayItemClientsShouldKeepAlive) |
| 25 CHECK(!item.value.contains(this)); |
| 26 } |
| 24 if (!liveDisplayItemClients) | 27 if (!liveDisplayItemClients) |
| 25 liveDisplayItemClients = new HashSet<const DisplayItemClient*>(); | 28 liveDisplayItemClients = new HashSet<const DisplayItemClient*>(); |
| 26 liveDisplayItemClients->add(this); | 29 liveDisplayItemClients->add(this); |
| 27 } | 30 } |
| 28 | 31 |
| 29 DisplayItemClient::~DisplayItemClient() | 32 DisplayItemClient::~DisplayItemClient() |
| 30 { | 33 { |
| 31 CHECK(!displayItemClientsShouldKeepAlive || !displayItemClientsShouldKeepAli
ve->contains(this)) | 34 if (displayItemClientsShouldKeepAlive) { |
| 32 << "Short-lived DisplayItemClient: " << displayItemClientsShouldKeepAliv
e->get(this) | 35 for (auto& item : *displayItemClientsShouldKeepAlive) { |
| 33 << ". See crbug.com/570030."; | 36 CHECK(!item.value.contains(this)) |
| 37 << "Short-lived DisplayItemClient: " << item.value.get(this) |
| 38 << ". See crbug.com/570030."; |
| 39 } |
| 40 } |
| 34 liveDisplayItemClients->remove(this); | 41 liveDisplayItemClients->remove(this); |
| 35 } | 42 } |
| 36 | 43 |
| 37 bool DisplayItemClient::isAlive() const | 44 bool DisplayItemClient::isAlive() const |
| 38 { | 45 { |
| 39 return liveDisplayItemClients && liveDisplayItemClients->contains(this); | 46 return liveDisplayItemClients && liveDisplayItemClients->contains(this); |
| 40 } | 47 } |
| 41 | 48 |
| 42 void DisplayItemClient::beginShouldKeepAlive() const | 49 void DisplayItemClient::beginShouldKeepAlive(const void* owner) const |
| 43 { | 50 { |
| 44 CHECK(isAlive()); | 51 CHECK(isAlive()); |
| 45 if (!displayItemClientsShouldKeepAlive) | 52 if (!displayItemClientsShouldKeepAlive) |
| 46 displayItemClientsShouldKeepAlive = new HashMap<const DisplayItemClient*
, String>(); | 53 displayItemClientsShouldKeepAlive = new HashMap<const void*, HashMap<con
st DisplayItemClient*, String>>(); |
| 47 #ifdef NDEBUG | 54 auto addResult = displayItemClientsShouldKeepAlive->add(owner, HashMap<const
DisplayItemClient*, String>()).storedValue->value.add(this, ""); |
| 48 displayItemClientsShouldKeepAlive->add(this, ""); | |
| 49 #else | |
| 50 auto addResult = displayItemClientsShouldKeepAlive->add(this, ""); | |
| 51 if (addResult.isNewEntry) | 55 if (addResult.isNewEntry) |
| 52 addResult.storedValue->value = debugName(); | 56 addResult.storedValue->value = debugName(); |
| 53 #endif | |
| 54 } | 57 } |
| 55 | 58 |
| 56 void DisplayItemClient::endShouldKeepAliveAllClients() | 59 void DisplayItemClient::endShouldKeepAliveAllClients(const void* owner) |
| 57 { | 60 { |
| 58 delete displayItemClientsShouldKeepAlive; | 61 if (displayItemClientsShouldKeepAlive) |
| 59 displayItemClientsShouldKeepAlive = nullptr; | 62 displayItemClientsShouldKeepAlive->remove(owner); |
| 60 } | 63 } |
| 61 | 64 |
| 62 #endif // CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 65 #endif // CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
| 63 | 66 |
| 64 } // namespace blink | 67 } // namespace blink |
| OLD | NEW |