Skip to content

get_image_data(_shared_memory) is a mess #35759

@sagudev

Description

@sagudev

First of all we have two variants that are roughly the same, just different data storages. Secondly there is no unified notion which data is should be returned (2d canvas returns bgra while webgl returns rgba also is it premultiplied?).

I propose we make single get_image_data that would return snapshot that is rough based on what is described in: https://www.w3.org/TR/webgpu/#abstract-opdef-get-a-copy-of-the-image-contents-of-a-context

Here is sketch:

struct Snapshot {
    /// internal data (can be any format it will be converted on use if needed)
    data: IpcSharedMemory,
    /// RGBA/BGRA (reflect internal data)
    format: ImageFormat,
    /// is alpha premultiplied (reflects internal data)
    alpha_premultiplied: bool,
    /// reflects internal data
    colorSpace: ColorSpace, // enum
    /// should be treated as opaque (that does not mean that internal data is)
    opaque: bool,
}

the idea is that we try to keep passing original data without any conversions as we can let GPU to do conversion for us (webgl supports loading both BGRA/RGBA with or without alpha-premultiply). Also some web endpoints require to return pre-multiplied while other un-multiplied.

To use IpcSharedMemory as backing data we would need to relay heavily on servo/ipc-channel#356 (usage would be safe as bitimage data is cloned and send to thread - ownership is transferred).

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions