| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h" | 11 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 | 14 |
| 15 #include <utility> | 15 #include <utility> |
| 16 | 16 |
| 17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
| 18 #include "webrtc/base/timeutils.h" |
| 18 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 19 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
| 19 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 20 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| 20 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" | 21 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" |
| 21 #include "webrtc/modules/desktop_capture/desktop_region.h" | 22 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 22 #include "webrtc/modules/desktop_capture/differ.h" | 23 #include "webrtc/modules/desktop_capture/differ.h" |
| 23 #include "webrtc/modules/desktop_capture/mouse_cursor.h" | 24 #include "webrtc/modules/desktop_capture/mouse_cursor.h" |
| 24 #include "webrtc/modules/desktop_capture/win/cursor.h" | 25 #include "webrtc/modules/desktop_capture/win/cursor.h" |
| 25 #include "webrtc/modules/desktop_capture/win/desktop.h" | 26 #include "webrtc/modules/desktop_capture/win/desktop.h" |
| 26 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" | 27 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" |
| 27 #include "webrtc/system_wrappers/include/logging.h" | 28 #include "webrtc/system_wrappers/include/logging.h" |
| 28 #include "webrtc/system_wrappers/include/tick_util.h" | |
| 29 | 29 |
| 30 namespace webrtc { | 30 namespace webrtc { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Constants from dwmapi.h. | 34 // Constants from dwmapi.h. |
| 35 const UINT DWM_EC_DISABLECOMPOSITION = 0; | 35 const UINT DWM_EC_DISABLECOMPOSITION = 0; |
| 36 const UINT DWM_EC_ENABLECOMPOSITION = 1; | 36 const UINT DWM_EC_ENABLECOMPOSITION = 1; |
| 37 | 37 |
| 38 const wchar_t kDwmapiLibraryName[] = L"dwmapi.dll"; | 38 const wchar_t kDwmapiLibraryName[] = L"dwmapi.dll"; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 if (dwmapi_library_) | 72 if (dwmapi_library_) |
| 73 FreeLibrary(dwmapi_library_); | 73 FreeLibrary(dwmapi_library_); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ScreenCapturerWinGdi::SetSharedMemoryFactory( | 76 void ScreenCapturerWinGdi::SetSharedMemoryFactory( |
| 77 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { | 77 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { |
| 78 shared_memory_factory_ = std::move(shared_memory_factory); | 78 shared_memory_factory_ = std::move(shared_memory_factory); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { | 81 void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { |
| 82 TickTime capture_start_time = TickTime::Now(); | 82 int64_t capture_start_time_nanos = rtc::TimeNanos(); |
| 83 | 83 |
| 84 queue_.MoveToNextFrame(); | 84 queue_.MoveToNextFrame(); |
| 85 RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); | 85 RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); |
| 86 | 86 |
| 87 // Request that the system not power-down the system, or the display hardware. | 87 // Request that the system not power-down the system, or the display hardware. |
| 88 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { | 88 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { |
| 89 if (!set_thread_execution_state_failed_) { | 89 if (!set_thread_execution_state_failed_) { |
| 90 set_thread_execution_state_failed_ = true; | 90 set_thread_execution_state_failed_ = true; |
| 91 LOG_F(LS_WARNING) << "Failed to make system & display power assertion: " | 91 LOG_F(LS_WARNING) << "Failed to make system & display power assertion: " |
| 92 << GetLastError(); | 92 << GetLastError(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 helper_.set_size_most_recent(current_frame->size()); | 130 helper_.set_size_most_recent(current_frame->size()); |
| 131 | 131 |
| 132 // Emit the current frame. | 132 // Emit the current frame. |
| 133 DesktopFrame* frame = queue_.current_frame()->Share(); | 133 DesktopFrame* frame = queue_.current_frame()->Share(); |
| 134 frame->set_dpi(DesktopVector( | 134 frame->set_dpi(DesktopVector( |
| 135 GetDeviceCaps(desktop_dc_, LOGPIXELSX), | 135 GetDeviceCaps(desktop_dc_, LOGPIXELSX), |
| 136 GetDeviceCaps(desktop_dc_, LOGPIXELSY))); | 136 GetDeviceCaps(desktop_dc_, LOGPIXELSY))); |
| 137 frame->mutable_updated_region()->Clear(); | 137 frame->mutable_updated_region()->Clear(); |
| 138 helper_.TakeInvalidRegion(frame->mutable_updated_region()); | 138 helper_.TakeInvalidRegion(frame->mutable_updated_region()); |
| 139 frame->set_capture_time_ms( | 139 frame->set_capture_time_ms( |
| 140 (TickTime::Now() - capture_start_time).Milliseconds()); | 140 (rtc::TimeNanos() - capture_start_time_nanos) / |
| 141 rtc::kNumNanosecsPerMillisec); |
| 141 callback_->OnCaptureCompleted(frame); | 142 callback_->OnCaptureCompleted(frame); |
| 142 } | 143 } |
| 143 | 144 |
| 144 bool ScreenCapturerWinGdi::GetScreenList(ScreenList* screens) { | 145 bool ScreenCapturerWinGdi::GetScreenList(ScreenList* screens) { |
| 145 return webrtc::GetScreenList(screens); | 146 return webrtc::GetScreenList(screens); |
| 146 } | 147 } |
| 147 | 148 |
| 148 bool ScreenCapturerWinGdi::SelectScreen(ScreenId id) { | 149 bool ScreenCapturerWinGdi::SelectScreen(ScreenId id) { |
| 149 bool valid = IsScreenValid(id, ¤t_device_key_); | 150 bool valid = IsScreenValid(id, ¤t_device_key_); |
| 150 if (valid) | 151 if (valid) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 SRCCOPY | CAPTUREBLT); | 267 SRCCOPY | CAPTUREBLT); |
| 267 | 268 |
| 268 // Select back the previously selected object to that the device contect | 269 // Select back the previously selected object to that the device contect |
| 269 // could be destroyed independently of the bitmap if needed. | 270 // could be destroyed independently of the bitmap if needed. |
| 270 SelectObject(memory_dc_, previous_object); | 271 SelectObject(memory_dc_, previous_object); |
| 271 } | 272 } |
| 272 return true; | 273 return true; |
| 273 } | 274 } |
| 274 | 275 |
| 275 } // namespace webrtc | 276 } // namespace webrtc |
| OLD | NEW |