Bug 1229262 - Fix nsScreenGonk's thread safety r=mwu
authorSotaro Ikeda <sotaro.ikeda.g@gmail.com>
Wed, 02 Dec 2015 22:27:55 -0800
changeset 309538 8af1d3533a713fb4bef7d83a6159a8430dec49b9
parent 309537 fc87f618625311247a70ce97e9cdd61d4a5c1f30
child 309539 dccb1af2b609e003e6dcc9726ea73070eadb30a3
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs1229262
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1229262 - Fix nsScreenGonk's thread safety r=mwu
widget/gonk/nsScreenManagerGonk.cpp
--- a/widget/gonk/nsScreenManagerGonk.cpp
+++ b/widget/gonk/nsScreenManagerGonk.cpp
@@ -27,16 +27,17 @@
 #include "VsyncSource.h"
 #include "nsWindow.h"
 #include "mozilla/layers/CompositorParent.h"
 #include "mozilla/Services.h"
 #include "mozilla/ProcessPriorityManager.h"
 #include "nsIdleService.h"
 #include "nsIObserverService.h"
 #include "nsAppShell.h"
+#include "nsProxyRelease.h"
 #include "nsTArray.h"
 #include "pixelflinger/format.h"
 #include "nsIDisplayInfo.h"
 
 #if ANDROID_VERSION >= 17
 #include "libdisplay/DisplaySurface.h"
 #endif
 
@@ -452,17 +453,17 @@ already_AddRefed<mozilla::gl::GLContext>
 nsScreenGonk::GetGLContext()
 {
     MOZ_ASSERT(CompositorParent::IsInCompositorThread());
     RefPtr<mozilla::gl::GLContext>glContext = mGLContext;
     return glContext.forget();
 }
 
 static void
-UpdateMirroringWidgetSync(RefPtr<nsScreenGonk>&& aScreen, nsWindow* aWindow)
+UpdateMirroringWidgetSync(nsMainThreadPtrHandle<nsScreenGonk>&& aScreen, nsWindow* aWindow)
 {
     MOZ_ASSERT(CompositorParent::IsInCompositorThread());
     already_AddRefed<nsWindow> window(aWindow);
     aScreen->UpdateMirroringWidget(window);
 }
 
 bool
 nsScreenGonk::EnableMirroring()
@@ -479,20 +480,22 @@ nsScreenGonk::EnableMirroring()
     // Create a widget for mirroring
     nsWidgetInitData initData;
     initData.mScreenId = mId;
     RefPtr<nsWindow> window = new nsWindow();
     window->Create(nullptr, nullptr, mNaturalBounds.ToUnknownRect(), &initData);
     MOZ_ASSERT(static_cast<nsWindow*>(window)->GetScreen() == this);
 
     // Update mMirroringWidget on compositor thread
+    nsMainThreadPtrHandle<nsScreenGonk> primary =
+      nsMainThreadPtrHandle<nsScreenGonk>(new nsMainThreadPtrHolder<nsScreenGonk>(primaryScreen, false));
     CompositorParent::CompositorLoop()->PostTask(
         FROM_HERE,
         NewRunnableFunction(&UpdateMirroringWidgetSync,
-                            primaryScreen,
+                            primary,
                             window.forget().take()));
 
     mIsMirroring = true;
     return true;
 }
 
 bool
 nsScreenGonk::DisableMirroring()
@@ -503,20 +506,22 @@ nsScreenGonk::DisableMirroring()
     mIsMirroring = false;
     RefPtr<nsScreenGonk> primaryScreen = nsScreenManagerGonk::GetPrimaryScreen();
     NS_ENSURE_TRUE(primaryScreen, false);
 
     bool ret = primaryScreen->ClearMirroringScreen(this);
     NS_ENSURE_TRUE(ret, false);
 
     // Update mMirroringWidget on compositor thread
+    nsMainThreadPtrHandle<nsScreenGonk> primary =
+      nsMainThreadPtrHandle<nsScreenGonk>(new nsMainThreadPtrHolder<nsScreenGonk>(primaryScreen, false));
     CompositorParent::CompositorLoop()->PostTask(
         FROM_HERE,
         NewRunnableFunction(&UpdateMirroringWidgetSync,
-                            primaryScreen,
+                            primary,
                             nullptr));
     return true;
 }
 
 bool
 nsScreenGonk::SetMirroringScreen(nsScreenGonk* aScreen)
 {
     MOZ_ASSERT(NS_IsMainThread());