Changeset View
Changeset View
Standalone View
Standalone View
src/server/outputdevice_interface.cpp
Show All 39 Lines | 36 | public: | |||
---|---|---|---|---|---|
40 | }; | 40 | }; | ||
41 | Private(OutputDeviceInterface *q, Display *d); | 41 | Private(OutputDeviceInterface *q, Display *d); | ||
42 | ~Private(); | 42 | ~Private(); | ||
43 | 43 | | |||
44 | void sendMode(wl_resource *resource, const Mode &mode); | 44 | void sendMode(wl_resource *resource, const Mode &mode); | ||
45 | void sendDone(const ResourceData &data); | 45 | void sendDone(const ResourceData &data); | ||
46 | void updateGeometry(); | 46 | void updateGeometry(); | ||
47 | void updateScale(); | 47 | void updateScale(); | ||
48 | void updateColorCurves(); | ||||
48 | 49 | | |||
49 | void sendUuid(); | 50 | void sendUuid(); | ||
50 | void sendEdid(); | 51 | void sendEdid(); | ||
51 | void sendEnabled(); | 52 | void sendEnabled(); | ||
52 | 53 | | |||
53 | QSize physicalSize; | 54 | QSize physicalSize; | ||
54 | QPoint globalPosition; | 55 | QPoint globalPosition; | ||
55 | QString manufacturer = QStringLiteral("org.kde.kwin"); | 56 | QString manufacturer = QStringLiteral("org.kde.kwin"); | ||
56 | QString model = QStringLiteral("none"); | 57 | QString model = QStringLiteral("none"); | ||
57 | int scale = 1; | 58 | int scale = 1; | ||
58 | SubPixel subPixel = SubPixel::Unknown; | 59 | SubPixel subPixel = SubPixel::Unknown; | ||
59 | Transform transform = Transform::Normal; | 60 | Transform transform = Transform::Normal; | ||
61 | ColorCurves colorCurves; | ||||
60 | QList<Mode> modes; | 62 | QList<Mode> modes; | ||
61 | QList<ResourceData> resources; | 63 | QList<ResourceData> resources; | ||
62 | 64 | | |||
63 | QByteArray edid; | 65 | QByteArray edid; | ||
64 | Enablement enabled = Enablement::Enabled; | 66 | Enablement enabled = Enablement::Enabled; | ||
65 | QByteArray uuid; | 67 | QByteArray uuid; | ||
66 | 68 | | |||
67 | static OutputDeviceInterface *get(wl_resource *native); | 69 | static OutputDeviceInterface *get(wl_resource *native); | ||
68 | 70 | | |||
69 | private: | 71 | private: | ||
70 | static Private *cast(wl_resource *native); | 72 | static Private *cast(wl_resource *native); | ||
71 | static void unbind(wl_resource *resource); | 73 | static void unbind(wl_resource *resource); | ||
72 | void bind(wl_client *client, uint32_t version, uint32_t id) override; | 74 | void bind(wl_client *client, uint32_t version, uint32_t id) override; | ||
73 | int32_t toTransform() const; | 75 | int32_t toTransform() const; | ||
74 | int32_t toSubPixel() const; | 76 | int32_t toSubPixel() const; | ||
75 | void sendGeometry(wl_resource *resource); | 77 | void sendGeometry(wl_resource *resource); | ||
76 | void sendScale(const ResourceData &data); | 78 | void sendScale(const ResourceData &data); | ||
79 | void sendColorCurves(const ResourceData &data); | ||||
77 | 80 | | |||
78 | static const quint32 s_version; | 81 | static const quint32 s_version; | ||
79 | OutputDeviceInterface *q; | 82 | OutputDeviceInterface *q; | ||
80 | static QVector<Private*> s_privates; | 83 | static QVector<Private*> s_privates; | ||
81 | }; | 84 | }; | ||
82 | 85 | | |||
83 | const quint32 OutputDeviceInterface::Private::s_version = 1; | 86 | const quint32 OutputDeviceInterface::Private::s_version = 2; | ||
84 | 87 | | |||
85 | QVector<OutputDeviceInterface::Private*> OutputDeviceInterface::Private::s_privates; | 88 | QVector<OutputDeviceInterface::Private*> OutputDeviceInterface::Private::s_privates; | ||
86 | 89 | | |||
87 | OutputDeviceInterface::Private::Private(OutputDeviceInterface *q, Display *d) | 90 | OutputDeviceInterface::Private::Private(OutputDeviceInterface *q, Display *d) | ||
88 | : Global::Private(d, &org_kde_kwin_outputdevice_interface, s_version) | 91 | : Global::Private(d, &org_kde_kwin_outputdevice_interface, s_version) | ||
89 | , q(q) | 92 | , q(q) | ||
90 | { | 93 | { | ||
91 | s_privates << this; | 94 | s_privates << this; | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 126 | connect(this, &OutputDeviceInterface::currentModeChanged, this, | |||
134 | } | 137 | } | ||
135 | ); | 138 | ); | ||
136 | connect(this, &OutputDeviceInterface::subPixelChanged, this, [this, d] { d->updateGeometry(); }); | 139 | connect(this, &OutputDeviceInterface::subPixelChanged, this, [this, d] { d->updateGeometry(); }); | ||
137 | connect(this, &OutputDeviceInterface::transformChanged, this, [this, d] { d->updateGeometry(); }); | 140 | connect(this, &OutputDeviceInterface::transformChanged, this, [this, d] { d->updateGeometry(); }); | ||
138 | connect(this, &OutputDeviceInterface::globalPositionChanged, this, [this, d] { d->updateGeometry(); }); | 141 | connect(this, &OutputDeviceInterface::globalPositionChanged, this, [this, d] { d->updateGeometry(); }); | ||
139 | connect(this, &OutputDeviceInterface::modelChanged, this, [this, d] { d->updateGeometry(); }); | 142 | connect(this, &OutputDeviceInterface::modelChanged, this, [this, d] { d->updateGeometry(); }); | ||
140 | connect(this, &OutputDeviceInterface::manufacturerChanged, this, [this, d] { d->updateGeometry(); }); | 143 | connect(this, &OutputDeviceInterface::manufacturerChanged, this, [this, d] { d->updateGeometry(); }); | ||
141 | connect(this, &OutputDeviceInterface::scaleChanged, this, [this, d] { d->updateScale(); }); | 144 | connect(this, &OutputDeviceInterface::scaleChanged, this, [this, d] { d->updateScale(); }); | ||
145 | connect(this, &OutputDeviceInterface::colorCurvesChanged, this, [this, d] { d->updateColorCurves(); }); | ||||
142 | } | 146 | } | ||
143 | 147 | | |||
144 | OutputDeviceInterface::~OutputDeviceInterface() = default; | 148 | OutputDeviceInterface::~OutputDeviceInterface() = default; | ||
145 | 149 | | |||
146 | QSize OutputDeviceInterface::pixelSize() const | 150 | QSize OutputDeviceInterface::pixelSize() const | ||
147 | { | 151 | { | ||
148 | Q_D(); | 152 | Q_D(); | ||
149 | auto it = std::find_if(d->modes.begin(), d->modes.end(), | 153 | auto it = std::find_if(d->modes.begin(), d->modes.end(), | ||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Line(s) | 324 | { | |||
328 | wl_resource_set_destructor(resource, unbind); | 332 | wl_resource_set_destructor(resource, unbind); | ||
329 | ResourceData r; | 333 | ResourceData r; | ||
330 | r.resource = resource; | 334 | r.resource = resource; | ||
331 | r.version = version; | 335 | r.version = version; | ||
332 | resources << r; | 336 | resources << r; | ||
333 | 337 | | |||
334 | sendGeometry(resource); | 338 | sendGeometry(resource); | ||
335 | sendScale(r); | 339 | sendScale(r); | ||
340 | sendColorCurves(r); | ||||
336 | 341 | | |||
337 | auto currentModeIt = modes.constEnd(); | 342 | auto currentModeIt = modes.constEnd(); | ||
338 | for (auto it = modes.constBegin(); it != modes.constEnd(); ++it) { | 343 | for (auto it = modes.constBegin(); it != modes.constEnd(); ++it) { | ||
339 | const Mode &mode = *it; | 344 | const Mode &mode = *it; | ||
340 | if (mode.flags.testFlag(ModeFlag::Current)) { | 345 | if (mode.flags.testFlag(ModeFlag::Current)) { | ||
341 | // needs to be sent as last mode | 346 | // needs to be sent as last mode | ||
342 | currentModeIt = it; | 347 | currentModeIt = it; | ||
343 | continue; | 348 | continue; | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 397 | org_kde_kwin_outputdevice_send_geometry(resource, | |||
400 | toTransform()); | 405 | toTransform()); | ||
401 | } | 406 | } | ||
402 | 407 | | |||
403 | void OutputDeviceInterface::Private::sendScale(const ResourceData &data) | 408 | void OutputDeviceInterface::Private::sendScale(const ResourceData &data) | ||
404 | { | 409 | { | ||
405 | org_kde_kwin_outputdevice_send_scale(data.resource, scale); | 410 | org_kde_kwin_outputdevice_send_scale(data.resource, scale); | ||
406 | } | 411 | } | ||
407 | 412 | | |||
413 | void OutputDeviceInterface::Private::sendColorCurves(const ResourceData &data) | ||||
414 | { | ||||
415 | wl_array wlRed, wlGreen, wlBlue; | ||||
416 | wl_array_init(&wlRed); | ||||
417 | wl_array_init(&wlGreen); | ||||
418 | wl_array_init(&wlBlue); | ||||
419 | | ||||
420 | auto fillArray = [](QVector<quint16> &origin, wl_array *dest) { | ||||
zzag: constify origin?
Can't you memcpy here? | |||||
421 | for (auto c : origin) { | ||||
422 | uint16_t *s = reinterpret_cast<uint16_t*>(wl_array_add(dest, sizeof(uint16_t))); | ||||
423 | *s = (uint16_t)c; | ||||
424 | } | ||||
425 | }; | ||||
426 | fillArray(colorCurves.red, &wlRed); | ||||
427 | fillArray(colorCurves.green, &wlGreen); | ||||
you need to do a version check and only send to clients which have the required version. A FOO_SINCE macro should be defined by the generated wayland header. graesslin: you need to do a version check and only send to clients which have the required version. A… | |||||
428 | fillArray(colorCurves.blue, &wlBlue); | ||||
429 | | ||||
430 | org_kde_kwin_outputdevice_send_colorcurves(data.resource, &wlRed, &wlGreen, &wlBlue); | ||||
431 | | ||||
432 | wl_array_release(&wlRed); | ||||
433 | wl_array_release(&wlGreen); | ||||
434 | wl_array_release(&wlBlue); | ||||
435 | } | ||||
436 | | ||||
408 | void OutputDeviceInterface::Private::sendDone(const ResourceData &data) | 437 | void OutputDeviceInterface::Private::sendDone(const ResourceData &data) | ||
409 | { | 438 | { | ||
410 | org_kde_kwin_outputdevice_send_done(data.resource); | 439 | org_kde_kwin_outputdevice_send_done(data.resource); | ||
411 | } | 440 | } | ||
412 | 441 | | |||
413 | void OutputDeviceInterface::Private::updateGeometry() | 442 | void OutputDeviceInterface::Private::updateGeometry() | ||
414 | { | 443 | { | ||
415 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | 444 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | ||
416 | sendGeometry((*it).resource); | 445 | sendGeometry((*it).resource); | ||
417 | sendDone(*it); | 446 | sendDone(*it); | ||
418 | } | 447 | } | ||
419 | } | 448 | } | ||
420 | 449 | | |||
421 | void OutputDeviceInterface::Private::updateScale() | 450 | void OutputDeviceInterface::Private::updateScale() | ||
422 | { | 451 | { | ||
423 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | 452 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | ||
424 | sendScale(*it); | 453 | sendScale(*it); | ||
425 | sendDone(*it); | 454 | sendDone(*it); | ||
426 | } | 455 | } | ||
427 | } | 456 | } | ||
428 | 457 | | |||
458 | void OutputDeviceInterface::Private::updateColorCurves() | ||||
459 | { | ||||
460 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | ||||
461 | sendColorCurves(*it); | ||||
462 | sendDone(*it); | ||||
463 | } | ||||
464 | } | ||||
465 | | ||||
466 | bool OutputDeviceInterface::ColorCurves::operator==(const ColorCurves &cc) const | ||||
467 | { | ||||
468 | return red == cc.red && green == cc.green && blue == cc.blue; | ||||
469 | } | ||||
470 | bool OutputDeviceInterface::ColorCurves::operator!=(const ColorCurves &cc) const { | ||||
471 | return !operator==(cc); | ||||
472 | } | ||||
473 | | ||||
429 | #define SETTER(setterName, type, argumentName) \ | 474 | #define SETTER(setterName, type, argumentName) \ | ||
430 | void OutputDeviceInterface::setterName(type arg) \ | 475 | void OutputDeviceInterface::setterName(type arg) \ | ||
431 | { \ | 476 | { \ | ||
432 | Q_D(); \ | 477 | Q_D(); \ | ||
433 | if (d->argumentName == arg) { \ | 478 | if (d->argumentName == arg) { \ | ||
434 | return; \ | 479 | return; \ | ||
435 | } \ | 480 | } \ | ||
436 | d->argumentName = arg; \ | 481 | d->argumentName = arg; \ | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
484 | } | 529 | } | ||
485 | 530 | | |||
486 | OutputDeviceInterface::Transform OutputDeviceInterface::transform() const | 531 | OutputDeviceInterface::Transform OutputDeviceInterface::transform() const | ||
487 | { | 532 | { | ||
488 | Q_D(); | 533 | Q_D(); | ||
489 | return d->transform; | 534 | return d->transform; | ||
490 | } | 535 | } | ||
491 | 536 | | |||
537 | OutputDeviceInterface::ColorCurves OutputDeviceInterface::colorCurves() const | ||||
538 | { | ||||
539 | Q_D(); | ||||
540 | return d->colorCurves; | ||||
541 | } | ||||
542 | | ||||
492 | QList< OutputDeviceInterface::Mode > OutputDeviceInterface::modes() const | 543 | QList< OutputDeviceInterface::Mode > OutputDeviceInterface::modes() const | ||
493 | { | 544 | { | ||
494 | Q_D(); | 545 | Q_D(); | ||
495 | return d->modes; | 546 | return d->modes; | ||
496 | } | 547 | } | ||
497 | 548 | | |||
498 | int OutputDeviceInterface::currentModeId() const | 549 | int OutputDeviceInterface::currentModeId() const | ||
499 | { | 550 | { | ||
500 | Q_D(); | 551 | Q_D(); | ||
501 | for (const Mode &m: d->modes) { | 552 | for (const Mode &m: d->modes) { | ||
502 | if (m.flags.testFlag(OutputDeviceInterface::ModeFlag::Current)) { | 553 | if (m.flags.testFlag(OutputDeviceInterface::ModeFlag::Current)) { | ||
503 | return m.id; | 554 | return m.id; | ||
504 | } | 555 | } | ||
505 | } | 556 | } | ||
506 | return -1; | 557 | return -1; | ||
507 | } | 558 | } | ||
508 | 559 | | |||
509 | OutputDeviceInterface::Private *OutputDeviceInterface::d_func() const | 560 | OutputDeviceInterface::Private *OutputDeviceInterface::d_func() const | ||
510 | { | 561 | { | ||
511 | return reinterpret_cast<Private*>(d.data()); | 562 | return reinterpret_cast<Private*>(d.data()); | ||
512 | } | 563 | } | ||
513 | 564 | | |||
565 | void OutputDeviceInterface::setColorCurves(const ColorCurves &colorCurves) | ||||
566 | { | ||||
567 | Q_D(); | ||||
568 | | ||||
569 | if (d->colorCurves == colorCurves) { | ||||
570 | return; | ||||
571 | } | ||||
572 | d->colorCurves = colorCurves; | ||||
573 | emit colorCurvesChanged(d->colorCurves); | ||||
574 | } | ||||
575 | | ||||
514 | void OutputDeviceInterface::setEdid(const QByteArray &edid) | 576 | void OutputDeviceInterface::setEdid(const QByteArray &edid) | ||
515 | { | 577 | { | ||
516 | Q_D(); | 578 | Q_D(); | ||
517 | d->edid = edid; | 579 | d->edid = edid; | ||
518 | d->sendEdid(); | 580 | d->sendEdid(); | ||
519 | emit edidChanged(); | 581 | emit edidChanged(); | ||
520 | } | 582 | } | ||
521 | 583 | | |||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |
constify origin?
Can't you memcpy here?