Bug 1060738 - Add IsGUIThread asserts in various webrtc capture related methods. r=jesup a=sylvestre
authorJim Mathies <jmathies@mozilla.com>
Fri, 12 Sep 2014 09:49:39 -0500
changeset 216722 84daded3719c
parent 216721 1355bb2a2765
child 216723 5b7a15b4fee2
push id3890
push userrjesup@wgate.com
push date2014-09-15 14:07 +0000
treeherdermozilla-beta@84daded3719c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, sylvestre
bugs1060738
milestone33.0
Bug 1060738 - Add IsGUIThread asserts in various webrtc capture related methods. r=jesup a=sylvestre
media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_win.cc
media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_win.cc
media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_win.cc
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_win.cc
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_win.cc
@@ -62,24 +62,26 @@ MouseCursorMonitorWin::MouseCursorMonito
 MouseCursorMonitorWin::~MouseCursorMonitorWin() {
   if (desktop_dc_)
     ReleaseDC(NULL, desktop_dc_);
 }
 
 void MouseCursorMonitorWin::Init(Callback* callback, Mode mode) {
   assert(!callback_);
   assert(callback);
+  assert(IsGUIThread(false));
 
   callback_ = callback;
   mode_ = mode;
 
   desktop_dc_ = GetDC(NULL);
 }
 
 void MouseCursorMonitorWin::Capture() {
+  assert(IsGUIThread(false));
   assert(callback_);
 
   CURSORINFO cursor_info;
   cursor_info.cbSize = sizeof(CURSORINFO);
   if (!GetCursorInfo(&cursor_info)) {
     LOG_F(LS_ERROR) << "Unable to get cursor info. Error = " << GetLastError();
     return;
   }
@@ -119,16 +121,17 @@ void MouseCursorMonitorWin::Capture() {
       inside = rect.Contains(position);
     position = position.subtract(rect.top_left());
   }
 
   callback_->OnMouseCursorPosition(inside ? INSIDE : OUTSIDE, position);
 }
 
 DesktopRect MouseCursorMonitorWin::GetScreenRect() {
+  assert(IsGUIThread(false));
   assert(screen_ != kInvalidScreenId);
   if (screen_ == kFullDesktopScreenId) {
     return DesktopRect::MakeXYWH(
         GetSystemMetrics(SM_XVIRTUALSCREEN),
         GetSystemMetrics(SM_YVIRTUALSCREEN),
         GetSystemMetrics(SM_CXVIRTUALSCREEN),
         GetSystemMetrics(SM_CYVIRTUALSCREEN));
   }
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_win.cc
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_win.cc
@@ -148,16 +148,17 @@ ScreenCapturerWin::~ScreenCapturerWin() 
       (*composition_func_)(DWM_EC_ENABLECOMPOSITION);
   }
 
   if (dwmapi_library_)
     FreeLibrary(dwmapi_library_);
 }
 
 void ScreenCapturerWin::Capture(const DesktopRegion& region) {
+  assert(IsGUIThread(false));
   TickTime capture_start_time = TickTime::Now();
 
   queue_.MoveToNextFrame();
 
   // Request that the system not power-down the system, or the display hardware.
   if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) {
     if (!set_thread_execution_state_failed_) {
       set_thread_execution_state_failed_ = true;
@@ -222,16 +223,17 @@ void ScreenCapturerWin::SetMouseShapeObs
       MouseShapeObserver* mouse_shape_observer) {
   assert(!mouse_shape_observer_);
   assert(mouse_shape_observer);
 
   mouse_shape_observer_ = mouse_shape_observer;
 }
 
 bool ScreenCapturerWin::GetScreenList(ScreenList* screens) {
+  assert(IsGUIThread(false));
   assert(screens->size() == 0);
   BOOL enum_result = TRUE;
   for (int device_index = 0; ; ++device_index) {
     DISPLAY_DEVICE device;
     device.cb = sizeof(device);
     enum_result = EnumDisplayDevices(NULL, device_index, &device, 0);
     // |enum_result| is 0 if we have enumerated all devices.
     if (!enum_result)
@@ -243,16 +245,17 @@ bool ScreenCapturerWin::GetScreenList(Sc
     Screen screen;
     screen.id = device_index;
     screens->push_back(screen);
   }
   return true;
 }
 
 bool ScreenCapturerWin::SelectScreen(ScreenId id) {
+  assert(IsGUIThread(false));
   if (id == kFullDesktopScreenId) {
     current_screen_id_ = id;
     return true;
   }
   DISPLAY_DEVICE device;
   device.cb = sizeof(device);
   BOOL enum_result = EnumDisplayDevices(NULL, id, &device, 0);
   if (!enum_result)
@@ -274,16 +277,17 @@ void ScreenCapturerWin::Start(Callback* 
     // will restore Aero automatically if the process exits. This has no effect
     // under Windows 8 or higher.  See crbug.com/124018.
     if (composition_func_)
       (*composition_func_)(DWM_EC_DISABLECOMPOSITION);
   }
 }
 
 void ScreenCapturerWin::PrepareCaptureResources() {
+  assert(IsGUIThread(false));
   // Switch to the desktop receiving user input if different from the current
   // one.
   scoped_ptr<Desktop> input_desktop(Desktop::GetInputDesktop());
   if (input_desktop.get() != NULL && !desktop_.IsSame(*input_desktop)) {
     // Release GDI resources otherwise SetThreadDesktop will fail.
     if (desktop_dc_) {
       ReleaseDC(NULL, desktop_dc_);
       desktop_dc_ = NULL;
@@ -341,16 +345,17 @@ void ScreenCapturerWin::PrepareCaptureRe
     // Make sure the frame buffers will be reallocated.
     queue_.Reset();
 
     helper_.ClearInvalidRegion();
   }
 }
 
 bool ScreenCapturerWin::CaptureImage() {
+  assert(IsGUIThread(false));
   DesktopRect screen_rect = GetScreenRect();
   if (screen_rect.is_empty())
     return false;
   DesktopSize size = screen_rect.size();
   // If the current buffer is from an older generation then allocate a new one.
   // Note that we can't reallocate other buffers at this point, since the caller
   // may still be reading from them.
   if (!queue_.current_frame() ||
@@ -394,16 +399,17 @@ bool ScreenCapturerWin::CaptureImage() {
     // Select back the previously selected object to that the device contect
     // could be destroyed independently of the bitmap if needed.
     SelectObject(memory_dc_, previous_object);
   }
   return true;
 }
 
 void ScreenCapturerWin::CaptureCursor() {
+  assert(IsGUIThread(false));
   CURSORINFO cursor_info;
   cursor_info.cbSize = sizeof(CURSORINFO);
   if (!GetCursorInfo(&cursor_info)) {
     LOG_F(LS_ERROR) << "Unable to get cursor info. Error = " << GetLastError();
     return;
   }
 
   // Note that |cursor_info.hCursor| does not need to be freed.
@@ -437,16 +443,17 @@ void ScreenCapturerWin::CaptureCursor() 
   // Record the last cursor image that we sent to the client.
   last_cursor_ = *cursor;
 
   if (mouse_shape_observer_)
     mouse_shape_observer_->OnCursorShapeChanged(cursor.release());
 }
 
 DesktopRect ScreenCapturerWin::GetScreenRect() {
+  assert(IsGUIThread(false));
   DesktopRect rect = desktop_dc_rect_;
   if (current_screen_id_ == kFullDesktopScreenId)
     return rect;
 
   DISPLAY_DEVICE device;
   device.cb = sizeof(device);
   BOOL result = EnumDisplayDevices(NULL, current_screen_id_, &device, 0);
   if (!result)
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_win.cc
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_win.cc
@@ -35,16 +35,17 @@ std::string Utf16ToUtf8(const WCHAR* str
                                &*(result.begin()), len_utf8, NULL, NULL);
   if (rv != len_utf8)
     assert(false);
 
   return result;
 }
 
 BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
+  assert(IsGUIThread(false));
   WindowCapturer::WindowList* list =
       reinterpret_cast<WindowCapturer::WindowList*>(param);
 
   // Skip windows that are invisible, minimized, have no title, or are owned,
   // unless they have the app window style set.
   int len = GetWindowTextLength(hwnd);
   HWND owner = GetWindow(hwnd, GW_OWNER);
   LONG exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
@@ -136,34 +137,37 @@ WindowCapturerWin::~WindowCapturerWin() 
 bool WindowCapturerWin::IsAeroEnabled() {
   BOOL result = FALSE;
   if (is_composition_enabled_func_)
     is_composition_enabled_func_(&result);
   return result != FALSE;
 }
 
 bool WindowCapturerWin::GetWindowList(WindowList* windows) {
+  assert(IsGUIThread(false));
   WindowList result;
   LPARAM param = reinterpret_cast<LPARAM>(&result);
   if (!EnumWindows(&WindowsEnumerationHandler, param))
     return false;
   windows->swap(result);
   return true;
 }
 
 bool WindowCapturerWin::SelectWindow(WindowId id) {
+  assert(IsGUIThread(false));
   HWND window = reinterpret_cast<HWND>(id);
   if (!IsWindow(window) || !IsWindowVisible(window) || IsIconic(window))
     return false;
   window_ = window;
   previous_size_.set(0, 0);
   return true;
 }
 
 bool WindowCapturerWin::BringSelectedWindowToFront() {
+  assert(IsGUIThread(false));
   if (!window_)
     return false;
 
   if (!IsWindow(window_) || !IsWindowVisible(window_) || IsIconic(window_))
     return false;
 
   return SetForegroundWindow(window_) != 0;
 }
@@ -171,16 +175,17 @@ bool WindowCapturerWin::BringSelectedWin
 void WindowCapturerWin::Start(Callback* callback) {
   assert(!callback_);
   assert(callback);
 
   callback_ = callback;
 }
 
 void WindowCapturerWin::Capture(const DesktopRegion& region) {
+  assert(IsGUIThread(false));
   if (!window_) {
     LOG(LS_ERROR) << "Window hasn't been selected: " << GetLastError();
     callback_->OnCaptureCompleted(NULL);
     return;
   }
 
   // Stop capturing if the window has been minimized or hidden.
   if (IsIconic(window_) || !IsWindowVisible(window_)) {