2019-03-12 18:06:48 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_layers_CompositionRecorder_h
|
|
|
|
#define mozilla_layers_CompositionRecorder_h
|
|
|
|
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsTArray.h"
|
2019-11-08 01:34:37 +03:00
|
|
|
#include "nsString.h"
|
2019-03-12 18:06:48 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace gfx {
|
|
|
|
class DataSourceSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace layers {
|
|
|
|
|
2019-05-31 03:30:24 +03:00
|
|
|
/**
|
|
|
|
* A captured frame from a |LayerManager|.
|
|
|
|
*/
|
2019-03-12 18:06:48 +03:00
|
|
|
class RecordedFrame {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RecordedFrame)
|
|
|
|
|
|
|
|
// The resulting DataSourceSurface must not be kept alive beyond the lifetime
|
|
|
|
// of the RecordedFrame object, since it may refer to data owned by the frame.
|
|
|
|
virtual already_AddRefed<gfx::DataSourceSurface> GetSourceSurface() = 0;
|
|
|
|
TimeStamp GetTimeStamp() { return mTimeStamp; }
|
|
|
|
|
|
|
|
protected:
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~RecordedFrame() = default;
|
2019-03-12 18:06:48 +03:00
|
|
|
RecordedFrame(const TimeStamp& aTimeStamp) : mTimeStamp(aTimeStamp) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TimeStamp mTimeStamp;
|
|
|
|
};
|
|
|
|
|
2019-11-08 01:34:37 +03:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
};
|
|
|
|
|
2019-03-12 18:06:48 +03:00
|
|
|
/**
|
2019-05-31 03:30:24 +03:00
|
|
|
* A recorder for composited frames.
|
2019-03-12 18:06:48 +03:00
|
|
|
*
|
2019-05-31 03:30:24 +03:00
|
|
|
* This object collects frames sent to it by a |LayerManager| and writes them
|
|
|
|
* out as a series of images until recording has finished.
|
|
|
|
*
|
|
|
|
* If GPU-accelerated rendering is used, the frames will not be mapped into
|
|
|
|
* memory until |WriteCollectedFrames| is called.
|
2019-03-12 18:06:48 +03:00
|
|
|
*/
|
2019-05-31 03:31:24 +03:00
|
|
|
class CompositionRecorder {
|
2019-03-12 18:06:48 +03:00
|
|
|
public:
|
|
|
|
explicit CompositionRecorder(TimeStamp aRecordingStart);
|
|
|
|
|
2019-05-31 03:30:24 +03:00
|
|
|
/**
|
|
|
|
* Record a composited frame.
|
|
|
|
*/
|
2019-07-31 21:28:47 +03:00
|
|
|
void RecordFrame(RecordedFrame* aFrame);
|
2019-05-30 23:17:39 +03:00
|
|
|
|
2019-05-31 03:30:24 +03:00
|
|
|
/**
|
|
|
|
* Write out the collected frames as a series of timestamped images.
|
|
|
|
*/
|
2019-07-31 21:28:47 +03:00
|
|
|
void WriteCollectedFrames();
|
2019-05-30 23:19:56 +03:00
|
|
|
|
2019-11-08 01:34:37 +03:00
|
|
|
/**
|
|
|
|
* Return the collected frames as an array of their timestamps and contents.
|
|
|
|
*/
|
|
|
|
CollectedFrames GetCollectedFrames();
|
|
|
|
|
2019-05-31 03:30:24 +03:00
|
|
|
protected:
|
2019-05-31 03:31:52 +03:00
|
|
|
void ClearCollectedFrames();
|
|
|
|
|
2019-03-12 18:06:48 +03:00
|
|
|
private:
|
|
|
|
nsTArray<RefPtr<RecordedFrame>> mCollectedFrames;
|
|
|
|
TimeStamp mRecordingStart;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-05-31 03:30:24 +03:00
|
|
|
#endif // mozilla_layers_CompositionRecorder_h
|