From 9baee632d4e706d3429780aa2a57223a6a7ff9b1 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Wed, 15 Jan 2014 14:00:52 +0200 Subject: [PATCH] Bug 930793 - Remove favor performance mode, r=roc,avih --HG-- extra : rebase_source : 5b466917ad1b1b5ef75119cfbeba75861cb49823 --- content/base/src/nsContentSink.cpp | 17 --------- content/base/src/nsContentSink.h | 3 -- docshell/base/nsDocShell.cpp | 38 ------------------- .../mochitest/general/test_vibrator.html | 2 +- .../pointerlock/file_screenClientXYConst.html | 4 +- layout/base/nsRefreshDriver.cpp | 2 +- view/public/nsViewManager.h | 7 +++- view/src/nsViewManager.cpp | 14 +++++-- widget/cocoa/nsChildView.h | 1 + widget/cocoa/nsChildView.mm | 12 ++++++ widget/gtk/nsWindow.cpp | 8 ++++ widget/gtk/nsWindow.h | 1 + widget/nsIAppShell.idl | 18 --------- widget/nsIWidget.h | 9 ++++- widget/windows/nsWindow.cpp | 8 ++++ widget/windows/nsWindow.h | 1 + widget/windows/winrt/MetroWidget.cpp | 8 ++++ widget/windows/winrt/MetroWidget.h | 1 + widget/xpwidgets/nsBaseAppShell.cpp | 38 +------------------ widget/xpwidgets/nsBaseAppShell.h | 4 -- 20 files changed, 69 insertions(+), 127 deletions(-) diff --git a/content/base/src/nsContentSink.cpp b/content/base/src/nsContentSink.cpp index 77226000e573..6600d488d0c8 100644 --- a/content/base/src/nsContentSink.cpp +++ b/content/base/src/nsContentSink.cpp @@ -200,7 +200,6 @@ nsContentSink::Init(nsIDocument* aDoc, if (sEnablePerfMode != 0) { mDynamicLowerValue = sEnablePerfMode == 1; - FavorPerformanceHint(!mDynamicLowerValue, 0); } return NS_OK; @@ -1376,15 +1375,6 @@ nsContentSink::DidProcessATokenImpl() //---------------------------------------------------------------------- -void -nsContentSink::FavorPerformanceHint(bool perfOverStarvation, uint32_t starvationDelay) -{ - static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); - nsCOMPtr appShell = do_GetService(kAppShellCID); - if (appShell) - appShell->FavorPerformanceHint(perfOverStarvation, starvationDelay); -} - void nsContentSink::BeginUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType) { @@ -1462,12 +1452,6 @@ nsContentSink::DropParserAndPerfHint(void) // reference. nsRefPtr kungFuDeathGrip(mParser.forget()); - if (mDynamicLowerValue) { - // Reset the performance hint which was set to FALSE - // when mDynamicLowerValue was set. - FavorPerformanceHint(true, 0); - } - if (!mRunsToCompletion) { mDocument->UnblockOnload(true); } @@ -1505,7 +1489,6 @@ nsContentSink::WillParseImpl(void) (currentTime - lastEventTime) < uint32_t(sInteractiveTime)); if (mDynamicLowerValue != newDynLower) { - FavorPerformanceHint(!newDynLower, 0); mDynamicLowerValue = newDynLower; } } diff --git a/content/base/src/nsContentSink.h b/content/base/src/nsContentSink.h index 305f828c9c44..febacd3abe83 100644 --- a/content/base/src/nsContentSink.h +++ b/content/base/src/nsContentSink.h @@ -237,9 +237,6 @@ public: static void NotifyDocElementCreated(nsIDocument* aDoc); protected: - void - FavorPerformanceHint(bool perfOverStarvation, uint32_t starvationDelay); - inline int32_t GetNotificationInterval() { if (mDynamicLowerValue) { diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index ca080b06df36..d89676757235 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -211,9 +211,6 @@ static bool gAddedPreferencesVarCache = false; bool nsDocShell::sUseErrorPages = false; -// Number of documents currently loading -static int32_t gNumberOfDocumentsLoading = 0; - // Global count of existing docshells. static int32_t gDocShellCount = 0; @@ -244,17 +241,6 @@ static PRLogModuleInfo* gDocShellLeakLog; const char kBrandBundleURL[] = "chrome://branding/locale/brand.properties"; const char kAppstringsBundleURL[] = "chrome://global/locale/appstrings.properties"; -static void -FavorPerformanceHint(bool perfOverStarvation) -{ - nsCOMPtr appShell = do_GetService(kAppShellCID); - if (appShell) { - appShell->FavorPerformanceHint(perfOverStarvation, - Preferences::GetUint("docshell.event_starvation_delay_hint", - NS_EVENT_STARVATION_DELAY_HINT)); - } -} - //***************************************************************************** // support //***************************************************************************** @@ -6865,14 +6851,6 @@ nsDocShell::EndPageLoad(nsIWebProgress * aProgress, mIsExecutingOnLoadHandler = false; mEODForCurrentDocument = true; - - // If all documents have completed their loading - // favor native event dispatch priorities - // over performance - if (--gNumberOfDocumentsLoading == 0) { - // Hint to use normal native event dispatch priorities - FavorPerformanceHint(false); - } } /* Check if the httpChannel has any cache-control related response headers, * like no-store, no-cache. If so, update SHEntry so that @@ -7876,12 +7854,6 @@ nsDocShell::RestoreFromHistory() mSavingOldViewer = false; mEODForCurrentDocument = false; - // Tell the event loop to favor plevents over user events, see comments - // in CreateContentViewer. - if (++gNumberOfDocumentsLoading == 1) - FavorPerformanceHint(true); - - if (oldMUDV && newMUDV) { newMUDV->SetMinFontSize(minFontSize); newMUDV->SetTextZoom(textZoom); @@ -8278,16 +8250,6 @@ nsDocShell::CreateContentViewer(const char *aContentType, } } - // Give hint to native plevent dispatch mechanism. If a document - // is loading the native plevent dispatch mechanism should favor - // performance over normal native event dispatch priorities. - if (++gNumberOfDocumentsLoading == 1) { - // Hint to favor performance for the plevent notification mechanism. - // We want the pages to load as fast as possible even if its means - // native messages might be starved. - FavorPerformanceHint(true); - } - if (onLocationChangeNeeded) { FireOnLocationChange(this, request, mCurrentURI, 0); } diff --git a/dom/tests/mochitest/general/test_vibrator.html b/dom/tests/mochitest/general/test_vibrator.html index fea819af939a..92990c7f61e3 100644 --- a/dom/tests/mochitest/general/test_vibrator.html +++ b/dom/tests/mochitest/general/test_vibrator.html @@ -57,7 +57,7 @@ function testSuccesses() { expectSuccess([1000, 1000.1]); // The following loop shouldn't cause us to crash. See bug 701716. - for (var i = 0; i < 10000; i++) { + for (var i = 0; i < 1000; i++) { navigator.vibrate([100, 100]); } ok(true, "Didn't crash after issuing a lot of vibrate() calls."); diff --git a/dom/tests/mochitest/pointerlock/file_screenClientXYConst.html b/dom/tests/mochitest/pointerlock/file_screenClientXYConst.html index 97f49e085f78..9378855e76b3 100644 --- a/dom/tests/mochitest/pointerlock/file_screenClientXYConst.html +++ b/dom/tests/mochitest/pointerlock/file_screenClientXYConst.html @@ -51,9 +51,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602 var firstCall = !unLockedCoords; if (!firstCall) { todo(false, "mousemove is fired twice."); + } else { + isUnlocked = !document.mozPointerLockElement; } - - isUnlocked = !document.mozPointerLockElement; unLockedCoords = { screenX: e.screenX, screenY: e.screenY, diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index 82419d1ecf01..26b84f9920ee 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -1204,7 +1204,7 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime) mViewManagerFlushIsPending = false; nsRefPtr vm = mPresContext->GetPresShell()->GetViewManager(); - vm->ProcessPendingUpdates(); + vm->ProcessPendingUpdates(nsViewManager::eTrySyncUpdate); #ifdef MOZ_DUMP_PAINTING if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) { printf_stderr("Ending ProcessPendingUpdates\n"); diff --git a/view/public/nsViewManager.h b/view/public/nsViewManager.h index 6885827c6dbb..e55a0aeea98e 100644 --- a/view/public/nsViewManager.h +++ b/view/public/nsViewManager.h @@ -302,11 +302,16 @@ public: */ static nsView* GetDisplayRootFor(nsView* aView); + enum UpdatingMode { + eNoSyncUpdate, + eTrySyncUpdate + }; + /** * Flush the accumulated dirty region to the widget and update widget * geometry. */ - void ProcessPendingUpdates(); + void ProcessPendingUpdates(UpdatingMode aMode); /** * Just update widget geometry without flushing the dirty region diff --git a/view/src/nsViewManager.cpp b/view/src/nsViewManager.cpp index 75fd3e669955..c784b1de84bb 100644 --- a/view/src/nsViewManager.cpp +++ b/view/src/nsViewManager.cpp @@ -654,7 +654,7 @@ void nsViewManager::WillPaintWindow(nsIWidget* aWidget) LayerManager *manager = aWidget->GetLayerManager(); if (view && (view->ForcedRepaint() || !manager->NeedsWidgetInvalidation())) { - ProcessPendingUpdates(); + ProcessPendingUpdates(eNoSyncUpdate); // Re-get the view pointer here since the ProcessPendingUpdates might have // destroyed it during CallWillPaintOnObservers. view = nsView::GetViewFor(aWidget); @@ -1037,10 +1037,10 @@ nsViewManager::IsPainting(bool& aIsPainting) } void -nsViewManager::ProcessPendingUpdates() +nsViewManager::ProcessPendingUpdates(UpdatingMode aMode) { if (!IsRootVM()) { - RootViewManager()->ProcessPendingUpdates(); + RootViewManager()->ProcessPendingUpdates(aMode); return; } @@ -1051,6 +1051,14 @@ nsViewManager::ProcessPendingUpdates() CallWillPaintOnObservers(); } ProcessPendingUpdatesForView(mRootView, true); + + if (aMode == eTrySyncUpdate) { + nsCOMPtr w; + GetRootWidget(getter_AddRefs(w)); + if (w) { + w->Update(); + } + } } void diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index 70c28ed34977..b9808c4ed1d2 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -486,6 +486,7 @@ public: virtual int32_t RoundsWidgetCoordinatesTo() MOZ_OVERRIDE; NS_IMETHOD Invalidate(const nsIntRect &aRect); + virtual void Update() MOZ_OVERRIDE; virtual void* GetNativeData(uint32_t aDataType); virtual nsresult ConfigureChildren(const nsTArray& aConfigurations); diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 1250ed82f583..aac79a39ec78 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1580,6 +1580,18 @@ NS_IMETHODIMP nsChildView::Invalidate(const nsIntRect &aRect) NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; } +void +nsChildView::Update() +{ + NS_OBJC_BEGIN_TRY_ABORT_BLOCK; + + if (!ShouldUseOffMainThreadCompositing() && mView) { + [mView displayIfNeeded]; + } + + NS_OBJC_END_TRY_ABORT_BLOCK; +} + bool nsChildView::ComputeShouldAccelerate(bool aDefault) { diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 5dc37fe4cfe8..c97b6587909b 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -1617,6 +1617,14 @@ nsWindow::Invalidate(const nsIntRect &aRect) return NS_OK; } +void +nsWindow::Update() +{ + if (!ShouldUseOffMainThreadCompositing() && mGdkWindow) { + gdk_window_process_updates(mGdkWindow, true); + } +} + void* nsWindow::GetNativeData(uint32_t aDataType) { diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index 61dbe1a9f469..273281f8e658 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -138,6 +138,7 @@ public: NS_IMETHOD SetCursor(imgIContainer* aCursor, uint32_t aHotspotX, uint32_t aHotspotY); NS_IMETHOD Invalidate(const nsIntRect &aRect); + virtual void Update() MOZ_OVERRIDE; virtual void* GetNativeData(uint32_t aDataType); NS_IMETHOD SetTitle(const nsAString& aTitle); NS_IMETHOD SetIcon(const nsAString& aIconSpec); diff --git a/widget/nsIAppShell.idl b/widget/nsIAppShell.idl index 3c0af793c633..be4e6eac5283 100644 --- a/widget/nsIAppShell.idl +++ b/widget/nsIAppShell.idl @@ -25,24 +25,6 @@ interface nsIAppShell : nsISupports */ void exit(); - /** - * Give hint to native event queue notification mechanism. If the native - * platform needs to tradeoff performance vs. native event starvation this - * hint tells the native dispatch code which to favor. The default is to - * prevent native event starvation. - * - * Calls to this function may be nested. When the number of calls that pass - * PR_TRUE is subtracted from the number of calls that pass PR_FALSE is - * greater than 0, performance is given precedence over preventing event - * starvation. - * - * The starvationDelay arg is only used when favorPerfOverStarvation is - * PR_FALSE. It is the amount of time in milliseconds to wait before the - * PR_FALSE actually takes effect. - */ - void favorPerformanceHint(in boolean favorPerfOverStarvation, - in unsigned long starvationDelay); - /** * Suspends the use of additional platform-specific methods (besides the * nsIAppShell->run() event loop) to run Gecko events on the main diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h index d402e43d369d..1cba8f18dfab 100644 --- a/widget/nsIWidget.h +++ b/widget/nsIWidget.h @@ -100,8 +100,8 @@ typedef void* nsNativeWidget; #endif #define NS_IWIDGET_IID \ -{ 0x67da44c4, 0xe21b, 0x4742, \ - { 0x9c, 0x2b, 0x26, 0xc7, 0x70, 0x21, 0xde, 0x87 } } +{ 0x7a4ece50, 0x5c52, 0x47c2, \ + { 0x8c, 0x9e, 0x32, 0xd2, 0x5a, 0x27, 0x53, 0x34 } } /* * Window shadow styles @@ -1177,6 +1177,11 @@ class nsIWidget : public nsISupports { */ NS_IMETHOD Invalidate(const nsIntRect & aRect) = 0; + /** + * Widget implementation may support synchronous painting. + */ + virtual void Update() { } + enum LayerManagerPersistence { LAYER_MANAGER_CURRENT = 0, diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index f2cd1b667216..210ba3fd0b90 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -2775,6 +2775,14 @@ NS_METHOD nsWindow::Invalidate(const nsIntRect & aRect) return NS_OK; } +void +nsWindow::Update() +{ + if (!ShouldUseOffMainThreadCompositing() && mWnd) { + ::UpdateWindow(mWnd); + } +} + NS_IMETHODIMP nsWindow::MakeFullScreen(bool aFullScreen) { diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index 6fc84a2c3e37..40c7b2c70f2d 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -137,6 +137,7 @@ public: bool aUpdateNCArea = false, bool aIncludeChildren = false); NS_IMETHOD Invalidate(const nsIntRect & aRect); + virtual void Update() MOZ_OVERRIDE; virtual void* GetNativeData(uint32_t aDataType); virtual void FreeNativeData(void * data, uint32_t aDataType); NS_IMETHOD SetTitle(const nsAString& aTitle); diff --git a/widget/windows/winrt/MetroWidget.cpp b/widget/windows/winrt/MetroWidget.cpp index 52493cd31d1f..427457342dba 100644 --- a/widget/windows/winrt/MetroWidget.cpp +++ b/widget/windows/winrt/MetroWidget.cpp @@ -1194,6 +1194,14 @@ MetroWidget::Invalidate(const nsIntRect & aRect) return NS_OK; } +void +MetroWidget::Update() +{ + if (!ShouldUseOffMainThreadCompositing() && mWnd) { + ::UpdateWindow(mWnd); + } +} + nsTransparencyMode MetroWidget::GetTransparencyMode() { diff --git a/widget/windows/winrt/MetroWidget.h b/widget/windows/winrt/MetroWidget.h index 084267aad60f..1391e6db3e30 100644 --- a/widget/windows/winrt/MetroWidget.h +++ b/widget/windows/winrt/MetroWidget.h @@ -107,6 +107,7 @@ public: bool aUpdateNCArea = false, bool aIncludeChildren = false); NS_IMETHOD Invalidate(const nsIntRect & aRect); + virtual void Update() MOZ_OVERRIDE; NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, nsEventStatus& aStatus); NS_IMETHOD ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY); diff --git a/widget/xpwidgets/nsBaseAppShell.cpp b/widget/xpwidgets/nsBaseAppShell.cpp index 1193a2a9e501..946ee0f35bf8 100644 --- a/widget/xpwidgets/nsBaseAppShell.cpp +++ b/widget/xpwidgets/nsBaseAppShell.cpp @@ -22,11 +22,7 @@ nsBaseAppShell::nsBaseAppShell() : mSuspendNativeCount(0) , mEventloopNestingLevel(0) , mBlockedWait(nullptr) - , mFavorPerf(0) , mNativeEventPending(0) - , mStarvationDelay(0) - , mSwitchTime(0) - , mLastNativeEventTime(0) , mEventloopNestingState(eEventloopNone) , mRunning(false) , mExiting(false) @@ -176,20 +172,6 @@ nsBaseAppShell::Exit(void) return NS_OK; } -NS_IMETHODIMP -nsBaseAppShell::FavorPerformanceHint(bool favorPerfOverStarvation, - uint32_t starvationDelay) -{ - mStarvationDelay = PR_MillisecondsToInterval(starvationDelay); - if (favorPerfOverStarvation) { - ++mFavorPerf; - } else { - --mFavorPerf; - mSwitchTime = PR_IntervalNow(); - } - return NS_OK; -} - NS_IMETHODIMP nsBaseAppShell::SuspendNative() { @@ -250,9 +232,6 @@ nsBaseAppShell::OnProcessNextEvent(nsIThreadInternal *thr, bool mayWait, OnDispatchedEvent(thr); // in case we blocked it earlier } - PRIntervalTime start = PR_IntervalNow(); - PRIntervalTime limit = THREAD_EVENT_STARVATION_LIMIT; - // Unblock outer nested wait loop (below). if (mBlockedWait) *mBlockedWait = false; @@ -268,21 +247,7 @@ nsBaseAppShell::OnProcessNextEvent(nsIThreadInternal *thr, bool mayWait, // NativeEventCallback to process gecko events. mProcessedGeckoEvents = false; - if (mFavorPerf <= 0 && start > mSwitchTime + mStarvationDelay) { - // Favor pending native events - PRIntervalTime now = start; - bool keepGoing; - do { - mLastNativeEventTime = now; - keepGoing = DoProcessNextNativeEvent(false, recursionDepth); - } while (keepGoing && ((now = PR_IntervalNow()) - start) < limit); - } else { - // Avoid starving native events completely when in performance mode - if (start - mLastNativeEventTime > limit) { - mLastNativeEventTime = start; - DoProcessNextNativeEvent(false, recursionDepth); - } - } + DoProcessNextNativeEvent(false, recursionDepth); while (!NS_HasPendingEvents(thr) && !mProcessedGeckoEvents) { // If we have been asked to exit from Run, then we should not wait for @@ -291,7 +256,6 @@ nsBaseAppShell::OnProcessNextEvent(nsIThreadInternal *thr, bool mayWait, if (mExiting) mayWait = false; - mLastNativeEventTime = PR_IntervalNow(); if (!DoProcessNextNativeEvent(mayWait, recursionDepth) || !mayWait) break; } diff --git a/widget/xpwidgets/nsBaseAppShell.h b/widget/xpwidgets/nsBaseAppShell.h index c976a2286eea..d67dd9786ec5 100644 --- a/widget/xpwidgets/nsBaseAppShell.h +++ b/widget/xpwidgets/nsBaseAppShell.h @@ -119,11 +119,7 @@ private: * have been consumed by the inner event loop(s). */ bool *mBlockedWait; - int32_t mFavorPerf; mozilla::Atomic mNativeEventPending; - PRIntervalTime mStarvationDelay; - PRIntervalTime mSwitchTime; - PRIntervalTime mLastNativeEventTime; enum EventloopNestingState { eEventloopNone, // top level thread execution eEventloopXPCOM, // innermost native event loop is ProcessNextNativeEvent