tuple: update to make use of C++11
[chromium-blink-merge.git] / remoting / client / plugin / pepper_view.h
blob388bd9abbd97060c0cca3af946e8bf024092b90f
1 // Copyright (c) 2012 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 // This class is an implementation of the ChromotingView for Pepper. It is
6 // callable only on the Pepper thread.
8 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_
9 #define REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_
11 #include <list>
13 #include "base/compiler_specific.h"
14 #include "ppapi/cpp/graphics_2d.h"
15 #include "ppapi/cpp/view.h"
16 #include "ppapi/cpp/point.h"
17 #include "ppapi/utility/completion_callback_factory.h"
18 #include "remoting/client/frame_consumer.h"
19 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
20 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
22 namespace base {
23 class Time;
24 } // namespace base
26 namespace webrtc {
27 class DesktopFrame;
28 } // namespace webrtc
30 namespace remoting {
32 class ChromotingInstance;
33 class ClientContext;
34 class FrameProducer;
36 class PepperView : public FrameConsumer {
37 public:
38 // Constructs a PepperView for the |instance|. The |instance| and |context|
39 // must outlive this class.
40 PepperView(ChromotingInstance* instance, ClientContext* context);
41 ~PepperView() override;
43 // Allocates buffers and passes them to the FrameProducer to render into until
44 // the maximum number of buffers are in-flight.
45 void Initialize(FrameProducer* producer);
47 // FrameConsumer implementation.
48 void ApplyBuffer(const webrtc::DesktopSize& view_size,
49 const webrtc::DesktopRect& clip_area,
50 webrtc::DesktopFrame* buffer,
51 const webrtc::DesktopRegion& region,
52 const webrtc::DesktopRegion& shape) override;
53 void ReturnBuffer(webrtc::DesktopFrame* buffer) override;
54 void SetSourceSize(const webrtc::DesktopSize& source_size,
55 const webrtc::DesktopVector& dpi) override;
56 PixelFormat GetPixelFormat() override;
58 // Updates the PepperView's size & clipping area, taking into account the
59 // DIP-to-device scale factor.
60 void SetView(const pp::View& view);
62 // Returns the dimensions of the most recently displayed frame, in pixels.
63 const webrtc::DesktopSize& get_source_size() const {
64 return source_size_;
67 private:
68 // Allocates a new frame buffer to supply to the FrameProducer to render into.
69 // Returns NULL if the maximum number of buffers has already been allocated.
70 webrtc::DesktopFrame* AllocateBuffer();
72 // Frees a frame buffer previously allocated by AllocateBuffer.
73 void FreeBuffer(webrtc::DesktopFrame* buffer);
75 // Renders the parts of |buffer| identified by |region| to the view. If the
76 // clip area of the view has changed since the buffer was generated then
77 // FrameProducer is supplied the missed parts of |region|. The FrameProducer
78 // will be supplied a new buffer when FlushBuffer() completes.
79 void FlushBuffer(const webrtc::DesktopRect& clip_area,
80 webrtc::DesktopFrame* buffer,
81 const webrtc::DesktopRegion& region);
83 // Handles completion of FlushBuffer(), triggering a new buffer to be
84 // returned to FrameProducer for rendering.
85 void OnFlushDone(int result,
86 const base::Time& paint_start,
87 webrtc::DesktopFrame* buffer);
89 // Reference to the creating plugin instance. Needed for interacting with
90 // pepper. Marking explicitly as const since it must be initialized at
91 // object creation, and never change.
92 ChromotingInstance* const instance_;
94 // Context should be constant for the lifetime of the plugin.
95 ClientContext* const context_;
97 pp::Graphics2D graphics2d_;
99 FrameProducer* producer_;
101 // List of allocated image buffers.
102 std::list<webrtc::DesktopFrame*> buffers_;
104 // Queued buffer to paint, with clip area and dirty region in device pixels.
105 webrtc::DesktopFrame* merge_buffer_;
106 webrtc::DesktopRect merge_clip_area_;
107 webrtc::DesktopRegion merge_region_;
109 // View size in Density Independent Pixels (DIPs).
110 webrtc::DesktopSize dips_size_;
112 // Scale factor from DIPs to device pixels.
113 float dips_to_device_scale_;
115 // View size in output pixels. This is the size at which FrameProducer must
116 // render frames. It usually matches the DIPs size of the view, but may match
117 // the size in device pixels when scaling is in effect, to reduce artefacts.
118 webrtc::DesktopSize view_size_;
120 // Scale factor from output pixels to device pixels.
121 float dips_to_view_scale_;
123 // Visible area of the view, in output pixels.
124 webrtc::DesktopRect clip_area_;
126 // Size of the most recent source frame in pixels.
127 webrtc::DesktopSize source_size_;
129 // Resolution of the most recent source frame dots-per-inch.
130 webrtc::DesktopVector source_dpi_;
132 // True if there is already a Flush() pending on the Graphics2D context.
133 bool flush_pending_;
135 // True after Initialize() has been called, until TearDown().
136 bool is_initialized_;
138 // True after the first call to ApplyBuffer().
139 bool frame_received_;
141 pp::CompletionCallbackFactory<PepperView> callback_factory_;
143 DISALLOW_COPY_AND_ASSIGN(PepperView);
146 } // namespace remoting
148 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_