Skip to content

Commit

Permalink
Bug 974197 - Fire MozAfterPaint after the compositor has composited t…
Browse files Browse the repository at this point in the history
…he frame. r=roc
  • Loading branch information
mattwoodrow committed Mar 7, 2014
1 parent c21c953 commit b4d6205
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 10 deletions.
1 change: 1 addition & 0 deletions b2g/app/b2g.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pref("ui.dragThresholdY", 25);
pref("layers.offmainthreadcomposition.enabled", true);
#ifndef MOZ_WIDGET_GONK
pref("dom.ipc.tabs.disabled", true);
pref("layers.acceleration.disabled", true);
pref("layers.offmainthreadcomposition.async-animations", false);
pref("layers.async-video.enabled", false);
#else
Expand Down
43 changes: 43 additions & 0 deletions dom/ipc/TabChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "ipc/nsGUIEventIPC.h"
#include "mozilla/gfx/Matrix.h"
#include "UnitTransforms.h"
#include "ClientLayerManager.h"

#include "nsColorPickerProxy.h"

Expand Down Expand Up @@ -105,6 +106,9 @@ static bool sCpowsEnabled = false;
static int32_t sActiveDurationMs = 10;
static bool sActiveDurationMsSet = false;

typedef nsDataHashtable<nsUint64HashKey, TabChild*> TabChildMap;
static TabChildMap* sTabChildren;

TabChildBase::TabChildBase()
: mOldViewportWidth(0.0f)
, mContentDocumentIsDisplayed(false)
Expand Down Expand Up @@ -669,6 +673,7 @@ TabChild::TabChild(ContentChild* aManager, const TabContext& aContext, uint32_t
, mRemoteFrame(nullptr)
, mManager(aManager)
, mChromeFlags(aChromeFlags)
, mLayersId(0)
, mOuterRect(0, 0, 0, 0)
, mActivePointerId(-1)
, mTapHoldTimer(nullptr)
Expand Down Expand Up @@ -1293,6 +1298,17 @@ TabChild::DestroyWindow()
mRemoteFrame->Destroy();
mRemoteFrame = nullptr;
}


if (mLayersId != 0) {
MOZ_ASSERT(sTabChildren);
sTabChildren->Remove(mLayersId);
if (!sTabChildren->Count()) {
delete sTabChildren;
sTabChildren = nullptr;
}
mLayersId = 0;
}
}

bool
Expand Down Expand Up @@ -2387,6 +2403,13 @@ TabChild::InitRenderingState()
ImageBridgeChild::IdentifyCompositorTextureHost(mTextureFactoryIdentifier);

mRemoteFrame = remoteFrame;
if (id != 0) {
if (!sTabChildren) {
sTabChildren = new TabChildMap;
}
sTabChildren->Put(id, this);
mLayersId = id;
}

nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
Expand Down Expand Up @@ -2583,6 +2606,26 @@ TabChild::GetFrom(nsIPresShell* aPresShell)
return GetFrom(docShell);
}

TabChild*
TabChild::GetFrom(uint64_t aLayersId)
{
if (!sTabChildren) {
return nullptr;
}
return sTabChildren->Get(aLayersId);
}

void
TabChild::DidComposite()
{
MOZ_ASSERT(mWidget);
MOZ_ASSERT(mWidget->GetLayerManager());
MOZ_ASSERT(mWidget->GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_CLIENT);

ClientLayerManager *manager = static_cast<ClientLayerManager*>(mWidget->GetLayerManager());
manager->DidComposite();
}

NS_IMETHODIMP
TabChild::OnShowTooltip(int32_t aXCoords, int32_t aYCoords, const char16_t *aTipText)
{
Expand Down
4 changes: 4 additions & 0 deletions dom/ipc/TabChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ class TabChild : public PBrowserChild,
}

static TabChild* GetFrom(nsIPresShell* aPresShell);
static TabChild* GetFrom(uint64_t aLayersId);

void DidComposite();

static inline TabChild*
GetFrom(nsIDOMWindow* aWindow)
Expand Down Expand Up @@ -514,6 +517,7 @@ class TabChild : public PBrowserChild,
RenderFrameChild* mRemoteFrame;
nsRefPtr<ContentChild> mManager;
uint32_t mChromeFlags;
uint64_t mLayersId;
nsIntRect mOuterRect;
// When we're tracking a possible tap gesture, this is the "down"
// point of the touchstart.
Expand Down
15 changes: 15 additions & 0 deletions gfx/layers/client/ClientLayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "mozilla/layers/SimpleTextureClientPool.h" // for SimpleTextureClientPool
#include "nsAString.h"
#include "nsIWidget.h" // for nsIWidget
#include "nsIWidgetListener.h"
#include "nsTArray.h" // for AutoInfallibleTArray
#include "nsXULAppAPI.h" // for XRE_GetProcessType, etc
#include "TiledLayerBuffer.h"
Expand Down Expand Up @@ -271,6 +272,20 @@ ClientLayerManager::Composite()
}
}

void
ClientLayerManager::DidComposite()
{
MOZ_ASSERT(mWidget);
nsIWidgetListener *listener = mWidget->GetWidgetListener();
if (listener) {
listener->DidCompositeWindow();
}
listener = mWidget->GetAttachedWidgetListener();
if (listener) {
listener->DidCompositeWindow();
}
}

void
ClientLayerManager::MakeSnapshotIfRequired()
{
Expand Down
2 changes: 2 additions & 0 deletions gfx/layers/client/ClientLayerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class ClientLayerManager : public LayerManager

virtual void Composite() MOZ_OVERRIDE;

virtual void DidComposite();

protected:
enum TransactionPhase {
PHASE_NONE, PHASE_CONSTRUCTION, PHASE_DRAWING, PHASE_FORWARD
Expand Down
16 changes: 16 additions & 0 deletions gfx/layers/ipc/CompositorChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "nsTArray.h" // for nsTArray, nsTArray_Impl
#include "nsXULAppAPI.h" // for XRE_GetIOMessageLoop, etc
#include "FrameLayerBuilder.h"
#include "mozilla/dom/TabChild.h"

using mozilla::layers::LayerTransactionChild;

Expand Down Expand Up @@ -120,6 +121,21 @@ CompositorChild::RecvInvalidateAll()
return true;
}

bool
CompositorChild::RecvDidComposite(const uint64_t& aId)
{
if (mLayerManager) {
MOZ_ASSERT(aId == 0);
mLayerManager->DidComposite();
} else if (aId != 0) {
dom::TabChild *child = dom::TabChild::GetFrom(aId);
if (child) {
child->DidComposite();
}
}
return true;
}

void
CompositorChild::ActorDestroy(ActorDestroyReason aWhy)
{
Expand Down
2 changes: 2 additions & 0 deletions gfx/layers/ipc/CompositorChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class CompositorChild MOZ_FINAL : public PCompositorChild

virtual bool RecvInvalidateAll() MOZ_OVERRIDE;

virtual bool RecvDidComposite(const uint64_t& aId) MOZ_OVERRIDE;

private:
// Private destructor, to discourage deletion outside of Release():
virtual ~CompositorChild();
Expand Down
24 changes: 24 additions & 0 deletions gfx/layers/ipc/CompositorParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#endif
#include "GeckoProfiler.h"
#include "mozilla/ipc/ProtocolTypes.h"
#include "mozilla/unused.h"

using namespace base;
using namespace mozilla;
Expand Down Expand Up @@ -188,6 +189,7 @@ CompositorParent::CompositorParent(nsIWidget* aWidget,
, mResumeCompositionMonitor("ResumeCompositionMonitor")
, mOverrideComposeReadiness(false)
, mForceCompositionTask(nullptr)
, mWantDidCompositeEvent(false)
{
NS_ABORT_IF_FALSE(sCompositorThread != nullptr || sCompositorThreadID,
"The compositor thread must be Initialized before instanciating a COmpositorParent.");
Expand Down Expand Up @@ -522,6 +524,8 @@ CompositorParent::NotifyShadowTreeTransaction(uint64_t aId, bool aIsFirstPaint,
if (aScheduleComposite) {
ScheduleComposition();
}

mWantDidCompositeEvent = true;
}

// Used when layout.frame_rate is -1. Needs to be kept in sync with
Expand Down Expand Up @@ -651,6 +655,11 @@ CompositorParent::CompositeToTarget(DrawTarget* aTarget)
mLayerManager->SetDebugOverlayWantsNextFrame(false);
mLayerManager->EndEmptyTransaction();

if (!aTarget && mWantDidCompositeEvent) {
DidComposite();
mWantDidCompositeEvent = false;
}

if (mLayerManager->DebugOverlayWantsNextFrame()) {
ScheduleComposition();
}
Expand Down Expand Up @@ -678,6 +687,20 @@ CompositorParent::CompositeToTarget(DrawTarget* aTarget)
profiler_tracing("Paint", "Composite", TRACING_INTERVAL_END);
}

void
CompositorParent::DidComposite()
{
unused << SendDidComposite(0);

for (LayerTreeMap::iterator it = sIndirectLayerTrees.begin();
it != sIndirectLayerTrees.end(); it++) {
LayerTreeState* lts = &it->second;
if (lts->mParent == this && lts->mCrossProcessParent) {
unused << lts->mCrossProcessParent->SendDidComposite(it->first);
}
}
}

void
CompositorParent::ForceComposeToTarget(DrawTarget* aTarget)
{
Expand Down Expand Up @@ -766,6 +789,7 @@ CompositorParent::ShadowLayersUpdated(LayerTransactionParent* aLayerTree,
}
}
mLayerManager->NotifyShadowTreeTransaction();
mWantDidCompositeEvent = true;
}

void
Expand Down
4 changes: 4 additions & 0 deletions gfx/layers/ipc/CompositorParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ class CompositorParent MOZ_FINAL : public PCompositorParent,
*/
bool CanComposite();

void DidComposite();

nsRefPtr<LayerManagerComposite> mLayerManager;
nsRefPtr<Compositor> mCompositor;
RefPtr<AsyncCompositionManager> mCompositionManager;
Expand Down Expand Up @@ -328,6 +330,8 @@ class CompositorParent MOZ_FINAL : public PCompositorParent,

nsRefPtr<APZCTreeManager> mApzcTreeManager;

bool mWantDidCompositeEvent;

DISALLOW_EVIL_CONSTRUCTORS(CompositorParent);
};

Expand Down
5 changes: 5 additions & 0 deletions gfx/layers/ipc/PCompositor.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ child:
// The child should invalidate everything so that the whole window is redrawn.
async InvalidateAll();

// The compositor completed a layers transaction. id is the layers id
// of the child layer tree that was composited (or 0 when notifying
// the root layer tree).
async DidComposite(uint64_t id);

parent:

// The child is about to be destroyed, so perform any necessary cleanup.
Expand Down
6 changes: 1 addition & 5 deletions layout/base/nsPresShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5824,11 +5824,7 @@ PresShell::Paint(nsView* aViewToPaint,
NS_ASSERTION(layerManager, "Must be in paint event");
bool shouldInvalidate = layerManager->NeedsWidgetInvalidation();

uint32_t didPaintFlags = aFlags;
if (!shouldInvalidate) {
didPaintFlags |= PAINT_COMPOSITE;
}
nsAutoNotifyDidPaint notifyDidPaint(this, didPaintFlags);
nsAutoNotifyDidPaint notifyDidPaint(this, aFlags);
AutoUpdateHitRegion updateHitRegion(this, frame);

// Whether or not we should set first paint when painting is
Expand Down
1 change: 0 additions & 1 deletion layout/reftests/forms/input/range/stepDown-unthemed.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
document.documentElement.className = '';
}
document.addEventListener("MozReftestInvalidate", setValue);
setTimeout(setValue, 2000); // useful when not running under reftest suite
</script>
<body>
<input type=range id='i' value=100 step=25 style='-moz-appearance:none'>
Expand Down
1 change: 0 additions & 1 deletion layout/reftests/forms/input/range/stepDown.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
document.documentElement.className = '';
}
document.addEventListener("MozReftestInvalidate", setValue);
setTimeout(setValue, 2000); // useful when not running under reftest suite
</script>
<body>
<input type=range id='i' value=100 step=25>
Expand Down
1 change: 0 additions & 1 deletion layout/reftests/forms/input/range/stepUp-unthemed.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
document.documentElement.className = '';
}
document.addEventListener("MozReftestInvalidate", setValue);
setTimeout(setValue, 2000); // useful when not running under reftest suite
</script>
<body>
<input type=range id='i' value=50 step=25 style='-moz-appearance:none'>
Expand Down
1 change: 0 additions & 1 deletion layout/reftests/forms/input/range/stepUp.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
document.documentElement.className = '';
}
document.addEventListener("MozReftestInvalidate", setValue);
setTimeout(setValue, 2000); // useful when not running under reftest suite
</script>
<body>
<input type=range id='i' value=50 step=25>
Expand Down
2 changes: 1 addition & 1 deletion layout/reftests/printing/745025-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
};
setTimeout(function() {
document.documentElement.className = "reftest-print"
}, 0);
}, 100);
};
</script>
</head>
Expand Down
1 change: 1 addition & 0 deletions view/public/nsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class nsView MOZ_FINAL : public nsIWidgetListener
virtual void WillPaintWindow(nsIWidget* aWidget) MOZ_OVERRIDE;
virtual bool PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) MOZ_OVERRIDE;
virtual void DidPaintWindow() MOZ_OVERRIDE;
virtual void DidCompositeWindow() MOZ_OVERRIDE;
virtual void RequestRepaint() MOZ_OVERRIDE;
virtual nsEventStatus HandleEvent(mozilla::WidgetGUIEvent* aEvent,
bool aUseAttachedEvents) MOZ_OVERRIDE;
Expand Down
11 changes: 11 additions & 0 deletions view/src/nsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "nsPresArena.h"
#include "nsXULPopupManager.h"
#include "nsIWidgetListener.h"
#include "nsContentUtils.h" // for nsAutoScriptBlocker

using namespace mozilla;

Expand Down Expand Up @@ -1056,6 +1057,16 @@ nsView::DidPaintWindow()
vm->DidPaintWindow();
}

void
nsView::DidCompositeWindow()
{
nsIPresShell* presShell = mViewManager->GetPresShell();
if (presShell) {
nsAutoScriptBlocker scriptBlocker;
presShell->GetPresContext()->GetDisplayRootPresContext()->GetRootPresContext()->NotifyDidPaintForSubtree(nsIPresShell::PAINT_COMPOSITE);
}
}

void
nsView::RequestRepaint()
{
Expand Down
2 changes: 2 additions & 0 deletions widget/nsIWidgetListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class nsIWidgetListener
*/
virtual void DidPaintWindow();

virtual void DidCompositeWindow();

/**
* Request that layout schedules a repaint on the next refresh driver tick.
*/
Expand Down
5 changes: 5 additions & 0 deletions widget/xpwidgets/nsIWidgetListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ nsIWidgetListener::DidPaintWindow()
{
}

void
nsIWidgetListener::DidCompositeWindow()
{
}

void
nsIWidgetListener::RequestRepaint()
{
Expand Down

0 comments on commit b4d6205

Please sign in to comment.