[web] Fix drawVertices rendering when colors array is null and style is fill (#23995)

This commit is contained in:
Ferhat 2021-01-28 09:37:57 -08:00 committed by GitHub
parent b928a2aeff
commit 7e0078fd19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 6 deletions

View File

@ -1,2 +1,2 @@
repository: https://github.com/flutter/goldens.git
revision: de71e99520d92bd82b2b64004cd8e74be08fba05
revision: d70eca62b254302b293973573d3b16ffd05b19db

View File

@ -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);

View File

@ -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',
<dynamic>[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();

View File

@ -59,11 +59,11 @@ void testMain() async {
Future<void> _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(<int>[
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,