Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 <wrl.h>
9
11
13
15public:
17 : deviceContext(dc)
18 {
19 if (!dc) {
20 HRESULT hr = QWindowsDirect2DContext::instance()->d2dDevice()->CreateDeviceContext(
21 D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
23 if (Q_UNLIKELY(FAILED(hr)))
24 qFatal("%s: Couldn't create Direct2D Device Context: %#lx", __FUNCTION__, hr);
25 }
26
28 deviceContext->SetUnitMode(D2D1_UNIT_MODE_PIXELS);
29 }
30
31 void begin()
32 {
34 Q_ASSERT(refCount >= 0);
35
36 if (refCount == 0)
37 deviceContext->BeginDraw();
38
39 refCount++;
40 }
41
42 bool end()
43 {
45 Q_ASSERT(refCount > 0);
46
47 bool success = true;
48 refCount--;
49
50 if (refCount == 0) {
51 D2D1_TAG tag1, tag2;
52 HRESULT hr = deviceContext->EndDraw(&tag1, &tag2);
53
54 if (FAILED(hr)) {
55 success = false;
56 qWarning("%s: EndDraw failed: %#lx, tag1: %lld, tag2: %lld",
57 __FUNCTION__, long(hr), tag1, tag2);
58 }
59 }
60
61 return success;
62 }
63
64 ComPtr<ID2D1DeviceContext> deviceContext;
65 int refCount = 0;
66};
67
72
77
78ID2D1DeviceContext *QWindowsDirect2DDeviceContext::get() const
79{
81 Q_ASSERT(d->deviceContext);
82
83 return d->deviceContext.Get();
84}
85
91
93{
95 return d->end();
96}
97
98void QWindowsDirect2DDeviceContext::suspend()
99{
101 if (d->refCount > 0)
102 d->deviceContext->EndDraw();
103}
104
105void QWindowsDirect2DDeviceContext::resume()
106{
108 if (d->refCount > 0)
109 d->deviceContext->BeginDraw();
110}
111
118
123
125{
126 if (m_dc) {
127 m_dc->resume();
128 m_dc = nullptr;
129 }
130}
131
static QWindowsDirect2DContext * instance()
QWindowsDirect2DDeviceContextSuspender(QWindowsDirect2DDeviceContext *dc)
QWindowsDirect2DDeviceContext(ID2D1DeviceContext *dc)
Combined button and popup list for selecting options.
#define Q_UNLIKELY(x)
#define qWarning
Definition qlogging.h:166
#define qFatal
Definition qlogging.h:168
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
long HRESULT