Bug 1163458: Part2. Remove sync dispatch from apple's initialization. r=cpearce

This commit is contained in:
Jean-Yves Avenard 2015-05-18 15:42:32 +10:00
Родитель 998eafdaa3
Коммит 6416c761ce
2 изменённых файлов: 1 добавлений и 68 удалений

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

@ -31,50 +31,12 @@ bool AppleDecoderModule::sIsVTHWAvailable = false;
bool AppleDecoderModule::sIsVDAAvailable = false; bool AppleDecoderModule::sIsVDAAvailable = false;
bool AppleDecoderModule::sForceVDA = false; bool AppleDecoderModule::sForceVDA = false;
class LinkTask : public nsRunnable {
public:
NS_IMETHOD Run() override {
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
MOZ_ASSERT(AppleDecoderModule::sInitialized);
if (AppleDecoderModule::sIsVDAAvailable) {
AppleVDALinker::Link();
}
if (AppleDecoderModule::sIsVTAvailable) {
AppleVTLinker::Link();
AppleCMLinker::Link();
}
return NS_OK;
}
};
class UnlinkTask : public nsRunnable {
public:
NS_IMETHOD Run() override {
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
MOZ_ASSERT(AppleDecoderModule::sInitialized);
if (AppleDecoderModule::sIsVDAAvailable) {
AppleVDALinker::Unlink();
}
if (AppleDecoderModule::sIsVTAvailable) {
AppleVTLinker::Unlink();
AppleCMLinker::Unlink();
}
return NS_OK;
}
};
AppleDecoderModule::AppleDecoderModule() AppleDecoderModule::AppleDecoderModule()
{ {
} }
AppleDecoderModule::~AppleDecoderModule() AppleDecoderModule::~AppleDecoderModule()
{ {
nsCOMPtr<nsIRunnable> task(new UnlinkTask());
if (!NS_IsMainThread()) {
NS_DispatchToMainThread(task);
} else {
task->Run();
}
} }
/* static */ /* static */
@ -102,40 +64,15 @@ AppleDecoderModule::Init()
sIsVTHWAvailable = AppleVTLinker::skPropEnableHWAccel != nullptr; sIsVTHWAvailable = AppleVTLinker::skPropEnableHWAccel != nullptr;
if (sIsVDAAvailable) {
AppleVDALinker::Unlink();
}
if (sIsVTAvailable) {
AppleVTLinker::Unlink();
AppleCMLinker::Unlink();
}
sInitialized = true; sInitialized = true;
} }
class InitTask : public nsRunnable {
public:
NS_IMETHOD Run() override {
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
AppleDecoderModule::Init();
return NS_OK;
}
};
nsresult nsresult
AppleDecoderModule::Startup() AppleDecoderModule::Startup()
{ {
if (!sIsVDAAvailable && !sIsVTAvailable) { if (!sInitialized || (!sIsVDAAvailable && !sIsVTAvailable)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
// Note: We can be called on the main thread from MP4Decoder::CanHandleMediaType().
nsCOMPtr<nsIRunnable> task(new LinkTask());
if (!NS_IsMainThread()) {
NS_DispatchToMainThread(task, NS_DISPATCH_SYNC);
} else {
task->Run();
}
return NS_OK; return NS_OK;
} }

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

@ -40,10 +40,6 @@ public:
static void Init(); static void Init();
private: private:
friend class InitTask;
friend class LinkTask;
friend class UnlinkTask;
static bool sInitialized; static bool sInitialized;
static bool sIsVTAvailable; static bool sIsVTAvailable;
static bool sIsVTHWAvailable; static bool sIsVTHWAvailable;