Skip to content

Commit

Permalink
Bug 1731138 - Invalidate WebRender mask data from css::ImageLoader. r…
Browse files Browse the repository at this point in the history
…=tnikkel

Otherwise we don't properly repaint animated images.

Differential Revision: https://phabricator.services.mozilla.com/D126093
  • Loading branch information
emilio committed Sep 21, 2021
1 parent 032eecd commit 79c6ddf
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 31 deletions.
39 changes: 8 additions & 31 deletions gfx/layers/wr/WebRenderCommandBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2409,39 +2409,16 @@ WebRenderCommandBuilder::GenerateFallbackData(
return fallbackData.forget();
}

class WebRenderMaskData : public WebRenderUserData {
public:
explicit WebRenderMaskData(RenderRootStateManager* aManager,
nsDisplayItem* aItem)
: WebRenderUserData(aManager, aItem),
mMaskStyle(nsStyleImageLayers::LayerType::Mask),
mShouldHandleOpacity(false) {
MOZ_COUNT_CTOR(WebRenderMaskData);
}
virtual ~WebRenderMaskData() {
MOZ_COUNT_DTOR(WebRenderMaskData);
ClearImageKey();
}

void ClearImageKey() {
if (mBlobKey) {
mManager->AddBlobImageKeyForDiscard(mBlobKey.value());
}
mBlobKey.reset();
void WebRenderMaskData::ClearImageKey() {
if (mBlobKey) {
mManager->AddBlobImageKeyForDiscard(mBlobKey.value());
}
mBlobKey.reset();
}

UserDataType GetType() override { return UserDataType::eMask; }
static UserDataType Type() { return UserDataType::eMask; }

Maybe<wr::BlobImageKey> mBlobKey;
std::vector<RefPtr<gfx::ScaledFont>> mFonts;
std::vector<RefPtr<gfx::SourceSurface>> mExternalSurfaces;
LayerIntRect mItemRect;
nsPoint mMaskOffset;
nsStyleImageLayers mMaskStyle;
gfx::Size mScale;
bool mShouldHandleOpacity;
};
void WebRenderMaskData::Invalidate() {
mMaskStyle = nsStyleImageLayers(nsStyleImageLayers::LayerType::Mask);
}

Maybe<wr::ImageMask> WebRenderCommandBuilder::BuildWrMaskImage(
nsDisplayMasksAndClipPaths* aMaskItem, wr::DisplayListBuilder& aBuilder,
Expand Down
30 changes: 30 additions & 0 deletions gfx/layers/wr/WebRenderUserData.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,36 @@ class WebRenderRemoteData : public WebRenderUserData {
RefPtr<dom::RemoteBrowser> mRemoteBrowser;
};

class WebRenderMaskData : public WebRenderUserData {
public:
explicit WebRenderMaskData(RenderRootStateManager* aManager,
nsDisplayItem* aItem)
: WebRenderUserData(aManager, aItem),
mMaskStyle(nsStyleImageLayers::LayerType::Mask),
mShouldHandleOpacity(false) {
MOZ_COUNT_CTOR(WebRenderMaskData);
}
virtual ~WebRenderMaskData() {
MOZ_COUNT_DTOR(WebRenderMaskData);
ClearImageKey();
}

void ClearImageKey();
void Invalidate();

UserDataType GetType() override { return UserDataType::eMask; }
static UserDataType Type() { return UserDataType::eMask; }

Maybe<wr::BlobImageKey> mBlobKey;
std::vector<RefPtr<gfx::ScaledFont>> mFonts;
std::vector<RefPtr<gfx::SourceSurface>> mExternalSurfaces;
LayerIntRect mItemRect;
nsPoint mMaskOffset;
nsStyleImageLayers mMaskStyle;
gfx::Size mScale;
bool mShouldHandleOpacity;
};

extern void DestroyWebRenderUserDataTable(WebRenderUserDataTable* aTable);

struct WebRenderUserDataProperty {
Expand Down
Binary file added image/test/mochitest/animatedMask.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions image/test/mochitest/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ support-files =
animated1.gif
animated1.svg
animated2.gif
animatedMask.gif
animated-gif.gif
animated-gif2.gif
animated-gif_trailing-garbage.gif
Expand Down
21 changes: 21 additions & 0 deletions image/test/mochitest/test_animated_css_image.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,27 @@
return doc.querySelector("div");
},
},

// bug 1731138: Animated mask
{
html: `
<!doctype html>
<style>
div {
width: 100px;
height: 100px;
background-color: lime;
mask-clip: border-box;
mask-size: 100% 100%;
mask-image: url(animatedMask.gif);
}
</style>
<div></div>
`,
element(doc) {
return doc.querySelector("div");
},
},
];

onload = async function() {
Expand Down
4 changes: 4 additions & 0 deletions layout/style/ImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@ static void InvalidateImages(nsIFrame* aFrame, imgIRequest* aRequest,
// XXX: handle Blob data
invalidateFrame = true;
break;
case layers::WebRenderUserData::UserDataType::eMask:
static_cast<layers::WebRenderMaskData*>(data.get())->Invalidate();
invalidateFrame = true;
break;
case layers::WebRenderUserData::UserDataType::eImage:
if (static_cast<layers::WebRenderImageData*>(data.get())
->UsingSharedSurface(aRequest->GetProducerId())) {
Expand Down

0 comments on commit 79c6ddf

Please sign in to comment.