From 5786db3a26c2d28863901a354602290aa4af7f77 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 1 Jul 2018 21:22:21 -0700 Subject: [PATCH] Fabric: Making `fabric/graphics` compilable on Android Summary: @public This compiles but this does not work. To make it actually work we have to implement all missing functions in `Color.cpp` and co. Reviewed By: fkgozali Differential Revision: D8655537 fbshipit-source-id: 564fb7131445af81cf05407239dc6ba870cf6b83 --- ReactCommon/fabric/graphics/BUCK | 40 ++++++++++++++++--- ReactCommon/fabric/graphics/ColorComponents.h | 21 ++++++++++ ReactCommon/fabric/graphics/Geometry.h | 16 +------- .../graphics/platform/android/Color.cpp | 24 +++++++++++ .../fabric/graphics/platform/android/Color.h | 24 +++++++++++ .../fabric/graphics/platform/android/Float.h | 28 +++++++++++++ .../graphics/{ => platform/ios}/Color.cpp | 3 -- .../graphics/{ => platform/ios}/Color.h | 12 ++---- .../fabric/graphics/platform/ios/Float.h | 29 ++++++++++++++ 9 files changed, 166 insertions(+), 31 deletions(-) create mode 100644 ReactCommon/fabric/graphics/ColorComponents.h create mode 100644 ReactCommon/fabric/graphics/platform/android/Color.cpp create mode 100644 ReactCommon/fabric/graphics/platform/android/Color.h create mode 100644 ReactCommon/fabric/graphics/platform/android/Float.h rename ReactCommon/fabric/graphics/{ => platform/ios}/Color.cpp (91%) rename ReactCommon/fabric/graphics/{ => platform/ios}/Color.h (77%) create mode 100644 ReactCommon/fabric/graphics/platform/ios/Float.h diff --git a/ReactCommon/fabric/graphics/BUCK b/ReactCommon/fabric/graphics/BUCK index e0b337da1..78061adc6 100644 --- a/ReactCommon/fabric/graphics/BUCK +++ b/ReactCommon/fabric/graphics/BUCK @@ -12,12 +12,15 @@ if not IS_OSS_BUILD: rn_xplat_cxx_library( name = "graphics", srcs = glob( - ["**/*.cpp"], - exclude = glob(["tests/**/*.cpp"]), + [ + "*.cpp", + ], ), - headers = glob( - ["**/*.h"], - exclude = glob(["tests/**/*.h"]), + headers = subdir_glob( + [ + ("", "*.h"), + ], + prefix = "", ), header_namespace = "", exported_headers = subdir_glob( @@ -32,6 +35,17 @@ rn_xplat_cxx_library( "-std=c++14", "-Wall", ], + fbandroid_exported_headers = subdir_glob( + [ + ("platform/android", "**/*.h"), + ], + prefix = "fabric/graphics", + ), + fbandroid_srcs = glob( + [ + "platform/android/**/*.cpp", + ], + ), fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + get_apple_inspector_flags(), fbobjc_tests = [ @@ -43,6 +57,22 @@ rn_xplat_cxx_library( "$SDKROOT/System/Library/Frameworks/Foundation.framework", "$SDKROOT/System/Library/Frameworks/UIKit.framework", ], + ios_deps = [ + "xplat//js:RCTImage", + "xplat//js/react-native-github:RCTCxxBridge", + ], + ios_exported_headers = subdir_glob( + [ + ("platform/ios", "*.h"), + ], + prefix = "fabric/graphics", + ), + ios_srcs = glob( + [ + "platform/ios/**/*.cpp", + "platform/ios/**/*.mm", + ], + ), macosx_tests_override = [], platforms = (ANDROID, APPLE), preprocessor_flags = [ diff --git a/ReactCommon/fabric/graphics/ColorComponents.h b/ReactCommon/fabric/graphics/ColorComponents.h new file mode 100644 index 000000000..489e18886 --- /dev/null +++ b/ReactCommon/fabric/graphics/ColorComponents.h @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +namespace facebook { +namespace react { + +struct ColorComponents { + float red {0}; + float green {0}; + float blue {0}; + float alpha {0}; +}; + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/graphics/Geometry.h b/ReactCommon/fabric/graphics/Geometry.h index 6e97ae851..3db790886 100644 --- a/ReactCommon/fabric/graphics/Geometry.h +++ b/ReactCommon/fabric/graphics/Geometry.h @@ -8,25 +8,11 @@ #include #include -#include +#include namespace facebook { namespace react { -/* - * Exact type of float numbers which ideally should match a type behing - * platform- and chip-architecture-specific float type. - */ -using Float = CGFloat; - -/* - * Large positive number signifies that the `Float` values is `undefined`. - */ -const Float kFloatUndefined = CGFLOAT_MAX; - -const Float kFloatMax = CGFLOAT_MAX; -const Float kFloatMin = CGFLOAT_MIN; - /* * Point */ diff --git a/ReactCommon/fabric/graphics/platform/android/Color.cpp b/ReactCommon/fabric/graphics/platform/android/Color.cpp new file mode 100644 index 000000000..3511eeb3b --- /dev/null +++ b/ReactCommon/fabric/graphics/platform/android/Color.cpp @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include "Color.h" + +namespace facebook { +namespace react { + +SharedColor colorFromComponents(ColorComponents components) { + // Not implemented. + return {}; +} + +ColorComponents colorComponentsFromColor(SharedColor color) { + // Not implemented. + return {}; +} + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/graphics/platform/android/Color.h b/ReactCommon/fabric/graphics/platform/android/Color.h new file mode 100644 index 000000000..761af1d2d --- /dev/null +++ b/ReactCommon/fabric/graphics/platform/android/Color.h @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +#include + +namespace facebook { +namespace react { + +using Color = float; +using SharedColor = std::shared_ptr; + +SharedColor colorFromComponents(ColorComponents components); +ColorComponents colorComponentsFromColor(SharedColor color); + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/graphics/platform/android/Float.h b/ReactCommon/fabric/graphics/platform/android/Float.h new file mode 100644 index 000000000..8351a8923 --- /dev/null +++ b/ReactCommon/fabric/graphics/platform/android/Float.h @@ -0,0 +1,28 @@ +// Copyright (c) 2004-present, Facebook, Inc. + +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#pragma once + +#include + +namespace facebook { +namespace react { + +/* + * Exact type of float numbers which ideally should match a type behing + * platform- and chip-architecture-specific float type. + */ +using Float = float; + +/* + * Large positive number signifies that the `Float` values is `undefined`. + */ +const Float kFloatUndefined = std::numeric_limits::max(); + +const Float kFloatMax = std::numeric_limits::max(); +const Float kFloatMin = std::numeric_limits::min(); + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/graphics/Color.cpp b/ReactCommon/fabric/graphics/platform/ios/Color.cpp similarity index 91% rename from ReactCommon/fabric/graphics/Color.cpp rename to ReactCommon/fabric/graphics/platform/ios/Color.cpp index 151e2923a..db03a0f4a 100644 --- a/ReactCommon/fabric/graphics/Color.cpp +++ b/ReactCommon/fabric/graphics/platform/ios/Color.cpp @@ -6,9 +6,6 @@ */ #include "Color.h" -#include -#include -#include namespace facebook { namespace react { diff --git a/ReactCommon/fabric/graphics/Color.h b/ReactCommon/fabric/graphics/platform/ios/Color.h similarity index 77% rename from ReactCommon/fabric/graphics/Color.h rename to ReactCommon/fabric/graphics/platform/ios/Color.h index f7622d213..019663e73 100644 --- a/ReactCommon/fabric/graphics/Color.h +++ b/ReactCommon/fabric/graphics/platform/ios/Color.h @@ -7,22 +7,18 @@ #pragma once -#include #include +#include + +#include + namespace facebook { namespace react { using Color = CGColor; using SharedColor = std::shared_ptr; -struct ColorComponents { - float red {0}; - float green {0}; - float blue {0}; - float alpha {0}; -}; - SharedColor colorFromComponents(ColorComponents components); ColorComponents colorComponentsFromColor(SharedColor color); diff --git a/ReactCommon/fabric/graphics/platform/ios/Float.h b/ReactCommon/fabric/graphics/platform/ios/Float.h new file mode 100644 index 000000000..fec03a684 --- /dev/null +++ b/ReactCommon/fabric/graphics/platform/ios/Float.h @@ -0,0 +1,29 @@ +// Copyright (c) 2004-present, Facebook, Inc. + +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +/* + * Exact type of float numbers which ideally should match a type behing + * platform- and chip-architecture-specific float type. + */ +using Float = CGFloat; + +/* + * Large positive number signifies that the `Float` values is `undefined`. + */ +const Float kFloatUndefined = std::numeric_limits::max(); + +const Float kFloatMax = std::numeric_limits::max(); +const Float kFloatMin = std::numeric_limits::min(); + +} // namespace react +} // namespace facebook