Commit 19de023d authored by Oksana Zhuravlova's avatar Oksana Zhuravlova Committed by Commit Bot

Create a shared component for gamepad_mojom_traits.{h,cc}

This change moves gamepad_mojom_traits to device/gamepad/public/cpp and
creates a shared component for them to be specified as a dependency in
gamepad.typemap. This will enable GamepadSharedMemoryReader to depend on
the traits after the move to blink.

Bug: 612330
Change-Id: I688a981313ec90a8c5bf909b0df4bb3e1f711388
Reviewed-on: https://chromium-review.googlesource.com/1103612Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568154}
parent 73963960
...@@ -21,3 +21,23 @@ source_set("shared_with_blink") { ...@@ -21,3 +21,23 @@ source_set("shared_with_blink") {
] ]
# Do not add deps here per the above comment. # Do not add deps here per the above comment.
} }
# Normally typemap traits sources should be build directly into mojom targets
# via the typemap file. This target is for typemapped types whose
# traits are shared between chromium and blink variants.
component("shared_typemap_traits") {
output_name = "gamepad_shared_typemap_traits"
sources = [
"gamepad_mojom_traits.cc",
"gamepad_mojom_traits.h",
]
defines = [ "IS_GAMEPAD_SHARED_TRAITS_IMPL" ]
public_deps = [
":shared_with_blink",
"//base",
"//device/gamepad/public/mojom:mojom_shared",
]
}
per-file *_mojom_traits*.*=set noparent
per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
...@@ -4,16 +4,17 @@ ...@@ -4,16 +4,17 @@
mojom = "//device/gamepad/public/mojom/gamepad.mojom" mojom = "//device/gamepad/public/mojom/gamepad.mojom"
public_headers = [ "//device/gamepad/public/cpp/gamepad.h" ] public_headers = [ "//device/gamepad/public/cpp/gamepad.h" ]
traits_headers = [ "//device/gamepad/public/mojom/gamepad_mojom_traits.h" ] traits_headers = [ "//device/gamepad/public/cpp/gamepad_mojom_traits.h" ]
sources = [
"//device/gamepad/public/mojom/gamepad_mojom_traits.cc",
]
deps = [ deps = [
"//device/gamepad/public/cpp:shared_with_blink", "//device/gamepad/public/cpp:shared_with_blink",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
"//third_party/blink/public:blink_headers", "//third_party/blink/public:blink_headers",
] ]
public_deps = [
"//device/gamepad/public/cpp:shared_typemap_traits",
]
# Use typemaps for device::Gamepad and its member types. Gamepad data is # Use typemaps for device::Gamepad and its member types. Gamepad data is
# intentionally POD and fixed size so that it can be stored in shared memory # intentionally POD and fixed size so that it can be stored in shared memory
# between hardware polling threads and the rest of the browser. # between hardware polling threads and the rest of the browser.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "device/gamepad/public/mojom/gamepad_mojom_traits.h" #include "device/gamepad/public/cpp/gamepad_mojom_traits.h"
#include "base/containers/span.h" #include "base/containers/span.h"
......
...@@ -2,22 +2,24 @@ ...@@ -2,22 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef DEVICE_GAMEPAD_PUBLIC_MOJOM_GAMEPAD_MOJOM_TRAITS_H_ #ifndef DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_MOJOM_TRAITS_H_
#define DEVICE_GAMEPAD_PUBLIC_MOJOM_GAMEPAD_MOJOM_TRAITS_H_ #define DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_MOJOM_TRAITS_H_
#include <stddef.h> #include <stddef.h>
#include "base/component_export.h"
#include "base/containers/span.h" #include "base/containers/span.h"
#include "device/gamepad/public/cpp/gamepad.h" #include "device/gamepad/public/cpp/gamepad.h"
#include "device/gamepad/public/mojom/gamepad.mojom.h" #include "device/gamepad/public/mojom/gamepad.mojom-shared.h"
#include "mojo/public/cpp/bindings/array_traits_span.h" #include "mojo/public/cpp/bindings/array_traits_span.h"
#include "mojo/public/cpp/bindings/struct_traits.h" #include "mojo/public/cpp/bindings/struct_traits.h"
namespace mojo { namespace mojo {
template <> template <>
struct StructTraits<device::mojom::GamepadQuaternionDataView, struct COMPONENT_EXPORT(GAMEPAD_SHARED_TRAITS)
device::GamepadQuaternion> { StructTraits<device::mojom::GamepadQuaternionDataView,
device::GamepadQuaternion> {
static bool IsNull(const device::GamepadQuaternion& r) { return !r.not_null; } static bool IsNull(const device::GamepadQuaternion& r) { return !r.not_null; }
static void SetToNull(device::GamepadQuaternion* out); static void SetToNull(device::GamepadQuaternion* out);
static float x(const device::GamepadQuaternion& r) { return r.x; } static float x(const device::GamepadQuaternion& r) { return r.x; }
...@@ -29,8 +31,8 @@ struct StructTraits<device::mojom::GamepadQuaternionDataView, ...@@ -29,8 +31,8 @@ struct StructTraits<device::mojom::GamepadQuaternionDataView,
}; };
template <> template <>
struct StructTraits<device::mojom::GamepadVectorDataView, struct COMPONENT_EXPORT(GAMEPAD_SHARED_TRAITS)
device::GamepadVector> { StructTraits<device::mojom::GamepadVectorDataView, device::GamepadVector> {
static bool IsNull(const device::GamepadVector& r) { return !r.not_null; } static bool IsNull(const device::GamepadVector& r) { return !r.not_null; }
static void SetToNull(device::GamepadVector* out); static void SetToNull(device::GamepadVector* out);
static float x(const device::GamepadVector& r) { return r.x; } static float x(const device::GamepadVector& r) { return r.x; }
...@@ -41,8 +43,8 @@ struct StructTraits<device::mojom::GamepadVectorDataView, ...@@ -41,8 +43,8 @@ struct StructTraits<device::mojom::GamepadVectorDataView,
}; };
template <> template <>
struct StructTraits<device::mojom::GamepadButtonDataView, struct COMPONENT_EXPORT(GAMEPAD_SHARED_TRAITS)
device::GamepadButton> { StructTraits<device::mojom::GamepadButtonDataView, device::GamepadButton> {
static bool pressed(const device::GamepadButton& r) { return r.pressed; } static bool pressed(const device::GamepadButton& r) { return r.pressed; }
static bool touched(const device::GamepadButton& r) { return r.touched; } static bool touched(const device::GamepadButton& r) { return r.touched; }
static double value(const device::GamepadButton& r) { return r.value; } static double value(const device::GamepadButton& r) { return r.value; }
...@@ -51,8 +53,9 @@ struct StructTraits<device::mojom::GamepadButtonDataView, ...@@ -51,8 +53,9 @@ struct StructTraits<device::mojom::GamepadButtonDataView,
}; };
template <> template <>
struct EnumTraits<device::mojom::GamepadHapticActuatorType, struct COMPONENT_EXPORT(GAMEPAD_SHARED_TRAITS)
device::GamepadHapticActuatorType> { EnumTraits<device::mojom::GamepadHapticActuatorType,
device::GamepadHapticActuatorType> {
static device::mojom::GamepadHapticActuatorType ToMojom( static device::mojom::GamepadHapticActuatorType ToMojom(
device::GamepadHapticActuatorType input); device::GamepadHapticActuatorType input);
static bool FromMojom(device::mojom::GamepadHapticActuatorType input, static bool FromMojom(device::mojom::GamepadHapticActuatorType input,
...@@ -60,8 +63,9 @@ struct EnumTraits<device::mojom::GamepadHapticActuatorType, ...@@ -60,8 +63,9 @@ struct EnumTraits<device::mojom::GamepadHapticActuatorType,
}; };
template <> template <>
struct StructTraits<device::mojom::GamepadHapticActuatorDataView, struct COMPONENT_EXPORT(GAMEPAD_SHARED_TRAITS)
device::GamepadHapticActuator> { StructTraits<device::mojom::GamepadHapticActuatorDataView,
device::GamepadHapticActuator> {
static bool IsNull(const device::GamepadHapticActuator& r) { static bool IsNull(const device::GamepadHapticActuator& r) {
return !r.not_null; return !r.not_null;
} }
...@@ -75,7 +79,8 @@ struct StructTraits<device::mojom::GamepadHapticActuatorDataView, ...@@ -75,7 +79,8 @@ struct StructTraits<device::mojom::GamepadHapticActuatorDataView,
}; };
template <> template <>
struct StructTraits<device::mojom::GamepadPoseDataView, device::GamepadPose> { struct COMPONENT_EXPORT(GAMEPAD_SHARED_TRAITS)
StructTraits<device::mojom::GamepadPoseDataView, device::GamepadPose> {
static bool IsNull(const device::GamepadPose& r) { return !r.not_null; } static bool IsNull(const device::GamepadPose& r) { return !r.not_null; }
static void SetToNull(device::GamepadPose* out); static void SetToNull(device::GamepadPose* out);
static const device::GamepadQuaternion& orientation( static const device::GamepadQuaternion& orientation(
...@@ -106,14 +111,16 @@ struct StructTraits<device::mojom::GamepadPoseDataView, device::GamepadPose> { ...@@ -106,14 +111,16 @@ struct StructTraits<device::mojom::GamepadPoseDataView, device::GamepadPose> {
}; };
template <> template <>
struct EnumTraits<device::mojom::GamepadHand, device::GamepadHand> { struct COMPONENT_EXPORT(GAMEPAD_SHARED_TRAITS)
EnumTraits<device::mojom::GamepadHand, device::GamepadHand> {
static device::mojom::GamepadHand ToMojom(device::GamepadHand input); static device::mojom::GamepadHand ToMojom(device::GamepadHand input);
static bool FromMojom(device::mojom::GamepadHand input, static bool FromMojom(device::mojom::GamepadHand input,
device::GamepadHand* output); device::GamepadHand* output);
}; };
template <> template <>
struct StructTraits<device::mojom::GamepadDataView, device::Gamepad> { struct COMPONENT_EXPORT(GAMEPAD_SHARED_TRAITS)
StructTraits<device::mojom::GamepadDataView, device::Gamepad> {
static bool connected(const device::Gamepad& r) { return r.connected; } static bool connected(const device::Gamepad& r) { return r.connected; }
static int64_t timestamp(const device::Gamepad& r) { return r.timestamp; } static int64_t timestamp(const device::Gamepad& r) { return r.timestamp; }
static base::span<const double> axes(const device::Gamepad& r) { static base::span<const double> axes(const device::Gamepad& r) {
...@@ -142,4 +149,4 @@ struct StructTraits<device::mojom::GamepadDataView, device::Gamepad> { ...@@ -142,4 +149,4 @@ struct StructTraits<device::mojom::GamepadDataView, device::Gamepad> {
} // namespace mojo } // namespace mojo
#endif // DEVICE_GAMEPAD_PUBLIC_MOJOM_GAMEPAD_MOJOM_TRAITS_H_ #endif // DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_MOJOM_TRAITS_H_
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
typemaps = [ "//device/gamepad/public/mojom/gamepad.typemap" ] typemaps = [ "//device/gamepad/public/cpp/gamepad.typemap" ]
...@@ -4,10 +4,13 @@ ...@@ -4,10 +4,13 @@
import("//mojo/public/tools/bindings/mojom.gni") import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") { mojom_component("mojom") {
sources = [ sources = [
"gamepad.mojom", "gamepad.mojom",
] ]
output_prefix = "gamepad_mojom"
macro_prefix = "GAMEPAD_MOJOM"
} }
mojom("gamepad_mojom_traits_test") { mojom("gamepad_mojom_traits_test") {
......
...@@ -2,7 +2,3 @@ ...@@ -2,7 +2,3 @@
# introducing new sandbox escapes. # introducing new sandbox escapes.
per-file *.mojom=set noparent per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS per-file *.mojom=file://ipc/SECURITY_OWNERS
per-file *_mojom_traits*.*=set noparent
per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
...@@ -22,7 +22,7 @@ _typemap_imports = [ ...@@ -22,7 +22,7 @@ _typemap_imports = [
"//content/public/common/typemaps.gni", "//content/public/common/typemaps.gni",
"//device/bluetooth/public/mojom/typemaps.gni", "//device/bluetooth/public/mojom/typemaps.gni",
"//device/bluetooth/public/mojom/test/typemaps.gni", "//device/bluetooth/public/mojom/test/typemaps.gni",
"//device/gamepad/public/mojom/typemaps.gni", "//device/gamepad/public/cpp/typemaps.gni",
"//gpu/ipc/common/typemaps.gni", "//gpu/ipc/common/typemaps.gni",
"//media/capture/mojom/typemaps.gni", "//media/capture/mojom/typemaps.gni",
"//media/mojo/interfaces/typemaps.gni", "//media/mojo/interfaces/typemaps.gni",
......
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