mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 993475 - Consolidate masking code in BasicCompositor and BasicLayersImpl. r=mattwoodrow
This commit is contained in:
parent
734f540069
commit
f8cf8f11e8
@ -4,6 +4,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "BasicCompositor.h"
|
||||
#include "BasicLayersImpl.h" // for FillRectWithMask
|
||||
#include "TextureHostBasic.h"
|
||||
#include "mozilla/layers/Effects.h"
|
||||
#include "mozilla/layers/YCbCrImageDataSerializer.h"
|
||||
@ -136,7 +137,7 @@ DrawSurfaceWithTextureCoords(DrawTarget *aDest,
|
||||
gfx::Filter aFilter,
|
||||
float aOpacity,
|
||||
SourceSurface *aMask,
|
||||
const Matrix& aMaskTransform)
|
||||
const Matrix* aMaskTransform)
|
||||
{
|
||||
// Convert aTextureCoords into aSource's coordinate space
|
||||
gfxRect sourceRect(aTextureCoords.x * aSource->GetSize().width,
|
||||
@ -155,22 +156,8 @@ DrawSurfaceWithTextureCoords(DrawTarget *aDest,
|
||||
gfx::Rect unitRect(0, 0, 1, 1);
|
||||
ExtendMode mode = unitRect.Contains(aTextureCoords) ? ExtendMode::CLAMP : ExtendMode::REPEAT;
|
||||
|
||||
if (aMask) {
|
||||
aDest->PushClipRect(aDestRect);
|
||||
Matrix maskTransformInverse = aMaskTransform;
|
||||
maskTransformInverse.Invert();
|
||||
Matrix dtTransform = aDest->GetTransform();
|
||||
aDest->SetTransform(aMaskTransform);
|
||||
Matrix patternMatrix = maskTransformInverse * dtTransform * matrix;
|
||||
aDest->MaskSurface(SurfacePattern(aSource, mode, patternMatrix, aFilter),
|
||||
aMask, Point(), DrawOptions(aOpacity));
|
||||
aDest->SetTransform(dtTransform);
|
||||
aDest->PopClip();
|
||||
} else {
|
||||
aDest->FillRect(aDestRect,
|
||||
SurfacePattern(aSource, mode, matrix, aFilter),
|
||||
DrawOptions(aOpacity));
|
||||
}
|
||||
FillRectWithMask(aDest, aDestRect, aSource, aFilter, DrawOptions(aOpacity),
|
||||
mode, aMask, aMaskTransform, &matrix);
|
||||
}
|
||||
|
||||
static pixman_transform
|
||||
@ -318,19 +305,8 @@ BasicCompositor::DrawQuad(const gfx::Rect& aRect,
|
||||
EffectSolidColor* effectSolidColor =
|
||||
static_cast<EffectSolidColor*>(aEffectChain.mPrimaryEffect.get());
|
||||
|
||||
if (sourceMask) {
|
||||
dest->PushClipRect(aRect);
|
||||
Matrix dtTransform = dest->GetTransform();
|
||||
dest->SetTransform(maskTransform);
|
||||
dest->MaskSurface(ColorPattern(effectSolidColor->mColor),
|
||||
sourceMask, Point(), DrawOptions(aOpacity));
|
||||
dest->SetTransform(dtTransform);
|
||||
dest->PopClip();
|
||||
} else {
|
||||
dest->FillRect(aRect,
|
||||
ColorPattern(effectSolidColor->mColor),
|
||||
DrawOptions(aOpacity));
|
||||
}
|
||||
FillRectWithMask(dest, aRect, effectSolidColor->mColor,
|
||||
DrawOptions(aOpacity), sourceMask, &maskTransform);
|
||||
break;
|
||||
}
|
||||
case EFFECT_RGB: {
|
||||
@ -342,7 +318,7 @@ BasicCompositor::DrawQuad(const gfx::Rect& aRect,
|
||||
source->GetSurface(),
|
||||
texturedEffect->mTextureCoords,
|
||||
texturedEffect->mFilter,
|
||||
aOpacity, sourceMask, maskTransform);
|
||||
aOpacity, sourceMask, &maskTransform);
|
||||
break;
|
||||
}
|
||||
case EFFECT_YCBCR: {
|
||||
@ -360,7 +336,7 @@ BasicCompositor::DrawQuad(const gfx::Rect& aRect,
|
||||
sourceSurf,
|
||||
effectRenderTarget->mTextureCoords,
|
||||
effectRenderTarget->mFilter,
|
||||
aOpacity, sourceMask, maskTransform);
|
||||
aOpacity, sourceMask, &maskTransform);
|
||||
break;
|
||||
}
|
||||
case EFFECT_COMPONENT_ALPHA: {
|
||||
|
@ -60,16 +60,15 @@ FillRectWithMask(DrawTarget* aDT,
|
||||
const Rect& aRect,
|
||||
const Color& aColor,
|
||||
const DrawOptions& aOptions,
|
||||
Layer* aMaskLayer)
|
||||
SourceSurface* aMaskSource,
|
||||
const Matrix* aMaskTransform)
|
||||
{
|
||||
AutoMoz2DMaskData mask;
|
||||
if (GetMaskData(aMaskLayer, &mask)) {
|
||||
if (aMaskSource && aMaskTransform) {
|
||||
aDT->PushClipRect(aRect);
|
||||
Matrix oldTransform = aDT->GetTransform();
|
||||
|
||||
aDT->SetTransform(mask.GetTransform());
|
||||
aDT->MaskSurface(ColorPattern(aColor), mask.GetSurface(),
|
||||
Point(0, 0), aOptions);
|
||||
aDT->SetTransform(*aMaskTransform);
|
||||
aDT->MaskSurface(ColorPattern(aColor), aMaskSource, Point(), aOptions);
|
||||
aDT->SetTransform(oldTransform);
|
||||
aDT->PopClip();
|
||||
return;
|
||||
@ -77,6 +76,60 @@ FillRectWithMask(DrawTarget* aDT,
|
||||
|
||||
aDT->FillRect(aRect, ColorPattern(aColor), aOptions);
|
||||
}
|
||||
void
|
||||
FillRectWithMask(DrawTarget* aDT,
|
||||
const Rect& aRect,
|
||||
const Color& aColor,
|
||||
const DrawOptions& aOptions,
|
||||
Layer* aMaskLayer)
|
||||
{
|
||||
AutoMoz2DMaskData mask;
|
||||
if (GetMaskData(aMaskLayer, &mask)) {
|
||||
const Matrix& maskTransform = mask.GetTransform();
|
||||
FillRectWithMask(aDT, aRect, aColor, aOptions, mask.GetSurface(), &maskTransform);
|
||||
return;
|
||||
}
|
||||
|
||||
FillRectWithMask(aDT, aRect, aColor, aOptions);
|
||||
}
|
||||
|
||||
void
|
||||
FillRectWithMask(DrawTarget* aDT,
|
||||
const Rect& aRect,
|
||||
SourceSurface* aSurface,
|
||||
Filter aFilter,
|
||||
const DrawOptions& aOptions,
|
||||
ExtendMode aExtendMode,
|
||||
SourceSurface* aMaskSource,
|
||||
const Matrix* aMaskTransform,
|
||||
const Matrix* aSurfaceTransform)
|
||||
{
|
||||
if (aMaskSource && aMaskTransform) {
|
||||
aDT->PushClipRect(aRect);
|
||||
Matrix oldTransform = aDT->GetTransform();
|
||||
|
||||
Matrix inverseMask = *aMaskTransform;
|
||||
inverseMask.Invert();
|
||||
|
||||
Matrix transform = inverseMask * oldTransform;
|
||||
if (aSurfaceTransform) {
|
||||
transform = transform * (*aSurfaceTransform);
|
||||
}
|
||||
|
||||
SurfacePattern source(aSurface, aExtendMode, transform, aFilter);
|
||||
|
||||
aDT->SetTransform(*aMaskTransform);
|
||||
aDT->MaskSurface(source, aMaskSource, Point(0, 0), aOptions);
|
||||
aDT->SetTransform(oldTransform);
|
||||
aDT->PopClip();
|
||||
return;
|
||||
}
|
||||
|
||||
aDT->FillRect(aRect,
|
||||
SurfacePattern(aSurface, aExtendMode,
|
||||
aSurfaceTransform ? (*aSurfaceTransform) : Matrix(),
|
||||
aFilter), aOptions);
|
||||
}
|
||||
|
||||
void
|
||||
FillRectWithMask(DrawTarget* aDT,
|
||||
@ -88,25 +141,13 @@ FillRectWithMask(DrawTarget* aDT,
|
||||
{
|
||||
AutoMoz2DMaskData mask;
|
||||
if (GetMaskData(aMaskLayer, &mask)) {
|
||||
aDT->PushClipRect(aRect);
|
||||
Matrix oldTransform = aDT->GetTransform();
|
||||
Matrix transform = oldTransform;
|
||||
|
||||
Matrix inverseMask = mask.GetTransform();
|
||||
inverseMask.Invert();
|
||||
|
||||
transform *= inverseMask;
|
||||
|
||||
SurfacePattern source(aSurface, ExtendMode::CLAMP, transform, aFilter);
|
||||
|
||||
aDT->SetTransform(mask.GetTransform());
|
||||
aDT->MaskSurface(source, mask.GetSurface(), Point(0, 0), aOptions);
|
||||
aDT->SetTransform(oldTransform);
|
||||
aDT->PopClip();
|
||||
const Matrix& maskTransform = mask.GetTransform();
|
||||
FillRectWithMask(aDT, aRect, aSurface, aFilter, aOptions, ExtendMode::CLAMP,
|
||||
mask.GetSurface(), &maskTransform);
|
||||
return;
|
||||
}
|
||||
|
||||
aDT->FillRect(aRect, SurfacePattern(aSurface, ExtendMode::CLAMP, Matrix(), aFilter), aOptions);
|
||||
FillRectWithMask(aDT, aRect, aSurface, aFilter, aOptions, ExtendMode::CLAMP);
|
||||
}
|
||||
|
||||
BasicImplData*
|
||||
|
@ -91,6 +91,23 @@ PaintWithMask(gfxContext* aContext, float aOpacity, Layer* aMaskLayer);
|
||||
|
||||
// Fill the rect with the source, using a mask and opacity, if present
|
||||
void
|
||||
FillRectWithMask(gfx::DrawTarget* aDT,
|
||||
const gfx::Rect& aRect,
|
||||
const gfx::Color& aColor,
|
||||
const gfx::DrawOptions& aOptions,
|
||||
gfx::SourceSurface* aMaskSource = nullptr,
|
||||
const gfx::Matrix* aMaskTransform = nullptr);
|
||||
void
|
||||
FillRectWithMask(gfx::DrawTarget* aDT,
|
||||
const gfx::Rect& aRect,
|
||||
gfx::SourceSurface* aSurface,
|
||||
gfx::Filter aFilter,
|
||||
const gfx::DrawOptions& aOptions,
|
||||
gfx::ExtendMode aExtendMode,
|
||||
gfx::SourceSurface* aMaskSource = nullptr,
|
||||
const gfx::Matrix* aMaskTransform = nullptr,
|
||||
const gfx::Matrix* aSurfaceTransform = nullptr);
|
||||
void
|
||||
FillRectWithMask(gfx::DrawTarget* aDT,
|
||||
const gfx::Rect& aRect,
|
||||
gfx::SourceSurface* aSurface,
|
||||
|
Loading…
Reference in New Issue
Block a user