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

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

Issue 2030333003: Revert of Use std::unique_ptr<> to pass frame ownership in DesktopCapturer impls. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 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 21 matching lines...) Expand all
32 // API. The other strings can be anything. 32 // API. The other strings can be anything.
33 static LPCTSTR kMagnifierHostClass = L"ScreenCapturerWinMagnifierHost"; 33 static LPCTSTR kMagnifierHostClass = L"ScreenCapturerWinMagnifierHost";
34 static LPCTSTR kHostWindowName = L"MagnifierHost"; 34 static LPCTSTR kHostWindowName = L"MagnifierHost";
35 static LPCTSTR kMagnifierWindowClass = L"Magnifier"; 35 static LPCTSTR kMagnifierWindowClass = L"Magnifier";
36 static LPCTSTR kMagnifierWindowName = L"MagnifierWindow"; 36 static LPCTSTR kMagnifierWindowName = L"MagnifierWindow";
37 37
38 Atomic32 ScreenCapturerWinMagnifier::tls_index_(TLS_OUT_OF_INDEXES); 38 Atomic32 ScreenCapturerWinMagnifier::tls_index_(TLS_OUT_OF_INDEXES);
39 39
40 ScreenCapturerWinMagnifier::ScreenCapturerWinMagnifier( 40 ScreenCapturerWinMagnifier::ScreenCapturerWinMagnifier(
41 std::unique_ptr<ScreenCapturer> fallback_capturer) 41 std::unique_ptr<ScreenCapturer> fallback_capturer)
42 : fallback_capturer_(std::move(fallback_capturer)) {} 42 : fallback_capturer_(std::move(fallback_capturer)),
43 fallback_capturer_started_(false),
44 callback_(NULL),
45 current_screen_id_(kFullDesktopScreenId),
46 excluded_window_(NULL),
47 set_thread_execution_state_failed_(false),
48 desktop_dc_(NULL),
49 mag_lib_handle_(NULL),
50 mag_initialize_func_(NULL),
51 mag_uninitialize_func_(NULL),
52 set_window_source_func_(NULL),
53 set_window_filter_list_func_(NULL),
54 set_image_scaling_callback_func_(NULL),
55 host_window_(NULL),
56 magnifier_window_(NULL),
57 magnifier_initialized_(false),
58 magnifier_capture_succeeded_(true) {}
43 59
44 ScreenCapturerWinMagnifier::~ScreenCapturerWinMagnifier() { 60 ScreenCapturerWinMagnifier::~ScreenCapturerWinMagnifier() {
45 // DestroyWindow must be called before MagUninitialize. magnifier_window_ is 61 // DestroyWindow must be called before MagUninitialize. magnifier_window_ is
46 // destroyed automatically when host_window_ is destroyed. 62 // destroyed automatically when host_window_ is destroyed.
47 if (host_window_) 63 if (host_window_)
48 DestroyWindow(host_window_); 64 DestroyWindow(host_window_);
49 65
50 if (magnifier_initialized_) 66 if (magnifier_initialized_)
51 mag_uninitialize_func_(); 67 mag_uninitialize_func_();
52 68
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 helper_.InvalidateRegion(region); 155 helper_.InvalidateRegion(region);
140 } else { 156 } else {
141 // No previous frame is available, or the screen is resized. Invalidate the 157 // No previous frame is available, or the screen is resized. Invalidate the
142 // whole screen. 158 // whole screen.
143 helper_.InvalidateScreen(current_frame->size()); 159 helper_.InvalidateScreen(current_frame->size());
144 } 160 }
145 161
146 helper_.set_size_most_recent(current_frame->size()); 162 helper_.set_size_most_recent(current_frame->size());
147 163
148 // Emit the current frame. 164 // Emit the current frame.
149 std::unique_ptr<DesktopFrame> frame = queue_.current_frame()->Share(); 165 DesktopFrame* frame = queue_.current_frame()->Share();
150 frame->set_dpi(DesktopVector(GetDeviceCaps(desktop_dc_, LOGPIXELSX), 166 frame->set_dpi(DesktopVector(GetDeviceCaps(desktop_dc_, LOGPIXELSX),
151 GetDeviceCaps(desktop_dc_, LOGPIXELSY))); 167 GetDeviceCaps(desktop_dc_, LOGPIXELSY)));
152 frame->mutable_updated_region()->Clear(); 168 frame->mutable_updated_region()->Clear();
153 helper_.TakeInvalidRegion(frame->mutable_updated_region()); 169 helper_.TakeInvalidRegion(frame->mutable_updated_region());
154 frame->set_capture_time_ms((rtc::TimeNanos() - capture_start_time_nanos) / 170 frame->set_capture_time_ms(
155 rtc::kNumNanosecsPerMillisec); 171 (rtc::TimeNanos() - capture_start_time_nanos) /
156 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); 172 rtc::kNumNanosecsPerMillisec);
173 callback_->OnCaptureCompleted(frame);
157 } 174 }
158 175
159 bool ScreenCapturerWinMagnifier::GetScreenList(ScreenList* screens) { 176 bool ScreenCapturerWinMagnifier::GetScreenList(ScreenList* screens) {
160 return webrtc::GetScreenList(screens); 177 return webrtc::GetScreenList(screens);
161 } 178 }
162 179
163 bool ScreenCapturerWinMagnifier::SelectScreen(ScreenId id) { 180 bool ScreenCapturerWinMagnifier::SelectScreen(ScreenId id) {
164 bool valid = IsScreenValid(id, &current_device_key_); 181 bool valid = IsScreenValid(id, &current_device_key_);
165 182
166 // Set current_screen_id_ even if the fallback capturer is being used, so we 183 // Set current_screen_id_ even if the fallback capturer is being used, so we
(...skipping 13 matching lines...) Expand all
180 set_window_filter_list_func_( 197 set_window_filter_list_func_(
181 magnifier_window_, MW_FILTERMODE_EXCLUDE, 1, &excluded_window_); 198 magnifier_window_, MW_FILTERMODE_EXCLUDE, 1, &excluded_window_);
182 } 199 }
183 } 200 }
184 201
185 bool ScreenCapturerWinMagnifier::CaptureImage(const DesktopRect& rect) { 202 bool ScreenCapturerWinMagnifier::CaptureImage(const DesktopRect& rect) {
186 assert(magnifier_initialized_); 203 assert(magnifier_initialized_);
187 204
188 // Set the magnifier control to cover the captured rect. The content of the 205 // Set the magnifier control to cover the captured rect. The content of the
189 // magnifier control will be the captured image. 206 // magnifier control will be the captured image.
190 BOOL result = SetWindowPos(magnifier_window_, NULL, rect.left(), rect.top(), 207 BOOL result = SetWindowPos(magnifier_window_,
191 rect.width(), rect.height(), 0); 208 NULL,
209 rect.left(), rect.top(),
210 rect.width(), rect.height(),
211 0);
192 if (!result) { 212 if (!result) {
193 LOG_F(LS_WARNING) << "Failed to call SetWindowPos: " << GetLastError() 213 LOG_F(LS_WARNING) << "Failed to call SetWindowPos: " << GetLastError()
194 << ". Rect = {" << rect.left() << ", " << rect.top() 214 << ". Rect = {" << rect.left() << ", " << rect.top()
195 << ", " << rect.right() << ", " << rect.bottom() << "}"; 215 << ", " << rect.right() << ", " << rect.bottom() << "}";
196 return false; 216 return false;
197 } 217 }
198 218
199 magnifier_capture_succeeded_ = false; 219 magnifier_capture_succeeded_ = false;
200 220
201 RECT native_rect = {rect.left(), rect.top(), rect.right(), rect.bottom()}; 221 RECT native_rect = {rect.left(), rect.top(), rect.right(), rect.bottom()};
(...skipping 28 matching lines...) Expand all
230 TlsGetValue(tls_index_.Value())); 250 TlsGetValue(tls_index_.Value()));
231 251
232 owner->OnCaptured(srcdata, srcheader); 252 owner->OnCaptured(srcdata, srcheader);
233 253
234 return TRUE; 254 return TRUE;
235 } 255 }
236 256
237 bool ScreenCapturerWinMagnifier::InitializeMagnifier() { 257 bool ScreenCapturerWinMagnifier::InitializeMagnifier() {
238 assert(!magnifier_initialized_); 258 assert(!magnifier_initialized_);
239 259
240 desktop_dc_ = GetDC(nullptr); 260 desktop_dc_ = GetDC(NULL);
241 261
242 mag_lib_handle_ = LoadLibrary(L"Magnification.dll"); 262 mag_lib_handle_ = LoadLibrary(L"Magnification.dll");
243 if (!mag_lib_handle_) 263 if (!mag_lib_handle_)
244 return false; 264 return false;
245 265
246 // Initialize Magnification API function pointers. 266 // Initialize Magnification API function pointers.
247 mag_initialize_func_ = reinterpret_cast<MagInitializeFunc>( 267 mag_initialize_func_ = reinterpret_cast<MagInitializeFunc>(
248 GetProcAddress(mag_lib_handle_, "MagInitialize")); 268 GetProcAddress(mag_lib_handle_, "MagInitialize"));
249 mag_uninitialize_func_ = reinterpret_cast<MagUninitializeFunc>( 269 mag_uninitialize_func_ = reinterpret_cast<MagUninitializeFunc>(
250 GetProcAddress(mag_lib_handle_, "MagUninitialize")); 270 GetProcAddress(mag_lib_handle_, "MagUninitialize"));
(...skipping 13 matching lines...) Expand all
264 return false; 284 return false;
265 } 285 }
266 286
267 BOOL result = mag_initialize_func_(); 287 BOOL result = mag_initialize_func_();
268 if (!result) { 288 if (!result) {
269 LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: " 289 LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: "
270 << "error from MagInitialize " << GetLastError(); 290 << "error from MagInitialize " << GetLastError();
271 return false; 291 return false;
272 } 292 }
273 293
274 HMODULE hInstance = nullptr; 294 HMODULE hInstance = NULL;
275 result = GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | 295 result = GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
276 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, 296 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
277 reinterpret_cast<char*>(&DefWindowProc), 297 reinterpret_cast<char*>(&DefWindowProc),
278 &hInstance); 298 &hInstance);
279 if (!result) { 299 if (!result) {
280 mag_uninitialize_func_(); 300 mag_uninitialize_func_();
281 LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: " 301 LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: "
282 << "error from GetModulehandleExA " << GetLastError(); 302 << "error from GetModulehandleExA " << GetLastError();
283 return false; 303 return false;
284 } 304 }
285 305
286 // Register the host window class. See the MSDN documentation of the 306 // Register the host window class. See the MSDN documentation of the
287 // Magnification API for more infomation. 307 // Magnification API for more infomation.
288 WNDCLASSEX wcex = {}; 308 WNDCLASSEX wcex = {};
289 wcex.cbSize = sizeof(WNDCLASSEX); 309 wcex.cbSize = sizeof(WNDCLASSEX);
290 wcex.lpfnWndProc = &DefWindowProc; 310 wcex.lpfnWndProc = &DefWindowProc;
291 wcex.hInstance = hInstance; 311 wcex.hInstance = hInstance;
292 wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); 312 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
293 wcex.lpszClassName = kMagnifierHostClass; 313 wcex.lpszClassName = kMagnifierHostClass;
294 314
295 // Ignore the error which may happen when the class is already registered. 315 // Ignore the error which may happen when the class is already registered.
296 RegisterClassEx(&wcex); 316 RegisterClassEx(&wcex);
297 317
298 // Create the host window. 318 // Create the host window.
299 host_window_ = 319 host_window_ = CreateWindowEx(WS_EX_LAYERED,
300 CreateWindowEx(WS_EX_LAYERED, kMagnifierHostClass, kHostWindowName, 0, 0, 320 kMagnifierHostClass,
301 0, 0, 0, nullptr, nullptr, hInstance, nullptr); 321 kHostWindowName,
322 0,
323 0, 0, 0, 0,
324 NULL,
325 NULL,
326 hInstance,
327 NULL);
302 if (!host_window_) { 328 if (!host_window_) {
303 mag_uninitialize_func_(); 329 mag_uninitialize_func_();
304 LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: " 330 LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: "
305 << "error from creating host window " << GetLastError(); 331 << "error from creating host window " << GetLastError();
306 return false; 332 return false;
307 } 333 }
308 334
309 // Create the magnifier control. 335 // Create the magnifier control.
310 magnifier_window_ = CreateWindow(kMagnifierWindowClass, kMagnifierWindowName, 336 magnifier_window_ = CreateWindow(kMagnifierWindowClass,
311 WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, 337 kMagnifierWindowName,
312 host_window_, nullptr, hInstance, nullptr); 338 WS_CHILD | WS_VISIBLE,
339 0, 0, 0, 0,
340 host_window_,
341 NULL,
342 hInstance,
343 NULL);
313 if (!magnifier_window_) { 344 if (!magnifier_window_) {
314 mag_uninitialize_func_(); 345 mag_uninitialize_func_();
315 LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: " 346 LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: "
316 << "error from creating magnifier window " 347 << "error from creating magnifier window "
317 << GetLastError(); 348 << GetLastError();
318 return false; 349 return false;
319 } 350 }
320 351
321 // Hide the host window. 352 // Hide the host window.
322 ShowWindow(host_window_, SW_HIDE); 353 ShowWindow(host_window_, SW_HIDE);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 const DesktopSize& size) { 426 const DesktopSize& size) {
396 // 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.
397 // 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
398 // may still be reading from them. 429 // may still be reading from them.
399 if (!queue_.current_frame() || !queue_.current_frame()->size().equals(size)) { 430 if (!queue_.current_frame() || !queue_.current_frame()->size().equals(size)) {
400 std::unique_ptr<DesktopFrame> frame = 431 std::unique_ptr<DesktopFrame> frame =
401 shared_memory_factory_ 432 shared_memory_factory_
402 ? SharedMemoryDesktopFrame::Create(size, 433 ? SharedMemoryDesktopFrame::Create(size,
403 shared_memory_factory_.get()) 434 shared_memory_factory_.get())
404 : std::unique_ptr<DesktopFrame>(new BasicDesktopFrame(size)); 435 : std::unique_ptr<DesktopFrame>(new BasicDesktopFrame(size));
405 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(std::move(frame))); 436 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(frame.release()));
406 } 437 }
407 } 438 }
408 439
409 void ScreenCapturerWinMagnifier::StartFallbackCapturer() { 440 void ScreenCapturerWinMagnifier::StartFallbackCapturer() {
410 assert(fallback_capturer_); 441 assert(fallback_capturer_);
411 if (!fallback_capturer_started_) { 442 if (!fallback_capturer_started_) {
412 fallback_capturer_started_ = true; 443 fallback_capturer_started_ = true;
413 444
414 fallback_capturer_->Start(callback_); 445 fallback_capturer_->Start(callback_);
415 fallback_capturer_->SelectScreen(current_screen_id_); 446 fallback_capturer_->SelectScreen(current_screen_id_);
416 } 447 }
417 } 448 }
418 449
419 } // namespace webrtc 450 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698