Commit e60cd866 authored by Oksana Zhuravlova's avatar Oksana Zhuravlova Committed by Commit Bot

Replace usages of device::MotionData with DeviceMotionData

Since DeviceMotionData class has all the information from
device::MotionData, and DeviceMotionEventPump is now in blink,
DeviceMotionData is now passed to DeviceMotionDispatcher.
device::MotionData will be removed in a subsequent change.

Bug: 861923
Change-Id: I1165d1dbd128197e2e00d7ad63db17d03e6af810
Reviewed-on: https://chromium-review.googlesource.com/1137171
Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarTim Volodine <timvolodine@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576301}
parent 6c94a953
...@@ -33,16 +33,14 @@ ...@@ -33,16 +33,14 @@
#include "third_party/blink/public/platform/web_platform_event_listener.h" #include "third_party/blink/public/platform/web_platform_event_listener.h"
namespace device {
class MotionData;
}
namespace blink { namespace blink {
class DeviceMotionData;
class WebDeviceMotionListener : public WebPlatformEventListener { class WebDeviceMotionListener : public WebPlatformEventListener {
public: public:
// This method is called every time new device motion data is available. // This method is called every time new device motion data is available.
virtual void DidChangeDeviceMotion(const device::MotionData&) = 0; virtual void DidChangeDeviceMotion(DeviceMotionData*) = 0;
~WebDeviceMotionListener() override = default; ~WebDeviceMotionListener() override = default;
}; };
......
...@@ -4,7 +4,6 @@ include_rules = [ ...@@ -4,7 +4,6 @@ include_rules = [
# NOTE: These files are POD structs used to interpret shared memory across # NOTE: These files are POD structs used to interpret shared memory across
# the Device Sensors implementation and the Blink client. # the Device Sensors implementation and the Blink client.
"+services/device/public/cpp/generic_sensor/motion_data.h",
"+services/device/public/cpp/generic_sensor/orientation_data.h", "+services/device/public/cpp/generic_sensor/orientation_data.h",
"+services/device/public/mojom/sensor.mojom-blink.h", "+services/device/public/mojom/sensor.mojom-blink.h",
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "third_party/blink/renderer/modules/device_orientation/device_motion_data.h" #include "third_party/blink/renderer/modules/device_orientation/device_motion_data.h"
#include "services/device/public/cpp/generic_sensor/motion_data.h"
#include "third_party/blink/renderer/modules/device_orientation/device_acceleration_init.h" #include "third_party/blink/renderer/modules/device_orientation/device_acceleration_init.h"
#include "third_party/blink/renderer/modules/device_orientation/device_motion_event_init.h" #include "third_party/blink/renderer/modules/device_orientation/device_motion_event_init.h"
#include "third_party/blink/renderer/modules/device_orientation/device_rotation_rate_init.h" #include "third_party/blink/renderer/modules/device_orientation/device_rotation_rate_init.h"
...@@ -126,25 +125,6 @@ DeviceMotionData* DeviceMotionData::Create(const DeviceMotionEventInit& init) { ...@@ -126,25 +125,6 @@ DeviceMotionData* DeviceMotionData::Create(const DeviceMotionEventInit& init) {
init.interval()); init.interval());
} }
DeviceMotionData* DeviceMotionData::Create(const device::MotionData& data) {
return DeviceMotionData::Create(
DeviceMotionData::Acceleration::Create(
data.has_acceleration_x, data.acceleration_x, data.has_acceleration_y,
data.acceleration_y, data.has_acceleration_z, data.acceleration_z),
DeviceMotionData::Acceleration::Create(
data.has_acceleration_including_gravity_x,
data.acceleration_including_gravity_x,
data.has_acceleration_including_gravity_y,
data.acceleration_including_gravity_y,
data.has_acceleration_including_gravity_z,
data.acceleration_including_gravity_z),
DeviceMotionData::RotationRate::Create(
data.has_rotation_rate_alpha, data.rotation_rate_alpha,
data.has_rotation_rate_beta, data.rotation_rate_beta,
data.has_rotation_rate_gamma, data.rotation_rate_gamma),
data.interval);
}
DeviceMotionData::DeviceMotionData() : interval_(0) {} DeviceMotionData::DeviceMotionData() : interval_(0) {}
DeviceMotionData::DeviceMotionData(Acceleration* acceleration, DeviceMotionData::DeviceMotionData(Acceleration* acceleration,
......
...@@ -26,19 +26,17 @@ ...@@ -26,19 +26,17 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_MOTION_DATA_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_MOTION_DATA_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_MOTION_DATA_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_MOTION_DATA_H_
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
namespace device {
class MotionData;
}
namespace blink { namespace blink {
class DeviceAccelerationInit; class DeviceAccelerationInit;
class DeviceMotionEventInit; class DeviceMotionEventInit;
class DeviceRotationRateInit; class DeviceRotationRateInit;
class DeviceMotionData final : public GarbageCollected<DeviceMotionData> { class MODULES_EXPORT DeviceMotionData final
: public GarbageCollected<DeviceMotionData> {
public: public:
class Acceleration final class Acceleration final
: public GarbageCollected<DeviceMotionData::Acceleration> { : public GarbageCollected<DeviceMotionData::Acceleration> {
...@@ -120,7 +118,6 @@ class DeviceMotionData final : public GarbageCollected<DeviceMotionData> { ...@@ -120,7 +118,6 @@ class DeviceMotionData final : public GarbageCollected<DeviceMotionData> {
RotationRate*, RotationRate*,
double interval); double interval);
static DeviceMotionData* Create(const DeviceMotionEventInit&); static DeviceMotionData* Create(const DeviceMotionEventInit&);
static DeviceMotionData* Create(const device::MotionData&);
void Trace(blink::Visitor*); void Trace(blink::Visitor*);
Acceleration* GetAcceleration() const { return acceleration_.Get(); } Acceleration* GetAcceleration() const { return acceleration_.Get(); }
......
...@@ -68,9 +68,8 @@ void DeviceMotionDispatcher::StopListening() { ...@@ -68,9 +68,8 @@ void DeviceMotionDispatcher::StopListening() {
last_device_motion_data_.Clear(); last_device_motion_data_.Clear();
} }
void DeviceMotionDispatcher::DidChangeDeviceMotion( void DeviceMotionDispatcher::DidChangeDeviceMotion(DeviceMotionData* motion) {
const device::MotionData& motion) { last_device_motion_data_ = motion;
last_device_motion_data_ = DeviceMotionData::Create(motion);
NotifyControllers(); NotifyControllers();
} }
......
...@@ -36,10 +36,6 @@ ...@@ -36,10 +36,6 @@
#include "third_party/blink/renderer/core/frame/platform_event_dispatcher.h" #include "third_party/blink/renderer/core/frame/platform_event_dispatcher.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
namespace device {
class MotionData;
}
namespace blink { namespace blink {
class DeviceMotionData; class DeviceMotionData;
...@@ -61,7 +57,7 @@ class DeviceMotionDispatcher final ...@@ -61,7 +57,7 @@ class DeviceMotionDispatcher final
const DeviceMotionData* LatestDeviceMotionData(); const DeviceMotionData* LatestDeviceMotionData();
// Inherited from WebDeviceMotionListener. // Inherited from WebDeviceMotionListener.
void DidChangeDeviceMotion(const device::MotionData&) override; void DidChangeDeviceMotion(DeviceMotionData*) override;
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
......
...@@ -4,13 +4,20 @@ ...@@ -4,13 +4,20 @@
#include <cmath> #include <cmath>
#include "services/device/public/cpp/generic_sensor/motion_data.h"
#include "services/device/public/mojom/sensor.mojom-blink.h" #include "services/device/public/mojom/sensor.mojom-blink.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/device_orientation/device_motion_data.h"
#include "third_party/blink/renderer/modules/device_orientation/device_motion_event_pump.h" #include "third_party/blink/renderer/modules/device_orientation/device_motion_event_pump.h"
#include "ui/gfx/geometry/angle_conversions.h" #include "ui/gfx/geometry/angle_conversions.h"
namespace {
constexpr double kDefaultPumpDelayMilliseconds =
blink::DeviceMotionEventPump::kDefaultPumpDelayMicroseconds / 1000;
} // namespace
namespace blink { namespace blink {
template class DeviceSensorEventPump<blink::WebDeviceMotionListener>; template class DeviceSensorEventPump<blink::WebDeviceMotionListener>;
...@@ -56,16 +63,12 @@ void DeviceMotionEventPump::SendStopMessage() { ...@@ -56,16 +63,12 @@ void DeviceMotionEventPump::SendStopMessage() {
} }
void DeviceMotionEventPump::FireEvent(TimerBase*) { void DeviceMotionEventPump::FireEvent(TimerBase*) {
device::MotionData data;
// The device orientation spec states that interval should be in milliseconds.
// https://w3c.github.io/deviceorientation/spec-source-orientation.html#devicemotion
data.interval = kDefaultPumpDelayMicroseconds / 1000;
DCHECK(listener()); DCHECK(listener());
GetDataFromSharedMemory(&data); DeviceMotionData* data = GetDataFromSharedMemory();
if (ShouldFireEvent(data)) // data is null if not all sensors are active
if (data)
listener()->DidChangeDeviceMotion(data); listener()->DidChangeDeviceMotion(data);
} }
...@@ -75,61 +78,63 @@ bool DeviceMotionEventPump::SensorsReadyOrErrored() const { ...@@ -75,61 +78,63 @@ bool DeviceMotionEventPump::SensorsReadyOrErrored() const {
gyroscope_.ReadyOrErrored(); gyroscope_.ReadyOrErrored();
} }
void DeviceMotionEventPump::GetDataFromSharedMemory(device::MotionData* data) { DeviceMotionData* DeviceMotionEventPump::GetDataFromSharedMemory() {
// "Active" here means that sensor has been initialized and is either ready DeviceMotionData::Acceleration* acceleration = nullptr;
// or not available. DeviceMotionData::Acceleration* acceleration_including_gravity = nullptr;
bool accelerometer_active = true; DeviceMotionData::RotationRate* rotation_rate = nullptr;
bool linear_acceleration_sensor_active = true;
bool gyroscope_active = true; if (accelerometer_.SensorReadingCouldBeRead()) {
if (accelerometer_.reading.timestamp() == 0.0)
if (accelerometer_.SensorReadingCouldBeRead() && return nullptr;
(accelerometer_active = accelerometer_.reading.timestamp() != 0.0)) {
data->acceleration_including_gravity_x = accelerometer_.reading.accel.x; acceleration_including_gravity = DeviceMotionData::Acceleration::Create(
data->acceleration_including_gravity_y = accelerometer_.reading.accel.y; !std::isnan(accelerometer_.reading.accel.x.value()),
data->acceleration_including_gravity_z = accelerometer_.reading.accel.z; accelerometer_.reading.accel.x,
data->has_acceleration_including_gravity_x = !std::isnan(accelerometer_.reading.accel.y.value()),
!std::isnan(accelerometer_.reading.accel.x.value()); accelerometer_.reading.accel.y,
data->has_acceleration_including_gravity_y = !std::isnan(accelerometer_.reading.accel.z.value()),
!std::isnan(accelerometer_.reading.accel.y.value()); accelerometer_.reading.accel.z);
data->has_acceleration_including_gravity_z = } else {
!std::isnan(accelerometer_.reading.accel.z.value()); acceleration_including_gravity = DeviceMotionData::Acceleration::Create(
false, 0.0, false, 0.0, false, 0.0);
} }
if (linear_acceleration_sensor_.SensorReadingCouldBeRead() && if (linear_acceleration_sensor_.SensorReadingCouldBeRead()) {
(linear_acceleration_sensor_active = if (linear_acceleration_sensor_.reading.timestamp() == 0.0)
linear_acceleration_sensor_.reading.timestamp() != 0.0)) { return nullptr;
data->acceleration_x = linear_acceleration_sensor_.reading.accel.x;
data->acceleration_y = linear_acceleration_sensor_.reading.accel.y; acceleration = DeviceMotionData::Acceleration::Create(
data->acceleration_z = linear_acceleration_sensor_.reading.accel.z; !std::isnan(linear_acceleration_sensor_.reading.accel.x.value()),
data->has_acceleration_x = linear_acceleration_sensor_.reading.accel.x,
!std::isnan(linear_acceleration_sensor_.reading.accel.x.value()); !std::isnan(linear_acceleration_sensor_.reading.accel.y.value()),
data->has_acceleration_y = linear_acceleration_sensor_.reading.accel.y,
!std::isnan(linear_acceleration_sensor_.reading.accel.y.value()); !std::isnan(linear_acceleration_sensor_.reading.accel.z.value()),
data->has_acceleration_z = linear_acceleration_sensor_.reading.accel.z);
!std::isnan(linear_acceleration_sensor_.reading.accel.z.value()); } else {
acceleration = DeviceMotionData::Acceleration::Create(false, 0.0, false,
0.0, false, 0.0);
} }
if (gyroscope_.SensorReadingCouldBeRead() && if (gyroscope_.SensorReadingCouldBeRead()) {
(gyroscope_active = gyroscope_.reading.timestamp() != 0.0)) { if (gyroscope_.reading.timestamp() == 0.0)
data->rotation_rate_alpha = gfx::RadToDeg(gyroscope_.reading.gyro.x); return nullptr;
data->rotation_rate_beta = gfx::RadToDeg(gyroscope_.reading.gyro.y);
data->rotation_rate_gamma = gfx::RadToDeg(gyroscope_.reading.gyro.z); rotation_rate = DeviceMotionData::RotationRate::Create(
data->has_rotation_rate_alpha = !std::isnan(gyroscope_.reading.gyro.x.value()),
!std::isnan(gyroscope_.reading.gyro.x.value()); gfx::RadToDeg(gyroscope_.reading.gyro.x),
data->has_rotation_rate_beta = !std::isnan(gyroscope_.reading.gyro.y.value()),
!std::isnan(gyroscope_.reading.gyro.y.value()); gfx::RadToDeg(gyroscope_.reading.gyro.y),
data->has_rotation_rate_gamma = !std::isnan(gyroscope_.reading.gyro.z.value()),
!std::isnan(gyroscope_.reading.gyro.z.value()); gfx::RadToDeg(gyroscope_.reading.gyro.z));
} else {
rotation_rate = DeviceMotionData::RotationRate::Create(false, 0.0, false,
0.0, false, 0.0);
} }
data->all_available_sensors_are_active = accelerometer_active && // The device orientation spec states that interval should be in
linear_acceleration_sensor_active && // milliseconds.
gyroscope_active; // https://w3c.github.io/deviceorientation/spec-source-orientation.html#devicemotion
} return DeviceMotionData::Create(acceleration, acceleration_including_gravity,
rotation_rate, kDefaultPumpDelayMilliseconds);
bool DeviceMotionEventPump::ShouldFireEvent(
const device::MotionData& data) const {
return data.all_available_sensors_are_active;
} }
} // namespace blink } // namespace blink
...@@ -10,12 +10,10 @@ ...@@ -10,12 +10,10 @@
#include "third_party/blink/renderer/modules/device_orientation/device_sensor_event_pump.h" #include "third_party/blink/renderer/modules/device_orientation/device_sensor_event_pump.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
namespace device {
class MotionData;
}
namespace blink { namespace blink {
class DeviceMotionData;
class MODULES_EXPORT DeviceMotionEventPump class MODULES_EXPORT DeviceMotionEventPump
: public DeviceSensorEventPump<blink::WebDeviceMotionListener> { : public DeviceSensorEventPump<blink::WebDeviceMotionListener> {
public: public:
...@@ -40,9 +38,7 @@ class MODULES_EXPORT DeviceMotionEventPump ...@@ -40,9 +38,7 @@ class MODULES_EXPORT DeviceMotionEventPump
// DeviceSensorEventPump: // DeviceSensorEventPump:
bool SensorsReadyOrErrored() const override; bool SensorsReadyOrErrored() const override;
void GetDataFromSharedMemory(device::MotionData* data); DeviceMotionData* GetDataFromSharedMemory();
bool ShouldFireEvent(const device::MotionData& data) const;
DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPump); DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPump);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment