diff --git a/lib/web_ui/test/canvaskit/canvaskit_api_test.dart b/lib/web_ui/test/canvaskit/canvaskit_api_test.dart index 2aacd2ea9304f..9a5784addac5c 100644 --- a/lib/web_ui/test/canvaskit/canvaskit_api_test.dart +++ b/lib/web_ui/test/canvaskit/canvaskit_api_test.dart @@ -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([]); + expect(shader, isNotNull); + + // mismatched uniforms returns null. + final SkShader? invalidShader = effect.makeShader([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([1.0, 0.0, 0.0, 1.0]); + + expect(shaderWithUniform, isNotNull); + } + }); } SkShader _makeTestShader() { @@ -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([]); - expect(shader, isNotNull); - - // mismatched uniforms returns null. - final SkShader? invalidShader = effect.makeShader([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([1.0, 0.0, 0.0, 1.0]); - - expect(shaderWithUniform, isNotNull); - // TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327 - }, skip: true); } diff --git a/lib/web_ui/test/canvaskit/fragment_program_test.dart b/lib/web_ui/test/canvaskit/fragment_program_test.dart index e4afafd6cb9e6..0a5184f6b3a5e 100644 --- a/lib/web_ui/test/canvaskit/fragment_program_test.dart +++ b/lib/web_ui/test/canvaskit/fragment_program_test.dart @@ -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); + } + }); }