onDisplayPlatformView JNI (flutter/engine#18786)

* onDisplayPlatformView JNI

* format

* add todo in onDisplayPlatformView

Co-authored-by: Emmanuel Garcia <egarciad@google.com>

* move methods

* add platformViewsController setter

* remove unnecessary calls

* remove override and add unit test

* remove override

* test

* mockito

* fix formatting

Co-authored-by: Emmanuel Garcia <egarciad@google.com>
This commit is contained in:
cg021
2020-06-04 11:20:45 -05:00
committed by GitHub
parent ff92a0e6f5
commit 24d7c5c16b
6 changed files with 75 additions and 0 deletions

View File

@@ -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());

View File

@@ -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() {

View File

@@ -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
}
}

View File

@@ -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()) {

View File

@@ -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);

View File

@@ -1,6 +1,7 @@
package io.flutter.embedding.engine;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
import java.util.concurrent.atomic.AtomicInteger;
@@ -44,4 +45,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);
}
}