Change how OpenGL textures are flipped in the Android embedder. (flutter/engine#49938)

h/t @bdero for [writing the actual
code](https://github.com/flutter/flutter/issues/141636#issuecomment-1903677360)
(I just wrote comments).

Manual test[^1] of `cd
packages/packages/video_player/video_player/example && flutter run`:

## Skia

![Screenshot 2024-01-22 at 3 21
20 PM](https://github.com/flutter/engine/assets/168174/f1023251-4b44-47f3-94f8-1d5dced7bcb3)

## Impeller + OpenGL

![Screenshot 2024-01-22 at 9 41
59 AM](https://github.com/flutter/engine/assets/168174/a2bed578-c929-4222-a1f9-010e2dc95b7e)

```xml
<meta-data
      android:name="io.flutter.embedding.android.EnableImpeller"
      android:value="true" />
<meta-data
      android:name="io.flutter.embedding.android.ImpellerBackend"
      android:value="opengles" />
```

Closes https://github.com/flutter/flutter/issues/141636.

[^1]: I can't write a test worth writing at the same time of this PR, so
I've filed https://github.com/flutter/flutter/issues/141973 to do it
after.
This commit is contained in:
Matan Lurey
2024-01-22 16:52:32 -08:00
committed by GitHub
parent f72693e774
commit 549738f77f
2 changed files with 18 additions and 8 deletions

View File

@@ -58,11 +58,17 @@ void SurfaceTextureExternalTexture::Paint(PaintContext& context,
if (dl_image_) {
DlAutoCanvasRestore autoRestore(context.canvas, true);
// The incoming texture is vertically flipped, so we flip it
// back. OpenGL's coordinate system has Positive Y equivalent to up, while
// Skia's coordinate system has Negative Y equvalent to up.
context.canvas->Translate(bounds.x(), bounds.y() + bounds.height());
context.canvas->Scale(bounds.width(), -bounds.height());
// The incoming texture is vertically flipped, so we flip it back.
//
// OpenGL's coordinate system has Positive Y equivalent to up, while Skia's
// coordinate system (as well as Impeller's) has Negative Y equvalent to up.
{
// Move (translate) the origin to the bottom-left corner of the image.
context.canvas->Translate(bounds.x(), bounds.y() + bounds.height());
// No change in the X axis, but we need to flip the Y axis.
context.canvas->Scale(1, -1);
}
if (!transform_.isIdentity()) {
DlImageColorSource source(dl_image_, DlTileMode::kRepeat,
@@ -73,7 +79,8 @@ void SurfaceTextureExternalTexture::Paint(PaintContext& context,
paintWithShader = *context.paint;
}
paintWithShader.setColorSource(&source);
context.canvas->DrawRect(SkRect::MakeWH(1, 1), paintWithShader);
context.canvas->DrawRect(SkRect::MakeWH(bounds.width(), bounds.height()),
paintWithShader);
} else {
context.canvas->DrawImage(dl_image_, {0, 0}, sampling, context.paint);
}

View File

@@ -48,8 +48,11 @@ void SurfaceTextureExternalTextureGL::ProcessFrame(PaintContext& context,
// Create a
GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_,
GL_RGBA8_OES};
auto backendTexture =
GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo);
auto backendTexture = GrBackendTextures::MakeGL(
/*width=*/bounds.width(),
/*height=*/bounds.height(),
/*Mipmapped=*/skgpu::Mipmapped::kNo,
/*glInfo=*/textureInfo);
dl_image_ = DlImage::Make(SkImages::BorrowTextureFrom(
context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr));