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