未验证 提交 f5bdf9b0 编写于 作者: Z Zachary Anderson 提交者: GitHub

[Android] Pulls the native platform view out of FlutterView (#4338)

上级 a9319a10
......@@ -113,6 +113,7 @@ java_library("flutter_shell_java") {
"io/flutter/util/Preconditions.java",
"io/flutter/view/AccessibilityBridge.java",
"io/flutter/view/FlutterMain.java",
"io/flutter/view/FlutterNativeView.java",
"io/flutter/view/FlutterView.java",
"io/flutter/view/ResourceCleaner.java",
"io/flutter/view/ResourceExtractor.java",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package io.flutter.view;
import android.util.Log;
import io.flutter.plugin.common.*;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.HashMap;
import java.util.Map;
class FlutterNativeView implements BinaryMessenger {
private static final String TAG = "FlutterNativeView";
private final Map<String, BinaryMessageHandler> mMessageHandlers;
private int mNextReplyId = 1;
private final Map<Integer, BinaryReply> mPendingReplies = new HashMap<>();
private long mNativePlatformView;
private FlutterView mFlutterView;
FlutterNativeView(FlutterView flutterView) {
mFlutterView = flutterView;
attach(this);
assertAttached();
mMessageHandlers = new HashMap<>();
}
FlutterNativeView() {
this(null);
}
public void destroy() {
mFlutterView = null;
nativeDestroy(mNativePlatformView);
mNativePlatformView = 0;
}
public boolean isAttached() {
return mNativePlatformView != 0;
}
public long get() {
return mNativePlatformView;
}
public void assertAttached() {
if (!isAttached())
throw new AssertionError("Platform view is not attached");
}
public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, boolean reuseRuntimeController) {
assertAttached();
nativeRunBundleAndSnapshot(mNativePlatformView, bundlePath, snapshotOverride, entrypoint, reuseRuntimeController);
}
public void runFromSource(final String assetsDirectory, final String main, final String packages) {
assertAttached();
nativeRunBundleAndSource(mNativePlatformView, assetsDirectory, main, packages);
}
public static String getObservatoryUri() {
return nativeGetObservatoryUri();
}
@Override
public void send(String channel, ByteBuffer message) {
send(channel, message, null);
}
@Override
public void send(String channel, ByteBuffer message, BinaryReply callback) {
if (!isAttached()) {
Log.d(TAG, "FlutterView.send called on a detached view, channel=" + channel);
return;
}
int replyId = 0;
if (callback != null) {
replyId = mNextReplyId++;
mPendingReplies.put(replyId, callback);
}
if (message == null) {
nativeDispatchEmptyPlatformMessage(mNativePlatformView, channel, replyId);
} else {
nativeDispatchPlatformMessage(mNativePlatformView, channel, message,
message.position(), replyId);
}
}
@Override
public void setMessageHandler(String channel, BinaryMessageHandler handler) {
if (handler == null) {
mMessageHandlers.remove(channel);
} else {
mMessageHandlers.put(channel, handler);
}
}
private void attach(FlutterNativeView view) {
mNativePlatformView = nativeAttach(view);
}
// Called by native to send us a platform message.
private void handlePlatformMessage(final String channel, byte[] message, final int replyId) {
assertAttached();
BinaryMessageHandler handler = mMessageHandlers.get(channel);
if (handler != null) {
try {
final ByteBuffer buffer = (message == null ? null : ByteBuffer.wrap(message));
handler.onMessage(buffer,
new BinaryReply() {
private final AtomicBoolean done = new AtomicBoolean(false);
@Override
public void reply(ByteBuffer reply) {
if (!isAttached()) {
Log.d(TAG, "handlePlatformMessage replying to a detached view, channel=" + channel);
return;
}
if (done.getAndSet(true)) {
throw new IllegalStateException("Reply already submitted");
}
if (reply == null) {
nativeInvokePlatformMessageEmptyResponseCallback(mNativePlatformView,
replyId);
} else {
nativeInvokePlatformMessageResponseCallback(mNativePlatformView,
replyId, reply, reply.position());
}
}
});
} catch (Exception ex) {
Log.e(TAG, "Uncaught exception in binary message listener", ex);
nativeInvokePlatformMessageEmptyResponseCallback(mNativePlatformView, replyId);
}
return;
}
nativeInvokePlatformMessageEmptyResponseCallback(mNativePlatformView, replyId);
}
// Called by native to respond to a platform message that we sent.
private void handlePlatformMessageResponse(int replyId, byte[] reply) {
BinaryReply callback = mPendingReplies.remove(replyId);
if (callback != null) {
try {
callback.reply(reply == null ? null : ByteBuffer.wrap(reply));
} catch (Exception ex) {
Log.e(TAG, "Uncaught exception in binary message reply handler", ex);
}
}
}
// Called by native to update the semantics/accessibility tree.
private void updateSemantics(ByteBuffer buffer, String[] strings) {
if (mFlutterView == null)
return;
mFlutterView.updateSemantics(buffer, strings);
}
// Called by native to notify first Flutter frame rendered.
private void onFirstFrame() {
if (mFlutterView == null)
return;
mFlutterView.onFirstFrame();
}
private static native long nativeAttach(FlutterNativeView view);
private static native void nativeDestroy(long nativePlatformViewAndroid);
private static native void nativeRunBundleAndSnapshot(long nativePlatformViewAndroid,
String bundlePath,
String snapshotOverride,
String entrypoint,
boolean reuseRuntimeController);
private static native void nativeRunBundleAndSource(long nativePlatformViewAndroid,
String bundlePath,
String main,
String packages);
private static native String nativeGetObservatoryUri();
// Send an empty platform message to Dart.
private static native void nativeDispatchEmptyPlatformMessage(long nativePlatformViewAndroid,
String channel, int responseId);
// Send a data-carrying platform message to Dart.
private static native void nativeDispatchPlatformMessage(long nativePlatformViewAndroid,
String channel, ByteBuffer message, int position, int responseId);
// Send an empty response to a platform message received from Dart.
private static native void nativeInvokePlatformMessageEmptyResponseCallback(
long nativePlatformViewAndroid, int responseId);
// Send a data-carrying response to a platform message received from Dart.
private static native void nativeInvokePlatformMessageResponseCallback(
long nativePlatformViewAndroid, int responseId, ByteBuffer message, int position);
}
......@@ -84,7 +84,6 @@ public class FlutterView extends SurfaceView
private static final String ACTION_DISCOVER = "io.flutter.view.DISCOVER";
static final class ViewportMetrics {
float devicePixelRatio = 1.0f;
int physicalWidth = 0;
int physicalHeight = 0;
......@@ -95,7 +94,6 @@ public class FlutterView extends SurfaceView
}
private final TextInputPlugin mTextInputPlugin;
private final Map<String, BinaryMessageHandler> mMessageHandlers;
private final SurfaceHolder.Callback mSurfaceCallback;
private final ViewportMetrics mMetrics;
private final AccessibilityManager mAccessibilityManager;
......@@ -109,7 +107,7 @@ public class FlutterView extends SurfaceView
private final List<ActivityLifecycleListener> mActivityLifecycleListeners;
private final List<FirstFrameListener> mFirstFrameListeners;
private final AtomicLong nextTextureId = new AtomicLong(0L);
private long mNativePlatformView;
private FlutterNativeView mNativeView;
private boolean mIsSoftwareRenderingEnabled = false; // using the software renderer or not
public FlutterView(Context context) {
......@@ -126,8 +124,7 @@ public class FlutterView extends SurfaceView
setFocusable(true);
setFocusableInTouchMode(true);
attach();
assertAttached();
mNativeView = new FlutterNativeView(this);
int color = 0xFF000000;
TypedValue typedValue = new TypedValue();
......@@ -143,19 +140,19 @@ public class FlutterView extends SurfaceView
@Override
public void surfaceCreated(SurfaceHolder holder) {
assertAttached();
nativeSurfaceCreated(mNativePlatformView, holder.getSurface(), backgroundColor);
nativeSurfaceCreated(mNativeView.get(), holder.getSurface(), backgroundColor);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
assertAttached();
nativeSurfaceChanged(mNativePlatformView, width, height);
nativeSurfaceChanged(mNativeView.get(), width, height);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
assertAttached();
nativeSurfaceDestroyed(mNativePlatformView);
nativeSurfaceDestroyed(mNativeView.get());
}
};
getHolder().addCallback(mSurfaceCallback);
......@@ -163,7 +160,6 @@ public class FlutterView extends SurfaceView
mAccessibilityManager = (AccessibilityManager) getContext()
.getSystemService(Context.ACCESSIBILITY_SERVICE);
mMessageHandlers = new HashMap<>();
mActivityLifecycleListeners = new ArrayList<>();
mFirstFrameListeners = new ArrayList<>();
......@@ -323,8 +319,6 @@ public class FlutterView extends SurfaceView
}
getHolder().removeCallback(mSurfaceCallback);
nativeDetach(mNativePlatformView);
mNativePlatformView = 0;
}
@Override
......@@ -496,7 +490,7 @@ public class FlutterView extends SurfaceView
}
assert packet.position() % (kPointerDataFieldCount * kBytePerField) == 0;
nativeDispatchPointerDataPacket(mNativePlatformView, packet, packet.position());
nativeDispatchPointerDataPacket(mNativeView.get(), packet, packet.position());
return true;
}
......@@ -547,17 +541,12 @@ public class FlutterView extends SurfaceView
}
}
private void attach() {
mNativePlatformView = nativeAttach(this);
}
private boolean isAttached() {
return mNativePlatformView != 0;
return mNativeView.isAttached();
}
void assertAttached() {
if (!isAttached())
throw new AssertionError("Platform view is not attached");
mNativeView.assertAttached();
}
private void preRun() {
......@@ -578,18 +567,16 @@ public class FlutterView extends SurfaceView
public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, boolean reuseRuntimeController) {
assertAttached();
preRun();
nativeRunBundleAndSnapshot(mNativePlatformView, bundlePath, snapshotOverride, entrypoint, reuseRuntimeController);
mNativeView.runFromBundle(bundlePath, snapshotOverride, entrypoint, reuseRuntimeController);
postRun();
}
private void runFromSource(final String assetsDirectory,
final String main,
final String packages) {
private void runFromSource(final String assetsDirectory, final String main, final String packages) {
Runnable runnable = new Runnable() {
public void run() {
assertAttached();
preRun();
nativeRunBundleAndSource(mNativePlatformView, assetsDirectory, main, packages);
mNativeView.runFromSource(assetsDirectory, main, packages);
postRun();
synchronized (this) {
notify();
......@@ -616,15 +603,9 @@ public class FlutterView extends SurfaceView
*/
public Bitmap getBitmap() {
assertAttached();
return nativeGetBitmap(mNativePlatformView);
return nativeGetBitmap(mNativeView.get());
}
private static native long nativeAttach(FlutterView view);
private static native String nativeGetObservatoryUri();
private static native void nativeDetach(long nativePlatformViewAndroid);
private static native void nativeSurfaceCreated(long nativePlatformViewAndroid,
Surface surface,
int backgroundColor);
......@@ -635,17 +616,6 @@ public class FlutterView extends SurfaceView
private static native void nativeSurfaceDestroyed(long nativePlatformViewAndroid);
private static native void nativeRunBundleAndSnapshot(long nativePlatformViewAndroid,
String bundlePath,
String snapshotOverride,
String entrypoint,
boolean reuseRuntimeController);
private static native void nativeRunBundleAndSource(long nativePlatformViewAndroid,
String bundlePath,
String main,
String packages);
private static native void nativeSetViewportMetrics(long nativePlatformViewAndroid,
float devicePixelRatio,
int physicalWidth,
......@@ -657,14 +627,6 @@ public class FlutterView extends SurfaceView
private static native Bitmap nativeGetBitmap(long nativePlatformViewAndroid);
// Send a data-carrying platform message to Dart.
private static native void nativeDispatchPlatformMessage(long nativePlatformViewAndroid,
String channel, ByteBuffer message, int position, int responseId);
// Send an empty platform message to Dart.
private static native void nativeDispatchEmptyPlatformMessage(long nativePlatformViewAndroid,
String channel, int responseId);
private static native void nativeDispatchPointerDataPacket(long nativePlatformViewAndroid,
ByteBuffer buffer, int position);
......@@ -674,14 +636,6 @@ public class FlutterView extends SurfaceView
private static native void nativeSetSemanticsEnabled(long nativePlatformViewAndroid,
boolean enabled);
// Send a data-carrying response to a platform message received from Dart.
private static native void nativeInvokePlatformMessageResponseCallback(
long nativePlatformViewAndroid, int responseId, ByteBuffer message, int position);
// Send an empty response to a platform message received from Dart.
private static native void nativeInvokePlatformMessageEmptyResponseCallback(
long nativePlatformViewAndroid, int responseId);
private static native boolean nativeGetIsSoftwareRenderingEnabled();
private static native void nativeRegisterTexture(long nativePlatformViewAndroid, long textureId, SurfaceTexture surfaceTexture);
......@@ -693,7 +647,7 @@ public class FlutterView extends SurfaceView
private void updateViewportMetrics() {
if (!isAttached())
return;
nativeSetViewportMetrics(mNativePlatformView,
nativeSetViewportMetrics(mNativeView.get(),
mMetrics.devicePixelRatio,
mMetrics.physicalWidth,
mMetrics.physicalHeight,
......@@ -708,60 +662,8 @@ public class FlutterView extends SurfaceView
VsyncWaiter.refreshPeriodNanos = (long)(1000000000.0 / fps);
}
// Called by native to send us a platform message.
private void handlePlatformMessage(final String channel, byte[] message, final int replyId) {
assertAttached();
BinaryMessageHandler handler = mMessageHandlers.get(channel);
if (handler != null) {
try {
final ByteBuffer buffer = (message == null ? null : ByteBuffer.wrap(message));
handler.onMessage(buffer,
new BinaryReply() {
private final AtomicBoolean done = new AtomicBoolean(false);
@Override
public void reply(ByteBuffer reply) {
if (!isAttached()) {
Log.d(TAG, "handlePlatformMessage replying to a detached view, channel=" + channel);
return;
}
if (done.getAndSet(true)) {
throw new IllegalStateException("Reply already submitted");
}
if (reply == null) {
nativeInvokePlatformMessageEmptyResponseCallback(mNativePlatformView,
replyId);
} else {
nativeInvokePlatformMessageResponseCallback(mNativePlatformView,
replyId, reply, reply.position());
}
}
});
} catch (Exception ex) {
Log.e(TAG, "Uncaught exception in binary message listener", ex);
nativeInvokePlatformMessageEmptyResponseCallback(mNativePlatformView, replyId);
}
return;
}
nativeInvokePlatformMessageEmptyResponseCallback(mNativePlatformView, replyId);
}
private int mNextReplyId = 1;
private final Map<Integer, BinaryReply> mPendingReplies = new HashMap<>();
// Called by native to respond to a platform message that we sent.
private void handlePlatformMessageResponse(int replyId, byte[] reply) {
BinaryReply callback = mPendingReplies.remove(replyId);
if (callback != null) {
try {
callback.reply(reply == null ? null : ByteBuffer.wrap(reply));
} catch (Exception ex) {
Log.e(TAG, "Uncaught exception in binary message reply handler", ex);
}
}
}
// Called by native to update the semantics/accessibility tree.
private void updateSemantics(ByteBuffer buffer, String[] strings) {
public void updateSemantics(ByteBuffer buffer, String[] strings) {
try {
if (mAccessibilityNodeProvider != null) {
buffer.order(ByteOrder.LITTLE_ENDIAN);
......@@ -773,7 +675,7 @@ public class FlutterView extends SurfaceView
}
// Called by native to notify first Flutter frame rendered.
private void onFirstFrame() {
public void onFirstFrame() {
for (FirstFrameListener listener : mFirstFrameListeners) {
listener.onFirstFrame();
}
......@@ -788,7 +690,7 @@ public class FlutterView extends SurfaceView
protected void dispatchSemanticsAction(int id, int action) {
if (!isAttached())
return;
nativeDispatchSemanticsAction(mNativePlatformView, id, action);
nativeDispatchSemanticsAction(mNativeView.get(), id, action);
}
@Override
......@@ -872,7 +774,7 @@ public class FlutterView extends SurfaceView
mAccessibilityEnabled = true;
if (mAccessibilityNodeProvider == null) {
mAccessibilityNodeProvider = new AccessibilityBridge(this);
nativeSetSemanticsEnabled(mNativePlatformView, true);
nativeSetSemanticsEnabled(mNativeView.get(), true);
}
mAccessibilityNodeProvider.setAccessibilityEnabled(true);
}
......@@ -901,36 +803,17 @@ public class FlutterView extends SurfaceView
@Override
public void send(String channel, ByteBuffer message) {
send(channel, message, null);
mNativeView.send(channel, message);
}
@Override
public void send(String channel, ByteBuffer message, BinaryReply callback) {
if (!isAttached()) {
Log.d(TAG, "FlutterView.send called on a detached view, channel=" + channel);
return;
}
int replyId = 0;
if (callback != null) {
replyId = mNextReplyId++;
mPendingReplies.put(replyId, callback);
}
if (message == null) {
nativeDispatchEmptyPlatformMessage(mNativePlatformView, channel, replyId);
} else {
nativeDispatchPlatformMessage(mNativePlatformView, channel, message,
message.position(), replyId);
}
mNativeView.send(channel, message, callback);
}
@Override
public void setMessageHandler(String channel, BinaryMessageHandler handler) {
if (handler == null) {
mMessageHandlers.remove(channel);
} else {
mMessageHandlers.put(channel, handler);
}
mNativeView.setMessageHandler(channel, handler);
}
/**
......@@ -944,7 +827,7 @@ public class FlutterView extends SurfaceView
@Override
public void onReceive(Context context, Intent intent) {
URI observatoryUri = URI.create(nativeGetObservatoryUri());
URI observatoryUri = URI.create(FlutterNativeView.getObservatoryUri());
JSONObject discover = new JSONObject();
try {
discover.put("id", getContext().getPackageName());
......@@ -968,7 +851,7 @@ public class FlutterView extends SurfaceView
surfaceTexture.detachFromGLContext();
final SurfaceTextureRegistryEntry entry = new SurfaceTextureRegistryEntry(
nextTextureId.getAndIncrement(), surfaceTexture);
nativeRegisterTexture(mNativePlatformView, entry.id(), surfaceTexture);
nativeRegisterTexture(mNativeView.get(), entry.id(), surfaceTexture);
return entry;
}
......@@ -983,7 +866,7 @@ public class FlutterView extends SurfaceView
this.surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
@Override
public void onFrameAvailable(SurfaceTexture texture) {
nativeMarkTextureFrameAvailable(mNativePlatformView, SurfaceTextureRegistryEntry.this.id);
nativeMarkTextureFrameAvailable(mNativeView.get(), SurfaceTextureRegistryEntry.this.id);
}
});
}
......@@ -1004,7 +887,7 @@ public class FlutterView extends SurfaceView
return;
}
released = true;
nativeUnregisterTexture(mNativePlatformView, id);
nativeUnregisterTexture(mNativeView.get(), id);
surfaceTexture.release();
}
}
......
......@@ -19,6 +19,8 @@
namespace shell {
static fml::jni::ScopedJavaGlobalRef<jclass>* g_flutter_view_class = nullptr;
static fml::jni::ScopedJavaGlobalRef<jclass>* g_flutter_native_view_class =
nullptr;
static fml::jni::ScopedJavaGlobalRef<jclass>* g_surface_texture_class = nullptr;
// Called By Native
......@@ -92,7 +94,7 @@ static jlong Attach(JNIEnv* env, jclass clazz, jobject flutterView) {
return reinterpret_cast<jlong>(storage);
}
static void Detach(JNIEnv* env, jobject jcaller, jlong platform_view) {
static void Destroy(JNIEnv* env, jobject jcaller, jlong platform_view) {
PLATFORM_VIEW->Detach();
delete &PLATFORM_VIEW;
}
......@@ -276,28 +278,72 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
return false;
}
g_flutter_native_view_class = new fml::jni::ScopedJavaGlobalRef<jclass>(
env, env->FindClass("io/flutter/view/FlutterNativeView"));
if (g_flutter_native_view_class->is_null()) {
return false;
}
g_surface_texture_class = new fml::jni::ScopedJavaGlobalRef<jclass>(
env, env->FindClass("android/graphics/SurfaceTexture"));
if (g_surface_texture_class->is_null()) {
return false;
}
static const JNINativeMethod methods[] = {
static const JNINativeMethod native_view_methods[] = {
{
.name = "nativeAttach",
.signature = "(Lio/flutter/view/FlutterView;)J",
.signature = "(Lio/flutter/view/FlutterNativeView;)J",
.fnPtr = reinterpret_cast<void*>(&shell::Attach),
},
{
.name = "nativeDetach",
.name = "nativeDestroy",
.signature = "(J)V",
.fnPtr = reinterpret_cast<void*>(&shell::Detach),
.fnPtr = reinterpret_cast<void*>(&shell::Destroy),
},
{
.name = "nativeRunBundleAndSnapshot",
.signature =
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V",
.fnPtr = reinterpret_cast<void*>(&shell::RunBundleAndSnapshot),
},
{
.name = "nativeRunBundleAndSource",
.signature =
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
.fnPtr = reinterpret_cast<void*>(&shell::RunBundleAndSource),
},
{
.name = "nativeGetObservatoryUri",
.signature = "()Ljava/lang/String;",
.fnPtr = reinterpret_cast<void*>(&shell::GetObservatoryUri),
},
{
.name = "nativeDispatchEmptyPlatformMessage",
.signature = "(JLjava/lang/String;I)V",
.fnPtr =
reinterpret_cast<void*>(&shell::DispatchEmptyPlatformMessage),
},
{
.name = "nativeDispatchPlatformMessage",
.signature = "(JLjava/lang/String;Ljava/nio/ByteBuffer;II)V",
.fnPtr = reinterpret_cast<void*>(&shell::DispatchPlatformMessage),
},
{
.name = "nativeInvokePlatformMessageResponseCallback",
.signature = "(JILjava/nio/ByteBuffer;I)V",
.fnPtr = reinterpret_cast<void*>(
&shell::InvokePlatformMessageResponseCallback),
},
{
.name = "nativeInvokePlatformMessageEmptyResponseCallback",
.signature = "(JI)V",
.fnPtr = reinterpret_cast<void*>(
&shell::InvokePlatformMessageEmptyResponseCallback),
},
};
static const JNINativeMethod view_methods[] = {
{
.name = "nativeSurfaceCreated",
.signature = "(JLandroid/view/Surface;I)V",
......@@ -313,18 +359,6 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
.signature = "(J)V",
.fnPtr = reinterpret_cast<void*>(&shell::SurfaceDestroyed),
},
{
.name = "nativeRunBundleAndSnapshot",
.signature =
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V",
.fnPtr = reinterpret_cast<void*>(&shell::RunBundleAndSnapshot),
},
{
.name = "nativeRunBundleAndSource",
.signature =
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
.fnPtr = reinterpret_cast<void*>(&shell::RunBundleAndSource),
},
{
.name = "nativeSetViewportMetrics",
.signature = "(JFIIIIII)V",
......@@ -335,17 +369,6 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
.signature = "(J)Landroid/graphics/Bitmap;",
.fnPtr = reinterpret_cast<void*>(&shell::GetBitmap),
},
{
.name = "nativeDispatchPlatformMessage",
.signature = "(JLjava/lang/String;Ljava/nio/ByteBuffer;II)V",
.fnPtr = reinterpret_cast<void*>(&shell::DispatchPlatformMessage),
},
{
.name = "nativeDispatchEmptyPlatformMessage",
.signature = "(JLjava/lang/String;I)V",
.fnPtr =
reinterpret_cast<void*>(&shell::DispatchEmptyPlatformMessage),
},
{
.name = "nativeDispatchPointerDataPacket",
.signature = "(JLjava/nio/ByteBuffer;I)V",
......@@ -361,18 +384,6 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
.signature = "(JZ)V",
.fnPtr = reinterpret_cast<void*>(&shell::SetSemanticsEnabled),
},
{
.name = "nativeInvokePlatformMessageResponseCallback",
.signature = "(JILjava/nio/ByteBuffer;I)V",
.fnPtr = reinterpret_cast<void*>(
&shell::InvokePlatformMessageResponseCallback),
},
{
.name = "nativeInvokePlatformMessageEmptyResponseCallback",
.signature = "(JI)V",
.fnPtr = reinterpret_cast<void*>(
&shell::InvokePlatformMessageEmptyResponseCallback),
},
{
.name = "nativeGetIsSoftwareRenderingEnabled",
.signature = "()Z",
......@@ -395,36 +406,43 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
},
};
if (env->RegisterNatives(g_flutter_view_class->obj(), methods,
arraysize(methods)) != 0) {
if (env->RegisterNatives(g_flutter_native_view_class->obj(),
native_view_methods,
arraysize(native_view_methods)) != 0) {
return false;
}
if (env->RegisterNatives(g_flutter_view_class->obj(), view_methods,
arraysize(view_methods)) != 0) {
return false;
}
g_handle_platform_message_method =
env->GetMethodID(g_flutter_view_class->obj(), "handlePlatformMessage",
"(Ljava/lang/String;[BI)V");
env->GetMethodID(g_flutter_native_view_class->obj(),
"handlePlatformMessage", "(Ljava/lang/String;[BI)V");
if (g_handle_platform_message_method == nullptr) {
return false;
}
g_handle_platform_message_response_method = env->GetMethodID(
g_flutter_view_class->obj(), "handlePlatformMessageResponse", "(I[B)V");
g_handle_platform_message_response_method =
env->GetMethodID(g_flutter_native_view_class->obj(),
"handlePlatformMessageResponse", "(I[B)V");
if (g_handle_platform_message_response_method == nullptr) {
return false;
}
g_update_semantics_method =
env->GetMethodID(g_flutter_view_class->obj(), "updateSemantics",
env->GetMethodID(g_flutter_native_view_class->obj(), "updateSemantics",
"(Ljava/nio/ByteBuffer;[Ljava/lang/String;)V");
if (g_update_semantics_method == nullptr) {
return false;
}
g_on_first_frame_method =
env->GetMethodID(g_flutter_view_class->obj(), "onFirstFrame", "()V");
g_on_first_frame_method = env->GetMethodID(g_flutter_native_view_class->obj(),
"onFirstFrame", "()V");
if (g_on_first_frame_method == nullptr) {
return false;
......
......@@ -1174,6 +1174,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/common/StandardM
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/common/StringCodec.java
FILE: ../../../flutter/shell/platform/android/io/flutter/util/PathUtils.java
FILE: ../../../flutter/shell/platform/android/io/flutter/util/Preconditions.java
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterNativeView.java
FILE: ../../../flutter/shell/platform/android/io/flutter/view/TextureRegistry.java
FILE: ../../../flutter/shell/platform/android/platform_view_android_jni.cc
FILE: ../../../flutter/shell/platform/android/platform_view_android_jni.h
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册