Bug 930939 - Add a function to encapsulate running things on the APZ controller thread. r=botond

This commit is contained in:
Kartikaya Gupta 2015-02-10 08:24:23 -05:00
parent b3954b6850
commit 224d1319e8
3 changed files with 37 additions and 2 deletions

View File

@ -49,5 +49,23 @@ APZThreadUtils::AssertOnCompositorThread()
}
}
/*static*/ void
APZThreadUtils::RunOnControllerThread(Task* aTask)
{
#ifdef MOZ_WIDGET_GONK
// On B2G the controller thread is the compositor thread, and this function
// is always called from the libui thread or the main thread.
MessageLoop* loop = CompositorParent::CompositorLoop();
MOZ_ASSERT(MessageLoop::current() != loop);
loop->PostTask(FROM_HERE, aTask);
#else
// On non-B2G platforms this is only ever called from the controller thread
// itself.
AssertOnControllerThread();
aTask->Run();
delete aTask;
#endif
}
} // namespace layers
} // namespace mozilla

View File

@ -6,6 +6,8 @@
#ifndef mozilla_layers_APZThreadUtils_h
#define mozilla_layers_APZThreadUtils_h
class Task;
namespace mozilla {
namespace layers {
@ -33,6 +35,13 @@ public:
* This does nothing if thread assertions are disabled.
*/
static void AssertOnCompositorThread();
/**
* Run the given task on the APZ "controller thread" for this platform. If
* this function is called from the controller thread itself then the task is
* run immediately without getting queued.
*/
static void RunOnControllerThread(Task* aTask);
};
} // namespace layers

View File

@ -16,6 +16,7 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/layers/APZCTreeManager.h"
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/LayerTransactionParent.h"
#include "nsContentUtils.h"
@ -531,7 +532,9 @@ RenderFrameParent::ContentReceivedInputBlock(const ScrollableLayerGuid& aGuid,
return;
}
if (GetApzcTreeManager()) {
GetApzcTreeManager()->ContentReceivedInputBlock(aInputBlockId, aPreventDefault);
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
GetApzcTreeManager(), &APZCTreeManager::ContentReceivedInputBlock,
aInputBlockId, aPreventDefault));
}
}
@ -547,7 +550,12 @@ RenderFrameParent::SetTargetAPZC(uint64_t aInputBlockId,
}
}
if (GetApzcTreeManager()) {
GetApzcTreeManager()->SetTargetAPZC(aInputBlockId, aTargets);
// need a local var to disambiguate between the SetTargetAPZC overloads.
void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray<ScrollableLayerGuid>&)
= &APZCTreeManager::SetTargetAPZC;
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
GetApzcTreeManager(), setTargetApzcFunc,
aInputBlockId, aTargets));
}
}