Bug 755084 Part 3: Move checks for whether to animate opacity and transforms on the compositor thread to nsLayoutUtils, and make them also check whether the compositor is actually running r=cjones,dbaron
authorDavid Zbarsky <dzbarsky@gmail.com>
Fri, 27 Jul 2012 13:23:45 -0700
changeset 100769 908eb2e268434808d19e4c2192a181c8af9a83e5
parent 100768 2194a2dd66b23aa0c931ac130959d1d1939a6041
child 100770 a76e0a267f2673952a0e50952a56bac8aaaffbad
push id12651
push userdzbarsky@gmail.com
push dateFri, 27 Jul 2012 20:23:57 +0000
treeherdermozilla-inbound@a76e0a267f26 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones, dbaron
bugs755084
milestone17.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 755084 Part 3: Move checks for whether to animate opacity and transforms on the compositor thread to nsLayoutUtils, and make them also check whether the compositor is actually running r=cjones,dbaron
gfx/layers/Makefile.in
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/style/AnimationCommon.cpp
layout/style/nsAnimationManager.h
--- a/gfx/layers/Makefile.in
+++ b/gfx/layers/Makefile.in
@@ -26,26 +26,28 @@ DEFINES += -DIMPL_THEBES
 ifdef MOZ_DEBUG
 DEFINES += -DD3D_DEBUG_INFO
 endif
 
 EXPORTS = \
         BasicLayers.h \
         BasicTiledThebesLayer.h \
         BasicImplData.h \
+        CompositorParent.h \
         ImageLayers.h \
         Layers.h \
         LayersBackend.h \
         LayerManagerOGLShaders.h \
         LayerManagerOGL.h \
         LayerManagerOGLProgram.h \
+        LayerSorter.h \
         ReadbackLayer.h \
-        LayerSorter.h \
+        ShadowLayersManager.h \
+        SharedTextureImage.h \
         TexturePoolOGL.h \
-        SharedTextureImage.h \
         $(NULL)
 
 CPPSRCS = \
         BasicImages.cpp \
         BasicLayerManager.cpp \
         BasicCanvasLayer.cpp \
         BasicColorLayer.cpp \
         BasicContainerLayer.cpp \
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 sw=2 et tw=78: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "base/basictypes.h"
 #include "mozilla/Util.h"
 
 #include "nsLayoutUtils.h"
 #include "nsIFormControlFrame.h"
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMHTMLElement.h"
@@ -65,17 +66,17 @@
 #include "mozilla/dom/Element.h"
 #include "nsCanvasFrame.h"
 #include "gfxDrawable.h"
 #include "gfxUtils.h"
 #include "nsDataHashtable.h"
 #include "nsTextFrame.h"
 #include "nsFontFaceList.h"
 #include "nsFontInflationData.h"
-
+#include "CompositorParent.h"
 #include "nsSVGUtils.h"
 #include "nsSVGIntegrationUtils.h"
 #include "nsSVGForeignObjectFrame.h"
 #include "nsSVGOuterSVGFrame.h"
 
 #include "mozilla/Preferences.h"
 
 #ifdef MOZ_XUL
@@ -145,24 +146,54 @@ nsLayoutUtils::HasAnimationsForComposito
 bool
 nsLayoutUtils::Are3DTransformsEnabled()
 {
   static bool s3DTransformsEnabled;
   static bool s3DTransformPrefCached = false;
 
   if (!s3DTransformPrefCached) {
     s3DTransformPrefCached = true;
-    mozilla::Preferences::AddBoolVarCache(&s3DTransformsEnabled, 
+    mozilla::Preferences::AddBoolVarCache(&s3DTransformsEnabled,
                                           "layout.3d-transforms.enabled");
   }
 
   return s3DTransformsEnabled;
 }
 
 bool
+nsLayoutUtils::AreOpacityAnimationsEnabled()
+{
+  static bool sAreOpacityAnimationsEnabled;
+  static bool sOpacityPrefCached = false;
+
+  if (!sOpacityPrefCached) {
+    sOpacityPrefCached = true;
+    Preferences::AddBoolVarCache(&sAreOpacityAnimationsEnabled,
+                                 "layers.offmainthreadcomposition.animate-opacity");
+  }
+
+  return sAreOpacityAnimationsEnabled && CompositorParent::CompositorLoop();
+}
+
+bool
+nsLayoutUtils::AreTransformAnimationsEnabled()
+{
+  static bool sAreTransformAnimationsEnabled;
+  static bool sTransformPrefCached = false;
+
+  if (!sTransformPrefCached) {
+    sTransformPrefCached = true;
+    Preferences::AddBoolVarCache(&sAreTransformAnimationsEnabled,
+                                 "layers.offmainthreadcomposition.animate-transform");
+  }
+
+  return sAreTransformAnimationsEnabled && CompositorParent::CompositorLoop();
+}
+
+bool
 nsLayoutUtils::UseBackgroundNearestFiltering()
 {
   static bool sUseBackgroundNearestFilteringEnabled;
   static bool sUseBackgroundNearestFilteringPrefInitialised = false;
 
   if (!sUseBackgroundNearestFilteringPrefInitialised) {
     sUseBackgroundNearestFilteringPrefInitialised = true;
     sUseBackgroundNearestFilteringEnabled = mozilla::Preferences::GetBool("gfx.filter.nearest.force-enabled", false);
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -1505,16 +1505,22 @@ public:
                                          nsCSSProperty aProperty);
 
   /**
    * Checks if CSS 3D transforms are currently enabled.
    */
   static bool Are3DTransformsEnabled();
 
   /**
+   * Checks if off-main-thread transform and opacity animations are enabled.
+   */
+  static bool AreOpacityAnimationsEnabled();
+  static bool AreTransformAnimationsEnabled();
+
+  /**
    * Checks if we should forcibly use nearest pixel filtering for the
    * background.
    */
   static bool UseBackgroundNearestFiltering();
 
   /**
    * Checks whether we want to use the GPU to scale images when
    * possible.
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AnimationCommon.h"
 #include "nsRuleData.h"
 #include "nsCSSValue.h"
 #include "nsStyleContext.h"
 #include "nsIFrame.h"
 #include "nsAnimationManager.h"
+#include "nsLayoutUtils.h"
 
 namespace mozilla {
 namespace css {
 
 CommonAnimationManager::CommonAnimationManager(nsPresContext *aPresContext)
   : mPresContext(aPresContext)
 {
   PR_INIT_CLIST(&mElementData);
@@ -36,17 +37,17 @@ CommonAnimationManager::Disconnect()
 void
 CommonAnimationManager::AddElementData(CommonElementAnimationData* aData)
 {
   if (PR_CLIST_IS_EMPTY(&mElementData)) {
     // We need to observe the refresh driver.
     nsRefreshDriver *rd = mPresContext->RefreshDriver();
     rd->AddRefreshObserver(this, Flush_Style);
   }
-    
+
   PR_INSERT_BEFORE(aData, &mElementData);
 }
 
 void
 CommonAnimationManager::ElementDataRemoved()
 {
   // If we have no transitions or animations left, remove ourselves from
   // the refresh driver.
@@ -216,25 +217,25 @@ ComputedTimingFunction::GetValue(double 
 }
 
 bool
 CommonElementAnimationData::CanAnimatePropertyOnCompositor(const dom::Element *aElement,
                                                            nsCSSProperty aProperty)
 {
   nsIFrame* frame = aElement->GetPrimaryFrame();
   if (aProperty == eCSSProperty_opacity) {
-    return nsAnimationManager::CanAnimateOpacity();
+    return nsLayoutUtils::AreOpacityAnimationsEnabled();
   }
   if (aProperty == eCSSProperty_transform && !(frame &&
       frame->Preserves3D() &&
       frame->Preserves3DChildren())) {
     if (frame && frame->IsSVGTransformed()) {
       return false;
     }
-    return nsAnimationManager::CanAnimateTransform();
+    return nsLayoutUtils::AreTransformAnimationsEnabled();
   }
   return false;
 }
 
 
 
 }
 }
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -177,30 +177,16 @@ class nsAnimationManager : public mozill
 public:
   nsAnimationManager(nsPresContext *aPresContext)
     : mozilla::css::CommonAnimationManager(aPresContext)
     , mKeyframesListIsDirty(true)
   {
     mKeyframesRules.Init(16); // FIXME: make infallible!
   }
 
-  static bool CanAnimateOpacity() {
-    static bool canAnimateOpacity =
-      mozilla::Preferences::GetBool("layers.offmainthreadcomposition.animate-opacity", false) &&
-      mozilla::Preferences::GetBool("layers.offmainthreadcomposition.enabled", false);
-    return canAnimateOpacity;
-  }
-
-  static bool CanAnimateTransform() {
-    static bool canAnimateTransform =
-      mozilla::Preferences::GetBool("layers.offmainthreadcomposition.animate-transform", false) &&
-      mozilla::Preferences::GetBool("layers.offmainthreadcomposition.enabled", false);
-    return canAnimateTransform;
-  }
-
   static ElementAnimations* GetAnimationsForCompositor(nsIContent* aContent,
                                                        nsCSSProperty aProperty)
   {
     if (!aContent->MayHaveAnimations())
       return nsnull;
     ElementAnimations* animations = static_cast<ElementAnimations*>(
       aContent->GetProperty(nsGkAtoms::animationsProperty));
     if (!animations)