Bug 1089177, part 1 - Expose PatternFromState to help with Moz2D porting. r=mattwoodrow

This commit is contained in:
Jonathan Watt 2014-10-28 14:40:39 +00:00
parent d6bd4e18e3
commit 99eeb78806
2 changed files with 48 additions and 42 deletions

View File

@ -36,22 +36,16 @@ using namespace mozilla::gfx;
UserDataKey gfxContext::sDontUseAsSourceKey;
/* This class lives on the stack and allows gfxContext users to easily, and
* performantly get a gfx::Pattern to use for drawing in their current context.
*/
class PatternFromState
{
public:
explicit PatternFromState(gfxContext *aContext) : mContext(aContext), mPattern(nullptr) {}
~PatternFromState() { if (mPattern) { mPattern->~Pattern(); } }
operator mozilla::gfx::Pattern&()
PatternFromState::operator mozilla::gfx::Pattern&()
{
gfxContext::AzureState &state = mContext->CurrentState();
if (state.pattern) {
return *state.pattern->GetPattern(mContext->mDT, state.patternTransformChanged ? &state.patternTransform : nullptr);
} else if (state.sourceSurface) {
}
if (state.sourceSurface) {
Matrix transform = state.surfTransform;
if (state.patternTransformChanged) {
@ -67,22 +61,13 @@ public:
mPattern = new (mSurfacePattern.addr())
SurfacePattern(state.sourceSurface, ExtendMode::CLAMP, transform);
return *mPattern;
} else {
}
mPattern = new (mColorPattern.addr())
ColorPattern(state.color);
return *mPattern;
}
}
private:
union {
mozilla::AlignedStorage2<mozilla::gfx::ColorPattern> mColorPattern;
mozilla::AlignedStorage2<mozilla::gfx::SurfacePattern> mSurfacePattern;
};
gfxContext *mContext;
Pattern *mPattern;
};
gfxContext::gfxContext(DrawTarget *aTarget, const Point& aDeviceOffset)
: mPathIsRect(false)

View File

@ -844,4 +844,25 @@ private:
bool mSubpixelAntialiasingEnabled;
};
/* This class lives on the stack and allows gfxContext users to easily, and
* performantly get a gfx::Pattern to use for drawing in their current context.
*/
class PatternFromState
{
public:
explicit PatternFromState(gfxContext *aContext) : mContext(aContext), mPattern(nullptr) {}
~PatternFromState() { if (mPattern) { mPattern->~Pattern(); } }
operator mozilla::gfx::Pattern&();
private:
union {
mozilla::AlignedStorage2<mozilla::gfx::ColorPattern> mColorPattern;
mozilla::AlignedStorage2<mozilla::gfx::SurfacePattern> mSurfacePattern;
};
gfxContext *mContext;
mozilla::gfx::Pattern *mPattern;
};
#endif /* GFX_CONTEXT_H */