Bug 781731 - Use a similar surface for non-blurred shadows to improve performance. r=joe

This commit is contained in:
Anthony Jones 2012-09-02 19:07:06 -04:00
Родитель fe3c0bfdf7
Коммит d08f2d71eb
4 изменённых файлов: 40 добавлений и 14 удалений

Просмотреть файл

@ -313,7 +313,7 @@ public:
mTarget =
mCtx->mTarget->CreateShadowDrawTarget(IntSize(int32_t(mTempRect.width), int32_t(mTempRect.height)),
FORMAT_B8G8R8A8);
FORMAT_B8G8R8A8, mSigma);
if (!mTarget) {
// XXX - Deal with the situation where our temp size is too big to

Просмотреть файл

@ -729,9 +729,15 @@ public:
/*
* Create a draw target optimized for drawing a shadow.
*
* Note that aSigma is the blur radius that must be used when we draw the
* shadow. Also note that this doesn't affect the size of the allocated
* surface, the caller is still responsible for including the shadow area in
* its size.
*/
virtual TemporaryRef<DrawTarget>
CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat,
float aSigma) const
{
return CreateSimilarDrawTarget(aSize, aFormat);
}

Просмотреть файл

@ -393,16 +393,26 @@ DrawTargetCairo::DrawSurfaceWithShadow(SourceSurface *aSurface,
SourceSurfaceCairo* source = static_cast<SourceSurfaceCairo*>(aSurface);
cairo_surface_t* sourcesurf = source->GetSurface();
cairo_surface_t* blursurf = cairo_tee_surface_index(sourcesurf, 0);
cairo_surface_t* surf = cairo_tee_surface_index(sourcesurf, 1);
MOZ_ASSERT(cairo_surface_get_type(blursurf) == CAIRO_SURFACE_TYPE_IMAGE);
Rect extents(0, 0, width, height);
AlphaBoxBlur blur(cairo_image_surface_get_data(blursurf),
extents,
cairo_image_surface_get_stride(blursurf),
aSigma);
blur.Blur();
cairo_surface_t* blursurf;
cairo_surface_t* surf;
// We only use the A8 surface for blurred shadows. Unblurred shadows can just
// use the RGBA surface directly.
if (cairo_surface_get_type(sourcesurf) == CAIRO_SURFACE_TYPE_TEE) {
blursurf = cairo_tee_surface_index(sourcesurf, 0);
surf = cairo_tee_surface_index(sourcesurf, 1);
MOZ_ASSERT(cairo_surface_get_type(blursurf) == CAIRO_SURFACE_TYPE_IMAGE);
Rect extents(0, 0, width, height);
AlphaBoxBlur blur(cairo_image_surface_get_data(blursurf),
extents,
cairo_image_surface_get_stride(blursurf),
aSigma);
blur.Blur();
} else {
blursurf = sourcesurf;
surf = sourcesurf;
}
WillChange();
ClearSurfaceForUnboundedSource(aOperator);
@ -792,7 +802,8 @@ DrawTargetCairo::InitAlreadyReferenced(cairo_surface_t* aSurface, const IntSize&
}
TemporaryRef<DrawTarget>
DrawTargetCairo::CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
DrawTargetCairo::CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat,
float aSigma) const
{
cairo_surface_t* similar = cairo_surface_create_similar(cairo_get_target(mContext),
GfxFormatToCairoContent(aFormat),
@ -802,6 +813,14 @@ DrawTargetCairo::CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFor
return nullptr;
}
// If we don't have a blur then we can use the RGBA mask and keep all the
// operations in graphics memory.
if (aSigma == 0.0F) {
RefPtr<DrawTargetCairo> target = new DrawTargetCairo();
target->InitAlreadyReferenced(similar, aSize);
return target;
}
cairo_surface_t* blursurf = cairo_image_surface_create(CAIRO_FORMAT_A8,
aSize.width,
aSize.height);

Просмотреть файл

@ -116,7 +116,8 @@ public:
virtual TemporaryRef<DrawTarget>
CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const;
virtual TemporaryRef<DrawTarget>
CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const;
CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat,
float aSigma) const;
virtual TemporaryRef<GradientStops>
CreateGradientStops(GradientStop *aStops,