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
This commit is contained in:
Barret Rennie 2019-11-06 20:48:45 +00:00
Родитель 8323f194e5
Коммит cfb037a230
2 изменённых файлов: 53 добавлений и 0 удалений

Просмотреть файл

@ -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 <ctime>
#include <iomanip>
@ -74,6 +77,29 @@ void CompositionRecorder::WriteCollectedFrames() {
mCollectedFrames.Clear();
}
CollectedFrames CompositionRecorder::GetCollectedFrames() {
nsTArray<CollectedFrame> frames;
TimeDuration delta = TimeStamp::NowUnfuzzed() - mRecordingStart;
double recordingStart = PR_Now() / 1000.0 - delta.ToMilliseconds();
for (RefPtr<RecordedFrame>& frame : mCollectedFrames) {
nsCString buffer;
RefPtr<DataSourceSurface> 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

Просмотреть файл

@ -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<CollectedFrame>&& aFrames)
: mRecordingStart(aRecordingStart), mFrames(std::move(aFrames)) {}
double mRecordingStart;
nsTArray<CollectedFrame> 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();