aboutsummaryrefslogtreecommitdiff
path: root/src/sfwk-wpe.c
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-05-02 21:44:42 +1200
committerArslaan Pathan <[email protected]>2026-05-02 21:44:42 +1200
commitab7a235f895013343500a0a4fe478634c0a7b17d (patch)
treeaa9cc4edd5b8e260f0c626f3b5b6b213bbb1bedf /src/sfwk-wpe.c
parent89e3064626fb05b2e90cd092ff918a7c3dc63326 (diff)
downloadsaffronwebkit-ab7a235f895013343500a0a4fe478634c0a7b17d.tar.xz
saffronwebkit-ab7a235f895013343500a0a4fe478634c0a7b17d.zip
Lazy loading
IT RUNS IT RUNS IT R U N S YESSSSSSSSS THIS TOOK SO LONG I DONT CARE THAT ITS A BLACK SCREEN, IT RUNS!!!!!!!!!!!
Diffstat (limited to 'src/sfwk-wpe.c')
-rw-r--r--src/sfwk-wpe.c115
1 files changed, 55 insertions, 60 deletions
diff --git a/src/sfwk-wpe.c b/src/sfwk-wpe.c
index e5ba7ec..d7cd128 100644
--- a/src/sfwk-wpe.c
+++ b/src/sfwk-wpe.c
@@ -3,7 +3,10 @@
// The original source code is available here: https://github.com/aperezdc/wpe-sdl-simple
// See external_licenses/COPYING_wpe-sdl-simple.txt
+#include "glib-object.h"
#include "glib.h"
+#include "wpe/wpe-platform.h"
+#include <EGL/egl.h>
#include <SDL3/SDL_video.h>
#include <saffron.h>
#include <stdio.h>
@@ -320,37 +323,9 @@ wpe_display_sdl3_connect(WPEDisplay *display, GError **error)
{
WPEDisplaySDL3 *self = WPE_DISPLAY_SDL3(display);
- if (!SDL_WasInit(SDL_INIT_EVENTS))
- self->init_flags |= SDL_INIT_EVENTS;
- if (!SDL_WasInit(SDL_INIT_VIDEO))
- self->init_flags |= SDL_INIT_VIDEO;
+ self->egl_display = SDL_EGL_GetCurrentDisplay();
- if (self->init_flags && !SDL_Init(self->init_flags)) {
- g_set_error(error, WPE_DISPLAY_ERROR, WPE_DISPLAY_ERROR_CONNECTION_FAILED,
- "Could not initialize SDL: %s", SDL_GetError());
- return FALSE;
- }
-
- if (!(self->hidden_window = SDL_CreateWindow("Dummy", 1, 1, SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL))) {
- g_set_error(error, WPE_DISPLAY_ERROR, WPE_DISPLAY_ERROR_CONNECTION_FAILED,
- "Could not create SDL hidden window: %s", SDL_GetError());
- return FALSE;
- }
-
- if (!(self->gl_context = SDL_GL_CreateContext(self->hidden_window))) {
- g_set_error(error, WPE_DISPLAY_ERROR, WPE_DISPLAY_ERROR_CONNECTION_FAILED,
- "Could not create SDL-managed EGL context: %s", SDL_GetError());
- return FALSE;
- }
- SDL_GL_MakeCurrent(self->hidden_window, self->gl_context);
-
- if (!SDL_SyncWindow(self->hidden_window)) {
- g_set_error(error, WPE_DISPLAY_ERROR, WPE_DISPLAY_ERROR_CONNECTION_FAILED,
- "Could not sync hidden SDL window: %s", SDL_GetError());
- return FALSE;
- }
-
- if ((self->egl_display = SDL_EGL_GetCurrentDisplay()) == EGL_NO_DISPLAY) {
+ if (self->egl_display == EGL_NO_DISPLAY) {
g_set_error(error, WPE_DISPLAY_ERROR, WPE_DISPLAY_ERROR_CONNECTION_FAILED,
"Could not get SDL-managed EGL display: %s", SDL_GetError());
return FALSE;
@@ -378,7 +353,7 @@ wpe_display_sdl3_get_egl_display(WPEDisplay *display, GError **error [[maybe_unu
WPEDisplaySDL3 *self = WPE_DISPLAY_SDL3(display);
return self->egl_display;
}
-//
+
// creates a new wpe view and toplevel
// oh and don't forget, GLib black magic
// yaaayyyyyyyyyyyy... we love glib (sarc)
@@ -504,56 +479,76 @@ SFWKContext* sfwk_init() {
SFWKContext* context = g_new0(SFWKContext, 1);
context->main_context = g_main_context_new_with_flags(G_MAIN_CONTEXT_FLAGS_OWNERLESS_POLLING);
+
+ context->display = g_object_new(wpe_display_sdl3_get_type(), NULL);
+
+ // ensure_initialized will do the GL context later, hopefully
+
+ return context;
+}
+
+static bool sfwk_webview_ensure_initialized(SFWKWebView* webview) {
+ if (webview->wpe.initialized) return true;
+
+ EGLDisplay display = SDL_EGL_GetCurrentDisplay();
+ if (display == EGL_NO_DISPLAY) {
+ return false;
+ }
g_autoptr(GError) error = NULL;
+ if (!wpe_display_connect(webview->context->display, &error)) {
+ return false;
+ }
- context->display = g_object_new(wpe_display_sdl3_get_type(), NULL);
- if (!wpe_display_connect(context->display, &error)) {
- g_printerr("cant connect to display T_T %s\n", error->message);
- g_clear_object(&context->display);
- g_clear_pointer(&context->main_context, g_main_context_unref);
- g_free(context);
- return NULL;
+ webview->wpe.toplevel = wpe_toplevel_sdl3_new(webview->context->display);
+ webview->wpe.wpeview = wpe_view_sdl3_new(webview->context->display);
+ ((WPEViewSDL3*)webview->wpe.wpeview)->userdata = webview;
+ wpe_view_set_toplevel(webview->wpe.wpeview, webview->wpe.toplevel);
+
+ webview->wpe.wkwebview = g_object_new(WEBKIT_TYPE_WEB_VIEW, "display", webview->context->display, NULL);
+ if (webview->url) {
+ webkit_web_view_load_uri(webview->wpe.wkwebview, webview->url);
}
- return context;
+ webview->wpe.initialized = TRUE;
+ return true;
}
static void sfwk_webview_draw(SaffronWidget* widget, SDL_Renderer* renderer) {
- SFWKWebView* webview = (SFWKWebView*)widget;
- webview->renderer = renderer;
-
- WPEToplevelSDL3 *toplevel = (WPEToplevelSDL3*)webview->toplevel;
- if (toplevel->texture) {
- SDL_RenderTexture(renderer, toplevel->texture, NULL, NULL);
- }
+ SFWKWebView* webview = (SFWKWebView*)widget;
+ webview->renderer = renderer;
+
+ if (sfwk_webview_ensure_initialized(webview)) {
+ WPEToplevelSDL3* toplevel = (WPEToplevelSDL3*)webview->wpe.toplevel;
+ if (toplevel && toplevel->texture) {
+ SDL_RenderTexture(renderer, toplevel->texture, NULL, NULL);
+ return;
+ }
+ }
+
+ // if its not init just be blank, too bad so sad, notmyfault
}
void sfwk_process_event(SFWKContext *context, SFWKWebView* webview, SDL_Event *event) {
- WPEToplevel* toplevel = webview->toplevel;
- // for some reason we're doing this weird sh*t? we could just use webview->view but oh well
- WPEView *view = toplevel ? wpe_toplevel_sdl3_get_view((WPEToplevelSDL3*) toplevel) : NULL;
+ // do that later
}
SFWKWebView* sfwk_webview_new(SFWKContext* context, const char* url, int w, int h) {
SFWKWebView* webview = malloc(sizeof(SFWKWebView));
if (!webview) return NULL; // good fucking luck
- //
+
saffron_widget_init((SaffronWidget*)webview);
((SaffronWidget*)webview)->type = SAFFRON_WIDGET_UNKNOWN; // saffron does not have a builtin for webviews, and i cant be bothered to add one because "if you have to edit the library, it's not extensible" - arslaan 2026
- ((SaffronWidget*)webview)->w = w;
- ((SaffronWidget*)webview)->h = h;
+ ((SaffronWidget*)webview)->w = webview->w = w;
+ ((SaffronWidget*)webview)->h = webview->h = h;
((SaffronWidget*)webview)->draw = sfwk_webview_draw;
// add an on_resize here
-
- webview->toplevel = wpe_toplevel_sdl3_new(context->display);
-
- webview->wpeview = wpe_view_sdl3_new(context->display);
- ((WPEViewSDL3*)webview->wpeview)->userdata = webview;
- wpe_view_set_toplevel(webview->wpeview, webview->toplevel);
- webview->wkwebview = g_object_new(WEBKIT_TYPE_WEB_VIEW, "display", context->display, NULL);
- webkit_web_view_load_uri(webview->wkwebview, url);
+ webview->context = context;
+ webview->url = strdup(url);
+ webview->wpe.initialized = FALSE;
+
+ // ensure initialized will init this later
return webview;
}