Bug 745145, part 0c: Only use nsIScreen on the main thread. r=mwu

This commit is contained in:
Chris Jones 2012-05-08 14:36:07 -07:00
Родитель 04f0e819a4
Коммит a825b8f413
1 изменённых файлов: 18 добавлений и 16 удалений

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

@ -517,18 +517,27 @@ GeckoInputDispatcher::unregisterInputChannel(const sp<InputChannel>& inputChanne
return OK; return OK;
} }
static already_AddRefed<nsIScreen>
Screen()
{
nsCOMPtr<nsIScreenManager> screenMgr =
do_GetService("@mozilla.org/gfx/screenmanager;1");
nsCOMPtr<nsIScreen> screen;
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
return screen.forget();
}
class ScreenRotateEvent : public nsRunnable { class ScreenRotateEvent : public nsRunnable {
public: public:
ScreenRotateEvent(nsIScreen* aScreen, PRUint32 aRotation) ScreenRotateEvent(PRUint32 aRotation)
: mScreen(aScreen), : mRotation(aRotation) {
mRotation(aRotation) {
} }
NS_IMETHOD Run() { NS_IMETHOD Run() {
return mScreen->SetRotation(mRotation); nsCOMPtr<nsIScreen> screen = Screen();
return screen->SetRotation(mRotation);
} }
private: private:
nsCOMPtr<nsIScreen> mScreen;
PRUint32 mRotation; PRUint32 mRotation;
}; };
@ -538,11 +547,6 @@ public:
: mLastUpdate(0) { : mLastUpdate(0) {
} }
void Notify(const SensorData& aSensorData) { void Notify(const SensorData& aSensorData) {
nsCOMPtr<nsIScreenManager> screenMgr =
do_GetService("@mozilla.org/gfx/screenmanager;1");
nsCOMPtr<nsIScreen> screen;
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
MOZ_ASSERT(aSensorData.sensor() == SensorType::SENSOR_ORIENTATION); MOZ_ASSERT(aSensorData.sensor() == SensorType::SENSOR_ORIENTATION);
InfallibleTArray<float> values = aSensorData.values(); InfallibleTArray<float> values = aSensorData.values();
// float azimuth = values[0]; // unused // float azimuth = values[0]; // unused
@ -560,10 +564,8 @@ public:
else else
return; // don't rotate if undecidable return; // don't rotate if undecidable
PRUint32 currRotation; // This check is racy, but that's OK.
nsresult res; if (rotation == nsScreenGonk::GetRotation())
res = screen->GetRotation(&currRotation);
if (NS_FAILED(res) || rotation == currRotation)
return; return;
PRTime now = PR_Now(); PRTime now = PR_Now();
@ -572,9 +574,9 @@ public:
return; return;
mLastUpdate = now; mLastUpdate = now;
NS_DispatchToMainThread(new ScreenRotateEvent(screen, rotation)); NS_DispatchToMainThread(new ScreenRotateEvent(rotation));
} }
private: private:
PRTime mLastUpdate; PRTime mLastUpdate;
static const PRTime sMinUpdateInterval = 500 * 1000; // 500 ms static const PRTime sMinUpdateInterval = 500 * 1000; // 500 ms