Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 37f68f6

Browse files
authored
Change how OpenGL textures are flipped in the Android embedder. (#49938)
h/t @bdero for [writing the actual code](flutter/flutter#141636 (comment)) (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 flutter/flutter#141636. [^1]: I can't write a test worth writing at the same time of this PR, so I've filed flutter/flutter#141973 to do it after.
1 parent 9e582c9 commit 37f68f6

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

shell/platform/android/surface_texture_external_texture.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ void SurfaceTextureExternalTexture::Paint(PaintContext& context,
5858
if (dl_image_) {
5959
DlAutoCanvasRestore autoRestore(context.canvas, true);
6060

61-
// The incoming texture is vertically flipped, so we flip it
62-
// back. OpenGL's coordinate system has Positive Y equivalent to up, while
63-
// Skia's coordinate system has Negative Y equvalent to up.
64-
context.canvas->Translate(bounds.x(), bounds.y() + bounds.height());
65-
context.canvas->Scale(bounds.width(), -bounds.height());
61+
// The incoming texture is vertically flipped, so we flip it back.
62+
//
63+
// OpenGL's coordinate system has Positive Y equivalent to up, while Skia's
64+
// coordinate system (as well as Impeller's) has Negative Y equvalent to up.
65+
{
66+
// Move (translate) the origin to the bottom-left corner of the image.
67+
context.canvas->Translate(bounds.x(), bounds.y() + bounds.height());
68+
69+
// No change in the X axis, but we need to flip the Y axis.
70+
context.canvas->Scale(1, -1);
71+
}
6672

6773
if (!transform_.isIdentity()) {
6874
DlImageColorSource source(dl_image_, DlTileMode::kRepeat,
@@ -73,7 +79,8 @@ void SurfaceTextureExternalTexture::Paint(PaintContext& context,
7379
paintWithShader = *context.paint;
7480
}
7581
paintWithShader.setColorSource(&source);
76-
context.canvas->DrawRect(SkRect::MakeWH(1, 1), paintWithShader);
82+
context.canvas->DrawRect(SkRect::MakeWH(bounds.width(), bounds.height()),
83+
paintWithShader);
7784
} else {
7885
context.canvas->DrawImage(dl_image_, {0, 0}, sampling, context.paint);
7986
}

shell/platform/android/surface_texture_external_texture_gl.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ void SurfaceTextureExternalTextureGL::ProcessFrame(PaintContext& context,
4848
// Create a
4949
GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_,
5050
GL_RGBA8_OES};
51-
auto backendTexture =
52-
GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo);
51+
auto backendTexture = GrBackendTextures::MakeGL(
52+
/*width=*/bounds.width(),
53+
/*height=*/bounds.height(),
54+
/*Mipmapped=*/skgpu::Mipmapped::kNo,
55+
/*glInfo=*/textureInfo);
5356
dl_image_ = DlImage::Make(SkImages::BorrowTextureFrom(
5457
context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin,
5558
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr));

0 commit comments

Comments
 (0)