Bug 6955 - Some characters aren't displayed when using xlib (cache usage missing freeze/thaw)
Summary: Some characters aren't displayed when using xlib (cache usage missing freeze/...
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: xlib backend (show other bugs)
Version: 1.1.1
Hardware: x86 (IA32) Linux (All)
: high blocker
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL: http://bugzilla.mozilla.gr.jp/attachm...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-18 01:51 UTC by Masayuki Nakano (Mozilla Japan)
Modified: 2006-06-22 22:40 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Patch rv2.0 (1.19 KB, patch)
2006-05-18 04:54 UTC, Masayuki Nakano (Mozilla Japan)
Details | Splinter Review
Patch rv3.0 (1.08 KB, patch)
2006-05-18 05:59 UTC, Masayuki Nakano (Mozilla Japan)
Details | Splinter Review
Patch rv4.0 (1.58 KB, patch)
2006-05-19 02:02 UTC, Masayuki Nakano (Mozilla Japan)
Details | Splinter Review
Perform freeze/thaw in _cairo_surface_show_glyphs (1.70 KB, patch)
2006-05-23 11:01 UTC, Carl Worth
Details | Splinter Review

Description Masayuki Nakano (Mozilla Japan) 2006-05-18 01:51:29 UTC
Hi, I'm a hacker of Gecko/Firefox/Thunderbird.
I found a bug of cairo on Firefox trunk build(Minefield).
# https://bugzilla.mozilla.org/show_bug.cgi?id=337245
On many Japanese language sites, the characters disappeared randomly.
See following screenshot of the test case.
testcase:
http://bugzilla.mozilla.gr.jp/attachment.cgi?id=3175
screenshot:
https://bugzilla.mozilla.org/attachment.cgi?id=221420

I tested on |cairo-xlib-surface.c|.

On |_cairo_xlib_surface_show_glyphs|, |_cairo_xlib_surface_add_glyph| may failed
sometimes. But |_cairo_xlib_surface_add_glyph| returns 'success' in all times.
I created following patch.
https://bugzilla.mozilla.org/attachment.cgi?id=222207
This bug is fixed. But I don't know whether this patch is correct way.
Comment 1 Carl Worth 2006-05-18 02:23:25 UTC
The patch is definitely not what we want to do as it discards the use of X
server-side glyph caches, so it should have bad performance characteristics.

Is this bug perhaps the same as bug #6617 ?
Comment 2 Masayuki Nakano (Mozilla Japan) 2006-05-18 02:32:37 UTC
(In reply to comment #1)
> The patch is definitely not what we want to do as it discards the use of X
> server-side glyph caches, so it should have bad performance characteristics.

Yeah, I worry about the performance too. If we can check faster whether the
character is added correctly, it makes happy.

> Is this bug perhaps the same as bug #6617 ?

Probably, no, this bug is occurred per character, not per transaction. 
Comment 3 Masayuki Nakano (Mozilla Japan) 2006-05-18 04:54:37 UTC
Created attachment 5663 [details] [review]
Patch rv2.0

This patch fixes this bug. But I don't know why current code have this line.
Comment 4 Carl Worth 2006-05-18 05:09:12 UTC
That's a much cleaner version of the same patch, so thanks. But it's still got
the same performance problems.

If I'm reading the code correctly, the purpose of the code your patch removes is
to ensure that the glyph data is only sent to the X server once, (and then it's
cached in the X server after that).

The X server glyph cache is client-managed. If glyphs are disappearing, perhaps
the bug is that when cairo removes glyphs from the server cache it is neglecting
to clear the scaled_glyph->surface_private flag?

I'll ask Keith Packard to take a look at this bug and let us know what might be
going on.
Comment 5 Masayuki Nakano (Mozilla Japan) 2006-05-18 05:59:45 UTC
Created attachment 5664 [details] [review]
Patch rv3.0

Is this correct?
Comment 6 Carl Worth 2006-05-18 09:16:03 UTC
(In reply to comment #5)
> Created an attachment (id=5664) [edit]
> Patch rv3.0
> 
> Is this correct?

I don't think so. Here's something to try though, (I'm far too lazy to make a
bugzilla attachment out of this). If this fixes the bug for you then I'm pretty
sure it's correct.

Meanwhile, all of this code could use a bit of cleanup, but less at least get
the functionality correct first.

-Carl

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index bcf2380..aad9f97 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -2173,6 +2173,7 @@ _cairo_xlib_surface_scaled_glyph_fini (c
        XRenderFreeGlyphs (font_private->dpy,
                           font_private->glyphset,
                           &glyph_index, 1);
+       scaled_glyph->surface_private = NULL;
     }
 }
Comment 7 Masayuki Nakano (Mozilla Japan) 2006-05-18 15:45:15 UTC
(In reply to comment #6)
> I don't think so. Here's something to try though, (I'm far too lazy to make a
> bugzilla attachment out of this). If this fixes the bug for you then I'm pretty
> sure it's correct.
> 
> Meanwhile, all of this code could use a bit of cleanup, but less at least get
> the functionality correct first.
> 
> -Carl
> 
> diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
> index bcf2380..aad9f97 100644
> --- a/src/cairo-xlib-surface.c
> +++ b/src/cairo-xlib-surface.c
> @@ -2173,6 +2173,7 @@ _cairo_xlib_surface_scaled_glyph_fini (c
>         XRenderFreeGlyphs (font_private->dpy,
>                            font_private->glyphset,
>                            &glyph_index, 1);
> +       scaled_glyph->surface_private = NULL;
>      }
>  }
> 

No, this cannot fix this bug :-(
Comment 8 Masayuki Nakano (Mozilla Japan) 2006-05-19 02:02:22 UTC
Created attachment 5676 [details] [review]
Patch rv4.0

O.K. I see why the characters disappears randomly. If there are more 256
characters, the cache table removes randomly at inserting new entry. So, we
must lock the cache table while crating glyphs and drawing the text.
Comment 9 Masayuki Nakano (Mozilla Japan) 2006-05-23 01:12:24 UTC
Carl:

Would you check the latest patch?
Comment 10 Carl Worth 2006-05-23 11:01:34 UTC
Created attachment 5717 [details] [review]
Perform freeze/thaw in _cairo_surface_show_glyphs

Thanks for the reminder, and thanks for chasing down the problem.

Here's another patch that simply moves the existing freeze/thaw all the way up
to _cairo_surface_show_glyphs so that any backends implementing show_glyphs
will benefit from the frozen cache.

I've put this patch (as well as the earlier fix I proposed, which I think is
still a valid bug fix, even if we may not have hit that bug yet) on the 6955
branch in my personal cairo tree which you can look at here:

http://gitweb.cairographics.org/?p=users-cworth-cairo;a=shortlog;h=6955

Or you can fetch it into a git clone of cairo with:

git fetch git://git.cairographics.org/~cworth/cairo 6955:6955
git checkout 6955

Please test and let me know how it works.

Thanks,

-Carl
Comment 11 Masayuki Nakano (Mozilla Japan) 2006-05-23 21:17:47 UTC
Thanks, your patch fixes this bug too.
Comment 12 Carl Worth 2006-06-19 07:48:04 UTC
I had Keith Packard take a look at the latest patch and he objected to doing the
freeze/thaw at the generic level since many backends will not require it. So he
suggests pushing this fix down into the xlib backend instead.

-Carl
Comment 13 Carl Worth 2006-06-22 22:40:43 UTC
Keith Packard recommended a good way to be able to write a test case for this
bug. I did that with the new test/glyph-cache-pressure. As expected, xlib failed
the test while all the other backends passed.

And, also as expected, just adding a freeze/thaw pair in
_cairo_xlib_surface_sho_glyphs made it pass again. See the commit here:

http://gitweb.cairographics.org/?p=cairo;a=commit;h=7e457cb4c1e69670f27e3e8e134a9e32a8f75788

So I'm glad to say that this problem is officially fixed in cairo 1.1.11 so the
fix will be in place for cairo 1.2.0.

Thanks for all the help on this one,

-Carl


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.