Skip to content

Commit f9e0387

Browse files
committed
wayland: support cm
1 parent 34a758f commit f9e0387

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ protocolnew("staging/ext-session-lock" "ext-session-lock-v1" false)
133133
protocolnew("stable/tablet" "tablet-v2" false)
134134
protocolnew("unstable/text-input" "text-input-unstable-v3" false)
135135
protocolnew("staging/linux-drm-syncobj" "linux-drm-syncobj-v1" false)
136+
protocolnew("staging/color-management" "color-management-v1" false)
136137
protocolnew("protocols" "wlr-layer-shell-unstable-v1" true)
137138

138139
# Tests

src/core/platforms/WaylandPlatform.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ bool CWaylandPlatform::attempt() {
110110
TRACE(g_logger->log(HT_LOG_TRACE, " > binding to global: {} (version {}) with id {}", name, 1, id));
111111
m_waylandState.sessionLock = makeShared<CCExtSessionLockManagerV1>(
112112
(wl_proxy*)wl_registry_bind((wl_registry*)m_waylandState.registry->resource(), id, &ext_session_lock_manager_v1_interface, 1));
113+
} else if (NAME == wp_color_manager_v1_interface.name) {
114+
TRACE(g_logger->log(HT_LOG_TRACE, " > binding to global: {} (version {}) with id {}", name, 1, id));
115+
m_waylandState.colorManagement =
116+
makeShared<CCWpColorManagerV1>((wl_proxy*)wl_registry_bind((wl_registry*)m_waylandState.registry->resource(), id, &wp_color_manager_v1_interface, 1));
113117
}
114118
});
115119
m_waylandState.registry->setGlobalRemove([this](CCWlRegistry* r, uint32_t id) {

src/core/platforms/WaylandPlatform.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <wlr-layer-shell-unstable-v1.hpp>
2626
#include <linux-drm-syncobj-v1.hpp>
2727
#include <ext-session-lock-v1.hpp>
28+
#include <color-management-v1.hpp>
2829

2930
#include <aquamarine/allocator/GBM.hpp>
3031
#include <aquamarine/backend/Misc.hpp>
@@ -91,6 +92,7 @@ namespace Hyprtoolkit {
9192
Hyprutils::Memory::CSharedPointer<CCZwlrLayerShellV1> layerShell;
9293
Hyprutils::Memory::CSharedPointer<CCWpLinuxDrmSyncobjManagerV1> syncobj;
9394
Hyprutils::Memory::CSharedPointer<CCExtSessionLockManagerV1> sessionLock;
95+
Hyprutils::Memory::CSharedPointer<CCWpColorManagerV1> colorManagement;
9496

9597
// control
9698
bool initialized = false;

src/window/IWaylandWindow.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void IWaylandWindow::configure(const Vector2D& size, uint32_t serial) {
6363

6464
resizeSwapchain(m_waylandState.size);
6565
damageEntire();
66+
ensureCMReady();
6667

6768
m_rootElement->reposition({0, 0, m_waylandState.logicalSize.x, m_waylandState.logicalSize.y});
6869
}
@@ -173,6 +174,8 @@ void IWaylandWindow::render() {
173174
if (!currentBuffer)
174175
return;
175176

177+
applyCMToSurface();
178+
176179
m_needsFrame = false;
177180

178181
g_renderer->beginRendering(m_self.lock(), currentBuffer->m_buffer.lock());
@@ -286,3 +289,42 @@ void IWaylandWindow::resetIM() {
286289
m_currentInput = "";
287290
m_currentInputCursor = 0;
288291
}
292+
293+
void IWaylandWindow::ensureCMReady() {
294+
if (m_waylandState.cmImageDesc || m_waylandState.cmSurface)
295+
return;
296+
297+
m_waylandState.cmSurface = makeShared<CCWpColorManagementSurfaceV1>(g_waylandPlatform->m_waylandState.colorManagement->sendGetSurface(m_waylandState.surface->resource()));
298+
299+
// create our image description.
300+
auto imageDesc = makeShared<CCWpImageDescriptionCreatorParamsV1>(g_waylandPlatform->m_waylandState.colorManagement->sendCreateParametricCreator());
301+
302+
// Because we don't actually give a flying fuck about color in our renderer... at the moment (FIXME: I wanna write an image viewer, proper colors would be nice...)
303+
// we essentially do an srgb kinda...
304+
305+
// FIXME: for some reason this is correct while named sRGB isn't. Hyprland bug probably. Needs a hl patch.
306+
constexpr const int32_t MILLION = 1000000;
307+
imageDesc->sendSetPrimaries( //
308+
0.64 * MILLION, 0.33 * MILLION, // r
309+
0.3 * MILLION, 0.6 * MILLION, // g
310+
0.15 * MILLION, 0.06 * MILLION, // b
311+
0.3127 * MILLION, 0.329 * MILLION // D65 white point
312+
);
313+
imageDesc->sendSetTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB);
314+
m_waylandState.cmImageDesc = makeShared<CCWpImageDescriptionV1>(imageDesc->sendCreate());
315+
m_waylandState.cmImageDesc->setReady([this](CCWpImageDescriptionV1* r, uint32_t id) {
316+
g_logger->log(HT_LOG_DEBUG, "wayland: cm creation succeeded");
317+
m_waylandState.cmReady = true;
318+
});
319+
m_waylandState.cmImageDesc->setFailed([this](CCWpImageDescriptionV1* r, wpImageDescriptionV1Cause c, const char* msg) {
320+
g_logger->log(HT_LOG_ERROR, "wayland: cm creation failed with code {} and message {}", sc<uint32_t>(c), msg);
321+
m_waylandState.cmImageDesc.reset();
322+
});
323+
}
324+
325+
void IWaylandWindow::applyCMToSurface() {
326+
if (m_waylandState.cmApplied)
327+
return;
328+
329+
m_waylandState.cmSurface->sendSetImageDescription(m_waylandState.cmImageDesc.get(), WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL);
330+
}

src/window/IWaylandWindow.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <viewporter.hpp>
1717
#include <text-input-unstable-v3.hpp>
1818
#include <linux-drm-syncobj-v1.hpp>
19+
#include <color-management-v1.hpp>
1920

2021
#include <chrono>
2122

@@ -64,6 +65,9 @@ namespace Hyprtoolkit {
6465
virtual void configure(const Hyprutils::Math::Vector2D& size, uint32_t serial);
6566
virtual void resizeSwapchain(const Hyprutils::Math::Vector2D& pixelSize);
6667

68+
void ensureCMReady();
69+
void applyCMToSurface();
70+
6771
void prepareExplicit(SP<CWaylandBuffer>);
6872
void submitExplicit(SP<CWaylandBuffer>);
6973

@@ -79,6 +83,10 @@ namespace Hyprtoolkit {
7983
SP<CCWlCallback> frameCallback;
8084
SP<CCWpLinuxDrmSyncobjSurfaceV1> syncobjSurf;
8185

86+
bool cmReady = false, cmApplied = false;
87+
SP<CCWpColorManagementSurfaceV1> cmSurface;
88+
SP<CCWpImageDescriptionV1> cmImageDesc;
89+
8290
std::array<SP<CWaylandBuffer>, 2> wlBuffers;
8391
SP<Aquamarine::CSwapchain> swapchain;
8492
size_t bufIdx = 0;

0 commit comments

Comments
 (0)