Bug 979949 - Expose compositor fill ratio to JS for automation. r=benwa,mrbkap.

This commit is contained in:
Mason Chang 2014-05-08 17:32:00 +02:00
parent 667578502d
commit 3146eb4aea
12 changed files with 111 additions and 4 deletions

View File

@ -105,6 +105,7 @@ struct ElementRegistrationOptions;
class Event;
class EventTarget;
class FrameRequestCallback;
class OverfillCallback;
class HTMLBodyElement;
struct LifecycleCallbackArgs;
class Link;

View File

@ -7061,6 +7061,22 @@ nsGlobalWindow::ScrollTo(const CSSIntPoint& aScroll)
}
}
void
nsGlobalWindow::MozRequestOverfill(OverfillCallback& aCallback,
mozilla::ErrorResult& aError)
{
nsIWidget* widget = nsContentUtils::WidgetForDocument(mDoc);
if (widget) {
mozilla::layers::LayerManager* manager = widget->GetLayerManager();
if (manager) {
manager->RequestOverfill(&aCallback);
return;
}
}
aError.Throw(NS_ERROR_NOT_AVAILABLE);
}
NS_IMETHODIMP
nsGlobalWindow::ScrollBy(int32_t aXScrollDif, int32_t aYScrollDif)
{

View File

@ -910,6 +910,7 @@ public:
{
return GetScrollY(aError);
}
void MozRequestOverfill(mozilla::dom::OverfillCallback& aCallback, mozilla::ErrorResult& aError);
int32_t GetScreenX(mozilla::ErrorResult& aError);
void SetScreenX(int32_t aScreenX, mozilla::ErrorResult& aError);
int32_t GetScreenY(mozilla::ErrorResult& aError);

View File

@ -198,6 +198,17 @@ partial interface Window {
[Throws] attribute long outerHeight;
};
/**
* Special function that gets the fill ratio from the compositor used for testing
* and is an indicator that we're layerizing correctly.
* This function will call the given callback current fill ratio for a
* composited frame. We don't guarantee which frame fill ratios will be returned.
*/
partial interface Window {
[ChromeOnly, Throws] void mozRequestOverfill(OverfillCallback callback);
};
callback OverfillCallback = void (unsigned long overfill);
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/RequestAnimationFrame/Overview.html
partial interface Window {
[Throws] long requestAnimationFrame(FrameRequestCallback callback);

View File

@ -69,6 +69,10 @@ namespace css {
class ComputedTimingFunction;
}
namespace dom {
class OverfillCallback;
}
namespace layers {
class Animation;
@ -605,6 +609,8 @@ public:
virtual bool IsCompositingCheap() { return true; }
bool IsInTransaction() const { return mInTransaction; }
virtual bool RequestOverfill(mozilla::dom::OverfillCallback* aCallback) { return true; }
virtual void RunOverfillCallback(const uint32_t aOverfill) { }
virtual void SetRegionToClear(const nsIntRegion& aRegion)
{

View File

@ -27,6 +27,7 @@
#include "nsTArray.h" // for AutoInfallibleTArray
#include "nsXULAppAPI.h" // for XRE_GetProcessType, etc
#include "TiledLayerBuffer.h"
#include "mozilla/dom/WindowBinding.h" // for Overfill Callback
#ifdef MOZ_WIDGET_ANDROID
#include "AndroidBridge.h"
#endif
@ -39,7 +40,7 @@ namespace layers {
ClientLayerManager::ClientLayerManager(nsIWidget* aWidget)
: mPhase(PHASE_NONE)
, mWidget(aWidget)
, mWidget(aWidget)
, mTargetRotation(ROTATION_0)
, mRepeatTransaction(false)
, mIsRepeatTransaction(false)
@ -291,7 +292,36 @@ ClientLayerManager::DidComposite()
}
}
void
bool
ClientLayerManager::RequestOverfill(mozilla::dom::OverfillCallback* aCallback)
{
MOZ_ASSERT(aCallback != nullptr);
MOZ_ASSERT(HasShadowManager(), "Request Overfill only supported on b2g for now");
if (HasShadowManager()) {
CompositorChild* child = GetRemoteRenderer();
NS_ASSERTION(child, "Could not get CompositorChild");
child->AddOverfillObserver(this);
child->SendRequestOverfill();
mOverfillCallbacks.AppendElement(aCallback);
}
return true;
}
void
ClientLayerManager::RunOverfillCallback(const uint32_t aOverfill)
{
for (size_t i = 0; i < mOverfillCallbacks.Length(); i++) {
ErrorResult error;
mOverfillCallbacks[i]->Call(aOverfill, error);
}
mOverfillCallbacks.Clear();
}
void
ClientLayerManager::MakeSnapshotIfRequired()
{
if (!mShadowTarget) {
@ -576,5 +606,5 @@ ClientLayer::~ClientLayer()
MOZ_COUNT_DTOR(ClientLayer);
}
}
}
} // layers
} // mozilla

View File

@ -162,6 +162,8 @@ public:
bool NeedsComposite() const { return mNeedsComposite; }
virtual void Composite() MOZ_OVERRIDE;
virtual bool RequestOverfill(mozilla::dom::OverfillCallback* aCallback) MOZ_OVERRIDE;
virtual void RunOverfillCallback(const uint32_t aOverfill) MOZ_OVERRIDE;
virtual void DidComposite();
@ -227,6 +229,7 @@ private:
RefPtr<ShadowLayerForwarder> mForwarder;
nsAutoTArray<RefPtr<TextureClientPool>,2> mTexturePools;
nsAutoTArray<dom::OverfillCallback*,0> mOverfillCallbacks;
// indexed by gfx::SurfaceFormat
nsTArray<RefPtr<SimpleTextureClientPool> > mSimpleTilePools;

View File

@ -138,6 +138,23 @@ CompositorChild::RecvDidComposite(const uint64_t& aId)
return true;
}
bool
CompositorChild::RecvOverfill(const uint32_t &aOverfill)
{
for (size_t i = 0; i < mOverfillObservers.Length(); i++) {
mOverfillObservers[i]->RunOverfillCallback(aOverfill);
}
mOverfillObservers.Clear();
return true;
}
void
CompositorChild::AddOverfillObserver(ClientLayerManager* aLayerManager)
{
MOZ_ASSERT(aLayerManager);
mOverfillObservers.AppendElement(aLayerManager);
}
void
CompositorChild::ActorDestroy(ActorDestroyReason aWhy)
{

View File

@ -55,6 +55,8 @@ public:
static bool ChildProcessHasCompositor() { return sCompositor != nullptr; }
virtual bool RecvInvalidateAll() MOZ_OVERRIDE;
virtual bool RecvOverfill(const uint32_t &aOverfill) MOZ_OVERRIDE;
void AddOverfillObserver(ClientLayerManager* aLayerManager);
virtual bool RecvDidComposite(const uint64_t& aId) MOZ_OVERRIDE;
@ -114,6 +116,9 @@ private:
static CompositorChild* sCompositor;
DISALLOW_EVIL_CONSTRUCTORS(CompositorChild);
// When we receive overfill numbers, notify these client layer managers
nsAutoTArray<ClientLayerManager*,0> mOverfillObservers;
};
} // layers

View File

@ -846,6 +846,14 @@ CompositorParent::LeaveTestMode(LayerTransactionParent* aLayerTree)
mIsTesting = false;
}
bool
CompositorParent::RecvRequestOverfill()
{
uint32_t overfillRatio = mCompositor->GetFillRatio();
unused << SendOverfill(overfillRatio);
return true;
}
void
CompositorParent::InitializeLayerManager(const nsTArray<LayersBackend>& aBackendHints)
{
@ -1095,6 +1103,7 @@ public:
virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
// FIXME/bug 774388: work out what shutdown protocol we need.
virtual bool RecvRequestOverfill() MOZ_OVERRIDE { return true; }
virtual bool RecvWillStop() MOZ_OVERRIDE { return true; }
virtual bool RecvStop() MOZ_OVERRIDE { return true; }
virtual bool RecvPause() MOZ_OVERRIDE { return true; }
@ -1159,6 +1168,7 @@ CompositorParent::Create(Transport* aTransport, ProcessId aOtherProcess)
// XXX need to kill |aOtherProcess|, it's boned
return nullptr;
}
cpcp->mSelfRef = cpcp;
CompositorLoop()->PostTask(
FROM_HERE,

View File

@ -78,6 +78,7 @@ public:
base::ProcessHandle aPeerProcess,
mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
virtual bool RecvRequestOverfill() MOZ_OVERRIDE;
virtual bool RecvWillStop() MOZ_OVERRIDE;
virtual bool RecvStop() MOZ_OVERRIDE;
virtual bool RecvPause() MOZ_OVERRIDE;

View File

@ -44,8 +44,14 @@ child:
// the root layer tree).
async DidComposite(uint64_t id);
// The parent sends the child the requested fill ratio numbers.
async Overfill(uint32_t aOverfill);
parent:
// Child sends the parent a request for fill ratio numbers.
async RequestOverfill();
// The child is about to be destroyed, so perform any necessary cleanup.
sync WillStop();