Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .gradle/6.5/fileChanges/last-build.bin
Binary file not shown.
Empty file added .gradle/6.5/gc.properties
Empty file.
2 changes: 2 additions & 0 deletions .gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Fri Jun 05 11:53:05 CDT 2020
gradle.version=6.5
Empty file added .gradle/vcs-1/gc.properties
Empty file.
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ LIBRARY: txt
ORIGIN: ../../../flutter/LICENSE
TYPE: LicenseType.bsd
FILE: ../../../flutter/.clang-tidy
FILE: ../../../flutter/.gradle/6.5/fileChanges/last-build.bin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need these .gradle/** files? I think they can be reverted in case you didn't intend to commit them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blasten The format_and_dart_test failed and said that licenses_flutter needed that file added on line 14.

Collecting licenses for fuchsia
    Skipping this component - no change in signature
Collecting licenses for gpu
    Skipping this component - no change in signature
Collecting licenses for third_party
    Skipping this component - no change in signature
Collecting licenses for skia
    Skipping this component - no change in signature
============================= ERROR =============================
License script got different results than expected for out/license_script_output/licenses_flutter.
Please rerun the licenses script locally to verify that it is
correctly catching any new licenses for anything you may have
changed, and then update this file:
  flutter/sky/packages/sky_engine/LICENSE
For more information, see the script in:
  https://github.com/flutter/engine/tree/master/tools/licenses

FILE: ../../../flutter/.gradle/buildOutputCleanup/cache.properties
FILE: ../../../flutter/DEPS
FILE: ../../../flutter/assets/asset_manager.cc
FILE: ../../../flutter/assets/asset_manager.h
Expand Down Expand Up @@ -702,6 +704,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/Flutte
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngineCache.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEnginePluginRegistry.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java
Expand Down
1 change: 1 addition & 0 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ android_java_sources = [
"io/flutter/embedding/engine/FlutterEngineCache.java",
"io/flutter/embedding/engine/FlutterEnginePluginRegistry.java",
"io/flutter/embedding/engine/FlutterJNI.java",
"io/flutter/embedding/engine/FlutterOverlaySurface.java",
"io/flutter/embedding/engine/FlutterShellArgs.java",
"io/flutter/embedding/engine/dart/DartExecutor.java",
"io/flutter/embedding/engine/dart/DartMessenger.java",
Expand Down
11 changes: 11 additions & 0 deletions shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,17 @@ public void onEndFrame() {
}
platformViewsController.onEndFrame();
}

@SuppressWarnings("unused")
@UiThread
public FlutterOverlaySurface createOverlaySurface() {
ensureRunningOnMainThread();
if (platformViewsController == null) {
throw new RuntimeException(
"platformViewsController must be set before attempting to position an overlay surface");
}
platformViewsController.onDisplayOverlaySurface(id, x, y, width, height);
}
// ----- End Engine Lifecycle Support ----

// @SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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;

public class FlutterOverlaySurface {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class needs the @Keep annotation. This is because the C++ code will do lookup by method/class name. As a result, these names cannot change, but tools like Proguard or R8 make classes and methods names shorter to reduce code size.

// @NonNull
private final Surface surface;

private final long id;

// @Keep
public FlutterOverlaySurface(long id, Surface surface) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about the annotation public FlutterOverlaySurface(long id, @NonNull Surface surface). id doesn't need one because it's a primitive type.

this.id = id;
this.surface = surface;
}

public long getId() {
return id;
}

public Surface getSurface() {
return surface;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.UiThread;
import androidx.annotation.VisibleForTesting;
import io.flutter.embedding.engine.FlutterOverlaySurface;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.systemchannels.PlatformViewsChannel;
import io.flutter.plugin.editing.TextInputPlugin;
Expand Down Expand Up @@ -549,4 +550,9 @@ public void onBeginFrame() {
public void onEndFrame() {
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
}

public FlutterOverlaySurface createOverlaySurface() {
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
return null;
}
}
9 changes: 9 additions & 0 deletions shell/platform/android/jni/platform_view_android_jni.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class PlatformViewAndroidJNI {
int y,
int width,
int height) = 0;

//----------------------------------------------------------------------------
/// @brief Initiates a frame if using hybrid composition.
///
Expand All @@ -145,6 +146,14 @@ class PlatformViewAndroidJNI {
/// @note Must be called from the platform thread.
///
virtual void FlutterViewEndFrame() = 0;

//----------------------------------------------------------------------------
/// @brief Indicates that the current frame ended.
/// It's used to clean up state.
///
/// @note Must be called from the platform thread.
///
virtual FlutterOverlaySurface FlutterViewCreateOverlaySurface() = 0;
};

} // namespace flutter
Expand Down
69 changes: 69 additions & 0 deletions shell/platform/android/platform_view_android_jni.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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_
55 changes: 55 additions & 0 deletions shell/platform/android/platform_view_android_jni_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,36 @@ 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_flutter_overlay_layer_get_id_method = nullptr;
static jmethodID g_flutter_overlay_layer_get_surface_method = nullptr;

std::unique_ptr<AndroidFlutterOverlaySurface> FlutterViewCreateOverlaySurface(
JNIEnv* env,
jobject obj) {
jobject joverlay_layer =
env->CallObjectMethod(obj, g_create_overlay_surface_method);
jlong layer_id = env->CallLongMethod(joverlay_layer,
g_flutter_overlay_layer_get_id_method);
jobject surface = env->CallObjectMethod(
joverlay_layer, g_flutter_overlay_layer_get_surface_method);

FML_CHECK(CheckException(env));
return std::make_unique<AndroidFlutterOverlaySurface>(
layer_id, fml::MakeRefCounted<AndroidNativeWindow>(
ANativeWindow_fromSurface(env, surface)));
}

static jmethodID g_on_begin_frame_method = nullptr;

static jmethodID g_on_end_frame_method = nullptr;

static jmethodID g_create_overlay_surface_method = nullptr;

static jmethodID g_flutter_overlay_layer_get_id_method = nullptr;

static jmethodID g_flutter_overlay_layer_get_surface_method = nullptr;

static jmethodID g_attach_to_gl_context_method = nullptr;

static jmethodID g_update_tex_image_method = nullptr;
Expand Down Expand Up @@ -683,6 +709,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;
}

Expand All @@ -707,6 +737,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()) {
Expand Down Expand Up @@ -738,6 +772,14 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
return false;
}

g_create_overlay_surface_method = env->GetMethodID(
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");

Expand Down Expand Up @@ -1080,4 +1122,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
2 changes: 2 additions & 0 deletions shell/platform/android/platform_view_android_jni_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class PlatformViewAndroidJNIImpl final : public PlatformViewAndroidJNI {

void FlutterViewEndFrame() override;

void FlutterViewCreateOverlaySurface() override;

private:
// Reference to FlutterJNI object.
const fml::jni::JavaObjectWeakGlobalRef java_object_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,20 @@ public void onEndFrame__callsPlatformViewsController() {
// --- Verify Results ---
verify(platformViewsController, times(1)).onEndFrame();
}

@Test
public void createOverlaySurface__callsPlatformViewsController() {
PlatformViewsController platformViewsController = mock(PlatformViewsController.class);

FlutterJNI flutterJNI = new FlutterJNI();
flutterJNI.setPlatformViewsController(platformViewsController);

// --- Execute Test ---
flutterJNI.onDisplayOverlaySurface(
/*id=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);

// --- Verify Results ---
verify(platformViewsController, times(1))
.onDisplayOverlaySurface(/*id=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);
}
}