I have just committed a change which turns SPCanvasBuf from 24bpp to 32bpp (since cairo cannot handle 24bpp buffers) and adds a cairo_t member (buf->ct) that canvas items can use to draw themselves using cairo. So far, canvas bpaths, ctrllines, and ctrlquadrs are drawn with cairo; the rest of items still use direct bitflipping although they are updated for 32bpp (and I think they should stay that way, as they don't need antialiasing and cairo would be much slower for them).
Everything should work and behave exactly as before, except a little faster, and except the temporary regressions outlined below. Note that this only concerns canvas items; regular objects are still rendered as before. Total cairofication has become closer but we're not there yet.
Here's what you need to remember to use cairo to render a canvasitem:
- In the update method, you're given an affine matrix. Remember it.
- In the render method, transform your points by the remembered affine, and then subtract from it the point (buf->rect.x0, buf->rect.y0). Use the resulting coords to draw into buf->ct, then everything will be where it must be.
- When setting colors using cairo_set_source_rgba, give the components in the order B, G, R, A, not R G B A.
Problems and regressions:
1 For some reason, drawing the canvasbuf onto the screen using cairo is very slow. So I had to keep the old method using gdk_draw_rgb_image_dithalign, which is faster even though it involves a 32bpp->24bpp conversion because gdk can only deal with 24bpp. This is controlled by the define CANVAS_OUTPUT_VIA_CAIRO in sp-canvas.cpp; uncomment it to use the cairo output. Can any cairo guru guess what is going wrong here?
2 Cairo cannot draw over the past content of the buffer with inversion. The XOR operator does not result in inversion, or at least I couldn't figure out how. So, the text selection (Shift+arrows over) had to become semitransparent blue instead of black with inversion. Hopefully this will be possible to fix with a future version of cairo.
3 With apologies to Mac users, I had to take out the code which reverts the byte order depending on endianness, which used to fix the problem caused by our using fixed byte order (RGBA) and cairo depending on the endianness of the hardware. Now that many things draw directly into the buffer using cairo, I can no longer easily separate what is drawn with cairo and what not, so there's no endianness fix anymore and as a result the colors of canvas items on a Mac will likely be wrong. This is a temporary regression; when rendering of regular objects is also cairoified, we can restore this fix, and when the problem 1 above is fixed, this endianness fix will be no longer needed because everything will be cairo throughout.
Let me know if you find any problems.
On Tue, 24 Jun 2008 01:40:14 -0300, "bulia byak" wrote:
Everything should work and behave exactly as before, except a little faster, and except the temporary regressions outlined below. Note that this only concerns canvas items; regular objects are still rendered as before. Total cairofication has become closer but we're not there yet.
Hi Bulia,
This seems really interesting!
Help me and my inkscape newbie-ness. What's a canvas vs. a regular object? Or, what buttons do I have to push in the inkscape UI to trigger cairo-based drawing.
1 For some reason, drawing the canvasbuf onto the screen using cairo is very slow. So I had to keep the old method using gdk_draw_rgb_image_dithalign, which is faster even though it involves a 32bpp->24bpp conversion because gdk can only deal with 24bpp. This is controlled by the define CANVAS_OUTPUT_VIA_CAIRO in sp-canvas.cpp; uncomment it to use the cairo output. Can any cairo guru guess what is going wrong here?
This one I definitely want to take a look at. I'll see if I can do that this week.
2 Cairo cannot draw over the past content of the buffer with inversion. The XOR operator does not result in inversion, or at least I couldn't figure out how. So, the text selection (Shift+arrows over) had to become semitransparent blue instead of black with inversion. Hopefully this will be possible to fix with a future version of cairo.
You are correct that CAIRO_OPERATOR_XOR, (the Porter-Duff XOR operator), has nothing to do with a bitwise-XOR operation. Cairo doesn't have any bitwise operations, (what would it mean to try to do that when targeting something like a PostScript or PDF target that doesn't have any bits?).
I think you just want to make inkscape draw something different here. But I'm open to suggestions for new cairo API here, (as long as it makes sense for all cairo backends).
-Carl
On Tue, Jun 24, 2008 at 1:49 AM, Carl Worth <cworth@...573...> wrote:
Help me and my inkscape newbie-ness. What's a canvas vs. a regular object?
Canvas items are the helper things that do not correspond to SVG objects - selection frame, knots and handles, bezier controls etc. Here are the cairoified ones:
- switch to the Tweak tool - the orange circle
- start to draw with Pen but not finish it - the green and red path, the node handles
- start to draw with Calligraphic but do not lift the pen - the path you see is a helper canvas item, it becomes a real object when you lift the pen
- the red helper path and the bezier controls in Node tool
You are correct that CAIRO_OPERATOR_XOR, (the Porter-Duff XOR operator), has nothing to do with a bitwise-XOR operation. Cairo doesn't have any bitwise operations, (what would it mean to try to do that when targeting something like a PostScript or PDF target that doesn't have any bits?).
I'm not talking about bits - I'm talking about inversion. For example, inversion is possible in SVG via filters, even though it has no pixels either :) In PDF, of course, it would have to be simulated by adding clipped copies of objects painted by inverse colors - messy but still possible without rasterization.
On Tue, Jun 24, 2008 at 2:50 AM, bulia byak <buliabyak@...400...> wrote:
I'm not talking about bits - I'm talking about inversion. For example, inversion is possible in SVG via filters, even though it has no pixels either :) In PDF, of course, it would have to be simulated by adding clipped copies of objects painted by inverse colors - messy but still possible without rasterization.
Actually, how do you do your existing composition operators in PS? I guess it's something similar, i.e. duplicate-clip-repaint. Either that or rasterization.
On Tue, 24 Jun 2008 11:43:09 -0300, "bulia byak" wrote:
Actually, how do you do your existing composition operators in PS? I guess it's something similar, i.e. duplicate-clip-repaint. Either that or rasterization.
Rasterization mostly.
But that doesn't make any sense for drawing something that's *not* *even* *there* anymore, (in the case that you've drawn something and then erased it again).
Seriously, I don't understand why "inversion" is an interesting operator at all. It's not too hard to construct a background on which your inverted objects are virtually impossible to see, right?
It still looks to me like an old-fashioned hack that made performance sense long ago, but doesn't anymore.
-Carl
On Tue, Jun 24, 2008 at 12:11 PM, Carl Worth <cworth@...573...> wrote:
But that doesn't make any sense for drawing something that's *not* *even* *there* anymore, (in the case that you've drawn something and then erased it again).
I'm not talking about that at all. I'm not going to use inversion to "delete" anything :) It is just a very convenient way to mark an area while keeping all the objects in it clearly discernible. It is a pretty common usage to invert text selection. It may also have very legitimate artistic uses.
Seriously, I don't understand why "inversion" is an interesting operator at all. It's not too hard to construct a background on which your inverted objects are virtually impossible to see, right?
No. I want to use inversion on an area, not on separate objects. If objects were standing out from the background without inversion, they will stand out just as much after the entire area is inverted. That's the whole point.
On Tue, Jun 24, 2008 at 2:50 AM, bulia byak <buliabyak@...400...> wrote:
Canvas items are the helper things that do not correspond to SVG objects - selection frame, knots and handles, bezier controls etc. Here are the cairoified ones:
One more thing: with regard to my problem #1 (slow output with cairo), you don't need to test these items specifically, just test any document. What is output at that stage is the complete composed buffer with all objects and canvas items, so the slowdown affects even those things that were not drawn with cairo.
participants (2)
-
bulia byak
-
Carl Worth