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 | qreal scale = 1.0; | 58 | qreal scale = 1.0; | ||
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 = 2; | 86 | const quint32 OutputDeviceInterface::Private::s_version = 2; | ||
84 | 87 | | |||
▲ Show 20 Lines • Show All 49 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::scaleFChanged, this, [this, d] { d->updateScale(); }); | 144 | connect(this, &OutputDeviceInterface::scaleFChanged, this, [this, d] { d->updateScale(); }); | ||
145 | connect(this, &OutputDeviceInterface::scaleChanged, this, [this, d] { d->updateScale(); }); | ||||
146 | connect(this, &OutputDeviceInterface::colorCurvesChanged, this, [this, d] { d->updateColorCurves(); }); | ||||
142 | } | 147 | } | ||
143 | 148 | | |||
144 | OutputDeviceInterface::~OutputDeviceInterface() = default; | 149 | OutputDeviceInterface::~OutputDeviceInterface() = default; | ||
145 | 150 | | |||
146 | QSize OutputDeviceInterface::pixelSize() const | 151 | QSize OutputDeviceInterface::pixelSize() const | ||
147 | { | 152 | { | ||
148 | Q_D(); | 153 | Q_D(); | ||
149 | auto it = std::find_if(d->modes.begin(), d->modes.end(), | 154 | auto it = std::find_if(d->modes.begin(), d->modes.end(), | ||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Line(s) | 325 | { | |||
328 | wl_resource_set_destructor(resource, unbind); | 333 | wl_resource_set_destructor(resource, unbind); | ||
329 | ResourceData r; | 334 | ResourceData r; | ||
330 | r.resource = resource; | 335 | r.resource = resource; | ||
331 | r.version = version; | 336 | r.version = version; | ||
332 | resources << r; | 337 | resources << r; | ||
333 | 338 | | |||
334 | sendGeometry(resource); | 339 | sendGeometry(resource); | ||
335 | sendScale(r); | 340 | sendScale(r); | ||
341 | sendColorCurves(r); | ||||
336 | 342 | | |||
337 | auto currentModeIt = modes.constEnd(); | 343 | auto currentModeIt = modes.constEnd(); | ||
338 | for (auto it = modes.constBegin(); it != modes.constEnd(); ++it) { | 344 | for (auto it = modes.constBegin(); it != modes.constEnd(); ++it) { | ||
339 | const Mode &mode = *it; | 345 | const Mode &mode = *it; | ||
340 | if (mode.flags.testFlag(ModeFlag::Current)) { | 346 | if (mode.flags.testFlag(ModeFlag::Current)) { | ||
341 | // needs to be sent as last mode | 347 | // needs to be sent as last mode | ||
342 | currentModeIt = it; | 348 | currentModeIt = it; | ||
343 | continue; | 349 | continue; | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
404 | { | 410 | { | ||
405 | if (wl_resource_get_version(data.resource) < ORG_KDE_KWIN_OUTPUTDEVICE_SCALEF_SINCE_VERSION) { | 411 | if (wl_resource_get_version(data.resource) < ORG_KDE_KWIN_OUTPUTDEVICE_SCALEF_SINCE_VERSION) { | ||
406 | org_kde_kwin_outputdevice_send_scale(data.resource, qRound(scale)); | 412 | org_kde_kwin_outputdevice_send_scale(data.resource, qRound(scale)); | ||
407 | } else { | 413 | } else { | ||
408 | org_kde_kwin_outputdevice_send_scalef(data.resource, wl_fixed_from_double(scale)); | 414 | org_kde_kwin_outputdevice_send_scalef(data.resource, wl_fixed_from_double(scale)); | ||
409 | } | 415 | } | ||
410 | } | 416 | } | ||
411 | 417 | | |||
418 | void OutputDeviceInterface::Private::sendColorCurves(const ResourceData &data) | ||||
419 | { | ||||
420 | if (data.version < ORG_KDE_KWIN_OUTPUTDEVICE_COLORCURVES_SINCE_VERSION) { | ||||
421 | return; | ||||
422 | } | ||||
423 | | ||||
424 | wl_array wlRed, wlGreen, wlBlue; | ||||
425 | | ||||
zzag: constify origin?
Can't you memcpy here? | |||||
426 | auto fillArray = [](const QVector<quint16> &origin, wl_array *dest) { | ||||
427 | wl_array_init(dest); | ||||
428 | const size_t memLength = sizeof(uint16_t) * origin.size(); | ||||
429 | void *s = wl_array_add(dest, memLength); | ||||
430 | memcpy(s, origin.data(), memLength); | ||||
431 | }; | ||||
432 | fillArray(colorCurves.red, &wlRed); | ||||
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… | |||||
433 | fillArray(colorCurves.green, &wlGreen); | ||||
434 | fillArray(colorCurves.blue, &wlBlue); | ||||
435 | | ||||
436 | org_kde_kwin_outputdevice_send_colorcurves(data.resource, &wlRed, &wlGreen, &wlBlue); | ||||
437 | | ||||
438 | wl_array_release(&wlRed); | ||||
439 | wl_array_release(&wlGreen); | ||||
440 | wl_array_release(&wlBlue); | ||||
441 | } | ||||
442 | | ||||
412 | void OutputDeviceInterface::Private::sendDone(const ResourceData &data) | 443 | void OutputDeviceInterface::Private::sendDone(const ResourceData &data) | ||
413 | { | 444 | { | ||
414 | org_kde_kwin_outputdevice_send_done(data.resource); | 445 | org_kde_kwin_outputdevice_send_done(data.resource); | ||
415 | } | 446 | } | ||
416 | 447 | | |||
417 | void OutputDeviceInterface::Private::updateGeometry() | 448 | void OutputDeviceInterface::Private::updateGeometry() | ||
418 | { | 449 | { | ||
419 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | 450 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | ||
420 | sendGeometry((*it).resource); | 451 | sendGeometry((*it).resource); | ||
421 | sendDone(*it); | 452 | sendDone(*it); | ||
422 | } | 453 | } | ||
423 | } | 454 | } | ||
424 | 455 | | |||
425 | void OutputDeviceInterface::Private::updateScale() | 456 | void OutputDeviceInterface::Private::updateScale() | ||
426 | { | 457 | { | ||
427 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | 458 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | ||
428 | sendScale(*it); | 459 | sendScale(*it); | ||
429 | sendDone(*it); | 460 | sendDone(*it); | ||
430 | } | 461 | } | ||
431 | } | 462 | } | ||
432 | 463 | | |||
464 | void OutputDeviceInterface::Private::updateColorCurves() | ||||
465 | { | ||||
466 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | ||||
467 | sendColorCurves(*it); | ||||
468 | sendDone(*it); | ||||
469 | } | ||||
470 | } | ||||
471 | | ||||
472 | bool OutputDeviceInterface::ColorCurves::operator==(const ColorCurves &cc) const | ||||
473 | { | ||||
474 | return red == cc.red && green == cc.green && blue == cc.blue; | ||||
475 | } | ||||
476 | bool OutputDeviceInterface::ColorCurves::operator!=(const ColorCurves &cc) const { | ||||
477 | return !operator==(cc); | ||||
478 | } | ||||
479 | | ||||
433 | #define SETTER(setterName, type, argumentName) \ | 480 | #define SETTER(setterName, type, argumentName) \ | ||
434 | void OutputDeviceInterface::setterName(type arg) \ | 481 | void OutputDeviceInterface::setterName(type arg) \ | ||
435 | { \ | 482 | { \ | ||
436 | Q_D(); \ | 483 | Q_D(); \ | ||
437 | if (d->argumentName == arg) { \ | 484 | if (d->argumentName == arg) { \ | ||
438 | return; \ | 485 | return; \ | ||
439 | } \ | 486 | } \ | ||
440 | d->argumentName = arg; \ | 487 | d->argumentName = arg; \ | ||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | |||||
516 | } | 563 | } | ||
517 | 564 | | |||
518 | OutputDeviceInterface::Transform OutputDeviceInterface::transform() const | 565 | OutputDeviceInterface::Transform OutputDeviceInterface::transform() const | ||
519 | { | 566 | { | ||
520 | Q_D(); | 567 | Q_D(); | ||
521 | return d->transform; | 568 | return d->transform; | ||
522 | } | 569 | } | ||
523 | 570 | | |||
571 | OutputDeviceInterface::ColorCurves OutputDeviceInterface::colorCurves() const | ||||
572 | { | ||||
573 | Q_D(); | ||||
574 | return d->colorCurves; | ||||
575 | } | ||||
576 | | ||||
524 | QList< OutputDeviceInterface::Mode > OutputDeviceInterface::modes() const | 577 | QList< OutputDeviceInterface::Mode > OutputDeviceInterface::modes() const | ||
525 | { | 578 | { | ||
526 | Q_D(); | 579 | Q_D(); | ||
527 | return d->modes; | 580 | return d->modes; | ||
528 | } | 581 | } | ||
529 | 582 | | |||
530 | int OutputDeviceInterface::currentModeId() const | 583 | int OutputDeviceInterface::currentModeId() const | ||
531 | { | 584 | { | ||
532 | Q_D(); | 585 | Q_D(); | ||
533 | for (const Mode &m: d->modes) { | 586 | for (const Mode &m: d->modes) { | ||
534 | if (m.flags.testFlag(OutputDeviceInterface::ModeFlag::Current)) { | 587 | if (m.flags.testFlag(OutputDeviceInterface::ModeFlag::Current)) { | ||
535 | return m.id; | 588 | return m.id; | ||
536 | } | 589 | } | ||
537 | } | 590 | } | ||
538 | return -1; | 591 | return -1; | ||
539 | } | 592 | } | ||
540 | 593 | | |||
541 | OutputDeviceInterface::Private *OutputDeviceInterface::d_func() const | 594 | OutputDeviceInterface::Private *OutputDeviceInterface::d_func() const | ||
542 | { | 595 | { | ||
543 | return reinterpret_cast<Private*>(d.data()); | 596 | return reinterpret_cast<Private*>(d.data()); | ||
544 | } | 597 | } | ||
545 | 598 | | |||
599 | void OutputDeviceInterface::setColorCurves(const ColorCurves &colorCurves) | ||||
600 | { | ||||
601 | Q_D(); | ||||
602 | | ||||
603 | if (d->colorCurves == colorCurves) { | ||||
604 | return; | ||||
605 | } | ||||
606 | d->colorCurves = colorCurves; | ||||
607 | emit colorCurvesChanged(d->colorCurves); | ||||
608 | } | ||||
609 | | ||||
546 | void OutputDeviceInterface::setEdid(const QByteArray &edid) | 610 | void OutputDeviceInterface::setEdid(const QByteArray &edid) | ||
547 | { | 611 | { | ||
548 | Q_D(); | 612 | Q_D(); | ||
549 | d->edid = edid; | 613 | d->edid = edid; | ||
550 | d->sendEdid(); | 614 | d->sendEdid(); | ||
551 | emit edidChanged(); | 615 | emit edidChanged(); | ||
552 | } | 616 | } | ||
553 | 617 | | |||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |
constify origin?
Can't you memcpy here?