Skip to content
Open
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
20 changes: 20 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
BasedOnStyle: Google
IndentWidth: 4
UseTab: Never

BreakBeforeBraces: Attach
BinPackParameters: false
BinPackArguments: false
ColumnLimit: 0

AlignAfterOpenBracket: BlockIndent

AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
AccessModifierOffset: -4
NamespaceIndentation: All

# Override Google style defaults
DerivePointerAlignment: false
PointerAlignment: Left

4 changes: 2 additions & 2 deletions examples/simple/simple.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* cc simple.c `pkg-config --libs --cflags libglace` */
#include <libglace/libglace.h>
/* cc simple.c `pkg-config --libs --cflags glace` */
#include <glace/glace.h>

static void on_client_chagend(GlaceClient* client) {
printf(
Expand Down
100 changes: 100 additions & 0 deletions glace/buffer-utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include <glib-2.0/glib.h>
#include <stddef.h>
#include <stdint.h>

#if defined(__SSSE3__)
#include <tmmintrin.h>
#elif defined(__SSE2__)
#include <emmintrin.h>
#endif
#if defined(__AVX2__)
#include <immintrin.h>
#endif

static inline void buffer_utils_bgrx_to_rgbx(unsigned char* restrict data, long pixels) {
#if defined(__AVX2__)
// 8 pixels (32 bytes) per iteration
long i = 0;
long n = pixels & ~7UL;

const __m256i shuffle_mask = _mm256_setr_epi8(
2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15, 18, 17, 16, 19, 22, 21, 20, 23, 26, 25, 24, 27, 30, 29, 28, 31
);

for (; i < n; i += 8) {
__m256i px = _mm256_loadu_si256((__m256i*)(data + i * 4));
px = _mm256_shuffle_epi8(px, shuffle_mask);
_mm256_storeu_si256((__m256i*)(data + i * 4), px);
}

// leftovers
for (; i < pixels; i++) {
unsigned char pixel = data[i];
data[i] = (pixel & 0xFF00FF00) | ((pixel << 16) & 0x00FF0000) | ((pixel >> 16) & 0xFF);
}
#elif defined(__SSSE3__)
// 4 pixels (16 bytes) per iteration
long i = 0;
long n = pixels & ~3UL;

const __m128i shuffle_mask = _mm_setr_epi8(
2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15
);

for (; i < n; i += 4) {
__m128i px = _mm_loadu_si128((__m128i*)(data + i * 4));
px = _mm_shuffle_epi8(px, shuffle_mask);
_mm_storeu_si128((__m128i*)(data + i * 4), px);
}

for (; i < pixels; i++) {
unsigned char pixel = data[i];
data[i] = (pixel & 0xFF00FF00) | ((pixel << 16) & 0x00FF0000) | ((pixel >> 16) & 0xFF);
}
#elif defined(__SSE2__)
// 4 pixels (16 bytes) per iteration (shift & mask)
long i = 0;
long n = pixels & ~3UL;

__m128i mask_rb = _mm_set1_epi32(0x00FF00FF); // R and B
__m128i mask_gx = _mm_set1_epi32(0xFF00FF00); // G and X

for (; i < n; i += 4) {
__m128i px = _mm_loadu_si128((__m128i*)(data + i * 4));

__m128i rb = _mm_and_si128(px, mask_rb);
__m128i gx = _mm_and_si128(px, mask_gx);

__m128i r = _mm_slli_epi32(rb, 16);
__m128i b = _mm_srli_epi32(rb, 16);

__m128i swapped = _mm_or_si128(gx, _mm_or_si128(r, b));
_mm_storeu_si128((__m128i*)(data + i * 4), swapped);
}

for (; i < pixels; i++) {
unsigned char pixel = data[i];
data[i] = (pixel & 0xFF00FF00) | ((pixel << 16) & 0x00FF0000) | ((pixel >> 16) & 0xFF);
}

#else
for (long i = 0; i < pixels; i++) {
unsigned char pixel = data[i];

data[i] = (pixel & 0xFF00FF00) | ((pixel << 16) & 0x00FF0000) | ((pixel >> 16) & 0xFF);
}
#endif
}

static void buffer_utils_log_available_accelerator() {
const char* prefix = "[INFO][BUFFER]";
#if defined(__AVX2__)
g_debug("%s using AVX2 for buffer format conversion acceleration", prefix);
#elif defined(__SSSE3__)
g_debug("%s using SSSE3 for buffer format conversion acceleration", prefix);
#elif defined(__SSE2__)
g_debug("%s using SSE2 for buffer format conversion acceleration", prefix);
#else
g_debug("%s compiled with no buffer conversion acceleration", prefix);
#endif
}
63 changes: 63 additions & 0 deletions glace/glace-client-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#pragma once

#ifndef __LIBGLACE_CLIENT_PRIVATE_H__
#define __LIBGLACE_CLIENT_PRIVATE_H__

#include "glace-client.h"
#include "glace-manager-private.h"

#define CLIENT_SET_CURRENT_PROP(client, prop, value) \
(client->priv->current_properties.prop = value)

#define CLIENT_SET_PENDING_PROP(client, prop, value) \
(client->priv->pending_properties.prop = value)

#define CLIENT_GET_CURRENT_PROP(client, prop) \
(client->priv->current_properties.prop)

#define CLIENT_GET_PENDING_PROP(client, prop) \
(client->priv->pending_properties.prop)

#define CLIENT_BRIDGE_PROPS(client, prop, PROP_UPPER) \
do { \
if (CLIENT_GET_CURRENT_PROP(client, prop) != CLIENT_GET_PENDING_PROP(client, prop)) { \
CLIENT_GET_CURRENT_PROP(client, prop) = CLIENT_GET_PENDING_PROP(client, prop); \
g_object_notify_by_pspec( \
G_OBJECT(client), \
glace_client_properties[GLACE_CLIENT_PROPERTY_##PROP_UPPER] \
); \
} \
} while (0)

#define CLIENT_SET_STATE_FOR_CASE(client, state, ENUM_M, prop) \
case ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_##ENUM_M: \
CLIENT_SET_PENDING_PROP(client, prop, true); \
break;

#define CLIENT_SET_DEFAULT_STATES(client) \
CLIENT_SET_PENDING_PROP(client, maximized, false); \
CLIENT_SET_PENDING_PROP(client, minimized, false); \
CLIENT_SET_PENDING_PROP(client, activated, false); \
CLIENT_SET_PENDING_PROP(client, fullscreen, false);

#define IF_INVALID_CLIENT(client) if (client == NULL || GLACE_IS_CLIENT(client) == false || client->priv->closed == true)

#define RETURN_IF_INVALID_CLIENT(client, r_value) \
do { \
IF_INVALID_CLIENT(client) { \
g_warning("[WARNING][CLIENT] function %s got an invalid client", __func__); \
return r_value; \
} \
} while (0)

// signal emitters
// static void glace_client_signal_changed_emit(GlaceClient* self);
// static void glace_client_signal_close_emit(GlaceClient* self);

// methods
// static void glace_client_init(GlaceClient* self);
// static void glace_client_class_init(GlaceClientClass* klass);

GlaceClient* glace_client_new(struct zwlr_foreign_toplevel_handle_v1* wlr_handle, struct hyprland_toplevel_mapping_manager_v1* hl_mapping_manager, GdkWaylandDisplay* gdk_display);

#endif /* __LIBGLACE_CLIENT_PRIVATE_H__ */
Loading