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
12 #include "mozilla/TimeStamp.h"
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
) {
26 if (TimeStamp::Now() - start
> TimeDuration::FromSeconds(2)) {
34 static inline bool WaitForFrameGPUQuery(ID3D11Device
* aDevice
,
35 ID3D11DeviceContext
* aContext
,
36 ID3D11Query
* aQuery
, BOOL
* aOut
) {
37 TimeStamp start
= TimeStamp::Now();
39 while (aContext
->GetData(aQuery
, aOut
, sizeof(*aOut
), 0) != S_OK
) {
40 HRESULT hr
= aDevice
->GetDeviceRemovedReason();
42 gfxCriticalNoteOnce
<< "WaitForFrameGPUQuery device removed: "
46 if (TimeStamp::Now() - start
> TimeDuration::FromSeconds(2)) {
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());
66 } // namespace mozilla
68 #endif // mozilla_gfx_layers_d3d11_HelpersD3D11_h