Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/scene_qpainter_drm_backend.cpp
Show All 26 Lines | |||||
27 | 27 | | |||
28 | DrmQPainterBackend::DrmQPainterBackend(DrmBackend *backend) | 28 | DrmQPainterBackend::DrmQPainterBackend(DrmBackend *backend) | ||
29 | : QObject() | 29 | : QObject() | ||
30 | , QPainterBackend() | 30 | , QPainterBackend() | ||
31 | , m_backend(backend) | 31 | , m_backend(backend) | ||
32 | { | 32 | { | ||
33 | const auto outputs = m_backend->outputs(); | 33 | const auto outputs = m_backend->outputs(); | ||
34 | for (auto output: outputs) { | 34 | for (auto output: outputs) { | ||
35 | initOutput(output); | 35 | initOutput(qobject_cast<DrmOutput*>(output)); | ||
36 | } | 36 | } | ||
37 | connect(m_backend, &DrmBackend::outputAdded, this, &DrmQPainterBackend::initOutput); | 37 | connect(m_backend, &DrmBackend::outputAdded, this, &DrmQPainterBackend::initOutput); | ||
38 | connect(m_backend, &DrmBackend::outputRemoved, this, | 38 | connect(m_backend, &DrmBackend::outputRemoved, this, | ||
39 | [this] (DrmOutput *o) { | 39 | [this] (DrmOutput *o) { | ||
40 | auto it = std::find_if(m_outputs.begin(), m_outputs.end(), | 40 | auto it = std::find_if(m_outputs.begin(), m_outputs.end(), | ||
41 | [o] (const Output &output) { | 41 | [o] (const QPainterOutput &output) { | ||
42 | return output.output == o; | 42 | return output.output == o; | ||
43 | } | 43 | } | ||
44 | ); | 44 | ); | ||
45 | if (it == m_outputs.end()) { | 45 | if (it == m_outputs.end()) { | ||
46 | return; | 46 | return; | ||
47 | } | 47 | } | ||
48 | delete (*it).buffer[0]; | 48 | delete (*it).buffer[0]; | ||
49 | delete (*it).buffer[1]; | 49 | delete (*it).buffer[1]; | ||
50 | m_outputs.erase(it); | 50 | m_outputs.erase(it); | ||
51 | } | 51 | } | ||
52 | ); | 52 | ); | ||
53 | } | 53 | } | ||
54 | 54 | | |||
55 | DrmQPainterBackend::~DrmQPainterBackend() | 55 | DrmQPainterBackend::~DrmQPainterBackend() | ||
56 | { | 56 | { | ||
57 | for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) { | 57 | for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) { | ||
58 | delete (*it).buffer[0]; | 58 | delete (*it).buffer[0]; | ||
59 | delete (*it).buffer[1]; | 59 | delete (*it).buffer[1]; | ||
60 | } | 60 | } | ||
61 | } | 61 | } | ||
62 | 62 | | |||
63 | void DrmQPainterBackend::initOutput(DrmOutput *output) | 63 | void DrmQPainterBackend::initOutput(DrmOutput *output) | ||
64 | { | 64 | { | ||
65 | Output o; | 65 | QPainterOutput o; | ||
66 | auto initBuffer = [&o, output, this] (int index) { | 66 | auto initBuffer = [&o, output, this] (int index) { | ||
67 | o.buffer[index] = m_backend->createBuffer(output->pixelSize()); | 67 | o.buffer[index] = m_backend->createBuffer(output->pixelSize()); | ||
68 | o.buffer[index]->map(); | 68 | o.buffer[index]->map(); | ||
69 | o.buffer[index]->image()->fill(Qt::black); | 69 | o.buffer[index]->image()->fill(Qt::black); | ||
70 | }; | 70 | }; | ||
71 | connect(output, &DrmOutput::modeChanged, this, | 71 | connect(output, &DrmOutput::modeChanged, this, | ||
72 | [output, this] { | 72 | [output, this] { | ||
73 | auto it = std::find_if(m_outputs.begin(), m_outputs.end(), | 73 | auto it = std::find_if(m_outputs.begin(), m_outputs.end(), | ||
Show All 23 Lines | |||||
97 | 97 | | |||
98 | QImage *DrmQPainterBackend::buffer() | 98 | QImage *DrmQPainterBackend::buffer() | ||
99 | { | 99 | { | ||
100 | return bufferForScreen(0); | 100 | return bufferForScreen(0); | ||
101 | } | 101 | } | ||
102 | 102 | | |||
103 | QImage *DrmQPainterBackend::bufferForScreen(int screenId) | 103 | QImage *DrmQPainterBackend::bufferForScreen(int screenId) | ||
104 | { | 104 | { | ||
105 | const Output &o = m_outputs.at(screenId); | 105 | const QPainterOutput &o = m_outputs.at(screenId); | ||
106 | return o.buffer[o.index]->image(); | 106 | return o.buffer[o.index]->image(); | ||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | bool DrmQPainterBackend::needsFullRepaint() const | 109 | bool DrmQPainterBackend::needsFullRepaint() const | ||
110 | { | 110 | { | ||
111 | return true; | 111 | return true; | ||
112 | } | 112 | } | ||
113 | 113 | | |||
114 | void DrmQPainterBackend::prepareRenderingFrame() | 114 | void DrmQPainterBackend::prepareRenderingFrame() | ||
115 | { | 115 | { | ||
116 | for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) { | 116 | for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) { | ||
117 | (*it).index = ((*it).index + 1) % 2; | 117 | (*it).index = ((*it).index + 1) % 2; | ||
118 | } | 118 | } | ||
119 | } | 119 | } | ||
120 | 120 | | |||
121 | void DrmQPainterBackend::present(int mask, const QRegion &damage) | 121 | void DrmQPainterBackend::present(int mask, const QRegion &damage) | ||
122 | { | 122 | { | ||
123 | Q_UNUSED(mask) | 123 | Q_UNUSED(mask) | ||
124 | Q_UNUSED(damage) | 124 | Q_UNUSED(damage) | ||
125 | if (!LogindIntegration::self()->isActiveSession()) { | 125 | if (!LogindIntegration::self()->isActiveSession()) { | ||
126 | return; | 126 | return; | ||
127 | } | 127 | } | ||
128 | for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) { | 128 | for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) { | ||
129 | const Output &o = *it; | 129 | const QPainterOutput &o = *it; | ||
130 | m_backend->present(o.buffer[o.index], o.output); | 130 | m_backend->present(o.buffer[o.index], o.output); | ||
131 | } | 131 | } | ||
132 | } | 132 | } | ||
133 | 133 | | |||
134 | bool DrmQPainterBackend::usesOverlayWindow() const | 134 | bool DrmQPainterBackend::usesOverlayWindow() const | ||
135 | { | 135 | { | ||
136 | return false; | 136 | return false; | ||
137 | } | 137 | } | ||
138 | 138 | | |||
139 | bool DrmQPainterBackend::perScreenRendering() const | 139 | bool DrmQPainterBackend::perScreenRendering() const | ||
140 | { | 140 | { | ||
141 | return true; | 141 | return true; | ||
142 | } | 142 | } | ||
143 | 143 | | |||
144 | } | 144 | } |