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>
Tue, 31 Jul 2012 10:28:22 -0700
changeset 101012 176d33be7c59f5e8e17dc52f38af94eb932c4d62
parent 101011 8652f9d5ec7d11931953b36a25766cee18dfe99a
child 101013 49dccc4947eacfdc43baf7100f129ae2834ff1d7
push id23206
push userryanvm@gmail.com
push dateWed, 01 Aug 2012 02:11:21 +0000
treeherdermozilla-central@582d4c67b3a7 [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
@@ -27,26 +27,28 @@ ifdef MOZ_DEBUG
 DEFINES += -DD3D_DEBUG_INFO
 endif
 
 EXPORTS = \
         BasicLayers.h \
         BasicTiledThebesLayer.h \
         BasicImplData.h \
         FrameMetrics.h \
+        CompositorParent.h \
         ImageLayers.h \
         Layers.h \
         LayersTypes.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 nullptr;
     ElementAnimations* animations = static_cast<ElementAnimations*>(
       aContent->GetProperty(nsGkAtoms::animationsProperty));
     if (!animations)