12#include <QPlatformSurfaceEvent>
14#include <qpa/qplatformnativeinterface.h>
15#include <qpa/qplatformwindow_p.h>
27 QPromise<std::decay_t<T>> promise;
29 promise.addResult(std::forward<T>(
value));
31 return promise.future();
35Q_GLOBAL_STATIC(std::weak_ptr<KisWaylandAPIColorManager>, s_waylandManager)
39 std::shared_ptr<KisWaylandAPIColorManager> result;
41 if (s_waylandManager.exists()) {
42 result = s_waylandManager->lock();
45 *s_waylandManager = result;
96 if (event->type() == QEvent::PlatformSurface) {
97 QPlatformSurfaceEvent *pevent =
static_cast<QPlatformSurfaceEvent*
>(event);
98 if (pevent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
100 }
else if (pevent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
122 qWarning() <<
"WARNING: KisWaylandSurfaceColorManager::reinitialize(): received unbalanced connectionActive(true) signal!";
139 using feature = QtWayland::wp_color_manager_v1::feature;
143 qWarning() <<
"KisWaylandSurfaceColorManager: feature_parametric is not supported";
147 if (!
m_waylandManager->isFeatureSupported(feature::feature_set_primaries) &&
150 qWarning() <<
"KisWaylandSurfaceColorManager: feature_set_primaries is not supported, even though requested";
157 qWarning() <<
"KisWaylandSurfaceColorManager: feature_set_tf_power is not supported, even though requested";
161 if (!
m_waylandManager->isFeatureSupported(feature::feature_set_luminances) &&
164 qWarning() <<
"KisWaylandSurfaceColorManager: feature_set_luminances is not supported, even though requested";
168 if (!
m_waylandManager->isFeatureSupported(feature::feature_set_mastering_display_primaries) &&
171 qWarning() <<
"KisWaylandSurfaceColorManager: feature_set_mastering_display_primaries is not supported, even though requested";
175 if (!
m_waylandManager->isFeatureSupported(feature::feature_extended_target_volume) &&
180 qWarning() <<
"KisWaylandSurfaceColorManager: feature_set_mastering_display_primaries is not supported, even though requested";
185 if (std::holds_alternative<KisSurfaceColorimetry::NamedPrimaries>(desc.
colorSpace.
primaries)) {
186 auto waylandPrimaries = primariesKritaToWayland(std::get<KisSurfaceColorimetry::NamedPrimaries>(desc.
colorSpace.
primaries));
193 auto waylandTransferFunction = transferFunctionKritaToWayland(std::get<KisSurfaceColorimetry::NamedTransferFunction>(desc.
colorSpace.
transferFunction));
202 if (waylandTransferFunction == QtWayland::wp_color_manager_v1::transfer_function_srgb ||
203 waylandTransferFunction == QtWayland::wp_color_manager_v1::transfer_function_ext_srgb) {
208 if (!
m_waylandManager->isTransferFunctionNamedSupported(waylandTransferFunction))
217 auto waylandIntent = renderIntentKritaToWayland(intent);
221#define USE_KWIN_BUG_WORKAROUND
223#ifdef USE_KWIN_BUG_WORKAROUND
224#include "wayland-wayland-client-protocol.h"
230 qWarning() <<
"ERROR: KisWaylandSurfaceColorManager::setSurfaceDescription: the manager is not ready";
231 return makeReadyQFuture(
false);
236 auto waylandDescription = WaylandSurfaceDescription::fromSurfaceDescription(desc);
237 auto waylandIntent = renderIntentKritaToWayland(intent);
240 qWarning() <<
"ERROR: KisWaylandSurfaceColorManager::setSurfaceDescription: unsupported surface description";
241 return makeReadyQFuture(
false);
245 qWarning() <<
"ERROR: KisWaylandSurfaceColorManager::setSurfaceDescription: unsupported rendering intent";
246 return makeReadyQFuture(
false);
250 std::shared_ptr<KisWaylandAPIImageDescriptionNoInfo> descriptionObject =
253 QPromise<bool> imageDescriptionPromise;
254 auto future = imageDescriptionPromise.future();
258 [promise = std::move(imageDescriptionPromise), descriptionObject] (
bool success)
mutable {
260 promise.addResult(success);
265 future.then([
this, desc, descriptionObject, waylandIntent, intent] (
QFuture<bool> future) {
266 if (!future.result())
return false;
269 qWarning() <<
"WARNING: the surface has been destroyed while its format was being set!";
273#ifdef USE_KWIN_BUG_WORKAROUND
274 if (qEnvironmentVariableIsSet(
"KRITA_ENABLE_KWIN_INTENT_WORKAROUND")) {
280 auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
281 ::wl_surface_commit(waylandWindow->surface());
286 m_surface->set_image_description(descriptionObject->object(), waylandIntent);
339 qWarning() <<
"WARNING: KisWaylandSurfaceColorManager::slotPlatformWindowCreated(): received unbalanced window created signal!";
349 qWarning() <<
"WARNING: KisWaylandSurfaceColorManager::slotPlatformWindowCreated(): failed to reach WaylandWindowCreated state";
366 qWarning() <<
"WARNING: KisWaylandSurfaceColorManager::slotWaylandSurfaceCreated(): received unbalanced surface created signal!";
376 qWarning() <<
"WARNING: KisWaylandSurfaceColorManager::slotWaylandSurfaceCreated(): failed to reach WaylandSurfaceCreated state";
415 m_window->installEventFilter(filter);
419 auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
426 auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
430 &QNativeInterface::Private::QWaylandWindow::surfaceCreated,
437 &QNativeInterface::Private::QWaylandWindow::surfaceDestroyed,
442 if (waylandWindow->surface()) {
448 auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
451 auto feedback = std::make_unique<KisWaylandAPISurfaceFeedback>(
458 std::move(feedback));
465 if (
m_surface->m_feedback->m_preferred->info.isReady()) {
466 auto waylandDesc =
m_surface->m_feedback->m_preferred->info.m_data;
481 if (!targetState || *targetState < currentState) {
489 auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
491 if (!waylandWindow || !waylandWindow->surface() ||
492 (targetState && *targetState < currentState)) {
498 if (!waylandWindow || !waylandWindow->surface() ||
499 (targetState && *targetState < currentState)) {
504 if (!waylandWindow || (targetState && *targetState < currentState)) {
514 if (!
m_waylandManager->isReady() || (targetState && *targetState < currentState)) {
525#include <moc_KisWaylandSurfaceColorManager.cpp>
526#include <KisWaylandSurfaceColorManager.moc>
float value(const T *src, size_t ch)
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void sigReadyChanged(bool value)
void sigPreferredSurfaceDescriptionChanged(const KisSurfaceColorimetry::SurfaceDescription &desc)
void sigReadyChanged(bool value)
std::unique_ptr< KisWaylandAPIImageDescriptionNoInfo > createImageDescription(const KisSurfaceColorimetry::WaylandSurfaceDescription &data)
Q_SIGNAL void sigDescriptionConstructed(bool success)
Q_SIGNAL void preferredChanged()
void setReadyImpl(bool value)
bool supportsSurfaceDescription(const KisSurfaceColorimetry::SurfaceDescription &desc) override
static std::shared_ptr< KisWaylandAPIColorManager > getOrCreateGlobalWaylandManager()
QFuture< bool > setSurfaceDescription(const KisSurfaceColorimetry::SurfaceDescription &desc, KisSurfaceColorimetry::RenderIntent intent) override
std::optional< KisSurfaceColorimetry::RenderIntent > m_renderingIntent
QMetaObject::Connection m_surfaceCreatedConnection
bool isReady() const override
WaylandSurfaceState m_currentState
void slotWaylandSurfaceDestroyed()
std::unique_ptr< KisWaylandAPISurface > m_surface
std::optional< KisSurfaceColorimetry::SurfaceDescription > preferredSurfaceDescription() const override
WaylandSurfaceState tryDeinitialize(std::optional< KisWaylandSurfaceColorManager::WaylandSurfaceState > targetState)
void slotPlatformWindowCreated()
~KisWaylandSurfaceColorManager() override
@ PreferredDescriptionReceived
WaylandSurfaceState tryInitilize()
std::optional< KisSurfaceColorimetry::SurfaceDescription > surfaceDescription() const override
void slotPlatformWindowDestroyed()
void slotWaylandSurfaceCreated()
QPointer< QObject > m_platformWindowStateDetector
bool supportsRenderIntent(const KisSurfaceColorimetry::RenderIntent &intent) override
void unsetSurfaceDescription() override
std::optional< KisSurfaceColorimetry::SurfaceDescription > m_currentDescription
std::shared_ptr< KisWaylandAPIColorManager > m_waylandManager
std::optional< KisSurfaceColorimetry::RenderIntent > renderingIntent() const override
void slotPreferredChanged()
std::optional< KisSurfaceColorimetry::SurfaceDescription > m_preferredDescription
KisWaylandSurfaceColorManager(QWindow *window, QObject *parent=nullptr)
QMetaObject::Connection m_surfaceDestroyedConnection
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
std::optional< Luminance > luminance
std::variant< NamedPrimaries, Colorimetry > primaries
std::variant< NamedTransferFunction, uint32_t > transferFunction
std::optional< MasteringInfo > masteringInfo