Visitar URL original
Adds switch for sdf rendering plus golden tests by gaaclarke · Pull Request #183543 · flutter/flutter · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
added macos
  • Loading branch information
gaaclarke committed Mar 11, 2026
commit 0f9845f7175faccce6d7c815fa158459a33c84f9
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ - (BOOL)enableFlutterGPU {
return NO;
}

- (BOOL)enableSDFs {
NSNumber* enableSDFs = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTEnableSDFs"];
if (enableSDFs != nil) {
return enableSDFs.boolValue;
}
return NO;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This method defaults to returning NO if the FLTEnableSDFs key is not found in the Info.plist. This causes the engine to be launched with --impeller-use-sdfs=false, which overrides the default value of true for this setting from settings.h. To align with the default behavior, this method should return YES when the key is not present.

Suggested change
return NO;
return YES;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Any reason to use ?: above but an if and a return here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is matching the other functions like enableFlutterGPU and enableWideGamut, no reason beyond that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, so local consistency rules over global consistency... 👍

}

- (NSString*)assetsPath {
if (_assetsPath) {
return _assetsPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
*/
@property(nonatomic, readonly) BOOL enableFlutterGPU;

/**
* Whether the Signed Distance Fields are enabled for rendering.
*/
@property(nonatomic, readonly) BOOL enableSDFs;

/**
* Whether wide gamut color support is enabled
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
std::find(switches.begin(), switches.end(), "--enable-impeller=true") != switches.end()) {
switches.push_back("--enable-impeller=true");
}
switches.push_back(_project.enableSDFs ? "--impeller-use-sdfs=true"
: "--impeller-use-sdfs=false");

if (_project.enableFlutterGPU ||
std::find(switches.begin(), switches.end(), "--enable-flutter-gpu=true") != switches.end()) {
Expand Down
81 changes: 42 additions & 39 deletions engine/src/flutter/shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -558,49 +558,52 @@ InferMetalPlatformViewCreationCallback(
std::shared_ptr<flutter::EmbedderExternalViewEmbedder> view_embedder =
std::move(external_view_embedder);

std::unique_ptr<flutter::EmbedderSurface> embedder_surface;

if (enable_impeller) {
flutter::EmbedderSurfaceMetalImpeller::MetalDispatchTable
metal_dispatch_table = {
.present = metal_present,
.get_texture = metal_get_texture,
};
embedder_surface = std::make_unique<flutter::EmbedderSurfaceMetalImpeller>(
const_cast<flutter::GPUMTLDeviceHandle>(config->metal.device),
const_cast<flutter::GPUMTLCommandQueueHandle>(
config->metal.present_command_queue),
metal_dispatch_table, view_embedder);
} else {
// The static leak checker gets confused by the use of fml::MakeCopyable.
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
return fml::MakeCopyable([config, metal_present, metal_get_texture,
view_embedder, platform_dispatch_table,
enable_impeller](flutter::Shell& shell) mutable {
std::unique_ptr<flutter::EmbedderSurface> embedder_surface;

if (enable_impeller) {
flutter::EmbedderSurfaceMetalImpeller::MetalDispatchTable
metal_dispatch_table = {
.present = metal_present,
.get_texture = metal_get_texture,
};
impeller::Flags impeller_flags;
impeller_flags.use_sdfs = shell.GetSettings().impeller_use_sdfs;
Comment thread
flar marked this conversation as resolved.
Resolved
embedder_surface =
std::make_unique<flutter::EmbedderSurfaceMetalImpeller>(
const_cast<flutter::GPUMTLDeviceHandle>(config->metal.device),
const_cast<flutter::GPUMTLCommandQueueHandle>(
config->metal.present_command_queue),
metal_dispatch_table, view_embedder, impeller_flags);
} else {
#if !SLIMPELLER
flutter::EmbedderSurfaceMetalSkia::MetalDispatchTable metal_dispatch_table =
{
.present = metal_present,
.get_texture = metal_get_texture,
};
embedder_surface = std::make_unique<flutter::EmbedderSurfaceMetalSkia>(
const_cast<flutter::GPUMTLDeviceHandle>(config->metal.device),
const_cast<flutter::GPUMTLCommandQueueHandle>(
config->metal.present_command_queue),
metal_dispatch_table, view_embedder);
flutter::EmbedderSurfaceMetalSkia::MetalDispatchTable
metal_dispatch_table = {
.present = metal_present,
.get_texture = metal_get_texture,
};
embedder_surface = std::make_unique<flutter::EmbedderSurfaceMetalSkia>(
const_cast<flutter::GPUMTLDeviceHandle>(config->metal.device),
const_cast<flutter::GPUMTLCommandQueueHandle>(
config->metal.present_command_queue),
metal_dispatch_table, view_embedder);
#else // !SLIMPELLER
FML_LOG(FATAL) << "Impeller opt-out unavailable.";
FML_LOG(FATAL) << "Impeller opt-out unavailable.";
#endif // !SLIMPELLER
}
}

// The static leak checker gets confused by the use of fml::MakeCopyable.
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
return fml::MakeCopyable(
[embedder_surface = std::move(embedder_surface), platform_dispatch_table,
external_view_embedder = view_embedder](flutter::Shell& shell) mutable {
return std::make_unique<flutter::PlatformViewEmbedder>(
shell, // delegate
shell.GetTaskRunners(), // task runners
std::move(embedder_surface), // embedder surface
platform_dispatch_table, // platform dispatch table
std::move(external_view_embedder) // external view embedder
);
});
return std::make_unique<flutter::PlatformViewEmbedder>(
shell, // delegate
shell.GetTaskRunners(), // task runners
std::move(embedder_surface), // embedder surface
platform_dispatch_table, // platform dispatch table
std::move(view_embedder) // external view embedder
);
});
#else // SHELL_ENABLE_METAL
FML_LOG(ERROR) << "This Flutter Engine does not support Metal rendering.";
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "fml/concurrent_message_loop.h"
#include "impeller/display_list/aiks_context.h"

#include "impeller/base/flags.h"

namespace impeller {
class Context;
}
Expand All @@ -33,7 +35,8 @@ class EmbedderSurfaceMetalImpeller final : public EmbedderSurface,
GPUMTLDeviceHandle device,
GPUMTLCommandQueueHandle command_queue,
MetalDispatchTable dispatch_table,
std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder);
std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder,
impeller::Flags impeller_flags);

~EmbedderSurfaceMetalImpeller() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
GPUMTLDeviceHandle device,
GPUMTLCommandQueueHandle command_queue,
MetalDispatchTable metal_dispatch_table,
std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder,
impeller::Flags impeller_flags)
: GPUSurfaceMetalDelegate(MTLRenderTargetType::kMTLTexture),
metal_dispatch_table_(std::move(metal_dispatch_table)),
external_view_embedder_(std::move(external_view_embedder)) {
Expand All @@ -41,7 +42,7 @@
impeller_framebuffer_blend_shaders_length),
};
context_ = impeller::ContextMTL::Create(
impeller::Flags{},
impeller_flags,
(__bridge id<MTLDevice>)device, // device
(__bridge id<MTLCommandQueue>)command_queue, // command_queue
shader_mappings, // shader_libraries_data
Expand Down