Bug 1428558 - Part 8. Integrate SharedSurfacesAnimation with the rest of imagelib. r=nical

This patch makes ImageContainer create a SharedSurfacesAnimation object
when it detects that we are using shared surfaces and are producing full
frames.

Differential Revision: https://phabricator.services.mozilla.com/D7505
This commit is contained in:
Andrew Osmond
2018-10-02 13:28:33 -04:00
parent babeb8d7ce
commit 21ef73e1f1
4 changed files with 32 additions and 9 deletions

View File

@@ -4,12 +4,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Image.h" #include "Image.h"
#include "gfxPrefs.h"
#include "Layers.h" // for LayerManager #include "Layers.h" // for LayerManager
#include "nsRefreshDriver.h" #include "nsRefreshDriver.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "mozilla/SizeOfState.h" #include "mozilla/SizeOfState.h"
#include "mozilla/TimeStamp.h" #include "mozilla/TimeStamp.h"
#include "mozilla/Tuple.h" // for Tie #include "mozilla/Tuple.h" // for Tie
#include "mozilla/layers/SharedSurfacesChild.h"
namespace mozilla { namespace mozilla {
namespace image { namespace image {
@@ -71,7 +73,7 @@ ImageResource::GetSpecTruncatedTo1k(nsCString& aSpec) const
void void
ImageResource::SetCurrentImage(ImageContainer* aContainer, ImageResource::SetCurrentImage(ImageContainer* aContainer,
SourceSurface* aSurface, SourceSurface* aSurface,
bool aInTransaction) const Maybe<IntRect>& aDirtyRect)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aContainer); MOZ_ASSERT(aContainer);
@@ -97,11 +99,26 @@ ImageResource::SetCurrentImage(ImageContainer* aContainer,
mLastFrameID++, mLastFrameID++,
mImageProducerID)); mImageProducerID));
if (aInTransaction) { if (aDirtyRect) {
aContainer->SetCurrentImagesInTransaction(imageList); aContainer->SetCurrentImagesInTransaction(imageList);
} else { } else {
aContainer->SetCurrentImages(imageList); aContainer->SetCurrentImages(imageList);
} }
// If we are generating full frames, and we are animated, then we should
// request that the image container be treated as such, to avoid display
// list rebuilding to update frames for WebRender.
if (gfxPrefs::ImageAnimatedGenerateFullFrames() &&
mProgressTracker->GetProgress() & FLAG_IS_ANIMATED) {
if (aDirtyRect) {
layers::SharedSurfacesChild::UpdateAnimation(aContainer, aSurface,
aDirtyRect.ref());
} else {
IntRect dirtyRect(IntPoint(0, 0), aSurface->GetSize());
layers::SharedSurfacesChild::UpdateAnimation(aContainer, aSurface,
dirtyRect);
}
}
} }
ImgDrawResult ImgDrawResult
@@ -253,14 +270,14 @@ ImageResource::GetImageContainerImpl(LayerManager* aManager,
} }
} }
SetCurrentImage(container, surface, true); SetCurrentImage(container, surface, Nothing());
entry->mLastDrawResult = drawResult; entry->mLastDrawResult = drawResult;
container.forget(aOutContainer); container.forget(aOutContainer);
return drawResult; return drawResult;
} }
void void
ImageResource::UpdateImageContainer() ImageResource::UpdateImageContainer(const Maybe<IntRect>& aDirtyRect)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@@ -278,7 +295,12 @@ ImageResource::UpdateImageContainer()
// managed to convert the weak reference into a strong reference, that // managed to convert the weak reference into a strong reference, that
// means that an imagelib user still is holding onto the container. thus // means that an imagelib user still is holding onto the container. thus
// we cannot consolidate and must keep updating the duplicate container. // we cannot consolidate and must keep updating the duplicate container.
SetCurrentImage(container, surface, false); if (aDirtyRect) {
SetCurrentImage(container, surface, aDirtyRect);
} else {
IntRect dirtyRect(IntPoint(0, 0), bestSize);
SetCurrentImage(container, surface, Some(dirtyRect));
}
} else { } else {
// Stop tracking if our weak pointer to the image container was freed. // Stop tracking if our weak pointer to the image container was freed.
mImageContainers.RemoveElementAt(i); mImageContainers.RemoveElementAt(i);

View File

@@ -6,6 +6,7 @@
#ifndef mozilla_image_Image_h #ifndef mozilla_image_Image_h
#define mozilla_image_Image_h #define mozilla_image_Image_h
#include "mozilla/Maybe.h"
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/Tuple.h" #include "mozilla/Tuple.h"
#include "mozilla/TimeStamp.h" #include "mozilla/TimeStamp.h"
@@ -393,14 +394,14 @@ protected:
uint32_t aFlags, uint32_t aFlags,
layers::ImageContainer** aContainer); layers::ImageContainer** aContainer);
void UpdateImageContainer(); void UpdateImageContainer(const Maybe<gfx::IntRect>& aDirtyRect);
void ReleaseImageContainer(); void ReleaseImageContainer();
private: private:
void SetCurrentImage(layers::ImageContainer* aContainer, void SetCurrentImage(layers::ImageContainer* aContainer,
gfx::SourceSurface* aSurface, gfx::SourceSurface* aSurface,
bool aInTransaction); const Maybe<gfx::IntRect>& aDirtyRect);
struct ImageContainerEntry { struct ImageContainerEntry {
ImageContainerEntry(const gfx::IntSize& aSize, ImageContainerEntry(const gfx::IntSize& aSize,

View File

@@ -1714,7 +1714,7 @@ RasterImage::NotifyProgress(Progress aProgress,
if (!aInvalidRect.IsEmpty() && wasDefaultFlags) { if (!aInvalidRect.IsEmpty() && wasDefaultFlags) {
// Update our image container since we're invalidating. // Update our image container since we're invalidating.
UpdateImageContainer(); UpdateImageContainer(Some(aInvalidRect));
} }
if (!(aDecoderFlags & DecoderFlags::FIRST_FRAME_ONLY)) { if (!(aDecoderFlags & DecoderFlags::FIRST_FRAME_ONLY)) {

View File

@@ -622,7 +622,7 @@ VectorImage::SendInvalidationNotifications()
GetMaxSizedIntRect()); GetMaxSizedIntRect());
} }
UpdateImageContainer(); UpdateImageContainer(Nothing());
} }
NS_IMETHODIMP_(IntRect) NS_IMETHODIMP_(IntRect)