Bug 1343458 - Label runnables in dom/media/VideoFrameContainer.cpp. r?cpearce
MozReview-Commit-ID: D0QTbA4UwAZ
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -744,16 +744,18 @@ public:
// These are used for testing only
float ComputedVolume() const;
bool ComputedMuted() const;
nsSuspendedTypes ComputedSuspended() const;
void SetMediaInfo(const MediaInfo& aInfo);
+ virtual AbstractThread* AbstractMainThread() const final override;
+
// Telemetry: to record the usage of a {visible / invisible} video element as
// the source of {drawImage(), createPattern(), createImageBitmap() and
// captureStream()} APIs.
enum class CallerAPI {
DRAW_IMAGE,
CREATE_PATTERN,
CREATE_IMAGEBITMAP,
CAPTURE_STREAM,
@@ -1183,18 +1185,16 @@ protected:
// Get the HTMLMediaElement object if the decoder is being used from an
// HTML media element, and null otherwise.
virtual HTMLMediaElement* GetMediaElement() final override
{
return this;
}
- virtual AbstractThread* AbstractMainThread() const final override;
-
// Return true if decoding should be paused
virtual bool GetPaused() final override
{
bool isPaused = false;
GetPaused(&isPaused);
return isPaused;
}
--- a/dom/media/VideoFrameContainer.cpp
+++ b/dom/media/VideoFrameContainer.cpp
@@ -12,24 +12,28 @@
#include "nsSVGEffects.h"
using namespace mozilla::layers;
namespace mozilla {
static LazyLogModule gVideoFrameContainerLog("VideoFrameContainer");
#define CONTAINER_LOG(type, msg) MOZ_LOG(gVideoFrameContainerLog, type, msg)
+#define NS_DispatchToMainThread(...) CompileError_UseAbstractMainThreadInstead
+
VideoFrameContainer::VideoFrameContainer(dom::HTMLMediaElement* aElement,
already_AddRefed<ImageContainer> aContainer)
: mElement(aElement),
mImageContainer(aContainer), mMutex("nsVideoFrameContainer"),
mBlackImage(nullptr),
mFrameID(0),
mIntrinsicSizeChanged(false), mImageSizeChanged(false),
- mPendingPrincipalHandle(PRINCIPAL_HANDLE_NONE), mFrameIDForPendingPrincipalHandle(0)
+ mPendingPrincipalHandle(PRINCIPAL_HANDLE_NONE),
+ mFrameIDForPendingPrincipalHandle(0),
+ mMainThread(aElement->AbstractMainThread())
{
NS_ASSERTION(aElement, "aElement must not be null");
NS_ASSERTION(mImageContainer, "aContainer must not be null");
}
VideoFrameContainer::~VideoFrameContainer()
{}
@@ -73,17 +77,18 @@ SetImageToBlackPixel(PlanarYCbCrImage* a
data.mYStride = data.mCbCrStride = 1;
data.mPicSize = data.mYSize = data.mCbCrSize = gfx::IntSize(1, 1);
aImage->CopyData(data);
}
class VideoFrameContainerInvalidateRunnable : public Runnable {
public:
explicit VideoFrameContainerInvalidateRunnable(VideoFrameContainer* aVideoFrameContainer)
- : mVideoFrameContainer(aVideoFrameContainer)
+ : Runnable("VideoFrameContainerInvalidateRunnable")
+ , mVideoFrameContainer(aVideoFrameContainer)
{}
NS_IMETHOD Run()
{
MOZ_ASSERT(NS_IsMainThread());
mVideoFrameContainer->Invalidate();
return NS_OK;
@@ -166,17 +171,17 @@ void VideoFrameContainer::SetCurrentFram
if (principalHandleChanged) {
UpdatePrincipalHandleForFrameIDLocked(lastPrincipalHandle,
newImages.LastElement().mFrameID);
}
SetCurrentFramesLocked(mLastPlayedVideoFrame.GetIntrinsicSize(), images);
nsCOMPtr<nsIRunnable> event =
new VideoFrameContainerInvalidateRunnable(this);
- NS_DispatchToMainThread(event.forget());
+ mMainThread->Dispatch(event.forget());
images.ClearAndRetainStorage();
}
void VideoFrameContainer::ClearFrames()
{
ClearFutureFrames();
}
@@ -237,21 +242,26 @@ void VideoFrameContainer::SetCurrentFram
// set of images.
// This means that the old principal handle has been flushed out and we can
// notify our video element about this change.
RefPtr<VideoFrameContainer> self = this;
PrincipalHandle principalHandle = mPendingPrincipalHandle;
mLastPrincipalHandle = mPendingPrincipalHandle;
mPendingPrincipalHandle = PRINCIPAL_HANDLE_NONE;
mFrameIDForPendingPrincipalHandle = 0;
- NS_DispatchToMainThread(NS_NewRunnableFunction([self, principalHandle]() {
- if (self->mElement) {
- self->mElement->PrincipalHandleChangedForVideoFrameContainer(self, principalHandle);
- }
- }));
+ mMainThread->Dispatch(
+ NS_NewRunnableFunction(
+ "PrincipalHandleChangedForVideoFrameContainer",
+ [self, principalHandle]() {
+ if (self->mElement) {
+ self->mElement->PrincipalHandleChangedForVideoFrameContainer(self, principalHandle);
+ }
+ }
+ )
+ );
}
if (aImages.IsEmpty()) {
mImageContainer->ClearAllImages();
} else {
mImageContainer->SetCurrentImages(aImages);
}
gfx::IntSize newFrameSize = mImageContainer->GetCurrentSize();
@@ -352,8 +362,10 @@ void VideoFrameContainer::InvalidateWith
asyncInvalidate ? nsIFrame::UPDATE_IS_ASYNC : 0);
}
}
nsSVGEffects::InvalidateDirectRenderingObservers(mElement);
}
} // namespace mozilla
+
+#undef NS_DispatchToMainThread
--- a/dom/media/VideoFrameContainer.h
+++ b/dom/media/VideoFrameContainer.h
@@ -135,13 +135,15 @@ protected:
bool mImageSizeChanged;
// The last PrincipalHandle we notified mElement about.
PrincipalHandle mLastPrincipalHandle;
// The PrincipalHandle the client has notified us is changing with FrameID
// mFrameIDForPendingPrincipalHandle.
PrincipalHandle mPendingPrincipalHandle;
// The FrameID for which mPendingPrincipal is first valid.
ImageContainer::FrameID mFrameIDForPendingPrincipalHandle;
+
+ const RefPtr<AbstractThread> mMainThread;
};
} // namespace mozilla
#endif /* VIDEOFRAMECONTAINER_H_ */