Skip to content

Commit

Permalink
Merge branch 'main' into deprecatedMember
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer authored Apr 2, 2024
2 parents 983766f + b1dbb43 commit e3fd50e
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 32 deletions.
11 changes: 11 additions & 0 deletions common/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ declare_args() {
#TODO(cyanglaz): Remove above comment about test flag when the entire iOS embedder supports app extension
#https://github.com/flutter/flutter/issues/124289
darwin_extension_safe = false

# Whether binary size optimizations with the assumption that Impeller is the
# only supported rendering engine are enabled.
#
# See [go/slimpeller-dashboard](https://github.com/orgs/flutter/projects/21)
# for details.
slimpeller = false
}

# feature_defines_list ---------------------------------------------------------
Expand Down Expand Up @@ -62,6 +69,10 @@ if (flutter_runtime_mode == "debug") {
feature_defines_list += [ "FLUTTER_RUNTIME_MODE=0" ]
}

if (slimpeller) {
feature_defines_list += [ "SLIMPELLER=1" ]
}

if (is_ios || is_mac) {
flutter_cflags_objc = [
"-Werror=overriding-method-mismatch",
Expand Down
36 changes: 36 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3073,6 +3073,42 @@ TEST_P(AiksTest, MipmapGenerationWorksCorrectly) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, DrawAtlasPlusWideGamut) {
if (GetParam() != PlaygroundBackend::kMetal) {
GTEST_SKIP_("This backend doesn't yet support wide gamut.");
}

EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
PixelFormat::kR16G16B16A16Float);

// Draws the image as four squares stiched together.
auto atlas =
std::make_shared<Image>(CreateTextureForFixture("bay_bridge.jpg"));
auto size = atlas->GetSize();
// Divide image into four quadrants.
Scalar half_width = size.width / 2;
Scalar half_height = size.height / 2;
std::vector<Rect> texture_coordinates = {
Rect::MakeLTRB(0, 0, half_width, half_height),
Rect::MakeLTRB(half_width, 0, size.width, half_height),
Rect::MakeLTRB(0, half_height, half_width, size.height),
Rect::MakeLTRB(half_width, half_height, size.width, size.height)};
// Position quadrants adjacent to eachother.
std::vector<Matrix> transforms = {
Matrix::MakeTranslation({0, 0, 0}),
Matrix::MakeTranslation({half_width, 0, 0}),
Matrix::MakeTranslation({0, half_height, 0}),
Matrix::MakeTranslation({half_width, half_height, 0})};
std::vector<Color> colors = {Color::Red(), Color::Green(), Color::Blue(),
Color::Yellow()};

Canvas canvas;
canvas.DrawAtlas(atlas, transforms, texture_coordinates, colors,
BlendMode::kPlus, {}, std::nullopt, {});

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

} // namespace testing
} // namespace impeller

Expand Down
11 changes: 11 additions & 0 deletions impeller/entity/shaders/blending/porter_duff_blend.frag
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ f16vec4 Sample(f16sampler2D texture_sampler, vec2 texture_coords) {
return IPHalfSampleDecal(texture_sampler, texture_coords);
}

float16_t ClampAlpha(float16_t alpha) {
float16_t min = 0.0hf;
float16_t max = 1.0hf;
return clamp(alpha, min, max);
}

void main() {
f16vec4 dst =
texture(texture_sampler_dst, v_texture_coords) * frag_info.input_alpha;
Expand All @@ -45,4 +51,9 @@ void main() {
dst * (frag_info.dst_coeff + src.a * frag_info.dst_coeff_src_alpha +
src * frag_info.dst_coeff_src_color);
frag_color *= frag_info.output_alpha;
// This currently needs a clamp so that floating point textures blend
// correctly in wide gamut. Remove if we switch to a fixed point extended
// range format.
// See https://github.com/flutter/flutter/issues/145933 .
frag_color.a = ClampAlpha(frag_color.a);
}
12 changes: 6 additions & 6 deletions impeller/tools/malioc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8434,8 +8434,8 @@
"varying"
],
"longest_path_cycles": [
0.21875,
0.21875,
0.234375,
0.234375,
0.0,
0.0,
0.0,
Expand All @@ -8455,8 +8455,8 @@
"varying"
],
"shortest_path_cycles": [
0.21875,
0.21875,
0.234375,
0.234375,
0.0,
0.0,
0.0,
Expand All @@ -8467,8 +8467,8 @@
"varying"
],
"total_cycles": [
0.21875,
0.21875,
0.234375,
0.234375,
0.0,
0.0,
0.0,
Expand Down
19 changes: 10 additions & 9 deletions lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class SkwasmLineMetrics extends SkwasmObjectWrapper<RawLineMetrics> implements u

@override
int get lineNumber => lineMetricsGetLineNumber(handle);

int get startIndex => lineMetricsGetStartIndex(handle);
int get endIndex => lineMetricsGetEndIndex(handle);
}

class SkwasmParagraph extends SkwasmObjectWrapper<RawParagraph> implements ui.Paragraph {
Expand Down Expand Up @@ -243,15 +246,13 @@ class SkwasmParagraph extends SkwasmObjectWrapper<RawParagraph> implements ui.Pa

@override
ui.TextRange getLineBoundary(ui.TextPosition position) {
final int lineNumber = paragraphGetLineNumberAt(handle, position.offset);
final LineMetricsHandle metricsHandle =
paragraphGetLineMetricsAtIndex(handle, lineNumber);
final ui.TextRange range = ui.TextRange(
start: lineMetricsGetStartIndex(metricsHandle),
end: lineMetricsGetEndIndex(metricsHandle),
);
lineMetricsDispose(metricsHandle);
return range;
final int offset = position.offset;
for (final SkwasmLineMetrics metrics in computeLineMetrics()) {
if (offset >= metrics.startIndex && offset <= metrics.endIndex) {
return ui.TextRange(start: metrics.startIndex, end: metrics.endIndex);
}
}
return ui.TextRange.empty;
}

@override
Expand Down
13 changes: 13 additions & 0 deletions lib/web_ui/test/ui/paragraph_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ Future<void> testMain() async {
expect(upstreamWordBoundary, const TextRange(start: 0, end: 5));
});

test('getLineBoundary at the last character position gives correct results', () {
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle());
builder.addText('hello world');

final Paragraph paragraph = builder.build();
paragraph.layout(const ParagraphConstraints(width: double.infinity));

final TextRange lineBoundary = paragraph.getLineBoundary(const TextPosition(
offset: 11,
));
expect(lineBoundary, const TextRange(start: 0, end: 11));
});

test('build and layout a paragraph with an empty addText', () {
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle());
builder.addText('');
Expand Down
1 change: 1 addition & 0 deletions testing/impeller_golden_tests_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ impeller_Play_AiksTest_DrawAdvancedBlendPartlyOffscreen_Vulkan.png
impeller_Play_AiksTest_DrawAtlasAdvancedAndTransform_Metal.png
impeller_Play_AiksTest_DrawAtlasAdvancedAndTransform_OpenGLES.png
impeller_Play_AiksTest_DrawAtlasAdvancedAndTransform_Vulkan.png
impeller_Play_AiksTest_DrawAtlasPlusWideGamut_Metal.png
impeller_Play_AiksTest_DrawAtlasWithColorAdvancedAndTransform_Metal.png
impeller_Play_AiksTest_DrawAtlasWithColorAdvancedAndTransform_OpenGLES.png
impeller_Play_AiksTest_DrawAtlasWithColorAdvancedAndTransform_Vulkan.png
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.Window;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import io.flutter.FlutterInjector;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.loader.FlutterLoader;
Expand All @@ -25,6 +29,7 @@ public abstract class TestActivity extends TestableFlutterActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideSystemBars(getWindow());
testFlutterLoaderCallbackWhenInitializedTwice();
}

Expand Down Expand Up @@ -104,4 +109,13 @@ protected void testFlutterLoaderCallbackWhenInitializedTwice() {
}
});
}

private static void hideSystemBars(Window window) {
final WindowInsetsControllerCompat insetController =
WindowCompat.getInsetsController(window, window.getDecorView());
assert insetController != null;
insetController.setSystemBarsBehavior(
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
insetController.hide(WindowInsetsCompat.Type.systemBars());
}
}
28 changes: 11 additions & 17 deletions testing/scenario_app/bin/run_android_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,23 +298,17 @@ Future<void> _run({
});

await step('Configuring emulator...', () async {
final List<List<String>> adbShellCommands = <List<String>> [
// Try to close all OS popups in the emulator, like "System UI stopped working".
<String>['am', 'broadcast', '-a', 'android.intent.action.CLOSE_SYSTEM_DIALOGS'],

// Don't show "this is how you exit fullscreen mode".
<String>['settings', 'put', 'secure', 'immersive_mode_confirmations', 'confirmed'],

// Hide all system bars.
<String>['settings', 'put', 'global', 'policy_control', 'immersive.full=*'],
];

// Run all the commands.
for (final List<String> command in adbShellCommands) {
final int exitCode = await pm.runAndForward(<String>[adb.path, 'shell', ...command]);
if (exitCode != 0) {
panic(<String>['could not run command: ${command.join(' ')}']);
}
final int exitCode = await pm.runAndForward(<String>[
adb.path,
'shell',
'settings',
'put',
'secure',
'immersive_mode_confirmations',
'confirmed',
]);
if (exitCode != 0) {
panic(<String>['could not configure emulator']);
}
});

Expand Down
12 changes: 12 additions & 0 deletions tools/gn
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def get_out_dir(args):
if args.darwin_extension_safe:
target_dir.append('extension_safe')

if args.slimpeller:
target_dir.append('slimpeller')

if args.target_dir != '':
target_dir = [args.target_dir]

Expand Down Expand Up @@ -1260,6 +1263,15 @@ def parse_args(args):
help='Do not run GN. Instead configure the Impeller cmake example build.',
)

parser.add_argument(
'--slimpeller',
default=False,
action='store_true',
help='Enable optimizations that attempt to reduce binary size of the ' +
'Flutter engine by assuming only the Impeller rendering engine is supported.' +
'See [go/slimpeller-dashboard](https://github.com/orgs/flutter/projects/21) for details.'
)

# Sanitizers.
parser.add_argument('--asan', default=False, action='store_true')
parser.add_argument('--lsan', default=False, action='store_true')
Expand Down

0 comments on commit e3fd50e

Please sign in to comment.