Bug 1356218 - Fix nsDeviceContext::GetDepth to use the information from the correct monitor. r=jfkthame
MozReview-Commit-ID: BQpm6y3Ayo4
--- 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;