GNOME Bugzilla – Bug 627245
Replace GDK drawing API with cairo
Last modified: 2015-04-15 14:23:35 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.
Created attachment 168181 [details] [review] Replace GDK drawing API with cairo The GDK drawing API was deprecated/removed.
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.
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].
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?
Created attachment 170343 [details] [review] Replace GDK drawing API with cairo Squashed the previous patch series and rebased on master.
Review of attachment 170343 [details] [review]: Committed.
Can we close this bug, then?
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.
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.
Doesn't yet handle the >1 width case, unfortunately. Missed that.
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.
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.
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).
Created attachment 170735 [details] [review] Use cairo_xlib + X primitive for line-drawing + fix for tint offset problem Updated patch. Fixed include directive.
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.