зеркало из https://github.com/mozilla/gecko-dev.git
Bug 990338 - Clean up CopyableCanvasLayer. r=nical
This commit is contained in:
Родитель
d179b128c4
Коммит
c90effdac3
|
@ -59,8 +59,6 @@ CopyableCanvasLayer::Initialize(const Data& aData)
|
|||
} else if (aData.mDrawTarget) {
|
||||
mDrawTarget = aData.mDrawTarget;
|
||||
mSurface = mDrawTarget->Snapshot();
|
||||
mDeprecatedSurface =
|
||||
gfxPlatform::GetPlatform()->CreateThebesSurfaceAliasForDrawTarget_hack(mDrawTarget);
|
||||
mNeedsYFlip = false;
|
||||
} else {
|
||||
NS_ERROR("CanvasLayer created without mSurface, mDrawTarget or mGLContext?");
|
||||
|
@ -76,8 +74,7 @@ CopyableCanvasLayer::IsDataValid(const Data& aData)
|
|||
}
|
||||
|
||||
void
|
||||
CopyableCanvasLayer::UpdateTarget(DrawTarget* aDestTarget,
|
||||
SourceSurface* aMaskSurface)
|
||||
CopyableCanvasLayer::UpdateTarget(DrawTarget* aDestTarget)
|
||||
{
|
||||
if (!IsDirty())
|
||||
return;
|
||||
|
@ -89,7 +86,12 @@ CopyableCanvasLayer::UpdateTarget(DrawTarget* aDestTarget,
|
|||
}
|
||||
|
||||
if (!mGLContext && aDestTarget) {
|
||||
PaintWithOpacity(aDestTarget, 1.0f, aMaskSurface);
|
||||
NS_ASSERTION(mSurface, "Must have surface to draw!");
|
||||
if (mSurface) {
|
||||
SurfacePattern source(mSurface, ExtendMode::CLAMP, Matrix(), ToFilter(mFilter));
|
||||
aDestTarget->FillRect(Rect(0, 0, mBounds.width, mBounds.height),
|
||||
source, DrawOptions(1.0f, CompositionOp::OP_SOURCE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -166,193 +168,6 @@ CopyableCanvasLayer::UpdateTarget(DrawTarget* aDestTarget,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
CopyableCanvasLayer::DeprecatedUpdateSurface(gfxASurface* aDestSurface,
|
||||
Layer* aMaskLayer)
|
||||
{
|
||||
if (!IsDirty())
|
||||
return;
|
||||
Painted();
|
||||
|
||||
if (mDrawTarget) {
|
||||
mDrawTarget->Flush();
|
||||
mDeprecatedSurface =
|
||||
gfxPlatform::GetPlatform()->CreateThebesSurfaceAliasForDrawTarget_hack(mDrawTarget);
|
||||
}
|
||||
|
||||
if (!mGLContext && aDestSurface) {
|
||||
nsRefPtr<gfxContext> tmpCtx = new gfxContext(aDestSurface);
|
||||
tmpCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
||||
DeprecatedPaintWithOpacity(tmpCtx, 1.0f, aMaskLayer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mGLContext) {
|
||||
nsRefPtr<gfxImageSurface> readSurf;
|
||||
RefPtr<DataSourceSurface> readDSurf;
|
||||
nsRefPtr<gfxASurface> resultSurf;
|
||||
|
||||
SharedSurface_GL* sharedSurf = mGLContext->RequestFrame();
|
||||
if (!sharedSurf) {
|
||||
NS_WARNING("Null frame received.");
|
||||
return;
|
||||
}
|
||||
|
||||
IntSize readSize(sharedSurf->Size());
|
||||
gfxImageFormat format = (GetContentFlags() & CONTENT_OPAQUE)
|
||||
? gfxImageFormat::RGB24
|
||||
: gfxImageFormat::ARGB32;
|
||||
|
||||
if (aDestSurface) {
|
||||
resultSurf = aDestSurface;
|
||||
} else {
|
||||
resultSurf = DeprecatedGetTempSurface(readSize, format);
|
||||
}
|
||||
MOZ_ASSERT(resultSurf);
|
||||
if (resultSurf->CairoStatus() != 0) {
|
||||
MOZ_ASSERT(false, "Bad resultSurf->CairoStatus().");
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(sharedSurf->APIType() == APITypeT::OpenGL);
|
||||
SharedSurface_GL* surfGL = SharedSurface_GL::Cast(sharedSurf);
|
||||
|
||||
if (surfGL->Type() == SharedSurfaceType::Basic) {
|
||||
// sharedSurf_Basic->mData must outlive readSurf and readDSurf. Alas,
|
||||
// readSurf and readDSurf may not leave the scope they were declared in.
|
||||
SharedSurface_Basic* sharedSurf_Basic = SharedSurface_Basic::Cast(surfGL);
|
||||
readDSurf = sharedSurf_Basic->GetData();
|
||||
readSurf = new gfxImageSurface(readDSurf->GetData(),
|
||||
ThebesIntSize(readDSurf->GetSize()),
|
||||
readDSurf->Stride(),
|
||||
SurfaceFormatToImageFormat(readDSurf->GetFormat()));
|
||||
} else {
|
||||
if (ToIntSize(resultSurf->GetSize()) != readSize ||
|
||||
!(readSurf = resultSurf->GetAsImageSurface()) ||
|
||||
readSurf->Format() != format)
|
||||
{
|
||||
readSurf = DeprecatedGetTempSurface(readSize, format);
|
||||
}
|
||||
|
||||
// Readback handles Flush/MarkDirty.
|
||||
mGLContext->Screen()->DeprecatedReadback(surfGL, readSurf);
|
||||
}
|
||||
MOZ_ASSERT(readSurf);
|
||||
|
||||
bool needsPremult = surfGL->HasAlpha() && !mIsGLAlphaPremult;
|
||||
if (needsPremult) {
|
||||
readSurf->Flush();
|
||||
gfxUtils::PremultiplyImageSurface(readSurf);
|
||||
readSurf->MarkDirty();
|
||||
}
|
||||
|
||||
if (readSurf != resultSurf) {
|
||||
readSurf->Flush();
|
||||
nsRefPtr<gfxContext> ctx = new gfxContext(resultSurf);
|
||||
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
||||
ctx->SetSource(readSurf);
|
||||
ctx->Paint();
|
||||
}
|
||||
|
||||
// If !aDestSurface then we will end up painting using mSurface, so
|
||||
// stick our surface into mSurface, so that the Paint() path is the same.
|
||||
if (!aDestSurface) {
|
||||
mDeprecatedSurface = resultSurf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CopyableCanvasLayer::PaintWithOpacity(gfx::DrawTarget* aTarget,
|
||||
float aOpacity,
|
||||
SourceSurface* aMaskSurface,
|
||||
gfx::CompositionOp aOperator)
|
||||
{
|
||||
if (!mSurface) {
|
||||
NS_WARNING("No valid surface to draw!");
|
||||
return;
|
||||
}
|
||||
|
||||
SurfacePattern pat(mSurface, ExtendMode::CLAMP, Matrix(), ToFilter(mFilter));
|
||||
|
||||
Matrix oldTransform;
|
||||
if (mNeedsYFlip) {
|
||||
oldTransform = aTarget->GetTransform();
|
||||
Matrix flipped = oldTransform;
|
||||
flipped.Translate(0, mBounds.height);
|
||||
flipped.Scale(1.0, -1.0);
|
||||
aTarget->SetTransform(flipped);
|
||||
}
|
||||
|
||||
DrawOptions options = DrawOptions(aOpacity, CompositionOp::OP_SOURCE);
|
||||
|
||||
if (aOperator != CompositionOp::OP_OVER) {
|
||||
options.mCompositionOp = aOperator;
|
||||
}
|
||||
|
||||
// XXX: This needs rewriting for acceptable performance using CoreGraphics.
|
||||
// Therefore - this ::PaintWithOpacity is currently not used
|
||||
Rect rect = Rect(0, 0, mBounds.width, mBounds.height);
|
||||
aTarget->FillRect(rect, pat, options);
|
||||
|
||||
if (aMaskSurface) {
|
||||
aTarget->MaskSurface(pat, aMaskSurface, Point(0, 0), options);
|
||||
}
|
||||
|
||||
if (mNeedsYFlip) {
|
||||
aTarget->SetTransform(oldTransform);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CopyableCanvasLayer::DeprecatedPaintWithOpacity(gfxContext* aContext,
|
||||
float aOpacity,
|
||||
Layer* aMaskLayer,
|
||||
gfxContext::GraphicsOperator aOperator)
|
||||
{
|
||||
if (!mDeprecatedSurface) {
|
||||
NS_WARNING("No valid surface to draw!");
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<gfxPattern> pat = new gfxPattern(mDeprecatedSurface);
|
||||
|
||||
pat->SetFilter(mFilter);
|
||||
pat->SetExtend(gfxPattern::EXTEND_PAD);
|
||||
|
||||
gfxMatrix m;
|
||||
if (mNeedsYFlip) {
|
||||
m = aContext->CurrentMatrix();
|
||||
aContext->Translate(gfxPoint(0.0, mBounds.height));
|
||||
aContext->Scale(1.0, -1.0);
|
||||
}
|
||||
|
||||
// If content opaque, then save off current operator and set to source.
|
||||
// This ensures that alpha is not applied even if the source surface
|
||||
// has an alpha channel
|
||||
gfxContext::GraphicsOperator savedOp;
|
||||
if (GetContentFlags() & CONTENT_OPAQUE) {
|
||||
savedOp = aContext->CurrentOperator();
|
||||
aContext->SetOperator(gfxContext::OPERATOR_SOURCE);
|
||||
}
|
||||
|
||||
AutoSetOperator setOperator(aContext, aOperator);
|
||||
aContext->NewPath();
|
||||
// No need to snap here; our transform is already set up to snap our rect
|
||||
aContext->Rectangle(gfxRect(0, 0, mBounds.width, mBounds.height));
|
||||
aContext->SetPattern(pat);
|
||||
|
||||
FillWithMask(aContext, aOpacity, aMaskLayer);
|
||||
// Restore surface operator
|
||||
if (GetContentFlags() & CONTENT_OPAQUE) {
|
||||
aContext->SetOperator(savedOp);
|
||||
}
|
||||
|
||||
if (mNeedsYFlip) {
|
||||
aContext->SetMatrix(m);
|
||||
}
|
||||
}
|
||||
|
||||
DataSourceSurface*
|
||||
CopyableCanvasLayer::GetTempSurface(const IntSize& aSize,
|
||||
const SurfaceFormat aFormat)
|
||||
|
@ -370,31 +185,10 @@ CopyableCanvasLayer::GetTempSurface(const IntSize& aSize,
|
|||
return mCachedTempSurface;
|
||||
}
|
||||
|
||||
gfxImageSurface*
|
||||
CopyableCanvasLayer::DeprecatedGetTempSurface(const IntSize& aSize,
|
||||
const gfxImageFormat aFormat)
|
||||
{
|
||||
if (!mDeprecatedCachedTempSurface ||
|
||||
aSize.width != mCachedSize.width ||
|
||||
aSize.height != mCachedSize.height ||
|
||||
aFormat != mDeprecatedCachedFormat)
|
||||
{
|
||||
mDeprecatedCachedTempSurface =
|
||||
new gfxImageSurface(ThebesIntSize(aSize), aFormat);
|
||||
mCachedSize = aSize;
|
||||
mDeprecatedCachedFormat = aFormat;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mDeprecatedCachedTempSurface->Stride() ==
|
||||
mDeprecatedCachedTempSurface->Width() * 4);
|
||||
return mDeprecatedCachedTempSurface;
|
||||
}
|
||||
|
||||
void
|
||||
CopyableCanvasLayer::DiscardTempSurface()
|
||||
{
|
||||
mCachedTempSurface = nullptr;
|
||||
mDeprecatedCachedTempSurface = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,16 +48,9 @@ public:
|
|||
virtual bool IsDataValid(const Data& aData);
|
||||
|
||||
protected:
|
||||
void PaintWithOpacity(gfx::DrawTarget* aTarget,
|
||||
float aOpacity,
|
||||
gfx::SourceSurface* aMaskSurface,
|
||||
gfx::CompositionOp aOperator = gfx::CompositionOp::OP_OVER);
|
||||
|
||||
void UpdateTarget(gfx::DrawTarget* aDestTarget = nullptr,
|
||||
gfx::SourceSurface* aMaskSurface = nullptr);
|
||||
void UpdateTarget(gfx::DrawTarget* aDestTarget = nullptr);
|
||||
|
||||
RefPtr<gfx::SourceSurface> mSurface;
|
||||
nsRefPtr<gfxASurface> mDeprecatedSurface;
|
||||
nsRefPtr<mozilla::gl::GLContext> mGLContext;
|
||||
mozilla::RefPtr<mozilla::gfx::DrawTarget> mDrawTarget;
|
||||
|
||||
|
@ -69,29 +62,13 @@ protected:
|
|||
bool mNeedsYFlip;
|
||||
|
||||
RefPtr<gfx::DataSourceSurface> mCachedTempSurface;
|
||||
nsRefPtr<gfxImageSurface> mDeprecatedCachedTempSurface;
|
||||
gfx::IntSize mCachedSize;
|
||||
gfx::SurfaceFormat mCachedFormat;
|
||||
gfxImageFormat mDeprecatedCachedFormat;
|
||||
|
||||
gfx::DataSourceSurface* GetTempSurface(const gfx::IntSize& aSize,
|
||||
const gfx::SurfaceFormat aFormat);
|
||||
|
||||
void DiscardTempSurface();
|
||||
|
||||
/* Deprecated thebes methods */
|
||||
protected:
|
||||
void DeprecatedPaintWithOpacity(gfxContext* aContext,
|
||||
float aOpacity,
|
||||
Layer* aMaskLayer,
|
||||
gfxContext::GraphicsOperator aOperator = gfxContext::OPERATOR_OVER);
|
||||
|
||||
void DeprecatedUpdateSurface(gfxASurface* aDestSurface = nullptr,
|
||||
Layer* aMaskLayer = nullptr);
|
||||
|
||||
gfxImageSurface* DeprecatedGetTempSurface(const gfx::IntSize& aSize,
|
||||
const gfxImageFormat aFormat);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче