Skip to content

Commit 2d81159

Browse files
author
Jonah Williams
authored
[Impeller] Fix GLES SurfaceTexture rendering. (#160634)
Fixes flutter/flutter#160480 Both The Impeller and Skia variant of the OES texture rendering use the same shared code path, so the Impeller code must match the weird 1x1 texture behavior of Skia. In addition, we have to add back the TiledTextureContents support, since we need to render a texture with a transform. I had previously tested this but neglected to force the SurfaceTexture path, so I only tested the ImageReader path which does not use a transform.
1 parent 9eca517 commit 2d81159

File tree

10 files changed

+65
-20
lines changed

10 files changed

+65
-20
lines changed

engine/src/flutter/impeller/entity/contents/color_source_contents.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ class ColorSourceContents : public Contents {
101101

102102
protected:
103103
using BindFragmentCallback = std::function<bool(RenderPass& pass)>;
104-
using PipelineBuilderMethod = std::shared_ptr<Pipeline<PipelineDescriptor>> (
105-
impeller::ContentContext::*)(ContentContextOptions) const;
106104
using PipelineBuilderCallback =
107105
std::function<PipelineRef(ContentContextOptions)>;
108106
using CreateGeometryCallback =

engine/src/flutter/impeller/entity/contents/content_context.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ ContentContext::ContentContext(
464464
#if !defined(FML_OS_MACOSX)
465465
// GLES only shader that is unsupported on macOS.
466466
tiled_texture_external_pipelines_.CreateDefault(*context_, options);
467+
tiled_texture_uv_external_pipelines_.CreateDefault(*context_, options);
467468
#endif // !defined(FML_OS_MACOSX)
468469
texture_downsample_gles_pipelines_.CreateDefault(*context_,
469470
options_trianglestrip);

engine/src/flutter/impeller/entity/contents/content_context.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ using VerticesUberShader = RenderPipelineHandle<PorterDuffBlendVertexShader,
257257
using TiledTextureExternalPipeline =
258258
RenderPipelineHandle<TextureFillVertexShader,
259259
TiledTextureFillExternalFragmentShader>;
260+
using TiledTextureUvExternalPipeline =
261+
RenderPipelineHandle<TextureUvFillVertexShader,
262+
TiledTextureFillExternalFragmentShader>;
260263
using TextureDownsampleGlesPipeline =
261264
RenderPipelineHandle<TextureFillVertexShader,
262265
TextureDownsampleGlesFragmentShader>;
@@ -469,6 +472,13 @@ class ContentContext {
469472
Context::BackendType::kOpenGLES);
470473
return GetPipeline(tiled_texture_external_pipelines_, opts);
471474
}
475+
476+
PipelineRef GetTiledTextureUvExternalPipeline(
477+
ContentContextOptions opts) const {
478+
FML_DCHECK(GetContext()->GetBackendType() ==
479+
Context::BackendType::kOpenGLES);
480+
return GetPipeline(tiled_texture_uv_external_pipelines_, opts);
481+
}
472482
#endif // IMPELLER_ENABLE_OPENGLES
473483

474484
PipelineRef GetTiledTexturePipeline(ContentContextOptions opts) const {
@@ -892,6 +902,8 @@ class ContentContext {
892902
tiled_texture_external_pipelines_;
893903
mutable Variants<TextureDownsampleGlesPipeline>
894904
texture_downsample_gles_pipelines_;
905+
mutable Variants<TiledTextureUvExternalPipeline>
906+
tiled_texture_uv_external_pipelines_;
895907
#endif // IMPELLER_ENABLE_OPENGLES
896908
mutable Variants<TiledTexturePipeline> tiled_texture_pipelines_;
897909
mutable Variants<GaussianBlurPipeline> gaussian_blur_pipelines_;

engine/src/flutter/impeller/entity/contents/tiled_texture_contents.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,46 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
128128
Rect::MakeSize(texture_size).GetNormalizingTransform() *
129129
GetInverseEffectTransform();
130130

131+
#ifdef IMPELLER_ENABLE_OPENGLES
132+
using FSExternal = TiledTextureFillExternalFragmentShader;
133+
if (texture_->GetTextureDescriptor().type ==
134+
TextureType::kTextureExternalOES) {
135+
return ColorSourceContents::DrawGeometry<VS>(
136+
renderer, entity, pass,
137+
[&renderer](ContentContextOptions options) {
138+
return renderer.GetTiledTextureUvExternalPipeline(options);
139+
},
140+
frame_info,
141+
[this, &renderer](RenderPass& pass) {
142+
auto& host_buffer = renderer.GetTransientsBuffer();
143+
#ifdef IMPELLER_DEBUG
144+
pass.SetCommandLabel("TextureFill External");
145+
#endif // IMPELLER_DEBUG
146+
147+
FML_DCHECK(!color_filter_);
148+
FSExternal::FragInfo frag_info;
149+
frag_info.x_tile_mode =
150+
static_cast<Scalar>(sampler_descriptor_.width_address_mode);
151+
frag_info.y_tile_mode =
152+
static_cast<Scalar>(sampler_descriptor_.height_address_mode);
153+
frag_info.alpha = GetOpacityFactor();
154+
FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
155+
156+
SamplerDescriptor sampler_desc;
157+
// OES_EGL_image_external states that only CLAMP_TO_EDGE is valid,
158+
// so we emulate all other tile modes here by remapping the texture
159+
// coordinates.
160+
sampler_desc.width_address_mode = SamplerAddressMode::kClampToEdge;
161+
sampler_desc.height_address_mode = SamplerAddressMode::kClampToEdge;
162+
FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
163+
pass, texture_,
164+
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
165+
sampler_desc));
166+
return true;
167+
});
168+
}
169+
#endif // IMPELLER_ENABLE_OPENGLES
170+
131171
PipelineBuilderCallback pipeline_callback =
132172
[&renderer](ContentContextOptions options) {
133173
return renderer.GetTiledTexturePipeline(options);

engine/src/flutter/impeller/entity/shaders/texture_fill.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ frame_info;
1414
in vec2 position;
1515
in vec2 texture_coords;
1616

17-
out vec2 v_texture_coords;
17+
out highp vec2 v_texture_coords;
1818

1919
void main() {
2020
gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0);

engine/src/flutter/impeller/entity/shaders/texture_uv_fill.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ frame_info;
1616

1717
in vec2 position;
1818

19-
out mediump vec2 v_texture_coords;
19+
out highp vec2 v_texture_coords;
2020

2121
void main() {
2222
gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0);

engine/src/flutter/impeller/entity/shaders/tiled_texture_fill.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ uniform FragInfo {
1818
}
1919
frag_info;
2020

21-
in mediump vec2 v_texture_coords;
21+
in highp vec2 v_texture_coords;
2222

2323
out f16vec4 frag_color;
2424

engine/src/flutter/impeller/tools/malioc.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5969,7 +5969,7 @@
59695969
"longest_path_cycles": [
59705970
0.078125,
59715971
0.078125,
5972-
0.078125,
5972+
0.015625,
59735973
0.0,
59745974
3.0,
59755975
0.0
@@ -5988,7 +5988,7 @@
59885988
"shortest_path_cycles": [
59895989
0.078125,
59905990
0.078125,
5991-
0.078125,
5991+
0.015625,
59925992
0.0,
59935993
3.0,
59945994
0.0
@@ -5999,7 +5999,7 @@
59995999
"total_cycles": [
60006000
0.078125,
60016001
0.078125,
6002-
0.078125,
6002+
0.015625,
60036003
0.0,
60046004
3.0,
60056005
0.0
@@ -6008,7 +6008,7 @@
60086008
"stack_spill_bytes": 0,
60096009
"thread_occupancy": 100,
60106010
"uniform_registers_used": 16,
6011-
"work_registers_used": 8
6011+
"work_registers_used": 9
60126012
}
60136013
}
60146014
},
@@ -8771,7 +8771,7 @@
87718771
"longest_path_cycles": [
87728772
0.078125,
87738773
0.078125,
8774-
0.078125,
8774+
0.015625,
87758775
0.0,
87768776
3.0,
87778777
0.0
@@ -8790,7 +8790,7 @@
87908790
"shortest_path_cycles": [
87918791
0.078125,
87928792
0.078125,
8793-
0.078125,
8793+
0.015625,
87948794
0.0,
87958795
3.0,
87968796
0.0
@@ -8801,7 +8801,7 @@
88018801
"total_cycles": [
88028802
0.078125,
88038803
0.078125,
8804-
0.078125,
8804+
0.015625,
88058805
0.0,
88068806
3.0,
88078807
0.0
@@ -8810,7 +8810,7 @@
88108810
"stack_spill_bytes": 0,
88118811
"thread_occupancy": 100,
88128812
"uniform_registers_used": 32,
8813-
"work_registers_used": 8
8813+
"work_registers_used": 9
88148814
}
88158815
}
88168816
}

engine/src/flutter/shell/platform/android/surface_texture_external_texture.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
#include "third_party/skia/include/core/SkColorSpace.h"
1414
#include "third_party/skia/include/core/SkColorType.h"
1515
#include "third_party/skia/include/core/SkImage.h"
16-
#include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
17-
#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
18-
#include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
19-
#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
20-
#include "third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"
2116

2217
namespace flutter {
2318

engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ void SurfaceTextureExternalTextureGLImpeller::ProcessFrame(
2929
desc.type = impeller::TextureType::kTextureExternalOES;
3030
desc.storage_mode = impeller::StorageMode::kDevicePrivate;
3131
desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt;
32-
desc.size = {static_cast<int>(bounds.width()),
33-
static_cast<int>(bounds.height())};
32+
desc.size = {1, 1};
3433
desc.mip_count = 1;
3534
texture_ = std::make_shared<impeller::TextureGLES>(
3635
impeller_context_->GetReactor(), desc);

0 commit comments

Comments
 (0)