summaryrefslogtreecommitdiffstats
path: root/gfx/layers/d3d11/GpuProcessD3D11QueryMap.cpp
blob: 858e39d9d56ace6fed1bd2ade3074e8a4af27046 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "GpuProcessD3D11QueryMap.h"

#include "mozilla/webrender/RenderThread.h"

namespace mozilla {

namespace layers {

StaticAutoPtr<GpuProcessD3D11QueryMap> GpuProcessD3D11QueryMap::sInstance;

/* static */
void GpuProcessD3D11QueryMap::Init() {
  MOZ_ASSERT(XRE_IsGPUProcess());
  sInstance = new GpuProcessD3D11QueryMap();
}

/* static */
void GpuProcessD3D11QueryMap::Shutdown() {
  MOZ_ASSERT(XRE_IsGPUProcess());
  sInstance = nullptr;
}

GpuProcessD3D11QueryMap::GpuProcessD3D11QueryMap()
    : mMonitor("GpuProcessD3D11QueryMap::mMonitor") {}

GpuProcessD3D11QueryMap::~GpuProcessD3D11QueryMap() {}

void GpuProcessD3D11QueryMap::Register(GpuProcessQueryId aQueryId,
                                       ID3D11Query* aQuery) {
  MOZ_RELEASE_ASSERT(aQuery);

  MonitorAutoLock lock(mMonitor);
  mD3D11QueriesById[aQueryId] = aQuery;
}

void GpuProcessD3D11QueryMap::Unregister(GpuProcessQueryId aQueryId) {
  MonitorAutoLock lock(mMonitor);

  auto it = mD3D11QueriesById.find(aQueryId);
  if (it == mD3D11QueriesById.end()) {
    return;
  }
  mD3D11QueriesById.erase(it);
}

RefPtr<ID3D11Query> GpuProcessD3D11QueryMap::GetQuery(
    GpuProcessQueryId aQueryId) {
  MOZ_ASSERT(wr::RenderThread::IsInRenderThread());

  MonitorAutoLock lock(mMonitor);

  auto it = mD3D11QueriesById.find(aQueryId);
  if (it == mD3D11QueriesById.end()) {
    return nullptr;
  }

  return it->second;
}

}  // namespace layers
}  // namespace mozilla