This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
add createOverlaySurface JNI #19040
Merged
Merged
add createOverlaySurface JNI #19040
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright 2013 The Flutter 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.embedding.engine; | ||
|
|
||
| import android.view.Surface; | ||
| import androidx.annotation.Keep; | ||
| import androidx.annotation.NonNull; | ||
|
|
||
| public class FlutterOverlaySurface { | ||
| @NonNull private final Surface surface; | ||
|
|
||
| private final long id; | ||
|
|
||
| @Keep | ||
| public FlutterOverlaySurface(long id, @NonNull Surface surface) { | ||
| this.id = id; | ||
| this.surface = surface; | ||
| } | ||
|
|
||
| public long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public Surface getSurface() { | ||
| return surface; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
|
|
||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_JNI_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_JNI_H_ | ||
|
|
||
| #include <jni.h> | ||
| #include "flutter/fml/macros.h" | ||
| #include "flutter/shell/platform/android/platform_view_android.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| void FlutterViewHandlePlatformMessage(JNIEnv* env, | ||
| jobject obj, | ||
| jstring channel, | ||
| jobject message, | ||
| jint responseId); | ||
|
|
||
| void FlutterViewHandlePlatformMessageResponse(JNIEnv* env, | ||
| jobject obj, | ||
| jint responseId, | ||
| jobject response); | ||
|
|
||
| void FlutterViewUpdateSemantics(JNIEnv* env, | ||
| jobject obj, | ||
| jobject buffer, | ||
| jobjectArray strings); | ||
|
|
||
| void FlutterViewUpdateCustomAccessibilityActions(JNIEnv* env, | ||
| jobject obj, | ||
| jobject buffer, | ||
| jobjectArray strings); | ||
|
|
||
| void FlutterViewOnFirstFrame(JNIEnv* env, jobject obj); | ||
|
|
||
| void FlutterViewOnPreEngineRestart(JNIEnv* env, jobject obj); | ||
|
|
||
| class AndroidFlutterOverlaySurface { | ||
| public: | ||
| AndroidFlutterOverlaySurface(long id, fml::RefPtr<AndroidNativeWindow> window) | ||
| : id_(id), window_(std::move(window)){}; | ||
|
|
||
| long GetId() { return id_; } | ||
|
|
||
| fml::RefPtr<AndroidNativeWindow> GetWindow() { return window_; } | ||
|
|
||
| private: | ||
| long id_; | ||
| fml::RefPtr<AndroidNativeWindow> window_; | ||
| }; | ||
|
|
||
| std::unique_ptr<AndroidFlutterOverlaySurface> FlutterViewCreateOverlaySurface( | ||
| JNIEnv* env, | ||
| jobject obj); | ||
|
|
||
| void SurfaceTextureAttachToGLContext(JNIEnv* env, jobject obj, jint textureId); | ||
|
|
||
| void SurfaceTextureUpdateTexImage(JNIEnv* env, jobject obj); | ||
|
|
||
| void SurfaceTextureGetTransformMatrix(JNIEnv* env, | ||
| jobject obj, | ||
| jfloatArray result); | ||
|
|
||
| void SurfaceTextureDetachFromGLContext(JNIEnv* env, jobject obj); | ||
|
|
||
| } // namespace flutter | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_JNI_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,9 @@ | |
| #include "flutter/shell/platform/android/android_shell_holder.h" | ||
| #include "flutter/shell/platform/android/apk_asset_provider.h" | ||
| #include "flutter/shell/platform/android/flutter_main.h" | ||
| #include "flutter/shell/platform/android/jni/platform_view_android_jni.h" | ||
| #include "flutter/shell/platform/android/platform_view_android.h" | ||
| #include "flutter/shell/platform/android/platform_view_android_jni.h" | ||
|
|
||
| #define ANDROID_SHELL_HOLDER \ | ||
| (reinterpret_cast<AndroidShellHolder*>(shell_holder)) | ||
|
|
@@ -80,6 +82,8 @@ static jmethodID g_on_first_frame_method = nullptr; | |
|
|
||
| static jmethodID g_on_engine_restart_method = nullptr; | ||
|
|
||
| static jmethodID g_create_overlay_surface_method = nullptr; | ||
|
|
||
| static jmethodID g_on_begin_frame_method = nullptr; | ||
|
|
||
| static jmethodID g_on_end_frame_method = nullptr; | ||
|
|
@@ -683,6 +687,10 @@ bool RegisterApi(JNIEnv* env) { | |
| return false; | ||
| } | ||
|
|
||
| g_create_overlay_surface_method = | ||
| env->GetMethodID(g_flutter_jni_class->obj(), "createOverlaySurface", | ||
| "()Lio/flutter/embedding/engine/FlutterOverlaySurface;"); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -707,6 +715,10 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { | |
| return false; | ||
| } | ||
|
|
||
| g_create_overlay_surface_method = | ||
| env->GetMethodID(g_flutter_jni_class->obj(), "createOverlaySurface", | ||
| "()Lio/flutter/embedding/engine/FlutterOverlaySurface;"); | ||
|
|
||
| g_flutter_jni_class = new fml::jni::ScopedJavaGlobalRef<jclass>( | ||
| env, env->FindClass("io/flutter/embedding/engine/FlutterJNI")); | ||
| if (g_flutter_jni_class->is_null()) { | ||
|
|
@@ -738,6 +750,14 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { | |
| return false; | ||
| } | ||
|
|
||
| g_create_overlay_surface_method = env->GetMethodID( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, I didn't catch this one: |
||
| g_flutter_jni_class->obj(), "createOverlaySurface", "()V"); | ||
|
|
||
| if (g_create_overlay_surface_method == nullptr) { | ||
| FML_LOG(ERROR) << "Could not locate createOverlaySurface method"; | ||
| return false; | ||
| } | ||
|
|
||
| g_on_display_overlay_surface_method = env->GetMethodID( | ||
| g_flutter_jni_class->obj(), "onDisplayOverlaySurface", "(IIIII)V"); | ||
|
|
||
|
|
@@ -1080,4 +1100,17 @@ void PlatformViewAndroidJNIImpl::FlutterViewEndFrame() { | |
| FML_CHECK(CheckException(env)); | ||
| } | ||
|
|
||
| void PlatformViewAndroidJNIImpl::FlutterViewCreateOverlaySurface() { | ||
| JNIEnv* env = fml::jni::AttachCurrentThread(); | ||
|
|
||
| auto java_object = java_object_.get(env); | ||
| if (java_object.is_null()) { | ||
| return; | ||
| } | ||
|
|
||
| env->CallVoidMethod(java_object.obj(), g_create_overlay_surface_method); | ||
|
|
||
| FML_CHECK(CheckException(env)); | ||
| } | ||
|
|
||
| } // namespace flutter | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.