setAlpha() in GraphicsContextCairo is unimplemented. Supporting this silly spec will be tedious but simple.
The Apollo WebKit port's Cairo changes are one example of how we might be able to support globalAlpha(). Those fixes haven't been merged to TOT yet at time of writing.
Created attachment 18318 [details] A little globalAlpha This is an old patch I had lying around. Only half the story since it doesn't deal with fillRect and other drawing ops.
Created attachment 23080 [details] Canvas globalAlpha This adds globalAlpha-support to cairo. The globalAlpha have to be applied during the drawing operation. Thats why the value has to be stored to m_common.state. Please give feedback.
The problem with adding a getAlpha() getter is that CG will have trouble supporting that API. void GraphicsContext::setAlpha(float alpha) { if (paintingDisabled()) return; CGContextSetAlpha(platformContext(), alpha); } There is no corresponding CGContextGetAlpha() (that I know of). so either we'd need to move to a model where GraphicsContext stored the alpha in the GraphicsContextState, or getAlpha() would need to be cairo only for now.
Created attachment 23088 [details] Canvas globalAlpha I use m_data to store the globalAlpha now but still had to use the getAlpha() call in GraphicsContext.h to support globalAlpha in ImageCairo.cpp. Otherwise globalAlpha wouldn't work on images (Canvas and HTML elements). I took #if PLATFORM(CAIRO) to make sure that other platforms are not affected. The globalAlpha implementation works for fill as well as stroke operations on any sharp or image. With color, gradients and patterns.
Created attachment 23090 [details] Canvas globalAlpha The same patch as before, but replaced cairo_mask with cairo_paint_with_alpha. Makes it 50% faster for strokes. I haven't chosen a common globalAlpha because of speed. The speed between the drawings can differ up to 300%. I choose the fastest way for every drawing operation. (fill/stroke with/without globalAlpha)
Comment on attachment 23090 [details] Canvas globalAlpha +static inline void setColor(cairo_t* cr, const Color& col, float globalAlpha) Perhaps globalAlpha should default to 1.0f so that lines like + setColor(cr, col, 1); don't have to change. + if (globalAlpha <= 0.999) + alpha *= globalAlpha; Why not just if (globalAlpha < 1.0) ? + if (m_data->globalAlpha <= 0.999) { same question. + : cr(0), + globalAlpha(1) This should read as GraphicsContextPlatformPrivate() : cr(0), , globalAlpha(1.0f)
Created attachment 23094 [details] Canvas globalAlpha changed setColor back and draw globalAlpha with cairo_paint_with_alpha.
Comment on attachment 23094 [details] Canvas globalAlpha I'm not a Cairo expert to be able to tell you how this could affect performance. I will have to trust you that cairo_paint_with_alpha is the right call for all of these. r=me. Great work as always Dirk.
landed in r36010