Bug 1919083 - [ci] Enable os-integration variant for more suites, r=jmaher
[gecko.git] / gfx / layers / d3d11 / HelpersD3D11.h
blob772f7701fa559ab24f26b5c17b20a03ed22140e7
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/. */
7 #ifndef mozilla_gfx_layers_d3d11_HelpersD3D11_h
8 #define mozilla_gfx_layers_d3d11_HelpersD3D11_h
10 #include <d3d11.h>
11 #include <array>
12 #include "mozilla/TimeStamp.h"
14 namespace mozilla {
15 namespace layers {
17 template <typename T>
18 static inline bool WaitForGPUQuery(ID3D11Device* aDevice,
19 ID3D11DeviceContext* aContext,
20 ID3D11Query* aQuery, T* aOut) {
21 TimeStamp start = TimeStamp::Now();
22 while (aContext->GetData(aQuery, aOut, sizeof(*aOut), 0) != S_OK) {
23 if (aDevice->GetDeviceRemovedReason() != S_OK) {
24 return false;
26 if (TimeStamp::Now() - start > TimeDuration::FromSeconds(2)) {
27 return false;
29 Sleep(0);
31 return true;
34 static inline bool WaitForFrameGPUQuery(ID3D11Device* aDevice,
35 ID3D11DeviceContext* aContext,
36 ID3D11Query* aQuery, BOOL* aOut) {
37 TimeStamp start = TimeStamp::Now();
38 bool success = true;
39 while (aContext->GetData(aQuery, aOut, sizeof(*aOut), 0) != S_OK) {
40 HRESULT hr = aDevice->GetDeviceRemovedReason();
41 if (hr != S_OK) {
42 gfxCriticalNoteOnce << "WaitForFrameGPUQuery device removed: "
43 << gfx::hexa(hr);
44 return false;
46 if (TimeStamp::Now() - start > TimeDuration::FromSeconds(2)) {
47 success = false;
48 break;
50 Sleep(0);
52 return success;
55 inline void ClearResource(ID3D11Device* const device, ID3D11Resource* const res,
56 const std::array<float, 4>& vals) {
57 RefPtr<ID3D11RenderTargetView> rtv;
58 (void)device->CreateRenderTargetView(res, nullptr, getter_AddRefs(rtv));
60 RefPtr<ID3D11DeviceContext> context;
61 device->GetImmediateContext(getter_AddRefs(context));
62 context->ClearRenderTargetView(rtv, vals.data());
65 } // namespace layers
66 } // namespace mozilla
68 #endif // mozilla_gfx_layers_d3d11_HelpersD3D11_h