Bug 1343341. Only call AnimationState::SetDiscarded on the main thread. r=aosmond

Image::OnSurfaceDiscarded can be called on any thread. But AnimationState is a main thread only object.
This commit is contained in:
Timothy Nikkel 2017-03-25 02:16:21 -05:00
parent edb96ff7d7
commit 63ad0ad7f3
2 changed files with 30 additions and 3 deletions

View File

@ -445,13 +445,38 @@ RasterImage::OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey)
{
MOZ_ASSERT(mProgressTracker);
if (mAnimationState && aSurfaceKey.Playback() == PlaybackType::eAnimated) {
bool animatedFramesDiscarded =
mAnimationState && aSurfaceKey.Playback() == PlaybackType::eAnimated;
if (animatedFramesDiscarded && NS_IsMainThread()) {
MOZ_ASSERT(gfxPrefs::ImageMemAnimatedDiscardable());
mAnimationState->SetDiscarded(true);
// We don't need OnSurfaceDiscardedInternal to handle the animated frames
// being discarded because we just did.
animatedFramesDiscarded = false;
}
RefPtr<RasterImage> image = this;
NS_DispatchToMainThread(NS_NewRunnableFunction(
"RasterImage::OnSurfaceDiscarded",
[=]() -> void {
image->OnSurfaceDiscardedInternal(animatedFramesDiscarded);
}));
}
void
RasterImage::OnSurfaceDiscardedInternal(bool aAnimatedFramesDiscarded)
{
MOZ_ASSERT(NS_IsMainThread());
if (aAnimatedFramesDiscarded && mAnimationState) {
MOZ_ASSERT(gfxPrefs::ImageMemAnimatedDiscardable());
mAnimationState->SetDiscarded(true);
}
NS_DispatchToMainThread(NewRunnableMethod("ProgressTracker::OnDiscard",
mProgressTracker, &ProgressTracker::OnDiscard));
if (mProgressTracker) {
mProgressTracker->OnDiscard();
}
}
//******************************************************************************

View File

@ -379,6 +379,8 @@ private:
*/
void RecoverFromInvalidFrames(const nsIntSize& aSize, uint32_t aFlags);
void OnSurfaceDiscardedInternal(bool aAnimatedFramesDiscarded);
private: // data
nsIntSize mSize;
nsTArray<nsIntSize> mNativeSizes;