Summary: This diff fixes two issues with the JNI integration of YogaLogger#log. (1) The YogaLogger class descriptor was missing a semicolon. This causes a ClassNotFoundException whenever you try to call the log method from C++. (2) The C++ signature for the class was using YogaNodeJNIBase as an arg but the Java signature was using YogaNode. This causes a MethodNotFoundException whenever you try to call the method after fixing problem 1. Reviewed By: astreet Differential Revision: D17439957 fbshipit-source-id: be3c16512558050265565b3688fb09a7da31b9b2
64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
/*
|
|
* 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 <fbjni/fbjni.h>
|
|
#include <yoga/YGValue.h>
|
|
#include <yoga/Yoga.h>
|
|
#include <map>
|
|
|
|
using namespace facebook::jni;
|
|
using namespace std;
|
|
|
|
struct JYogaNode : public facebook::jni::JavaClass<JYogaNode> {
|
|
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<JYogaLogLevel> {
|
|
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
|
|
|
|
static facebook::jni::local_ref<JYogaLogLevel> fromInt(jint);
|
|
};
|
|
|
|
struct JYogaLogger : public facebook::jni::JavaClass<JYogaLogger> {
|
|
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogger;";
|
|
|
|
void log(
|
|
facebook::jni::alias_ref<JYogaNode>,
|
|
facebook::jni::alias_ref<JYogaLogLevel>,
|
|
jstring);
|
|
};
|
|
|
|
class PtrJNodeMap {
|
|
using JNodeArray = JArrayClass<JYogaNode::javaobject>;
|
|
std::map<YGNodeRef, size_t> ptrsToIdxs_;
|
|
alias_ref<JNodeArray> javaNodes_;
|
|
|
|
public:
|
|
PtrJNodeMap() : ptrsToIdxs_{}, javaNodes_{} {}
|
|
PtrJNodeMap(
|
|
alias_ref<JArrayLong> nativePointers,
|
|
alias_ref<JNodeArray> 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<JYogaNode> ref(YGNodeRef node) {
|
|
auto idx = ptrsToIdxs_.find(node);
|
|
if (idx == ptrsToIdxs_.end()) {
|
|
return local_ref<JYogaNode>{};
|
|
} else {
|
|
return javaNodes_->getElement(idx->second);
|
|
}
|
|
}
|
|
};
|