Skip to content

[Impeller] Add Texture::GetContents for host-readable textures. #133101

@bdero

Description

@bdero

We already have places where we need to transfer texture data to the host. For example, the Metal golden tests: https://github.com/flutter/engine/blob/41912e7be15a96e410febcf62952ab4cf13e5706/impeller/golden_tests/metal_screenshoter.mm#L27-L55

Example of what retrieving a texture drawn by Impeller looks like with the GLES backend:

auto canvas = impeller::Canvas();
// ... Record something into the canvas ...
auto picture = canvas.EndRecordingAsPicture();
std::shared_ptr<impeller::Image> image = picture.ToImage(your_aiks_context, impeller::ISize{800, 600});
std::shared_ptr<impeller::Texture> texture = image->GetTexture();

// From here, you're on your own. :(

auto& texture_gl = impeller::TextureGLES::Cast(texture);
std::optional<GLuint> texture_handle = texture_gl.GetGLHandle();

glBindTexture(GL_TEXTURE_2D, texture_handle.get());

auto size = texture.GetSize();
std::vector<uint8_t> pixels(size.width, size.height * 4);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work liste: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions