[dart:ui] dont create Timers in FragmentShader (flutter/engine#33488)

This commit is contained in:
Jonah Williams
2022-05-19 14:08:05 -07:00
committed by GitHub
parent 3e5a9e8aba
commit 50eaa4b0e9
2 changed files with 24 additions and 7 deletions

View File

@@ -3911,7 +3911,9 @@ class FragmentProgram extends NativeFieldWrapperClass1 {
required ByteBuffer spirv,
bool debugPrint = false,
}) {
return Future<FragmentProgram>(() => FragmentProgram._(spirv: spirv, debugPrint: debugPrint));
// Delay compilation without creating a timer, which interacts poorly with the
// flutter test framework. See: https://github.com/flutter/flutter/issues/104084
return Future<FragmentProgram>.microtask(() => FragmentProgram._(spirv: spirv, debugPrint: debugPrint));
}
@pragma('vm:entry-point')

View File

@@ -107,15 +107,15 @@ void main() {
final Float32List zeroes = Float32List.fromList(<double>[0]);
{
final a = program.shader(floatUniforms: ones);
final b = program.shader(floatUniforms: ones);
final Shader a = program.shader(floatUniforms: ones);
final Shader b = program.shader(floatUniforms: ones);
expect(a, b);
expect(a.hashCode, b.hashCode);
}
{
final a = program.shader(floatUniforms: ones);
final b = program.shader(floatUniforms: zeroes);
final Shader a = program.shader(floatUniforms: ones);
final Shader b = program.shader(floatUniforms: zeroes);
expect(a, notEquals(b));
expect(a.hashCode, notEquals(b.hashCode));
}
@@ -128,12 +128,27 @@ void main() {
.readAsBytesSync().buffer;
final FragmentProgram programA = await FragmentProgram.compile(spirv: spirvA);
final FragmentProgram programB = await FragmentProgram.compile(spirv: spirvB);
final a = programA.shader();
final b = programB.shader();
final Shader a = programA.shader();
final Shader b = programB.shader();
expect(a, notEquals(b));
expect(a.hashCode, notEquals(b.hashCode));
});
test('Compilation does not create a Timer object', () async {
final ByteBuffer spirvA = spvFile('general_shaders', 'simple.spv')
.readAsBytesSync().buffer;
bool createdTimer = false;
final ZoneSpecification specification = ZoneSpecification(createTimer: (Zone self, ZoneDelegate parent, Zone zone, Duration duration, void Function() f) {
createdTimer = true;
return parent.createTimer(zone, duration, f);
});
await runZoned(() async {
await FragmentProgram.compile(spirv: spirvA);
}, zoneSpecification: specification);
expect(createdTimer, false);
});
}
// Expect that all of the spirv shaders in this folder render green.