Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/ipc/LayerTreeOwnerTracker.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "LayerTreeOwnerTracker.h"
8
9
#include "mozilla/StaticPtr.h"              // for StaticAutoPtr
10
#include "mozilla/dom/ContentParent.h"      // for ContentParent
11
#include "mozilla/gfx/GPUChild.h"           // for GPUChild
12
#include "mozilla/gfx/GPUProcessManager.h"  // for GPUProcessManager
13
14
#include <functional>
15
#include <utility> // for std::make_pair
16
17
namespace mozilla {
18
namespace layers {
19
20
static StaticAutoPtr<LayerTreeOwnerTracker> sSingleton;
21
22
LayerTreeOwnerTracker::LayerTreeOwnerTracker() :
23
  mLayerIdsLock("LayerTreeOwnerTrackerLock")
24
0
{
25
0
}
26
27
void
28
LayerTreeOwnerTracker::Initialize()
29
0
{
30
0
  MOZ_ASSERT(!sSingleton);
31
0
  sSingleton = new LayerTreeOwnerTracker();
32
0
}
33
34
void
35
LayerTreeOwnerTracker::Shutdown()
36
0
{
37
0
  sSingleton = nullptr;
38
0
}
39
40
LayerTreeOwnerTracker*
41
LayerTreeOwnerTracker::Get()
42
0
{
43
0
  return sSingleton;
44
0
}
45
46
void
47
LayerTreeOwnerTracker::Map(LayersId aLayersId, base::ProcessId aProcessId)
48
0
{
49
0
  MutexAutoLock lock(mLayerIdsLock);
50
0
51
0
  // Add the mapping to the list
52
0
  mLayerIds[aLayersId] = aProcessId;
53
0
}
54
55
void
56
LayerTreeOwnerTracker::Unmap(LayersId aLayersId, base::ProcessId aProcessId)
57
0
{
58
0
  MutexAutoLock lock(mLayerIdsLock);
59
0
60
0
  MOZ_ASSERT(mLayerIds[aLayersId] == aProcessId);
61
0
  mLayerIds.erase(aLayersId);
62
0
}
63
64
bool
65
LayerTreeOwnerTracker::IsMapped(LayersId aLayersId, base::ProcessId aProcessId)
66
0
{
67
0
  MutexAutoLock lock(mLayerIdsLock);
68
0
69
0
  auto iter = mLayerIds.find(aLayersId);
70
0
  return iter != mLayerIds.end() && iter->second == aProcessId;
71
0
}
72
73
void
74
LayerTreeOwnerTracker::Iterate(const std::function<void(LayersId aLayersId, base::ProcessId aProcessId)>& aCallback)
75
0
{
76
0
  MutexAutoLock lock(mLayerIdsLock);
77
0
78
0
  for (const auto& iter : mLayerIds) {
79
0
    aCallback(iter.first, iter.second);
80
0
  }
81
0
}
82
83
} // namespace layers
84
} // namespace mozilla