Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: third_party/WebKit/Source/modules/sensor/OrientationSensor.cpp

Issue 2746573002: [Sensors] Implement bindings for AbsoluteOrientationSensor (Closed)
Patch Set: [Sensors] Implement bindings for AbsoluteOrientationSensor Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/sensor/OrientationSensor.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/OrientationSensor.cpp b/third_party/WebKit/Source/modules/sensor/OrientationSensor.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..34581415e2e6c35c13c23ba45d650078f6cc9982
--- /dev/null
+++ b/third_party/WebKit/Source/modules/sensor/OrientationSensor.cpp
@@ -0,0 +1,65 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/sensor/OrientationSensor.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+
+using device::mojom::blink::SensorType;
+
+namespace blink {
+
+Vector<double> OrientationSensor::quaternion(bool& isNull) const {
+ isNull = !canReturnReadings();
shalamov 2017/03/23 08:41:06 Can we return [SameObject] unless reading is chang
Mikhail 2017/03/24 14:47:09 Cached using [CachedAttribute]
+ return isNull ? Vector<double>()
+ : Vector<double>({readingValueUnchecked(3), // W
+ readingValueUnchecked(0), // Vx
+ readingValueUnchecked(1), // Vy
+ readingValueUnchecked(2)}); // Vz
+}
+
+void OrientationSensor::populateMatrix(DOMFloat32Array* buffer,
+ ExceptionState& exceptionState) {
+ if (buffer->length() < 16) {
+ exceptionState.throwTypeError(
+ "Target buffer must have minimal size of 16.");
+ return;
+ }
+ if (!isActivated()) {
+ exceptionState.throwDOMException(
+ InvalidStateError, "The Sensor must be in 'connected' state.");
+ return;
+ }
+ if (!canReturnReadings())
+ return;
+
+ float x = readingValueUnchecked(0);
+ float y = readingValueUnchecked(1);
+ float z = readingValueUnchecked(2);
+ float w = readingValueUnchecked(3);
+
+ float* out = buffer->data();
+ out[0] = 1.0 - 2 * (y * y - z * z);
+ out[1] = 2 * (x * y - z * w);
+ out[2] = 2 * (x * z + y * w);
+ out[4] = 2 * (x * y + z * w);
+ out[5] = 1.0 - 2 * (x * x - z * z);
+ out[6] = 2 * (y * z - x * w);
+ out[8] = 2 * (x * z - y * w);
+ out[9] = 2 * (y * z + x * w);
+ out[10] = 1.0 - 2 * (x * x - y * y);
+ out[15] = 1.0;
+}
+
+OrientationSensor::OrientationSensor(ExecutionContext* executionContext,
+ const SensorOptions& options,
+ ExceptionState& exceptionState,
+ device::mojom::blink::SensorType type)
+ : Sensor(executionContext, options, exceptionState, type) {}
+
+DEFINE_TRACE(OrientationSensor) {
+ Sensor::trace(visitor);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698