perf: don't create unused menuitem icons (#47128)
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. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
ae232703de
commit
8f908ffce2
2 changed files with 6 additions and 14 deletions
|
@ -60,29 +60,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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue