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

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

Issue 1347793005: Replace Atomic32 with webrtc/base/atomicops.h. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: fix typo Created 5 years, 2 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
11 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h" 11 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 14
15 #include "webrtc/base/atomicops.h"
15 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" 16 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
16 #include "webrtc/modules/desktop_capture/desktop_frame.h" 17 #include "webrtc/modules/desktop_capture/desktop_frame.h"
17 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" 18 #include "webrtc/modules/desktop_capture/desktop_frame_win.h"
18 #include "webrtc/modules/desktop_capture/desktop_region.h" 19 #include "webrtc/modules/desktop_capture/desktop_region.h"
19 #include "webrtc/modules/desktop_capture/differ.h" 20 #include "webrtc/modules/desktop_capture/differ.h"
20 #include "webrtc/modules/desktop_capture/mouse_cursor.h" 21 #include "webrtc/modules/desktop_capture/mouse_cursor.h"
21 #include "webrtc/modules/desktop_capture/win/cursor.h" 22 #include "webrtc/modules/desktop_capture/win/cursor.h"
22 #include "webrtc/modules/desktop_capture/win/desktop.h" 23 #include "webrtc/modules/desktop_capture/win/desktop.h"
23 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" 24 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h"
24 #include "webrtc/system_wrappers/interface/logging.h" 25 #include "webrtc/system_wrappers/interface/logging.h"
25 #include "webrtc/system_wrappers/interface/tick_util.h" 26 #include "webrtc/system_wrappers/interface/tick_util.h"
26 27
27 namespace webrtc { 28 namespace webrtc {
28 29
29 // kMagnifierWindowClass has to be "Magnifier" according to the Magnification 30 // kMagnifierWindowClass has to be "Magnifier" according to the Magnification
30 // API. The other strings can be anything. 31 // API. The other strings can be anything.
31 static LPCTSTR kMagnifierHostClass = L"ScreenCapturerWinMagnifierHost"; 32 static LPCTSTR kMagnifierHostClass = L"ScreenCapturerWinMagnifierHost";
32 static LPCTSTR kHostWindowName = L"MagnifierHost"; 33 static LPCTSTR kHostWindowName = L"MagnifierHost";
33 static LPCTSTR kMagnifierWindowClass = L"Magnifier"; 34 static LPCTSTR kMagnifierWindowClass = L"Magnifier";
34 static LPCTSTR kMagnifierWindowName = L"MagnifierWindow"; 35 static LPCTSTR kMagnifierWindowName = L"MagnifierWindow";
35 36
36 Atomic32 ScreenCapturerWinMagnifier::tls_index_(TLS_OUT_OF_INDEXES); 37 volatile int ScreenCapturerWinMagnifier::tls_index_(TLS_OUT_OF_INDEXES);
37 38
38 ScreenCapturerWinMagnifier::ScreenCapturerWinMagnifier( 39 ScreenCapturerWinMagnifier::ScreenCapturerWinMagnifier(
39 rtc::scoped_ptr<ScreenCapturer> fallback_capturer) 40 rtc::scoped_ptr<ScreenCapturer> fallback_capturer)
40 : fallback_capturer_(fallback_capturer.Pass()), 41 : fallback_capturer_(fallback_capturer.Pass()),
41 fallback_capturer_started_(false), 42 fallback_capturer_started_(false),
42 callback_(NULL), 43 callback_(NULL),
43 current_screen_id_(kFullDesktopScreenId), 44 current_screen_id_(kFullDesktopScreenId),
44 excluded_window_(NULL), 45 excluded_window_(NULL),
45 set_thread_execution_state_failed_(false), 46 set_thread_execution_state_failed_(false),
46 desktop_dc_(NULL), 47 desktop_dc_(NULL),
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 230
230 BOOL ScreenCapturerWinMagnifier::OnMagImageScalingCallback( 231 BOOL ScreenCapturerWinMagnifier::OnMagImageScalingCallback(
231 HWND hwnd, 232 HWND hwnd,
232 void* srcdata, 233 void* srcdata,
233 MAGIMAGEHEADER srcheader, 234 MAGIMAGEHEADER srcheader,
234 void* destdata, 235 void* destdata,
235 MAGIMAGEHEADER destheader, 236 MAGIMAGEHEADER destheader,
236 RECT unclipped, 237 RECT unclipped,
237 RECT clipped, 238 RECT clipped,
238 HRGN dirty) { 239 HRGN dirty) {
239 assert(tls_index_.Value() != TLS_OUT_OF_INDEXES); 240 assert(rtc::AtomicOps::AcquireLoad(&tls_index_) != TLS_OUT_OF_INDEXES);
240 241
241 ScreenCapturerWinMagnifier* owner = 242 ScreenCapturerWinMagnifier* owner =
242 reinterpret_cast<ScreenCapturerWinMagnifier*>( 243 reinterpret_cast<ScreenCapturerWinMagnifier*>(
243 TlsGetValue(tls_index_.Value())); 244 TlsGetValue(rtc::AtomicOps::AcquireLoad(&tls_index_)));
244 245
245 owner->OnCaptured(srcdata, srcheader); 246 owner->OnCaptured(srcdata, srcheader);
246 247
247 return TRUE; 248 return TRUE;
248 } 249 }
249 250
250 bool ScreenCapturerWinMagnifier::InitializeMagnifier() { 251 bool ScreenCapturerWinMagnifier::InitializeMagnifier() {
251 assert(!magnifier_initialized_); 252 assert(!magnifier_initialized_);
252 253
253 desktop_dc_ = GetDC(NULL); 254 desktop_dc_ = GetDC(NULL);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 magnifier_window_, MW_FILTERMODE_EXCLUDE, 1, &excluded_window_); 363 magnifier_window_, MW_FILTERMODE_EXCLUDE, 1, &excluded_window_);
363 if (!result) { 364 if (!result) {
364 mag_uninitialize_func_(); 365 mag_uninitialize_func_();
365 LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: " 366 LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: "
366 << "error from MagSetWindowFilterList " 367 << "error from MagSetWindowFilterList "
367 << GetLastError(); 368 << GetLastError();
368 return false; 369 return false;
369 } 370 }
370 } 371 }
371 372
372 if (tls_index_.Value() == TLS_OUT_OF_INDEXES) { 373 if (rtc::AtomicOps::AcquireLoad(&tls_index_) == TLS_OUT_OF_INDEXES) {
373 // More than one threads may get here at the same time, but only one will 374 // More than one threads may get here at the same time, but only one will
374 // write to tls_index_ using CompareExchange. 375 // write to tls_index_ using CompareAndSwap.
375 DWORD new_tls_index = TlsAlloc(); 376 DWORD new_tls_index = TlsAlloc();
376 if (!tls_index_.CompareExchange(new_tls_index, TLS_OUT_OF_INDEXES)) 377 if (rtc::AtomicOps::CompareAndSwap(&tls_index_, TLS_OUT_OF_INDEXES,
378 new_tls_index) != TLS_OUT_OF_INDEXES) {
379 // Another thread allocated TLS before us, remove additional allocation.
377 TlsFree(new_tls_index); 380 TlsFree(new_tls_index);
381 }
378 } 382 }
379 383
380 assert(tls_index_.Value() != TLS_OUT_OF_INDEXES); 384 assert(rtc::AtomicOps::AcquireLoad(&tls_index_) != TLS_OUT_OF_INDEXES);
381 TlsSetValue(tls_index_.Value(), this); 385 TlsSetValue(rtc::AtomicOps::AcquireLoad(&tls_index_), this);
382 386
383 magnifier_initialized_ = true; 387 magnifier_initialized_ = true;
384 return true; 388 return true;
385 } 389 }
386 390
387 void ScreenCapturerWinMagnifier::OnCaptured(void* data, 391 void ScreenCapturerWinMagnifier::OnCaptured(void* data,
388 const MAGIMAGEHEADER& header) { 392 const MAGIMAGEHEADER& header) {
389 DesktopFrame* current_frame = queue_.current_frame(); 393 DesktopFrame* current_frame = queue_.current_frame();
390 394
391 // Verify the format. 395 // Verify the format.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 assert(fallback_capturer_); 444 assert(fallback_capturer_);
441 if (!fallback_capturer_started_) { 445 if (!fallback_capturer_started_) {
442 fallback_capturer_started_ = true; 446 fallback_capturer_started_ = true;
443 447
444 fallback_capturer_->Start(callback_); 448 fallback_capturer_->Start(callback_);
445 fallback_capturer_->SelectScreen(current_screen_id_); 449 fallback_capturer_->SelectScreen(current_screen_id_);
446 } 450 }
447 } 451 }
448 452
449 } // namespace webrtc 453 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698