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
7
8#include <QtCore/private/qcomptr_p.h>
9
11
13public:
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
63 int refCount = 0;
64};
65
66QWindowsDirect2DDeviceContext::QWindowsDirect2DDeviceContext(ID2D1DeviceContext *dc)
67 : d_ptr(new QWindowsDirect2DDeviceContextPrivate(dc))
68{
69}
70
75
77{
78 Q_D(const QWindowsDirect2DDeviceContext);
79 Q_ASSERT(d->deviceContext);
80
81 return d->deviceContext.Get();
82}
83
85{
86 Q_D(QWindowsDirect2DDeviceContext);
87 d->begin();
88}
89
91{
92 Q_D(QWindowsDirect2DDeviceContext);
93 return d->end();
94}
95
97{
98 Q_D(QWindowsDirect2DDeviceContext);
99 if (d->refCount > 0)
100 d->deviceContext->EndDraw();
101}
102
104{
105 Q_D(QWindowsDirect2DDeviceContext);
106 if (d->refCount > 0)
107 d->deviceContext->BeginDraw();
108}
109
116
121
123{
124 if (m_dc) {
125 m_dc->resume();
126 m_dc = nullptr;
127 }
128}
129
130QT_END_NAMESPACE
QWindowsDirect2DDeviceContextSuspender(QWindowsDirect2DDeviceContext *dc)