Skip to content

Eliminate heap allocations for gradient color conversions #154650

Closed
flutter/engine
#57143
@gaaclarke

Description

@gaaclarke

Spawned from flutter/engine#54748

When colors of a gradient are communicated from Dart to C++ they are coming in as arrays of floats which represent the color components of the colors in extended sRGB. When they get stored in the display list they are stored as an array of DlColor. As a temporary measure the floats are converted to DlColor on the heap, then sent into the display list for storage. We can't do it on the stack because the number of colors is unlimited.

I looked into trying to switch the DlColorSource factory methods to take in DlScalar*'s, that way it could be converted to DlColors while we were iterating over them, avoiding the heap allocation. That doesn't work however because there is a second client of those functions, the DlColorSource::shared() methods which does not have DlScalar*, they already have their colors stored as DlColor*. The only way to make that work would have been to refactor all the API's to take in an iterator. That's kind of messy in C++ since it would mean surfacing more logic into templates and headers, or incurring dynamic dispatch cost.

@jonahwilliams proposes we should do a larger refactor where we change the storage of the DlColorSource to instead store its colors as a DlScalar*. That way both clients of the DlColorColorSource::Make* functions can pass in DlScalar*. He noted that storing the colorspace per color may be redundant anyways.

cc @flar

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work listteam-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