OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "remoting/host/capturer_gdi.h" | 5 #include "remoting/host/capturer.h" |
6 | |
7 #include <windows.h> | |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "remoting/host/capturer_helper.h" | |
6 #include "remoting/host/differ.h" | 11 #include "remoting/host/differ.h" |
7 | |
8 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
9 | 13 |
10 namespace remoting { | 14 namespace remoting { |
11 | 15 |
16 namespace { | |
17 | |
18 // CapturerGdi captures 32bit RGB using GDI. | |
19 // | |
20 // CapturerGdi is double-buffered as required by Capturer. See | |
21 // remoting/host/capturer.h. | |
22 class CapturerGdi : public Capturer { | |
23 public: | |
24 CapturerGdi(); | |
25 virtual ~CapturerGdi(); | |
26 | |
27 // Capturer interface. | |
28 virtual void ScreenConfigurationChanged() OVERRIDE; | |
29 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; | |
30 virtual void ClearInvalidRects() OVERRIDE; | |
31 virtual void InvalidateRects(const InvalidRects& inval_rects) OVERRIDE; | |
32 virtual void InvalidateScreen(const gfx::Size& size) OVERRIDE; | |
33 virtual void InvalidateFullScreen() OVERRIDE; | |
34 virtual void CaptureInvalidRects(CaptureCompletedCallback* callback) OVERRIDE; | |
35 virtual const gfx::Size& size_most_recent() const OVERRIDE; | |
36 | |
37 private: | |
38 struct VideoFrameBuffer { | |
39 VideoFrameBuffer(void* data, const gfx::Size& size, int bytes_per_pixel, | |
40 int bytes_per_row) | |
41 : data(data), size(size), bytes_per_pixel(bytes_per_pixel), | |
42 bytes_per_row(bytes_per_row) { | |
43 } | |
44 VideoFrameBuffer() { | |
45 data = 0; | |
46 size = gfx::Size(0, 0); | |
47 bytes_per_pixel = 0; | |
48 bytes_per_row = 0; | |
49 } | |
50 void* data; | |
51 gfx::Size size; | |
52 int bytes_per_pixel; | |
53 int bytes_per_row; | |
54 }; | |
55 | |
56 // Make sure that the current buffer has the same size as the screen. | |
57 void UpdateBufferCapture(const gfx::Size& size); | |
58 | |
59 // Allocate memory for a buffer of a given size, freeing any memory previously | |
60 // allocated for that buffer. | |
61 void ReallocateBuffer(int buffer_index, const gfx::Size& size); | |
62 | |
63 void CalculateInvalidRects(); | |
64 void CaptureRects(const InvalidRects& rects, | |
65 CaptureCompletedCallback* callback); | |
66 | |
67 void ReleaseBuffers(); | |
68 // Generates an image in the current buffer. | |
69 void CaptureImage(); | |
70 | |
71 // Gets the current screen size and calls ScreenConfigurationChanged | |
72 // if the screen size has changed. | |
73 void MaybeChangeScreenConfiguration(); | |
74 | |
75 // Gets the screen size. | |
76 gfx::Size GetScreenSize(); | |
77 | |
78 // A thread-safe list of invalid rectangles, and the size of the most | |
79 // recently captured screen. | |
80 CapturerHelper helper; | |
81 | |
82 // There are two buffers for the screen images, as required by Capturer. | |
83 static const int kNumBuffers = 2; | |
84 VideoFrameBuffer buffers_[kNumBuffers]; | |
85 | |
86 // Gdi specific information about screen. | |
87 HDC desktop_dc_; | |
88 HDC memory_dc_; | |
89 HBITMAP target_bitmap_[kNumBuffers]; | |
90 | |
91 // The screen size attached to the device contexts through which the screen | |
92 // is captured. | |
93 gfx::Size dc_size_; | |
94 | |
95 // The current buffer with valid data for reading. | |
96 int current_buffer_; | |
97 | |
98 // Format of pixels returned in buffer. | |
99 media::VideoFrame::Format pixel_format_; | |
100 | |
101 // Class to calculate the difference between two screen bitmaps. | |
102 scoped_ptr<Differ> differ_; | |
103 | |
104 // True if we should force a fullscreen capture. | |
105 bool capture_fullscreen_; | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(CapturerGdi); | |
108 }; | |
109 | |
12 // 3780 pixels per meter is equivalent to 96 DPI, typical on desktop monitors. | 110 // 3780 pixels per meter is equivalent to 96 DPI, typical on desktop monitors. |
Jamie
2011/04/01 10:51:10
Why can't these be static?
dmac
2011/04/01 21:15:07
I turned them back to static.
| |
13 static const int kPixelsPerMeter = 3780; | 111 const int kPixelsPerMeter = 3780; |
14 // 32 bit RGBA is 4 bytes per pixel. | 112 // 32 bit RGBA is 4 bytes per pixel. |
15 static const int kBytesPerPixel = 4; | 113 const int kBytesPerPixel = 4; |
16 | 114 |
17 CapturerGdi::CapturerGdi() | 115 CapturerGdi::CapturerGdi() |
18 : desktop_dc_(NULL), | 116 : desktop_dc_(NULL), |
19 memory_dc_(NULL), | 117 memory_dc_(NULL), |
20 dc_size_(0, 0), | 118 dc_size_(0, 0), |
21 current_buffer_(0), | 119 current_buffer_(0), |
22 pixel_format_(media::VideoFrame::RGB32), | 120 pixel_format_(media::VideoFrame::RGB32), |
23 capture_fullscreen_(true) { | 121 capture_fullscreen_(true) { |
24 memset(target_bitmap_, 0, sizeof(target_bitmap_)); | 122 memset(target_bitmap_, 0, sizeof(target_bitmap_)); |
25 memset(buffers_, 0, sizeof(buffers_)); | 123 memset(buffers_, 0, sizeof(buffers_)); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 BitBlt(memory_dc_, 0, 0, buffers_[current_buffer_].size.width(), | 320 BitBlt(memory_dc_, 0, 0, buffers_[current_buffer_].size.width(), |
223 buffers_[current_buffer_].size.height(), desktop_dc_, 0, 0, | 321 buffers_[current_buffer_].size.height(), desktop_dc_, 0, 0, |
224 SRCCOPY | CAPTUREBLT); | 322 SRCCOPY | CAPTUREBLT); |
225 } | 323 } |
226 | 324 |
227 gfx::Size CapturerGdi::GetScreenSize() { | 325 gfx::Size CapturerGdi::GetScreenSize() { |
228 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), | 326 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), |
229 GetSystemMetrics(SM_CYSCREEN)); | 327 GetSystemMetrics(SM_CYSCREEN)); |
230 } | 328 } |
231 | 329 |
330 } // namespace | |
331 | |
232 // static | 332 // static |
233 Capturer* Capturer::Create() { | 333 Capturer* Capturer::Create() { |
234 return new CapturerGdi(); | 334 return new CapturerGdi(); |
235 } | 335 } |
236 | 336 |
237 } // namespace remoting | 337 } // namespace remoting |
OLD | NEW |