Commit 1365a76f authored by Xaver Hugl's avatar Xaver Hugl
Browse files

manage ColorPipelineStages with unique_ptr

parent 14e7afcb
Pipeline #168717 passed with stage
in 12 minutes and 47 seconds
......@@ -59,9 +59,9 @@ public:
uint brightness = 100;
uint temperature = 6500;
QSharedPointer<ColorPipelineStage> temperatureStage;
QSharedPointer<ColorPipelineStage> brightnessStage;
QSharedPointer<ColorPipelineStage> calibrationStage;
std::unique_ptr<ColorPipelineStage> temperatureStage;
std::unique_ptr<ColorPipelineStage> brightnessStage;
std::unique_ptr<ColorPipelineStage> calibrationStage;
QSharedPointer<ColorTransformation> transformation;
};
......@@ -79,7 +79,30 @@ void ColorDevicePrivate::rebuildPipeline()
}
dirtyCurves = DirtyToneCurves();
const auto tmp = QSharedPointer<ColorTransformation>::create(QVector{calibrationStage, brightnessStage, temperatureStage});
std::vector<std::unique_ptr<ColorPipelineStage>> stages;
if (calibrationStage) {
if (auto s = calibrationStage->dup()) {
stages.push_back(std::move(s));
} else {
return;
}
}
if (brightnessStage) {
if (auto s = brightnessStage->dup()) {
stages.push_back(std::move(s));
} else {
return;
}
}
if (temperatureStage) {
if (auto s = temperatureStage->dup()) {
stages.push_back(std::move(s));
} else {
return;
}
}
const auto tmp = QSharedPointer<ColorTransformation>::create(std::move(stages));
if (tmp->valid()) {
transformation = tmp;
}
......@@ -135,7 +158,7 @@ void ColorDevicePrivate::updateTemperatureToneCurves()
// The ownership of the tone curves will be moved to the pipeline stage.
cmsToneCurve *toneCurves[] = {redCurve.take(), greenCurve.take(), blueCurve.take()};
temperatureStage = QSharedPointer<ColorPipelineStage>::create(cmsStageAllocToneCurves(nullptr, 3, toneCurves));
temperatureStage = std::make_unique<ColorPipelineStage>(cmsStageAllocToneCurves(nullptr, 3, toneCurves));
if (!temperatureStage) {
qCWarning(KWIN_CORE) << "Failed to create the color temperature pipeline stage";
}
......@@ -172,7 +195,7 @@ void ColorDevicePrivate::updateBrightnessToneCurves()
// The ownership of the tone curves will be moved to the pipeline stage.
cmsToneCurve *toneCurves[] = {redCurve.take(), greenCurve.take(), blueCurve.take()};
brightnessStage = QSharedPointer<ColorPipelineStage>::create(cmsStageAllocToneCurves(nullptr, 3, toneCurves));
brightnessStage = std::make_unique<ColorPipelineStage>(cmsStageAllocToneCurves(nullptr, 3, toneCurves));
if (!brightnessStage) {
qCWarning(KWIN_CORE) << "Failed to create the color brightness pipeline stage";
}
......@@ -202,7 +225,7 @@ void ColorDevicePrivate::updateCalibrationToneCurves()
cmsDupToneCurve(vcgt[1]),
cmsDupToneCurve(vcgt[2]),
};
calibrationStage = QSharedPointer<ColorPipelineStage>::create(cmsStageAllocToneCurves(nullptr, 3, toneCurves));
calibrationStage = std::make_unique<ColorPipelineStage>(cmsStageAllocToneCurves(nullptr, 3, toneCurves));
}
cmsCloseProfile(handle);
......
......@@ -27,18 +27,17 @@ ColorPipelineStage::~ColorPipelineStage()
}
}
QSharedPointer<ColorPipelineStage> ColorPipelineStage::dup() const
std::unique_ptr<ColorPipelineStage> ColorPipelineStage::dup() const
{
if (m_stage) {
auto dup = cmsStageDup(m_stage);
if (dup) {
return QSharedPointer<ColorPipelineStage>::create(dup);
return std::make_unique<ColorPipelineStage>(dup);
} else {
qCWarning(KWIN_CORE) << "Failed to duplicate cmsStage!";
}
}
return nullptr;
;
}
cmsStage *ColorPipelineStage::stage() const
......
......@@ -10,7 +10,7 @@
#include "kwin_export.h"
#include <QSharedPointer>
#include <memory>
typedef struct _cmsStage_struct cmsStage;
......@@ -23,7 +23,7 @@ public:
ColorPipelineStage(cmsStage *stage);
~ColorPipelineStage();
QSharedPointer<ColorPipelineStage> dup() const;
std::unique_ptr<ColorPipelineStage> dup() const;
cmsStage *stage() const;
private:
......
......@@ -9,27 +9,20 @@
namespace KWin
{
ColorTransformation::ColorTransformation(const QVector<QSharedPointer<ColorPipelineStage>> &stages)
ColorTransformation::ColorTransformation(std::vector<std::unique_ptr<ColorPipelineStage>> &&stages)
: m_pipeline(cmsPipelineAlloc(nullptr, 3, 3))
, m_stages(std::move(stages))
{
if (!m_pipeline) {
qCWarning(KWIN_CORE) << "Failed to allocate cmsPipeline!";
m_valid = false;
return;
}
for (const auto &stage : stages) {
if (stage) {
const auto dup = stage->dup();
if (!dup) {
m_valid = false;
return;
}
m_stages << dup;
if (!cmsPipelineInsertStage(m_pipeline, cmsAT_END, dup->stage())) {
qCWarning(KWIN_CORE) << "Failed to insert cmsPipeline stage!";
m_valid = false;
return;
}
for (auto &stage : m_stages) {
if (!cmsPipelineInsertStage(m_pipeline, cmsAT_END, stage->stage())) {
qCWarning(KWIN_CORE) << "Failed to insert cmsPipeline stage!";
m_valid = false;
return;
}
}
}
......
......@@ -25,7 +25,7 @@ class ColorPipelineStage;
class KWIN_EXPORT ColorTransformation
{
public:
ColorTransformation(const QVector<QSharedPointer<ColorPipelineStage>> &stages);
ColorTransformation(std::vector<std::unique_ptr<ColorPipelineStage>> &&stages);
~ColorTransformation();
bool valid() const;
......@@ -34,7 +34,7 @@ public:
private:
cmsPipeline *const m_pipeline;
QVector<QSharedPointer<ColorPipelineStage>> m_stages;
const std::vector<std::unique_ptr<ColorPipelineStage>> m_stages;
bool m_valid = true;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment