Bug 1593325 - Use NextSurfaceAsDrawTarget in nsChildView. r=mattwoodrow
authorMarkus Stange <mstange@themasta.com>
Tue, 05 Nov 2019 18:59:36 +0000
changeset 500655 08e402640f7e00dcdf86b194c1eaa6c07b01626f
parent 500654 12df7898b0eee9b11ed6189769f2a6199d93d4e1
child 500656 1975423d6915e495f40e592325e5d0e9894aecb9
push id36769
push userncsoregi@mozilla.com
push dateWed, 06 Nov 2019 09:57:42 +0000
treeherdermozilla-central@d73cfe3a04e9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1593325
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 1593325 - Use NextSurfaceAsDrawTarget in nsChildView. r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D50876
gfx/layers/NativeLayerCA.h
gfx/layers/NativeLayerCA.mm
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
--- a/gfx/layers/NativeLayerCA.h
+++ b/gfx/layers/NativeLayerCA.h
@@ -115,27 +115,16 @@ class NativeLayerCA : public NativeLayer
   void NotifySurfaceReady() override;
   void SetIsOpaque(bool aIsOpaque) override;
   bool IsOpaque() override;
   void SetClipRect(const Maybe<gfx::IntRect>& aClipRect) override;
   Maybe<gfx::IntRect> ClipRect() override;
   void SetSurfaceIsFlipped(bool aIsFlipped) override;
   bool SurfaceIsFlipped() override;
 
-  // Returns an IOSurface that can be drawn to. The size of the IOSurface will
-  // be the size of the rect that has been passed to SetRect.
-  // The returned surface is guaranteed to be not in use by the window server.
-  // After a call to NextSurface, NextSurface must not be called again until
-  // after NotifySurfaceReady has been called. Can be called on any thread. When
-  // used from multiple threads, callers need to make sure that they still only
-  // call NextSurface and NotifySurfaceReady alternatingly and not in any other
-  // order.
-  CFTypeRefPtr<IOSurfaceRef> NextSurface();
-  CFTypeRefPtr<IOSurfaceRef> NextSurfaceLocked(const MutexAutoLock&);
-
   // Consumers may provide an object that implements the IOSurfaceRegistry
   // interface.
   // The registry's methods, Register/UnregisterSurface, will be called
   // synchronously during calls to NextSurface(), SetSurfaceRegistry(), and the
   // NativeLayer destructor, on the thread that those things happen to run on.
   // If this layer already owns surfaces when SetSurfaceRegistry gets called
   // with a non-null surface registry, those surfaces will immediately
   // (synchronously) be registered with that registry. If the current surface
@@ -150,16 +139,26 @@ class NativeLayerCA : public NativeLayer
   RefPtr<IOSurfaceRegistry> GetSurfaceRegistry();
 
  protected:
   friend class NativeLayerRootCA;
 
   NativeLayerCA();
   ~NativeLayerCA() override;
 
+  // Returns an IOSurface that can be drawn to. The size of the IOSurface will
+  // be the size of the rect that has been passed to SetRect.
+  // The returned surface is guaranteed to be not in use by the window server.
+  // After a call to NextSurface, NextSurface must not be called again until
+  // after NotifySurfaceReady has been called. Can be called on any thread. When
+  // used from multiple threads, callers need to make sure that they still only
+  // call NextSurface and NotifySurfaceReady alternatingly and not in any other
+  // order.
+  CFTypeRefPtr<IOSurfaceRef> NextSurface(const MutexAutoLock&);
+
   // To be called by NativeLayerRootCA:
   CALayer* UnderlyingCALayer() { return mWrappingCALayer; }
   void ApplyChanges();
   void SetBackingScale(float aBackingScale);
 
   GLuint GetOrCreateFramebufferForSurface(const MutexAutoLock&,
                                           CFTypeRefPtr<IOSurfaceRef> aSurface,
                                           bool aNeedsDepth);
--- a/gfx/layers/NativeLayerCA.mm
+++ b/gfx/layers/NativeLayerCA.mm
@@ -282,22 +282,17 @@ void NativeLayerCA::InvalidateRegionThro
   if (mReadySurface) {
     mReadySurface->mInvalidRegion.OrWith(r);
   }
   for (auto& surf : mSurfaces) {
     surf.mInvalidRegion.OrWith(r);
   }
 }
 
-CFTypeRefPtr<IOSurfaceRef> NativeLayerCA::NextSurface() {
-  MutexAutoLock lock(mMutex);
-  return NextSurfaceLocked(lock);
-}
-
-CFTypeRefPtr<IOSurfaceRef> NativeLayerCA::NextSurfaceLocked(const MutexAutoLock& aLock) {
+CFTypeRefPtr<IOSurfaceRef> NativeLayerCA::NextSurface(const MutexAutoLock& aLock) {
   IntSize surfaceSize = mSize;
   if (surfaceSize.IsEmpty()) {
     NSLog(@"NextSurface returning nullptr because of invalid surfaceSize (%d, %d).",
           surfaceSize.width, surfaceSize.height);
     return nullptr;
   }
 
   MOZ_RELEASE_ASSERT(
@@ -351,17 +346,17 @@ CFTypeRefPtr<IOSurfaceRef> NativeLayerCA
   MOZ_RELEASE_ASSERT(surf);
   mInProgressSurface = std::move(surf);
   IOSurfaceIncrementUseCount(mInProgressSurface->mSurface.get());
   return mInProgressSurface->mSurface;
 }
 
 RefPtr<gfx::DrawTarget> NativeLayerCA::NextSurfaceAsDrawTarget(gfx::BackendType aBackendType) {
   MutexAutoLock lock(mMutex);
-  CFTypeRefPtr<IOSurfaceRef> surface = NextSurfaceLocked(lock);
+  CFTypeRefPtr<IOSurfaceRef> surface = NextSurface(lock);
   if (!surface) {
     return nullptr;
   }
 
   mInProgressLockedIOSurface = new MacIOSurface(std::move(surface));
   mInProgressLockedIOSurface->Lock(false);
   return mInProgressLockedIOSurface->GetAsDrawTargetLocked(aBackendType);
 }
@@ -380,17 +375,17 @@ void NativeLayerCA::SetGLContext(gl::GLC
 
 gl::GLContext* NativeLayerCA::GetGLContext() {
   MutexAutoLock lock(mMutex);
   return mGLContext;
 }
 
 Maybe<GLuint> NativeLayerCA::NextSurfaceAsFramebuffer(bool aNeedsDepth) {
   MutexAutoLock lock(mMutex);
-  CFTypeRefPtr<IOSurfaceRef> surface = NextSurfaceLocked(lock);
+  CFTypeRefPtr<IOSurfaceRef> surface = NextSurface(lock);
   if (!surface) {
     return Nothing();
   }
 
   return Some(GetOrCreateFramebufferForSurface(lock, std::move(surface), aNeedsDepth));
 }
 
 GLuint NativeLayerCA::GetOrCreateFramebufferForSurface(const MutexAutoLock&,
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -21,17 +21,16 @@
 #include "gfxQuartzSurface.h"
 #include "GLContextTypes.h"
 #include "mozilla/DataMutex.h"
 #include "mozilla/Mutex.h"
 #include "nsRegion.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/webrender/WebRenderTypes.h"
-#include "mozilla/gfx/MacIOSurface.h"
 
 #include "nsString.h"
 #include "nsIDragService.h"
 #include "ViewRegion.h"
 #include "CFTypeRefPtr.h"
 
 #import <Carbon/Carbon.h>
 #import <Cocoa/Cocoa.h>
@@ -473,18 +472,16 @@ class nsChildView final : public nsBaseW
   virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event);
 
   void WillPaintWindow();
   bool PaintWindow(LayoutDeviceIntRegion aRegion);
   bool PaintWindowInDrawTarget(mozilla::gfx::DrawTarget* aDT, const LayoutDeviceIntRegion& aRegion,
                                const mozilla::gfx::IntSize& aSurfaceSize);
   bool PaintWindowInContext(CGContextRef aContext, const LayoutDeviceIntRegion& aRegion,
                             mozilla::gfx::IntSize aSurfaceSize);
-  bool PaintWindowInIOSurface(CFTypeRefPtr<IOSurfaceRef> aSurface,
-                              const LayoutDeviceIntRegion& aInvalidRegion);
 
   void PaintWindowInContentLayer();
   void HandleMainThreadCATransaction();
 
 #ifdef ACCESSIBILITY
   already_AddRefed<mozilla::a11y::Accessible> GetDocumentAccessible();
 #endif
 
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -6,18 +6,16 @@
 #include "mozilla/ArrayUtils.h"
 
 #include "mozilla/Logging.h"
 #include "mozilla/Unused.h"
 
 #include <unistd.h>
 #include <math.h>
 
-#include <IOSurface/IOSurface.h>
-
 #include "nsChildView.h"
 #include "nsCocoaWindow.h"
 
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/PresShell.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
@@ -83,17 +81,16 @@
 #include "mozilla/layers/NativeLayerCA.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 #include "mozilla/widget/CompositorWidget.h"
 #include "gfxUtils.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/BorrowedContext.h"
-#include "mozilla/gfx/MacIOSurface.h"
 #ifdef ACCESSIBILITY
 #  include "nsAccessibilityService.h"
 #  include "mozilla/a11y/Platform.h"
 #endif
 
 #include "mozilla/Preferences.h"
 #include "mozilla/StaticPrefs_apz.h"
 #include "mozilla/StaticPrefs_general.h"
@@ -1488,26 +1485,16 @@ bool nsChildView::PaintWindowInContext(C
   CGDataProviderRelease(provider);
   CGContextRestoreGState(aContext);
 
   mBackingSurface->ReleaseBits(data);
 
   return painted;
 }
 
-bool nsChildView::PaintWindowInIOSurface(CFTypeRefPtr<IOSurfaceRef> aSurface,
-                                         const LayoutDeviceIntRegion& aInvalidRegion) {
-  RefPtr<MacIOSurface> surf = new MacIOSurface(std::move(aSurface));
-  surf->Lock(false);
-  RefPtr<gfx::DrawTarget> dt = surf->GetAsDrawTargetLocked(gfx::BackendType::SKIA);
-  bool result = PaintWindowInDrawTarget(dt, aInvalidRegion, dt->GetSize());
-  surf->Unlock(false);
-  return result;
-}
-
 void nsChildView::EnsureContentLayerForMainThreadPainting() {
   if (!mContentLayer) {
     // The content layer gets created on demand for BasicLayers windows. We do
     // not create it during widget creation because, for non-BasicLayers windows,
     // the compositing layer manager will create any layers it needs.
     RefPtr<NativeLayer> contentLayer = mNativeLayerRoot->CreateLayer();
     mNativeLayerRoot->AppendLayer(contentLayer);
     mContentLayer = contentLayer->AsNativeLayerCA();
@@ -1518,23 +1505,24 @@ void nsChildView::PaintWindowInContentLa
   EnsureContentLayerForMainThreadPainting();
   mContentLayer->SetRect(GetBounds().ToUnknownRect());
   {
     auto opaqueRegion = mOpaqueRegion.Lock();
     bool isOpaque = *opaqueRegion == GetBounds();
     mContentLayer->SetIsOpaque(isOpaque);
   }
   mContentLayer->SetSurfaceIsFlipped(false);
-  CFTypeRefPtr<IOSurfaceRef> surf = mContentLayer->NextSurface();
-  if (!surf) {
+  RefPtr<DrawTarget> dt = mContentLayer->NextSurfaceAsDrawTarget(gfx::BackendType::SKIA);
+  if (!dt) {
     return;
   }
 
-  PaintWindowInIOSurface(
-      surf, LayoutDeviceIntRegion::FromUnknownRegion(mContentLayer->CurrentSurfaceInvalidRegion()));
+  PaintWindowInDrawTarget(
+      dt, LayoutDeviceIntRegion::FromUnknownRegion(mContentLayer->CurrentSurfaceInvalidRegion()),
+      dt->GetSize());
   mContentLayer->NotifySurfaceReady();
 }
 
 void nsChildView::HandleMainThreadCATransaction() {
   WillPaintWindow();
 
   if (GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_BASIC) {
     // We're in BasicLayers mode, i.e. main thread software compositing.