Bug 1592512 - Handle surface opacity of OS compositor surface on Windows r=gw
authorsotaro <sotaro.ikeda.g@gmail.com>
Fri, 08 Nov 2019 10:15:07 +0000
changeset 501243 91888af951c5e671b6cd76ecefc5c446f86765bd
parent 501242 e2ceb42ddbbff20868afb21dfee7be3ea89ea134
child 501244 52a6fac5e177f7c2b242855e1d4ecd0617ca4a51
push id36784
push userrgurzau@mozilla.com
push dateFri, 08 Nov 2019 21:36:09 +0000
treeherdermozilla-central@f414b9e6d857 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw
bugs1592512
milestone72.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 1592512 - Handle surface opacity of OS compositor surface on Windows r=gw Differential Revision: https://phabricator.services.mozilla.com/D52322
gfx/webrender_bindings/DCLayerTree.cpp
gfx/webrender_bindings/DCLayerTree.h
--- a/gfx/webrender_bindings/DCLayerTree.cpp
+++ b/gfx/webrender_bindings/DCLayerTree.cpp
@@ -211,17 +211,17 @@ void DCLayerTree::CreateSurface(wr::Nati
   // MOZ_RELEASE_ASSERT(it == mDCLayers.end());
   MOZ_ASSERT(it == mDCLayers.end());
   if (it != mDCLayers.end()) {
     // DCLayer already exists.
     return;
   }
 
   auto layer = MakeUnique<DCLayer>(this);
-  if (!layer->Initialize(aSize)) {
+  if (!layer->Initialize(aSize, aIsOpaque)) {
     gfxCriticalNote << "Failed to initialize DCLayer";
     return;
   }
 
   mDCLayers[wr::AsUint64(aId)] = std::move(layer);
 }
 
 void DCLayerTree::DestroySurface(NativeSurfaceId aId) {
@@ -265,51 +265,50 @@ void DCLayerTree::AddSurface(wr::NativeS
   visual->SetClip(clip_rect);
 }
 
 DCLayer::DCLayer(DCLayerTree* aDCLayerTree)
     : mDCLayerTree(aDCLayerTree), mEGLSurface(EGL_NO_SURFACE) {}
 
 DCLayer::~DCLayer() { DestroyEGLSurface(); }
 
-bool DCLayer::Initialize(wr::DeviceIntSize aSize) {
+bool DCLayer::Initialize(wr::DeviceIntSize aSize, bool aIsOpaque) {
   if (aSize.width <= 0 || aSize.height <= 0) {
     return false;
   }
   mBufferSize = LayoutDeviceIntSize(aSize.width, aSize.height);
 
   HRESULT hr;
   const auto dCompDevice = mDCLayerTree->GetCompositionDevice();
   hr = dCompDevice->CreateVisual(getter_AddRefs(mVisual));
   if (FAILED(hr)) {
     gfxCriticalNote << "Failed to create DCompositionVisual: " << gfx::hexa(hr);
     return false;
   }
 
-  // XXX Always request alpha usage. But it could degrade performance.
-  mCompositionSurface = CreateCompositionSurface(aSize, /* aUseAlpha */ true);
+  mCompositionSurface = CreateCompositionSurface(aSize, aIsOpaque);
   if (!mCompositionSurface) {
     return false;
   }
 
   hr = mVisual->SetContent(mCompositionSurface);
   if (FAILED(hr)) {
     gfxCriticalNote << "SetContent failed: " << gfx::hexa(hr);
     return false;
   }
 
   return true;
 }
 
 RefPtr<IDCompositionSurface> DCLayer::CreateCompositionSurface(
-    wr::DeviceIntSize aSize, bool aUseAlpha) {
+    wr::DeviceIntSize aSize, bool aIsOpaque) {
   HRESULT hr;
   const auto dCompDevice = mDCLayerTree->GetCompositionDevice();
   const auto alphaMode =
-      aUseAlpha ? DXGI_ALPHA_MODE_PREMULTIPLIED : DXGI_ALPHA_MODE_IGNORE;
+      aIsOpaque ? DXGI_ALPHA_MODE_IGNORE : DXGI_ALPHA_MODE_PREMULTIPLIED;
   RefPtr<IDCompositionSurface> compositionSurface;
 
   hr = dCompDevice->CreateSurface(aSize.width, aSize.height,
                                   DXGI_FORMAT_B8G8R8A8_UNORM, alphaMode,
                                   getter_AddRefs(compositionSurface));
   if (FAILED(hr)) {
     gfxCriticalNote << "Failed to create DCompositionSurface: "
                     << gfx::hexa(hr);
--- a/gfx/webrender_bindings/DCLayerTree.h
+++ b/gfx/webrender_bindings/DCLayerTree.h
@@ -95,30 +95,30 @@ class DCLayerTree {
 
   std::unordered_map<uint64_t, UniquePtr<DCLayer>> mDCLayers;
 };
 
 class DCLayer {
  public:
   explicit DCLayer(DCLayerTree* aDCLayerTree);
   ~DCLayer();
-  bool Initialize(wr::DeviceIntSize aSize);
+  bool Initialize(wr::DeviceIntSize aSize, bool aIsOpaque);
   bool CreateEGLSurfaceForCompositionSurface(wr::DeviceIntRect aDirtyRect,
                                              wr::DeviceIntPoint* aOffset);
   void EndDraw();
 
   IDCompositionSurface* GetCompositionSurface() const {
     return mCompositionSurface;
   }
   EGLSurface GetEGLSurface() const { return mEGLSurface; }
   IDCompositionVisual2* GetVisual() const { return mVisual; }
 
  protected:
   RefPtr<IDCompositionSurface> CreateCompositionSurface(wr::DeviceIntSize aSize,
-                                                        bool aUseAlpha);
+                                                        bool aIsOpaque);
   void DestroyEGLSurface();
 
  protected:
   DCLayerTree* mDCLayerTree;
 
   RefPtr<IDCompositionSurface> mCompositionSurface;
 
   LayoutDeviceIntSize mBufferSize;