Use C++11 static initialization, replacing Atomic32 CompareExchange.
Bug: webrtc:8270 Change-Id: I328cec46be2a017a518946d19d21c242a067747d Reviewed-on: https://webrtc-review.googlesource.com/14220 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Zijie He <zijiehe@chromium.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20383}
This commit is contained in:
parent
d6314d9fc1
commit
4d9ac5886d
@ -26,6 +26,15 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
DWORD GetTlsIndex() {
|
||||
static const DWORD tls_index = TlsAlloc();
|
||||
RTC_DCHECK(tls_index != TLS_OUT_OF_INDEXES);
|
||||
return tls_index;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// kMagnifierWindowClass has to be "Magnifier" according to the Magnification
|
||||
// API. The other strings can be anything.
|
||||
static LPCTSTR kMagnifierHostClass = L"ScreenCapturerWinMagnifierHost";
|
||||
@ -33,8 +42,6 @@ static LPCTSTR kHostWindowName = L"MagnifierHost";
|
||||
static LPCTSTR kMagnifierWindowClass = L"Magnifier";
|
||||
static LPCTSTR kMagnifierWindowName = L"MagnifierWindow";
|
||||
|
||||
Atomic32 ScreenCapturerWinMagnifier::tls_index_(TLS_OUT_OF_INDEXES);
|
||||
|
||||
ScreenCapturerWinMagnifier::ScreenCapturerWinMagnifier() = default;
|
||||
ScreenCapturerWinMagnifier::~ScreenCapturerWinMagnifier() {
|
||||
// DestroyWindow must be called before MagUninitialize. magnifier_window_ is
|
||||
@ -152,8 +159,7 @@ bool ScreenCapturerWinMagnifier::CaptureImage(const DesktopRect& rect) {
|
||||
|
||||
RECT native_rect = {rect.left(), rect.top(), rect.right(), rect.bottom()};
|
||||
|
||||
RTC_DCHECK(tls_index_.Value() != static_cast<int32_t>(TLS_OUT_OF_INDEXES));
|
||||
TlsSetValue(tls_index_.Value(), this);
|
||||
TlsSetValue(GetTlsIndex(), this);
|
||||
// OnCaptured will be called via OnMagImageScalingCallback and fill in the
|
||||
// frame before set_window_source_func_ returns.
|
||||
result = set_window_source_func_(magnifier_window_, native_rect);
|
||||
@ -177,11 +183,10 @@ BOOL ScreenCapturerWinMagnifier::OnMagImageScalingCallback(
|
||||
RECT unclipped,
|
||||
RECT clipped,
|
||||
HRGN dirty) {
|
||||
RTC_DCHECK(tls_index_.Value() != static_cast<int32_t>(TLS_OUT_OF_INDEXES));
|
||||
ScreenCapturerWinMagnifier* owner =
|
||||
reinterpret_cast<ScreenCapturerWinMagnifier*>(
|
||||
TlsGetValue(tls_index_.Value()));
|
||||
TlsSetValue(tls_index_.Value(), nullptr);
|
||||
TlsGetValue(GetTlsIndex()));
|
||||
TlsSetValue(GetTlsIndex(), nullptr);
|
||||
owner->OnCaptured(srcdata, srcheader);
|
||||
|
||||
return TRUE;
|
||||
@ -309,14 +314,6 @@ bool ScreenCapturerWinMagnifier::InitializeMagnifier() {
|
||||
}
|
||||
}
|
||||
|
||||
if (tls_index_.Value() == static_cast<int32_t>(TLS_OUT_OF_INDEXES)) {
|
||||
// More than one threads may get here at the same time, but only one will
|
||||
// write to tls_index_ using CompareExchange.
|
||||
DWORD new_tls_index = TlsAlloc();
|
||||
if (!tls_index_.CompareExchange(new_tls_index, TLS_OUT_OF_INDEXES))
|
||||
TlsFree(new_tls_index);
|
||||
}
|
||||
|
||||
magnifier_initialized_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
#include "modules/desktop_capture/shared_desktop_frame.h"
|
||||
#include "modules/desktop_capture/win/scoped_thread_desktop.h"
|
||||
#include "rtc_base/constructormagic.h"
|
||||
#include "system_wrappers/include/atomic32.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -99,8 +98,6 @@ class ScreenCapturerWinMagnifier : public DesktopCapturer {
|
||||
// Makes sure the current frame exists and matches |size|.
|
||||
void CreateCurrentFrameIfNecessary(const DesktopSize& size);
|
||||
|
||||
static Atomic32 tls_index_;
|
||||
|
||||
Callback* callback_ = nullptr;
|
||||
std::unique_ptr<SharedMemoryFactory> shared_memory_factory_;
|
||||
ScreenId current_screen_id_ = kFullDesktopScreenId;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user