* onEndFrame JNI

* beginFrame brief change
This commit is contained in:
cg021 2020-06-12 16:21:25 -05:00 committed by GitHub
parent b0aa9f4bdc
commit ea31a75bd4
6 changed files with 63 additions and 0 deletions

View File

@ -810,6 +810,17 @@ public class FlutterJNI {
}
platformViewsController.onBeginFrame();
}
@SuppressWarnings("unused")
@UiThread
public void onEndFrame() {
ensureRunningOnMainThread();
if (platformViewsController == null) {
throw new RuntimeException(
"platformViewsController must be set before attempting to end the frame");
}
platformViewsController.onEndFrame();
}
// ----- End Engine Lifecycle Support ----
// @SuppressWarnings("unused")

View File

@ -545,4 +545,8 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
public void onBeginFrame() {
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
}
public void onEndFrame() {
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
}
}

View File

@ -137,6 +137,14 @@ class PlatformViewAndroidJNI {
/// @note Must be called from the platform thread.
///
virtual void FlutterViewBeginFrame() = 0;
//----------------------------------------------------------------------------
/// @brief Indicates that the current frame ended.
/// It's used to clean up state.
///
/// @note Must be called from the platform thread.
///
virtual void FlutterViewEndFrame() = 0;
};
} // namespace flutter

View File

@ -82,6 +82,8 @@ static jmethodID g_on_engine_restart_method = nullptr;
static jmethodID g_on_begin_frame_method = nullptr;
static jmethodID g_on_end_frame_method = nullptr;
static jmethodID g_attach_to_gl_context_method = nullptr;
static jmethodID g_update_tex_image_method = nullptr;
@ -717,6 +719,14 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
return false;
}
g_on_end_frame_method =
env->GetMethodID(g_flutter_jni_class->obj(), "onEndFrame", "()V");
if (g_on_end_frame_method == nullptr) {
FML_LOG(ERROR) << "Could not locate onEndFrame method";
return false;
}
g_on_display_overlay_surface_method = env->GetMethodID(
g_flutter_jni_class->obj(), "onDisplayOverlaySurface", "(IIIII)V");
@ -1046,4 +1056,17 @@ void PlatformViewAndroidJNIImpl::FlutterViewBeginFrame() {
FML_CHECK(CheckException(env));
}
void PlatformViewAndroidJNIImpl::FlutterViewEndFrame() {
JNIEnv* env = fml::jni::AttachCurrentThread();
auto java_object = java_object_.get(env);
if (java_object.is_null()) {
return;
}
env->CallVoidMethod(java_object.obj(), g_on_end_frame_method);
FML_CHECK(CheckException(env));
}
} // namespace flutter

View File

@ -64,6 +64,8 @@ class PlatformViewAndroidJNIImpl final : public PlatformViewAndroidJNI {
void FlutterViewBeginFrame() override;
void FlutterViewEndFrame() override;
private:
// Reference to FlutterJNI object.
const fml::jni::JavaObjectWeakGlobalRef java_object_;

View File

@ -96,4 +96,19 @@ public class FlutterJNITest {
// --- Verify Results ---
verify(platformViewsController, times(1)).onBeginFrame();
}
@Test
public void onEndFrame__callsPlatformViewsController() {
PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
// --- Test Setup ---
FlutterJNI flutterJNI = new FlutterJNI();
flutterJNI.setPlatformViewsController(platformViewsController);
// --- Execute Test ---
flutterJNI.onEndFrame();
// --- Verify Results ---
verify(platformViewsController, times(1)).onEndFrame();
}
}