diff --git a/lib/web_ui/dev/goldens_lock.yaml b/lib/web_ui/dev/goldens_lock.yaml index e8c8f3e75d7..682f836bbe1 100644 --- a/lib/web_ui/dev/goldens_lock.yaml +++ b/lib/web_ui/dev/goldens_lock.yaml @@ -1,2 +1,2 @@ repository: https://github.com/flutter/goldens.git -revision: de71e99520d92bd82b2b64004cd8e74be08fba05 +revision: d70eca62b254302b293973573d3b16ffd05b19db diff --git a/lib/web_ui/lib/src/engine/bitmap_canvas.dart b/lib/web_ui/lib/src/engine/bitmap_canvas.dart index f25471a8966..eab08433a93 100644 --- a/lib/web_ui/lib/src/engine/bitmap_canvas.dart +++ b/lib/web_ui/lib/src/engine/bitmap_canvas.dart @@ -916,7 +916,7 @@ class BitmapCanvas extends EngineCanvas { final Int32List? colors = vertices._colors; final ui.VertexMode mode = vertices._mode; html.CanvasRenderingContext2D? ctx = _canvasPool.context; - if (colors == null) { + if (colors == null && paint.style != ui.PaintingStyle.fill) { final Float32List positions = mode == ui.VertexMode.triangles ? vertices._positions : _convertVertexPositions(mode, vertices._positions); diff --git a/lib/web_ui/lib/src/engine/html/render_vertices.dart b/lib/web_ui/lib/src/engine/html/render_vertices.dart index d8d2985ff94..10b714ff743 100644 --- a/lib/web_ui/lib/src/engine/html/render_vertices.dart +++ b/lib/web_ui/lib/src/engine/html/render_vertices.dart @@ -157,14 +157,25 @@ class _WebGlRenderer implements _GlRenderer { // Setup color buffer. Object? colorsBuffer = gl.createBuffer(); gl.bindArrayBuffer(colorsBuffer); + + final int vertexCount = positions.length ~/ 2; + // Buffer kBGRA_8888. - gl.bufferData(vertices._colors, gl.kStaticDraw); + if (vertices._colors == null) { + final ui.Color color = paint.color ?? ui.Color(0xFF000000); + Uint32List vertexColors = Uint32List(vertexCount); + for (int i = 0; i < vertexCount; i++) { + vertexColors[i] = color.value; + } + gl.bufferData(vertexColors, gl.kStaticDraw); + } else { + gl.bufferData(vertices._colors, gl.kStaticDraw); + } Object colorLoc = gl.getAttributeLocation(glProgram.program, 'color'); js_util.callMethod(gl.glContext, 'vertexAttribPointer', [colorLoc, 4, gl.kUnsignedByte, true, 0, 0]); gl.enableVertexAttribArray(1); gl.clear(); - final int vertexCount = positions.length ~/ 2; gl.drawTriangles(vertexCount, vertices._mode); context!.save(); diff --git a/lib/web_ui/test/golden_tests/engine/draw_vertices_golden_test.dart b/lib/web_ui/test/golden_tests/engine/draw_vertices_golden_test.dart index 84e9017bfb9..5e02b2445c3 100644 --- a/lib/web_ui/test/golden_tests/engine/draw_vertices_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/draw_vertices_golden_test.dart @@ -59,11 +59,11 @@ void testMain() async { Future _testVertices(String fileName, Vertices vertices, BlendMode blendMode, - Paint paint) async { + Paint paint, {bool write: false}) async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500)); rc.drawVertices(vertices, blendMode, paint); - await _checkScreenshot(rc, fileName); + await _checkScreenshot(rc, fileName, write: write); } test('Should draw green hairline triangles when colors array is null.', @@ -101,6 +101,31 @@ void testMain() async { Paint()); }); + /// Regression test for https://github.com/flutter/flutter/issues/71442. + test('Should draw filled triangles when colors array is null' + ' and Paint() has color.', + () async { + // ignore: unused_local_variable + final Int32List colors = Int32List.fromList([ + 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, + 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, + 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, + 0xFFFF0000, 0xFF00FF00, 0xFF0000FF]); + final Vertices vertices = Vertices.raw(VertexMode.triangles, + Float32List.fromList([ + 20.0, 20.0, 220.0, 10.0, 110.0, 220.0, + 220.0, 320.0, 20.0, 310.0, 200.0, 420.0 + ])); + await _testVertices( + 'draw_vertices_triangle_green_filled', + vertices, + BlendMode.srcOver, + Paint() + ..style = PaintingStyle.fill + ..color = const Color(0xFF00FF00) + ); + }); + test('Should draw hairline triangleFan.', () async { final Vertices vertices = Vertices.raw(VertexMode.triangleFan,