Lift compositor-accessed methods from nsIWidget into CompositorWidgetProxy. (bug 1264545 part 2, r=jimm)
authorDavid Anderson <danderson@mozilla.com>
Fri, 29 Apr 2016 19:20:40 -0400
changeset 295588 d1dad3cf31c1590d30af46c2a93e8fdbe6fe8019
parent 295587 25d57a3a2abd86b4283c84b8380b49dd5cda33cb
child 295589 05519a5963f05ad386c2f61bc0b1ba57f3965477
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1264545
milestone49.0a1
Lift compositor-accessed methods from nsIWidget into CompositorWidgetProxy. (bug 1264545 part 2, r=jimm)
widget/CompositorWidgetProxy.h
widget/moz.build
widget/nsBaseWidget.h
widget/nsIWidget.h
new file mode 100644
--- /dev/null
+++ b/widget/CompositorWidgetProxy.h
@@ -0,0 +1,172 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_widget_CompositorWidgetProxy_h__
+#define mozilla_widget_CompositorWidgetProxy_h__
+
+#include "nsISupports.h"
+#include "mozilla/RefPtr.h"
+#include "Units.h"
+
+namespace mozilla {
+namespace layers {
+class LayerManagerComposite;
+class Compositor;
+class Composer2D;
+} // namespace layers
+namespace gfx {
+class DrawTarget;
+} // namespace gfx
+namespace widget {
+
+/**
+ * Access to a widget from the compositor is restricted to these methods.
+ */
+class CompositorWidgetProxy
+{
+public:
+  /**
+   * Called before rendering using OMTC. Returns false when the widget is
+   * not ready to be rendered (for example while the window is closed).
+   *
+   * Always called from the compositing thread, which may be the main-thread if
+   * OMTC is not enabled.
+   */
+  virtual bool PreRender(layers::LayerManagerComposite* aManager) {
+    return true;
+  }
+
+  /**
+   * Called after rendering using OMTC. Not called when rendering was
+   * cancelled by a negative return value from PreRender.
+   *
+   * Always called from the compositing thread, which may be the main-thread if
+   * OMTC is not enabled.
+   */
+  virtual void PostRender(layers::LayerManagerComposite* aManager)
+  {}
+
+  /**
+   * Called before the LayerManager draws the layer tree.
+   *
+   * Always called from the compositing thread.
+   */
+  virtual void DrawWindowUnderlay(layers::LayerManagerComposite* aManager,
+                                  LayoutDeviceIntRect aRect)
+  {}
+
+  /**
+   * Called after the LayerManager draws the layer tree
+   *
+   * Always called from the compositing thread.
+   */
+  virtual void DrawWindowOverlay(layers::LayerManagerComposite* aManager,
+                                 LayoutDeviceIntRect aRect)
+  {}
+
+  /**
+   * Return a DrawTarget for the window which can be composited into.
+   *
+   * Called by BasicCompositor on the compositor thread for OMTC drawing
+   * before each composition.
+   *
+   * The window may specify its buffer mode. If unspecified, it is assumed
+   * to require double-buffering.
+   */
+  virtual already_AddRefed<gfx::DrawTarget> StartRemoteDrawing() = 0;
+  virtual already_AddRefed<gfx::DrawTarget>
+  StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion,
+                             layers::BufferMode* aBufferMode)
+  {
+    return StartRemoteDrawing();
+  }
+
+  /**
+   * Ensure that what was painted into the DrawTarget returned from
+   * StartRemoteDrawing reaches the screen.
+   *
+   * Called by BasicCompositor on the compositor thread for OMTC drawing
+   * after each composition.
+   */
+  virtual void EndRemoteDrawing()
+  {}
+  virtual void EndRemoteDrawingInRegion(gfx::DrawTarget* aDrawTarget,
+                                        LayoutDeviceIntRegion& aInvalidRegion)
+  {
+    EndRemoteDrawing();
+  }
+
+  /**
+   * Clean up any resources used by Start/EndRemoteDrawing.
+   *
+   * Called by BasicCompositor on the compositor thread for OMTC drawing
+   * when the compositor is destroyed.
+   */
+  virtual void CleanupRemoteDrawing() = 0;
+
+  /**
+   * Called when shutting down the LayerManager to clean-up any cached resources.
+   *
+   * Always called from the compositing thread.
+   */
+  virtual void CleanupWindowEffects()
+  {}
+
+  /**
+   * Create DrawTarget used as BackBuffer of the screen
+   */
+  virtual already_AddRefed<gfx::DrawTarget>
+  CreateBackBufferDrawTarget(gfx::DrawTarget* aScreenTarget,
+                             const LayoutDeviceIntRect& aRect,
+                             const LayoutDeviceIntRect& aClearRect) = 0;
+
+  /**
+   * A hook for the widget to prepare a Compositor, during the latter's initialization.
+   *
+   * If this method returns true, it means that the widget will be able to
+   * present frames from the compoositor.
+   *
+   * Returning false will cause the compositor's initialization to fail, and
+   * a different compositor backend will be used (if any).
+   */
+  virtual bool InitCompositor(layers::Compositor* aCompositor) {
+    return true;
+  }
+
+  /**
+   * Return the size of the drawable area of the widget.
+   */
+  virtual LayoutDeviceIntSize GetClientSize() = 0;
+
+  /**
+   * Return the internal format of the default framebuffer for this
+   * widget.
+   */
+  virtual uint32_t GetGLFrameBufferFormat() {
+    return 0; /* GL_NONE */
+  }
+
+  /**
+   * If this widget has a more efficient composer available for its
+   * native framebuffer, return it.
+   *
+   * This can be called from a non-main thread, but that thread must
+   * hold a strong reference to this.
+   */
+  virtual layers::Composer2D* GetComposer2D() {
+    return nullptr;
+  }
+
+  /*
+   * Access the underlying nsIWidget. This method will be removed when the compositor no longer
+   * depends on nsIWidget on any platform.
+   */
+  virtual nsIWidget* RealWidget() = 0;
+};
+
+
+} // namespace widget
+} // namespace mozilla
+
+#endif
--- a/widget/moz.build
+++ b/widget/moz.build
@@ -82,16 +82,17 @@ XPIDL_SOURCES += [
     'nsIScreenManager.idl',
     'nsISound.idl',
     'nsITransferable.idl',
 ]
 
 XPIDL_MODULE = 'widget'
 
 EXPORTS += [
+    'CompositorWidgetProxy.h',
     'ContentHelper.h',
     'GfxDriverInfo.h',
     'GfxInfoBase.h',
     'GfxInfoCollector.h',
     'InputData.h',
     'nsBaseScreen.h',
     'nsBaseWidget.h',
     'nsDeviceContextSpecProxy.h',
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -350,16 +350,20 @@ public:
   friend class AutoLayerManagerSetup;
 
   virtual bool            ShouldUseOffMainThreadCompositing();
 
   static nsIRollupListener* GetActiveRollupListener();
 
   void Shutdown();
 
+  virtual nsIWidget* RealWidget() override {
+    return this;
+  }
+
 protected:
 
   void            ResolveIconName(const nsAString &aIconName,
                                   const nsAString &aIconSuffix,
                                   nsIFile **aResult);
   virtual void    OnDestroy();
   void            BaseCreate(nsIWidget *aParent,
                              nsWidgetInitData* aInitData);
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -26,16 +26,17 @@
 #include "mozilla/TimeStamp.h"
 #include "mozilla/gfx/Point.h"
 #include "mozilla/widget/IMEData.h"
 #include "nsDataHashtable.h"
 #include "nsIObserver.h"
 #include "nsIWidgetListener.h"
 #include "FrameMetrics.h"
 #include "Units.h"
+#include "CompositorWidgetProxy.h"
 
 // forward declarations
 class   nsIRollupListener;
 class   imgIContainer;
 class   nsIContent;
 class   ViewWrapper;
 class   nsIScreen;
 class   nsIRunnable;
@@ -317,17 +318,20 @@ private:
 
 } // namespace widget
 } // namespace mozilla
 
 /**
  * The base class for all the widgets. It provides the interface for
  * all basic and necessary functionality.
  */
-class nsIWidget : public nsISupports {
+class nsIWidget
+  : public nsISupports,
+    public mozilla::widget::CompositorWidgetProxy
+{
   protected:
     typedef mozilla::dom::TabChild TabChild;
 
   public:
     typedef mozilla::layers::Composer2D Composer2D;
     typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild;
     typedef mozilla::layers::AsyncDragMetrics AsyncDragMetrics;
     typedef mozilla::layers::FrameMetrics FrameMetrics;
@@ -1240,100 +1244,16 @@ class nsIWidget : public nsISupports {
      * Called before each layer manager transaction to allow any preparation
      * for DrawWindowUnderlay/Overlay that needs to be on the main thread.
      *
      * Always called on the main thread.
      */
     virtual void PrepareWindowEffects() = 0;
 
     /**
-     * Called when shutting down the LayerManager to clean-up any cached resources.
-     *
-     * Always called from the compositing thread, which may be the main-thread if
-     * OMTC is not enabled.
-     */
-    virtual void CleanupWindowEffects() = 0;
-
-    /**
-     * Called before rendering using OMTC. Returns false when the widget is
-     * not ready to be rendered (for example while the window is closed).
-     *
-     * Always called from the compositing thread, which may be the main-thread if
-     * OMTC is not enabled.
-     */
-    virtual bool PreRender(LayerManagerComposite* aManager) = 0;
-
-    /**
-     * Called after rendering using OMTC. Not called when rendering was
-     * cancelled by a negative return value from PreRender.
-     *
-     * Always called from the compositing thread, which may be the main-thread if
-     * OMTC is not enabled.
-     */
-    virtual void PostRender(LayerManagerComposite* aManager) = 0;
-
-    /**
-     * Called before the LayerManager draws the layer tree.
-     *
-     * Always called from the compositing thread.
-     */
-    virtual void DrawWindowUnderlay(LayerManagerComposite* aManager,
-                                    LayoutDeviceIntRect aRect) = 0;
-
-    /**
-     * Called after the LayerManager draws the layer tree
-     *
-     * Always called from the compositing thread.
-     */
-    virtual void DrawWindowOverlay(LayerManagerComposite* aManager,
-                                   LayoutDeviceIntRect aRect) = 0;
-
-    /**
-     * Return a DrawTarget for the window which can be composited into.
-     *
-     * Called by BasicCompositor on the compositor thread for OMTC drawing
-     * before each composition.
-     *
-     * The window may specify its buffer mode. If unspecified, it is assumed
-     * to require double-buffering.
-     */
-    virtual already_AddRefed<mozilla::gfx::DrawTarget> StartRemoteDrawing() = 0;
-    virtual already_AddRefed<mozilla::gfx::DrawTarget> StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion,
-                                                                                  mozilla::layers::BufferMode* aBufferMode) {
-      return StartRemoteDrawing();
-    }
-
-    /**
-     * Ensure that what was painted into the DrawTarget returned from
-     * StartRemoteDrawing reaches the screen.
-     *
-     * Called by BasicCompositor on the compositor thread for OMTC drawing
-     * after each composition.
-     */
-    virtual void EndRemoteDrawing() = 0;
-    virtual void EndRemoteDrawingInRegion(mozilla::gfx::DrawTarget* aDrawTarget, LayoutDeviceIntRegion& aInvalidRegion) {
-      EndRemoteDrawing();
-    }
-
-    /**
-     * Clean up any resources used by Start/EndRemoteDrawing.
-     *
-     * Called by BasicCompositor on the compositor thread for OMTC drawing
-     * when the compositor is destroyed.
-     */
-    virtual void CleanupRemoteDrawing() = 0;
-
-    /**
-     * Create DrawTarget used as BackBuffer of the screen
-     */
-    virtual already_AddRefed<mozilla::gfx::DrawTarget> CreateBackBufferDrawTarget(mozilla::gfx::DrawTarget* aScreenTarget,
-                                                                                  const LayoutDeviceIntRect& aRect,
-                                                                                  const LayoutDeviceIntRect& aClearRect) = 0;
-
-    /**
      * A hook for the widget to prepare a Compositor, during the latter's initialization.
      *
      * If this method returns true, it means that the widget will be able to
      * present frames from the compoositor.
      * Returning false will cause the compositor's initialization to fail, and
      * a different compositor backend will be used (if any).
      */
     virtual bool InitCompositor(mozilla::layers::Compositor*) { return true; }
@@ -2011,26 +1931,16 @@ public:
     /**
      * If this isn't directly compositing to its window surface,
      * return the compositor which is doing that on our behalf.
      */
     virtual CompositorBridgeChild* GetRemoteRenderer()
     { return nullptr; }
 
     /**
-     * If this widget has a more efficient composer available for its
-     * native framebuffer, return it.
-     *
-     * This can be called from a non-main thread, but that thread must
-     * hold a strong reference to this.
-     */
-    virtual Composer2D* GetComposer2D()
-    { return nullptr; }
-
-    /**
      * Some platforms (only cocoa right now) round widget coordinates to the
      * nearest even pixels (see bug 892994), this function allows us to
      * determine how widget coordinates will be rounded.
      */
     virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
 
     virtual void UpdateZoomConstraints(const uint32_t& aPresShellId,
                                        const FrameMetrics::ViewID& aViewId,