Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support hyprland-ctm-control-v1 #8023

Merged
merged 8 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ find_package(OpenGL REQUIRED COMPONENTS ${GLES_VERSION})

pkg_check_modules(hyprctl_deps REQUIRED IMPORTED_TARGET hyprutils>=0.2.1)

pkg_check_modules(aquamarine_dep REQUIRED IMPORTED_TARGET aquamarine)
pkg_check_modules(aquamarine_dep REQUIRED IMPORTED_TARGET aquamarine>=0.4.2)

add_compile_definitions(AQUAMARINE_VERSION="${aquamarine_dep_VERSION}")

Expand Down Expand Up @@ -274,7 +274,7 @@ endfunction()

target_link_libraries(Hyprland OpenGL::EGL OpenGL::GL Threads::Threads)

pkg_check_modules(hyprland_protocols_dep hyprland-protocols>=0.2.0)
pkg_check_modules(hyprland_protocols_dep hyprland-protocols>=0.4.0)
if(hyprland_protocols_dep_FOUND)
pkg_get_variable(HYPRLAND_PROTOCOLS hyprland-protocols pkgdatadir)
message(STATUS "hyprland-protocols dependency set to ${HYPRLAND_PROTOCOLS}")
Expand All @@ -301,6 +301,8 @@ protocolnew("protocols" "wlr-data-control-unstable-v1" true)
protocolnew("${HYPRLAND_PROTOCOLS}/protocols" "hyprland-focus-grab-v1" true)
protocolnew("protocols" "wlr-layer-shell-unstable-v1" true)
protocolnew("protocols" "wayland-drm" true)
protocolnew("${HYPRLAND_PROTOCOLS}/protocols" "hyprland-ctm-control-v1" true)

protocolnew("staging/tearing-control" "tearing-control-v1" false)
protocolnew("staging/fractional-scale" "fractional-scale-v1" false)
protocolnew("unstable/xdg-output" "xdg-output-unstable-v1" false)
Expand Down
36 changes: 18 additions & 18 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if cpp_compiler.check_header('execinfo.h')
add_project_arguments('-DHAS_EXECINFO', language: 'cpp')
endif

aquamarine = dependency('aquamarine')
aquamarine = dependency('aquamarine', version: '>=0.4.2')
add_project_arguments(['-DAQUAMARINE_VERSION="@0@"'.format(aquamarine.version())], language: 'cpp')

xcb_dep = dependency('xcb', required: get_option('xwayland'))
Expand Down
3 changes: 2 additions & 1 deletion protocols/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ wayland_protos = dependency(

hyprland_protos = dependency(
'hyprland-protocols',
version: '>=0.2',
version: '>=0.4',
fallback: 'hyprland-protocols',
)

Expand Down Expand Up @@ -36,6 +36,7 @@ protocols = [
hyprland_protocol_dir / 'protocols/hyprland-global-shortcuts-v1.xml',
hyprland_protocol_dir / 'protocols/hyprland-toplevel-export-v1.xml',
hyprland_protocol_dir / 'protocols/hyprland-focus-grab-v1.xml',
hyprland_protocol_dir / 'protocols/hyprland-ctm-control-v1.xml',
wayland_protocol_dir / 'staging/tearing-control/tearing-control-v1.xml',
wayland_protocol_dir / 'staging/fractional-scale/fractional-scale-v1.xml',
wayland_protocol_dir / 'unstable/xdg-output/xdg-output-unstable-v1.xml',
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,12 @@ void CMonitor::scheduleDone() {
});
}

void CMonitor::setCTM(const Mat3x3& ctm_) {
ctm = ctm_;
ctmUpdated = true;
g_pCompositor->scheduleFrameForMonitor(this, Aquamarine::IOutput::scheduleFrameReason::AQ_SCHEDULE_NEEDS_FRAME);
}

bool CMonitor::attemptDirectScanout() {
if (!mirrors.empty() || isMirror() || g_pHyprRenderer->m_bDirectScanoutBlocked)
return false; // do not DS if this monitor is being mirrored. Will break the functionality.
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/Monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class CMonitor {
CMonitor* pMirrorOf = nullptr;
std::vector<CMonitor*> mirrors;

// ctm
Mat3x3 ctm = Mat3x3::identity();
bool ctmUpdated = false;

// for tearing
PHLWINDOWREF solitaryClient;

Expand Down Expand Up @@ -179,6 +183,7 @@ class CMonitor {
CBox logicalBox();
void scheduleDone();
bool attemptDirectScanout();
void setCTM(const Mat3x3& ctm);

bool m_bEnabled = false;
bool m_bRenderingInitPassed = false;
Expand Down
3 changes: 3 additions & 0 deletions src/managers/ProtocolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "../protocols/XDGDialog.hpp"
#include "../protocols/SinglePixel.hpp"
#include "../protocols/SecurityContext.hpp"
#include "../protocols/CTMControl.hpp"

#include "../protocols/core/Seat.hpp"
#include "../protocols/core/DataDevice.hpp"
Expand Down Expand Up @@ -157,6 +158,7 @@ CProtocolManager::CProtocolManager() {
PROTO::xdgDialog = std::make_unique<CXDGDialogProtocol>(&xdg_dialog_v1_interface, 1, "XDGDialog");
PROTO::singlePixel = std::make_unique<CSinglePixelProtocol>(&wp_single_pixel_buffer_manager_v1_interface, 1, "SinglePixel");
PROTO::securityContext = std::make_unique<CSecurityContextProtocol>(&wp_security_context_manager_v1_interface, 1, "SecurityContext");
PROTO::ctm = std::make_unique<CHyprlandCTMControlProtocol>(&hyprland_ctm_control_manager_v1_interface, 1, "CTMControl");

for (auto const& b : g_pCompositor->m_pAqBackend->getImplementations()) {
if (b->type() != Aquamarine::AQ_BACKEND_DRM)
Expand Down Expand Up @@ -229,6 +231,7 @@ CProtocolManager::~CProtocolManager() {
PROTO::xdgDialog.reset();
PROTO::singlePixel.reset();
PROTO::securityContext.reset();
PROTO::ctm.reset();

PROTO::lease.reset();
PROTO::sync.reset();
Expand Down
86 changes: 86 additions & 0 deletions src/protocols/CTMControl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "CTMControl.hpp"
#include "../Compositor.hpp"
#include "core/Output.hpp"

CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP<CHyprlandCtmControlManagerV1> resource_) : resource(resource_) {
if (!good())
return;

resource->setDestroy([this](CHyprlandCtmControlManagerV1* pMgr) { PROTO::ctm->destroyResource(this); });
resource->setOnDestroy([this](CHyprlandCtmControlManagerV1* pMgr) { PROTO::ctm->destroyResource(this); });

resource->setSetCtmForOutput([this](CHyprlandCtmControlManagerV1* r, wl_resource* output, wl_fixed_t mat0, wl_fixed_t mat1, wl_fixed_t mat2, wl_fixed_t mat3, wl_fixed_t mat4,
wl_fixed_t mat5, wl_fixed_t mat6, wl_fixed_t mat7, wl_fixed_t mat8) {
const auto OUTPUTRESOURCE = CWLOutputResource::fromResource(output);

if (!OUTPUTRESOURCE)
return; // ?!

const auto PMONITOR = OUTPUTRESOURCE->monitor.lock();

if (!PMONITOR)
return; // ?!?!

const std::array<float, 9> MAT = {wl_fixed_to_double(mat0), wl_fixed_to_double(mat1), wl_fixed_to_double(mat2), wl_fixed_to_double(mat3), wl_fixed_to_double(mat4),
wl_fixed_to_double(mat5), wl_fixed_to_double(mat6), wl_fixed_to_double(mat7), wl_fixed_to_double(mat8)};

for (auto& el : MAT) {
if (el < 0.F) {
resource->error(HYPRLAND_CTM_CONTROL_MANAGER_V1_ERROR_INVALID_MATRIX, "a matrix component was < 0");
return;
}
}

ctms[PMONITOR->szName] = MAT;

LOGM(LOG, "CTM set for output {}: {}", PMONITOR->szName, ctms.at(PMONITOR->szName).toString());
});

resource->setCommit([this](CHyprlandCtmControlManagerV1* r) {
LOGM(LOG, "Committing ctms to outputs");

for (auto& m : g_pCompositor->m_vMonitors) {
if (!ctms.contains(m->szName)) {
PROTO::ctm->setCTM(m, Mat3x3::identity());
continue;
}

PROTO::ctm->setCTM(m, ctms.at(m->szName));
}
});
}

CHyprlandCTMControlResource::~CHyprlandCTMControlResource() {
for (auto& m : g_pCompositor->m_vMonitors) {
PROTO::ctm->setCTM(m, Mat3x3::identity());
}
}

bool CHyprlandCTMControlResource::good() {
return resource->resource();
}

CHyprlandCTMControlProtocol::CHyprlandCTMControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
;
}

void CHyprlandCTMControlProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {

const auto RESOURCE = m_vManagers.emplace_back(makeShared<CHyprlandCTMControlResource>(makeShared<CHyprlandCtmControlManagerV1>(client, ver, id)));

if (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;
}

LOGM(LOG, "New CTM Manager at 0x{:x}", (uintptr_t)RESOURCE.get());
}

void CHyprlandCTMControlProtocol::destroyResource(CHyprlandCTMControlResource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == res; });
}

void CHyprlandCTMControlProtocol::setCTM(SP<CMonitor> monitor, const Mat3x3& ctm) {
monitor->setCTM(ctm);
}
44 changes: 44 additions & 0 deletions src/protocols/CTMControl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <memory>
#include <vector>
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "hyprland-ctm-control-v1.hpp"
#include <unordered_map>

class CMonitor;

class CHyprlandCTMControlResource {
public:
CHyprlandCTMControlResource(SP<CHyprlandCtmControlManagerV1> resource_);
~CHyprlandCTMControlResource();

bool good();

private:
SP<CHyprlandCtmControlManagerV1> resource;

std::unordered_map<std::string, Mat3x3> ctms;
};

class CHyprlandCTMControlProtocol : public IWaylandProtocol {
public:
CHyprlandCTMControlProtocol(const wl_interface* iface, const int& ver, const std::string& name);

virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);

private:
void destroyResource(CHyprlandCTMControlResource* resource);

void setCTM(SP<CMonitor> monitor, const Mat3x3& ctm);

//
std::vector<SP<CHyprlandCTMControlResource>> m_vManagers;

friend class CHyprlandCTMControlResource;
};

namespace PROTO {
inline UP<CHyprlandCTMControlProtocol> ctm;
};
5 changes: 5 additions & 0 deletions src/render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,11 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(CMonitor* pMonitor) {
if (inFD >= 0)
pMonitor->output->state->setExplicitInFence(inFD);

if (pMonitor->ctmUpdated) {
pMonitor->ctmUpdated = false;
pMonitor->output->state->setCTM(pMonitor->ctm);
}

bool ok = pMonitor->state.commit();
if (!ok) {
if (inFD >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion subprojects/hyprland-protocols
Loading