mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-11 22:40:37 +08:00
Pull an updated version of fbjni into RN OSS
Differential Revision: D3521227 fbshipit-source-id: 57db97ea2af2b2c9e55f380ce05d9e78a5f9d48c
This commit is contained in:
committed by
Facebook Github Bot 9
parent
7795918eb4
commit
7f790dc0de
@@ -3,13 +3,15 @@ include_defs('//ReactAndroid/DEFS')
|
||||
android_library(
|
||||
name = 'jni',
|
||||
srcs = glob(['**/*.java']),
|
||||
proguard_config = 'fbjni.pro',
|
||||
deps = [
|
||||
react_native_dep('java/com/facebook/proguard/annotations:annotations'),
|
||||
react_native_dep('libraries/soloader/java/com/facebook/soloader:soloader'),
|
||||
react_native_dep('third-party/java/jsr-305:jsr-305'),
|
||||
],
|
||||
visibility = [
|
||||
'PUBLIC',
|
||||
],
|
||||
]
|
||||
)
|
||||
|
||||
project_config(
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.jni;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
/**
|
||||
* A Java Object that has native memory allocated corresponding to this instance.
|
||||
@@ -23,14 +17,15 @@ import com.facebook.proguard.annotations.DoNotStrip;
|
||||
*/
|
||||
@DoNotStrip
|
||||
public class Countable {
|
||||
|
||||
static {
|
||||
SoLoader.loadLibrary("fb");
|
||||
}
|
||||
|
||||
// Private C++ instance
|
||||
@DoNotStrip
|
||||
private long mInstance = 0;
|
||||
|
||||
public Countable() {
|
||||
Prerequisites.ensure();
|
||||
}
|
||||
|
||||
public native void dispose();
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.jni;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
@DoNotStrip
|
||||
public class CppException extends RuntimeException {
|
||||
@DoNotStrip
|
||||
public CppException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.jni;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
/**
|
||||
* This object holds a native C++ member for hybrid Java/C++ objects.
|
||||
@@ -24,14 +18,15 @@ import com.facebook.proguard.annotations.DoNotStrip;
|
||||
*/
|
||||
@DoNotStrip
|
||||
public class HybridData {
|
||||
|
||||
static {
|
||||
SoLoader.loadLibrary("fb");
|
||||
}
|
||||
|
||||
// Private C++ instance
|
||||
@DoNotStrip
|
||||
private long mNativePointer = 0;
|
||||
|
||||
public HybridData() {
|
||||
Prerequisites.ensure();
|
||||
}
|
||||
|
||||
/**
|
||||
* To explicitly delete the instance, call resetNative(). If the C++
|
||||
* instance is referenced after this is called, a NullPointerException will
|
||||
@@ -47,4 +42,8 @@ public class HybridData {
|
||||
resetNative();
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return mNativePointer != 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.jni;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* To iterate over an Iterator from C++ requires two calls per entry: hasNext()
|
||||
* and next(). This helper reduces it to one call and one field get per entry.
|
||||
* It does not use a generic argument, since in C++, the types will be erased,
|
||||
* anyway. This is *not* a {@link java.util.Iterator}.
|
||||
*/
|
||||
@DoNotStrip
|
||||
public class IteratorHelper {
|
||||
private final Iterator mIterator;
|
||||
|
||||
// This is private, but accessed via JNI.
|
||||
@DoNotStrip
|
||||
private @Nullable Object mElement;
|
||||
|
||||
@DoNotStrip
|
||||
public IteratorHelper(Iterator iterator) {
|
||||
mIterator = iterator;
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public IteratorHelper(Iterable iterable) {
|
||||
mIterator = iterable.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the helper to the next entry in the map, if any. Returns true iff
|
||||
* there is an entry to read.
|
||||
*/
|
||||
@DoNotStrip
|
||||
boolean hasNext() {
|
||||
if (mIterator.hasNext()) {
|
||||
mElement = mIterator.next();
|
||||
return true;
|
||||
} else {
|
||||
mElement = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.jni;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
/**
|
||||
* To iterate over a Map from C++ requires four calls per entry: hasNext(),
|
||||
* next(), getKey(), getValue(). This helper reduces it to one call and two
|
||||
* field gets per entry. It does not use a generic argument, since in C++, the
|
||||
* types will be erased, anyway. This is *not* a {@link java.util.Iterator}.
|
||||
*/
|
||||
@DoNotStrip
|
||||
public class MapIteratorHelper {
|
||||
@DoNotStrip private final Iterator<Map.Entry> mIterator;
|
||||
@DoNotStrip private @Nullable Object mKey;
|
||||
@DoNotStrip private @Nullable Object mValue;
|
||||
|
||||
@DoNotStrip
|
||||
public MapIteratorHelper(Map map) {
|
||||
mIterator = map.entrySet().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the helper to the next entry in the map, if any. Returns true iff
|
||||
* there is an entry to read.
|
||||
*/
|
||||
@DoNotStrip
|
||||
boolean hasNext() {
|
||||
if (mIterator.hasNext()) {
|
||||
Map.Entry entry = mIterator.next();
|
||||
mKey = entry.getKey();
|
||||
mValue = entry.getValue();
|
||||
return true;
|
||||
} else {
|
||||
mKey = null;
|
||||
mValue = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -9,19 +9,20 @@
|
||||
|
||||
package com.facebook.jni;
|
||||
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
/**
|
||||
* A Runnable that has a native run implementation.
|
||||
*/
|
||||
@DoNotStrip
|
||||
public class CppSystemErrorException extends CppException {
|
||||
int errorCode;
|
||||
public class NativeRunnable implements Runnable {
|
||||
|
||||
@DoNotStrip
|
||||
public CppSystemErrorException(String message, int errorCode) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
private final HybridData mHybridData;
|
||||
|
||||
private NativeRunnable(HybridData hybridData) {
|
||||
mHybridData = hybridData;
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
public native void run();
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.facebook.jni;
|
||||
|
||||
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLContext;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
|
||||
public class Prerequisites {
|
||||
private static final int EGL_OPENGL_ES2_BIT = 0x0004;
|
||||
|
||||
public static void ensure() {
|
||||
SoLoader.loadLibrary("fb");
|
||||
}
|
||||
|
||||
// Code is simplified version of getDetectedVersion()
|
||||
// from cts/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
|
||||
static public boolean supportsOpenGL20() {
|
||||
EGL10 egl = (EGL10) EGLContext.getEGL();
|
||||
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
|
||||
int[] numConfigs = new int[1];
|
||||
|
||||
if (egl.eglInitialize(display, null)) {
|
||||
try {
|
||||
if (egl.eglGetConfigs(display, null, 0, numConfigs)) {
|
||||
EGLConfig[] configs = new EGLConfig[numConfigs[0]];
|
||||
if (egl.eglGetConfigs(display, configs, numConfigs[0], numConfigs)) {
|
||||
int[] value = new int[1];
|
||||
for (int i = 0; i < numConfigs[0]; i++) {
|
||||
if (egl.eglGetConfigAttrib(display, configs[i],
|
||||
EGL10.EGL_RENDERABLE_TYPE, value)) {
|
||||
if ((value[0] & EGL_OPENGL_ES2_BIT) == EGL_OPENGL_ES2_BIT) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
egl.eglTerminate(display);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.jni;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
@DoNotStrip
|
||||
public class ThreadScopeSupport {
|
||||
static {
|
||||
SoLoader.loadLibrary("fb");
|
||||
}
|
||||
|
||||
// This is just used for ThreadScope::withClassLoader to have a java function
|
||||
// in the stack so that jni has access to the correct classloader.
|
||||
@DoNotStrip
|
||||
private static void runStdFunction(long ptr) {
|
||||
runStdFunctionImpl(ptr);
|
||||
}
|
||||
|
||||
private static native void runStdFunctionImpl(long ptr);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.jni;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
@DoNotStrip
|
||||
public class UnknownCppException extends CppException {
|
||||
@DoNotStrip
|
||||
public UnknownCppException() {
|
||||
super("Unknown");
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public UnknownCppException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
11
ReactAndroid/src/main/java/com/facebook/jni/fbjni.pro
Normal file
11
ReactAndroid/src/main/java/com/facebook/jni/fbjni.pro
Normal file
@@ -0,0 +1,11 @@
|
||||
# For common use cases for the hybrid pattern, keep symbols which may
|
||||
# be referenced only from C++.
|
||||
|
||||
-keepclassmembers class * {
|
||||
com.facebook.jni.HybridData *;
|
||||
<init>(com.facebook.jni.HybridData);
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
com.facebook.jni.HybridData *;
|
||||
}
|
||||
Reference in New Issue
Block a user