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