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 627245 - Replace GDK drawing API with cairo
Replace GDK drawing API with cairo
Status: RESOLVED FIXED
Product: metacity
Classification: Other
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Metacity maintainers list
Metacity maintainers list
Depends on:
Blocks: 626688
 
 
Reported: 2010-08-18 09:32 UTC by Florian Müllner
Modified: 2015-04-15 14:23 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Replace GDK drawing API with cairo (33.18 KB, patch)
2010-08-18 09:32 UTC, Florian Müllner
none Details | Review
Use gdk_window_get_background_pattern() to clear the background (4.58 KB, patch)
2010-08-18 09:32 UTC, Florian Müllner
none Details | Review
Fix build against gtk+ older than 2.21.6. (1.56 KB, patch)
2010-08-23 10:19 UTC, Florian Müllner
none Details | Review
Replace GDK drawing API with cairo (35.15 KB, patch)
2010-09-15 14:33 UTC, Florian Müllner
committed Details | Review
Add manual aliased line-drawing function using cairo rectangles. (1.92 KB, patch)
2010-09-20 09:50 UTC, Brandon Wright
none Details | Review
Use X primitive for line-drawing. (3.95 KB, patch)
2010-09-20 13:17 UTC, Brandon Wright
none Details | Review
Use cairo_xlib + X primitive for line-drawing + fix for tint offset problem (4.34 KB, patch)
2010-09-21 04:36 UTC, Brandon Wright
none Details | Review
Use cairo_xlib + X primitive for line-drawing + fix for tint offset problem (4.33 KB, patch)
2010-09-21 06:45 UTC, Brandon Wright
none Details | Review
Cairo-based fix for themes (2.66 KB, patch)
2010-09-21 08:27 UTC, Brandon Wright
none Details | Review

Description Florian Müllner 2010-08-18 09:32:06 UTC
The attached patches are based on the mutter commits 08cfdcd8 and 0839c100c0.
With the exception of switched on anti-alias for sloped lines, the drawing should be as close to the original X drawing as possible.
Comment 1 Florian Müllner 2010-08-18 09:32:09 UTC
Created attachment 168181 [details] [review]
Replace GDK drawing API with cairo

The GDK drawing API was deprecated/removed.
Comment 2 Florian Müllner 2010-08-18 09:32:13 UTC
Created attachment 168182 [details] [review]
Use gdk_window_get_background_pattern() to clear the background

gdk_window_get_back_pixmap() and gdk_window_get_background() have
been removed/deprecated. Use gdk_window_get_background_pattern()
as replacement.
Comment 3 Florian Müllner 2010-08-23 10:19:25 UTC
Created attachment 168548 [details] [review]
Fix build against gtk+ older than 2.21.6.

The gdk_window_get_background_pattern() function copied from GDK and
introduced in commit 0839c10 has a small syntax error and uses a private
API (_gdk_drawable_ref_cairo_surface()). This patch imports the missing
API and fixes the syntax error.

A follow-up patch committed to mutter to fix some errors in attachment 168182 [details] [review].
Comment 4 Thomas Thurman 2010-09-15 12:21:46 UTC
Review of attachment 168181 [details] [review]:

I can't get this patch to apply to metacity HEAD.  Is it supposed to be applied to some branch or other?
Comment 5 Florian Müllner 2010-09-15 14:33:12 UTC
Created attachment 170343 [details] [review]
Replace GDK drawing API with cairo

Squashed the previous patch series and rebased on master.
Comment 6 Thomas Thurman 2010-09-15 16:11:11 UTC
Review of attachment 170343 [details] [review]:

Committed.
Comment 7 Javier Jardón (IRC: jjardon) 2010-09-17 18:21:37 UTC
Can we close this bug, then?
Comment 8 Brandon Wright 2010-09-20 00:24:08 UTC
This still screws up sloped line-drawing, which is used in many preexisting themes. I really don't like that this was broken in a point release, and I certainly hope you're not planning on leaving things as they are. We need a solution that doesn't break all the content that's already out there.

From what I've tried, I can get lines to draw sort of similarly to GDK by setting the cairo antialias mode to NONE, but they always draw ~one pixel shorter than they're supposed to. I've messed around with it and I don't think this is directly related to cairo's half-pixel offset matrix. It seems to be something to do with not being "as inclusive" with the destination point as GDK/X was. Hopefully someone who knows cairo better can figure out why that's happening and get a revised fix in.
Comment 9 Brandon Wright 2010-09-20 09:50:43 UTC
Created attachment 170643 [details] [review]
Add manual aliased line-drawing function using cairo rectangles.

Ok, I've realized that the cairo API is simply unable to reproduce the aliased line drawing of X because it uses coverage to determine whether the pixel is on or off. 

As such, I've added a line-drawing function using the algorithm found here:
http://en.wikipedia.org/wiki/Bresenham's_line_algorithm

This uses cairo rectangles as pixels and properly duplicates earlier theme behavior. I'm unsure how exactly cairo handles this rectangle case (i.e. whether they're accumulated as a mask or regions), but, in actual use with metacity themes, sloped lines like these are always extremely short--it really shouldn't affect speed too much.
Comment 10 Brandon Wright 2010-09-20 10:01:55 UTC
Doesn't yet handle the >1 width case, unfortunately. Missed that.
Comment 11 Brandon Wright 2010-09-20 11:06:15 UTC
Comment on attachment 170643 [details] [review]
Add manual aliased line-drawing function using cairo rectangles.

My mistake-this isn't viable. Nothing short of using X itself or copying the polygon code into metacity is going to get identical behavior.
Comment 12 Brandon Wright 2010-09-20 13:17:44 UTC
Created attachment 170658 [details] [review]
Use X primitive for line-drawing.

Ok, I don't know if this could be considered "cairo blasphemy", but I've attached a patch that uses X line drawing. This necessitates cairo_xlib, but since this is currently just an X11 window manager, I assume it's implicitly available.

I've also noticed that the tint operation is producing different results. This is visible on GNOME extra Unity metacity theme, where the button glyphs are oddly blurry. You can also see it on this theme:
http://gnome-look.org/content/show.php/MurrineRounded?content=54088
where the corners exhibit the same blurred effect. It seems to me like the tint operation just alpha-blends a colored rectangle over a region. I'm not sure why that causes this.
Comment 13 Brandon Wright 2010-09-21 04:36:06 UTC
Created attachment 170729 [details] [review]
Use cairo_xlib + X primitive for line-drawing + fix for tint offset problem

The tint problem was simply because it used a cairo rectangle and applied a 0.5 pixel offset to that when rectangles don't need it. I've updated the patch to include this. 

With this patch, all themes I've tested draw correctly again (I've never seen anything use draw_arc). It also still doesn't use the deprecated gdk symbols, so I think it's perfectly viable. Though that really depends on if you guys think it's OK to use Xlib for drawing (it was being used before, just with the GDK wrapper).
Comment 14 Brandon Wright 2010-09-21 06:45:31 UTC
Created attachment 170735 [details] [review]
Use cairo_xlib + X primitive for line-drawing + fix for tint offset problem 

Updated patch. Fixed include directive.
Comment 15 Brandon Wright 2010-09-21 08:27:50 UTC
Created attachment 170738 [details] [review]
Cairo-based fix for themes

Ok, sorry for the message spam :-), but this simple patch should do the trick using just cairo itself. Hope you can get it in before GNOME 2.32.