Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_layers_CompositionRecorder_h
8
#define mozilla_layers_CompositionRecorder_h
9
10
#include "mozilla/RefPtr.h"
11
#include "mozilla/TimeStamp.h"
12
#include "nsISupportsImpl.h"
13
#include "nsTArray.h"
14
#include "nsString.h"
15
16
namespace mozilla {
17
18
namespace gfx {
19
class DataSourceSurface;
20
}
21
22
namespace layers {
23
24
/**
25
* A captured frame from a |LayerManager|.
26
*/
27
class RecordedFrame {
28
public:
29
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RecordedFrame)
30
31
// The resulting DataSourceSurface must not be kept alive beyond the lifetime
32
// of the RecordedFrame object, since it may refer to data owned by the frame.
33
virtual already_AddRefed<gfx::DataSourceSurface> GetSourceSurface() = 0;
34
TimeStamp GetTimeStamp() { return mTimeStamp; }
35
36
protected:
37
virtual ~RecordedFrame() = default;
38
RecordedFrame(const TimeStamp& aTimeStamp) : mTimeStamp(aTimeStamp) {}
39
40
private:
41
TimeStamp mTimeStamp;
42
};
43
44
/**
45
* A recorded frame that has been encoded into a data: URI.
46
*/
47
struct CollectedFrame {
48
CollectedFrame(double aTimeOffset, nsCString&& aDataUri)
49
: mTimeOffset(aTimeOffset), mDataUri(std::move(aDataUri)) {}
50
51
double mTimeOffset;
52
nsCString mDataUri;
53
};
54
55
/**
56
* All of the frames collected during a composition recording session.
57
*/
58
struct CollectedFrames {
59
CollectedFrames(double aRecordingStart, nsTArray<CollectedFrame>&& aFrames)
60
: mRecordingStart(aRecordingStart), mFrames(std::move(aFrames)) {}
61
62
double mRecordingStart;
63
nsTArray<CollectedFrame> mFrames;
64
};
65
66
/**
67
* A recorder for composited frames.
68
*
69
* This object collects frames sent to it by a |LayerManager| and writes them
70
* out as a series of images until recording has finished.
71
*
72
* If GPU-accelerated rendering is used, the frames will not be mapped into
73
* memory until |WriteCollectedFrames| is called.
74
*/
75
class CompositionRecorder {
76
public:
77
explicit CompositionRecorder(TimeStamp aRecordingStart);
78
79
/**
80
* Record a composited frame.
81
*/
82
void RecordFrame(RecordedFrame* aFrame);
83
84
/**
85
* Write out the collected frames as a series of timestamped images.
86
*/
87
void WriteCollectedFrames();
88
89
/**
90
* Return the collected frames as an array of their timestamps and contents.
91
*/
92
CollectedFrames GetCollectedFrames();
93
94
protected:
95
void ClearCollectedFrames();
96
97
private:
98
nsTArray<RefPtr<RecordedFrame>> mCollectedFrames;
99
TimeStamp mRecordingStart;
100
};
101
102
} // namespace layers
103
} // namespace mozilla
104
105
#endif // mozilla_layers_CompositionRecorder_h