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();
51 *s_waylandManager = result;
102 if (event->type() == QEvent::PlatformSurface) {
103 QPlatformSurfaceEvent *pevent =
static_cast<QPlatformSurfaceEvent*
>(event);
104 if (pevent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
106 }
else if (pevent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
128 qWarning() <<
"WARNING: KisWaylandSurfaceColorManager::reinitialize(): received unbalanced connectionActive(true) signal!";
145 using feature = QtWayland::wp_color_manager_v1::feature;
149 qWarning() <<
"KisWaylandSurfaceColorManager: feature_parametric is not supported";
153 if (!
m_waylandManager->isFeatureSupported(feature::feature_set_primaries) &&
156 qWarning() <<
"KisWaylandSurfaceColorManager: feature_set_primaries is not supported, even though requested";
163 qWarning() <<
"KisWaylandSurfaceColorManager: feature_set_tf_power is not supported, even though requested";
167 if (!
m_waylandManager->isFeatureSupported(feature::feature_set_luminances) &&
170 qWarning() <<
"KisWaylandSurfaceColorManager: feature_set_luminances is not supported, even though requested";
174 if (!
m_waylandManager->isFeatureSupported(feature::feature_set_mastering_display_primaries) &&
177 qWarning() <<
"KisWaylandSurfaceColorManager: feature_set_mastering_display_primaries is not supported, even though requested";
181 if (!
m_waylandManager->isFeatureSupported(feature::feature_extended_target_volume) &&
186 qWarning() <<
"KisWaylandSurfaceColorManager: feature_set_mastering_display_primaries is not supported, even though requested";
191 if (std::holds_alternative<KisSurfaceColorimetry::NamedPrimaries>(desc.
colorSpace.
primaries)) {
192 auto waylandPrimaries = primariesKritaToWayland(std::get<KisSurfaceColorimetry::NamedPrimaries>(desc.
colorSpace.
primaries));
199 auto waylandTransferFunction = transferFunctionKritaToWayland(std::get<KisSurfaceColorimetry::NamedTransferFunction>(desc.
colorSpace.
transferFunction));
208 if (waylandTransferFunction == QtWayland::wp_color_manager_v1::transfer_function_srgb ||
209 waylandTransferFunction == QtWayland::wp_color_manager_v1::transfer_function_ext_srgb) {
214 if (!
m_waylandManager->isTransferFunctionNamedSupported(waylandTransferFunction))
223 auto waylandIntent = renderIntentKritaToWayland(intent);
227#define USE_KWIN_BUG_WORKAROUND
229#ifdef USE_KWIN_BUG_WORKAROUND
230#include "wayland-wayland-client-protocol.h"
236 qWarning() <<
"ERROR: KisWaylandSurfaceColorManager::setSurfaceDescription: the manager is not ready";
237 return makeReadyQFuture(
false);
242 auto waylandDescription = WaylandSurfaceDescription::fromSurfaceDescription(desc);
243 auto waylandIntent = renderIntentKritaToWayland(intent);
246 qWarning() <<
"ERROR: KisWaylandSurfaceColorManager::setSurfaceDescription: unsupported surface description";
247 return makeReadyQFuture(
false);
251 qWarning() <<
"ERROR: KisWaylandSurfaceColorManager::setSurfaceDescription: unsupported rendering intent";
252 return makeReadyQFuture(
false);
256 std::shared_ptr<KisWaylandAPIImageDescriptionNoInfo> descriptionObject =
259 QPromise<bool> imageDescriptionPromise;
260 auto future = imageDescriptionPromise.future();
264 [promise = std::move(imageDescriptionPromise), descriptionObject] (
bool success)
mutable {
266 promise.addResult(success);
271 future.then([
this, desc, descriptionObject, waylandIntent, intent] (
QFuture<bool> future) {
272 if (!future.result())
return false;
275 qWarning() <<
"WARNING: the surface has been destroyed while its format was being set!";
279#ifdef USE_KWIN_BUG_WORKAROUND
280 if (qEnvironmentVariableIsSet(
"KRITA_ENABLE_KWIN_INTENT_WORKAROUND")) {
286 auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
287 ::wl_surface_commit(waylandWindow->surface());
292 m_surface->set_image_description(descriptionObject->object(), waylandIntent);
345 qWarning() <<
"WARNING: KisWaylandSurfaceColorManager::slotPlatformWindowCreated(): received unbalanced window created signal!";
355 qWarning() <<
"WARNING: KisWaylandSurfaceColorManager::slotPlatformWindowCreated(): failed to reach WaylandWindowCreated state";
372 qWarning() <<
"WARNING: KisWaylandSurfaceColorManager::slotWaylandSurfaceCreated(): received unbalanced surface created signal!";
382 qWarning() <<
"WARNING: KisWaylandSurfaceColorManager::slotWaylandSurfaceCreated(): failed to reach WaylandSurfaceCreated state";
421 m_window->installEventFilter(filter);
425 auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
432 auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
436 &QNativeInterface::Private::QWaylandWindow::surfaceCreated,
443 &QNativeInterface::Private::QWaylandWindow::surfaceDestroyed,
448 if (waylandWindow->surface()) {
454 auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
457 auto feedback = std::make_unique<KisWaylandAPISurfaceFeedback>(
459 connect(feedback.get(),
464 std::move(feedback));
471 if (
m_surface->m_feedback->m_preferred->info.isReady()) {
472 auto waylandDesc =
m_surface->m_feedback->m_preferred->info.m_data;
487 if (!targetState || *targetState < currentState) {
495 auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
497 if (!waylandWindow || !waylandWindow->surface() ||
498 (targetState && *targetState < currentState)) {
504 if (!waylandWindow || !waylandWindow->surface() ||
505 (targetState && *targetState < currentState)) {
510 if (!waylandWindow || (targetState && *targetState < currentState)) {
520 if (!
m_waylandManager->isReady() || (targetState && *targetState < currentState)) {
531#include <moc_KisWaylandSurfaceColorManager.cpp>
532#include <KisWaylandSurfaceColorManager.moc>
float value(const T *src, size_t ch)
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
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