Bug 1509466 - Pass frame request callbacks along with their handles to nsRefreshDriver; r=farre

In the next patch in this series we want to compare the handle of frame
callbacks we are about to run,  with a set of canceled handles stored on the
document. This patch makes us pass the handles along with the callbacks so we
can do that.

Incidentally doing this allows us to just swap array elements when building up
the refresh driver's set of callbacks to run. That is hopefully a little more
efficient than running the implicit conversion operator on each item and then
appending to an array.

Differential Revision: https://phabricator.services.mozilla.com/D20973

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brian Birtles 2019-02-27 13:43:23 +00:00
Родитель bb9e8e48d6
Коммит c2a7b658ea
3 изменённых файлов: 21 добавлений и 25 удалений

Просмотреть файл

@ -1168,22 +1168,9 @@ void Document::SelectorCache::NotifyExpired(SelectorCacheKey* aSelector) {
delete aSelector;
}
struct Document::FrameRequest {
FrameRequest(FrameRequestCallback& aCallback, int32_t aHandle)
: mCallback(&aCallback), mHandle(aHandle) {}
// Conversion operator so that we can append these to a
// FrameRequestCallbackList
operator const RefPtr<FrameRequestCallback>&() const { return mCallback; }
// Comparator operators to allow RemoveElementSorted with an
// integer argument on arrays of FrameRequest
bool operator==(int32_t aHandle) const { return mHandle == aHandle; }
bool operator<(int32_t aHandle) const { return mHandle < aHandle; }
RefPtr<FrameRequestCallback> mCallback;
int32_t mHandle;
};
Document::FrameRequest::FrameRequest(FrameRequestCallback& aCallback,
int32_t aHandle)
: mCallback(&aCallback), mHandle(aHandle) {}
// ==================================================================
// =
@ -3673,9 +3660,9 @@ void Document::UpdateFrameRequestCallbackSchedulingState(
mFrameRequestCallbacksScheduled = shouldBeScheduled;
}
void Document::TakeFrameRequestCallbacks(FrameRequestCallbackList& aCallbacks) {
aCallbacks.AppendElements(mFrameRequestCallbacks);
mFrameRequestCallbacks.Clear();
void Document::TakeFrameRequestCallbacks(nsTArray<FrameRequest>& aCallbacks) {
MOZ_ASSERT(aCallbacks.IsEmpty());
aCallbacks.SwapElements(mFrameRequestCallbacks);
// No need to manually remove ourselves from the refresh driver; it will
// handle that part. But we do have to update our state.
mFrameRequestCallbacksScheduled = false;

Просмотреть файл

@ -2922,16 +2922,27 @@ class Document : public nsINode,
SVGSVGElement* GetSVGRootElement() const;
struct FrameRequest {
FrameRequest(FrameRequestCallback& aCallback, int32_t aHandle);
// Comparator operators to allow RemoveElementSorted with an
// integer argument on arrays of FrameRequest
bool operator==(int32_t aHandle) const { return mHandle == aHandle; }
bool operator<(int32_t aHandle) const { return mHandle < aHandle; }
RefPtr<FrameRequestCallback> mCallback;
int32_t mHandle;
};
nsresult ScheduleFrameRequestCallback(FrameRequestCallback& aCallback,
int32_t* aHandle);
void CancelFrameRequestCallback(int32_t aHandle);
typedef nsTArray<RefPtr<FrameRequestCallback>> FrameRequestCallbackList;
/**
* Put this document's frame request callbacks into the provided
* list, and forget about them.
*/
void TakeFrameRequestCallbacks(FrameRequestCallbackList& aCallbacks);
void TakeFrameRequestCallbacks(nsTArray<FrameRequest>& aCallbacks);
/**
* @return true if this document's frame request callbacks should be
@ -4380,8 +4391,6 @@ class Document : public nsINode,
nsCOMPtr<nsIDocumentEncoder> mCachedEncoder;
struct FrameRequest;
nsTArray<FrameRequest> mFrameRequestCallbacks;
// This object allows us to evict ourself from the back/forward cache. The

Просмотреть файл

@ -1482,7 +1482,7 @@ struct DocumentFrameCallbacks {
explicit DocumentFrameCallbacks(Document* aDocument) : mDocument(aDocument) {}
RefPtr<Document> mDocument;
Document::FrameRequestCallbackList mCallbacks;
nsTArray<Document::FrameRequest> mCallbacks;
};
static nsDocShell* GetDocShell(nsPresContext* aPresContext) {
@ -1674,7 +1674,7 @@ void nsRefreshDriver::RunFrameRequestCallbacks(TimeStamp aNowTime) {
// else window is partially torn down already
}
for (auto& callback : docCallbacks.mCallbacks) {
callback->Call(timeStamp);
callback.mCallback->Call(timeStamp);
}
}
}