Bug 1352527 - Part 1: Add the nsPresContext::GetBidiEngine() API; r=jfkthame
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 11 Apr 2017 00:51:30 -0400
changeset 401295 a8e6a2c7e9265300edd47402f0dc09f8db326257
parent 401294 df4e3ee037d6f236f80eaecbc4e7d5b91151d9f3
child 401296 ea2dc5a6091d6120ff67351aa80ce041b57d485a
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1352527
milestone55.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 1352527 - Part 1: Add the nsPresContext::GetBidiEngine() API; r=jfkthame The nsBidi API requires the consumer to first call SetPara() in order to perform bidi resolution and that resets the data members, so there is no need to recreate nsBidi objects from scratch each time we need to perform bidi resolution. Having this API allows us to reuse this object across the calls to nsBidiPresUtils members.
layout/base/nsBidi_ICU.h
layout/base/nsBidi_noICU.h
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
--- a/layout/base/nsBidi_ICU.h
+++ b/layout/base/nsBidi_ICU.h
@@ -178,13 +178,17 @@ public:
    *      indexes which will reflect the reordering of the characters.
    *      The array does not need to be initialized.<p>
    *      The index map will result in
    *        <code>aIndexMap[aVisualIndex]==aLogicalIndex</code>.
    */
   static nsresult ReorderVisual(const nsBidiLevel* aLevels, int32_t aLength,
                                 int32_t* aIndexMap);
 
+private:
+  nsBidi(const nsBidi&) = delete;
+  void operator=(const nsBidi&) = delete;
+
 protected:
   UBiDi* mBiDi;
 };
 
 #endif // _nsBidi_ICU_h_
--- a/layout/base/nsBidi_noICU.h
+++ b/layout/base/nsBidi_noICU.h
@@ -699,11 +699,14 @@ private:
 
   bool GetRuns();
 
   void GetSingleRun(nsBidiLevel aLevel);
 
   void ReorderLine(nsBidiLevel aMinLevel, nsBidiLevel aMaxLevel);
 
   static bool PrepareReorder(const nsBidiLevel *aLevels, int32_t aLength, int32_t *aIndexMap, nsBidiLevel *aMinLevel, nsBidiLevel *aMaxLevel);
+
+  nsBidi(const nsBidi&) = delete;
+  void operator=(const nsBidi&) = delete;
 };
 
 #endif // _nsBidi_noICU_h_
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -84,16 +84,17 @@
 
 // Needed for Start/Stop of Image Animation
 #include "imgIContainer.h"
 #include "nsIImageLoadingContent.h"
 
 #include "nsCSSParser.h"
 #include "nsBidiUtils.h"
 #include "nsServiceManagerUtils.h"
+#include "nsBidi.h"
 
 #include "mozilla/dom/URL.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::layers;
 
 uint8_t gNotifySubDocInvalidationData;
@@ -3007,16 +3008,27 @@ uint64_t
 nsPresContext::GetRestyleGeneration() const
 {
   if (!mRestyleManager) {
     return 0;
   }
   return mRestyleManager->GetRestyleGeneration();
 }
 
+nsBidi&
+nsPresContext::GetBidiEngine()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  if (!mBidiEngine) {
+    mBidiEngine.reset(new nsBidi());
+  }
+  return *mBidiEngine;
+}
+
 nsRootPresContext::nsRootPresContext(nsIDocument* aDocument,
                                      nsPresContextType aType)
   : nsPresContext(aDocument, aType),
     mDOMGeneration(0)
 {
 }
 
 nsRootPresContext::~nsRootPresContext()
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* a presentation of a document, part 1 */
 
 #ifndef nsPresContext_h___
 #define nsPresContext_h___
 
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 #include "mozilla/WeakPtr.h"
 #include "nsColor.h"
 #include "nsCoord.h"
 #include "nsCOMPtr.h"
 #include "nsIPresShell.h"
 #include "nsRect.h"
 #include "nsFont.h"
 #include "gfxFontConstants.h"
@@ -40,16 +41,17 @@
 #include "nsIMessageManager.h"
 #include "mozilla/RestyleLogging.h"
 #include "Units.h"
 #include "prenv.h"
 #include "mozilla/StaticPresData.h"
 #include "mozilla/StyleBackendType.h"
 
 class nsAString;
+class nsBidi;
 class nsIPrintSettings;
 class nsDocShell;
 class nsIDocShell;
 class nsIDocument;
 class nsILanguageAtomService;
 class nsITheme;
 class nsIContent;
 class nsIFrame;
@@ -1188,16 +1190,18 @@ public:
   bool HasWarnedAboutTooLargeDashedOrDottedRadius() const {
     return mHasWarnedAboutTooLargeDashedOrDottedRadius;
   }
 
   void SetHasWarnedAboutTooLargeDashedOrDottedRadius() {
     mHasWarnedAboutTooLargeDashedOrDottedRadius = true;
   }
 
+  nsBidi& GetBidiEngine();
+
 protected:
   friend class nsRunnableMethod<nsPresContext>;
   void ThemeChangedInternal();
   void SysColorChangedInternal();
 
   // update device context's resolution from the widget
   void UIResolutionChangedInternal();
 
@@ -1344,16 +1348,18 @@ protected:
   int32_t               mCurAppUnitsPerDevPixel;
   int32_t               mAutoQualityMinFontSizePixelsPref;
 
   nsCOMPtr<nsITheme> mTheme;
   nsCOMPtr<nsILanguageAtomService> mLangService;
   nsCOMPtr<nsIPrintSettings> mPrintSettings;
   nsCOMPtr<nsITimer>    mPrefChangedTimer;
 
+  mozilla::UniquePtr<nsBidi> mBidiEngine;
+
   FramePropertyTable    mPropertyTable;
 
   struct TransactionInvalidations {
     uint64_t mTransactionId;
     nsTArray<nsRect> mInvalidations;
   };
   AutoTArray<TransactionInvalidations, 4> mTransactions;