Bug 1257369 - Suppress the DisplayPort when scrolling via nsSliderFrame. r=kats
authorBenoit Girard <b56girard@gmail.com>
Fri, 18 Mar 2016 14:46:54 -0400
changeset 289401 8bfe5bd9b1c71f2cb9f4054686684d36391e0a20
parent 289400 a6dca9d0ecdd537f5f0bed34fcb557d787f72f22
child 289402 d0d3f2d377e702022baa964cc58415270b421959
push id73826
push userb56girard@gmail.com
push dateFri, 18 Mar 2016 20:21:25 +0000
treeherdermozilla-inbound@8bfe5bd9b1c7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1257369
milestone48.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 1257369 - Suppress the DisplayPort when scrolling via nsSliderFrame. r=kats MozReview-Commit-ID: 8I3UfWlkdPq
layout/xul/nsSliderFrame.cpp
layout/xul/nsSliderFrame.h
--- a/layout/xul/nsSliderFrame.cpp
+++ b/layout/xul/nsSliderFrame.cpp
@@ -17,39 +17,44 @@
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "nsCOMPtr.h"
 #include "nsNameSpaceManager.h"
 #include "nsGkAtoms.h"
 #include "nsHTMLParts.h"
 #include "nsIPresShell.h"
 #include "nsCSSRendering.h"
+#include "nsIDOMEvent.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsScrollbarButtonFrame.h"
 #include "nsISliderListener.h"
 #include "nsIScrollableFrame.h"
 #include "nsIScrollbarMediator.h"
+#include "nsISupportsImpl.h"
 #include "nsScrollbarFrame.h"
 #include "nsRepeatService.h"
 #include "nsBoxLayoutState.h"
 #include "nsSprocketLayout.h"
 #include "nsIServiceManager.h"
 #include "nsContentUtils.h"
 #include "nsLayoutUtils.h"
 #include "nsDisplayList.h"
+#include "mozilla/Assertions.h"         // for MOZ_ASSERT
 #include "mozilla/Preferences.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Telemetry.h"
+#include "mozilla/layers/APZCCallbackHelper.h"
 #include "mozilla/layers/AsyncDragMetrics.h"
 #include "mozilla/layers/InputAPZContext.h"
 #include "mozilla/layers/ScrollInputMethods.h"
 #include <algorithm>
 
 using namespace mozilla;
+using mozilla::layers::APZCCallbackHelper;
 using mozilla::layers::AsyncDragMetrics;
 using mozilla::layers::InputAPZContext;
 using mozilla::layers::ScrollInputMethod;
 
 bool nsSliderFrame::gMiddlePref = false;
 int32_t nsSliderFrame::gSnapMultiplier;
 
 // Turn this on if you want to debug slider frames.
@@ -75,23 +80,30 @@ NS_QUERYFRAME_HEAD(nsSliderFrame)
 NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
 
 nsSliderFrame::nsSliderFrame(nsStyleContext* aContext):
   nsBoxFrame(aContext),
   mCurPos(0),
   mChange(0),
   mDragFinished(true),
   mUserChanged(false),
-  mScrollingWithAPZ(false)
+  mScrollingWithAPZ(false),
+  mSuppressionActive(false)
 {
 }
 
 // stop timer
 nsSliderFrame::~nsSliderFrame()
 {
+  MOZ_ASSERT(!mSuppressionActive, "Should have un-suppress via StopDrag() first.");
+  if (mSuppressionActive) {
+    APZCCallbackHelper::SuppressDisplayport(false, PresContext() ?
+                                                   PresContext()->PresShell() :
+                                                   nullptr);
+  }
 }
 
 void
 nsSliderFrame::Init(nsIContent*       aContent,
                     nsContainerFrame* aParent,
                     nsIFrame*         aPrevInFlow)
 {
   nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
@@ -1037,27 +1049,39 @@ nsSliderFrame::StartDrag(nsIDOMEvent* aE
   mDragStart = pos - mThumbStart;
 
   mScrollingWithAPZ = StartAPZDrag();
 
 #ifdef DEBUG_SLIDER
   printf("Pressed mDragStart=%d\n",mDragStart);
 #endif
 
+  if (!mScrollingWithAPZ && !mSuppressionActive) {
+    MOZ_ASSERT(PresContext()->PresShell());
+    APZCCallbackHelper::SuppressDisplayport(true, PresContext()->PresShell());
+    mSuppressionActive = true;
+  }
+
   return NS_OK;
 }
 
 nsresult
 nsSliderFrame::StopDrag()
 {
   AddListener();
   DragThumb(false);
 
   mScrollingWithAPZ = false;
 
+  if (mSuppressionActive) {
+    MOZ_ASSERT(PresContext()->PresShell());
+    APZCCallbackHelper::SuppressDisplayport(false, PresContext()->PresShell());
+    mSuppressionActive = false;
+  }
+
 #ifdef MOZ_WIDGET_GTK
   nsIFrame* thumbFrame = mFrames.FirstChild();
   if (thumbFrame) {
     nsCOMPtr<nsIContent> thumb = thumbFrame->GetContent();
     thumb->UnsetAttr(kNameSpaceID_None, nsGkAtoms::active, true);
   }
 #endif
 
--- a/layout/xul/nsSliderFrame.h
+++ b/layout/xul/nsSliderFrame.h
@@ -190,13 +190,17 @@ private:
   bool mUserChanged;
 
   // true if we've handed off the scrolling to APZ. This means that we should
   // ignore scrolling events as the position will be updated by APZ. If we were
   // to process these events then the scroll position update would conflict
   // causing the scroll position to jump.
   bool mScrollingWithAPZ;
 
+  // true if displayport suppression is active, for more performant
+  // scrollbar-dragging behaviour.
+  bool mSuppressionActive;
+
   static bool gMiddlePref;
   static int32_t gSnapMultiplier;
 }; // class nsSliderFrame
 
 #endif