Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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
3 changes: 3 additions & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ struct Settings {
bool enable_impeller = false;
#endif

// Indicates if image reader backed platform views are disabled.
bool disable_image_reader_platform_views = false;

// Requests a particular backend to be used (ex "opengles" or "vulkan")
std::optional<std::string> impeller_backend;

Expand Down
11 changes: 11 additions & 0 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,17 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
}
}

{
std::string disable_image_reader_platform_views_value;
if (command_line.GetOptionValue(
FlagForSwitch(Switch::DisableImageReaderPlatformViews),
&disable_image_reader_platform_views_value)) {
settings.disable_image_reader_platform_views =
disable_image_reader_platform_views_value.empty() ||
"true" == disable_image_reader_platform_views_value;
}
}

{
std::string impeller_backend_value;
if (command_line.GetOptionValue(FlagForSwitch(Switch::ImpellerBackend),
Expand Down
3 changes: 3 additions & 0 deletions shell/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ DEF_SWITCH(LeakVM,
"When the last shell shuts down, the shared VM is leaked by default "
"(the leak_vm in VM settings is true). To clean up the leak VM, set "
"this value to false.")
DEF_SWITCH(DisableImageReaderPlatformViews,
"disable-image-reader-platform-views",
"Disables the use of ImageReader backed Platform Views on Android.")
DEF_SWITCH(
MsaaSamples,
"msaa-samples",
Expand Down
19 changes: 19 additions & 0 deletions shell/common/switches_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ TEST(SwitchesTest, NoEnableImpeller) {
}
}

TEST(SwitchesTest, DisableImageReaderPlatformViews) {
{
// enable
fml::CommandLine command_line = fml::CommandLineFromInitializerList(
{"command", "--disable-image-reader-platform-views"});
EXPECT_TRUE(command_line.HasOption("disable-image-reader-platform-views"));
Settings settings = SettingsFromCommandLine(command_line);
EXPECT_EQ(settings.disable_image_reader_platform_views, true);
}
{
// disable
fml::CommandLine command_line = fml::CommandLineFromInitializerList(
{"command", "--disable-image-reader-platform-views=false"});
EXPECT_TRUE(command_line.HasOption("disable-image-reader-platform-views"));
Settings settings = SettingsFromCommandLine(command_line);
EXPECT_EQ(settings.disable_image_reader_platform_views, false);
}
}

} // namespace testing
} // namespace flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ public FlutterEngine(
this.renderer = new FlutterRenderer(flutterJNI);

this.platformViewsController = platformViewsController;
this.platformViewsController.setDisableImageReaderPlatformViews(
flutterJNI.getDisableImageReaderPlatformViews());
this.platformViewsController.onAttachedToJNI();

this.pluginRegistry =
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 @@ -237,6 +237,17 @@ public boolean getIsSoftwareRenderingEnabled() {
return nativeGetIsSoftwareRenderingEnabled();
}

private native boolean nativeGetDisableImageReaderPlatformViews();

/**
* Checks launch settings for whether image reader platform views are disabled.
*
* <p>The value is the same per program.
*/
@UiThread
public boolean getDisableImageReaderPlatformViews() {
return nativeGetDisableImageReaderPlatformViews();
}
/**
* VM Service URI for the VM instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class FlutterShellArgs {
private static final String TAG = "FlutterShellArgs";
public static final String ARG_KEY_TRACE_STARTUP = "trace-startup";
public static final String ARG_TRACE_STARTUP = "--trace-startup";
public static final String ARG_KEY_START_PAUSED = "start-paused";
Expand All @@ -38,6 +39,10 @@ public class FlutterShellArgs {
public static final String ARG_SKIA_DETERMINISTIC_RENDERING = "--skia-deterministic-rendering";
public static final String ARG_KEY_TRACE_SKIA = "trace-skia";
public static final String ARG_TRACE_SKIA = "--trace-skia";
public static final String ARG_KEY_DISABLE_IMAGE_READER_PLATFORM_VIEWS =
"disable-image-reader-platform-views";
public static final String ARG_DISABLE_IMAGE_READER_PLATFORM_VIEWS =
"--disable-image-reader-platform-views";
public static final String ARG_KEY_TRACE_SKIA_ALLOWLIST = "trace-skia-allowlist";
public static final String ARG_TRACE_SKIA_ALLOWLIST = "--trace-skia-allowlist=";
public static final String ARG_KEY_TRACE_SYSTRACE = "trace-systrace";
Expand Down Expand Up @@ -128,6 +133,9 @@ public static FlutterShellArgs fromIntent(@NonNull Intent intent) {
if (intent.getBooleanExtra(ARG_KEY_ENABLE_IMPELLER, false)) {
args.add(ARG_ENABLE_IMPELLER);
}
if (intent.getBooleanExtra(ARG_KEY_DISABLE_IMAGE_READER_PLATFORM_VIEWS, false)) {
args.add(ARG_DISABLE_IMAGE_READER_PLATFORM_VIEWS);
}
if (intent.getBooleanExtra(ARG_KEY_ENABLE_VULKAN_VALIDATION, false)) {
args.add(ARG_ENABLE_VULKAN_VALIDATION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class FlutterLoader {
"io.flutter.embedding.android.EnableVulkanValidation";
private static final String IMPELLER_BACKEND_META_DATA_KEY =
"io.flutter.embedding.android.ImpellerBackend";
private static final String DISABLE_IMAGE_READER_PLATFORM_VIEWS_KEY =
"io.flutter.embedding.android.DisableImageReaderPlatformViews";

/**
* Set whether leave or clean up the VM after the last shell shuts down. It can be set from app's
Expand Down Expand Up @@ -331,6 +333,9 @@ public void ensureInitializationComplete(
if (metaData.getBoolean(ENABLE_IMPELLER_META_DATA_KEY, false)) {
shellArgs.add("--enable-impeller");
}
if (metaData.getBoolean(DISABLE_IMAGE_READER_PLATFORM_VIEWS_KEY, false)) {
shellArgs.add("--disable-image-reader-platform-views");
}
if (metaData.getBoolean(
ENABLE_VULKAN_VALIDATION_META_DATA_KEY, areValidationLayersOnByDefault())) {
shellArgs.add("--enable-vulkan-validation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,10 @@ public void setSoftwareRendering(boolean useSoftwareRendering) {
usesSoftwareRendering = useSoftwareRendering;
}

public void setDisableImageReaderPlatformViews(boolean disableImageReaderPlatformViews) {
enableHardwareBufferRenderingTarget = !disableImageReaderPlatformViews;
}

/**
* Detaches this platform views controller.
*
Expand Down Expand Up @@ -972,9 +976,11 @@ private static PlatformViewRenderTarget makePlatformViewRenderTarget(
TextureRegistry textureRegistry) {
if (enableHardwareBufferRenderingTarget && Build.VERSION.SDK_INT >= 29) {
final TextureRegistry.ImageTextureEntry textureEntry = textureRegistry.createImageTexture();
Log.i(TAG, "PlatformView is using ImageReader backend");
return new ImageReaderPlatformViewRenderTarget(textureEntry);
}
final TextureRegistry.SurfaceTextureEntry textureEntry = textureRegistry.createSurfaceTexture();
Log.i(TAG, "PlatformView is using SurfaceTexture backend");
return new SurfaceTexturePlatformViewRenderTarget(textureEntry);
}

Expand Down
10 changes: 10 additions & 0 deletions shell/platform/android/platform_view_android_jni_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ static jboolean GetIsSoftwareRendering(JNIEnv* env, jobject jcaller) {
return FlutterMain::Get().GetSettings().enable_software_rendering;
}

static jboolean GetDisableImageReaderPlatformViews(JNIEnv* env,
jobject jcaller) {
return FlutterMain::Get().GetSettings().disable_image_reader_platform_views;
}

static void RegisterTexture(JNIEnv* env,
jobject jcaller,
jlong shell_holder,
Expand Down Expand Up @@ -778,6 +783,11 @@ bool RegisterApi(JNIEnv* env) {
.signature = "()Z",
.fnPtr = reinterpret_cast<void*>(&GetIsSoftwareRendering),
},
{
.name = "nativeGetDisableImageReaderPlatformViews",
.signature = "()Z",
.fnPtr = reinterpret_cast<void*>(&GetDisableImageReaderPlatformViews),
},
{
.name = "nativeRegisterTexture",
.signature = "(JJLjava/lang/ref/"
Expand Down