Third part of soft transition to async FragmentProgram.fromAsset (flutter/engine#34932)
This commit is contained in:
@@ -4039,14 +4039,16 @@ class FragmentProgram extends NativeFieldWrapperClass1 {
|
||||
/// The asset must be a file produced as the output of the `impellerc`
|
||||
/// compiler. The constructed object should then be reused via the [shader]
|
||||
/// method to create [Shader] objects that can be used by [Shader.paint].
|
||||
static FragmentProgram fromAsset(String assetKey) {
|
||||
static Future<FragmentProgram> fromAsset(String assetKey) {
|
||||
FragmentProgram? program = _shaderRegistry[assetKey]?.target;
|
||||
if (program == null) {
|
||||
program = FragmentProgram._fromAsset(assetKey);
|
||||
_shaderRegistry[assetKey] = WeakReference<FragmentProgram>(program);
|
||||
if (program != null) {
|
||||
return Future<FragmentProgram>.value(program);
|
||||
}
|
||||
|
||||
return program;
|
||||
return Future<FragmentProgram>.microtask(() {
|
||||
final FragmentProgram program = FragmentProgram._fromAsset(assetKey);
|
||||
_shaderRegistry[assetKey] = WeakReference<FragmentProgram>(program);
|
||||
return program;
|
||||
});
|
||||
}
|
||||
|
||||
// TODO(zra): This is part of a soft transition of the framework to this
|
||||
|
||||
@@ -835,7 +835,7 @@ class ImageDescriptor {
|
||||
}
|
||||
|
||||
class FragmentProgram {
|
||||
static FragmentProgram fromAsset(String assetKey) {
|
||||
static Future<FragmentProgram> fromAsset(String assetKey) {
|
||||
throw UnsupportedError('FragmentProgram is not supported for the CanvasKit or HTML renderers.');
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import 'shader_test_file_utils.dart';
|
||||
|
||||
void main() async {
|
||||
test('simple shader renders correctly', () async {
|
||||
final FragmentProgram program = await FragmentProgram.fromAssetAsync(
|
||||
final FragmentProgram program = await FragmentProgram.fromAsset(
|
||||
'functions.frag.iplr',
|
||||
);
|
||||
final Shader shader = program.shader(
|
||||
@@ -25,7 +25,7 @@ void main() async {
|
||||
});
|
||||
|
||||
test('blue-green image renders green', () async {
|
||||
final FragmentProgram program = await FragmentProgram.fromAssetAsync(
|
||||
final FragmentProgram program = await FragmentProgram.fromAsset(
|
||||
'blue_green_sampler.frag.iplr',
|
||||
);
|
||||
final Image blueGreenImage = await _createBlueGreenImage();
|
||||
@@ -39,7 +39,7 @@ void main() async {
|
||||
});
|
||||
|
||||
test('shader with uniforms renders correctly', () async {
|
||||
final FragmentProgram program = await FragmentProgram.fromAssetAsync(
|
||||
final FragmentProgram program = await FragmentProgram.fromAsset(
|
||||
'uniforms.frag.iplr',
|
||||
);
|
||||
|
||||
@@ -65,7 +65,7 @@ void main() async {
|
||||
});
|
||||
|
||||
test('The ink_sparkle shader is accepted', () async {
|
||||
final FragmentProgram program = await FragmentProgram.fromAssetAsync(
|
||||
final FragmentProgram program = await FragmentProgram.fromAsset(
|
||||
'ink_sparkle.frag.iplr',
|
||||
);
|
||||
final Shader shader = program.shader(
|
||||
@@ -79,7 +79,7 @@ void main() async {
|
||||
});
|
||||
|
||||
test('Uniforms are sorted correctly', () async {
|
||||
final FragmentProgram program = await FragmentProgram.fromAssetAsync(
|
||||
final FragmentProgram program = await FragmentProgram.fromAsset(
|
||||
'uniforms_sorted.frag.iplr',
|
||||
);
|
||||
|
||||
@@ -97,7 +97,7 @@ void main() async {
|
||||
test('fromAsset throws an exception on invalid assetKey', () async {
|
||||
bool throws = false;
|
||||
try {
|
||||
final FragmentProgram program = await FragmentProgram.fromAssetAsync(
|
||||
await FragmentProgram.fromAsset(
|
||||
'<invalid>',
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -109,7 +109,7 @@ void main() async {
|
||||
test('fromAsset throws an exception on invalid data', () async {
|
||||
bool throws = false;
|
||||
try {
|
||||
final FragmentProgram program = await FragmentProgram.fromAssetAsync(
|
||||
await FragmentProgram.fromAsset(
|
||||
'DashInNooglerHat.jpg',
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -119,7 +119,7 @@ void main() async {
|
||||
});
|
||||
|
||||
test('fromAsset accepts a shader with no uniforms', () async {
|
||||
final FragmentProgram program = await FragmentProgram.fromAssetAsync(
|
||||
final FragmentProgram program = await FragmentProgram.fromAsset(
|
||||
'no_uniforms.frag.iplr',
|
||||
);
|
||||
final Shader shader = program.shader();
|
||||
@@ -143,7 +143,7 @@ void main() async {
|
||||
_expectIplrShadersRenderGreen(iplrSupportedOpShaders);
|
||||
|
||||
test('Equality depends on floatUniforms', () async {
|
||||
final FragmentProgram program = await FragmentProgram.fromAssetAsync(
|
||||
final FragmentProgram program = await FragmentProgram.fromAsset(
|
||||
'simple.frag.iplr',
|
||||
);
|
||||
final Float32List ones = Float32List.fromList(<double>[1]);
|
||||
@@ -165,10 +165,10 @@ void main() async {
|
||||
});
|
||||
|
||||
test('Equality depends on data', () async {
|
||||
final FragmentProgram programA = await FragmentProgram.fromAssetAsync(
|
||||
final FragmentProgram programA = await FragmentProgram.fromAsset(
|
||||
'simple.frag.iplr',
|
||||
);
|
||||
final FragmentProgram programB = await FragmentProgram.fromAssetAsync(
|
||||
final FragmentProgram programB = await FragmentProgram.fromAsset(
|
||||
'uniforms.frag.iplr',
|
||||
);
|
||||
final Shader a = programA.shader();
|
||||
@@ -242,7 +242,7 @@ Future<Map<String, FragmentProgram>> _loadShaderAssets(
|
||||
.where((FileSystemEntity entry) => path.extension(entry.path) == ext),
|
||||
(FileSystemEntity entry) async {
|
||||
final String key = path.basenameWithoutExtension(entry.path);
|
||||
out[key] = await FragmentProgram.fromAssetAsync(
|
||||
out[key] = await FragmentProgram.fromAsset(
|
||||
path.basename(entry.path),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -14,12 +14,13 @@ void main() {
|
||||
test('simple iplr shader can be re-initialized', () async {
|
||||
vms.VmService? vmService;
|
||||
try {
|
||||
final FragmentProgram program = await FragmentProgram.fromAssetAsync(
|
||||
final FragmentProgram program = await FragmentProgram.fromAsset(
|
||||
'functions.frag.iplr',
|
||||
);
|
||||
final Shader shader = program.shader(
|
||||
floatUniforms: Float32List.fromList(<double>[1]),
|
||||
);
|
||||
_use(shader);
|
||||
|
||||
final developer.ServiceProtocolInfo info = await developer.Service.getInfo();
|
||||
|
||||
@@ -48,3 +49,7 @@ void main() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _use(Shader shader) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user