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.h" | 5 #include "remoting/host/capturer.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "remoting/host/capturer_helper.h" | 10 #include "remoting/host/capturer_helper.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 CapturerGdi(); | 23 CapturerGdi(); |
24 virtual ~CapturerGdi(); | 24 virtual ~CapturerGdi(); |
25 | 25 |
26 // Capturer interface. | 26 // Capturer interface. |
27 virtual void ScreenConfigurationChanged() OVERRIDE; | 27 virtual void ScreenConfigurationChanged() OVERRIDE; |
28 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; | 28 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; |
29 virtual void ClearInvalidRegion() OVERRIDE; | 29 virtual void ClearInvalidRegion() OVERRIDE; |
30 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; | 30 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; |
31 virtual void InvalidateScreen(const SkISize& size) OVERRIDE; | 31 virtual void InvalidateScreen(const SkISize& size) OVERRIDE; |
32 virtual void InvalidateFullScreen() OVERRIDE; | 32 virtual void InvalidateFullScreen() OVERRIDE; |
33 virtual void CaptureInvalidRegion(CaptureCompletedCallback* callback) | 33 virtual void CaptureInvalidRegion( |
34 OVERRIDE; | 34 const CaptureCompletedCallback& callback) OVERRIDE; |
35 virtual const SkISize& size_most_recent() const OVERRIDE; | 35 virtual const SkISize& size_most_recent() const OVERRIDE; |
36 | 36 |
37 private: | 37 private: |
38 struct VideoFrameBuffer { | 38 struct VideoFrameBuffer { |
39 VideoFrameBuffer(void* data, const SkISize& size, int bytes_per_pixel, | 39 VideoFrameBuffer(void* data, const SkISize& size, int bytes_per_pixel, |
40 int bytes_per_row) | 40 int bytes_per_row) |
41 : data(data), size(size), bytes_per_pixel(bytes_per_pixel), | 41 : data(data), size(size), bytes_per_pixel(bytes_per_pixel), |
42 bytes_per_row(bytes_per_row) { | 42 bytes_per_row(bytes_per_row) { |
43 } | 43 } |
44 VideoFrameBuffer() { | 44 VideoFrameBuffer() { |
(...skipping 10 matching lines...) Expand all Loading... |
55 | 55 |
56 // Make sure that the current buffer has the same size as the screen. | 56 // Make sure that the current buffer has the same size as the screen. |
57 void UpdateBufferCapture(const SkISize& size); | 57 void UpdateBufferCapture(const SkISize& size); |
58 | 58 |
59 // Allocate memory for a buffer of a given size, freeing any memory previously | 59 // Allocate memory for a buffer of a given size, freeing any memory previously |
60 // allocated for that buffer. | 60 // allocated for that buffer. |
61 void ReallocateBuffer(int buffer_index, const SkISize& size); | 61 void ReallocateBuffer(int buffer_index, const SkISize& size); |
62 | 62 |
63 void CalculateInvalidRegion(); | 63 void CalculateInvalidRegion(); |
64 void CaptureRegion(const SkRegion& region, | 64 void CaptureRegion(const SkRegion& region, |
65 CaptureCompletedCallback* callback); | 65 const CaptureCompletedCallback& callback); |
66 | 66 |
67 void ReleaseBuffers(); | 67 void ReleaseBuffers(); |
68 // Generates an image in the current buffer. | 68 // Generates an image in the current buffer. |
69 void CaptureImage(); | 69 void CaptureImage(); |
70 | 70 |
71 // Gets the current screen size and calls ScreenConfigurationChanged | 71 // Gets the current screen size and calls ScreenConfigurationChanged |
72 // if the screen size has changed. | 72 // if the screen size has changed. |
73 void MaybeChangeScreenConfiguration(); | 73 void MaybeChangeScreenConfiguration(); |
74 | 74 |
75 // Gets the screen size. | 75 // Gets the screen size. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 137 } |
138 | 138 |
139 void CapturerGdi::InvalidateScreen(const SkISize& size) { | 139 void CapturerGdi::InvalidateScreen(const SkISize& size) { |
140 helper_.InvalidateScreen(size); | 140 helper_.InvalidateScreen(size); |
141 } | 141 } |
142 | 142 |
143 void CapturerGdi::InvalidateFullScreen() { | 143 void CapturerGdi::InvalidateFullScreen() { |
144 helper_.InvalidateFullScreen(); | 144 helper_.InvalidateFullScreen(); |
145 } | 145 } |
146 | 146 |
147 void CapturerGdi::CaptureInvalidRegion(CaptureCompletedCallback* callback) { | 147 void CapturerGdi::CaptureInvalidRegion( |
| 148 const CaptureCompletedCallback& callback) { |
148 CalculateInvalidRegion(); | 149 CalculateInvalidRegion(); |
149 SkRegion invalid_region; | 150 SkRegion invalid_region; |
150 helper_.SwapInvalidRegion(&invalid_region); | 151 helper_.SwapInvalidRegion(&invalid_region); |
151 CaptureRegion(invalid_region, callback); | 152 CaptureRegion(invalid_region, callback); |
152 } | 153 } |
153 | 154 |
154 const SkISize& CapturerGdi::size_most_recent() const { | 155 const SkISize& CapturerGdi::size_most_recent() const { |
155 return helper_.size_most_recent(); | 156 return helper_.size_most_recent(); |
156 } | 157 } |
157 | 158 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 current.bytes_per_pixel, current.bytes_per_row)); | 271 current.bytes_per_pixel, current.bytes_per_row)); |
271 } | 272 } |
272 | 273 |
273 SkRegion region; | 274 SkRegion region; |
274 differ_->CalcDirtyRegion(prev.data, current.data, ®ion); | 275 differ_->CalcDirtyRegion(prev.data, current.data, ®ion); |
275 | 276 |
276 InvalidateRegion(region); | 277 InvalidateRegion(region); |
277 } | 278 } |
278 | 279 |
279 void CapturerGdi::CaptureRegion(const SkRegion& region, | 280 void CapturerGdi::CaptureRegion(const SkRegion& region, |
280 CaptureCompletedCallback* callback) { | 281 const CaptureCompletedCallback& callback) { |
281 scoped_ptr<CaptureCompletedCallback> callback_deleter(callback); | |
282 | |
283 const VideoFrameBuffer& buffer = buffers_[current_buffer_]; | 282 const VideoFrameBuffer& buffer = buffers_[current_buffer_]; |
284 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; | 283 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; |
285 | 284 |
286 DataPlanes planes; | 285 DataPlanes planes; |
287 planes.data[0] = static_cast<uint8*>(buffer.data); | 286 planes.data[0] = static_cast<uint8*>(buffer.data); |
288 planes.strides[0] = buffer.bytes_per_row; | 287 planes.strides[0] = buffer.bytes_per_row; |
289 | 288 |
290 scoped_refptr<CaptureData> data(new CaptureData(planes, | 289 scoped_refptr<CaptureData> data(new CaptureData(planes, |
291 buffer.size, | 290 buffer.size, |
292 pixel_format_)); | 291 pixel_format_)); |
293 data->mutable_dirty_region() = region; | 292 data->mutable_dirty_region() = region; |
294 | 293 |
295 helper_.set_size_most_recent(data->size()); | 294 helper_.set_size_most_recent(data->size()); |
296 | 295 |
297 callback->Run(data); | 296 callback.Run(data); |
298 } | 297 } |
299 | 298 |
300 void CapturerGdi::CaptureImage() { | 299 void CapturerGdi::CaptureImage() { |
301 // Make sure the structures we use to capture the image have the correct size. | 300 // Make sure the structures we use to capture the image have the correct size. |
302 UpdateBufferCapture(GetScreenSize()); | 301 UpdateBufferCapture(GetScreenSize()); |
303 | 302 |
304 // Select the target bitmap into the memory dc. | 303 // Select the target bitmap into the memory dc. |
305 SelectObject(memory_dc_, target_bitmap_[current_buffer_]); | 304 SelectObject(memory_dc_, target_bitmap_[current_buffer_]); |
306 | 305 |
307 // And then copy the rect from desktop to memory. | 306 // And then copy the rect from desktop to memory. |
308 BitBlt(memory_dc_, 0, 0, buffers_[current_buffer_].size.width(), | 307 BitBlt(memory_dc_, 0, 0, buffers_[current_buffer_].size.width(), |
309 buffers_[current_buffer_].size.height(), desktop_dc_, 0, 0, | 308 buffers_[current_buffer_].size.height(), desktop_dc_, 0, 0, |
310 SRCCOPY | CAPTUREBLT); | 309 SRCCOPY | CAPTUREBLT); |
311 } | 310 } |
312 | 311 |
313 SkISize CapturerGdi::GetScreenSize() { | 312 SkISize CapturerGdi::GetScreenSize() { |
314 return SkISize::Make(GetSystemMetrics(SM_CXSCREEN), | 313 return SkISize::Make(GetSystemMetrics(SM_CXSCREEN), |
315 GetSystemMetrics(SM_CYSCREEN)); | 314 GetSystemMetrics(SM_CYSCREEN)); |
316 } | 315 } |
317 | 316 |
318 } // namespace | 317 } // namespace |
319 | 318 |
320 // static | 319 // static |
321 Capturer* Capturer::Create() { | 320 Capturer* Capturer::Create() { |
322 return new CapturerGdi(); | 321 return new CapturerGdi(); |
323 } | 322 } |
324 | 323 |
325 } // namespace remoting | 324 } // namespace remoting |
OLD | NEW |