Mir

Code review comment for lp:~andreas-pokorny/mir/add-pixel-format-to-display-configuration

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> The idea was that default display configuration policy should try to select an
> opaque format where possible.
...
> Hm if there is no opaque format in the vector it takes the preconfigured one -
> blindly assuming that it is part of the vector. Which would then be a format
> with alpha channel.
>
> > So the return is one of mir_pixel_format_invalid, format, or the first alpha
> > format from formats.
>
> no the first non-alpha format - it uses find_if_not

I'd find it easier to follow like this:

MirPixelFormat select_opaque_format(MirPixelFormat format, std::vector<MirPixelFormat> const& formats)
{
    auto const format_in_formats = formats.end() != std::find(formats.begin(), formats.end(), format);

    if (!mg::contains_alpha(format) && format_in_formats)
        return format;

    // format is either unavailable or transparent
    auto const first_opaque = std::find_if_not(formats.begin(), formats.end(), mg::contains_alpha);

    if (first_opaque != formats.end())
        return *first_opaque;

    // only tranparent options - allow choice if available
    if (format_in_formats)
        return format;

    if (formats.size())
        return formats.at(0);

    return mir_pixel_format_invalid;
}

review: Abstain

« Back to merge proposal