After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 340066 - Get rid of pango_layout_context_changed()
Get rid of pango_layout_context_changed()
Status: RESOLVED FIXED
Product: pango
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: Medium API
Assigned To: Behdad Esfahbod
pango-maint
: 328189 (view as bug list)
Depends on:
Blocks: 340141
 
 
Reported: 2006-04-28 21:22 UTC by Behdad Esfahbod
Modified: 2012-12-06 23:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (9.22 KB, patch)
2006-04-29 07:58 UTC, Behdad Esfahbod
needs-work Details | Review
Final patch (26.08 KB, patch)
2006-06-07 08:12 UTC, Behdad Esfahbod
needs-work Details | Review
Track changes in FontMaps using a serial (16.22 KB, patch)
2012-12-05 13:54 UTC, Alexander Larsson
none Details | Review
Track changes in PangoContext via a serial (9.40 KB, patch)
2012-12-05 13:54 UTC, Alexander Larsson
none Details | Review
Track changes in layout and dependencies via serials (10.12 KB, patch)
2012-12-05 13:54 UTC, Alexander Larsson
none Details | Review
GtkLabel: Rely on the new pango support for context change tracking (5.35 KB, patch)
2012-12-05 13:55 UTC, Alexander Larsson
none Details | Review

Description Behdad Esfahbod 2006-04-28 21:22:40 UTC
As Owen suggested, this can be done by keeping a serial number in the context...
Comment 1 Behdad Esfahbod 2006-04-29 07:58:30 UTC
Created attachment 64505 [details] [review]
Patch

Patch to implement pango_context_changed and pango_context_get_serial.  The former is available to backends only.  PangoLayout uses pango_context_get_serial to update itself.  pangocairo uses pango_context_changed to notify the context of changes to data it attaches to PangoContext.

Owen, can you review please.
Comment 2 Behdad Esfahbod 2006-04-29 07:59:44 UTC
Needs to update docs for pango_layout_context_changed too.
Comment 3 Behdad Esfahbod 2006-05-19 18:04:23 UTC
*** Bug 328189 has been marked as a duplicate of this bug. ***
Comment 4 Behdad Esfahbod 2006-05-22 00:50:57 UTC
While patching Bug 342529, I came across the case that the fontmap may change resolution without contexts noticing, and I thought that can be implemented using a serial too.  The get_serial for context then fetches get_serial for fontmap and adds to its own serial...

While adding the serial APIs, we can add one to PangoLayout itself too.  That may come handy in upper layers to see if redraws are needed, etc.

Owen, what do you think?
Comment 5 Behdad Esfahbod 2006-06-07 08:12:42 UTC
Created attachment 66891 [details] [review]
Final patch

Going to commit something like this soon.

Matthias, can you do a quick review, do you see any flaws, etc with the approach?
Comment 6 Behdad Esfahbod 2006-06-08 03:44:24 UTC
The patch needs to do the same thing it's doing for Xft for FT2 backend too...
Comment 7 Behdad Esfahbod 2009-05-20 19:28:02 UTC
Also, should add serial api to the layout itself, such that apps can check it and detect changes.
Comment 8 Alexander Larsson 2012-12-05 13:54:49 UTC
Created attachment 230757 [details] [review]
Track changes in FontMaps using a serial

This adds the pango_font_map_get_serial method that lets you see
if a fontmap has changes since the last check. It adds implementations
to all current fontmaps.
Comment 9 Alexander Larsson 2012-12-05 13:54:53 UTC
Created attachment 230758 [details] [review]
Track changes in PangoContext via a serial

Whenever a PangoContext or its fontmap changes we bump the
contexts serial, you can get it via pango_context_get_serial()
to see find out if the context changed since the last time and
you need to relayout.

You can also force the context to be "changed" by calling
pango_context_changed().
Comment 10 Alexander Larsson 2012-12-05 13:54:57 UTC
Created attachment 230759 [details] [review]
Track changes in layout and dependencies via serials

We track changes in the PangoContext and automatically call
pango_layout_context_changed() when needed, plus we track
changes in the layout and let apps know via pango_layout_get_serial
when the layout changed and needs to be redrawn.
Comment 11 Alexander Larsson 2012-12-05 13:55:17 UTC
Created attachment 230760 [details] [review]
GtkLabel: Rely on the new pango support for context change tracking

Now that Pango tracks changes to the context automatically there is
no need to do it manually in e.g. style-updated or direction-changed,
in fact the only case we have to care about is when we re-create
the PangoContext due to a screen change, so we only have to clear
the layouts in GtkLabel in screen-changed.

This means we're not clearing all the layouts whenever the state changes,
which happens to every widget when the window is unfocused, which helps
performance a lot.
Comment 12 Alexander Larsson 2012-12-05 13:58:11 UTC
I updated the patch to the latest tree, fixes a few bugs and split it up.
I also added a test patch for GtkLabel to rely on the pango patch to verify that it worked (in fact, this caught a bug in pango_layout_get_extents_internal() which didn't check the serial before relying on the extents cache).

This is a lot more imporant now that we get a lot of state changes (every widget changes to/from backdrop state when the window is focused/unfocused) which is currently causing all labels to constantly drop their PangoLayouts.
Comment 13 Behdad Esfahbod 2012-12-05 22:34:36 UTC
Thanks Alex!

Quick review:

- I suggest making serial unsigned int, with initial number greater than zero.  I expect this to do overflow in real world cases.  So possibly make the increment code also skip zero?



+/**
+ * pango_context_changed:
+ * @context: a #PangoContext
+ *
+ * Creates a new #PangoContext initialized to default value.

Fix doc.


 void
 pango_layout_context_changed (PangoLayout *layout)
 {
+  g_return_if_fail (PANGO_IS_LAYOUT (layout));
+
+  layout_changed (layout);
   pango_layout_clear_lines (layout);

So, essentially you want to remove the call to clear_lines() in every place you call layout_changed().  layout_changed then can clear_lines (and nothing else really, except for bumping serial).


Please push after addressing these minor issues.
Comment 14 Alexander Larsson 2012-12-06 23:06:40 UTC
pushed and released in 1.32.4.