Commit 54c54c7a authored by Kartikaya Gupta's avatar Kartikaya Gupta
Browse files

Bug 1315706 - Pass a wrapper struct to various CompositorWidget functions. r=dvander

This is the first step in using these functions without having a
LayerManagerComposite at all.

MozReview-Commit-ID: 2zkuB7Ox4Ut

--HG--
extra : rebase_source : b23988275f5851a2fd30bd3e8a9931107a224c66
parent 50ccc2b3
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include "mozilla/layers/Effects.h"     // for Effect, EffectChain, etc
#include "mozilla/layers/LayerMetricsWrapper.h" // for LayerMetricsWrapper
#include "mozilla/layers/LayersTypes.h"  // for etc
#include "mozilla/widget/CompositorWidget.h" // for WidgetRenderingContext
#include "ipc/CompositorBench.h"        // for CompositorBench
#include "ipc/ShadowLayerUtils.h"
#include "mozilla/mozalloc.h"           // for operator new, etc
@@ -911,11 +912,18 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi
    mLastFrameMissedHWC = !!composer2D;
  }

  mozilla::widget::WidgetRenderingContext widgetContext;
#if defined(XP_MACOSX)
  widgetContext.mLayerManager = this;
#elif defined(MOZ_WIDGET_ANDROID)
  widgetContext.mCompositor = GetCompositor();
#endif

  {
    PROFILER_LABEL("LayerManagerComposite", "PreRender",
      js::ProfileEntry::Category::GRAPHICS);

    if (!mCompositor->GetWidget()->PreRender(this)) {
    if (!mCompositor->GetWidget()->PreRender(&widgetContext)) {
      return;
    }
  }
@@ -946,13 +954,13 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi
  }

  if (actualBounds.IsEmpty()) {
    mCompositor->GetWidget()->PostRender(this);
    mCompositor->GetWidget()->PostRender(&widgetContext);
    return;
  }

  // Allow widget to render a custom background.
  mCompositor->GetWidget()->DrawWindowUnderlay(
    this, LayoutDeviceIntRect::FromUnknownRect(actualBounds));
    &widgetContext, LayoutDeviceIntRect::FromUnknownRect(actualBounds));

  RefPtr<CompositingRenderTarget> previousTarget;
  if (haveLayerEffects) {
@@ -980,7 +988,7 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi

  // Allow widget to render a custom foreground.
  mCompositor->GetWidget()->DrawWindowOverlay(
    this, LayoutDeviceIntRect::FromUnknownRect(actualBounds));
    &widgetContext, LayoutDeviceIntRect::FromUnknownRect(actualBounds));

  // Debugging
  RenderDebugOverlay(actualBounds);
@@ -999,7 +1007,7 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi
    composer2D->Render(mCompositor->GetWidget()->RealWidget());
  }

  mCompositor->GetWidget()->PostRender(this);
  mCompositor->GetWidget()->PostRender(&widgetContext);

  RecordFrame();
}
+16 −4
Original line number Diff line number Diff line
@@ -53,6 +53,18 @@ class CompositorWidgetChild;
# define MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING
#endif

class WidgetRenderingContext
{
public:
#if defined(XP_MACOSX)
  WidgetRenderingContext() : mLayerManager(nullptr) {}
  layers::LayerManagerComposite* mLayerManager;
#elif defined(MOZ_WIDGET_ANDROID)
  WidgetRenderingContext() : mCompositor(nullptr) {}
  layers::Compositor* mCompositor;
#endif
};

/**
 * Access to a widget from the compositor is restricted to these methods.
 */
@@ -74,7 +86,7 @@ public:
   * Always called from the compositing thread, which may be the main-thread if
   * OMTC is not enabled.
   */
  virtual bool PreRender(layers::LayerManagerComposite* aManager) {
  virtual bool PreRender(WidgetRenderingContext* aContext) {
    return true;
  }

@@ -85,7 +97,7 @@ public:
   * Always called from the compositing thread, which may be the main-thread if
   * OMTC is not enabled.
   */
  virtual void PostRender(layers::LayerManagerComposite* aManager)
  virtual void PostRender(WidgetRenderingContext* aContext)
  {}

  /**
@@ -93,7 +105,7 @@ public:
   *
   * Always called from the compositing thread.
   */
  virtual void DrawWindowUnderlay(layers::LayerManagerComposite* aManager,
  virtual void DrawWindowUnderlay(WidgetRenderingContext* aContext,
                                  LayoutDeviceIntRect aRect)
  {}

@@ -102,7 +114,7 @@ public:
   *
   * Always called from the compositing thread.
   */
  virtual void DrawWindowOverlay(layers::LayerManagerComposite* aManager,
  virtual void DrawWindowOverlay(WidgetRenderingContext* aContext,
                                 LayoutDeviceIntRect aRect)
  {}

+10 −10
Original line number Diff line number Diff line
@@ -33,29 +33,29 @@ InProcessCompositorWidget::InProcessCompositorWidget(nsBaseWidget* aWidget)
}

bool
InProcessCompositorWidget::PreRender(layers::LayerManagerComposite* aManager)
InProcessCompositorWidget::PreRender(WidgetRenderingContext* aContext)
{
  return mWidget->PreRender(aManager);
  return mWidget->PreRender(aContext);
}

void
InProcessCompositorWidget::PostRender(layers::LayerManagerComposite* aManager)
InProcessCompositorWidget::PostRender(WidgetRenderingContext* aContext)
{
  mWidget->PostRender(aManager);
  mWidget->PostRender(aContext);
}

void
InProcessCompositorWidget::DrawWindowUnderlay(layers::LayerManagerComposite* aManager,
InProcessCompositorWidget::DrawWindowUnderlay(WidgetRenderingContext* aContext,
                                              LayoutDeviceIntRect aRect)
{
  mWidget->DrawWindowUnderlay(aManager, aRect);
  mWidget->DrawWindowUnderlay(aContext, aRect);
}

void
InProcessCompositorWidget::DrawWindowOverlay(layers::LayerManagerComposite* aManager,
InProcessCompositorWidget::DrawWindowOverlay(WidgetRenderingContext* aContext,
                                             LayoutDeviceIntRect aRect)
{
  mWidget->DrawWindowOverlay(aManager, aRect);
  mWidget->DrawWindowOverlay(aContext, aRect);
}

already_AddRefed<gfx::DrawTarget>
+4 −4
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@ class InProcessCompositorWidget : public CompositorWidget
public:
  explicit InProcessCompositorWidget(nsBaseWidget* aWidget);

  virtual bool PreRender(layers::LayerManagerComposite* aManager) override;
  virtual void PostRender(layers::LayerManagerComposite* aManager) override;
  virtual void DrawWindowUnderlay(layers::LayerManagerComposite* aManager,
  virtual bool PreRender(WidgetRenderingContext* aManager) override;
  virtual void PostRender(WidgetRenderingContext* aManager) override;
  virtual void DrawWindowUnderlay(WidgetRenderingContext* aContext,
                                  LayoutDeviceIntRect aRect) override;
  virtual void DrawWindowOverlay(layers::LayerManagerComposite* aManager,
  virtual void DrawWindowOverlay(WidgetRenderingContext* aContext,
                                 LayoutDeviceIntRect aRect) override;
  virtual already_AddRefed<gfx::DrawTarget> StartRemoteDrawing() override;
  virtual already_AddRefed<gfx::DrawTarget>
+4 −4
Original line number Diff line number Diff line
@@ -3462,13 +3462,13 @@ nsWindow::SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
}

bool
nsWindow::PreRender(LayerManagerComposite* aManager)
nsWindow::PreRender(WidgetRenderingContext* aContext)
{
    if (Destroyed()) {
        return true;
    }

    layers::Compositor* compositor = aManager->GetCompositor();
    layers::Compositor* compositor = aContext->mCompositor;

    GeckoLayerClient::LocalRef client;

@@ -3484,7 +3484,7 @@ nsWindow::PreRender(LayerManagerComposite* aManager)
    return true;
}
void
nsWindow::DrawWindowUnderlay(LayerManagerComposite* aManager,
nsWindow::DrawWindowUnderlay(WidgetRenderingContext* aContext,
                             LayoutDeviceIntRect aRect)
{
    if (Destroyed()) {
@@ -3515,7 +3515,7 @@ nsWindow::DrawWindowUnderlay(LayerManagerComposite* aManager,
}

void
nsWindow::DrawWindowOverlay(LayerManagerComposite* aManager,
nsWindow::DrawWindowOverlay(WidgetRenderingContext* aContext,
                            LayoutDeviceIntRect aRect)
{
    PROFILER_LABEL("nsWindow", "DrawWindowOverlay",
Loading