mirror of
https://github.com/electron/electron.git
synced 2026-01-10 07:58:08 -05:00
perf: don't create unused menuitem icons (#47100)
GTK >= 3.90.0 removed support for menuitem icons. When Electron is built with GTK >= 3.90.0, our code builds these icons and then throws them away unused. Instead, let's just not build them. Our gtk_util::GdkPixbufFromSkBitmap utility uses BGRAToRGBA and is expensive to call.
This commit is contained in:
@@ -61,29 +61,23 @@ GdkModifierType GetGdkModifierForAccelerator(
|
||||
|
||||
} // namespace
|
||||
|
||||
GtkWidget* BuildMenuItemWithImage(const std::string& label, GtkWidget* image) {
|
||||
// GTK4 removed support for image menu items.
|
||||
GtkWidget* BuildMenuItemWithImage(const std::string& label,
|
||||
const gfx::Image& icon) {
|
||||
// GTK4 removed support for menuitem icons.
|
||||
#if GTK_CHECK_VERSION(3, 90, 0)
|
||||
return gtk_menu_item_new_with_mnemonic(label.c_str());
|
||||
#else
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
||||
GtkWidget* menu_item = gtk_image_menu_item_new_with_mnemonic(label.c_str());
|
||||
GdkPixbuf* pixbuf = gtk_util::GdkPixbufFromSkBitmap(*icon.ToSkBitmap());
|
||||
GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
|
||||
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), image);
|
||||
g_object_unref(pixbuf);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS;
|
||||
return menu_item;
|
||||
#endif
|
||||
}
|
||||
|
||||
GtkWidget* BuildMenuItemWithImage(const std::string& label,
|
||||
const gfx::Image& icon) {
|
||||
GdkPixbuf* pixbuf = gtk_util::GdkPixbufFromSkBitmap(*icon.ToSkBitmap());
|
||||
|
||||
GtkWidget* menu_item =
|
||||
BuildMenuItemWithImage(label, gtk_image_new_from_pixbuf(pixbuf));
|
||||
g_object_unref(pixbuf);
|
||||
return menu_item;
|
||||
}
|
||||
|
||||
GtkWidget* BuildMenuItemWithLabel(const std::string& label) {
|
||||
return gtk_menu_item_new_with_mnemonic(label.c_str());
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ using MenuActivatedCallback = base::RepeatingCallback<void(GtkWidget*)>;
|
||||
|
||||
// Builds GtkImageMenuItems.
|
||||
GtkWidget* BuildMenuItemWithImage(const std::string& label, GtkWidget* image);
|
||||
GtkWidget* BuildMenuItemWithImage(const std::string& label,
|
||||
const gfx::Image& icon);
|
||||
GtkWidget* BuildMenuItemWithLabel(const std::string& label);
|
||||
|
||||
ui::MenuModel* ModelForMenuItem(GtkMenuItem* menu_item);
|
||||
|
||||
Reference in New Issue
Block a user