Skip to content

Binding a Flutter Canvas / PictureRecorder to a Texture? #20664

@ltc

Description

@ltc

I'm looking into rendering Flutter canvas graphics onto an Android surface from another plugin.

Currently I have the following:

Android flutter plugin that obtains an Android Surface.

  • option 1: flutter app renders Canvas, save with PictureRecorder, copy RGBA bytes to plugin, draw to Surface
  • option 2: flutter app sends messages to plugin to draw on an Android Canvas, draw to Surface

option 2 is significantly faster - but requires mirroring Canvas methods in the UI with plugin methods,

e.g.

// Draw UI
canvas
  .. drawPaint(paint)
  .. drawLine(pt1, pt2, paint);

// Render same thing to plugin
plugin
  ..drawPaint(paint);
  ..drawLine(pt1, ot2, paint);

In our case - we currently only need a subset of Canvas methods, so this isn't too burdensome for now.

Ideally, however, this could look something like this:

// Draw UI
canvas
  .. drawPaint(paint)
  .. drawLine(pt1, pt2, paint);

// Render same thing to plugin
canvas = new Canvas(new PictureRecorder(plugin.textureId))
  ..drawPaint(paint);
  ..drawLine(pt1, pt2, paint);

Is there a way to let a PictureRecorder record canvas operations to a texture?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityengineflutter/engine related. See also e: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions