OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_HOST_CAPTURER_H_ | 5 #ifndef REMOTING_HOST_CAPTURER_H_ |
6 #define REMOTING_HOST_CAPTURER_H_ | 6 #define REMOTING_HOST_CAPTURER_H_ |
7 | 7 |
8 #include <vector> | |
9 | |
10 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
11 #include "base/callback.h" | 9 #include "base/callback.h" |
12 #include "base/lock.h" | 10 #include "base/lock.h" |
13 #include "base/task.h" | 11 #include "base/task.h" |
14 #include "gfx/rect.h" | 12 #include "remoting/base/capture_data.h" |
15 #include "remoting/base/protocol/chromotocol.pb.h" | |
16 | 13 |
17 namespace remoting { | 14 namespace remoting { |
18 | 15 |
19 typedef std::vector<gfx::Rect> RectVector; | |
20 | |
21 // A class to perform the task of capturing the image of a window. | 16 // A class to perform the task of capturing the image of a window. |
22 // The capture action is asynchronous to allow maximum throughput. | 17 // The capture action is asynchronous to allow maximum throughput. |
23 // | 18 // |
24 // Implementation has to ensure the following gurantees: | 19 // Implementation has to ensure the following gurantees: |
25 // 1. Double buffering | 20 // 1. Double buffering |
26 // Since data can be read while another capture action is | 21 // Since data can be read while another capture action is |
27 // happening. | 22 // happening. |
28 class Capturer { | 23 class Capturer { |
29 public: | 24 public: |
30 | |
31 struct DataPlanes { | |
32 static const int kPlaneCount = 3; | |
33 uint8* data[kPlaneCount]; | |
34 int strides[kPlaneCount]; | |
35 | |
36 DataPlanes() { | |
37 for (int i = 0; i < kPlaneCount; ++i) { | |
38 data[i] = NULL; | |
39 strides[i] = 0; | |
40 } | |
41 } | |
42 }; | |
43 | |
44 // Stores the data and information of a capture to pass off to the | |
45 // encoding thread. | |
46 class CaptureData : public base::RefCountedThreadSafe<CaptureData> { | |
47 public: | |
48 CaptureData(const DataPlanes &data_planes, | |
49 int width, | |
50 int height, | |
51 PixelFormat format) : | |
52 data_planes_(data_planes), dirty_rects_(), | |
53 width_(width), height_(height), pixel_format_(format) { } | |
54 | |
55 // Get the data_planes data of the last capture. | |
56 const DataPlanes& data_planes() const { return data_planes_; } | |
57 | |
58 // Get the list of updated rectangles in the last capture. The result is | |
59 // written into |rects|. | |
60 const RectVector& dirty_rects() const { return dirty_rects_; } | |
61 | |
62 // Get the width of the image captured. | |
63 int width() const { return width_; } | |
64 | |
65 // Get the height of the image captured. | |
66 int height() const { return height_; } | |
67 | |
68 // Get the pixel format of the image captured. | |
69 PixelFormat pixel_format() const { return pixel_format_; } | |
70 | |
71 // Mutating methods. | |
72 RectVector& mutable_dirty_rects() { return dirty_rects_; } | |
73 | |
74 private: | |
75 const DataPlanes data_planes_; | |
76 RectVector dirty_rects_; | |
77 int width_; | |
78 int height_; | |
79 PixelFormat pixel_format_; | |
80 | |
81 friend class base::RefCountedThreadSafe<CaptureData>; | |
82 ~CaptureData() {} | |
83 }; | |
84 | |
85 // CaptureCompletedCallback is called when the capturer has completed. | 25 // CaptureCompletedCallback is called when the capturer has completed. |
86 typedef Callback1<scoped_refptr<CaptureData> >::Type CaptureCompletedCallback; | 26 typedef Callback1<scoped_refptr<CaptureData> >::Type CaptureCompletedCallback; |
87 | 27 |
88 Capturer(); | 28 Capturer(); |
89 virtual ~Capturer(); | 29 virtual ~Capturer(); |
90 | 30 |
91 | 31 |
92 // Capture the updated regions since last capture. If the last | 32 // Capture the updated regions since last capture. If the last |
93 // capture doesn't exist, the full window is captured. | 33 // capture doesn't exist, the full window is captured. |
94 // | 34 // |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // capture. | 101 // capture. |
162 RectVector inval_rects_; | 102 RectVector inval_rects_; |
163 | 103 |
164 // A lock protecting |inval_rects_| across threads. | 104 // A lock protecting |inval_rects_| across threads. |
165 Lock inval_rects_lock_; | 105 Lock inval_rects_lock_; |
166 }; | 106 }; |
167 | 107 |
168 } // namespace remoting | 108 } // namespace remoting |
169 | 109 |
170 #endif // REMOTING_HOST_CAPTURER_H_ | 110 #endif // REMOTING_HOST_CAPTURER_H_ |
OLD | NEW |