From 2aeccb360b8b1f4afe0986f46914e92dc139ee39 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Wed, 18 Dec 2024 09:15:43 -0800 Subject: [PATCH 1/2] [Impeller] fix OES texture SurfaceTexture + GL backend. --- .../entity/contents/color_source_contents.h | 2 - impeller/entity/contents/content_context.cc | 1 + impeller/entity/contents/content_context.h | 12 ++++++ .../entity/contents/tiled_texture_contents.cc | 41 ++++++++++++++++++- impeller/entity/shaders/texture_fill.vert | 2 +- impeller/entity/shaders/texture_uv_fill.vert | 2 +- .../entity/shaders/tiled_texture_fill.frag | 2 +- .../renderer/backend/gles/proc_table_gles.h | 6 +-- .../surface_texture_external_texture.cc | 1 + ...ce_texture_external_texture_gl_impeller.cc | 3 +- 10 files changed, 61 insertions(+), 11 deletions(-) diff --git a/impeller/entity/contents/color_source_contents.h b/impeller/entity/contents/color_source_contents.h index 17eba81f8930a..b988ff4ee009e 100644 --- a/impeller/entity/contents/color_source_contents.h +++ b/impeller/entity/contents/color_source_contents.h @@ -101,8 +101,6 @@ class ColorSourceContents : public Contents { protected: using BindFragmentCallback = std::function; - using PipelineBuilderMethod = std::shared_ptr> ( - impeller::ContentContext::*)(ContentContextOptions) const; using PipelineBuilderCallback = std::function; using CreateGeometryCallback = diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index a214b436c0f97..ba1c8290138ed 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -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); diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 0a0aee36262b9..982d35fc1baf1 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -257,6 +257,9 @@ using VerticesUberShader = RenderPipelineHandle; +using TiledTextureUvExternalPipeline = + RenderPipelineHandle; using TextureDownsampleGlesPipeline = RenderPipelineHandle; @@ -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 { @@ -890,6 +900,8 @@ class ContentContext { #ifdef IMPELLER_ENABLE_OPENGLES mutable Variants tiled_texture_external_pipelines_; + mutable Variants + tiled_texture_uv_external_pipelines_; mutable Variants texture_downsample_gles_pipelines_; #endif // IMPELLER_ENABLE_OPENGLES diff --git a/impeller/entity/contents/tiled_texture_contents.cc b/impeller/entity/contents/tiled_texture_contents.cc index e7b9e946de34c..cb3254ebffb75 100644 --- a/impeller/entity/contents/tiled_texture_contents.cc +++ b/impeller/entity/contents/tiled_texture_contents.cc @@ -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( + 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(sampler_descriptor_.width_address_mode); + frag_info.y_tile_mode = + static_cast(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); @@ -163,7 +203,6 @@ bool TiledTextureContents::Render(const ContentContext& renderer, renderer.GetContext()->GetSamplerLibrary()->GetSampler( CreateSamplerDescriptor(renderer.GetDeviceCapabilities()))); } - return true; }); } diff --git a/impeller/entity/shaders/texture_fill.vert b/impeller/entity/shaders/texture_fill.vert index 0dbc6fd4bfad4..49338765bd387 100644 --- a/impeller/entity/shaders/texture_fill.vert +++ b/impeller/entity/shaders/texture_fill.vert @@ -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); diff --git a/impeller/entity/shaders/texture_uv_fill.vert b/impeller/entity/shaders/texture_uv_fill.vert index 786aedd042280..cd07abfdaea59 100644 --- a/impeller/entity/shaders/texture_uv_fill.vert +++ b/impeller/entity/shaders/texture_uv_fill.vert @@ -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); diff --git a/impeller/entity/shaders/tiled_texture_fill.frag b/impeller/entity/shaders/tiled_texture_fill.frag index 8061712591792..25b2af3526ecf 100644 --- a/impeller/entity/shaders/tiled_texture_fill.frag +++ b/impeller/entity/shaders/tiled_texture_fill.frag @@ -18,7 +18,7 @@ uniform FragInfo { } frag_info; -in mediump vec2 v_texture_coords; +in highp vec2 v_texture_coords; out f16vec4 frag_color; diff --git a/impeller/renderer/backend/gles/proc_table_gles.h b/impeller/renderer/backend/gles/proc_table_gles.h index 8bc3ca76ba835..6de49008462cf 100644 --- a/impeller/renderer/backend/gles/proc_table_gles.h +++ b/impeller/renderer/backend/gles/proc_table_gles.h @@ -35,7 +35,7 @@ struct AutoErrorCheck { return; } if (GLErrorIsFatal(error)) { - FML_LOG(FATAL) << "Fatal GL Error " << GLErrorToString(error) << "(" + FML_LOG(ERROR) << "Fatal GL Error " << GLErrorToString(error) << "(" << error << ")" << " encountered on call to " << name; } else { FML_LOG(ERROR) << "GL Error " << GLErrorToString(error) << "(" << error @@ -107,7 +107,7 @@ struct GLProc { /// template auto operator()(Args&&... args) const { -#if defined(IMPELLER_DEBUG) && !defined(NDEBUG) + // #if defined(IMPELLER_DEBUG) && !defined(NDEBUG) AutoErrorCheck error(error_fn, name); // We check for the existence of extensions, and reset the function pointer // but it's still called unconditionally below, and will segfault. This @@ -118,7 +118,7 @@ struct GLProc { FML_LOG(IMPORTANT) << name << BuildGLArguments(std::forward(args)...); } -#endif // defined(IMPELLER_DEBUG) && !defined(NDEBUG) + // #endif // defined(IMPELLER_DEBUG) && !defined(NDEBUG) return function(std::forward(args)...); } diff --git a/shell/platform/android/surface_texture_external_texture.cc b/shell/platform/android/surface_texture_external_texture.cc index ed019b9101a16..9df3744f4469e 100644 --- a/shell/platform/android/surface_texture_external_texture.cc +++ b/shell/platform/android/surface_texture_external_texture.cc @@ -9,6 +9,7 @@ #include #include "flutter/display_list/effects/dl_color_source.h" +#include "include/core/SkMatrix.h" #include "third_party/skia/include/core/SkAlphaType.h" #include "third_party/skia/include/core/SkColorSpace.h" #include "third_party/skia/include/core/SkColorType.h" diff --git a/shell/platform/android/surface_texture_external_texture_gl_impeller.cc b/shell/platform/android/surface_texture_external_texture_gl_impeller.cc index 69f4b5e2c6906..e7f5336c29ff4 100644 --- a/shell/platform/android/surface_texture_external_texture_gl_impeller.cc +++ b/shell/platform/android/surface_texture_external_texture_gl_impeller.cc @@ -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(bounds.width()), - static_cast(bounds.height())}; + desc.size = {static_cast(1), static_cast(1)}; desc.mip_count = 1; texture_ = std::make_shared( impeller_context_->GetReactor(), desc); From da7dd92dae64b2225781b9371e98c3280ca783e6 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Wed, 18 Dec 2024 09:17:32 -0800 Subject: [PATCH 2/2] revert unrelated cases. --- impeller/renderer/backend/gles/proc_table_gles.h | 6 +++--- shell/platform/android/surface_texture_external_texture.cc | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/impeller/renderer/backend/gles/proc_table_gles.h b/impeller/renderer/backend/gles/proc_table_gles.h index 6de49008462cf..8bc3ca76ba835 100644 --- a/impeller/renderer/backend/gles/proc_table_gles.h +++ b/impeller/renderer/backend/gles/proc_table_gles.h @@ -35,7 +35,7 @@ struct AutoErrorCheck { return; } if (GLErrorIsFatal(error)) { - FML_LOG(ERROR) << "Fatal GL Error " << GLErrorToString(error) << "(" + FML_LOG(FATAL) << "Fatal GL Error " << GLErrorToString(error) << "(" << error << ")" << " encountered on call to " << name; } else { FML_LOG(ERROR) << "GL Error " << GLErrorToString(error) << "(" << error @@ -107,7 +107,7 @@ struct GLProc { /// template auto operator()(Args&&... args) const { - // #if defined(IMPELLER_DEBUG) && !defined(NDEBUG) +#if defined(IMPELLER_DEBUG) && !defined(NDEBUG) AutoErrorCheck error(error_fn, name); // We check for the existence of extensions, and reset the function pointer // but it's still called unconditionally below, and will segfault. This @@ -118,7 +118,7 @@ struct GLProc { FML_LOG(IMPORTANT) << name << BuildGLArguments(std::forward(args)...); } - // #endif // defined(IMPELLER_DEBUG) && !defined(NDEBUG) +#endif // defined(IMPELLER_DEBUG) && !defined(NDEBUG) return function(std::forward(args)...); } diff --git a/shell/platform/android/surface_texture_external_texture.cc b/shell/platform/android/surface_texture_external_texture.cc index 9df3744f4469e..9843937a0329f 100644 --- a/shell/platform/android/surface_texture_external_texture.cc +++ b/shell/platform/android/surface_texture_external_texture.cc @@ -9,16 +9,10 @@ #include #include "flutter/display_list/effects/dl_color_source.h" -#include "include/core/SkMatrix.h" #include "third_party/skia/include/core/SkAlphaType.h" #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 {