summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/graphics/paint/display_item_client.cc
blob: 5fac148c2daa3a2148b225138292ceef3c691624 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/graphics/paint/display_item_client.h"

#if DCHECK_IS_ON()
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#endif

namespace blink {

DisplayItemClient::CacheGenerationOrInvalidationReason::ValueType
    DisplayItemClient::CacheGenerationOrInvalidationReason::next_generation_ =
        kFirstValidGeneration;

#if DCHECK_IS_ON()

HashSet<const DisplayItemClient*>* g_live_display_item_clients = nullptr;

DisplayItemClient::DisplayItemClient() {
  if (!g_live_display_item_clients)
    g_live_display_item_clients = new HashSet<const DisplayItemClient*>();
  g_live_display_item_clients->insert(this);
}

DisplayItemClient::~DisplayItemClient() {
  g_live_display_item_clients->erase(this);
}

bool DisplayItemClient::IsAlive() const {
  return g_live_display_item_clients &&
         g_live_display_item_clients->Contains(this);
}

String DisplayItemClient::SafeDebugName(const DisplayItemClient& client,
                                        bool known_to_be_safe) {
  if (known_to_be_safe) {
    DCHECK(client.IsAlive());
    return client.DebugName();
  }

  // If the caller is not sure, we must ensure the client is alive, and it's
  // not a destroyed client at the same address of a new client.
  if (client.IsAlive() && !client.IsJustCreated())
    return client.DebugName();

  return "DEAD";
}

#endif  // DCHECK_IS_ON()

}  // namespace blink