Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / remoting / client / plugin / pepper_video_renderer_2d.h
blob1e592790a85f92ba0e836f5a2b2b3efea8c562d9
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.
5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_2D_H_
6 #define REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_2D_H_
8 #include <list>
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "ppapi/cpp/graphics_2d.h"
16 #include "ppapi/cpp/image_data.h"
17 #include "ppapi/cpp/point.h"
18 #include "ppapi/cpp/view.h"
19 #include "ppapi/utility/completion_callback_factory.h"
20 #include "remoting/client/frame_consumer.h"
21 #include "remoting/client/plugin/pepper_video_renderer.h"
22 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
23 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
25 namespace base {
26 class ScopedClosureRunner;
27 } // namespace base
29 namespace webrtc {
30 class DesktopFrame;
31 class SharedDesktopFrame;
32 } // namespace webrtc
34 namespace remoting {
36 class SoftwareVideoRenderer;
38 // Video renderer that wraps SoftwareVideoRenderer and displays it using Pepper
39 // 2D graphics API.
40 class PepperVideoRenderer2D : public PepperVideoRenderer,
41 public FrameConsumer {
42 public:
43 PepperVideoRenderer2D();
44 ~PepperVideoRenderer2D() override;
46 // PepperVideoRenderer interface.
47 bool Initialize(pp::Instance* instance,
48 const ClientContext& context,
49 EventHandler* event_handler,
50 protocol::PerformanceTracker* perf_tracker) override;
51 void OnViewChanged(const pp::View& view) override;
52 void EnableDebugDirtyRegion(bool enable) override;
54 // VideoRenderer interface.
55 void OnSessionConfig(const protocol::SessionConfig& config) override;
56 protocol::VideoStub* GetVideoStub() override;
58 private:
59 // FrameConsumer implementation.
60 scoped_ptr<webrtc::DesktopFrame> AllocateFrame(
61 const webrtc::DesktopSize& size) override;
62 void DrawFrame(scoped_ptr<webrtc::DesktopFrame> frame,
63 const base::Closure& done) override;
64 PixelFormat GetPixelFormat() override;
67 void Flush();
68 void OnFlushDone(int result);
70 // Parameters passed to Initialize().
71 pp::Instance* instance_ = nullptr;
72 EventHandler* event_handler_ = nullptr;
74 pp::Graphics2D graphics2d_;
76 scoped_ptr<SoftwareVideoRenderer> software_video_renderer_;
78 // View size in output pixels.
79 webrtc::DesktopSize view_size_;
81 // Size of the most recent source frame in pixels.
82 webrtc::DesktopSize source_size_;
84 // Resolution of the most recent source frame dots-per-inch.
85 webrtc::DesktopVector source_dpi_;
87 // Shape of the most recent source frame.
88 scoped_ptr<webrtc::DesktopRegion> source_shape_;
90 // Done callbacks for the frames that have been painted but not flushed.
91 ScopedVector<base::ScopedClosureRunner> pending_frames_done_callbacks_;
93 // Done callbacks for the frames that are currently being flushed.
94 ScopedVector<base::ScopedClosureRunner> flushing_frames_done_callbacks_;
96 // True if there paint operations that need to be flushed.
97 bool need_flush_ = false;
99 // True if there is already a Flush() pending on the Graphics2D context.
100 bool flush_pending_ = false;
102 // True after the first call to DrawFrame().
103 bool frame_received_ = false;
105 // True if dirty regions are to be sent to |event_handler_| for debugging.
106 bool debug_dirty_region_ = false;
108 base::ThreadChecker thread_checker_;
110 pp::CompletionCallbackFactory<PepperVideoRenderer2D> callback_factory_;
111 base::WeakPtrFactory<PepperVideoRenderer2D> weak_factory_;
113 DISALLOW_COPY_AND_ASSIGN(PepperVideoRenderer2D);
116 } // namespace remoting
118 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_2D_H_