Bug 795763 - Support extend mode for gradient patterns in DrawTargetCairo. r=joe

This commit is contained in:
Anthony Jones 2012-10-10 06:32:36 -04:00
parent 4c511b46d7
commit f118b7b673
2 changed files with 22 additions and 7 deletions

View File

@ -221,8 +221,10 @@ GfxPatternToCairoPattern(const Pattern& aPattern, Float aAlpha)
pattern.mEnd.x, pattern.mEnd.y);
MOZ_ASSERT(pattern.mStops->GetBackendType() == BACKEND_CAIRO);
const std::vector<GradientStop>& stops =
static_cast<GradientStopsCairo*>(pattern.mStops.get())->GetStops();
GradientStopsCairo* cairoStops = static_cast<GradientStopsCairo*>(pattern.mStops.get());
cairo_pattern_set_extend(pat, GfxExtendToCairoExtend(cairoStops->GetExtendMode()));
const std::vector<GradientStop>& stops = cairoStops->GetStops();
for (size_t i = 0; i < stops.size(); ++i) {
const GradientStop& stop = stops[i];
cairo_pattern_add_color_stop_rgba(pat, stop.offset, stop.color.r,
@ -239,8 +241,11 @@ GfxPatternToCairoPattern(const Pattern& aPattern, Float aAlpha)
pat = cairo_pattern_create_radial(pattern.mCenter1.x, pattern.mCenter1.y, pattern.mRadius1,
pattern.mCenter2.x, pattern.mCenter2.y, pattern.mRadius2);
const std::vector<GradientStop>& stops =
static_cast<GradientStopsCairo*>(pattern.mStops.get())->GetStops();
MOZ_ASSERT(pattern.mStops->GetBackendType() == BACKEND_CAIRO);
GradientStopsCairo* cairoStops = static_cast<GradientStopsCairo*>(pattern.mStops.get());
cairo_pattern_set_extend(pat, GfxExtendToCairoExtend(cairoStops->GetExtendMode()));
const std::vector<GradientStop>& stops = cairoStops->GetStops();
for (size_t i = 0; i < stops.size(); ++i) {
const GradientStop& stop = stops[i];
cairo_pattern_add_color_stop_rgba(pat, stop.offset, stop.color.r,
@ -727,9 +732,11 @@ DrawTargetCairo::ClearSurfaceForUnboundedSource(const CompositionOp &aOperator)
TemporaryRef<GradientStops>
DrawTargetCairo::CreateGradientStops(GradientStop *aStops, uint32_t aNumStops, ExtendMode aExtendMode) const
DrawTargetCairo::CreateGradientStops(GradientStop *aStops, uint32_t aNumStops,
ExtendMode aExtendMode) const
{
RefPtr<GradientStopsCairo> stops = new GradientStopsCairo(aStops, aNumStops);
RefPtr<GradientStopsCairo> stops = new GradientStopsCairo(aStops, aNumStops,
aExtendMode);
return stops;
}

View File

@ -20,7 +20,9 @@ class SourceSurfaceCairo;
class GradientStopsCairo : public GradientStops
{
public:
GradientStopsCairo(GradientStop* aStops, uint32_t aNumStops)
GradientStopsCairo(GradientStop* aStops, uint32_t aNumStops,
ExtendMode aExtendMode)
: mExtendMode(aExtendMode)
{
for (uint32_t i = 0; i < aNumStops; ++i) {
mStops.push_back(aStops[i]);
@ -34,10 +36,16 @@ class GradientStopsCairo : public GradientStops
return mStops;
}
ExtendMode GetExtendMode() const
{
return mExtendMode;
}
virtual BackendType GetBackendType() const { return BACKEND_CAIRO; }
private:
std::vector<GradientStop> mStops;
ExtendMode mExtendMode;
};
class DrawTargetCairo : public DrawTarget