From a8d3cad5ac4e0de2bf8a8245e837d3ba3a234218 Mon Sep 17 00:00:00 2001 From: Xiaowei Guan Date: Mon, 17 Jun 2024 21:41:08 +0800 Subject: [PATCH] Move update size code to ResolveTexture method --- .../embedder_external_texture_gl_impeller.cc | 32 ++++++++----------- .../embedder_external_texture_gl_impeller.h | 12 +++---- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/shell/platform/embedder/embedder_external_texture_gl_impeller.cc b/shell/platform/embedder/embedder_external_texture_gl_impeller.cc index adbc8cc895706..d5c4a5a677b26 100755 --- a/shell/platform/embedder/embedder_external_texture_gl_impeller.cc +++ b/shell/platform/embedder/embedder_external_texture_gl_impeller.cc @@ -17,7 +17,7 @@ namespace flutter { EmbedderExternalTextureGLImpeller::EmbedderExternalTextureGLImpeller( int64_t texture_identifier, - const ExternalTextureCallback& callback) + const EmbedderExternalTextureGL::ExternalTextureCallback& callback) : Texture(texture_identifier), external_texture_callback_(callback) { FML_DCHECK(external_texture_callback_); } @@ -74,11 +74,19 @@ sk_sp EmbedderExternalTextureGLImpeller::ResolveTexture( if (!texture) { return nullptr; } + size_t width = size.width(); + size_t height = size.height(); + if (texture->width != 0 && texture->height != 0) { + width = texture->width; + height = texture->height; + } if (texture->impeller_texture_type == FlutterGLImpellerTextureType::kFlutterGLImpellerTexturePixelBuffer) { - return ResolvePixelBufferTexture(texture.get(), context, size); + return ResolvePixelBufferTexture(texture.get(), context, + SkISize::Make(width, height)); } else { - return ResolveGpuSurfaceTexture(texture.get(), context, size); + return ResolveGpuSurfaceTexture(texture.get(), context, + SkISize::Make(width, height)); } } @@ -86,21 +94,14 @@ sk_sp EmbedderExternalTextureGLImpeller::ResolvePixelBufferTexture( FlutterOpenGLTexture* texture, PaintContext& context, const SkISize& size) { - size_t width = size.width(); - size_t height = size.height(); - if (texture->width != 0 && texture->height != 0) { - width = texture->width; - height = texture->height; - } impeller::TextureDescriptor desc; desc.type = impeller::TextureType::kTexture2D; - impeller::AiksContext* aiks_context = context.aiks_context; const auto& gl_context = impeller::ContextGLES::Cast(*aiks_context->GetContext()); desc.storage_mode = impeller::StorageMode::kDevicePrivate; desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt; - desc.size = {static_cast(width), static_cast(height)}; + desc.size = {static_cast(size.width()), static_cast(size.height())}; desc.mip_count = 1; auto textureGLES = @@ -121,12 +122,6 @@ sk_sp EmbedderExternalTextureGLImpeller::ResolveGpuSurfaceTexture( FlutterOpenGLTexture* texture, PaintContext& context, const SkISize& size) { - size_t width = size.width(); - size_t height = size.height(); - if (texture->width != 0 && texture->height != 0) { - width = texture->width; - height = texture->height; - } impeller::TextureDescriptor desc; desc.type = impeller::TextureType::kTextureExternalOES; impeller::AiksContext* aiks_context = context.aiks_context; @@ -134,8 +129,7 @@ sk_sp EmbedderExternalTextureGLImpeller::ResolveGpuSurfaceTexture( impeller::ContextGLES::Cast(*aiks_context->GetContext()); desc.storage_mode = impeller::StorageMode::kDevicePrivate; desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt; - desc.size = {static_cast(texture->width), - static_cast(texture->height)}; + desc.size = {static_cast(size.width()), static_cast(size.height())}; desc.mip_count = 1; auto textureGLES = std::make_shared( gl_context.GetReactor(), desc, diff --git a/shell/platform/embedder/embedder_external_texture_gl_impeller.h b/shell/platform/embedder/embedder_external_texture_gl_impeller.h index c80028513e9e2..2b2e12d3bc6f6 100755 --- a/shell/platform/embedder/embedder_external_texture_gl_impeller.h +++ b/shell/platform/embedder/embedder_external_texture_gl_impeller.h @@ -8,22 +8,22 @@ #include "flutter/common/graphics/texture.h" #include "flutter/fml/macros.h" #include "flutter/shell/platform/embedder/embedder.h" +#include "flutter/shell/platform/embedder/embedder_external_texture_gl.h" #include "third_party/skia/include/core/SkSize.h" namespace flutter { class EmbedderExternalTextureGLImpeller : public flutter::Texture { public: - using ExternalTextureCallback = std::function< - std::unique_ptr(int64_t, size_t, size_t)>; - - EmbedderExternalTextureGLImpeller(int64_t texture_identifier, - const ExternalTextureCallback& callback); + EmbedderExternalTextureGLImpeller( + int64_t texture_identifier, + const EmbedderExternalTextureGL::ExternalTextureCallback& callback); ~EmbedderExternalTextureGLImpeller(); private: - const ExternalTextureCallback& external_texture_callback_; + const EmbedderExternalTextureGL::ExternalTextureCallback& + external_texture_callback_; sk_sp last_image_; sk_sp ResolveTexture(int64_t texture_id,