1313#include " impeller/entity/entity.h"
1414#include " impeller/entity/texture_fill.frag.h"
1515#include " impeller/entity/texture_fill.vert.h"
16- #include " impeller/entity/texture_fill_external.frag.h"
16+ #include " impeller/entity/texture_fill_strict_src.frag.h"
17+ #include " impeller/entity/tiled_texture_fill_external.frag.h"
1718#include " impeller/geometry/constants.h"
1819#include " impeller/renderer/render_pass.h"
1920#include " impeller/renderer/vertex_buffer_builder.h"
@@ -113,8 +114,8 @@ bool TextureContents::Render(const ContentContext& renderer,
113114
114115 using VS = TextureFillVertexShader;
115116 using FS = TextureFillFragmentShader;
116- using FSStrictSrc = TextureFillStrictSrcFragmentShader ;
117- using FSExternal = TextureFillExternalFragmentShader ;
117+ using FSExternal = TiledTextureFillExternalFragmentShader ;
118+ using FSStrict = TextureFillStrictSrcFragmentShader ;
118119
119120 if (destination_rect_.IsEmpty () || source_rect_.IsEmpty () ||
120121 texture_ == nullptr || texture_->GetSize ().IsEmpty ()) {
@@ -129,7 +130,6 @@ bool TextureContents::Render(const ContentContext& renderer,
129130 Rect::MakeSize (texture_->GetSize ()).Project (source_rect);
130131
131132 VertexBufferBuilder<VS::PerVertexData> vertex_builder;
132-
133133 auto destination_rect =
134134 capture.AddRect (" Destination rect" , destination_rect_);
135135 vertex_builder.AddVertices ({
@@ -144,7 +144,6 @@ bool TextureContents::Render(const ContentContext& renderer,
144144 VS::FrameInfo frame_info;
145145 frame_info.mvp = entity.GetShaderTransform (pass);
146146 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale ();
147- frame_info.alpha = capture.AddScalar (" Alpha" , GetOpacity ());
148147
149148#ifdef IMPELLER_DEBUG
150149 if (label_.empty ()) {
@@ -163,7 +162,7 @@ bool TextureContents::Render(const ContentContext& renderer,
163162 std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
164163#ifdef IMPELLER_ENABLE_OPENGLES
165164 if (is_external_texture) {
166- pipeline = renderer.GetTextureExternalPipeline (pipeline_options);
165+ pipeline = renderer.GetTiledTextureExternalPipeline (pipeline_options);
167166 }
168167#endif // IMPELLER_ENABLE_OPENGLES
169168
@@ -178,26 +177,46 @@ bool TextureContents::Render(const ContentContext& renderer,
178177
179178 pass.SetVertexBuffer (vertex_builder.CreateVertexBuffer (host_buffer));
180179 VS::BindFrameInfo (pass, host_buffer.EmplaceUniform (frame_info));
180+
181181 if (is_external_texture) {
182+ FSExternal::FragInfo frag_info;
183+ frag_info.x_tile_mode =
184+ static_cast <int >(sampler_descriptor_.width_address_mode );
185+ frag_info.y_tile_mode =
186+ static_cast <int >(sampler_descriptor_.height_address_mode );
187+ frag_info.alpha = capture.AddScalar (" Alpha" , GetOpacity ());
188+
189+ auto sampler_descriptor = sampler_descriptor_;
190+ // OES_EGL_image_external states that only CLAMP_TO_EDGE is valid, so
191+ // we emulate all other tile modes here by remapping the texture
192+ // coordinates.
193+ sampler_descriptor.width_address_mode = SamplerAddressMode::kClampToEdge ;
194+ sampler_descriptor.height_address_mode = SamplerAddressMode::kClampToEdge ;
195+
196+ FSExternal::BindFragInfo (pass, host_buffer.EmplaceUniform ((frag_info)));
182197 FSExternal::BindSAMPLEREXTERNALOESTextureSampler (
183198 pass, texture_,
184199 renderer.GetContext ()->GetSamplerLibrary ()->GetSampler (
185- sampler_descriptor_ ));
200+ sampler_descriptor ));
186201 } else if (strict_source_rect_enabled_) {
187202 // For a strict source rect, shrink the texture coordinate range by half a
188203 // texel to ensure that linear filtering does not sample anything outside
189204 // the source rect bounds.
190205 auto strict_texture_coords =
191206 Rect::MakeSize (texture_->GetSize ()).Project (source_rect.Expand (-0.5 ));
192207
193- FSStrictSrc ::FragInfo frag_info;
208+ FSStrict ::FragInfo frag_info;
194209 frag_info.source_rect = Vector4 (strict_texture_coords.GetLTRB ());
195- FSStrictSrc::BindFragInfo (pass, host_buffer.EmplaceUniform (frag_info));
196- FSStrictSrc::BindTextureSampler (
210+ frag_info.alpha = capture.AddScalar (" Alpha" , GetOpacity ());
211+ FSStrict::BindFragInfo (pass, host_buffer.EmplaceUniform ((frag_info)));
212+ FSStrict::BindTextureSampler (
197213 pass, texture_,
198214 renderer.GetContext ()->GetSamplerLibrary ()->GetSampler (
199215 sampler_descriptor_));
200216 } else {
217+ FS::FragInfo frag_info;
218+ frag_info.alpha = capture.AddScalar (" Alpha" , GetOpacity ());
219+ FS::BindFragInfo (pass, host_buffer.EmplaceUniform ((frag_info)));
201220 FS::BindTextureSampler (
202221 pass, texture_,
203222 renderer.GetContext ()->GetSamplerLibrary ()->GetSampler (
0 commit comments