Changeset View
Changeset View
Standalone View
Standalone View
src/client/outputdevice.cpp
1 | /******************************************************************** | 1 | /******************************************************************** | ||
---|---|---|---|---|---|
2 | Copyright 2013 Martin Gräßlin <mgraesslin@kde.org> | 2 | Copyright 2013 Martin Gräßlin <mgraesslin@kde.org> | ||
3 | Copyright 2018 Roman Gilg <subdiff@gmail.com> | ||||
3 | 4 | | |||
4 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | 6 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either | ||
7 | version 2.1 of the License, or (at your option) version 3, or any | 8 | version 2.1 of the License, or (at your option) version 3, or any | ||
8 | later version accepted by the membership of KDE e.V. (or its | 9 | later version accepted by the membership of KDE e.V. (or its | ||
9 | successor approved by the membership of KDE e.V.), which shall | 10 | successor approved by the membership of KDE e.V.), which shall | ||
10 | act as a proxy defined in Section 6 of version 3 of the license. | 11 | act as a proxy defined in Section 6 of version 3 of the license. | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 43 | public: | |||
53 | SubPixel subPixel = SubPixel::Unknown; | 54 | SubPixel subPixel = SubPixel::Unknown; | ||
54 | Transform transform = Transform::Normal; | 55 | Transform transform = Transform::Normal; | ||
55 | Modes modes; | 56 | Modes modes; | ||
56 | Modes::iterator currentMode = modes.end(); | 57 | Modes::iterator currentMode = modes.end(); | ||
57 | 58 | | |||
58 | QByteArray edid; | 59 | QByteArray edid; | ||
59 | OutputDevice::Enablement enabled = OutputDevice::Enablement::Enabled; | 60 | OutputDevice::Enablement enabled = OutputDevice::Enablement::Enabled; | ||
60 | QByteArray uuid; | 61 | QByteArray uuid; | ||
62 | | ||||
63 | ColorCurves colorCurves; | ||||
64 | | ||||
61 | bool done = false; | 65 | bool done = false; | ||
62 | 66 | | |||
63 | private: | 67 | private: | ||
64 | static void geometryCallback(void *data, org_kde_kwin_outputdevice *output, int32_t x, int32_t y, | 68 | static void geometryCallback(void *data, org_kde_kwin_outputdevice *output, int32_t x, int32_t y, | ||
65 | int32_t physicalWidth, int32_t physicalHeight, int32_t subPixel, | 69 | int32_t physicalWidth, int32_t physicalHeight, int32_t subPixel, | ||
66 | const char *make, const char *model, int32_t transform); | 70 | const char *make, const char *model, int32_t transform); | ||
67 | static void modeCallback(void *data, org_kde_kwin_outputdevice *output, uint32_t flags, int32_t width, int32_t height, int32_t refresh, int32_t mode_id); | 71 | static void modeCallback(void *data, org_kde_kwin_outputdevice *output, uint32_t flags, int32_t width, int32_t height, int32_t refresh, int32_t mode_id); | ||
68 | static void doneCallback(void *data, org_kde_kwin_outputdevice *output); | 72 | static void doneCallback(void *data, org_kde_kwin_outputdevice *output); | ||
69 | static void scaleCallback(void *data, org_kde_kwin_outputdevice *output, int32_t scale); | 73 | static void scaleCallback(void *data, org_kde_kwin_outputdevice *output, int32_t scale); | ||
70 | 74 | | |||
71 | static void edidCallback(void *data, org_kde_kwin_outputdevice *output, const char *raw); | 75 | static void edidCallback(void *data, org_kde_kwin_outputdevice *output, const char *raw); | ||
72 | static void enabledCallback(void *data, org_kde_kwin_outputdevice *output, int32_t enabled); | 76 | static void enabledCallback(void *data, org_kde_kwin_outputdevice *output, int32_t enabled); | ||
73 | static void uuidCallback(void *data, org_kde_kwin_outputdevice *output, const char *uuid); | 77 | static void uuidCallback(void *data, org_kde_kwin_outputdevice *output, const char *uuid); | ||
74 | 78 | | |||
79 | static void colorcurvesCallback(void *data, org_kde_kwin_outputdevice *output, | ||||
80 | struct wl_array *red, struct wl_array *green, struct wl_array *blue); | ||||
81 | | ||||
75 | void setPhysicalSize(const QSize &size); | 82 | void setPhysicalSize(const QSize &size); | ||
76 | void setGlobalPosition(const QPoint &pos); | 83 | void setGlobalPosition(const QPoint &pos); | ||
77 | void setManufacturer(const QString &manufacturer); | 84 | void setManufacturer(const QString &manufacturer); | ||
78 | void setModel(const QString &model); | 85 | void setModel(const QString &model); | ||
79 | void setScale(int scale); | 86 | void setScale(int scale); | ||
80 | void setSubPixel(SubPixel subPixel); | 87 | void setSubPixel(SubPixel subPixel); | ||
81 | void setTransform(Transform transform); | 88 | void setTransform(Transform transform); | ||
82 | void addMode(uint32_t flags, int32_t width, int32_t height, int32_t refresh, int32_t mode_id); | 89 | void addMode(uint32_t flags, int32_t width, int32_t height, int32_t refresh, int32_t mode_id); | ||
Show All 18 Lines | |||||
101 | bool OutputDevice::Mode::operator==(const OutputDevice::Mode &m) const | 108 | bool OutputDevice::Mode::operator==(const OutputDevice::Mode &m) const | ||
102 | { | 109 | { | ||
103 | return size == m.size | 110 | return size == m.size | ||
104 | && refreshRate == m.refreshRate | 111 | && refreshRate == m.refreshRate | ||
105 | && flags == m.flags | 112 | && flags == m.flags | ||
106 | && output == m.output; | 113 | && output == m.output; | ||
107 | } | 114 | } | ||
108 | 115 | | |||
116 | bool OutputDevice::ColorCurves::operator==(const OutputDevice::ColorCurves &cc) const | ||||
117 | { | ||||
118 | return red == cc.red && green == cc.green && blue == cc.blue; | ||||
119 | } | ||||
120 | bool OutputDevice::ColorCurves::operator!=(const ColorCurves &cc) const { | ||||
121 | return !operator==(cc); | ||||
122 | } | ||||
123 | | ||||
109 | OutputDevice::OutputDevice(QObject *parent) | 124 | OutputDevice::OutputDevice(QObject *parent) | ||
110 | : QObject(parent) | 125 | : QObject(parent) | ||
111 | , d(new Private(this)) | 126 | , d(new Private(this)) | ||
112 | { | 127 | { | ||
113 | } | 128 | } | ||
114 | 129 | | |||
115 | OutputDevice::~OutputDevice() | 130 | OutputDevice::~OutputDevice() | ||
116 | { | 131 | { | ||
117 | d->output.release(); | 132 | d->output.release(); | ||
118 | } | 133 | } | ||
119 | 134 | | |||
120 | org_kde_kwin_outputdevice_listener OutputDevice::Private::s_outputListener = { | 135 | org_kde_kwin_outputdevice_listener OutputDevice::Private::s_outputListener = { | ||
121 | geometryCallback, | 136 | geometryCallback, | ||
122 | modeCallback, | 137 | modeCallback, | ||
123 | doneCallback, | 138 | doneCallback, | ||
124 | scaleCallback, | 139 | scaleCallback, | ||
140 | colorcurvesCallback, | ||||
125 | edidCallback, | 141 | edidCallback, | ||
126 | enabledCallback, | 142 | enabledCallback, | ||
127 | uuidCallback | 143 | uuidCallback | ||
128 | }; | 144 | }; | ||
129 | 145 | | |||
130 | void OutputDevice::Private::geometryCallback(void *data, org_kde_kwin_outputdevice *output, | 146 | void OutputDevice::Private::geometryCallback(void *data, org_kde_kwin_outputdevice *output, | ||
131 | int32_t x, int32_t y, | 147 | int32_t x, int32_t y, | ||
132 | int32_t physicalWidth, int32_t physicalHeight, | 148 | int32_t physicalWidth, int32_t physicalHeight, | ||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Line(s) | 302 | if (o->uuid != uuid) { | |||
287 | o->uuid = uuid; | 303 | o->uuid = uuid; | ||
288 | emit o->q->uuidChanged(o->uuid); | 304 | emit o->q->uuidChanged(o->uuid); | ||
289 | if (o->done) { | 305 | if (o->done) { | ||
290 | emit o->q->changed(); | 306 | emit o->q->changed(); | ||
291 | } | 307 | } | ||
292 | } | 308 | } | ||
293 | } | 309 | } | ||
294 | 310 | | |||
311 | void OutputDevice::Private::colorcurvesCallback(void *data, org_kde_kwin_outputdevice *output, | ||||
312 | struct wl_array *red, | ||||
313 | struct wl_array *green, | ||||
314 | struct wl_array *blue) | ||||
315 | { | ||||
316 | Q_UNUSED(output); | ||||
317 | auto o = reinterpret_cast<OutputDevice::Private*>(data); | ||||
318 | | ||||
319 | auto cc = ColorCurves(); | ||||
320 | | ||||
321 | auto setCurve = [](struct wl_array *curve, QVector<quint16> *destination) { | ||||
zzag: That's not C so you can get rid of `struct` keyword. ;-)
Also, you could constify `curve` to… | |||||
322 | uint16_t *curvePtr = reinterpret_cast<uint16_t *>(curve->data); | ||||
323 | for (size_t i = 0; i < curve->size / sizeof(uint16_t); i++) { | ||||
You can do this all in once destination->resize(curve->size); davidedmundson: You can do this all in once
destination->resize(curve->size);
memcpy(...) | |||||
324 | destination->append(curvePtr[i]); | ||||
325 | } | ||||
326 | }; | ||||
327 | setCurve(red, &cc.red); | ||||
328 | setCurve(green, &cc.green); | ||||
329 | setCurve(blue, &cc.blue); | ||||
330 | | ||||
331 | if (o->colorCurves != cc) { | ||||
332 | o->colorCurves = cc; | ||||
333 | emit o->q->colorCurvesChanged(); | ||||
334 | if (o->done) { | ||||
335 | emit o->q->changed(); | ||||
336 | } | ||||
337 | } | ||||
338 | } | ||||
339 | | ||||
295 | void OutputDevice::setup(org_kde_kwin_outputdevice *output) | 340 | void OutputDevice::setup(org_kde_kwin_outputdevice *output) | ||
296 | { | 341 | { | ||
297 | d->setup(output); | 342 | d->setup(output); | ||
298 | } | 343 | } | ||
299 | 344 | | |||
300 | EventQueue *OutputDevice::eventQueue() const | 345 | EventQueue *OutputDevice::eventQueue() const | ||
301 | { | 346 | { | ||
302 | return d->queue; | 347 | return d->queue; | ||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Line(s) | 478 | { | |||
434 | return d->enabled; | 479 | return d->enabled; | ||
435 | } | 480 | } | ||
436 | 481 | | |||
437 | QByteArray OutputDevice::uuid() const | 482 | QByteArray OutputDevice::uuid() const | ||
438 | { | 483 | { | ||
439 | return d->uuid; | 484 | return d->uuid; | ||
440 | } | 485 | } | ||
441 | 486 | | |||
487 | OutputDevice::ColorCurves OutputDevice::colorCurves() const | ||||
488 | { | ||||
489 | return d->colorCurves; | ||||
490 | } | ||||
491 | | ||||
442 | void OutputDevice::destroy() | 492 | void OutputDevice::destroy() | ||
443 | { | 493 | { | ||
444 | d->output.destroy(); | 494 | d->output.destroy(); | ||
445 | 495 | | |||
446 | } | 496 | } | ||
447 | 497 | | |||
448 | } | 498 | } | ||
449 | } | 499 | } |
That's not C so you can get rid of struct keyword. ;-)
Also, you could constify curve to show that it's read-only.