[gtksourceview] view: reduce chances for textview overdraw



commit c9cb1aa5c1c89ee16b44a26e457a5b45de827e7d
Author: Christian Hergert <christian hergert me>
Date:   Fri Feb 18 13:46:36 2022 -0800

    view: reduce chances for textview overdraw
    
    Currently there is the chance that a textview could cause the GPU to render
    large color regions at least 4 times.
    
     1) The window background
     2) The .view background for GtkSourceView
     3) The view-style applied to "textview text" background in many themes
        which inherited from the old Adwaita/Default CSS (now fixed in both).
     4) The right margin area
    
    If we force disable #3 we get the same results but it also allows us to be
    able to snapshot some render nodes from gtk_source_view_snapshot() before
    any GSK transforms are applied. This will be important because it improves
    the chances that the GSK render node diff code will elide the large
    rectangular regions.

 gtksourceview/GtkSourceView.css |  5 -----
 gtksourceview/gtksourceinit.c   | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/gtksourceview/GtkSourceView.css b/gtksourceview/GtkSourceView.css
index f0094e93..e049364c 100644
--- a/gtksourceview/GtkSourceView.css
+++ b/gtksourceview/GtkSourceView.css
@@ -167,11 +167,6 @@ GtkSourceStyleSchemePreview.selected image {
   margin: 6px;
 }
 
-/* Ensure we don't double draw backgrounds */
-textview.GtkSourceView text {
-  background: transparent;
-}
-
 textview.GtkSourceMap {
   font-size: 1.75pt;
   line-height: 4px;
diff --git a/gtksourceview/gtksourceinit.c b/gtksourceview/gtksourceinit.c
index 028d60e9..9f5cb6b7 100644
--- a/gtksourceview/gtksourceinit.c
+++ b/gtksourceview/gtksourceinit.c
@@ -220,6 +220,21 @@ gtk_source_init (void)
                                                                    
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION-1);
                        g_clear_object (&css_provider);
 
+                       /* We need an additional provider that ensures that the application cannot set
+                        * a background for "textview text" which would end up drawing the background
+                        * twice for textview, drawing over our right-margin. See gtksourceview.c for
+                        * details on why we draw the right-margin from gtk_source_view_snapshot().
+                        */
+                       css_provider = gtk_css_provider_new ();
+                       gtk_css_provider_load_from_data (css_provider,
+                                                        "textview.GtkSourceView text {background: 
transparent;}\n"
+                                                        "textview.GtkSourceMap text {background: 
transparent;}\n",
+                                                        -1);
+                       gtk_style_context_add_provider_for_display (display,
+                                                                   GTK_STYLE_PROVIDER (css_provider),
+                                                                   G_MAXINT);
+                       g_clear_object (&css_provider);
+
                        /* Add path to internal scalable icons */
                        icon_theme = gtk_icon_theme_get_for_display (display);
                        gtk_icon_theme_add_search_path (icon_theme, HICOLORDIR);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]