Bug 1247570 - unbreak widget/gonk/nativewindow/FakeSurfaceComposer.cpp r=gwagner
authorFabrice Desré <fabrice@mozilla.com>
Thu, 11 Feb 2016 14:05:11 -0800
changeset 284039 c46aba18e8d852f3962d6c4c96ec7a962fe6888a
parent 284038 cba7b2666224a9a1d43df9c60adcc51936117f1e
child 284040 acaeaa89ffc186aff44994e3b62568f57b68470f
push id29995
push usercbook@mozilla.com
push dateFri, 12 Feb 2016 14:16:12 +0000
treeherdermozilla-central@218d16a9ddcc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner
bugs1247570
milestone47.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 1247570 - unbreak widget/gonk/nativewindow/FakeSurfaceComposer.cpp r=gwagner
widget/gonk/nativewindow/FakeSurfaceComposer.cpp
--- a/widget/gonk/nativewindow/FakeSurfaceComposer.cpp
+++ b/widget/gonk/nativewindow/FakeSurfaceComposer.cpp
@@ -477,55 +477,56 @@ FakeSurfaceComposer::captureScreenImp(co
                 reqWidth, reqHeight, hw_w, hw_h);
         static_cast<GraphicProducerWrapper*>(producer->asBinder().get())->exit(BAD_VALUE);
         return;
     }
 
     reqWidth  = (!reqWidth)  ? hw_w : reqWidth;
     reqHeight = (!reqHeight) ? hw_h : reqHeight;
 
-    nsScreenGonk* screenPtr = screen.forget().take();
     nsCOMPtr<nsIRunnable> runnable =
-        NS_NewRunnableFunction([screenPtr, reqWidth, reqHeight, producer, wrapper]() {
+        NS_NewRunnableFunction([screen, reqWidth, reqHeight, producer, wrapper]() {
             // create a surface (because we're a producer, and we need to
             // dequeue/queue a buffer)
             sp<Surface> sur = new Surface(producer);
             ANativeWindow* window = sur.get();
+            // The closure makes screen const and we can't call forget() on it.
+            RefPtr<nsScreenGonk> screenAlias = screen;
 
             if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) != NO_ERROR) {
                 static_cast<GraphicProducerWrapper*>(producer->asBinder().get())->exit(BAD_VALUE);
-                NS_ReleaseOnMainThread(screenPtr);
+                NS_ReleaseOnMainThread(screenAlias.forget());
                 return;
             }
             uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
                              GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
 
             int err = 0;
             err = native_window_set_buffers_dimensions(window, reqWidth, reqHeight);
             err |= native_window_set_scaling_mode(window, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
             err |= native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_RGBA_8888);
             err |= native_window_set_usage(window, usage);
 
             status_t result = NO_ERROR;
             if (err == NO_ERROR) {
                 ANativeWindowBuffer* buffer;
                 result = native_window_dequeue_buffer_and_wait(window,  &buffer);
                 if (result == NO_ERROR) {
-                    nsresult rv = screenPtr->MakeSnapshot(buffer);
+                    nsresult rv = screen->MakeSnapshot(buffer);
                     if (rv != NS_OK) {
                         result = INVALID_OPERATION;
                     }
                     window->queueBuffer(window, buffer, -1);
                 }
             } else {
                 result = BAD_VALUE;
             }
             native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
             static_cast<GraphicProducerWrapper*>(producer->asBinder().get())->exit(result);
-            NS_ReleaseOnMainThread(screenPtr);
+            NS_ReleaseOnMainThread(screenAlias.forget());
         });
 
     mozilla::layers::CompositorParent::CompositorLoop()->PostTask(
         FROM_HERE, new RunnableCallTask(runnable));
 }
 
 #if ANDROID_VERSION >= 21
 void