OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_2D_H_ | 5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_2D_H_ |
6 #define REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_2D_H_ | 6 #define REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_2D_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_vector.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/thread_checker.h" |
14 #include "ppapi/cpp/graphics_2d.h" | 15 #include "ppapi/cpp/graphics_2d.h" |
| 16 #include "ppapi/cpp/image_data.h" |
15 #include "ppapi/cpp/point.h" | 17 #include "ppapi/cpp/point.h" |
16 #include "ppapi/cpp/view.h" | 18 #include "ppapi/cpp/view.h" |
17 #include "ppapi/utility/completion_callback_factory.h" | 19 #include "ppapi/utility/completion_callback_factory.h" |
18 #include "remoting/client/frame_consumer.h" | 20 #include "remoting/client/frame_consumer.h" |
19 #include "remoting/client/plugin/pepper_video_renderer.h" | 21 #include "remoting/client/plugin/pepper_video_renderer.h" |
20 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 22 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
21 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" | 23 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
22 | 24 |
23 namespace base { | 25 namespace base { |
24 class Time; | 26 class ScopedClosureRunner; |
25 } // namespace base | 27 } // namespace base |
26 | 28 |
27 namespace webrtc { | 29 namespace webrtc { |
28 class DesktopFrame; | 30 class DesktopFrame; |
| 31 class SharedDesktopFrame; |
29 } // namespace webrtc | 32 } // namespace webrtc |
30 | 33 |
31 namespace remoting { | 34 namespace remoting { |
32 | 35 |
33 class SoftwareVideoRenderer; | 36 class SoftwareVideoRenderer; |
34 | 37 |
35 // Video renderer that wraps SoftwareVideoRenderer and displays it using Pepper | 38 // Video renderer that wraps SoftwareVideoRenderer and displays it using Pepper |
36 // 2D graphics API. | 39 // 2D graphics API. |
37 class PepperVideoRenderer2D : public PepperVideoRenderer, | 40 class PepperVideoRenderer2D : public PepperVideoRenderer, |
38 public FrameConsumer, | 41 public FrameConsumer { |
39 public base::NonThreadSafe { | |
40 public: | 42 public: |
41 PepperVideoRenderer2D(); | 43 PepperVideoRenderer2D(); |
42 ~PepperVideoRenderer2D() override; | 44 ~PepperVideoRenderer2D() override; |
43 | 45 |
44 // PepperVideoRenderer interface. | 46 // PepperVideoRenderer interface. |
45 bool Initialize(pp::Instance* instance, | 47 bool Initialize(pp::Instance* instance, |
46 const ClientContext& context, | 48 const ClientContext& context, |
47 EventHandler* event_handler) override; | 49 EventHandler* event_handler) override; |
48 void OnViewChanged(const pp::View& view) override; | 50 void OnViewChanged(const pp::View& view) override; |
49 void EnableDebugDirtyRegion(bool enable) override; | 51 void EnableDebugDirtyRegion(bool enable) override; |
50 | 52 |
51 // VideoRenderer interface. | 53 // VideoRenderer interface. |
52 void OnSessionConfig(const protocol::SessionConfig& config) override; | 54 void OnSessionConfig(const protocol::SessionConfig& config) override; |
53 ChromotingStats* GetStats() override; | 55 ChromotingStats* GetStats() override; |
54 protocol::VideoStub* GetVideoStub() override; | 56 protocol::VideoStub* GetVideoStub() override; |
55 | 57 |
56 private: | 58 private: |
57 // FrameConsumer implementation. | 59 // FrameConsumer implementation. |
58 void ApplyBuffer(const webrtc::DesktopSize& view_size, | 60 scoped_ptr<webrtc::DesktopFrame> AllocateFrame( |
59 const webrtc::DesktopRect& clip_area, | 61 const webrtc::DesktopSize& size) override; |
60 webrtc::DesktopFrame* buffer, | 62 void DrawFrame(scoped_ptr<webrtc::DesktopFrame> frame, |
61 const webrtc::DesktopRegion& region, | 63 const base::Closure& done) override; |
62 const webrtc::DesktopRegion* shape) override; | |
63 void ReturnBuffer(webrtc::DesktopFrame* buffer) override; | |
64 void SetSourceSize(const webrtc::DesktopSize& source_size, | |
65 const webrtc::DesktopVector& dpi) override; | |
66 PixelFormat GetPixelFormat() override; | 64 PixelFormat GetPixelFormat() override; |
67 | 65 |
68 // Helper to allocate buffers for the decoder. | |
69 void AllocateBuffers(); | |
70 | 66 |
71 // Frees a frame buffer previously allocated by AllocateBuffer. | 67 void Flush(); |
72 void FreeBuffer(webrtc::DesktopFrame* buffer); | 68 void OnFlushDone(int result); |
73 | |
74 // Renders the parts of |buffer| identified by |region| to the view. If the | |
75 // clip area of the view has changed since the buffer was generated then | |
76 // FrameProducer is supplied the missed parts of |region|. The FrameProducer | |
77 // will be supplied a new buffer when FlushBuffer() completes. | |
78 void FlushBuffer(const webrtc::DesktopRect& clip_area, | |
79 webrtc::DesktopFrame* buffer, | |
80 const webrtc::DesktopRegion& region); | |
81 | |
82 // Handles completion of FlushBuffer(), triggering a new buffer to be | |
83 // returned to FrameProducer for rendering. | |
84 void OnFlushDone(int result, | |
85 const base::Time& paint_start, | |
86 webrtc::DesktopFrame* buffer); | |
87 | 69 |
88 // Parameters passed to Initialize(). | 70 // Parameters passed to Initialize(). |
89 pp::Instance* instance_; | 71 pp::Instance* instance_ = nullptr; |
90 EventHandler* event_handler_; | 72 EventHandler* event_handler_ = nullptr; |
91 | 73 |
92 pp::Graphics2D graphics2d_; | 74 pp::Graphics2D graphics2d_; |
93 | 75 |
94 scoped_ptr<SoftwareVideoRenderer> software_video_renderer_; | 76 scoped_ptr<SoftwareVideoRenderer> software_video_renderer_; |
95 | 77 |
96 // List of allocated image buffers. | 78 // View size in output pixels. |
97 std::list<webrtc::DesktopFrame*> buffers_; | |
98 | |
99 // Queued buffer to paint, with clip area and dirty region in device pixels. | |
100 webrtc::DesktopFrame* merge_buffer_; | |
101 webrtc::DesktopRect merge_clip_area_; | |
102 webrtc::DesktopRegion merge_region_; | |
103 | |
104 // View size in Density Independent Pixels (DIPs). | |
105 webrtc::DesktopSize dips_size_; | |
106 | |
107 // Scale factor from DIPs to device pixels. | |
108 float dips_to_device_scale_; | |
109 | |
110 // View size in output pixels. This is the size at which FrameProducer must | |
111 // render frames. It usually matches the DIPs size of the view, but may match | |
112 // the size in device pixels when scaling is in effect, to reduce artefacts. | |
113 webrtc::DesktopSize view_size_; | 79 webrtc::DesktopSize view_size_; |
114 | 80 |
115 // Scale factor from output pixels to device pixels. | |
116 float dips_to_view_scale_; | |
117 | |
118 // Visible area of the view, in output pixels. | |
119 webrtc::DesktopRect clip_area_; | |
120 | |
121 // Size of the most recent source frame in pixels. | 81 // Size of the most recent source frame in pixels. |
122 webrtc::DesktopSize source_size_; | 82 webrtc::DesktopSize source_size_; |
123 | 83 |
124 // Resolution of the most recent source frame dots-per-inch. | 84 // Resolution of the most recent source frame dots-per-inch. |
125 webrtc::DesktopVector source_dpi_; | 85 webrtc::DesktopVector source_dpi_; |
126 | 86 |
127 // Shape of the most recent source frame. | 87 // Shape of the most recent source frame. |
128 scoped_ptr<webrtc::DesktopRegion> source_shape_; | 88 scoped_ptr<webrtc::DesktopRegion> source_shape_; |
129 | 89 |
| 90 // Done callbacks for the frames that have been painted but not flushed. |
| 91 ScopedVector<base::ScopedClosureRunner> pending_frames_done_callbacks_; |
| 92 |
| 93 // Done callbacks for the frames that are currently being flushed. |
| 94 ScopedVector<base::ScopedClosureRunner> flushing_frames_done_callbacks_; |
| 95 |
| 96 // True if there paint operations that need to be flushed. |
| 97 bool need_flush_ = false; |
| 98 |
130 // True if there is already a Flush() pending on the Graphics2D context. | 99 // True if there is already a Flush() pending on the Graphics2D context. |
131 bool flush_pending_; | 100 bool flush_pending_ = false; |
132 | 101 |
133 // True after the first call to ApplyBuffer(). | 102 // True after the first call to DrawFrame(). |
134 bool frame_received_; | 103 bool frame_received_ = false; |
135 | 104 |
136 // True if dirty regions are to be sent to |event_handler_| for debugging. | 105 // True if dirty regions are to be sent to |event_handler_| for debugging. |
137 bool debug_dirty_region_; | 106 bool debug_dirty_region_ = false; |
| 107 |
| 108 base::ThreadChecker thread_checker_; |
138 | 109 |
139 pp::CompletionCallbackFactory<PepperVideoRenderer2D> callback_factory_; | 110 pp::CompletionCallbackFactory<PepperVideoRenderer2D> callback_factory_; |
140 base::WeakPtrFactory<PepperVideoRenderer2D> weak_factory_; | 111 base::WeakPtrFactory<PepperVideoRenderer2D> weak_factory_; |
141 | 112 |
142 DISALLOW_COPY_AND_ASSIGN(PepperVideoRenderer2D); | 113 DISALLOW_COPY_AND_ASSIGN(PepperVideoRenderer2D); |
143 }; | 114 }; |
144 | 115 |
145 } // namespace remoting | 116 } // namespace remoting |
146 | 117 |
147 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_2D_H_ | 118 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_2D_H_ |
OLD | NEW |