Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[canvaskit] Fix Shader program tests #37644

Merged
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
83 changes: 41 additions & 42 deletions lib/web_ui/test/canvaskit/canvaskit_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,47 @@ void _shaderTests() {
),
isNotNull);
});

test('RuntimeEffect', () {
// TODO(hterkelsen): Remove this check when local CanvasKit is default.
if (isRuntimeEffectAvailable) {
const String kSkSlProgram = r'''
half4 main(vec2 fragCoord) {
return vec4(1.0, 0.0, 0.0, 1.0);
}
''';

final SkRuntimeEffect? effect = MakeRuntimeEffect(kSkSlProgram);
expect(effect, isNotNull);

const String kInvalidSkSlProgram = '';

// Invalid SkSL returns null.
final SkRuntimeEffect? invalidEffect = MakeRuntimeEffect(kInvalidSkSlProgram);
expect(invalidEffect, isNull);

final SkShader? shader = effect!.makeShader(<double>[]);
expect(shader, isNotNull);

// mismatched uniforms returns null.
final SkShader? invalidShader = effect.makeShader(<double>[1]);

expect(invalidShader, isNull);

const String kSkSlProgramWithUniforms = r'''
uniform vec4 u_color;

half4 main(vec2 fragCoord) {
return u_color;
}
''';

final SkShader? shaderWithUniform = MakeRuntimeEffect(kSkSlProgramWithUniforms)
!.makeShader(<double>[1.0, 0.0, 0.0, 1.0]);

expect(shaderWithUniform, isNotNull);
}
});
}

SkShader _makeTestShader() {
Expand Down Expand Up @@ -1707,46 +1748,4 @@ void _paragraphTests() {
canvasKit.TextHeightBehavior.DisableAll,
);
});

test('RuntimeEffect', () {
// Is supported..
expect(isRuntimeEffectAvailable, isTrue);

const String kSkSlProgram = r'''
half4 main(vec2 fragCoord) {
return vec4(1.0, 0.0, 0.0, 1.0);
}
''';

final SkRuntimeEffect? effect = MakeRuntimeEffect(kSkSlProgram);
expect(effect, isNotNull);

const String kInvalidSkSlProgram = '';

// Invalid SkSL returns null.
final SkRuntimeEffect? invalidEffect = MakeRuntimeEffect(kInvalidSkSlProgram);
expect(invalidEffect, isNull);

final SkShader? shader = effect!.makeShader(<double>[]);
expect(shader, isNotNull);

// mismatched uniforms returns null.
final SkShader? invalidShader = effect.makeShader(<double>[1]);

expect(invalidShader, isNull);

const String kSkSlProgramWithUniforms = r'''
uniform vec4 u_color;

half4 main(vec2 fragCoord) {
return u_color;
}
''';

final SkShader? shaderWithUniform = MakeRuntimeEffect(kSkSlProgramWithUniforms)
!.makeShader(<double>[1.0, 0.0, 0.0, 1.0]);

expect(shaderWithUniform, isNotNull);
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
}, skip: true);
}
36 changes: 19 additions & 17 deletions lib/web_ui/test/canvaskit/fragment_program_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,29 @@ void testMain() {
});

test('FragmentProgram can be created from JSON IPLR bundle', () async {
final Uint8List data = utf8.encode(kJsonIPLR) as Uint8List;
final CkFragmentProgram program = await CkFragmentProgram.fromBytes('test', data);
// TODO(hterkelsen): Remove this check when local CanvasKit is default.
if (isRuntimeEffectAvailable) {
final Uint8List data = utf8.encode(kJsonIPLR) as Uint8List;
final CkFragmentProgram program = await CkFragmentProgram.fromBytes('test', data);

expect(program.effect, isNotNull);
expect(program.floatCount, 17);
expect(program.textureCount, 0);
expect(program.uniforms, hasLength(17));
expect(program.name, 'test');
expect(program.effect, isNotNull);
expect(program.floatCount, 17);
expect(program.textureCount, 0);
expect(program.uniforms, hasLength(17));
expect(program.name, 'test');

final ui.FragmentShader shader = program.fragmentShader();
final ui.FragmentShader shader = program.fragmentShader();

shader.setFloat(0, 4);
shader.dispose();
shader.setFloat(0, 4);
shader.dispose();

expect(shader.debugDisposed, true);
expect(shader.debugDisposed, true);

final ui.FragmentShader shader2 = program.fragmentShader();
final ui.FragmentShader shader2 = program.fragmentShader();

shader.setFloat(0, 5);
shader2.dispose();
expect(shader2.debugDisposed, true);
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
}, skip: true);
shader.setFloat(0, 5);
shader2.dispose();
expect(shader2.debugDisposed, true);
}
});
}