Skip to content

Commit

Permalink
Make the Linux backend compile
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 24, 2025
1 parent 1d763f1 commit 9818cd5
Show file tree
Hide file tree
Showing 20 changed files with 751 additions and 750 deletions.
1 change: 1 addition & 0 deletions backends/gpu/vulkan/sources/vulkanunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <kore3/gpu/device.h>

#include <assert.h>
#include <string.h>

static VkFormat convert_format(kore_gpu_texture_format format) {
switch (format) {
Expand Down
18 changes: 9 additions & 9 deletions backends/system/linux/includes/kore3/backend/funcs.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <kinc/display.h>
#include <kinc/global.h>
#include <kinc/window.h>
#include <kore3/display.h>
#include <kore3/global.h>
#include <kore3/window.h>
#ifdef KINC_EGL
#define EGL_NO_PLATFORM_SPECIFIC_TYPES
#include <EGL/egl.h>
Expand All @@ -16,22 +16,22 @@ struct linux_procs {
void (*shutdown)(void);

void (*display_init)(void);
kinc_display_mode_t (*display_available_mode)(int display, int mode);
kore_display_mode (*display_available_mode)(int display, int mode);
int (*display_count_available_modes)(int display);
bool (*display_available)(int display_index);
const char *(*display_name)(int display_index);
kinc_display_mode_t (*display_current_mode)(int display_index);
kore_display_mode (*display_current_mode)(int display_index);
int (*display_primary)(void);
int (*count_displays)(void);

int (*window_create)(kinc_window_options_t *window_options, kinc_framebuffer_options_t *framebuffer_options);
int (*window_create)(kore_window_parameters *window_options, kore_framebuffer_parameters *framebuffer_options);
void (*window_destroy)(int window_index);
int (*window_display)(int window_index);
void (*window_show)(int window_index);
void (*window_hide)(int window_index);
void (*window_set_title)(int window_index, const char *title);
void (*window_change_mode)(int window_index, kinc_window_mode_t mode);
kinc_window_mode_t (*window_get_mode)(int window_index);
void (*window_change_mode)(int window_index, kore_window_mode mode);
kore_window_mode (*window_get_mode)(int window_index);
void (*window_move)(int window_index, int x, int y);
void (*window_resize)(int window_index, int width, int height);
int (*window_x)(int window_index);
Expand Down Expand Up @@ -64,4 +64,4 @@ struct linux_procs {

extern struct linux_procs procs;

void kinc_linux_init_procs();
void kinc_linux_init_procs();
16 changes: 8 additions & 8 deletions backends/system/linux/includes/kore3/backend/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ extern "C" {
#else
typedef struct {
int nothing;
} kinc_video_impl_t;
} kore_video_impl;

typedef struct kinc_internal_video_sound_stream {
typedef struct kore_internal_video_sound_stream {
int nothing;
} kinc_internal_video_sound_stream_t;
} kore_internal_video_sound_stream;

void kinc_internal_video_sound_stream_init(kinc_internal_video_sound_stream_t *stream, int channel_count, int frequency);
void kore_internal_video_sound_stream_init(kore_internal_video_sound_stream *stream, int channel_count, int frequency);

void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t *stream);
void kore_internal_video_sound_stream_destroy(kore_internal_video_sound_stream *stream);

void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count);
void kore_internal_video_sound_stream_insert_data(kore_internal_video_sound_stream *stream, float *data, int sample_count);

float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream);
float *kore_internal_video_sound_stream_next_frame(kore_internal_video_sound_stream *stream);

bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream);
bool kore_internal_video_sound_stream_ended(kore_internal_video_sound_stream *stream);
#endif

#ifdef __cplusplus
Expand Down
18 changes: 8 additions & 10 deletions backends/system/linux/includes/kore3/backend/wayland.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#ifndef _GNU_SOURCE
#define _GNU_SOURCE // put this here too, to make clangd happy
#endif
#include <kinc/display.h>
#include <kinc/log.h>
#include <kinc/system.h>

#include <kore3/display.h>
#include <kore3/log.h>
#include <kore3/system.h>
#include <kore3/window.h>

#include <wayland-client-core.h>
#include <wayland-cursor.h>
Expand Down Expand Up @@ -121,11 +124,6 @@ struct kinc_xkb_procs {

extern struct kinc_xkb_procs wl_xkb;

#include <kinc/display.h>
#include <kinc/global.h>
#include <kinc/system.h>
#include <kinc/window.h>

#define MAXIMUM_WINDOWS 16
#define MAXIMUM_DISPLAYS 16
#define MAXIMUM_DISPLAY_MODES 16
Expand Down Expand Up @@ -183,7 +181,7 @@ struct kinc_wl_window {
int buffer_width;
int buffer_height;

kinc_window_mode_t mode;
kore_window_mode mode;
struct wl_surface *surface;
struct xdg_surface *xdg_surface;
struct xdg_toplevel *toplevel;
Expand Down Expand Up @@ -230,7 +228,7 @@ struct kinc_wl_display {
int subpixel;
enum wl_output_transform transform;
enum wl_output_subpixel scale;
kinc_display_mode_t modes[MAXIMUM_DISPLAY_MODES];
kore_display_mode modes[MAXIMUM_DISPLAY_MODES];
};

struct kinc_wl_mouse {
Expand Down
12 changes: 6 additions & 6 deletions backends/system/linux/includes/kore3/backend/x11.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include <kinc/display.h>
#include <kinc/log.h>
#include <kinc/system.h>
#include <kinc/window.h>
#include <kore3/display.h>
#include <kore3/log.h>
#include <kore3/system.h>
#include <kore3/window.h>

#include <X11/Xatom.h>
#include <X11/Xlib.h>
Expand All @@ -25,7 +25,7 @@ struct kinc_x11_window {
int window_index;
int width;
int height;
kinc_window_mode_t mode;
kore_window_mode mode;
Window window;
XIM xInputMethod;
XIC xInputContext;
Expand Down Expand Up @@ -197,4 +197,4 @@ struct x11_context {
struct kinc_x11_procs xlib;
struct x11_context x11_ctx;

void kinc_x11_copy_to_clipboard(const char *text);
void kinc_x11_copy_to_clipboard(const char *text);
6 changes: 3 additions & 3 deletions backends/system/linux/sources/display-wayland.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "wayland.h"
#include <kore3/backend/wayland.h>

void kinc_wayland_display_init(void) {
// This is a no-op because displays are already registered in kinc_wayland_init,
Expand Down Expand Up @@ -28,7 +28,7 @@ const char *kinc_wayland_display_name(int display_index) {
return display->name;
}

kinc_display_mode_t kinc_wayland_display_current_mode(int display_index) {
kore_display_mode kinc_wayland_display_current_mode(int display_index) {
if (display_index >= MAXIMUM_DISPLAYS)
display_index = 0;
struct kinc_wl_display *display = &wl_ctx.displays[display_index];
Expand All @@ -42,7 +42,7 @@ int kinc_wayland_display_count_available_modes(int display_index) {
return display->num_modes;
}

kinc_display_mode_t kinc_wayland_display_available_mode(int display_index, int mode_index) {
kore_display_mode kinc_wayland_display_available_mode(int display_index, int mode_index) {
if (display_index >= MAXIMUM_DISPLAYS)
display_index = 0;
struct kinc_wl_display *display = &wl_ctx.displays[display_index];
Expand Down
20 changes: 10 additions & 10 deletions backends/system/linux/sources/display-x11.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <kore3/backend/x11.h>

#include "x11.h"
#include <string.h>

// TODO: deal with monitor hotplugging and such
Expand All @@ -21,7 +21,7 @@ void kinc_x11_display_init(void) {

for (int i = 0; i < screen_resources->noutput; i++) {
if (i >= MAXIMUM_DISPLAYS) {
kinc_log(KINC_LOG_LEVEL_ERROR, "Too many screens (maximum %i)", MAXIMUM_DISPLAYS);
kore_log(KORE_LOG_LEVEL_ERROR, "Too many screens (maximum %i)", MAXIMUM_DISPLAYS);
break;
}

Expand Down Expand Up @@ -83,11 +83,11 @@ const char *kinc_x11_display_name(int display_index) {
return x11_ctx.displays[display_index].name;
}

kinc_display_mode_t kinc_x11_display_current_mode(int display_index) {
kore_display_mode kinc_x11_display_current_mode(int display_index) {
if (display_index >= MAXIMUM_DISPLAYS)
display_index = 0;
struct kinc_x11_display *display = &x11_ctx.displays[display_index];
kinc_display_mode_t mode;
kore_display_mode mode;
mode.x = 0;
mode.y = 0;
mode.width = display->width;
Expand All @@ -101,7 +101,7 @@ kinc_display_mode_t kinc_x11_display_current_mode(int display_index) {

XRROutputInfo *output_info = xlib.XRRGetOutputInfo(x11_ctx.display, screen_resources, screen_resources->outputs[display->index]);
if (output_info->connection != RR_Connected || output_info->crtc == None) {
kinc_log(KINC_LOG_LEVEL_ERROR, "Display %i not connected.", display_index);
kore_log(KORE_LOG_LEVEL_ERROR, "Display %i not connected.", display_index);
xlib.XRRFreeOutputInfo(output_info);
xlib.XRRFreeScreenResources(screen_resources);
return mode;
Expand Down Expand Up @@ -150,7 +150,7 @@ int kinc_x11_display_count_available_modes(int display_index) {

XRROutputInfo *output_info = xlib.XRRGetOutputInfo(x11_ctx.display, screen_resources, screen_resources->outputs[display->index]);
if (output_info->connection != RR_Connected || output_info->crtc == None) {
kinc_log(KINC_LOG_LEVEL_ERROR, "Display %i not connected.", display_index);
kore_log(KORE_LOG_LEVEL_ERROR, "Display %i not connected.", display_index);
xlib.XRRFreeOutputInfo(output_info);
xlib.XRRFreeScreenResources(screen_resources);
return 0;
Expand All @@ -162,11 +162,11 @@ int kinc_x11_display_count_available_modes(int display_index) {
return num_modes;
}

kinc_display_mode_t kinc_x11_display_available_mode(int display_index, int mode_index) {
kore_display_mode kinc_x11_display_available_mode(int display_index, int mode_index) {
if (display_index >= MAXIMUM_DISPLAYS)
display_index = 0;
struct kinc_x11_display *display = &x11_ctx.displays[display_index];
kinc_display_mode_t mode;
kore_display_mode mode;
mode.x = 0;
mode.y = 0;
mode.width = display->width;
Expand All @@ -180,14 +180,14 @@ kinc_display_mode_t kinc_x11_display_available_mode(int display_index, int mode_

XRROutputInfo *output_info = xlib.XRRGetOutputInfo(x11_ctx.display, screen_resources, screen_resources->outputs[display->index]);
if (output_info->connection != RR_Connected || output_info->crtc == None) {
kinc_log(KINC_LOG_LEVEL_ERROR, "Display %i not connected.", display_index);
kore_log(KORE_LOG_LEVEL_ERROR, "Display %i not connected.", display_index);
xlib.XRRFreeOutputInfo(output_info);
xlib.XRRFreeScreenResources(screen_resources);
return mode;
}

if (mode_index >= output_info->nmode) {
kinc_log(KINC_LOG_LEVEL_ERROR, "Invalid mode index %i.", mode_index);
kore_log(KORE_LOG_LEVEL_ERROR, "Invalid mode index %i.", mode_index);
}

RRMode rr_mode = output_info->modes[mode_index];
Expand Down
21 changes: 11 additions & 10 deletions backends/system/linux/sources/display.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "funcs.h"
#include <kinc/display.h>
#include <kore3/backend/funcs.h>

void kinc_display_init() {
#include <kore3/display.h>

void kore_display_init() {
static bool display_initialized = false;
if (display_initialized) {
return;
Expand All @@ -12,30 +13,30 @@ void kinc_display_init() {
display_initialized = true;
}

kinc_display_mode_t kinc_display_available_mode(int display, int mode) {
kore_display_mode kore_display_available_mode(int display, int mode) {
return procs.display_available_mode(display, mode);
}

int kinc_display_count_available_modes(int display) {
int kore_display_count_available_modes(int display) {
return procs.display_count_available_modes(display);
}

bool kinc_display_available(int display) {
bool kore_display_available(int display) {
return procs.display_available(display);
}

const char *kinc_display_name(int display) {
const char *kore_display_name(int display) {
return procs.display_name(display);
}

kinc_display_mode_t kinc_display_current_mode(int display) {
kore_display_mode kore_display_current_mode(int display) {
return procs.display_current_mode(display);
}

int kinc_primary_display(void) {
int kore_primary_display(void) {
return procs.display_primary();
}

int kinc_count_displays(void) {
int kore_count_displays(void) {
return procs.count_displays();
}
Loading

0 comments on commit 9818cd5

Please sign in to comment.