From e298c2d5842ddf405a01db6b9024a58ae5fa6525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 24 Apr 2015 09:26:13 +0200 Subject: [PATCH] React on DrmOutput added/removed in DrmQPainterBackend For a new DrmOutput a new buffer needs to be created, for a removed one the existing buffers need to be deleted. --- scene_qpainter.cpp | 43 ++++++++++++++++++++++++++++++++----------- scene_qpainter.h | 1 + 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/scene_qpainter.cpp b/scene_qpainter.cpp index 8400db0499..3f62928d9b 100644 --- a/scene_qpainter.cpp +++ b/scene_qpainter.cpp @@ -358,17 +358,24 @@ DrmQPainterBackend::DrmQPainterBackend(DrmBackend *backend) { const auto outputs = m_backend->outputs(); for (auto output: outputs) { - Output o; - auto initBuffer = [&o, output, this] (int index) { - o.buffer[index] = m_backend->createBuffer(output->size()); - o.buffer[index]->map(); - o.buffer[index]->image()->fill(Qt::black); - }; - initBuffer(0); - initBuffer(1); - o.output = output; - m_outputs << o; - } + initOutput(output); + } + connect(m_backend, &DrmBackend::outputAdded, this, &DrmQPainterBackend::initOutput); + connect(m_backend, &DrmBackend::outputRemoved, this, + [this] (DrmOutput *o) { + auto it = std::find_if(m_outputs.begin(), m_outputs.end(), + [o] (const Output &output) { + return output.output == o; + } + ); + if (it == m_outputs.end()) { + return; + } + delete (*it).buffer[0]; + delete (*it).buffer[1]; + m_outputs.erase(it); + } + ); } DrmQPainterBackend::~DrmQPainterBackend() @@ -379,6 +386,20 @@ DrmQPainterBackend::~DrmQPainterBackend() } } +void DrmQPainterBackend::initOutput(DrmOutput *output) +{ + Output o; + auto initBuffer = [&o, output, this] (int index) { + o.buffer[index] = m_backend->createBuffer(output->size()); + o.buffer[index]->map(); + o.buffer[index]->image()->fill(Qt::black); + }; + initBuffer(0); + initBuffer(1); + o.output = output; + m_outputs << o; +} + QImage *DrmQPainterBackend::buffer() { return bufferForScreen(0); diff --git a/scene_qpainter.h b/scene_qpainter.h index 73484323c8..007fd2ccb1 100644 --- a/scene_qpainter.h +++ b/scene_qpainter.h @@ -207,6 +207,7 @@ public: bool perScreenRendering() const override; private: + void initOutput(DrmOutput *output); struct Output { DrmBuffer *buffer[2]; DrmOutput *output;