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

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

Issue 12211101: Assert both display and system keep-alive on each capture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 7 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 // Rectangle describing the bounds of the desktop device context. 126 // Rectangle describing the bounds of the desktop device context.
127 SkIRect desktop_dc_rect_; 127 SkIRect desktop_dc_rect_;
128 128
129 // Class to calculate the difference between two screen bitmaps. 129 // Class to calculate the difference between two screen bitmaps.
130 scoped_ptr<Differ> differ_; 130 scoped_ptr<Differ> differ_;
131 131
132 base::ScopedNativeLibrary dwmapi_library_; 132 base::ScopedNativeLibrary dwmapi_library_;
133 DwmEnableCompositionFunc composition_func_; 133 DwmEnableCompositionFunc composition_func_;
134 134
135 // Used to suppress duplicate logging of SetThreadExecutionState errors.
136 bool set_thread_execution_state_failed_;
137
135 DISALLOW_COPY_AND_ASSIGN(ScreenCapturerWin); 138 DISALLOW_COPY_AND_ASSIGN(ScreenCapturerWin);
136 }; 139 };
137 140
138 // 3780 pixels per meter is equivalent to 96 DPI, typical on desktop monitors. 141 // 3780 pixels per meter is equivalent to 96 DPI, typical on desktop monitors.
139 static const int kPixelsPerMeter = 3780; 142 static const int kPixelsPerMeter = 3780;
140 143
141 ScreenCaptureFrameWin::ScreenCaptureFrameWin( 144 ScreenCaptureFrameWin::ScreenCaptureFrameWin(
142 HDC desktop_dc, 145 HDC desktop_dc,
143 const SkISize& size, 146 const SkISize& size,
144 ScreenCapturer::Delegate* delegate) 147 ScreenCapturer::Delegate* delegate)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 set_pixels(reinterpret_cast<uint8*>(data)); 199 set_pixels(reinterpret_cast<uint8*>(data));
197 set_dimensions(SkISize::Make(bmi.bmiHeader.biWidth, 200 set_dimensions(SkISize::Make(bmi.bmiHeader.biWidth,
198 std::abs(bmi.bmiHeader.biHeight))); 201 std::abs(bmi.bmiHeader.biHeight)));
199 set_bytes_per_row( 202 set_bytes_per_row(
200 bmi.bmiHeader.biSizeImage / std::abs(bmi.bmiHeader.biHeight)); 203 bmi.bmiHeader.biSizeImage / std::abs(bmi.bmiHeader.biHeight));
201 } 204 }
202 205
203 ScreenCapturerWin::ScreenCapturerWin() 206 ScreenCapturerWin::ScreenCapturerWin()
204 : delegate_(NULL), 207 : delegate_(NULL),
205 desktop_dc_rect_(SkIRect::MakeEmpty()), 208 desktop_dc_rect_(SkIRect::MakeEmpty()),
206 composition_func_(NULL) { 209 composition_func_(NULL),
210 set_thread_execution_state_failed_(false) {
207 } 211 }
208 212
209 ScreenCapturerWin::~ScreenCapturerWin() { 213 ScreenCapturerWin::~ScreenCapturerWin() {
210 } 214 }
211 215
212 void ScreenCapturerWin::InvalidateRegion(const SkRegion& invalid_region) { 216 void ScreenCapturerWin::InvalidateRegion(const SkRegion& invalid_region) {
213 helper_.InvalidateRegion(invalid_region); 217 helper_.InvalidateRegion(invalid_region);
214 } 218 }
215 219
216 void ScreenCapturerWin::CaptureFrame() { 220 void ScreenCapturerWin::CaptureFrame() {
217 base::Time capture_start_time = base::Time::Now(); 221 base::Time capture_start_time = base::Time::Now();
218 222
219 // Force the system to power-up display hardware, if it has been suspended. 223 // Request that the system not power-down the system, or the display hardware.
220 SetThreadExecutionState(ES_DISPLAY_REQUIRED); 224 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) {
225 if (!set_thread_execution_state_failed_) {
226 set_thread_execution_state_failed_ = true;
227 LOG_GETLASTERROR(WARNING)
228 << "Failed to make system & display power assertion";
229 }
230 }
221 231
222 // Make sure the GDI capture resources are up-to-date. 232 // Make sure the GDI capture resources are up-to-date.
223 PrepareCaptureResources(); 233 PrepareCaptureResources();
224 234
225 // Copy screen bits to the current buffer. 235 // Copy screen bits to the current buffer.
226 CaptureImage(); 236 CaptureImage();
227 237
228 const ScreenCaptureFrame* current_buffer = queue_.current_frame(); 238 const ScreenCaptureFrame* current_buffer = queue_.current_frame();
229 const ScreenCaptureFrame* last_buffer = queue_.previous_frame(); 239 const ScreenCaptureFrame* last_buffer = queue_.previous_frame();
230 if (last_buffer) { 240 if (last_buffer) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 void ScreenCapturer::Delegate::ReleaseSharedBuffer( 587 void ScreenCapturer::Delegate::ReleaseSharedBuffer(
578 scoped_refptr<SharedBuffer> buffer) { 588 scoped_refptr<SharedBuffer> buffer) {
579 } 589 }
580 590
581 // static 591 // static
582 scoped_ptr<ScreenCapturer> ScreenCapturer::Create() { 592 scoped_ptr<ScreenCapturer> ScreenCapturer::Create() {
583 return scoped_ptr<ScreenCapturer>(new ScreenCapturerWin()); 593 return scoped_ptr<ScreenCapturer>(new ScreenCapturerWin());
584 } 594 }
585 595
586 } // namespace media 596 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698