Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use stubs for gdk-pixbuf dependency #34077

Merged
merged 7 commits into from Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion BUILD.gn
Expand Up @@ -87,7 +87,10 @@ if (is_linux) {
# implementation. In future, this file can be extended to contain
# gtk4 stubs to switch gtk version in runtime.
generate_stubs("electron_gtk_stubs") {
sigs = [ "shell/browser/ui/electron_gtk.sigs" ]
sigs = [
"shell/browser/ui/electron_gdk_pixbuf.sigs",
"shell/browser/ui/electron_gtk.sigs",
]
extra_header = "shell/browser/ui/electron_gtk.fragment"
output_name = "electron_gtk_stubs"
public_deps = [ "//ui/gtk:gtk_config" ]
Expand Down
1 change: 1 addition & 0 deletions patches/chromium/.patches
Expand Up @@ -111,3 +111,4 @@ make_gtk_getlibgtk_public.patch
build_disable_print_content_analysis.patch
custom_protocols_plzserviceworker.patch
feat_filter_out_non-shareable_windows_in_the_current_application_in.patch
make_gtk_getlibgdkpixbuf_public.patch
rzhao271 marked this conversation as resolved.
Show resolved Hide resolved
50 changes: 50 additions & 0 deletions patches/chromium/make_gtk_getlibgdkpixbuf_public.patch
@@ -0,0 +1,50 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com>
Date: Wed, 15 Jun 2022 17:59:18 +0000
Subject: Make gtk::GetLibGdkPixbuf public

Allows Electron to fetch libgdk_pixbuf during run-time
rather than having to link to it statically.

diff --git a/ui/gtk/gtk_compat.cc b/ui/gtk/gtk_compat.cc
index 40b706ed7cde206e98274025148604760b7477f9..65b097cfab72b92f301968715eb218ef0e468567 100644
--- a/ui/gtk/gtk_compat.cc
+++ b/ui/gtk/gtk_compat.cc
@@ -66,11 +66,6 @@ void* GetLibGio() {
return libgio;
}

-void* GetLibGdkPixbuf() {
- static void* libgdk_pixbuf = DlOpen("libgdk_pixbuf-2.0.so.0");
- return libgdk_pixbuf;
-}
-
void* GetLibGdk3() {
static void* libgdk3 = DlOpen("libgdk-3.so.0");
return libgdk3;
@@ -128,6 +123,11 @@ gfx::Insets InsetsFromGtkBorder(const GtkBorder& border) {

} // namespace

+void* GetLibGdkPixbuf() {
+ static void* libgdk_pixbuf = DlOpen("libgdk_pixbuf-2.0.so.0");
+ return libgdk_pixbuf;
+}
+
void* GetLibGtk() {
if (GtkCheckVersion(4))
return GetLibGtk4();
diff --git a/ui/gtk/gtk_compat.h b/ui/gtk/gtk_compat.h
index 2245974f91be4a691d82f54b55e12e44ae2000c5..37720be9e393d192b3b7db13a007431a9ce77ddc 100644
--- a/ui/gtk/gtk_compat.h
+++ b/ui/gtk/gtk_compat.h
@@ -34,6 +34,9 @@ using SkColor = uint32_t;

namespace gtk {

+// Get handle to the currently loaded gdk_pixbuf library in the process.
+void* GetLibGdkPixbuf();
+
// Get handle to the currently loaded gtk library in the process.
void* GetLibGtk();

5 changes: 5 additions & 0 deletions shell/browser/electron_browser_main_parts.cc
Expand Up @@ -371,6 +371,11 @@ void ElectronBrowserMainParts::ToolkitInitialized() {
electron::UninitializeElectron_gtk();
}

electron::InitializeElectron_gdk_pixbuf(gtk::GetLibGdkPixbuf());
if (!electron::IsElectron_gdk_pixbufInitialized()) {
electron::UninitializeElectron_gdk_pixbuf();
}
rzhao271 marked this conversation as resolved.
Show resolved Hide resolved

// Chromium does not respect GTK dark theme setting, but they may change
// in future and this code might be no longer needed. Check the Chromium
// issue to keep updated:
Expand Down
3 changes: 3 additions & 0 deletions shell/browser/ui/electron_gdk_pixbuf.sigs
@@ -0,0 +1,3 @@
GdkPixbuf* gdk_pixbuf_new(GdkColorspace colorspace, gboolean has_alpha, int bits_per_sample, int width, int height)
GdkPixbuf* gdk_pixbuf_scale_simple(const GdkPixbuf* src, int dest_width, int dest_height, GdkInterpType interp_type)
guchar* gdk_pixbuf_get_pixels(const GdkPixbuf* pixbuf)
3 changes: 2 additions & 1 deletion shell/browser/ui/electron_gtk.fragment
@@ -1 +1,2 @@
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
2 changes: 1 addition & 1 deletion shell/browser/ui/electron_gtk.sigs
Expand Up @@ -4,4 +4,4 @@ void gtk_native_dialog_show(GtkNativeDialog* self);
void gtk_native_dialog_hide(GtkNativeDialog* self);
gint gtk_native_dialog_run(GtkNativeDialog* self);
void gtk_native_dialog_destroy(GtkNativeDialog* self);
GType gtk_native_dialog_get_type(void);
GType gtk_native_dialog_get_type(void);
1 change: 1 addition & 0 deletions shell/browser/ui/gtk_util.cc
Expand Up @@ -12,6 +12,7 @@

#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
#include "electron/electron_gtk_stubs.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkUnPreMultiply.h"
Expand Down
1 change: 1 addition & 0 deletions shell/browser/ui/message_box_gtk.cc
Expand Up @@ -11,6 +11,7 @@
#include "base/no_destructor.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "electron/electron_gtk_stubs.h"
#include "shell/browser/browser.h"
#include "shell/browser/native_window_observer.h"
#include "shell/browser/native_window_views.h"
Expand Down