blob: 29185a9d934630eb983d609d718d78d2e87f3963 (
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Trim11.cpp: Trim support utility class.
#include "libANGLE/renderer/d3d/d3d11/Trim11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#if defined (ANGLE_ENABLE_WINDOWS_STORE)
#include <wrl.h>
#include <wrl/wrappers/corewrappers.h>
#include <windows.applicationmodel.core.h>
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::ApplicationModel;
using namespace ABI::Windows::ApplicationModel::Core;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::Foundation::Collections;
#endif
namespace rx
{
Trim11::Trim11(rx::Renderer11 *renderer)
: mRenderer(renderer)
{
bool result = true;
result = registerForRendererTrimRequest();
ASSERT(result);
}
Trim11::~Trim11()
{
unregisterForRendererTrimRequest();
}
void Trim11::trim()
{
if (!mRenderer)
{
return;
}
#if defined (ANGLE_ENABLE_WINDOWS_STORE)
ID3D11Device* device = mRenderer->getDevice();
IDXGIDevice3 *dxgiDevice3 = d3d11::DynamicCastComObject<IDXGIDevice3>(device);
if (dxgiDevice3)
{
dxgiDevice3->Trim();
}
SafeRelease(dxgiDevice3);
#endif
}
bool Trim11::registerForRendererTrimRequest()
{
#if defined (ANGLE_ENABLE_WINDOWS_STORE)
ICoreApplication* coreApplication = nullptr;
HRESULT result = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(), &coreApplication);
if (SUCCEEDED(result))
{
auto suspendHandler = Callback<IEventHandler<SuspendingEventArgs*>>(
[this](IInspectable*, ISuspendingEventArgs*) -> HRESULT
{
trim();
return S_OK;
});
result = coreApplication->add_Suspending(suspendHandler.Get(), &mApplicationSuspendedEventToken);
}
SafeRelease(coreApplication);
if (FAILED(result))
{
return false;
}
#endif
return true;
}
void Trim11::unregisterForRendererTrimRequest()
{
#if defined (ANGLE_ENABLE_WINDOWS_STORE)
if (mApplicationSuspendedEventToken.value != 0)
{
ICoreApplication* coreApplication = nullptr;
if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(), &coreApplication)))
{
coreApplication->remove_Suspending(mApplicationSuspendedEventToken);
}
mApplicationSuspendedEventToken.value = 0;
SafeRelease(coreApplication);
}
#endif
}
}
|