Bug 1191347 - Explicitly release surfaces on the main thread in TestDecodeToSurface. r=me
authorSeth Fowler <mark.seth.fowler@gmail.com>
Sat, 19 Sep 2015 15:47:36 -0700
changeset 296038 4ef727eb2cce5ea61af11489096576772be0d7b7
parent 296037 a9705e55f06d441594321a2e99c0e8b9c34eeb91
child 296039 6e112d30103e1f13d93f3380d83c50485b30b172
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1191347
milestone43.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 1191347 - Explicitly release surfaces on the main thread in TestDecodeToSurface. r=me
image/test/gtest/TestDecodeToSurface.cpp
--- a/image/test/gtest/TestDecodeToSurface.cpp
+++ b/image/test/gtest/TestDecodeToSurface.cpp
@@ -17,81 +17,87 @@
 #include "mozilla/nsRefPtr.h"
 #include "nsString.h"
 #include "nsThreadUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using namespace mozilla::image;
 
-
 TEST(ImageDecodeToSurface, ImageModuleAvailable)
 {
   // We can run into problems if XPCOM modules get initialized in the wrong
   // order. It's important that this test run first, both as a sanity check and
   // to ensure we get the module initialization order we want.
   nsCOMPtr<imgITools> imgTools =
     do_CreateInstance("@mozilla.org/image/tools;1");
   EXPECT_TRUE(imgTools != nullptr);
 }
 
 class DecodeToSurfaceRunnable : public nsRunnable
 {
 public:
-  DecodeToSurfaceRunnable(nsIInputStream* aInputStream,
+  DecodeToSurfaceRunnable(nsRefPtr<SourceSurface>& aSurface,
+                          nsIInputStream* aInputStream,
                           const ImageTestCase& aTestCase)
-    : mInputStream(aInputStream)
+    : mSurface(aSurface)
+    , mInputStream(aInputStream)
     , mTestCase(aTestCase)
   { }
 
   NS_IMETHOD Run()
   {
     Go();
     return NS_OK;
   }
 
   void Go()
   {
-    nsRefPtr<SourceSurface> surface =
+    mSurface =
       ImageOps::DecodeToSurface(mInputStream,
                                 nsAutoCString(mTestCase.mMimeType),
                                 imgIContainer::DECODE_FLAGS_DEFAULT);
-    ASSERT_TRUE(surface != nullptr);
+    ASSERT_TRUE(mSurface != nullptr);
 
-    EXPECT_EQ(SurfaceType::DATA, surface->GetType());
-    EXPECT_TRUE(surface->GetFormat() == SurfaceFormat::B8G8R8X8 ||
-                surface->GetFormat() == SurfaceFormat::B8G8R8A8);
-    EXPECT_EQ(mTestCase.mSize, surface->GetSize());
+    EXPECT_EQ(SurfaceType::DATA, mSurface->GetType());
+    EXPECT_TRUE(mSurface->GetFormat() == SurfaceFormat::B8G8R8X8 ||
+                mSurface->GetFormat() == SurfaceFormat::B8G8R8A8);
+    EXPECT_EQ(mTestCase.mSize, mSurface->GetSize());
 
-    EXPECT_TRUE(IsSolidColor(surface, BGRAColor::Green(),
+    EXPECT_TRUE(IsSolidColor(mSurface, BGRAColor::Green(),
                              mTestCase.mFlags & TEST_CASE_IS_FUZZY));
   }
 
 private:
+  nsRefPtr<SourceSurface>& mSurface;
   nsCOMPtr<nsIInputStream> mInputStream;
   ImageTestCase mTestCase;
 };
 
 static void
 RunDecodeToSurface(const ImageTestCase& aTestCase)
 {
   nsCOMPtr<nsIInputStream> inputStream = LoadFile(aTestCase.mPath);
   ASSERT_TRUE(inputStream != nullptr);
 
   nsCOMPtr<nsIThread> thread;
   nsresult rv = NS_NewThread(getter_AddRefs(thread), nullptr);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   // We run the DecodeToSurface tests off-main-thread to ensure that
   // DecodeToSurface doesn't require any main-thread-only code.
+  nsRefPtr<SourceSurface> surface;
   nsCOMPtr<nsIRunnable> runnable =
-    new DecodeToSurfaceRunnable(inputStream, aTestCase);
+    new DecodeToSurfaceRunnable(surface, inputStream, aTestCase);
   thread->Dispatch(runnable, nsIThread::DISPATCH_SYNC);
 
   thread->Shutdown();
+
+  // Explicitly release the SourceSurface on the main thread.
+  surface = nullptr;
 }
 
 TEST(ImageDecodeToSurface, PNG) { RunDecodeToSurface(GreenPNGTestCase()); }
 TEST(ImageDecodeToSurface, GIF) { RunDecodeToSurface(GreenGIFTestCase()); }
 TEST(ImageDecodeToSurface, JPG) { RunDecodeToSurface(GreenJPGTestCase()); }
 TEST(ImageDecodeToSurface, BMP) { RunDecodeToSurface(GreenBMPTestCase()); }
 TEST(ImageDecodeToSurface, ICO) { RunDecodeToSurface(GreenICOTestCase()); }