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

Side by Side Diff: webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc

Issue 1902323002: Modify ScreenCaptureFrameQueue into a template (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix build break in linux Created 4 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
OLDNEW
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
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 void ScreenCapturerWinMagnifier::SetSharedMemoryFactory( 84 void ScreenCapturerWinMagnifier::SetSharedMemoryFactory(
85 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) { 85 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) {
86 shared_memory_factory_ = 86 shared_memory_factory_ =
87 rtc::ScopedToUnique(std::move(shared_memory_factory)); 87 rtc::ScopedToUnique(std::move(shared_memory_factory));
88 } 88 }
89 89
90 void ScreenCapturerWinMagnifier::Capture(const DesktopRegion& region) { 90 void ScreenCapturerWinMagnifier::Capture(const DesktopRegion& region) {
91 TickTime capture_start_time = TickTime::Now(); 91 TickTime capture_start_time = TickTime::Now();
92 92
93 queue_.MoveToNextFrame(); 93 queue_.MoveToNext();
94 94
95 // Request that the system not power-down the system, or the display hardware. 95 // Request that the system not power-down the system, or the display hardware.
96 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { 96 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) {
97 if (!set_thread_execution_state_failed_) { 97 if (!set_thread_execution_state_failed_) {
98 set_thread_execution_state_failed_ = true; 98 set_thread_execution_state_failed_ = true;
99 LOG_F(LS_WARNING) << "Failed to make system & display power assertion: " 99 LOG_F(LS_WARNING) << "Failed to make system & display power assertion: "
100 << GetLastError(); 100 << GetLastError();
101 } 101 }
102 } 102 }
103 // Switch to the desktop receiving user input if different from the current 103 // Switch to the desktop receiving user input if different from the current
(...skipping 24 matching lines...) Expand all
128 } 128 }
129 129
130 // Defer to the fallback capturer if magnifier capturer did not work. 130 // Defer to the fallback capturer if magnifier capturer did not work.
131 if (!succeeded) { 131 if (!succeeded) {
132 LOG_F(LS_WARNING) << "Switching to the fallback screen capturer."; 132 LOG_F(LS_WARNING) << "Switching to the fallback screen capturer.";
133 StartFallbackCapturer(); 133 StartFallbackCapturer();
134 fallback_capturer_->Capture(region); 134 fallback_capturer_->Capture(region);
135 return; 135 return;
136 } 136 }
137 137
138 const DesktopFrame* current_frame = queue_.current_frame(); 138 const DesktopFrame* current_frame = queue_.current();
139 const DesktopFrame* last_frame = queue_.previous_frame(); 139 const DesktopFrame* last_frame = queue_.previous();
140 if (last_frame && last_frame->size().equals(current_frame->size())) { 140 if (last_frame && last_frame->size().equals(current_frame->size())) {
141 // Make sure the differencer is set up correctly for these previous and 141 // Make sure the differencer is set up correctly for these previous and
142 // current screens. 142 // current screens.
143 if (!differ_.get() || (differ_->width() != current_frame->size().width()) || 143 if (!differ_.get() || (differ_->width() != current_frame->size().width()) ||
144 (differ_->height() != current_frame->size().height()) || 144 (differ_->height() != current_frame->size().height()) ||
145 (differ_->bytes_per_row() != current_frame->stride())) { 145 (differ_->bytes_per_row() != current_frame->stride())) {
146 differ_.reset(new Differ(current_frame->size().width(), 146 differ_.reset(new Differ(current_frame->size().width(),
147 current_frame->size().height(), 147 current_frame->size().height(),
148 DesktopFrame::kBytesPerPixel, 148 DesktopFrame::kBytesPerPixel,
149 current_frame->stride())); 149 current_frame->stride()));
150 } 150 }
151 151
152 // Calculate difference between the two last captured frames. 152 // Calculate difference between the two last captured frames.
153 DesktopRegion region; 153 DesktopRegion region;
154 differ_->CalcDirtyRegion( 154 differ_->CalcDirtyRegion(
155 last_frame->data(), current_frame->data(), &region); 155 last_frame->data(), current_frame->data(), &region);
156 helper_.InvalidateRegion(region); 156 helper_.InvalidateRegion(region);
157 } else { 157 } else {
158 // No previous frame is available, or the screen is resized. Invalidate the 158 // No previous frame is available, or the screen is resized. Invalidate the
159 // whole screen. 159 // whole screen.
160 helper_.InvalidateScreen(current_frame->size()); 160 helper_.InvalidateScreen(current_frame->size());
161 } 161 }
162 162
163 helper_.set_size_most_recent(current_frame->size()); 163 helper_.set_size_most_recent(current_frame->size());
164 164
165 // Emit the current frame. 165 // Emit the current frame.
166 DesktopFrame* frame = queue_.current_frame()->Share(); 166 DesktopFrame* frame = queue_.current()->Share();
167 frame->set_dpi(DesktopVector(GetDeviceCaps(desktop_dc_, LOGPIXELSX), 167 frame->set_dpi(DesktopVector(GetDeviceCaps(desktop_dc_, LOGPIXELSX),
168 GetDeviceCaps(desktop_dc_, LOGPIXELSY))); 168 GetDeviceCaps(desktop_dc_, LOGPIXELSY)));
169 frame->mutable_updated_region()->Clear(); 169 frame->mutable_updated_region()->Clear();
170 helper_.TakeInvalidRegion(frame->mutable_updated_region()); 170 helper_.TakeInvalidRegion(frame->mutable_updated_region());
171 frame->set_capture_time_ms( 171 frame->set_capture_time_ms(
172 (TickTime::Now() - capture_start_time).Milliseconds()); 172 (TickTime::Now() - capture_start_time).Milliseconds());
173 callback_->OnCaptureCompleted(frame); 173 callback_->OnCaptureCompleted(frame);
174 } 174 }
175 175
176 bool ScreenCapturerWinMagnifier::GetScreenList(ScreenList* screens) { 176 bool ScreenCapturerWinMagnifier::GetScreenList(ScreenList* screens) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 386
387 assert(tls_index_.Value() != static_cast<int32_t>(TLS_OUT_OF_INDEXES)); 387 assert(tls_index_.Value() != static_cast<int32_t>(TLS_OUT_OF_INDEXES));
388 TlsSetValue(tls_index_.Value(), this); 388 TlsSetValue(tls_index_.Value(), this);
389 389
390 magnifier_initialized_ = true; 390 magnifier_initialized_ = true;
391 return true; 391 return true;
392 } 392 }
393 393
394 void ScreenCapturerWinMagnifier::OnCaptured(void* data, 394 void ScreenCapturerWinMagnifier::OnCaptured(void* data,
395 const MAGIMAGEHEADER& header) { 395 const MAGIMAGEHEADER& header) {
396 DesktopFrame* current_frame = queue_.current_frame(); 396 DesktopFrame* current_frame = queue_.current();
397 397
398 // Verify the format. 398 // Verify the format.
399 // TODO(jiayl): support capturing sources with pixel formats other than RGBA. 399 // TODO(jiayl): support capturing sources with pixel formats other than RGBA.
400 int captured_bytes_per_pixel = header.cbSize / header.width / header.height; 400 int captured_bytes_per_pixel = header.cbSize / header.width / header.height;
401 if (header.format != GUID_WICPixelFormat32bppRGBA || 401 if (header.format != GUID_WICPixelFormat32bppRGBA ||
402 header.width != static_cast<UINT>(current_frame->size().width()) || 402 header.width != static_cast<UINT>(current_frame->size().width()) ||
403 header.height != static_cast<UINT>(current_frame->size().height()) || 403 header.height != static_cast<UINT>(current_frame->size().height()) ||
404 header.stride != static_cast<UINT>(current_frame->stride()) || 404 header.stride != static_cast<UINT>(current_frame->stride()) ||
405 captured_bytes_per_pixel != DesktopFrame::kBytesPerPixel) { 405 captured_bytes_per_pixel != DesktopFrame::kBytesPerPixel) {
406 LOG_F(LS_WARNING) << "Output format does not match the captured format: " 406 LOG_F(LS_WARNING) << "Output format does not match the captured format: "
(...skipping 13 matching lines...) Expand all
420 DesktopRect::MakeXYWH(0, 0, header.width, header.height)); 420 DesktopRect::MakeXYWH(0, 0, header.width, header.height));
421 421
422 magnifier_capture_succeeded_ = true; 422 magnifier_capture_succeeded_ = true;
423 } 423 }
424 424
425 void ScreenCapturerWinMagnifier::CreateCurrentFrameIfNecessary( 425 void ScreenCapturerWinMagnifier::CreateCurrentFrameIfNecessary(
426 const DesktopSize& size) { 426 const DesktopSize& size) {
427 // If the current buffer is from an older generation then allocate a new one. 427 // If the current buffer is from an older generation then allocate a new one.
428 // Note that we can't reallocate other buffers at this point, since the caller 428 // Note that we can't reallocate other buffers at this point, since the caller
429 // may still be reading from them. 429 // may still be reading from them.
430 if (!queue_.current_frame() || !queue_.current_frame()->size().equals(size)) { 430 if (!queue_.current() || !queue_.current()->size().equals(size)) {
431 std::unique_ptr<DesktopFrame> frame = 431 std::unique_ptr<DesktopFrame> frame =
432 shared_memory_factory_ 432 shared_memory_factory_
433 ? SharedMemoryDesktopFrame::Create(size, 433 ? SharedMemoryDesktopFrame::Create(size,
434 shared_memory_factory_.get()) 434 shared_memory_factory_.get())
435 : std::unique_ptr<DesktopFrame>(new BasicDesktopFrame(size)); 435 : std::unique_ptr<DesktopFrame>(new BasicDesktopFrame(size));
436 queue_.ReplaceCurrentFrame(frame.release()); 436 queue_.ReplaceCurrent(SharedDesktopFrame::Wrap(std::move(frame)));
437 } 437 }
438 } 438 }
439 439
440 void ScreenCapturerWinMagnifier::StartFallbackCapturer() { 440 void ScreenCapturerWinMagnifier::StartFallbackCapturer() {
441 assert(fallback_capturer_); 441 assert(fallback_capturer_);
442 if (!fallback_capturer_started_) { 442 if (!fallback_capturer_started_) {
443 fallback_capturer_started_ = true; 443 fallback_capturer_started_ = true;
444 444
445 fallback_capturer_->Start(callback_); 445 fallback_capturer_->Start(callback_);
446 fallback_capturer_->SelectScreen(current_screen_id_); 446 fallback_capturer_->SelectScreen(current_screen_id_);
447 } 447 }
448 } 448 }
449 449
450 } // namespace webrtc 450 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698