Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] fix OES texture SurfaceTexture + GL backend. #57251

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions impeller/entity/contents/color_source_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ class ColorSourceContents : public Contents {

protected:
using BindFragmentCallback = std::function<bool(RenderPass& pass)>;
using PipelineBuilderMethod = std::shared_ptr<Pipeline<PipelineDescriptor>> (
impeller::ContentContext::*)(ContentContextOptions) const;
using PipelineBuilderCallback =
std::function<PipelineRef(ContentContextOptions)>;
using CreateGeometryCallback =
Expand Down
1 change: 1 addition & 0 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ ContentContext::ContentContext(
#if !defined(FML_OS_MACOSX)
// GLES only shader that is unsupported on macOS.
tiled_texture_external_pipelines_.CreateDefault(*context_, options);
tiled_texture_uv_external_pipelines_.CreateDefault(*context_, options);
#endif // !defined(FML_OS_MACOSX)
texture_downsample_gles_pipelines_.CreateDefault(*context_,
options_trianglestrip);
Expand Down
12 changes: 12 additions & 0 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ using VerticesUberShader = RenderPipelineHandle<PorterDuffBlendVertexShader,
using TiledTextureExternalPipeline =
RenderPipelineHandle<TextureFillVertexShader,
TiledTextureFillExternalFragmentShader>;
using TiledTextureUvExternalPipeline =
RenderPipelineHandle<TextureUvFillVertexShader,
TiledTextureFillExternalFragmentShader>;
using TextureDownsampleGlesPipeline =
RenderPipelineHandle<TextureFillVertexShader,
TextureDownsampleGlesFragmentShader>;
Expand Down Expand Up @@ -469,6 +472,13 @@ class ContentContext {
Context::BackendType::kOpenGLES);
return GetPipeline(tiled_texture_external_pipelines_, opts);
}

PipelineRef GetTiledTextureUvExternalPipeline(
ContentContextOptions opts) const {
FML_DCHECK(GetContext()->GetBackendType() ==
Context::BackendType::kOpenGLES);
return GetPipeline(tiled_texture_uv_external_pipelines_, opts);
}
#endif // IMPELLER_ENABLE_OPENGLES

PipelineRef GetTiledTexturePipeline(ContentContextOptions opts) const {
Expand Down Expand Up @@ -890,6 +900,8 @@ class ContentContext {
#ifdef IMPELLER_ENABLE_OPENGLES
mutable Variants<TiledTextureExternalPipeline>
tiled_texture_external_pipelines_;
mutable Variants<TiledTextureUvExternalPipeline>
tiled_texture_uv_external_pipelines_;
mutable Variants<TextureDownsampleGlesPipeline>
texture_downsample_gles_pipelines_;
#endif // IMPELLER_ENABLE_OPENGLES
Expand Down
41 changes: 40 additions & 1 deletion impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,46 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
Rect::MakeSize(texture_size).GetNormalizingTransform() *
GetInverseEffectTransform();

#ifdef IMPELLER_ENABLE_OPENGLES
using FSExternal = TiledTextureFillExternalFragmentShader;
if (texture_->GetTextureDescriptor().type ==
TextureType::kTextureExternalOES) {
return ColorSourceContents::DrawGeometry<VS>(
renderer, entity, pass,
[&renderer](ContentContextOptions options) {
return renderer.GetTiledTextureUvExternalPipeline(options);
},
frame_info,
[this, &renderer](RenderPass& pass) {
auto& host_buffer = renderer.GetTransientsBuffer();
#ifdef IMPELLER_DEBUG
pass.SetCommandLabel("TextureFill External");
#endif // IMPELLER_DEBUG

FML_DCHECK(!color_filter_);
FSExternal::FragInfo frag_info;
frag_info.x_tile_mode =
static_cast<Scalar>(sampler_descriptor_.width_address_mode);
frag_info.y_tile_mode =
static_cast<Scalar>(sampler_descriptor_.height_address_mode);
frag_info.alpha = GetOpacityFactor();
FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));

SamplerDescriptor sampler_desc;
// OES_EGL_image_external states that only CLAMP_TO_EDGE is valid,
// so we emulate all other tile modes here by remapping the texture
// coordinates.
sampler_desc.width_address_mode = SamplerAddressMode::kClampToEdge;
sampler_desc.height_address_mode = SamplerAddressMode::kClampToEdge;
FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
pass, texture_,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
sampler_desc));
return true;
});
}
#endif // IMPELLER_ENABLE_OPENGLES

PipelineBuilderCallback pipeline_callback =
[&renderer](ContentContextOptions options) {
return renderer.GetTiledTexturePipeline(options);
Expand Down Expand Up @@ -163,7 +203,6 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
CreateSamplerDescriptor(renderer.GetDeviceCapabilities())));
}

return true;
});
}
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/shaders/texture_fill.vert
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ frame_info;
in vec2 position;
in vec2 texture_coords;

out vec2 v_texture_coords;
out highp vec2 v_texture_coords;

void main() {
gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0);
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/shaders/texture_uv_fill.vert
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ frame_info;

in vec2 position;

out mediump vec2 v_texture_coords;
out highp vec2 v_texture_coords;

void main() {
gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0);
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/shaders/tiled_texture_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ uniform FragInfo {
}
frag_info;

in mediump vec2 v_texture_coords;
in highp vec2 v_texture_coords;

out f16vec4 frag_color;

Expand Down
5 changes: 0 additions & 5 deletions shell/platform/android/surface_texture_external_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkColorType.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
#include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
#include "third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"

namespace flutter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ void SurfaceTextureExternalTextureGLImpeller::ProcessFrame(
desc.type = impeller::TextureType::kTextureExternalOES;
desc.storage_mode = impeller::StorageMode::kDevicePrivate;
desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt;
desc.size = {static_cast<int>(bounds.width()),
static_cast<int>(bounds.height())};
desc.size = {static_cast<int>(1), static_cast<int>(1)};
desc.mip_count = 1;
texture_ = std::make_shared<impeller::TextureGLES>(
impeller_context_->GetReactor(), desc);
Expand Down
Loading