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// Qt-Security score:significant reason:default
4
8
9#include <QtCore/private/qcomptr_p.h>
10
12
14public:
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
64 int refCount = 0;
65};
66
67QWindowsDirect2DDeviceContext::QWindowsDirect2DDeviceContext(ID2D1DeviceContext *dc)
68 : d_ptr(new QWindowsDirect2DDeviceContextPrivate(dc))
69{
70}
71
76
78{
79 Q_D(const QWindowsDirect2DDeviceContext);
80 Q_ASSERT(d->deviceContext);
81
82 return d->deviceContext.Get();
83}
84
86{
87 Q_D(QWindowsDirect2DDeviceContext);
88 d->begin();
89}
90
92{
93 Q_D(QWindowsDirect2DDeviceContext);
94 return d->end();
95}
96
98{
99 Q_D(QWindowsDirect2DDeviceContext);
100 if (d->refCount > 0)
101 d->deviceContext->EndDraw();
102}
103
105{
106 Q_D(QWindowsDirect2DDeviceContext);
107 if (d->refCount > 0)
108 d->deviceContext->BeginDraw();
109}
110
117
122
124{
125 if (m_dc) {
126 m_dc->resume();
127 m_dc = nullptr;
128 }
129}
130
131QT_END_NAMESPACE
static QWindowsDirect2DContext * instance()
QWindowsDirect2DDeviceContextSuspender(QWindowsDirect2DDeviceContext *dc)
Combined button and popup list for selecting options.