| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ | |
| 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/cancelable_callback.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "base/time/time.h" | |
| 17 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" | |
| 18 #include "content/public/browser/readback_types.h" | |
| 19 | |
| 20 class SkBitmap; | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 class RenderViewHostImpl; | |
| 25 | |
| 26 namespace devtools { | |
| 27 namespace page { | |
| 28 | |
| 29 using EncodedFrame = std::pair<std::string, double>; | |
| 30 | |
| 31 class FrameRecorder { | |
| 32 public: | |
| 33 using Response = DevToolsProtocolClient::Response; | |
| 34 using StopRecordingFramesCallback = | |
| 35 base::Callback<void(scoped_refptr<StopRecordingFramesResponse>)>; | |
| 36 | |
| 37 explicit FrameRecorder(); | |
| 38 virtual ~FrameRecorder(); | |
| 39 | |
| 40 Response StartRecordingFrames(int max_frame_count); | |
| 41 Response StopRecordingFrames(StopRecordingFramesCallback callback); | |
| 42 Response CancelRecordingFrames(); | |
| 43 | |
| 44 void SetRenderViewHost(RenderViewHostImpl* host); | |
| 45 void OnSwapCompositorFrame(); | |
| 46 | |
| 47 private: | |
| 48 enum State { | |
| 49 Ready, | |
| 50 Recording, | |
| 51 Encoding | |
| 52 }; | |
| 53 | |
| 54 void FrameCaptured(const SkBitmap& bitmap, ReadbackResponse response); | |
| 55 void FrameEncoded(const scoped_ptr<EncodedFrame>& encoded_frame); | |
| 56 void MaybeSendResponse(); | |
| 57 | |
| 58 RenderViewHostImpl* host_; | |
| 59 State state_; | |
| 60 StopRecordingFramesCallback callback_; | |
| 61 size_t inflight_requests_count_; | |
| 62 size_t max_frame_count_; | |
| 63 size_t captured_frames_count_; | |
| 64 base::Time last_captured_frame_timestamp_; | |
| 65 std::vector<scoped_refptr<devtools::page::RecordedFrame>> frames_; | |
| 66 | |
| 67 base::CancelableCallback<void(const scoped_ptr<EncodedFrame>&)> | |
| 68 frame_encoded_callback_; | |
| 69 base::WeakPtrFactory<FrameRecorder> weak_factory_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(FrameRecorder); | |
| 72 }; | |
| 73 | |
| 74 } // namespace page | |
| 75 } // namespace devtools | |
| 76 } // namespace content | |
| 77 | |
| 78 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ | |
| OLD | NEW |