Bug 1315554 - Part 10b. Force CMS output profile to be sRGB for gtests. r=me
authorAndrew Osmond <aosmond@mozilla.com>
Sat, 22 Jul 2017 07:50:32 -0400
changeset 419121 6b3ee47d2f8fda2ea668bbf2355eb05724687652
parent 419120 6a5ba604200e8db1efe18d7f637e11a2b0286060
child 419122 c27fa0fef4060d74eb3014d2da4a1139c6ab5ba3
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1315554
milestone56.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 1315554 - Part 10b. Force CMS output profile to be sRGB for gtests. r=me Thus far gtests have only tested fairly simple images which already render the same on all platforms (e.g. solid green 100x100 square). If we want to test more complicated images consistently across platforms, we need to ensure the color adjustments we perform are also consistent. Using the pref gfx.color_management.force_srgb to force an sRGB CMS profile makes us consistent with the reftests and mochitests. However an additional quirk of the gtests is that we own the main thread and we never check our event queue to see if anything is pending. Depending on the initialization order of our graphics dependencies, it may or may not have created pending runnables to process the pref change. As such, we need to change the pref, initialize imagelib/gfx and then check for, and if present execute, any necessary runnables. Only then can we be sure that our desired CMS profile is applied.
image/test/gtest/Common.cpp
image/test/gtest/Common.h
--- a/image/test/gtest/Common.cpp
+++ b/image/test/gtest/Common.cpp
@@ -21,16 +21,51 @@
 namespace mozilla {
 namespace image {
 
 using namespace gfx;
 
 using std::abs;
 using std::vector;
 
+static bool sImageLibInitialized = false;
+
+AutoInitializeImageLib::AutoInitializeImageLib()
+{
+  if (MOZ_LIKELY(sImageLibInitialized)) {
+    return;
+  }
+
+  EXPECT_TRUE(NS_IsMainThread());
+  sImageLibInitialized = true;
+
+  // Force sRGB to be consistent with reftests.
+  Preferences::SetBool("gfx.color_management.force_srgb", true);
+
+  // Ensure that ImageLib services are initialized.
+  nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
+  EXPECT_TRUE(imgTools != nullptr);
+
+  // Ensure gfxPlatform is initialized.
+  gfxPlatform::GetPlatform();
+
+  // Depending on initialization order, it is possible that our pref changes
+  // have not taken effect yet because there are pending gfx-related events on
+  // the main thread.
+  nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
+  EXPECT_TRUE(mainThread != nullptr);
+
+  bool processed;
+  do {
+    processed = false;
+    nsresult rv = mainThread->ProcessNextEvent(false, &processed);
+    EXPECT_TRUE(NS_SUCCEEDED(rv));
+  } while (processed);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // General Helpers
 ///////////////////////////////////////////////////////////////////////////////
 
 // These macros work like gtest's ASSERT_* macros, except that they can be used
 // in functions that return values.
 #define ASSERT_TRUE_OR_RETURN(e, rv) \
   EXPECT_TRUE(e);                    \
--- a/image/test/gtest/Common.h
+++ b/image/test/gtest/Common.h
@@ -102,24 +102,20 @@ struct BGRAColor
 
 /**
  * A RAII class that ensure that ImageLib services are available. Any tests that
  * require ImageLib to be initialized (for example, any test that uses the
  * SurfaceCache; see image::EnsureModuleInitialized() for the full list) can
  * use this class to ensure that ImageLib services are available. Failure to do
  * so can result in strange, non-deterministic failures.
  */
-struct AutoInitializeImageLib
+class AutoInitializeImageLib
 {
-  AutoInitializeImageLib()
-  {
-    // Ensure that ImageLib services are initialized.
-    nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
-    EXPECT_TRUE(imgTools != nullptr);
-  }
+public:
+  AutoInitializeImageLib();
 };
 
 /// Loads a file from the current directory. @return an nsIInputStream for it.
 already_AddRefed<nsIInputStream> LoadFile(const char* aRelativePath);
 
 /**
  * @returns true if every pixel of @aSurface is @aColor.
  *