CompositionRecorder.h (2212B)
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 "mozilla/layers/PCompositorBridgeTypes.h" 13 #include "nsISupportsImpl.h" 14 #include "nsTArray.h" 15 #include "nsString.h" 16 17 namespace mozilla { 18 19 namespace gfx { 20 class DataSourceSurface; 21 } 22 23 namespace layers { 24 25 /** 26 * A captured frame from a |LayerManager|. 27 */ 28 class RecordedFrame { 29 public: 30 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RecordedFrame) 31 32 // The resulting DataSourceSurface must not be kept alive beyond the lifetime 33 // of the RecordedFrame object, since it may refer to data owned by the frame. 34 virtual already_AddRefed<gfx::DataSourceSurface> GetSourceSurface() = 0; 35 TimeStamp GetTimeStamp() { return mTimeStamp; } 36 37 protected: 38 virtual ~RecordedFrame() = default; 39 RecordedFrame(const TimeStamp& aTimeStamp) : mTimeStamp(aTimeStamp) {} 40 41 private: 42 TimeStamp mTimeStamp; 43 }; 44 45 /** 46 * A recorder for composited frames. 47 * 48 * This object collects frames sent to it by a |LayerManager| and writes them 49 * out as a series of images until recording has finished. 50 * 51 * If GPU-accelerated rendering is used, the frames will not be mapped into 52 * memory until |WriteCollectedFrames| is called. 53 */ 54 class CompositionRecorder { 55 public: 56 explicit CompositionRecorder(TimeStamp aRecordingStart); 57 58 /** 59 * Record a composited frame. 60 */ 61 void RecordFrame(RecordedFrame* aFrame); 62 63 /** 64 * Get the array of frames that were recorded since the last call to 65 * GetRecording(), where each frame consists of a presentation time and 66 * the PNG-encoded contents as an array of bytes 67 */ 68 Maybe<FrameRecording> GetRecording(); 69 70 private: 71 nsTArray<RefPtr<RecordedFrame>> mRecordedFrames; 72 TimeStamp mRecordingStart; 73 }; 74 75 } // namespace layers 76 } // namespace mozilla 77 78 #endif // mozilla_layers_CompositionRecorder_h