未验证 提交 773ac974 编写于 作者: C cg021 提交者: GitHub

onDisplayPlatformView JNI (#18828)

* missing imports

* onDisplayPlatformView JNI

* imports

* ran ./ci/format.sh | patch -p0

* missing imports

* onDisplayPlatformView JNI

* imports

* ran ./ci/format.sh | patch -p0

* missing imports

* ran ./ci/format.sh | patch -p0
上级 d13861da
......@@ -103,6 +103,10 @@ public class FlutterEngine {
platformViewsController.onPreEngineRestart();
}
public void onDisplayPlatformView(int viewId, int x, int y, int width, int height) {
platformViewsController.onDisplayPlatformView(viewId, x, y, width, height);
}
};
/**
......@@ -207,6 +211,7 @@ public class FlutterEngine {
flutterLoader.ensureInitializationComplete(context, dartVmArgs);
flutterJNI.addEngineLifecycleListener(engineLifecycleListener);
flutterJNI.setPlatformViewsController(platformViewsController);
attachToJni();
this.dartExecutor = new DartExecutor(flutterJNI, context.getAssets());
......
......@@ -22,6 +22,7 @@ import io.flutter.embedding.engine.dart.PlatformMessageHandler;
import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
import io.flutter.embedding.engine.renderer.RenderSurface;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformViewsController;
import io.flutter.view.AccessibilityBridge;
import io.flutter.view.FlutterCallbackInformation;
import java.nio.ByteBuffer;
......@@ -168,6 +169,7 @@ public class FlutterJNI {
@Nullable private Long nativePlatformViewId;
@Nullable private AccessibilityDelegate accessibilityDelegate;
@Nullable private PlatformMessageHandler platformMessageHandler;
@Nullable private PlatformViewsController platformViewsController;
@NonNull
private final Set<EngineLifecycleListener> engineLifecycleListeners = new CopyOnWriteArraySet<>();
......@@ -415,6 +417,12 @@ public class FlutterJNI {
long nativePlatformViewId, @NonNull ByteBuffer buffer, int position);
// ------ End Touch Interaction Support ---
@UiThread
public void setPlatformViewsController(@NonNull PlatformViewsController platformViewsController) {
ensureRunningOnMainThread();
this.platformViewsController = platformViewsController;
}
// ------ Start Accessibility Support -----
/**
* Sets the {@link AccessibilityDelegate} for the attached Flutter context.
......@@ -782,6 +790,17 @@ public class FlutterJNI {
}
// ----- End Engine Lifecycle Support ----
// @SuppressWarnings("unused")
@UiThread
public void onDisplayPlatformView(int viewId, int x, int y, int width, int height) {
ensureRunningOnMainThread();
if (platformViewsController == null) {
throw new RuntimeException(
"platformViewsController must be set before attempting to position a platform view");
}
platformViewsController.onDisplayPlatformView(viewId, x, y, width, height);
}
// TODO(mattcarroll): determine if this is nonull or nullable
@UiThread
public Bitmap getBitmap() {
......
......@@ -533,4 +533,8 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
}
vdControllers.clear();
}
public void onDisplayPlatformView(int viewId, int x, int y, int width, int height) {
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
}
}
......@@ -118,6 +118,19 @@ void FlutterViewOnPreEngineRestart(JNIEnv* env, jobject obj) {
FML_CHECK(CheckException(env));
}
static jmethodID g_on_display_platform_view_method = nullptr;
void FlutterViewOnDisplayPlatformView(JNIEnv* env,
jobject obj,
jint view_id,
jint x,
jint y,
jint width,
jint height) {
env->CallVoidMethod(obj, g_on_display_platform_view_method, view_id, x, y,
width, height);
FML_CHECK(CheckException(env));
}
static jmethodID g_attach_to_gl_context_method = nullptr;
void SurfaceTextureAttachToGLContext(JNIEnv* env, jobject obj, jint textureId) {
env->CallVoidMethod(obj, g_attach_to_gl_context_method, textureId);
......@@ -750,6 +763,14 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
return false;
}
g_on_display_platform_view_method = env->GetMethodID(
g_flutter_jni_class->obj(), "onDisplayPlatformView", "(IIIII)V");
if (g_on_display_platform_view_method == nullptr) {
FML_LOG(ERROR) << "Could not locate onDisplayPlatformView method";
return false;
}
g_surface_texture_class = new fml::jni::ScopedJavaGlobalRef<jclass>(
env, env->FindClass("android/graphics/SurfaceTexture"));
if (g_surface_texture_class->is_null()) {
......
......@@ -36,6 +36,14 @@ void FlutterViewOnFirstFrame(JNIEnv* env, jobject obj);
void FlutterViewOnPreEngineRestart(JNIEnv* env, jobject obj);
void FlutterViewOnDisplayPlatformView(JNIEnv* env,
jobject obj,
jint view_id,
jint x,
jint y,
jint width,
jint height);
void SurfaceTextureAttachToGLContext(JNIEnv* env, jobject obj, jint textureId);
void SurfaceTextureUpdateTexImage(JNIEnv* env, jobject obj);
......
package io.flutter.embedding.engine;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
import io.flutter.plugin.platform.PlatformViewsController;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -44,4 +48,21 @@ public class FlutterJNITest {
// --- Verify Results ---
assertEquals(1, callbackInvocationCount.get());
}
@Test
public void onDisplayPlatformView__callsPlatformViewsController() {
PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
FlutterJNI flutterJNI = new FlutterJNI();
flutterJNI.setPlatformViewsController(platformViewsController);
// --- Execute Test ---
flutterJNI.onDisplayPlatformView(
/*viewId=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);
// --- Verify Results ---
verify(platformViewsController, times(1))
.onDisplayPlatformView(
/*viewId=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册