Commit 7b301640 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1742358 - Set default clear color to widget window background on expose,...

Bug 1742358 - Set default clear color to widget window background on expose, and reset it on first contentful paint. r=jrmuizel,stransky

Differential Revision: https://phabricator.services.mozilla.com/D135075
parent 4bd69494
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ parent:
  sync GetSnapshot(PTexture texture) returns (bool aNeedsYFlip);
  async SetLayersObserverEpoch(LayersObserverEpoch childEpoch);
  async ClearCachedResources();
  async SetDefaultClearColor(uint32_t aColor);
  // Invalidate rendered frame
  async InvalidateRenderedFrame();
  // Schedule a composite if one isn't already scheduled.
+6 −0
Original line number Diff line number Diff line
@@ -2561,6 +2561,12 @@ void WebRenderBridgeParent::FlushRendering(wr::RenderReasons aReasons,
  }
}

ipc::IPCResult WebRenderBridgeParent::RecvSetDefaultClearColor(
    const uint32_t& aColor) {
  SetClearColor(gfx::DeviceColor::FromABGR(aColor));
  return IPC_OK();
}

void WebRenderBridgeParent::SetClearColor(const gfx::DeviceColor& aColor) {
  MOZ_ASSERT(IsRootWebRenderBridgeParent());

+2 −0
Original line number Diff line number Diff line
@@ -172,6 +172,8 @@ class WebRenderBridgeParent final : public PWebRenderBridgeParent,

  void ActorDestroy(ActorDestroyReason aWhy) override;

  mozilla::ipc::IPCResult RecvSetDefaultClearColor(
      const uint32_t& aColor) override;
  void SetClearColor(const gfx::DeviceColor& aColor);

  void Pause();
+36 −30
Original line number Diff line number Diff line
@@ -2593,18 +2593,25 @@ void nsPresContext::NotifyNonBlankPaint() {
}

void nsPresContext::NotifyContentfulPaint() {
  if (mHadContentfulPaint) {
    return;
  }
  nsRootPresContext* rootPresContext = GetRootPresContext();
  if (!rootPresContext) {
    return;
  }
  if (!mHadContentfulPaint) {
#if defined(MOZ_WIDGET_ANDROID)
  if (!mHadNonTickContentfulPaint) {
#ifdef MOZ_WIDGET_ANDROID
    (new AsyncEventDispatcher(mDocument, u"MozFirstContentfulPaint"_ns,
                              CanBubble::eYes, ChromeOnlyDispatch::eYes))
        ->PostDOMEvent();
    }
#endif
    if (rootPresContext == this && IsChrome()) {
      if (nsCOMPtr<nsIWidget> rootWidget = GetRootWidget()) {
        rootWidget->DidGetContentfulPaint();
      }
    }
  }
  if (!rootPresContext->RefreshDriver()->IsInRefresh()) {
    if (!mHadNonTickContentfulPaint) {
      rootPresContext->RefreshDriver()
@@ -2632,7 +2639,6 @@ void nsPresContext::NotifyContentfulPaint() {
    }
  }
}
}

void nsPresContext::NotifyPaintStatusReset() {
  mHadNonBlankPaint = false;
+25 −2
Original line number Diff line number Diff line
@@ -414,8 +414,9 @@ nsWindow::nsWindow()
      mPopupClosed(false),
      mPopupUseMoveToRect(false),
      mPreferredPopupRectFlushed(false),
      mWaitingForMoveToRectCallback(false)
{
      mWaitingForMoveToRectCallback(false),
      mConfiguredClearColor(false),
      mGotContentfulPaint(false) {
  mWindowType = eWindowType_child;
  mSizeConstraints.mMaxSize = GetSafeWindowSize(mSizeConstraints.mMaxSize);

@@ -3524,6 +3525,13 @@ gboolean nsWindow::OnExposeEvent(cairo_t* cr) {
  KnowsCompositor* knowsCompositor = renderer->AsKnowsCompositor();

  if (knowsCompositor && layerManager && mCompositorSession) {
    if (!mConfiguredClearColor && !mParent) {
      layerManager->WrBridge()->SendSetDefaultClearColor(LookAndFeel::Color(
          LookAndFeel::ColorID::Window, LookAndFeel::ColorSchemeForChrome(),
          LookAndFeel::UseStandins::No));
      mConfiguredClearColor = true;
    }

    // We need to paint to the screen even if nothing changed, since if we
    // don't have a compositing window manager, our pixels could be stale.
    layerManager->SetNeedsComposite(true);
@@ -8368,6 +8376,21 @@ nsIWidget::WindowRenderer* nsWindow::GetWindowRenderer() {
  return nsBaseWidget::GetWindowRenderer();
}

void nsWindow::DidGetContentfulPaint() {
  if (mGotContentfulPaint) {
    return;
  }
  mGotContentfulPaint = true;
  if (!mConfiguredClearColor) {
    // Nothing to do, we hadn't overridden the clear color.
    mConfiguredClearColor = true;
    return;
  }
  // Reset the clear color set in the expose event to transparent.
  GetWindowRenderer()->AsWebRender()->WrBridge()->SendSetDefaultClearColor(
      NS_TRANSPARENT);
}

/* nsWindow::SetCompositorWidgetDelegate() sets remote GtkCompositorWidget
 * to render into with compositor.
 *
Loading