зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1073363, part 3 - Convert some Mozilla code to use Moz2D's new GeneralPattern class. r=Bas
This commit is contained in:
Родитель
eab304ab9a
Коммит
4d2d3b0296
|
@ -82,6 +82,7 @@
|
|||
#include "mozilla/gfx/Helpers.h"
|
||||
#include "mozilla/gfx/PathHelpers.h"
|
||||
#include "mozilla/gfx/DataSurfaceHelpers.h"
|
||||
#include "mozilla/gfx/PatternHelpers.h"
|
||||
#include "mozilla/ipc/DocumentRendererParent.h"
|
||||
#include "mozilla/ipc/PDocumentRendererParent.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
|
@ -223,42 +224,33 @@ public:
|
|||
typedef CanvasRenderingContext2D::Style Style;
|
||||
typedef CanvasRenderingContext2D::ContextState ContextState;
|
||||
|
||||
CanvasGeneralPattern() : mPattern(nullptr) {}
|
||||
~CanvasGeneralPattern()
|
||||
{
|
||||
if (mPattern) {
|
||||
mPattern->~Pattern();
|
||||
}
|
||||
}
|
||||
|
||||
Pattern& ForStyle(CanvasRenderingContext2D *aCtx,
|
||||
Style aStyle,
|
||||
DrawTarget *aRT)
|
||||
{
|
||||
// This should only be called once or the mPattern destructor will
|
||||
// not be executed.
|
||||
NS_ASSERTION(!mPattern, "ForStyle() should only be called once on CanvasGeneralPattern!");
|
||||
NS_ASSERTION(!mPattern.GetPattern(), "ForStyle() should only be called once on CanvasGeneralPattern!");
|
||||
|
||||
const ContextState &state = aCtx->CurrentState();
|
||||
|
||||
if (state.StyleIsColor(aStyle)) {
|
||||
mPattern = new (mColorPattern.addr()) ColorPattern(Color::FromABGR(state.colorStyles[aStyle]));
|
||||
mPattern.InitColorPattern(Color::FromABGR(state.colorStyles[aStyle]));
|
||||
} else if (state.gradientStyles[aStyle] &&
|
||||
state.gradientStyles[aStyle]->GetType() == CanvasGradient::Type::LINEAR) {
|
||||
CanvasLinearGradient *gradient =
|
||||
static_cast<CanvasLinearGradient*>(state.gradientStyles[aStyle].get());
|
||||
|
||||
mPattern = new (mLinearGradientPattern.addr())
|
||||
LinearGradientPattern(gradient->mBegin, gradient->mEnd,
|
||||
gradient->GetGradientStopsForTarget(aRT));
|
||||
mPattern.InitLinearGradientPattern(gradient->mBegin, gradient->mEnd,
|
||||
gradient->GetGradientStopsForTarget(aRT));
|
||||
} else if (state.gradientStyles[aStyle] &&
|
||||
state.gradientStyles[aStyle]->GetType() == CanvasGradient::Type::RADIAL) {
|
||||
CanvasRadialGradient *gradient =
|
||||
static_cast<CanvasRadialGradient*>(state.gradientStyles[aStyle].get());
|
||||
|
||||
mPattern = new (mRadialGradientPattern.addr())
|
||||
RadialGradientPattern(gradient->mCenter1, gradient->mCenter2, gradient->mRadius1,
|
||||
gradient->mRadius2, gradient->GetGradientStopsForTarget(aRT));
|
||||
mPattern.InitRadialGradientPattern(gradient->mCenter1, gradient->mCenter2,
|
||||
gradient->mRadius1, gradient->mRadius2,
|
||||
gradient->GetGradientStopsForTarget(aRT));
|
||||
} else if (state.patternStyles[aStyle]) {
|
||||
if (aCtx->mCanvasElement) {
|
||||
CanvasUtils::DoDrawImageSecurityCheck(aCtx->mCanvasElement,
|
||||
|
@ -273,21 +265,14 @@ public:
|
|||
} else {
|
||||
mode = ExtendMode::REPEAT;
|
||||
}
|
||||
mPattern = new (mSurfacePattern.addr())
|
||||
SurfacePattern(state.patternStyles[aStyle]->mSurface, mode,
|
||||
state.patternStyles[aStyle]->mTransform);
|
||||
mPattern.InitSurfacePattern(state.patternStyles[aStyle]->mSurface, mode,
|
||||
state.patternStyles[aStyle]->mTransform);
|
||||
}
|
||||
|
||||
return *mPattern;
|
||||
return *mPattern.GetPattern();
|
||||
}
|
||||
|
||||
union {
|
||||
AlignedStorage2<ColorPattern> mColorPattern;
|
||||
AlignedStorage2<LinearGradientPattern> mLinearGradientPattern;
|
||||
AlignedStorage2<RadialGradientPattern> mRadialGradientPattern;
|
||||
AlignedStorage2<SurfacePattern> mSurfacePattern;
|
||||
};
|
||||
Pattern *mPattern;
|
||||
GeneralPattern mPattern;
|
||||
};
|
||||
|
||||
/* This is an RAII based class that can be used as a drawtarget for
|
||||
|
|
|
@ -20,18 +20,14 @@ using namespace mozilla::gfx;
|
|||
gfxPattern::gfxPattern(const gfxRGBA& aColor)
|
||||
: mExtend(EXTEND_NONE)
|
||||
{
|
||||
mGfxPattern =
|
||||
new (mColorPattern.addr()) ColorPattern(Color(aColor.r, aColor.g, aColor.b, aColor.a));
|
||||
mGfxPattern.InitColorPattern(Color(aColor.r, aColor.g, aColor.b, aColor.a));
|
||||
}
|
||||
|
||||
// linear
|
||||
gfxPattern::gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1)
|
||||
: mExtend(EXTEND_NONE)
|
||||
{
|
||||
mGfxPattern =
|
||||
new (mLinearGradientPattern.addr()) LinearGradientPattern(Point(x0, y0),
|
||||
Point(x1, y1),
|
||||
nullptr);
|
||||
mGfxPattern.InitLinearGradientPattern(Point(x0, y0), Point(x1, y1), nullptr);
|
||||
}
|
||||
|
||||
// radial
|
||||
|
@ -39,11 +35,8 @@ gfxPattern::gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0,
|
|||
gfxFloat cx1, gfxFloat cy1, gfxFloat radius1)
|
||||
: mExtend(EXTEND_NONE)
|
||||
{
|
||||
mGfxPattern =
|
||||
new (mRadialGradientPattern.addr()) RadialGradientPattern(Point(cx0, cy0),
|
||||
Point(cx1, cy1),
|
||||
radius0, radius1,
|
||||
nullptr);
|
||||
mGfxPattern.InitRadialGradientPattern(Point(cx0, cy0), Point(cx1, cy1),
|
||||
radius0, radius1, nullptr);
|
||||
}
|
||||
|
||||
// Azure
|
||||
|
@ -51,23 +44,15 @@ gfxPattern::gfxPattern(SourceSurface *aSurface, const Matrix &aPatternToUserSpac
|
|||
: mPatternToUserSpace(aPatternToUserSpace)
|
||||
, mExtend(EXTEND_NONE)
|
||||
{
|
||||
mGfxPattern = new (mSurfacePattern.addr())
|
||||
SurfacePattern(aSurface, ToExtendMode(mExtend), Matrix(), // matrix is overridden in GetPattern()
|
||||
mozilla::gfx::Filter::GOOD);
|
||||
}
|
||||
|
||||
gfxPattern::~gfxPattern()
|
||||
{
|
||||
if (mGfxPattern) {
|
||||
mGfxPattern->~Pattern();
|
||||
}
|
||||
mGfxPattern.InitSurfacePattern(aSurface, ToExtendMode(mExtend), Matrix(), // matrix is overridden in GetPattern()
|
||||
mozilla::gfx::Filter::GOOD);
|
||||
}
|
||||
|
||||
void
|
||||
gfxPattern::AddColorStop(gfxFloat offset, const gfxRGBA& c)
|
||||
{
|
||||
if (mGfxPattern->GetType() != PatternType::LINEAR_GRADIENT &&
|
||||
mGfxPattern->GetType() != PatternType::RADIAL_GRADIENT) {
|
||||
if (mGfxPattern.GetPattern()->GetType() != PatternType::LINEAR_GRADIENT &&
|
||||
mGfxPattern.GetPattern()->GetType() != PatternType::RADIAL_GRADIENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -156,25 +141,31 @@ gfxPattern::GetPattern(DrawTarget *aTarget,
|
|||
ToExtendMode(mExtend));
|
||||
}
|
||||
|
||||
switch (mGfxPattern->GetType()) {
|
||||
case PatternType::SURFACE:
|
||||
mSurfacePattern.addr()->mMatrix = patternToUser;
|
||||
mSurfacePattern.addr()->mExtendMode = ToExtendMode(mExtend);
|
||||
switch (mGfxPattern.GetPattern()->GetType()) {
|
||||
case PatternType::SURFACE: {
|
||||
SurfacePattern* surfacePattern = static_cast<SurfacePattern*>(mGfxPattern.GetPattern());
|
||||
surfacePattern->mMatrix = patternToUser;
|
||||
surfacePattern->mExtendMode = ToExtendMode(mExtend);
|
||||
break;
|
||||
case PatternType::LINEAR_GRADIENT:
|
||||
mLinearGradientPattern.addr()->mMatrix = patternToUser;
|
||||
mLinearGradientPattern.addr()->mStops = mStops;
|
||||
}
|
||||
case PatternType::LINEAR_GRADIENT: {
|
||||
LinearGradientPattern* linearGradientPattern = static_cast<LinearGradientPattern*>(mGfxPattern.GetPattern());
|
||||
linearGradientPattern->mMatrix = patternToUser;
|
||||
linearGradientPattern->mStops = mStops;
|
||||
break;
|
||||
case PatternType::RADIAL_GRADIENT:
|
||||
mRadialGradientPattern.addr()->mMatrix = patternToUser;
|
||||
mRadialGradientPattern.addr()->mStops = mStops;
|
||||
}
|
||||
case PatternType::RADIAL_GRADIENT: {
|
||||
RadialGradientPattern* radialGradientPattern = static_cast<RadialGradientPattern*>(mGfxPattern.GetPattern());
|
||||
radialGradientPattern->mMatrix = patternToUser;
|
||||
radialGradientPattern->mStops = mStops;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
/* Reassure the compiler we are handling all the enum values. */
|
||||
break;
|
||||
}
|
||||
|
||||
return mGfxPattern;
|
||||
return mGfxPattern.GetPattern();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -187,11 +178,11 @@ gfxPattern::SetExtend(GraphicsExtend extend)
|
|||
bool
|
||||
gfxPattern::IsOpaque()
|
||||
{
|
||||
if (mGfxPattern->GetType() != PatternType::SURFACE) {
|
||||
if (mGfxPattern.GetPattern()->GetType() != PatternType::SURFACE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mSurfacePattern.addr()->mSurface->GetFormat() == SurfaceFormat::B8G8R8X8) {
|
||||
if (static_cast<SurfacePattern*>(mGfxPattern.GetPattern())->mSurface->GetFormat() == SurfaceFormat::B8G8R8X8) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -206,27 +197,27 @@ gfxPattern::Extend() const
|
|||
void
|
||||
gfxPattern::SetFilter(GraphicsFilter filter)
|
||||
{
|
||||
if (mGfxPattern->GetType() != PatternType::SURFACE) {
|
||||
if (mGfxPattern.GetPattern()->GetType() != PatternType::SURFACE) {
|
||||
return;
|
||||
}
|
||||
|
||||
mSurfacePattern.addr()->mFilter = ToFilter(filter);
|
||||
static_cast<SurfacePattern*>(mGfxPattern.GetPattern())->mFilter = ToFilter(filter);
|
||||
}
|
||||
|
||||
GraphicsFilter
|
||||
gfxPattern::Filter() const
|
||||
{
|
||||
if (mGfxPattern->GetType() != PatternType::SURFACE) {
|
||||
if (mGfxPattern.GetPattern()->GetType() != PatternType::SURFACE) {
|
||||
return GraphicsFilter::FILTER_GOOD;
|
||||
}
|
||||
return ThebesFilter(mSurfacePattern.addr()->mFilter);
|
||||
return ThebesFilter(static_cast<const SurfacePattern*>(mGfxPattern.GetPattern())->mFilter);
|
||||
}
|
||||
|
||||
bool
|
||||
gfxPattern::GetSolidColor(gfxRGBA& aColor)
|
||||
{
|
||||
if (mGfxPattern->GetType() == PatternType::COLOR) {
|
||||
aColor = ThebesColor(mColorPattern.addr()->mColor);
|
||||
if (mGfxPattern.GetPattern()->GetType() == PatternType::COLOR) {
|
||||
aColor = ThebesColor(static_cast<ColorPattern*>(mGfxPattern.GetPattern())->mColor);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -236,7 +227,7 @@ gfxPattern::GetSolidColor(gfxRGBA& aColor)
|
|||
gfxPattern::GraphicsPatternType
|
||||
gfxPattern::GetType() const
|
||||
{
|
||||
return ThebesPatternType(mGfxPattern->GetType());
|
||||
return ThebesPatternType(mGfxPattern.GetPattern()->GetType());
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "gfxMatrix.h"
|
||||
#include "mozilla/Alignment.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/PatternHelpers.h"
|
||||
#include "GraphicsFilter.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
@ -95,17 +96,9 @@ public:
|
|||
|
||||
private:
|
||||
// Private destructor, to discourage deletion outside of Release():
|
||||
~gfxPattern();
|
||||
|
||||
union {
|
||||
mozilla::AlignedStorage2<mozilla::gfx::ColorPattern> mColorPattern;
|
||||
mozilla::AlignedStorage2<mozilla::gfx::LinearGradientPattern> mLinearGradientPattern;
|
||||
mozilla::AlignedStorage2<mozilla::gfx::RadialGradientPattern> mRadialGradientPattern;
|
||||
mozilla::AlignedStorage2<mozilla::gfx::SurfacePattern> mSurfacePattern;
|
||||
};
|
||||
|
||||
mozilla::gfx::Pattern *mGfxPattern;
|
||||
~gfxPattern() {}
|
||||
|
||||
mozilla::gfx::GeneralPattern mGfxPattern;
|
||||
mozilla::RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
|
||||
mozilla::gfx::Matrix mPatternToUserSpace;
|
||||
mozilla::RefPtr<mozilla::gfx::GradientStops> mStops;
|
||||
|
|
Загрузка…
Ссылка в новой задаче