Bug 781731 - Clean up DrawTargetCairo::DrawSurfaceWithShadow() to make it simpler and paint correctly in all modes. r=jrmuizel

This commit is contained in:
Anthony Jones 2012-08-29 17:00:09 -04:00
parent 0cf2cc0c59
commit 1e9cee75b3

View File

@ -412,19 +412,13 @@ DrawTargetCairo::DrawSurfaceWithShadow(SourceSurface *aSurface,
// Draw the source surface into the surface we're going to blur. // Draw the source surface into the surface we're going to blur.
SourceSurfaceCairo* source = static_cast<SourceSurfaceCairo*>(aSurface); SourceSurfaceCairo* source = static_cast<SourceSurfaceCairo*>(aSurface);
cairo_surface_t* surf = source->GetSurface(); cairo_surface_t* surf = source->GetSurface();
cairo_pattern_t* pat = cairo_pattern_create_for_surface(surf);
cairo_pattern_set_extend(pat, CAIRO_EXTEND_PAD);
cairo_t* ctx = cairo_create(blursurf); cairo_t* ctx = cairo_create(blursurf);
cairo_set_source_surface(ctx, surf, 0, 0);
cairo_set_source(ctx, pat);
IntRect blurrect = blur.GetRect(); IntRect blurrect = blur.GetRect();
cairo_new_path(ctx); cairo_new_path(ctx);
cairo_rectangle(ctx, blurrect.x, blurrect.y, blurrect.width, blurrect.height); cairo_rectangle(ctx, blurrect.x, blurrect.y, blurrect.width, blurrect.height);
cairo_clip(ctx); cairo_fill(ctx);
cairo_paint(ctx);
cairo_destroy(ctx); cairo_destroy(ctx);
// Blur the result, then use that blurred result as a mask to draw the shadow // Blur the result, then use that blurred result as a mask to draw the shadow
@ -440,32 +434,26 @@ DrawTargetCairo::DrawSurfaceWithShadow(SourceSurface *aSurface,
cairo_push_group(mContext); cairo_push_group(mContext);
cairo_set_source_rgba(mContext, aColor.r, aColor.g, aColor.b, aColor.a); cairo_set_source_rgba(mContext, aColor.r, aColor.g, aColor.b, aColor.a);
cairo_mask_surface(mContext, blursurf, aOffset.x, aOffset.y); cairo_mask_surface(mContext, blursurf, aOffset.x, aOffset.y);
cairo_pop_group_to_source(mContext);
cairo_paint(mContext);
// Now that the shadow has been drawn, we can draw the surface on top. // Now that the shadow has been drawn, we can draw the surface on top.
cairo_push_group(mContext); cairo_set_source_surface(mContext, surf, 0, 0);
cairo_new_path(mContext); cairo_new_path(mContext);
cairo_rectangle(mContext, 0, 0, width, height); cairo_rectangle(mContext, 0, 0, width, height);
cairo_set_source(mContext, pat);
cairo_fill(mContext); cairo_fill(mContext);
cairo_pop_group_to_source(mContext); cairo_pop_group_to_source(mContext);
cairo_paint(mContext);
} else { } else {
cairo_set_source_rgba(mContext, aColor.r, aColor.g, aColor.b, aColor.a); cairo_set_source_rgba(mContext, aColor.r, aColor.g, aColor.b, aColor.a);
cairo_mask_surface(mContext, blursurf, aOffset.x, aOffset.y); cairo_mask_surface(mContext, blursurf, aOffset.x, aOffset.y);
// Now that the shadow has been drawn, we can draw the surface on top. // Now that the shadow has been drawn, we can draw the surface on top.
cairo_set_source(mContext, pat); cairo_set_source_surface(mContext, surf, 0, 0);
cairo_new_path(mContext); cairo_new_path(mContext);
cairo_rectangle(mContext, 0, 0, width, height); cairo_rectangle(mContext, 0, 0, width, height);
cairo_clip(mContext); cairo_fill(mContext);
} }
cairo_paint(mContext);
cairo_restore(mContext); cairo_restore(mContext);
cairo_pattern_destroy(pat);
cairo_surface_destroy(blursurf); cairo_surface_destroy(blursurf);
} }