Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: media/video/capture/screen/screen_capturer_win.cc

Issue 14305004: Simplify ScreenCapturer interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "media/video/capture/screen/screen_capturer.h" 5 #include "media/video/capture/screen/screen_capturer.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // ScreenCapturerWin captures 32bit RGB using GDI. 73 // ScreenCapturerWin captures 32bit RGB using GDI.
74 // 74 //
75 // ScreenCapturerWin is double-buffered as required by ScreenCapturer. 75 // ScreenCapturerWin is double-buffered as required by ScreenCapturer.
76 class ScreenCapturerWin : public ScreenCapturer { 76 class ScreenCapturerWin : public ScreenCapturer {
77 public: 77 public:
78 ScreenCapturerWin(); 78 ScreenCapturerWin();
79 virtual ~ScreenCapturerWin(); 79 virtual ~ScreenCapturerWin();
80 80
81 // Overridden from ScreenCapturer: 81 // Overridden from ScreenCapturer:
82 virtual void Start(Delegate* delegate) OVERRIDE; 82 virtual void Start(Delegate* delegate) OVERRIDE;
83 virtual void Stop() OVERRIDE;
84 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE;
85 virtual void CaptureFrame() OVERRIDE; 83 virtual void CaptureFrame() OVERRIDE;
86 84
87 private: 85 private:
88 // Make sure that the device contexts match the screen configuration. 86 // Make sure that the device contexts match the screen configuration.
89 void PrepareCaptureResources(); 87 void PrepareCaptureResources();
90 88
91 // Creates a ScreenCaptureData instance wrapping the current framebuffer and 89 // Creates a ScreenCaptureData instance wrapping the current framebuffer and
92 // notifies |delegate_|. 90 // notifies |delegate_|.
93 void CaptureRegion(const SkRegion& region, 91 void CaptureRegion(const SkRegion& region,
94 const base::Time& capture_start_time); 92 const base::Time& capture_start_time);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 202 }
205 203
206 ScreenCapturerWin::ScreenCapturerWin() 204 ScreenCapturerWin::ScreenCapturerWin()
207 : delegate_(NULL), 205 : delegate_(NULL),
208 desktop_dc_rect_(SkIRect::MakeEmpty()), 206 desktop_dc_rect_(SkIRect::MakeEmpty()),
209 composition_func_(NULL), 207 composition_func_(NULL),
210 set_thread_execution_state_failed_(false) { 208 set_thread_execution_state_failed_(false) {
211 } 209 }
212 210
213 ScreenCapturerWin::~ScreenCapturerWin() { 211 ScreenCapturerWin::~ScreenCapturerWin() {
214 } 212 // Restore Aero.
213 if (composition_func_ != NULL) {
214 (*composition_func_)(DWM_EC_ENABLECOMPOSITION);
215 }
215 216
216 void ScreenCapturerWin::InvalidateRegion(const SkRegion& invalid_region) { 217 delegate_ = NULL;
217 helper_.InvalidateRegion(invalid_region);
218 } 218 }
219 219
220 void ScreenCapturerWin::CaptureFrame() { 220 void ScreenCapturerWin::CaptureFrame() {
221 base::Time capture_start_time = base::Time::Now(); 221 base::Time capture_start_time = base::Time::Now();
222 222
223 // Request that the system not power-down the system, or the display hardware. 223 // Request that the system not power-down the system, or the display hardware.
224 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { 224 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) {
225 if (!set_thread_execution_state_failed_) { 225 if (!set_thread_execution_state_failed_) {
226 set_thread_execution_state_failed_ = true; 226 set_thread_execution_state_failed_ = true;
227 LOG_GETLASTERROR(WARNING) 227 LOG_GETLASTERROR(WARNING)
(...skipping 19 matching lines...) Expand all
247 differ_.reset(new Differ(current_buffer->dimensions().width(), 247 differ_.reset(new Differ(current_buffer->dimensions().width(),
248 current_buffer->dimensions().height(), 248 current_buffer->dimensions().height(),
249 ScreenCaptureData::kBytesPerPixel, 249 ScreenCaptureData::kBytesPerPixel,
250 current_buffer->bytes_per_row())); 250 current_buffer->bytes_per_row()));
251 } 251 }
252 252
253 // Calculate difference between the two last captured frames. 253 // Calculate difference between the two last captured frames.
254 SkRegion region; 254 SkRegion region;
255 differ_->CalcDirtyRegion(last_buffer->pixels(), current_buffer->pixels(), 255 differ_->CalcDirtyRegion(last_buffer->pixels(), current_buffer->pixels(),
256 &region); 256 &region);
257 InvalidateRegion(region); 257 helper_.InvalidateRegion(region);
258 } else { 258 } else {
259 // No previous frame is available. Invalidate the whole screen. 259 // No previous frame is available. Invalidate the whole screen.
260 helper_.InvalidateScreen(current_buffer->dimensions()); 260 helper_.InvalidateScreen(current_buffer->dimensions());
261 } 261 }
262 262
263 // Wrap the captured frame into ScreenCaptureData structure and invoke 263 // Wrap the captured frame into ScreenCaptureData structure and invoke
264 // the completion callback. 264 // the completion callback.
265 SkRegion invalid_region; 265 SkRegion invalid_region;
266 helper_.SwapInvalidRegion(&invalid_region); 266 helper_.SwapInvalidRegion(&invalid_region);
267 CaptureRegion(invalid_region, capture_start_time); 267 CaptureRegion(invalid_region, capture_start_time);
(...skipping 20 matching lines...) Expand all
288 } 288 }
289 289
290 // Vote to disable Aero composited desktop effects while capturing. Windows 290 // Vote to disable Aero composited desktop effects while capturing. Windows
291 // will restore Aero automatically if the process exits. This has no effect 291 // will restore Aero automatically if the process exits. This has no effect
292 // under Windows 8 or higher. See crbug.com/124018. 292 // under Windows 8 or higher. See crbug.com/124018.
293 if (composition_func_ != NULL) { 293 if (composition_func_ != NULL) {
294 (*composition_func_)(DWM_EC_DISABLECOMPOSITION); 294 (*composition_func_)(DWM_EC_DISABLECOMPOSITION);
295 } 295 }
296 } 296 }
297 297
298 void ScreenCapturerWin::Stop() {
299 // Restore Aero.
300 if (composition_func_ != NULL) {
301 (*composition_func_)(DWM_EC_ENABLECOMPOSITION);
302 }
303
304 delegate_ = NULL;
305 }
306
307 void ScreenCapturerWin::PrepareCaptureResources() { 298 void ScreenCapturerWin::PrepareCaptureResources() {
308 // Switch to the desktop receiving user input if different from the current 299 // Switch to the desktop receiving user input if different from the current
309 // one. 300 // one.
310 scoped_ptr<Desktop> input_desktop = Desktop::GetInputDesktop(); 301 scoped_ptr<Desktop> input_desktop = Desktop::GetInputDesktop();
311 if (input_desktop.get() != NULL && !desktop_.IsSame(*input_desktop)) { 302 if (input_desktop.get() != NULL && !desktop_.IsSame(*input_desktop)) {
312 // Release GDI resources otherwise SetThreadDesktop will fail. 303 // Release GDI resources otherwise SetThreadDesktop will fail.
313 desktop_dc_.reset(); 304 desktop_dc_.reset();
314 memory_dc_.Set(NULL); 305 memory_dc_.Set(NULL);
315 306
316 // If SetThreadDesktop() fails, the thread is still assigned a desktop. 307 // If SetThreadDesktop() fails, the thread is still assigned a desktop.
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 void ScreenCapturer::Delegate::ReleaseSharedBuffer( 590 void ScreenCapturer::Delegate::ReleaseSharedBuffer(
600 scoped_refptr<SharedBuffer> buffer) { 591 scoped_refptr<SharedBuffer> buffer) {
601 } 592 }
602 593
603 // static 594 // static
604 scoped_ptr<ScreenCapturer> ScreenCapturer::Create() { 595 scoped_ptr<ScreenCapturer> ScreenCapturer::Create() {
605 return scoped_ptr<ScreenCapturer>(new ScreenCapturerWin()); 596 return scoped_ptr<ScreenCapturer>(new ScreenCapturerWin());
606 } 597 }
607 598
608 } // namespace media 599 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/screen/screen_capturer_unittest.cc ('k') | media/video/capture/screen/screen_capturer_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698