OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 REMOTING_CLIENT_DUAL_BUFFER_FRAME_CONSUMER_H_ |
| 6 #define REMOTING_CLIENT_DUAL_BUFFER_FRAME_CONSUMER_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_checker.h" |
| 14 #include "remoting/protocol/frame_consumer.h" |
| 15 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
| 16 |
| 17 namespace webrtc { |
| 18 class SharedDesktopFrame; |
| 19 } // namespace webrtc |
| 20 |
| 21 namespace remoting { |
| 22 |
| 23 // This class continuously uses two BasicDesktopFrame as buffer for decoding |
| 24 // updated regions until the resolution is changed. |
| 25 // This class should be used and destroyed on the same thread. If |task_runner| |
| 26 // is null |callback| will be run directly upon the stack of DrawFrame, |
| 27 // otherwise a task will be posted to feed the callback on the thread of |
| 28 // |task_runner|. |
| 29 // Only areas bound by updated_region() on the buffer are considered valid to |
| 30 // |callback|. Please use RequestFullDesktopFrame() if you want to get a full |
| 31 // desktop frame. |
| 32 class DualBufferFrameConsumer : public protocol::FrameConsumer { |
| 33 public: |
| 34 // RenderCallback(decoded_frame, done) |
| 35 // |done| should be run after it is rendered. Can be called on any thread. |
| 36 using RenderCallback = |
| 37 base::Callback<void(std::unique_ptr<webrtc::DesktopFrame>, |
| 38 const base::Closure&)>; |
| 39 DualBufferFrameConsumer( |
| 40 const RenderCallback& callback, |
| 41 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 42 PixelFormat format); |
| 43 ~DualBufferFrameConsumer() override; |
| 44 |
| 45 // Feeds the callback on the right thread with a BasicDesktopFrame that merges |
| 46 // updates from buffer_[0] and buffer_[1]. Do nothing if no updates have |
| 47 // received yet. |
| 48 void RequestFullDesktopFrame(); |
| 49 |
| 50 // FrameConsumer interface. |
| 51 std::unique_ptr<webrtc::DesktopFrame> AllocateFrame( |
| 52 const webrtc::DesktopSize& size) override; |
| 53 void DrawFrame(std::unique_ptr<webrtc::DesktopFrame> frame, |
| 54 const base::Closure& done) override; |
| 55 PixelFormat GetPixelFormat() override; |
| 56 |
| 57 base::WeakPtr<DualBufferFrameConsumer> GetWeakPtr(); |
| 58 |
| 59 private: |
| 60 void RunRenderCallback(std::unique_ptr<webrtc::DesktopFrame> frame, |
| 61 const base::Closure& done); |
| 62 |
| 63 std::unique_ptr<webrtc::SharedDesktopFrame> buffers_[2]; |
| 64 |
| 65 // Represents dirty regions that are currently in buffers_[1]. Will be used |
| 66 // when calling RequestFullDesktopFrame() to construct the full desktop frame. |
| 67 webrtc::DesktopRegion buffer_1_mask_; |
| 68 |
| 69 int current_buffer_ = 0; |
| 70 |
| 71 RenderCallback callback_; |
| 72 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 73 PixelFormat pixel_format_; |
| 74 base::ThreadChecker thread_checker_; |
| 75 base::WeakPtr<DualBufferFrameConsumer> weak_ptr_; |
| 76 base::WeakPtrFactory<DualBufferFrameConsumer> weak_factory_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(DualBufferFrameConsumer); |
| 79 }; |
| 80 |
| 81 } // namespace remoting |
| 82 #endif // REMOTING_CLIENT_DUAL_BUFFER_FRAME_CONSUMER_H_ |
OLD | NEW |