Chromium Code Reviews| Index: remoting/client/dual_buffer_frame_consumer.h |
| diff --git a/remoting/client/dual_buffer_frame_consumer.h b/remoting/client/dual_buffer_frame_consumer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b87e0c1fc74038b52c394ffa31ecd0fbc96a6c2c |
| --- /dev/null |
| +++ b/remoting/client/dual_buffer_frame_consumer.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef REMOTING_CLIENT_DUAL_BUFFER_FRAME_CONSUMER_H_ |
| +#define REMOTING_CLIENT_DUAL_BUFFER_FRAME_CONSUMER_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/single_thread_task_runner.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "remoting/protocol/frame_consumer.h" |
| +#include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
| + |
| +namespace webrtc { |
| +class SharedDesktopFrame; |
| +} // namespace webrtc |
| + |
| +namespace remoting { |
| + |
| +// This class continuously uses two BasicDesktopFrame as buffer for decoding |
| +// updated regions until the resolution is changed. |
| +// This class should be used and destroyed on the same thread. If |task_runner| |
| +// is null |callback| will be run directly upon the stack of DrawFrame, |
| +// otherwise a task will be posted to feed the callback on the thread of |
| +// |task_runner|. |
| +// Only areas bound by updated_region() on the buffer are considered valid to |
| +// |callback|. Please use RequestFullDesktopFrame() if you want to get a full |
| +// desktop frame. |
| +class DualBufferFrameConsumer : public protocol::FrameConsumer { |
| + public: |
| + DualBufferFrameConsumer( |
| + base::Callback<void(std::unique_ptr<webrtc::DesktopFrame>)> callback, |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| + PixelFormat format); |
| + ~DualBufferFrameConsumer() override; |
| + |
| + // Feeds the callback on the right thread with a BasicDesktopFrame that merges |
| + // updates from buffer_[0] and buffer_[1]. Do nothing if no updates have |
| + // received yet. |
| + void RequestFullDesktopFrame(); |
| + |
| + // FrameConsumer interface. |
| + std::unique_ptr<webrtc::DesktopFrame> AllocateFrame( |
| + const webrtc::DesktopSize& size) override; |
| + void DrawFrame(std::unique_ptr<webrtc::DesktopFrame> frame, |
| + const base::Closure& done) override; |
| + PixelFormat GetPixelFormat() override; |
| + |
| + base::WeakPtr<DualBufferFrameConsumer> GetWeakPtr(); |
| + |
| + private: |
| + void RunRenderCallback(std::unique_ptr<webrtc::DesktopFrame> frame, |
| + const base::Closure& done); |
| + void OnFrameRendered(const base::Closure& done); |
| + |
| + std::unique_ptr<webrtc::SharedDesktopFrame> buffers_[2]; |
| + webrtc::DesktopRegion buffer_1_mask_; |
|
Yuwei
2016/07/21 19:00:32
I'll add some comment here.
Yuwei
2016/07/22 03:38:22
Done.
|
| + int current_buffer_ = 0; |
| + |
| + base::Callback<void(std::unique_ptr<webrtc::DesktopFrame>)> callback_; |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| + PixelFormat pixel_format_; |
| + base::ThreadChecker thread_checker_; |
| + base::WeakPtr<DualBufferFrameConsumer> weak_ptr_; |
| + base::WeakPtrFactory<DualBufferFrameConsumer> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DualBufferFrameConsumer); |
| +}; |
| + |
| +} // namespace remoting |
| +#endif // REMOTING_CLIENT_DUAL_BUFFER_FRAME_CONSUMER_H_ |