Bug 1340276 - Force wmode=direct for certain Flash objects. r=aklotz
authorJim Mathies <jmathies@mozilla.com>
Thu, 16 Feb 2017 16:13:30 -0600
changeset 372832 9f91a792c4f9fa1323823ca08ad30a862ab83879
parent 372831 4a930acd18f8de343fc8ae6eafcd0b12798ea69c
child 372833 49ac21ebc141fdedd165b36658e3f809437b2576
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1340276
milestone54.0a1
Bug 1340276 - Force wmode=direct for certain Flash objects. r=aklotz MozReview-Commit-ID: 6WsZL99kUc
dom/plugins/ipc/PluginModuleParent.cpp
modules/libpref/init/all.js
--- a/dom/plugins/ipc/PluginModuleParent.cpp
+++ b/dom/plugins/ipc/PluginModuleParent.cpp
@@ -2715,16 +2715,36 @@ ForceWindowless(InfallibleTArray<nsCStri
             values[wmodeAttributeIndex].Assign(opaqueAttributeValue);
         }
     } else {
         names.AppendElement(wmodeAttributeName);
         values.AppendElement(opaqueAttributeValue);
     }
 }
 #endif // windows or linux
+#if defined(XP_WIN)
+static void
+ForceDirect(InfallibleTArray<nsCString>& names,
+            InfallibleTArray<nsCString>& values)
+{
+    nsCaseInsensitiveUTF8StringArrayComparator comparator;
+    NS_NAMED_LITERAL_CSTRING(wmodeAttributeName, "wmode");
+    NS_NAMED_LITERAL_CSTRING(directAttributeValue, "direct");
+    auto wmodeAttributeIndex =
+        names.IndexOf(wmodeAttributeName, 0, comparator);
+    if (wmodeAttributeIndex != names.NoIndex) {
+        if (values[wmodeAttributeIndex].EqualsLiteral("window")) {
+            values[wmodeAttributeIndex].Assign(directAttributeValue);
+        }
+    } else {
+        names.AppendElement(wmodeAttributeName);
+        values.AppendElement(directAttributeValue);
+    }
+}
+#endif // windows
 
 nsresult
 PluginModuleParent::NPP_NewInternal(NPMIMEType pluginType, NPP instance,
                                     uint16_t mode,
                                     InfallibleTArray<nsCString>& names,
                                     InfallibleTArray<nsCString>& values,
                                     NPSavedData* saved, NPError* error)
 {
@@ -2753,16 +2773,18 @@ PluginModuleParent::NPP_NewInternal(NPMI
     PluginInstanceParent* parentInstance =
         new PluginInstanceParent(this, instance, strPluginType, mNPNIface);
 
     if (mIsFlashPlugin) {
         parentInstance->InitMetadata(strPluginType, srcAttribute);
 #ifdef XP_WIN
         bool supportsAsyncRender =
           Preferences::GetBool("dom.ipc.plugins.asyncdrawing.enabled", false);
+        bool supportsForceDirect =
+          Preferences::GetBool("dom.ipc.plugins.forcedirect.enabled", false);
         if (supportsAsyncRender) {
           // Prefs indicates we want async plugin rendering, make sure
           // the flash module has support.
           CallModuleSupportsAsyncRender(&supportsAsyncRender);
         }
 #ifdef _WIN64
         // For 64-bit builds force windowless if the flash library doesn't support
         // async rendering regardless of sandbox level.
@@ -2773,16 +2795,24 @@ PluginModuleParent::NPP_NewInternal(NPMI
         if (!supportsAsyncRender && mSandboxLevel >= 2) {
 #endif
             ForceWindowless(names, values);
         }
 #elif defined(MOZ_WIDGET_GTK)
         // We no longer support windowed mode on Linux.
         ForceWindowless(names, values);
 #endif
+#ifdef XP_WIN
+        // For all builds that use async rendering force use of the accelerated
+        // direct path for flash objects that have wmode=window or no wmode
+        // specified.
+        if (supportsAsyncRender && supportsForceDirect) {
+            ForceDirect(names, values);
+        }
+#endif
     }
 
     // Release the surrogate reference that was in pdata
     RefPtr<PluginAsyncSurrogate> surrogate(
         dont_AddRef(PluginAsyncSurrogate::Cast(instance)));
     // Now replace it with the instance
     instance->pdata = static_cast<PluginDataResolver*>(parentInstance);
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2910,16 +2910,18 @@ pref("dom.ipc.plugins.unloadTimeoutSecs"
 // Asynchronous plugin initialization is on hold.
 pref("dom.ipc.plugins.asyncInit.enabled", false);
 
 #ifdef RELEASE_OR_BETA
 pref("dom.ipc.plugins.asyncdrawing.enabled", false);
 #else
 // Allow the AsyncDrawing mode to be used for plugins in dev channels.
 pref("dom.ipc.plugins.asyncdrawing.enabled", true);
+// Force the accelerated path for a subset of Flash wmode values
+pref("dom.ipc.plugins.forcedirect.enabled", true);
 #endif
 
 #ifdef NIGHTLY_BUILD
 pref("dom.ipc.processCount", 2);
 #else
 pref("dom.ipc.processCount", 1);
 #endif