Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
refactor: add asahi devshell and package, working on proper gpu support
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed May 6, 2024
1 parent b70ff41 commit 20d6773
Show file tree
Hide file tree
Showing 13 changed files with 370 additions and 134 deletions.
83 changes: 76 additions & 7 deletions flake.lock

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

40 changes: 32 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
url = "github:RossComputerGuy/mobile-nixos/fix/impure";
flake = false;
};
nixos-apple-silicon.url = "github:tpwrules/nixos-apple-silicon/777e10ec2094a0ac92e61cbfe338063d1e64646e";
flake-utils.url = "github:numtide/flake-utils";
};

Expand All @@ -14,14 +15,17 @@
nixpkgs,
nixos-hardware,
nixos-mobile,
nixos-apple-silicon,
flake-utils,
...
}@inputs:
(flake-utils.lib.eachSystem (flake-utils.lib.defaultSystems ++ [ "riscv64-linux" ]) (system:
(flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;

isAsahi = pkgs.targetPlatform.isAarch64 && pkgs.stdenv.isLinux;

overlay = f: s: {
expidus = s.expidus // {
genesis-shell = s.flutter.buildFlutterApplication {
Expand All @@ -34,6 +38,7 @@
pam accountsservice polkit seatd wlroots_0_17 libdrm libGL libxkbcommon
mesa vulkan-loader libdisplay-info libliftoff libinput xorg.xcbutilwm
xorg.libX11 xorg.xcbutilerrors xorg.xcbutilimage xorg.xcbutilrenderutil
libepoxy
];

pubspecLock = lib.importJSON ./pubspec.lock.json;
Expand All @@ -54,16 +59,35 @@
};
};
in {
packages.default = self.legacyPackages.${system}.expidus.genesis-shell;
packages = {
default = self.legacyPackages.${system}.expidus.genesis-shell;
} // lib.optionalAttrs (isAsahi) {
asahi = self.legacyPackages.${system}.pkgsAsahi.expidus.genesis-shell;
};

legacyPackages = pkgs.appendOverlays [
legacyPackages = pkgs.appendOverlays (lib.optionals (isAsahi) [
(f: p: {
pkgsAsahi = p.appendOverlays [
nixos-apple-silicon.overlays.default
(f: p: {
mesa = p.mesa-asahi-edge;
})
];
})
] ++ [
overlay
];
]);

devShells.default = pkgs.mkShell {
inherit (self.packages.${system}.default) pname version name;
inputsFrom = [ self.packages.${system}.default ];
packages = [ pkgs.flutter pkgs.yq ];
devShells = let
mkShell = pkg: pkgs.mkShell {
inherit (pkg) pname version name;
inputsFrom = [ pkg ];
packages = [ pkgs.flutter pkgs.yq ];
};
in {
default = mkShell self.packages.${system}.default;
} // lib.optionalAttrs (isAsahi) {
asahi = mkShell self.packages.${system}.asahi;
};
})) // {
nixosConfigurations = let
Expand Down
3 changes: 2 additions & 1 deletion linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ endfunction()

find_package(PkgConfig REQUIRED)
pkg_check_modules(ACCOUNTSSERVICE REQUIRED IMPORTED_TARGET accountsservice)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0 epoxy)
pkg_check_modules(LIBSEAT REQUIRED IMPORTED_TARGET libseat)
pkg_check_modules(PAM REQUIRED IMPORTED_TARGET pam)
pkg_check_modules(WLROOTS REQUIRED IMPORTED_TARGET wlroots wayland-server wayland-client xkbcommon libdrm)
Expand All @@ -118,6 +118,7 @@ add_executable(${BINARY_NAME}
"messaging.c"
"channels/account.cc"
"channels/auth.cc"
"channels/display/backend/dummy.c"
"channels/display/backend/wayland.c"
"channels/display/backend.c"
"channels/display/texture.c"
Expand Down
63 changes: 25 additions & 38 deletions linux/channels/display.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <wlr/render/pixman.h>
#include <drm_fourcc.h>

#include "display.h"
Expand Down Expand Up @@ -32,30 +33,31 @@ static void method_call_handler(FlMethodChannel* channel, FlMethodCall* method_c
return;
}

DisplayChannelDisplay* disp = (DisplayChannelDisplay*)malloc(sizeof (DisplayChannelDisplay));
GdkDisplay* gdk_disp = gtk_widget_get_display(GTK_WIDGET(app->win));

disp->display = wl_display_create();
if (disp->display == NULL) {
fl_method_call_respond_error(method_call, "wayland", "failed to create server", NULL, NULL);
free(disp);
return;
}
DisplayChannelDisplay* disp = (DisplayChannelDisplay*)malloc(sizeof (DisplayChannelDisplay));
disp->backend = display_channel_backend_create(gdk_disp);

disp->backend = wlr_headless_backend_create(disp->display);
struct wl_display* wl_display = display_channel_backend_get_display(disp->backend);

disp->socket = wl_display_add_socket_auto(disp->display);
disp->socket = wl_display_add_socket_auto(wl_display);
if (disp->socket == NULL) {
fl_method_call_respond_error(method_call, "wayland", "failed to create socket", NULL, NULL);
wlr_backend_destroy(disp->backend);
wl_display_destroy(disp->display);
free(disp);
return;
}

// FIXME: EGL swap issues
disp->renderer = wlr_renderer_autocreate(disp->backend);
// disp->renderer = wlr_pixman_renderer_create();
wlr_renderer_init_wl_display(disp->renderer, wl_display);

disp->allocator = wlr_allocator_autocreate(disp->backend, disp->renderer);

if (!wlr_backend_start(disp->backend)) {
fl_method_call_respond_error(method_call, "wlroots", "failed to start backend", NULL, NULL);
wlr_backend_destroy(disp->backend);
wl_display_destroy(disp->display);
free(disp);
return;
}
Expand All @@ -65,27 +67,20 @@ static void method_call_handler(FlMethodChannel* channel, FlMethodCall* method_c
disp->toplevels = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, NULL);
disp->channel = self;

disp->compositor = wlr_compositor_create(disp->display, 5, NULL);
wlr_subcompositor_create(disp->display);
wlr_data_device_manager_create(disp->display);
disp->compositor = wlr_compositor_create(wl_display, 5, NULL);
wlr_subcompositor_create(wl_display);
wlr_data_device_manager_create(wl_display);

size_t n_formats = 0;
uint32_t* formats = display_channel_backend_get_shm_formats(self->backend, &n_formats);

disp->shm = wlr_shm_create(disp->display, 1, formats, n_formats);

disp->linux_dmabuf = wlr_linux_dmabuf_v1_create(disp->display, 4, display_channel_backend_get_default_drm_feedback(self->backend));

disp->seat = wlr_seat_create(disp->display, session_name);
disp->xdg_shell = wlr_xdg_shell_create(disp->display, 3);
disp->seat = wlr_seat_create(wl_display, session_name);
disp->xdg_shell = wlr_xdg_shell_create(wl_display, 3);

disp->xdg_surface_new.notify = xdg_surface_new;
wl_signal_add(&disp->xdg_shell->events.new_surface, &disp->xdg_surface_new);

disp->prev_wl_disp = getenv("WAYLAND_DISPLAY");
setenv("WAYLAND_DISPLAY", disp->socket, true);

pthread_create(&disp->thread, NULL, (void *(*)(void*))wl_display_run, disp->display);
pthread_create(&disp->thread, NULL, (void *(*)(void*))wl_display_run, wl_display);
g_hash_table_insert(self->displays, (gpointer)g_strdup(disp->socket), (gpointer)disp);

response = FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_string(disp->socket)));
Expand Down Expand Up @@ -135,7 +130,7 @@ static void method_call_handler(FlMethodChannel* channel, FlMethodCall* method_c
int64_t refresh = fl_value_get_int(fl_value_lookup_string(item, "refreshRate"));
int64_t scale = fl_value_get_int(fl_value_lookup_string(item, "scale"));

struct wlr_output* output = wlr_headless_add_output(disp->backend, width, height);
struct wlr_output* output = display_channel_backend_add_output(disp->backend, width, height);
output->model = get_string(fl_value_lookup_string(item, "model"));
output->make = get_string(fl_value_lookup_string(item, "manufacturer"));

Expand Down Expand Up @@ -191,30 +186,23 @@ static void method_call_handler(FlMethodChannel* channel, FlMethodCall* method_c
}
}

static void destory_display(DisplayChannelDisplay* self) {
wl_display_terminate(self->display);
static void destroy_display(DisplayChannelDisplay* self) {
struct wl_display* wl_display = display_channel_backend_get_display(self->backend);

wl_display_terminate(wl_display);
pthread_join(self->thread, NULL);

g_clear_list(&self->outputs, (GDestroyNotify)wlr_output_destroy_global);
g_hash_table_unref(self->toplevels);

wlr_backend_destroy(self->backend);
wl_display_destroy(self->display);

setenv("WAYLAND_DISPLAY", self->prev_wl_disp, true);
free(self);
}

void display_channel_init(DisplayChannel* self, FlView* view) {
GenesisShellApplication* app = wl_container_of(self, app, display);
GdkDisplay* disp = gtk_widget_get_display(GTK_WIDGET(app->win));

self->backend = display_channel_backend_init(disp);
if (self->backend == NULL) {
g_warning("Backend is not supported");
}

self->displays = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)destory_display);
self->displays = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)destroy_display);

g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
self->channel = fl_method_channel_new(fl_engine_get_binary_messenger(fl_view_get_engine(view)), "com.expidusos.genesis.shell/display", FL_METHOD_CODEC(codec));
Expand All @@ -223,6 +211,5 @@ void display_channel_init(DisplayChannel* self, FlView* view) {

void display_channel_deinit(DisplayChannel* self) {
g_clear_object(&self->channel);
g_clear_pointer(&self->backend, display_channel_backend_deinit);
g_hash_table_unref(self->displays);
}
10 changes: 5 additions & 5 deletions linux/channels/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ extern "C" {
#define static
#endif

#include <wlr/backend/headless.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_linux_dmabuf_v1.h>
Expand Down Expand Up @@ -58,11 +59,11 @@ typedef struct _DisplayChannelToplevel {
} DisplayChannelToplevel;

typedef struct _DisplayChannelDisplay {
struct wl_display* display;
struct wlr_backend* backend;
struct wlr_renderer* renderer;
struct wlr_allocator* allocator;

struct wlr_compositor* compositor;
struct wlr_shm* shm;
struct wlr_linux_dmabuf_v1* linux_dmabuf;
struct wlr_seat* seat;
struct wlr_xdg_shell* xdg_shell;

Expand All @@ -79,7 +80,6 @@ typedef struct _DisplayChannelDisplay {
} DisplayChannelDisplay;

typedef struct _DisplayChannel {
DisplayChannelBackend* backend;
GHashTable* displays;
FlMethodChannel* channel;
} DisplayChannel;
Expand Down
Loading

0 comments on commit 20d6773

Please sign in to comment.