Bug 16171 - [CAIRO] Canvas does not support globalAlpha
Summary: [CAIRO] Canvas does not support globalAlpha
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: Cairo, Gtk
Depends on:
Blocks:
 
Reported: 2007-11-28 07:25 PST by Alp Toker
Modified: 2008-09-01 05:46 PDT (History)
0 users

See Also:


Attachments
A little globalAlpha (3.52 KB, patch)
2008-01-07 13:58 PST, Alp Toker
no flags Details | Formatted Diff | Diff
Canvas globalAlpha (9.03 KB, patch)
2008-08-30 12:05 PDT, Dirk Schulze
no flags Details | Formatted Diff | Diff
Canvas globalAlpha (9.43 KB, patch)
2008-08-31 10:06 PDT, Dirk Schulze
no flags Details | Formatted Diff | Diff
Canvas globalAlpha (9.38 KB, patch)
2008-08-31 12:52 PDT, Dirk Schulze
sam: review-
Details | Formatted Diff | Diff
Canvas globalAlpha (6.04 KB, patch)
2008-08-31 23:45 PDT, Dirk Schulze
eric: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alp Toker 2007-11-28 07:25:40 PST
setAlpha() in GraphicsContextCairo is unimplemented.

Supporting this silly spec will be tedious but simple.
Comment 1 Alp Toker 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.
Comment 2 Alp Toker 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.
Comment 3 Dirk Schulze 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.
Comment 4 Eric Seidel (no email) 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.
Comment 5 Dirk Schulze 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.
Comment 6 Dirk Schulze 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)
Comment 7 Sam Weinig 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)
Comment 8 Dirk Schulze 2008-08-31 23:45:43 PDT
Created attachment 23094 [details]
Canvas globalAlpha

changed setColor back and draw globalAlpha with cairo_paint_with_alpha.
Comment 9 Eric Seidel (no email) 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.
Comment 10 Jan Alonzo 2008-09-01 05:46:26 PDT
landed in r36010