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

Commit

Permalink
feat(linux): working on buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed May 5, 2024
1 parent 86d8cfa commit b70ff41
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 32 deletions.
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
# shell
# Genesis Shell

Next-gen mobile & desktop compositor

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
A next-gen compositor designed to adapt between mobile and desktop devices.
Genesis Shell is built using wlroots and Flutter. It runs a Wayland server inside
of the shell with the help of wlroots. To use it as a regular compositor, it is
recommended to use cage. Genesis Shell also supports multiple monitors with the
help of cage.
1 change: 1 addition & 0 deletions linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ add_executable(${BINARY_NAME}
"channels/auth.cc"
"channels/display/backend/wayland.c"
"channels/display/backend.c"
"channels/display/texture.c"
"channels/display/toplevel.c"
"channels/display.c"
"channels/outputs.cc"
Expand Down
2 changes: 2 additions & 0 deletions linux/application-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
struct _GenesisShellApplication {
GtkApplication parent_instance;
char** dart_entrypoint_arguments;

GtkWindow* win;
FlView* view;

AccountChannel account;
AuthChannel auth;
Expand Down
20 changes: 10 additions & 10 deletions linux/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ static void genesis_shell_application_activate(GApplication* application) {
g_autoptr(FlDartProject) project = fl_dart_project_new();
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);

FlView* view = fl_view_new(project);
gtk_widget_show(GTK_WIDGET(view));
gtk_container_add(GTK_CONTAINER(self->win), GTK_WIDGET(view));
self->view = fl_view_new(project);
gtk_widget_show(GTK_WIDGET(self->view));
gtk_container_add(GTK_CONTAINER(self->win), GTK_WIDGET(self->view));

fl_register_plugins(FL_PLUGIN_REGISTRY(view));
fl_register_plugins(FL_PLUGIN_REGISTRY(self->view));

account_channel_init(&self->account, view);
auth_channel_init(&self->auth, view);
display_channel_init(&self->display, view);
outputs_channel_init(&self->outputs, view);
session_channel_init(&self->session, view);
account_channel_init(&self->account, self->view);
auth_channel_init(&self->auth, self->view);
display_channel_init(&self->display, self->view);
outputs_channel_init(&self->outputs, self->view);
session_channel_init(&self->session, self->view);

gtk_widget_grab_focus(GTK_WIDGET(view));
gtk_widget_grab_focus(GTK_WIDGET(self->view));
}

// Implements GApplication::local_command_line.
Expand Down
3 changes: 0 additions & 3 deletions linux/channels/display/backend/wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ static void handle_global(void* data, struct wl_registry* registry, uint32_t id,
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
self->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
wl_shm_add_listener(self->shm, &shm_listener, self);
} else {
g_message("%s:%d", interface, version);
}
}

Expand Down Expand Up @@ -272,6 +270,5 @@ DisplayChannelBackend* display_channel_backend_wayland_init(GdkWaylandDisplay* d
}
}

g_message("%s", self->drm_render_name);
return &self->base;
}
10 changes: 10 additions & 0 deletions linux/channels/display/texture.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "texture.h"

typedef struct _DisplayChannelTexturePrivate {
int padding[1];
} DisplayChannelTexturePrivate;

G_DEFINE_TYPE_WITH_PRIVATE(DisplayChannelTexture, display_channel_texture, display_channel_texture_get_type());

static void display_channel_texture_class_init(DisplayChannelTextureClass* klass) {}
static void display_channel_texture_init(DisplayChannelTexture* self) {}
15 changes: 15 additions & 0 deletions linux/channels/display/texture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <flutter_linux/flutter_linux.h>

G_BEGIN_DECLS

G_DECLARE_FINAL_TYPE(DisplayChannelTexture, display_channel_texture, DISPLAY_CHANNEL, TEXTURE, FlTextureGL);

struct _DisplayChannelTexture {
FlTextureGL parent_instance;
};

#define DISPLAY_CHANNEL_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), display_channel_texture_get_type(), DisplayChannelTexture))

G_END_DECLS
18 changes: 14 additions & 4 deletions linux/channels/display/toplevel.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "../display.h"
#include "../../application.h"
#include "../../application-priv.h"
#include "../../messaging.h"

static FlValue* new_string(const gchar* str) {
Expand Down Expand Up @@ -80,13 +82,21 @@ static void xdg_toplevel_commit(struct wl_listener* listener, void* data) {
return;
}

struct wlr_buffer* buffer = self->xdg->base->surface->current.buffer;
GenesisShellApplication* app = wl_container_of(self->display->channel, app, display);
GdkWindow* win = gtk_widget_get_window(GTK_WIDGET(app->view));

size_t stride = 0;
uint32_t fmt = 0;
void* fb = NULL;
wlr_buffer_begin_data_ptr_access(self->xdg->base->surface->current.buffer, WLR_BUFFER_DATA_PTR_ACCESS_READ, &fb, &fmt, &stride);
void* fbdata = NULL;
wlr_buffer_begin_data_ptr_access(buffer, WLR_BUFFER_DATA_PTR_ACCESS_READ, &fbdata, &fmt, &stride);

GError* error = NULL;
GdkGLContext* ctx = gdk_window_create_gl_context(win, &error);
gdk_gl_context_make_current(ctx);
gdk_gl_context_clear_current();

g_message("%p %d %zu", fb, fmt, stride);
wlr_buffer_end_data_ptr_access(self->xdg->base->surface->current.buffer);
wlr_buffer_end_data_ptr_access(buffer);

// TODO: render the buffer into an OpenGL texture.
}
Expand Down

0 comments on commit b70ff41

Please sign in to comment.