@@ -120,14 +120,14 @@ static bool MCGContextStateCreate(MCGContextStateRef& r_state)
120120 t_state -> should_antialias = false ;
121121
122122 t_state -> fill_color = MCGColorMakeRGBA (0 .0f , 0 .0f , 0 .0f , 1 .0f );
123- t_state -> fill_opacity = 0 .0f ;
123+ t_state -> fill_opacity = 1 .0f ;
124124 t_state -> fill_rule = kMCGFillRuleNonZero ;
125125 t_state -> fill_pattern = NULL ;
126126 t_state -> fill_gradient= NULL ;
127127 t_state -> fill_style = kMCGPaintStyleOpaque ;
128128
129129 t_state -> stroke_color = MCGColorMakeRGBA (0 .0f , 0 .0f , 0 .0f , 1 .0f );
130- t_state -> stroke_opacity = 0 .0f ;
130+ t_state -> stroke_opacity = 1 .0f ;
131131 t_state -> stroke_pattern = NULL ;
132132 t_state -> stroke_gradient= NULL ;
133133 t_state -> stroke_attr . width = 0 .0f ;
@@ -2029,7 +2029,7 @@ void MCGContextAddPath(MCGContextRef self, MCGPathRef p_path)
20292029// //////////////////////////////////////////////////////////////////////////////
20302030// Paint setup
20312031
2032- static bool MCGContextApplyPaintSettingsToSkPaint (MCGContextRef self, MCGColor p_color, MCGPatternRef p_pattern, MCGGradientRef p_gradient, MCGPaintStyle p_paint_style, SkPaint &r_paint)
2032+ static bool MCGContextApplyPaintSettingsToSkPaint (MCGContextRef self, MCGFloat p_opacity, MCGColor p_color, MCGPatternRef p_pattern, MCGGradientRef p_gradient, MCGPaintStyle p_paint_style, SkPaint &r_paint)
20332033{
20342034 // TODO: Refactor color, pattern and gradients into ref counted (copy on write?) paint type.
20352035 bool t_success;
@@ -2076,11 +2076,20 @@ static bool MCGContextApplyPaintSettingsToSkPaint(MCGContextRef self, MCGColor p
20762076
20772077 if (t_success)
20782078 {
2079- // Don't set the paint color if using a shader, as the color's alpha value will be applied to the paint (which we don't want to happen!).
2079+ // Set the shader or solid color here - the opacity for a shader is taken
2080+ // from the Alpha channel of the solid color; but for solid colors we
2081+ // must multiply the solid color's alpha by the provided alpha.
20802082 if (t_shader != nil)
2083+ {
20812084 r_paint . setShader (t_shader);
2085+ r_paint . setAlpha ((U8CPU)(p_opacity * 255 ));
2086+ }
20822087 else
2088+ {
20832089 r_paint . setColor (MCGColorToSkColor (p_color));
2090+ r_paint . setAlpha ((U8CPU)(r_paint.getAlpha () * p_opacity));
2091+ }
2092+
20842093 r_paint . setMaskFilter (t_stipple);
20852094
20862095 // MM-2014-01-09: [[ LibSkiaUpdate ]] Updated filters to use Skia's new filter levels.
@@ -2110,7 +2119,7 @@ static bool MCGContextSetupFillPaint(MCGContextRef self, SkPaint &r_paint)
21102119 t_success = true ;
21112120
21122121 if (t_success)
2113- t_success = MCGContextApplyPaintSettingsToSkPaint (self, self -> state -> fill_color, self -> state -> fill_pattern, self -> state -> fill_gradient, self -> state -> fill_style, r_paint);
2122+ t_success = MCGContextApplyPaintSettingsToSkPaint (self, self -> state -> fill_opacity, self -> state -> fill_color, self -> state -> fill_pattern, self -> state -> fill_gradient, self -> state -> fill_style, r_paint);
21142123
21152124 if (t_success)
21162125 {
@@ -2128,7 +2137,7 @@ static bool MCGContextSetupStrokePaint(MCGContextRef self, SkPaint &r_paint)
21282137 t_success = true ;
21292138
21302139 if (t_success)
2131- t_success = MCGContextApplyPaintSettingsToSkPaint (self, self -> state -> stroke_color, self -> state -> stroke_pattern, self -> state -> stroke_gradient, self -> state -> stroke_style, r_paint);
2140+ t_success = MCGContextApplyPaintSettingsToSkPaint (self, self -> state -> stroke_opacity, self -> state -> stroke_color, self -> state -> stroke_pattern, self -> state -> stroke_gradient, self -> state -> stroke_style, r_paint);
21322141
21332142 sk_sp<SkPathEffect> t_dash_effect;
21342143 if (t_success)
0 commit comments