Bug 1496823 - Remove EventThreadRunner and the pref that enabled it. r=kats,spohl
authorMarkus Stange <mstange@themasta.com>
Wed, 17 Oct 2018 20:44:28 +0000
changeset 497582 959084361b1580b3dd586b6e229e21274cc83556
parent 497581 34f52a304c5251541685810ab2fb2e0a508d7508
child 497583 8848453f27af6f3ae1538e9cbadef50bf4e95455
push id9996
push userarchaeopteryx@coole-files.de
push dateThu, 18 Oct 2018 18:37:15 +0000
treeherdermozilla-beta@8efe26839243 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats, spohl
bugs1496823
milestone64.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 1496823 - Remove EventThreadRunner and the pref that enabled it. r=kats,spohl This was an experiment before we had e10s. It's no longer needed. Depends on D7922 Differential Revision: https://phabricator.services.mozilla.com/D7924
gfx/thebes/gfxPrefs.h
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -572,17 +572,16 @@ private:
   DECL_GFX_PREF(Once, "layers.acceleration.disabled",          LayersAccelerationDisabledDoNotUseDirectly, bool, false);
   DECL_GFX_PREF(Live, "layers.acceleration.draw-fps",          LayersDrawFPS, bool, false);
   DECL_GFX_PREF(Live, "layers.acceleration.draw-fps.print-histogram",  FPSPrintHistogram, bool, false);
   DECL_GFX_PREF(Live, "layers.acceleration.draw-fps.write-to-file", WriteFPSToFile, bool, false);
   DECL_GFX_PREF(Once, "layers.acceleration.force-enabled",     LayersAccelerationForceEnabledDoNotUseDirectly, bool, false);
   DECL_GFX_PREF(Live, "layers.advanced.basic-layer.enabled",          LayersAdvancedBasicLayerEnabled, bool, false);
   DECL_GFX_PREF(Once, "layers.amd-switchable-gfx.enabled",     LayersAMDSwitchableGfxEnabled, bool, false);
   DECL_GFX_PREF(Once, "layers.async-pan-zoom.enabled",         AsyncPanZoomEnabledDoNotUseDirectly, bool, true);
-  DECL_GFX_PREF(Once, "layers.async-pan-zoom.separate-event-thread", AsyncPanZoomSeparateEventThread, bool, false);
   DECL_GFX_PREF(Live, "layers.bench.enabled",                  LayersBenchEnabled, bool, false);
   DECL_GFX_PREF(Once, "layers.bufferrotation.enabled",         BufferRotationEnabled, bool, true);
   DECL_GFX_PREF(Live, "layers.child-process-shutdown",         ChildProcessShutdown, bool, true);
 #ifdef MOZ_GFX_OPTIMIZE_MOBILE
   // If MOZ_GFX_OPTIMIZE_MOBILE is defined, we force component alpha off
   // and ignore the preference.
   DECL_GFX_PREF(Skip, "layers.componentalpha.enabled",         ComponentAlphaEnabled, bool, false);
 #else
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -249,17 +249,16 @@ class WidgetRenderingContext;
 - (void)swipeWithEvent:(NSEvent *)anEvent;
 - (void)beginGestureWithEvent:(NSEvent *)anEvent;
 - (void)magnifyWithEvent:(NSEvent *)anEvent;
 - (void)smartMagnifyWithEvent:(NSEvent *)anEvent;
 - (void)rotateWithEvent:(NSEvent *)anEvent;
 - (void)endGestureWithEvent:(NSEvent *)anEvent;
 
 - (void)scrollWheel:(NSEvent *)anEvent;
-- (void)handleAsyncScrollEvent:(CGEventRef)cgEvent ofType:(CGEventType)type;
 
 - (void)setUsingOMTCompositor:(BOOL)aUseOMTC;
 
 - (NSEvent*)lastKeyDownEvent;
 
 + (uint32_t)sUniqueKeyEventId;
 
 + (NSMutableDictionary*)sNativeKeyEventsMap;
@@ -521,18 +520,16 @@ public:
 
   already_AddRefed<mozilla::gfx::DrawTarget>
     StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion,
                                mozilla::layers::BufferMode* aBufferMode) override;
   void EndRemoteDrawing() override;
   void CleanupRemoteDrawing() override;
   bool InitCompositor(mozilla::layers::Compositor* aCompositor) override;
 
-  IAPZCTreeManager* APZCTM() { return mAPZC ; }
-
   virtual MOZ_MUST_USE nsresult
   StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent,
                  int32_t aPanelX, int32_t aPanelY,
                  nsString& aCommitted) override;
 
   virtual void SetPluginFocused(bool& aFocused) override;
 
   bool IsPluginFocused() { return mPluginFocused; }
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -152,18 +152,16 @@ NSPoint ChildViewMouseTracker::sLastScro
 static void blinkRect(Rect* r);
 static void blinkRgn(RgnHandle rgn);
 #endif
 
 bool gUserCancelledDrag = false;
 
 uint32_t nsChildView::sLastInputEventCount = 0;
 
-static uint32_t gNumberOfWidgetsNeedingEventThread = 0;
-
 static bool sIsTabletPointerActivated = false;
 
 static uint32_t sUniqueKeyEventId = 0;
 
 static NSMutableDictionary* sNativeKeyEventsMap =
   [NSMutableDictionary dictionary];
 
 @interface ChildView(Private)
@@ -206,38 +204,26 @@ static NSMutableDictionary* sNativeKeyEv
 #endif
 
 #ifdef ACCESSIBILITY
 - (id<mozAccessible>)accessible;
 #endif
 
 - (LayoutDeviceIntPoint)convertWindowCoordinates:(NSPoint)aPoint;
 - (LayoutDeviceIntPoint)convertWindowCoordinatesRoundDown:(NSPoint)aPoint;
-- (IAPZCTreeManager*)apzctm;
 
 - (BOOL)inactiveWindowAcceptsMouseEvent:(NSEvent*)aEvent;
 - (void)updateWindowDraggableState;
 
 - (bool)beginOrEndGestureForEventPhase:(NSEvent*)aEvent;
 
 - (bool)shouldConsiderStartingSwipeFromEvent:(NSEvent*)aEvent;
 
 @end
 
-@interface EventThreadRunner : NSObject
-{
-  NSThread* mThread;
-}
-- (id)init;
-
-+ (void)start;
-+ (void)stop;
-
-@end
-
 @interface NSView(NSThemeFrameCornerRadius)
 - (float)roundedCornerRadius;
 @end
 
 @interface NSView(DraggableRegion)
 - (CGSRegionObj)_regionForOpaqueDescendants:(NSRect)aRect forMove:(BOOL)aForMove;
 - (CGSRegionObj)_regionForOpaqueDescendants:(NSRect)aRect forMove:(BOOL)aForMove forUnderTitlebar:(BOOL)aForUnderTitlebar;
 @end
@@ -394,23 +380,16 @@ nsChildView::~nsChildView()
   }
 
   NS_WARNING_ASSERTION(
     mOnDestroyCalled,
     "nsChildView object destroyed without calling Destroy()");
 
   DestroyCompositor();
 
-  if (mAPZC && gfxPrefs::AsyncPanZoomSeparateEventThread()) {
-    gNumberOfWidgetsNeedingEventThread--;
-    if (gNumberOfWidgetsNeedingEventThread == 0) {
-      [EventThreadRunner stop];
-    }
-  }
-
   // An nsChildView object that was in use can be destroyed without Destroy()
   // ever being called on it.  So we also need to do a quick, safe cleanup
   // here (it's too late to just call Destroy(), which can cause crashes).
   // It's particularly important to make sure widgetDestroyed is called on our
   // mView -- this method NULLs mView's mGeckoChild, and NULL checks on
   // mGeckoChild are used throughout the ChildView class to tell if it's safe
   // to use a ChildView object.
   [mView widgetDestroyed]; // Safe if mView is nil.
@@ -1974,35 +1953,22 @@ nsChildView::CreateCompositor()
     [(ChildView *)mView setUsingOMTCompositor:true];
   }
 }
 
 void
 nsChildView::ConfigureAPZCTreeManager()
 {
   nsBaseWidget::ConfigureAPZCTreeManager();
-
-  if (gfxPrefs::AsyncPanZoomSeparateEventThread()) {
-    if (gNumberOfWidgetsNeedingEventThread == 0) {
-      [EventThreadRunner start];
-    }
-    gNumberOfWidgetsNeedingEventThread++;
-  }
 }
 
 void
 nsChildView::ConfigureAPZControllerThread()
 {
-  if (gfxPrefs::AsyncPanZoomSeparateEventThread()) {
-    // The EventThreadRunner is the controller thread, but it doesn't
-    // have a MessageLoop.
-    APZThreadUtils::SetControllerThread(nullptr);
-  } else {
-    nsBaseWidget::ConfigureAPZControllerThread();
-  }
+  nsBaseWidget::ConfigureAPZControllerThread();
 }
 
 LayoutDeviceIntRect
 nsChildView::RectContainingTitlebarControls()
 {
   NSRect rect = NSZeroRect;
 
   // If we draw the titlebar title string, set the rect to the full window
@@ -4957,22 +4923,16 @@ GetIntegerDeltaForEvent(NSEvent* aEvent)
   // For line scrolls, or pre-10.12, just use the rounded up value of deltaX / deltaY.
   return gfx::IntPoint(RoundUp([aEvent deltaX]), RoundUp([aEvent deltaY]));
 }
 
 - (void)scrollWheel:(NSEvent*)theEvent
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
-  if (gfxPrefs::AsyncPanZoomSeparateEventThread() && [self apzctm]) {
-    // Disable main-thread scrolling completely when using APZ with the
-    // separate event thread. This is bug 1013412.
-    return;
-  }
-
   nsAutoRetainCocoaObject kungFuDeathGrip(self);
 
   ChildViewMouseTracker::MouseScrolled(theEvent);
 
   if ([self maybeRollup:theEvent]) {
     return;
   }
 
@@ -5102,115 +5062,16 @@ GetIntegerDeltaForEvent(NSEvent* aEvent)
     wheelEvent.mLineOrPageDeltaX = lineOrPageDelta.x;
     wheelEvent.mLineOrPageDeltaY = lineOrPageDelta.y;
     geckoChildDeathGrip->DispatchAPZWheelInputEvent(wheelEvent, false);
   }
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
-- (void)handleAsyncScrollEvent:(CGEventRef)cgEvent ofType:(CGEventType)type
-{
-  IAPZCTreeManager* apzctm = [self apzctm];
-  if (!apzctm) {
-    return;
-  }
-
-  CGPoint loc = CGEventGetLocation(cgEvent);
-  loc.y = nsCocoaUtils::FlippedScreenY(loc.y);
-  NSPoint locationInWindow =
-    nsCocoaUtils::ConvertPointFromScreen([self window], NSPointFromCGPoint(loc));
-  ScreenIntPoint location = ViewAs<ScreenPixel>(
-    [self convertWindowCoordinates:locationInWindow],
-    PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent);
-
-  static NSTimeInterval sStartTime = [NSDate timeIntervalSinceReferenceDate];
-  static TimeStamp sStartTimeStamp = TimeStamp::Now();
-
-  if (type == kCGEventScrollWheel) {
-    NSEvent* event = [NSEvent eventWithCGEvent:cgEvent];
-    NSEventPhase phase = nsCocoaUtils::EventPhase(event);
-    NSEventPhase momentumPhase = nsCocoaUtils::EventMomentumPhase(event);
-    CGFloat pixelDeltaX = 0, pixelDeltaY = 0;
-    nsCocoaUtils::GetScrollingDeltas(event, &pixelDeltaX, &pixelDeltaY);
-    uint32_t eventTime = ([event timestamp] - sStartTime) * 1000;
-    TimeStamp eventTimeStamp = sStartTimeStamp +
-      TimeDuration::FromSeconds([event timestamp] - sStartTime);
-    NSPoint locationInWindowMoved = NSMakePoint(
-      locationInWindow.x + pixelDeltaX,
-      locationInWindow.y - pixelDeltaY);
-    ScreenIntPoint locationMoved = ViewAs<ScreenPixel>(
-      [self convertWindowCoordinates:locationInWindowMoved],
-      PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent);
-    ScreenPoint delta = ScreenPoint(locationMoved - location);
-    ScrollableLayerGuid guid;
-
-    // MayBegin and Cancelled are dispatched when the fingers start or stop
-    // touching the touchpad before any scrolling has occurred. These events
-    // can be used to control scrollbar visibility or interrupt scroll
-    // animations. They are only dispatched on 10.8 or later, and only by
-    // relatively modern devices.
-    if (phase == NSEventPhaseMayBegin) {
-      PanGestureInput panInput(PanGestureInput::PANGESTURE_MAYSTART, eventTime,
-                               eventTimeStamp, location, ScreenPoint(0, 0), 0);
-      apzctm->InputBridge()->ReceiveInputEvent(panInput, &guid, nullptr);
-      return;
-    }
-    if (phase == NSEventPhaseCancelled) {
-      PanGestureInput panInput(PanGestureInput::PANGESTURE_CANCELLED, eventTime,
-                               eventTimeStamp, location, ScreenPoint(0, 0), 0);
-      apzctm->InputBridge()->ReceiveInputEvent(panInput, &guid, nullptr);
-      return;
-    }
-
-    // Legacy scroll events are dispatched by devices that do not have a
-    // concept of a scroll gesture, for example by USB mice with
-    // traditional mouse wheels.
-    // For these kinds of scrolls, we want to surround every single scroll
-    // event with a PANGESTURE_START and a PANGESTURE_END event. The APZC
-    // needs to know that the real scroll gesture can end abruptly after any
-    // one of these events.
-    bool isLegacyScroll = (phase == NSEventPhaseNone &&
-      momentumPhase == NSEventPhaseNone && delta != ScreenPoint(0, 0));
-
-    if (phase == NSEventPhaseBegan || isLegacyScroll) {
-      PanGestureInput panInput(PanGestureInput::PANGESTURE_START, eventTime,
-                               eventTimeStamp, location, ScreenPoint(0, 0), 0);
-      apzctm->InputBridge()->ReceiveInputEvent(panInput, &guid, nullptr);
-    }
-    if (momentumPhase == NSEventPhaseNone && delta != ScreenPoint(0, 0)) {
-      PanGestureInput panInput(PanGestureInput::PANGESTURE_PAN, eventTime,
-                               eventTimeStamp, location, delta, 0);
-      apzctm->InputBridge()->ReceiveInputEvent(panInput, &guid, nullptr);
-    }
-    if (phase == NSEventPhaseEnded || isLegacyScroll) {
-      PanGestureInput panInput(PanGestureInput::PANGESTURE_END, eventTime,
-                               eventTimeStamp, location, ScreenPoint(0, 0), 0);
-      apzctm->InputBridge()->ReceiveInputEvent(panInput, &guid, nullptr);
-    }
-
-    // Any device that can dispatch momentum events supports all three momentum phases.
-    if (momentumPhase == NSEventPhaseBegan) {
-      PanGestureInput panInput(PanGestureInput::PANGESTURE_MOMENTUMSTART, eventTime,
-                               eventTimeStamp, location, ScreenPoint(0, 0), 0);
-      apzctm->InputBridge()->ReceiveInputEvent(panInput, &guid, nullptr);
-    }
-    if (momentumPhase == NSEventPhaseChanged && delta != ScreenPoint(0, 0)) {
-      PanGestureInput panInput(PanGestureInput::PANGESTURE_MOMENTUMPAN, eventTime,
-                               eventTimeStamp, location, delta, 0);
-      apzctm->InputBridge()->ReceiveInputEvent(panInput, &guid, nullptr);
-    }
-    if (momentumPhase == NSEventPhaseEnded) {
-      PanGestureInput panInput(PanGestureInput::PANGESTURE_MOMENTUMEND, eventTime,
-                               eventTimeStamp, location, ScreenPoint(0, 0), 0);
-      apzctm->InputBridge()->ReceiveInputEvent(panInput, &guid, nullptr);
-    }
-  }
-}
-
 -(NSMenu*)menuForEvent:(NSEvent*)theEvent
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
   if (!mGeckoChild)
     return nil;
 
   nsAutoRetainCocoaObject kungFuDeathGrip(self);
@@ -6086,21 +5947,16 @@ GetIntegerDeltaForEvent(NSEvent* aEvent)
   if (!mGeckoChild) {
     return LayoutDeviceIntPoint(0, 0);
   }
 
   NSPoint localPoint = [self convertPoint:aPoint fromView:nil];
   return mGeckoChild->CocoaPointsToDevPixelsRoundDown(localPoint);
 }
 
-- (IAPZCTreeManager*)apzctm
-{
-  return mGeckoChild ? mGeckoChild->APZCTM() : nullptr;
-}
-
 // This is a utility function used by NSView drag event methods
 // to send events. It contains all of the logic needed for Gecko
 // dragging to work. Returns the appropriate cocoa drag operation code.
 - (NSDragOperation)doDragAction:(EventMessage)aMessage sender:(id)aSender
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
   if (!mGeckoChild)
@@ -7050,115 +6906,16 @@ ChildViewMouseTracker::WindowAcceptsEven
 
   // If we're here then we're dealing with a left click or mouse move on an
   // inactive window or something similar. Ask Gecko what to do.
   return [aView inactiveWindowAcceptsMouseEvent:aEvent];
 }
 
 #pragma mark -
 
-@interface EventThreadRunner(Private)
-- (void)runEventThread;
-- (void)shutdownAndReleaseCalledOnEventThread;
-- (void)shutdownAndReleaseCalledOnAnyThread;
-- (void)handleEvent:(CGEventRef)cgEvent type:(CGEventType)type;
-@end
-
-static EventThreadRunner* sEventThreadRunner = nil;
-
-@implementation EventThreadRunner
-
-+ (void)start
-{
-  sEventThreadRunner = [[EventThreadRunner alloc] init];
-}
-
-+ (void)stop
-{
-  if (sEventThreadRunner) {
-    [sEventThreadRunner shutdownAndReleaseCalledOnAnyThread];
-    sEventThreadRunner = nil;
-  }
-}
-
-- (id)init
-{
-  if ((self = [super init])) {
-    mThread = nil;
-    [NSThread detachNewThreadSelector:@selector(runEventThread)
-                             toTarget:self
-                           withObject:nil];
-  }
-  return self;
-}
-
-static CGEventRef
-HandleEvent(CGEventTapProxy aProxy, CGEventType aType,
-            CGEventRef aEvent, void* aClosure)
-{
-  [(EventThreadRunner*)aClosure handleEvent:aEvent type:aType];
-  return aEvent;
-}
-
-- (void)runEventThread
-{
-  PROFILER_REGISTER_THREAD("APZC Event Thread");
-  NS_SetCurrentThreadName("APZC Event Thread");
-
-  mThread = [NSThread currentThread];
-  ProcessSerialNumber currentProcess;
-  GetCurrentProcess(&currentProcess);
-  CFMachPortRef eventPort =
-    CGEventTapCreateForPSN(&currentProcess,
-                           kCGHeadInsertEventTap,
-                           kCGEventTapOptionListenOnly,
-                           CGEventMaskBit(kCGEventScrollWheel),
-                           HandleEvent,
-                           self);
-  CFRunLoopSourceRef eventPortSource =
-    CFMachPortCreateRunLoopSource(kCFAllocatorSystemDefault, eventPort, 0);
-  CFRunLoopAddSource(CFRunLoopGetCurrent(), eventPortSource, kCFRunLoopCommonModes);
-  CFRunLoopRun();
-  CFRunLoopRemoveSource(CFRunLoopGetCurrent(), eventPortSource, kCFRunLoopCommonModes);
-  CFRelease(eventPortSource);
-  CFRelease(eventPort);
-  [self release];
-}
-
-- (void)shutdownAndReleaseCalledOnEventThread
-{
-  CFRunLoopStop(CFRunLoopGetCurrent());
-}
-
-- (void)shutdownAndReleaseCalledOnAnyThread
-{
-  [self performSelector:@selector(shutdownAndReleaseCalledOnEventThread) onThread:mThread withObject:nil waitUntilDone:NO];
-}
-
-static const CGEventField kCGWindowNumberField = (const CGEventField) 51;
-
-// Called on scroll thread
-- (void)handleEvent:(CGEventRef)cgEvent type:(CGEventType)type
-{
-  if (type != kCGEventScrollWheel) {
-    return;
-  }
-
-  int windowNumber = CGEventGetIntegerValueField(cgEvent, kCGWindowNumberField);
-  NSWindow* window = [NSApp windowWithWindowNumber:windowNumber];
-  if (!window || ![window isKindOfClass:[BaseWindow class]]) {
-    return;
-  }
-
-  ChildView* childView = [(BaseWindow*)window mainChildView];
-  [childView handleAsyncScrollEvent:cgEvent ofType:type];
-}
-
-@end
-
 @interface NSView (MethodSwizzling)
 - (BOOL)nsChildView_NSView_mouseDownCanMoveWindow;
 @end
 
 @implementation NSView (MethodSwizzling)
 
 // All top-level browser windows belong to the ToolbarWindow class and have
 // NSTexturedBackgroundWindowMask turned on in their "style" (see particularly