From cfb037a230cdb201d1ebc8795a1a4013586d9c83 Mon Sep 17 00:00:00 2001 From: Barret Rennie Date: Wed, 6 Nov 2019 20:48:45 +0000 Subject: [PATCH] Bug 1581240 - Return collected frames from the composition recorder as data URIs r=mstange The composition recorder can now either write frames to disk as PNGs or return the frames as an array of data URIs. This will allow us to send the collected frames across IPC and hand them over to JS in a later patch. Differential Revision: https://phabricator.services.mozilla.com/D47815 --HG-- extra : moz-landing-system : lando --- gfx/layers/CompositionRecorder.cpp | 26 ++++++++++++++++++++++++++ gfx/layers/CompositionRecorder.h | 27 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/gfx/layers/CompositionRecorder.cpp b/gfx/layers/CompositionRecorder.cpp index a05adfb55a8f..8d9cd9209cf4 100644 --- a/gfx/layers/CompositionRecorder.cpp +++ b/gfx/layers/CompositionRecorder.cpp @@ -8,6 +8,9 @@ #include "gfxUtils.h" #include "mozilla/gfx/2D.h" #include "mozilla/gfx/gfxVars.h" +#include "nsIInputStream.h" +#include "nsIBinaryOutputStream.h" +#include "nsIObjectOutputStream.h" #include #include @@ -74,6 +77,29 @@ void CompositionRecorder::WriteCollectedFrames() { mCollectedFrames.Clear(); } +CollectedFrames CompositionRecorder::GetCollectedFrames() { + nsTArray frames; + + TimeDuration delta = TimeStamp::NowUnfuzzed() - mRecordingStart; + double recordingStart = PR_Now() / 1000.0 - delta.ToMilliseconds(); + + for (RefPtr& frame : mCollectedFrames) { + nsCString buffer; + + RefPtr surf = frame->GetSourceSurface(); + double offset = (frame->GetTimeStamp() - mRecordingStart).ToMilliseconds(); + + gfxUtils::EncodeSourceSurface(surf, ImageType::PNG, EmptyString(), + gfxUtils::eDataURIEncode, nullptr, &buffer); + + frames.EmplaceBack(offset, std::move(buffer)); + } + + mCollectedFrames.Clear(); + + return CollectedFrames(recordingStart, std::move(frames)); +} + void CompositionRecorder::ClearCollectedFrames() { mCollectedFrames.Clear(); } } // namespace layers diff --git a/gfx/layers/CompositionRecorder.h b/gfx/layers/CompositionRecorder.h index b8c9452a4c1d..3d2f9216be79 100644 --- a/gfx/layers/CompositionRecorder.h +++ b/gfx/layers/CompositionRecorder.h @@ -40,6 +40,28 @@ class RecordedFrame { TimeStamp mTimeStamp; }; +/** + * A recorded frame that has been encoded into a data: URI. + */ +struct CollectedFrame { + CollectedFrame(double aTimeOffset, nsCString&& aDataUri) + : mTimeOffset(aTimeOffset), mDataUri(std::move(aDataUri)) {} + + double mTimeOffset; + nsCString mDataUri; +}; + +/** + * All of the frames collected during a composition recording session. + */ +struct CollectedFrames { + CollectedFrames(double aRecordingStart, nsTArray&& aFrames) + : mRecordingStart(aRecordingStart), mFrames(std::move(aFrames)) {} + + double mRecordingStart; + nsTArray mFrames; +}; + /** * A recorder for composited frames. * @@ -63,6 +85,11 @@ class CompositionRecorder { */ void WriteCollectedFrames(); + /** + * Return the collected frames as an array of their timestamps and contents. + */ + CollectedFrames GetCollectedFrames(); + protected: void ClearCollectedFrames();