Bug 930451 - Part 3: Use the gradient cache for SVG gradients as well. r=roc

This commit is contained in:
Andreas Gal 2013-11-08 17:50:39 +13:00
parent 4c4062be6f
commit 75a4efaf58
3 changed files with 34 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include "gfxASurface.h"
#include "gfxPlatform.h"
#include "gfx2DGlue.h"
#include "gfxGradientCache.h"
#include "cairo.h"
@ -102,6 +103,29 @@ gfxPattern::SetColorStops(mozilla::RefPtr<mozilla::gfx::GradientStops> aStops)
mStops = aStops;
}
void
gfxPattern::CacheColorStops(mozilla::gfx::DrawTarget *aDT)
{
if (mPattern) {
mStops = nullptr;
nsTArray<GradientStop> stops;
int count = 0;
cairo_pattern_get_color_stop_count(mPattern, &count);
stops.SetLength(count);
for (int n = 0; n < count; ++n) {
double offset, r, g, b, a;
cairo_pattern_get_color_stop_rgba(mPattern, n, &offset, &r, &g, &b, &a);
stops[n].color = mozilla::gfx::Color(r, g, b, a);
stops[n].offset = offset;
}
mStops = gfxGradientCache::GetOrCreateGradientStops(aDT,
stops,
(cairo_pattern_get_extend(mPattern) == CAIRO_EXTEND_REPEAT)
? mozilla::gfx::EXTEND_REPEAT
: mozilla::gfx::EXTEND_CLAMP);
}
}
void
gfxPattern::SetMatrix(const gfxMatrix& matrix)
{

View File

@ -14,6 +14,7 @@
#include "GraphicsFilter.h"
#include "nsISupportsImpl.h"
#include "nsAutoPtr.h"
#include "nsTArray.h"
class gfxContext;
class gfxASurface;
@ -40,6 +41,11 @@ public:
void AddColorStop(gfxFloat offset, const gfxRGBA& c);
void SetColorStops(mozilla::RefPtr<mozilla::gfx::GradientStops> aStops);
// This should only be called on a cairo pattern that we want to use with
// Azure. We will read back the color stops from cairo and try to look
// them up in the cache.
void CacheColorStops(mozilla::gfx::DrawTarget *aDT);
void SetMatrix(const gfxMatrix& matrix);
gfxMatrix GetMatrix() const;
gfxMatrix GetInverseMatrix() const;

View File

@ -25,6 +25,10 @@ nsSVGPaintServerFrame::SetupPaintServer(gfxContext *aContext,
if (!pattern)
return false;
if (!aContext->IsCairo()) {
pattern->CacheColorStops(aContext->GetDrawTarget());
}
aContext->SetPattern(pattern);
return true;
}