Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qwindowsdirect2ddevicecontext.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qwindowsdirect2dcontext.h"
6
#
include
"qwindowsdirect2dhelpers.h"
7
#
include
"qwindowsdirect2ddevicecontext.h"
8
9
#
include
<
QtCore
/
private
/
qcomptr_p
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
class
QWindowsDirect2DDeviceContextPrivate
{
14
public
:
15
QWindowsDirect2DDeviceContextPrivate
(ID2D1DeviceContext *dc)
16
:
deviceContext
(
dc
)
17
{
18
if
(!dc) {
19
HRESULT hr =
QWindowsDirect2DContext
::
instance
(
)
->
d2dDevice
(
)
->CreateDeviceContext(
20
D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
21
&deviceContext);
22
if
(Q_UNLIKELY(FAILED(hr)))
23
qFatal(
"%s: Couldn't create Direct2D Device Context: %#lx"
,
__FUNCTION__
, hr);
24
}
25
26
Q_ASSERT(deviceContext);
27
deviceContext->SetUnitMode(D2D1_UNIT_MODE_PIXELS);
28
}
29
30
void
begin
()
31
{
32
Q_ASSERT(deviceContext);
33
Q_ASSERT(
refCount
>= 0);
34
35
if
(refCount == 0)
36
deviceContext->BeginDraw();
37
38
refCount
++;
39
}
40
41
bool
end
()
42
{
43
Q_ASSERT(deviceContext);
44
Q_ASSERT(
refCount
> 0);
45
46
bool
success =
true
;
47
refCount
--;
48
49
if
(
refCount
== 0) {
50
D2D1_TAG tag1, tag2;
51
HRESULT hr = deviceContext->EndDraw(&tag1, &tag2);
52
53
if
(FAILED(hr)) {
54
success =
false
;
55
qWarning(
"%s: EndDraw failed: %#lx, tag1: %lld, tag2: %lld"
,
56
__FUNCTION__
,
long
(hr), tag1, tag2);
57
}
58
}
59
60
return
success;
61
}
62
63
ComPtr
<
ID2D1DeviceContext
>
deviceContext
;
64
int
refCount
= 0;
65
};
66
67
QWindowsDirect2DDeviceContext
::QWindowsDirect2DDeviceContext(ID2D1DeviceContext *dc)
68
: d_ptr(
new
QWindowsDirect2DDeviceContextPrivate(dc))
69
{
70
}
71
72
QWindowsDirect2DDeviceContext
::~
QWindowsDirect2DDeviceContext
()
73
{
74
75
}
76
77
ID2D1DeviceContext
*
QWindowsDirect2DDeviceContext
::
get
()
const
78
{
79
Q_D(
const
QWindowsDirect2DDeviceContext);
80
Q_ASSERT(d->deviceContext);
81
82
return
d->deviceContext.Get();
83
}
84
85
void
QWindowsDirect2DDeviceContext
::
begin
()
86
{
87
Q_D(QWindowsDirect2DDeviceContext);
88
d->begin();
89
}
90
91
bool
QWindowsDirect2DDeviceContext
::
end
()
92
{
93
Q_D(QWindowsDirect2DDeviceContext);
94
return
d->end();
95
}
96
97
void
QWindowsDirect2DDeviceContext
::suspend()
98
{
99
Q_D(QWindowsDirect2DDeviceContext);
100
if
(d->refCount > 0)
101
d->deviceContext->EndDraw();
102
}
103
104
void
QWindowsDirect2DDeviceContext
::resume()
105
{
106
Q_D(QWindowsDirect2DDeviceContext);
107
if
(d->refCount > 0)
108
d->deviceContext->BeginDraw();
109
}
110
111
QWindowsDirect2DDeviceContextSuspender
::
QWindowsDirect2DDeviceContextSuspender
(
QWindowsDirect2DDeviceContext
*dc)
112
: m_dc(dc)
113
{
114
Q_ASSERT(m_dc);
115
m_dc->suspend();
116
}
117
118
QWindowsDirect2DDeviceContextSuspender
::~
QWindowsDirect2DDeviceContextSuspender
()
119
{
120
resume
(
)
;
121
}
122
123
void
QWindowsDirect2DDeviceContextSuspender
::
resume
()
124
{
125
if
(m_dc) {
126
m_dc->resume();
127
m_dc =
nullptr
;
128
}
129
}
130
131
QT_END_NAMESPACE
QWindowsDirect2DContext
Definition
qwindowsdirect2dcontext.h:22
QWindowsDirect2DContext::d2dDevice
ID2D1Device * d2dDevice() const
Definition
qwindowsdirect2dcontext.cpp:148
QWindowsDirect2DContext::instance
static QWindowsDirect2DContext * instance()
Definition
qwindowsdirect2dcontext.cpp:137
QWindowsDirect2DDeviceContextPrivate
Definition
qwindowsdirect2ddevicecontext.cpp:13
QWindowsDirect2DDeviceContextPrivate::deviceContext
ComPtr< ID2D1DeviceContext > deviceContext
Definition
qwindowsdirect2ddevicecontext.cpp:63
QWindowsDirect2DDeviceContextPrivate::end
bool end()
Definition
qwindowsdirect2ddevicecontext.cpp:41
QWindowsDirect2DDeviceContextPrivate::begin
void begin()
Definition
qwindowsdirect2ddevicecontext.cpp:30
QWindowsDirect2DDeviceContextPrivate::refCount
int refCount
Definition
qwindowsdirect2ddevicecontext.cpp:64
QWindowsDirect2DDeviceContextPrivate::QWindowsDirect2DDeviceContextPrivate
QWindowsDirect2DDeviceContextPrivate(ID2D1DeviceContext *dc)
Definition
qwindowsdirect2ddevicecontext.cpp:15
QWindowsDirect2DDeviceContextSuspender
Definition
qwindowsdirect2ddevicecontext.h:58
QWindowsDirect2DDeviceContextSuspender::resume
void resume()
Definition
qwindowsdirect2ddevicecontext.cpp:123
QWindowsDirect2DDeviceContextSuspender::QWindowsDirect2DDeviceContextSuspender
QWindowsDirect2DDeviceContextSuspender(QWindowsDirect2DDeviceContext *dc)
Definition
qwindowsdirect2ddevicecontext.cpp:111
QWindowsDirect2DDeviceContextSuspender::~QWindowsDirect2DDeviceContextSuspender
~QWindowsDirect2DDeviceContextSuspender()
Definition
qwindowsdirect2ddevicecontext.cpp:118
QWindowsDirect2DDeviceContext
Definition
qwindowsdirect2ddevicecontext.h:39
QWindowsDirect2DDeviceContext::end
bool end()
Definition
qwindowsdirect2ddevicecontext.cpp:91
QWindowsDirect2DDeviceContext::~QWindowsDirect2DDeviceContext
~QWindowsDirect2DDeviceContext()
Definition
qwindowsdirect2ddevicecontext.cpp:72
QWindowsDirect2DDeviceContext::begin
void begin()
Definition
qwindowsdirect2ddevicecontext.cpp:85
QWindowsDirect2DDeviceContext::get
ID2D1DeviceContext * get() const
Definition
qwindowsdirect2ddevicecontext.cpp:77
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
plugins
platforms
direct2d
qwindowsdirect2ddevicecontext.cpp
Generated on
for Qt by
1.18.0