aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/helpers
diff options
context:
space:
mode:
authorVaxry <[email protected]>2024-09-25 10:01:13 +0100
committerGitHub <[email protected]>2024-09-25 10:01:13 +0100
commit2320b2241c0713b8d81e8f467cb99bd4179ad23b (patch)
tree36d090c3de4199fa8b15fd1b4596ec584fe743a1 /src/helpers
parent8f5188269b7d58a90c569fd150435b4330dff7df (diff)
downloadHyprland-2320b2241c0713b8d81e8f467cb99bd4179ad23b.tar.gz
Hyprland-2320b2241c0713b8d81e8f467cb99bd4179ad23b.zip
Internal: move to Mat3x3 from hyprutils (#7902)
* Meson: require hyprutils >= 0.2.3 * flake.lock: update hyprutils --------- Co-authored-by: Mihai Fufezan <[email protected]>
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/MiscFunctions.cpp21
-rw-r--r--src/helpers/MiscFunctions.hpp1
-rw-r--r--src/helpers/Monitor.cpp9
-rw-r--r--src/helpers/Monitor.hpp2
-rw-r--r--src/helpers/math/Math.cpp120
-rw-r--r--src/helpers/math/Math.hpp10
6 files changed, 5 insertions, 158 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index b9970399..20c79a2b 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -628,27 +628,6 @@ void logSystemInfo() {
Debug::log(NONE, "{}", execAndGet("cat /etc/os-release"));
}
-void matrixProjection(float mat[9], int w, int h, wl_output_transform tr) {
- memset(mat, 0, sizeof(*mat) * 9);
-
- const float* t = transforms[tr];
- float x = 2.0f / w;
- float y = 2.0f / h;
-
- // Rotation + reflection
- mat[0] = x * t[0];
- mat[1] = x * t[1];
- mat[3] = y * t[3];
- mat[4] = y * t[4];
-
- // Translation
- mat[2] = -copysign(1.0f, mat[0] + mat[1]);
- mat[5] = -copysign(1.0f, mat[3] + mat[4]);
-
- // Identity
- mat[8] = 1.0f;
-}
-
int64_t getPPIDof(int64_t pid) {
#if defined(KERN_PROC_PID)
int mib[] = {
diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp
index 8b2ea0d1..f696fc5d 100644
--- a/src/helpers/MiscFunctions.hpp
+++ b/src/helpers/MiscFunctions.hpp
@@ -34,7 +34,6 @@ int64_t getPPIDof(int64_t pid);
int64_t configStringToInt(const std::string&);
Vector2D configStringToVector2D(const std::string&);
std::optional<float> getPlusMinusKeywordResult(std::string in, float relative);
-void matrixProjection(float mat[9], int w, int h, wl_output_transform tr);
double normalizeAngleRad(double ang);
std::vector<SCallstackFrameInfo> getBacktrace();
void throwError(const std::string& err);
diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp
index 223a3f94..a2d4c504 100644
--- a/src/helpers/Monitor.cpp
+++ b/src/helpers/Monitor.cpp
@@ -772,12 +772,9 @@ Vector2D CMonitor::middle() {
}
void CMonitor::updateMatrix() {
- matrixIdentity(projMatrix.data());
- if (transform != WL_OUTPUT_TRANSFORM_NORMAL) {
- matrixTranslate(projMatrix.data(), vecPixelSize.x / 2.0, vecPixelSize.y / 2.0);
- matrixTransform(projMatrix.data(), wlTransformToHyprutils(transform));
- matrixTranslate(projMatrix.data(), -vecTransformedSize.x / 2.0, -vecTransformedSize.y / 2.0);
- }
+ projMatrix = Mat3x3::identity();
+ if (transform != WL_OUTPUT_TRANSFORM_NORMAL)
+ projMatrix.translate(vecPixelSize / 2.0).transform(wlTransformToHyprutils(transform)).translate(-vecTransformedSize / 2.0);
}
WORKSPACEID CMonitor::activeWorkspaceID() {
diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp
index 203cac90..97d9f8ab 100644
--- a/src/helpers/Monitor.hpp
+++ b/src/helpers/Monitor.hpp
@@ -96,7 +96,7 @@ class CMonitor {
bool scheduledRecalc = false;
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
float xwaylandScale = 1.f;
- std::array<float, 9> projMatrix = {0};
+ Mat3x3 projMatrix;
std::optional<Vector2D> forceSize;
SP<Aquamarine::SOutputMode> currentMode;
SP<Aquamarine::CSwapchain> cursorSwapchain;
diff --git a/src/helpers/math/Math.cpp b/src/helpers/math/Math.cpp
index fccfd636..d111690e 100644
--- a/src/helpers/math/Math.cpp
+++ b/src/helpers/math/Math.cpp
@@ -1,6 +1,4 @@
#include "Math.hpp"
-#include <unordered_map>
-#include <cstring>
Hyprutils::Math::eTransform wlTransformToHyprutils(wl_output_transform t) {
switch (t) {
@@ -17,124 +15,6 @@ Hyprutils::Math::eTransform wlTransformToHyprutils(wl_output_transform t) {
return Hyprutils::Math::eTransform::HYPRUTILS_TRANSFORM_NORMAL;
}
-void matrixIdentity(float mat[9]) {
- static const float identity[9] = {
- 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
- };
- memcpy(mat, identity, sizeof(identity));
-}
-
-void matrixMultiply(float mat[9], const float a[9], const float b[9]) {
- float product[9];
-
- product[0] = a[0] * b[0] + a[1] * b[3] + a[2] * b[6];
- product[1] = a[0] * b[1] + a[1] * b[4] + a[2] * b[7];
- product[2] = a[0] * b[2] + a[1] * b[5] + a[2] * b[8];
-
- product[3] = a[3] * b[0] + a[4] * b[3] + a[5] * b[6];
- product[4] = a[3] * b[1] + a[4] * b[4] + a[5] * b[7];
- product[5] = a[3] * b[2] + a[4] * b[5] + a[5] * b[8];
-
- product[6] = a[6] * b[0] + a[7] * b[3] + a[8] * b[6];
- product[7] = a[6] * b[1] + a[7] * b[4] + a[8] * b[7];
- product[8] = a[6] * b[2] + a[7] * b[5] + a[8] * b[8];
-
- memcpy(mat, product, sizeof(product));
-}
-
-void matrixTranspose(float mat[9], const float a[9]) {
- float transposition[9] = {
- a[0], a[3], a[6], a[1], a[4], a[7], a[2], a[5], a[8],
- };
- memcpy(mat, transposition, sizeof(transposition));
-}
-
-void matrixTranslate(float mat[9], float x, float y) {
- float translate[9] = {
- 1.0f, 0.0f, x, 0.0f, 1.0f, y, 0.0f, 0.0f, 1.0f,
- };
- matrixMultiply(mat, mat, translate);
-}
-
-void matrixScale(float mat[9], float x, float y) {
- float scale[9] = {
- x, 0.0f, 0.0f, 0.0f, y, 0.0f, 0.0f, 0.0f, 1.0f,
- };
- matrixMultiply(mat, mat, scale);
-}
-
-void matrixRotate(float mat[9], float rad) {
- float rotate[9] = {
- cos(rad), -sin(rad), 0.0f, sin(rad), cos(rad), 0.0f, 0.0f, 0.0f, 1.0f,
- };
- matrixMultiply(mat, mat, rotate);
-}
-
-const std::unordered_map<eTransform, std::array<float, 9>>& getTransforms() {
- static std::unordered_map<eTransform, std::array<float, 9>> transforms = {
- {HYPRUTILS_TRANSFORM_NORMAL, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
- {HYPRUTILS_TRANSFORM_90, {0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
- {HYPRUTILS_TRANSFORM_180, {-1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
- {HYPRUTILS_TRANSFORM_270, {0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
- {HYPRUTILS_TRANSFORM_FLIPPED, {-1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
- {HYPRUTILS_TRANSFORM_FLIPPED_90, {0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
- {HYPRUTILS_TRANSFORM_FLIPPED_180, {1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
- {HYPRUTILS_TRANSFORM_FLIPPED_270, {0.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
- };
- return transforms;
-}
-
-void matrixTransform(float mat[9], eTransform transform) {
- matrixMultiply(mat, mat, getTransforms().at(transform).data());
-}
-
-void matrixProjection(float mat[9], int width, int height, eTransform transform) {
- memset(mat, 0, sizeof(*mat) * 9);
-
- const float* t = getTransforms().at(transform).data();
- float x = 2.0f / width;
- float y = 2.0f / height;
-
- // Rotation + reflection
- mat[0] = x * t[0];
- mat[1] = x * t[1];
- mat[3] = y * -t[3];
- mat[4] = y * -t[4];
-
- // Translation
- mat[2] = -copysign(1.0f, mat[0] + mat[1]);
- mat[5] = -copysign(1.0f, mat[3] + mat[4]);
-
- // Identity
- mat[8] = 1.0f;
-}
-
-void projectBox(float mat[9], CBox& box, eTransform transform, float rotation, const float projection[9]) {
- double x = box.x;
- double y = box.y;
- double width = box.width;
- double height = box.height;
-
- matrixIdentity(mat);
- matrixTranslate(mat, x, y);
-
- if (rotation != 0) {
- matrixTranslate(mat, width / 2, height / 2);
- matrixRotate(mat, rotation);
- matrixTranslate(mat, -width / 2, -height / 2);
- }
-
- matrixScale(mat, width, height);
-
- if (transform != HYPRUTILS_TRANSFORM_NORMAL) {
- matrixTranslate(mat, 0.5, 0.5);
- matrixTransform(mat, transform);
- matrixTranslate(mat, -0.5, -0.5);
- }
-
- matrixMultiply(mat, projection, mat);
-}
-
wl_output_transform invertTransform(wl_output_transform tr) {
if ((tr & WL_OUTPUT_TRANSFORM_90) && !(tr & WL_OUTPUT_TRANSFORM_FLIPPED))
tr = (wl_output_transform)(tr ^ (int)WL_OUTPUT_TRANSFORM_180);
diff --git a/src/helpers/math/Math.hpp b/src/helpers/math/Math.hpp
index f57cef93..9b73a20f 100644
--- a/src/helpers/math/Math.hpp
+++ b/src/helpers/math/Math.hpp
@@ -4,17 +4,9 @@
// includes box and vector as well
#include <hyprutils/math/Region.hpp>
+#include <hyprutils/math/Mat3x3.hpp>
using namespace Hyprutils::Math;
eTransform wlTransformToHyprutils(wl_output_transform t);
-void projectBox(float mat[9], CBox& box, eTransform transform, float rotation, const float projection[9]);
-void matrixProjection(float mat[9], int width, int height, eTransform transform);
-void matrixTransform(float mat[9], eTransform transform);
-void matrixRotate(float mat[9], float rad);
-void matrixScale(float mat[9], float x, float y);
-void matrixTranslate(float mat[9], float x, float y);
-void matrixTranspose(float mat[9], const float a[9]);
-void matrixMultiply(float mat[9], const float a[9], const float b[9]);
-void matrixIdentity(float mat[9]);
wl_output_transform invertTransform(wl_output_transform tr);