Bug 1418816 - Part 2: Handle repeated image layers in ImageLayerComposite. r=mattwoodrow

Depends on D6024

Differential Revision: https://phabricator.services.mozilla.com/D6025

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jamie Nicol 2018-09-19 12:14:10 +00:00
Родитель 5294656897
Коммит b1d6426ad5
3 изменённых файлов: 50 добавлений и 5 удалений

Просмотреть файл

@ -60,5 +60,23 @@ void ImageLayer::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSu
ComputeEffectiveTransformForMaskLayers(aTransformToSurface);
}
gfx::IntPoint
ImageLayer::GetTopLeftTilePos(const gfx::IntRect& aDestRect,
const gfx::IntRect& aFillRect,
const gfx::IntSize& aRepeatSize)
{
int x = aDestRect.x;
while (aRepeatSize.width && x > aFillRect.x) {
x -= aRepeatSize.width;
}
int y = aDestRect.y;
while (aRepeatSize.width && y > aFillRect.y) {
y -= aRepeatSize.height;
}
return gfx::IntPoint(x, y);
}
} // namespace layers
} // namespace mozilla

Просмотреть файл

@ -98,6 +98,13 @@ protected:
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;
virtual void DumpPacket(layerscope::LayersPacket* aPacket, const void* aParent) override;
/*
* Calculate the position of the top-left tile for repeated images.
*/
static gfx::IntPoint GetTopLeftTilePos(const gfx::IntRect& aDestRect,
const gfx::IntRect& aFillRect,
const gfx::IntSize& aRepeatSize);
RefPtr<ImageContainer> mContainer;
gfx::SamplingFilter mSamplingFilter;
gfx::IntSize mScaleToSize;

Просмотреть файл

@ -103,11 +103,31 @@ ImageLayerComposite::RenderLayer(const IntRect& aClipRect,
RenderWithAllMasks(this, mCompositor, aClipRect,
[&](EffectChain& effectChain, const IntRect& clipRect) {
mImageHost->SetTextureSourceProvider(mCompositor);
mImageHost->Composite(mCompositor, this, effectChain,
GetEffectiveOpacity(),
GetEffectiveTransformForBuffer(),
GetSamplingFilter(),
clipRect);
const IntRect destRect(IntPoint(0, 0), mImageHost->GetImageSize());
const IntRect fillRect = mVisibleRegion.GetBounds().ToUnknownRect();
const IntPoint topLeft = GetTopLeftTilePos(destRect, fillRect, mRepeatSize);
for (int x = topLeft.x; x < fillRect.XMost(); x += mRepeatSize.width) {
for (int y = topLeft.y; y < fillRect.YMost(); y += mRepeatSize.height) {
Matrix4x4 tileTransform = GetEffectiveTransformForBuffer();
tileTransform.PreTranslate(x - destRect.x, y - destRect.y, 0);
mImageHost->Composite(mCompositor, this, effectChain,
GetEffectiveOpacity(),
tileTransform,
GetSamplingFilter(),
clipRect);
if (!mRepeatSize.height) {
break;
}
}
if (!mRepeatSize.width) {
break;
}
}
});
mImageHost->BumpFlashCounter();
}