RESOLVED FIXED 16171
[CAIRO] Canvas does not support globalAlpha
https://bugs.webkit.org/show_bug.cgi?id=16171
Summary [CAIRO] Canvas does not support globalAlpha
Alp Toker
Reported 2007-11-28 07:25:40 PST
setAlpha() in GraphicsContextCairo is unimplemented. Supporting this silly spec will be tedious but simple.
Attachments
A little globalAlpha (3.52 KB, patch)
2008-01-07 13:58 PST, Alp Toker
no flags
Canvas globalAlpha (9.03 KB, patch)
2008-08-30 12:05 PDT, Dirk Schulze
no flags
Canvas globalAlpha (9.43 KB, patch)
2008-08-31 10:06 PDT, Dirk Schulze
no flags
Canvas globalAlpha (9.38 KB, patch)
2008-08-31 12:52 PDT, Dirk Schulze
sam: review-
Canvas globalAlpha (6.04 KB, patch)
2008-08-31 23:45 PDT, Dirk Schulze
eric: review+
Alp Toker
Comment 1 2007-12-23 19:12:40 PST
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.
Alp Toker
Comment 2 2008-01-07 13:58:05 PST
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.
Dirk Schulze
Comment 3 2008-08-30 12:05:45 PDT
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.
Eric Seidel (no email)
Comment 4 2008-08-30 12:14:13 PDT
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.
Dirk Schulze
Comment 5 2008-08-31 10:06:55 PDT
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.
Dirk Schulze
Comment 6 2008-08-31 12:52:07 PDT
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)
Sam Weinig
Comment 7 2008-08-31 19:23:26 PDT
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)
Dirk Schulze
Comment 8 2008-08-31 23:45:43 PDT
Created attachment 23094 [details] Canvas globalAlpha changed setColor back and draw globalAlpha with cairo_paint_with_alpha.
Eric Seidel (no email)
Comment 9 2008-09-01 00:10:03 PDT
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.
Jan Alonzo
Comment 10 2008-09-01 05:46:26 PDT
landed in r36010
Note You need to log in before you can comment on or make changes to this bug.