/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the LICENSE * file in the root directory of this source tree. */ #include #include #include #include using namespace facebook::jni; using namespace std; struct JYogaNode : public facebook::jni::JavaClass { static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNIBase;"; jfloat baseline(jfloat width, jfloat height); jlong measure(jfloat width, jint widthMode, jfloat height, jint heightMode); }; struct JYogaLogLevel : public facebook::jni::JavaClass { static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;"; static facebook::jni::local_ref fromInt(jint); }; struct JYogaLogger : public facebook::jni::JavaClass { static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogger;"; void log( facebook::jni::alias_ref, facebook::jni::alias_ref, jstring); }; class PtrJNodeMap { using JNodeArray = JArrayClass; std::map ptrsToIdxs_; alias_ref javaNodes_; public: PtrJNodeMap() : ptrsToIdxs_{}, javaNodes_{} {} PtrJNodeMap( alias_ref nativePointers, alias_ref javaNodes) : javaNodes_{javaNodes} { auto pin = nativePointers->pinCritical(); auto ptrs = pin.get(); for (size_t i = 0, n = pin.size(); i < n; ++i) { ptrsToIdxs_[(YGNodeRef) ptrs[i]] = i; } } local_ref ref(YGNodeRef node) { auto idx = ptrsToIdxs_.find(node); if (idx == ptrsToIdxs_.end()) { return local_ref{}; } else { return javaNodes_->getElement(idx->second); } } };