Bug 1256547: When the DWM is disabled don't force presentation. r=milan draft
authorBas Schouten <bschouten@mozilla.com>
Mon, 11 Apr 2016 13:08:00 +0200
changeset 349390 b0ea7bca01be0bc89e37b4525be9d1a82f4168da
parent 348236 b548578a1980f2da63e4ca9c4b41b55f17be53de
child 518083 647884f56a49483773e055685e45d00ca8f6930d
push id15069
push userbschouten@mozilla.com
push dateMon, 11 Apr 2016 11:07:58 +0000
reviewersmilan
bugs1256547
milestone48.0a1
Bug 1256547: When the DWM is disabled don't force presentation. r=milan MozReview-Commit-ID: 4fd8QUWq0f1
gfx/thebes/gfxWindowsPlatform.cpp
gfx/thebes/gfxWindowsPlatform.h
widget/windows/nsWindowGfx.cpp
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -2588,22 +2588,30 @@ gfxWindowsPlatform::CreateD3D11DecoderDe
   RefPtr<ID3D10Multithread> multi;
   device->QueryInterface(__uuidof(ID3D10Multithread), getter_AddRefs(multi));
 
   multi->SetMultithreadProtected(TRUE);
 
   return device.forget();
 }
 
-static bool
-DwmCompositionEnabled()
+bool
+gfxWindowsPlatform::DwmCompositionEnabled()
 {
+  if (!IsVistaOrLater()) {
+    return false;
+  }
+
   MOZ_ASSERT(WinUtils::dwmIsCompositionEnabledPtr);
   BOOL dwmEnabled = false;
-  WinUtils::dwmIsCompositionEnabledPtr(&dwmEnabled);
+
+  if (FAILED(WinUtils::dwmIsCompositionEnabledPtr(&dwmEnabled))) {
+    return false;
+  }
+
   return dwmEnabled;
 }
 
 class D3DVsyncSource final : public VsyncSource
 {
 public:
 
   class D3DVsyncDisplay final : public VsyncSource::Display
@@ -2619,17 +2627,17 @@ public:
         const double rate = 1000 / 60.0;
         mSoftwareVsyncRate = TimeDuration::FromMilliseconds(rate);
         MOZ_RELEASE_ASSERT(mVsyncThread->Start(), "Could not start Windows vsync thread");
         SetVsyncRate();
       }
 
       void SetVsyncRate()
       {
-        if (!DwmCompositionEnabled()) {
+        if (!gfxWindowsPlatform::GetPlatform()->DwmCompositionEnabled()) {
           mVsyncRate = TimeDuration::FromMilliseconds(1000.0 / 60.0);
           return;
         }
 
         DWM_TIMING_INFO vblankTime;
         // Make sure to init the cbSize, otherwise GetCompositionTiming will fail
         vblankTime.cbSize = sizeof(DWM_TIMING_INFO);
         HRESULT hr = WinUtils::dwmGetCompositionTimingInfoPtr(0, &vblankTime);
@@ -2775,17 +2783,17 @@ public:
           // must be <= Now() and cannot be in the future.
           MOZ_ASSERT(vsync <= TimeStamp::Now());
           Display::NotifyVsync(vsync);
 
           // DwmComposition can be dynamically enabled/disabled
           // so we have to check every time that it's available.
           // When it is unavailable, we fallback to software but will try
           // to get back to dwm rendering once it's re-enabled
-          if (!DwmCompositionEnabled()) {
+          if (!gfxWindowsPlatform::GetPlatform()->DwmCompositionEnabled()) {
             ScheduleSoftwareVsync(vsync);
             return;
           }
 
           // Use a combination of DwmFlush + DwmGetCompositionTimingInfoPtr
           // Using WaitForVBlank, the whole system dies :/
           HRESULT hr = WinUtils::dwmFlushProcPtr();
           if (!SUCCEEDED(hr)) {
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -216,16 +216,18 @@ public:
     ID3D11Device *GetD3D11ContentDevice();
 
     // Create a D3D11 device to be used for DXVA decoding.
     already_AddRefed<ID3D11Device> CreateD3D11DecoderDevice();
     bool CreateD3D11DecoderDeviceHelper(
       IDXGIAdapter1* aAdapter, RefPtr<ID3D11Device>& aDevice,
       HRESULT& aResOut);
 
+    bool DwmCompositionEnabled();
+
     mozilla::layers::ReadbackManagerD3D11* GetReadbackManager();
 
     static bool IsOptimus();
 
     bool IsWARP() { return mIsWARP; }
 
     // Returns whether the compositor's D3D11 device supports texture sharing.
     bool CompositorD3D11TextureSharingWorks() const {
--- a/widget/windows/nsWindowGfx.cpp
+++ b/widget/windows/nsWindowGfx.cpp
@@ -522,17 +522,17 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t
             }
           }
         }
         break;
       case LayersBackend::LAYERS_CLIENT:
         {
           result = listener->PaintWindow(
             this, LayoutDeviceIntRegion::FromUnknownRegion(region));
-          if (!gfxEnv::DisableForcePresent()) {
+          if (!gfxEnv::DisableForcePresent() && gfxWindowsPlatform::GetPlatform()->DwmCompositionEnabled()) {
             nsCOMPtr<nsIRunnable> event =
               NS_NewRunnableMethod(this, &nsWindow::ForcePresent);
             NS_DispatchToMainThread(event);
           }
         }
         break;
       default:
         NS_ERROR("Unknown layers backend used!");