Bug 1365660: Part 5c - Enable compositing for popups with remote content on OS-X. r?mstange draft
authorKris Maglione <maglione.k@gmail.com>
Wed, 17 May 2017 14:46:11 -0700
changeset 579868 f4a2a967c85e39314d0ca1cfd6a76feed2c6527d
parent 579867 61b0bbc674f69866e6113df0638e136be8013b88
child 580106 c56c434d9a4858b540529f9950bb82cc17348140
child 580852 7754cf81a858616a82961f6af620f9ba40347610
push id59389
push usermaglione.k@gmail.com
push dateWed, 17 May 2017 21:48:42 +0000
reviewersmstange
bugs1365660
milestone55.0a1
Bug 1365660: Part 5c - Enable compositing for popups with remote content on OS-X. r?mstange MozReview-Commit-ID: 90JJVJ2eR9C
widget/cocoa/nsChildView.mm
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -1416,27 +1416,33 @@ nsChildView::Invalidate(const LayoutDevi
   }
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 bool
 nsChildView::WidgetTypeSupportsAcceleration()
 {
+  // We need to enable acceleration in popups which contain remote layer
+  // trees, since the remote content won't be rendered at all otherwise. This
+  // causes issues with transparency and drop shadows, so it should not be
+  // used by default in release builds.
+  if (HasRemoteContent())
+    return true;
+
   // Don't use OpenGL for transparent windows or for popup windows.
   return mView && [[mView window] isOpaque] &&
          ![[mView window] isKindOfClass:[PopupWindow class]];
 }
 
 bool
 nsChildView::ShouldUseOffMainThreadCompositing()
 {
   // Don't use OMTC for transparent windows or for popup windows.
-  if (!mView || ![[mView window] isOpaque] ||
-      [[mView window] isKindOfClass:[PopupWindow class]])
+  if (!WidgetTypeSupportsAcceleration())
     return false;
 
   return nsBaseWidget::ShouldUseOffMainThreadCompositing();
 }
 
 inline uint16_t COLOR8TOCOLOR16(uint8_t color8)
 {
   // return (color8 == 0xFF ? 0xFFFF : (color8 << 8));
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -355,17 +355,18 @@ public:
     void SetPopupWindowLevel();
 
 protected:
   virtual ~nsCocoaWindow();
 
   nsresult             CreateNativeWindow(const NSRect &aRect,
                                           nsBorderStyle aBorderStyle,
                                           bool aRectIsFrameRect);
-  nsresult             CreatePopupContentView(const LayoutDeviceIntRect &aRect);
+  nsresult             CreatePopupContentView(const LayoutDeviceIntRect &aRect,
+                                              nsWidgetInitData* aInitData);
   void                 DestroyNativeWindow();
   void                 AdjustWindowShadow();
   void                 SetWindowBackgroundBlur();
   void                 UpdateBounds();
 
   void                 DoResize(double aX, double aY, double aWidth, double aHeight,
                                 bool aRepaint, bool aConstrainToCurrentScreen);
 
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -301,17 +301,17 @@ nsCocoaWindow::Create(nsIWidget* aParent
   if (mWindowType == eWindowType_popup) {
     if (aInitData->mMouseTransparent) {
       [mWindow setIgnoresMouseEvents:YES];
     }
     // now we can convert newBounds to device pixels for the window we created,
     // as the child view expects a rect expressed in the dev pix of its parent
     LayoutDeviceIntRect devRect =
       RoundedToInt(newBounds * GetDesktopToDeviceScale());
-    return CreatePopupContentView(devRect);
+    return CreatePopupContentView(devRect, aInitData);
   }
 
   mIsAnimationSuppressed = aInitData->mIsAnimationSuppressed;
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
@@ -468,17 +468,16 @@ nsresult nsCocoaWindow::CreateNativeWind
   UpdateBounds();
 
   if (mWindowType == eWindowType_invisible) {
     [mWindow setLevel:kCGDesktopWindowLevelKey];
   }
 
   if (mWindowType == eWindowType_popup) {
     SetPopupWindowLevel();
-    [mWindow setHasShadow:YES];
     [mWindow setBackgroundColor:[NSColor clearColor]];
     [mWindow setOpaque:NO];
   } else {
     // Make sure that regular windows are opaque from the start, so that
     // nsChildView::WidgetTypeSupportsAcceleration returns true for them.
     [mWindow setOpaque:YES];
   }
 
@@ -493,30 +492,31 @@ nsresult nsCocoaWindow::CreateNativeWind
   mWindowMadeHere = true;
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 nsresult
-nsCocoaWindow::CreatePopupContentView(const LayoutDeviceIntRect &aRect)
+nsCocoaWindow::CreatePopupContentView(const LayoutDeviceIntRect &aRect,
+                                      nsWidgetInitData* aInitData)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   // We need to make our content view a ChildView.
   mPopupContentView = new nsChildView();
   if (!mPopupContentView)
     return NS_ERROR_FAILURE;
 
   NS_ADDREF(mPopupContentView);
 
   nsIWidget* thisAsWidget = static_cast<nsIWidget*>(this);
   nsresult rv = mPopupContentView->Create(thisAsWidget, nullptr, aRect,
-                                          nullptr);
+                                          aInitData);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   ChildView* newContentView = (ChildView*)mPopupContentView->GetNativeData(NS_NATIVE_WIDGET);
   [mWindow setContentView:newContentView];
 
   return NS_OK;
@@ -2142,18 +2142,25 @@ nsCocoaWindow::SetWindowShadowStyle(int3
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if (!mWindow)
     return;
 
   mShadowStyle = aStyle;
 
   // Shadowless windows are only supported on popups.
-  if (mWindowType == eWindowType_popup)
-    [mWindow setHasShadow:(aStyle != NS_STYLE_WINDOW_SHADOW_NONE)];
+  if (mWindowType == eWindowType_popup) {
+    MOZ_ASSERT(mPopupContentView);
+
+    // Drop shadows are not sized correctly for composited popups when they are
+    // animated, so disable them entirely if the popup is composited.
+    bool disableShadow = (aStyle == NS_STYLE_WINDOW_SHADOW_NONE ||
+                          mPopupContentView->ShouldUseOffMainThreadCompositing());
+    [mWindow setHasShadow:!disableShadow];
+  }
 
   [mWindow setUseMenuStyle:(aStyle == NS_STYLE_WINDOW_SHADOW_MENU)];
   AdjustWindowShadow();
   SetWindowBackgroundBlur();
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }