Bug 1356218 - Fix nsDeviceContext::GetDepth to use the information from the correct monitor. r=jfkthame draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Fri, 14 Apr 2017 20:50:13 +0900
changeset 563697 c798db446d28c0621d38fb65a5345300ace8cca7
parent 563696 932e17cc61ba1a7344b1740ed14ece0484200e32
child 624544 d970679286d4d988960e2c36502513274ce8d425
push id54385
push userVYV03354@nifty.ne.jp
push dateMon, 17 Apr 2017 15:24:13 +0000
reviewersjfkthame
bugs1356218
milestone55.0a1
Bug 1356218 - Fix nsDeviceContext::GetDepth to use the information from the correct monitor. r=jfkthame MozReview-Commit-ID: BQpm6y3Ayo4
gfx/src/nsDeviceContext.cpp
gfx/src/nsDeviceContext.h
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -23,30 +23,31 @@
 #include "nsFontMetrics.h"              // for nsFontMetrics
 #include "nsIAtom.h"                    // for nsIAtom, NS_Atomize
 #include "nsID.h"
 #include "nsIDeviceContextSpec.h"       // for nsIDeviceContextSpec
 #include "nsILanguageAtomService.h"     // for nsILanguageAtomService, etc
 #include "nsIObserver.h"                // for nsIObserver, etc
 #include "nsIObserverService.h"         // for nsIObserverService
 #include "nsIScreen.h"                  // for nsIScreen
-#include "nsIScreenManager.h"           // for nsIScreenManager
 #include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
 #include "nsISupportsUtils.h"           // for NS_ADDREF, NS_RELEASE
 #include "nsIWidget.h"                  // for nsIWidget, NS_NATIVE_WINDOW
 #include "nsRect.h"                     // for nsRect
 #include "nsServiceManagerUtils.h"      // for do_GetService
 #include "nsString.h"               // for nsDependentString
 #include "nsTArray.h"                   // for nsTArray, nsTArray_Impl
 #include "nsThreadUtils.h"              // for NS_IsMainThread
 #include "mozilla/gfx/Logging.h"
+#include "mozilla/widget/ScreenManager.h" // for ScreenManager
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using mozilla::services::GetObserverService;
+using mozilla::widget::ScreenManager;
 
 class nsFontCache final : public nsIObserver
 {
 public:
     nsFontCache() {}
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
@@ -185,17 +186,17 @@ nsFontCache::Flush()
         // FontMetricsDeleted() in the subsequent release
         fm->Destroy();
         NS_RELEASE(fm);
     }
     mFontMetrics.Clear();
 }
 
 nsDeviceContext::nsDeviceContext()
-    : mWidth(0), mHeight(0), mDepth(0),
+    : mWidth(0), mHeight(0),
       mAppUnitsPerDevPixel(-1), mAppUnitsPerDevPixelAtUnitFullZoom(-1),
       mAppUnitsPerPhysicalInch(-1),
       mFullZoom(1.0f), mPrintingScale(1.0f)
 #ifdef DEBUG
     , mIsInitialized(false)
 #endif
 {
     MOZ_ASSERT(NS_IsMainThread(), "nsDeviceContext created off main thread");
@@ -394,23 +395,25 @@ nsDeviceContext::CreateRenderingContextC
 
     pContext->SetMatrix(transform);
     return pContext.forget();
 }
 
 nsresult
 nsDeviceContext::GetDepth(uint32_t& aDepth)
 {
-    if (mDepth == 0 && mScreenManager) {
-        nsCOMPtr<nsIScreen> primaryScreen;
-        mScreenManager->GetPrimaryScreen(getter_AddRefs(primaryScreen));
-        primaryScreen->GetColorDepth(reinterpret_cast<int32_t *>(&mDepth));
+    nsCOMPtr<nsIScreen> screen;
+    FindScreen(getter_AddRefs(screen));
+    if (!screen) {
+        ScreenManager& screenManager = ScreenManager::GetSingleton();
+        screenManager.GetPrimaryScreen(getter_AddRefs(screen));
+        MOZ_ASSERT(screen);
     }
+    screen->GetColorDepth(reinterpret_cast<int32_t *>(&aDepth));
 
-    aDepth = mDepth;
     return NS_OK;
 }
 
 nsresult
 nsDeviceContext::GetDeviceSurfaceDimensions(nscoord &aWidth, nscoord &aHeight)
 {
     if (IsPrinterContext()) {
         aWidth = mWidth;
--- a/gfx/src/nsDeviceContext.h
+++ b/gfx/src/nsDeviceContext.h
@@ -289,17 +289,16 @@ private:
     void FindScreen(nsIScreen **outScreen);
 
     // Return false if the surface is not right
     bool CalcPrintingSize();
     void UpdateAppUnitsForFullZoom();
 
     nscoord  mWidth;
     nscoord  mHeight;
-    uint32_t mDepth;
     int32_t  mAppUnitsPerDevPixel;
     int32_t  mAppUnitsPerDevPixelAtUnitFullZoom;
     int32_t  mAppUnitsPerPhysicalInch;
     float    mFullZoom;
     float    mPrintingScale;
 
     RefPtr<nsFontCache>            mFontCache;
     nsCOMPtr<nsIWidget>            mWidget;