Skip to content

toImageSync should use kPremul_SkAlphaType #109372

@dnfield

Description

@dnfield

Right now it's using kUnpremul_SkAlphaType, which is resulting in darker anti-aliasing around edges, e.g. compare the square on bottom to the one on top:

image

They're made form the same picture drawn like this:

Future<List<ui.Image>> drawImage() async {
  var recorder = ui.PictureRecorder();
  var canvas = ui.Canvas(recorder);
  canvas.drawRect(ui.Rect.fromLTWH(20, 20, 100, 100),
      ui.Paint()..color = ui.Color(0xFFFF6D00));
  var picture = recorder.endRecording();
  var toImageImage = await picture.toImage(200, 200);
  var toImageSyncImage = picture.toImageSync(200, 200);
  return [toImageImage, toImageSyncImage];
}

The toImage image is on top, the toImageSync image is on bottom. Changing https://github.com/flutter/engine/blob/5f92d3668c7a172be23df13eebd24ab7e7df29ee/lib/ui/painting/picture.cc#L71 to kPremul_SkAlphaType seems to fix this, but probably deserves to be tested to make sure it works - Im' pretty sure I tried unpremul at one point to try to get Linux to be happy, before finally just putting Linux on the software path for now.

@jonahwilliams fyi. If you don't get to this first, I'll pick it up when I come back next week. We may want a golden test that asserts the bytes are the same between these calls.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listengineflutter/engine related. See also e: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions