Bug 733653 - use 100ms as the default sensor poll hint. Ensuring that our sensors are polled allows us to conform to the DeviceOrientation Event Specification. See DeviceMotionEvent.interval. r=jdm

This commit is contained in:
Doug Turner 2012-03-13 09:59:24 -07:00
parent fc9a4d3d9a
commit edffb9b4d9
6 changed files with 20 additions and 17 deletions

View File

@ -44,6 +44,7 @@
#import "smslib.h"
#define MEAN_GRAVITY 9.80665
#define DEFAULT_SENSOR_POLL 100
nsDeviceMotionSystem::nsDeviceMotionSystem()
{
@ -79,7 +80,7 @@ void nsDeviceMotionSystem::Startup()
if (mUpdateTimer)
mUpdateTimer->InitWithFuncCallback(UpdateHandler,
this,
mUpdateInterval,
DEFAULT_SENSOR_POLL,
nsITimer::TYPE_REPEATING_SLACK);
}

View File

@ -50,6 +50,9 @@
#include "nsIPrefService.h"
#include "nsDOMDeviceMotionEvent.h"
// also see sDefaultSensorHint in mobile/android/base/GeckoAppShell.java
#define DEFAULT_SENSOR_POLL 100
static const nsTArray<nsIDOMWindow*>::index_type NoIndex =
nsTArray<nsIDOMWindow*>::NoIndex;
@ -117,18 +120,12 @@ NS_IMPL_ISUPPORTS2(nsDeviceMotion, nsIDeviceMotion, nsIDeviceMotionUpdate)
nsDeviceMotion::nsDeviceMotion()
: mStarted(false),
mUpdateInterval(50), /* default to 50 ms */
mEnabled(true)
{
nsCOMPtr<nsIPrefBranch> prefSrv = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefSrv) {
PRInt32 value;
nsresult rv = prefSrv->GetIntPref("device.motion.update.interval", &value);
if (NS_SUCCEEDED(rv))
mUpdateInterval = value;
bool bvalue;
rv = prefSrv->GetBoolPref("device.motion.enabled", &bvalue);
nsresult rv = prefSrv->GetBoolPref("device.motion.enabled", &bvalue);
if (NS_SUCCEEDED(rv) && bvalue == false)
mEnabled = false;
}
@ -322,7 +319,7 @@ nsDeviceMotion::FireDOMMotionEvent(nsIDOMDocument *domdoc,
nsnull,
acceleration,
nsnull,
0);
DEFAULT_SENSOR_POLL);
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
if (privateEvent)

View File

@ -87,9 +87,7 @@ private:
double x,
double y,
double z);
PRUint32 mUpdateInterval;
bool mEnabled;
bool mEnabled;
virtual void Startup() = 0;
virtual void Shutdown() = 0;

View File

@ -42,6 +42,8 @@
#include "nsDeviceMotionSystem.h"
#include "nsIServiceManager.h"
#define DEFAULT_SENSOR_POLL 100
using namespace mozilla;
typedef struct {
@ -223,7 +225,7 @@ void nsDeviceMotionSystem::Startup()
if (mUpdateTimer)
mUpdateTimer->InitWithFuncCallback(UpdateHandler,
this,
mUpdateInterval,
DEFAULT_SENSOR_POLL,
nsITimer::TYPE_REPEATING_SLACK);
}

View File

@ -39,6 +39,8 @@
#include "nsIServiceManager.h"
#include "windows.h"
#define DEFAULT_SENSOR_POLL 100
////////////////////////////
// ThinkPad
////////////////////////////
@ -156,7 +158,7 @@ void nsDeviceMotionSystem::Startup()
if (mUpdateTimer)
mUpdateTimer->InitWithFuncCallback(UpdateHandler,
this,
mUpdateInterval,
DEFAULT_SENSOR_POLL,
nsITimer::TYPE_REPEATING_SLACK);
}

View File

@ -126,6 +126,9 @@ public class GeckoAppShell
* sVibrationMaybePlaying is true. */
private static long sVibrationEndTime = 0;
/* Default value of how fast we should hint the Android sensors. */
private static int sDefaultSensorHint = 100;
/* The Android-side API: API methods that Android calls */
// Initialization methods
@ -547,9 +550,9 @@ public class GeckoAppShell
if (enable) {
if (gAccelerometerSensor != null)
sm.registerListener(GeckoApp.mAppContext, gAccelerometerSensor, SensorManager.SENSOR_DELAY_GAME);
sm.registerListener(GeckoApp.mAppContext, gAccelerometerSensor, sDefaultSensorHint);
if (gOrientationSensor != null)
sm.registerListener(GeckoApp.mAppContext, gOrientationSensor, SensorManager.SENSOR_DELAY_GAME);
sm.registerListener(GeckoApp.mAppContext, gOrientationSensor, sDefaultSensorHint);
} else {
if (gAccelerometerSensor != null)
sm.unregisterListener(GeckoApp.mAppContext, gAccelerometerSensor);
@ -603,7 +606,7 @@ public class GeckoAppShell
if(gProximitySensor == null)
gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
sm.registerListener(GeckoApp.mAppContext, gProximitySensor,
SensorManager.SENSOR_DELAY_GAME);
sDefaultSensorHint);
break;
}
}