diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index 0239307f19..a0736f230c 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -43288,8 +43288,8 @@ ORIGIN: ../../../flutter/shell/platform/android/android_context_gl_impeller.cc + ORIGIN: ../../../flutter/shell/platform/android/android_context_gl_impeller.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/android_context_gl_skia.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/android_context_gl_skia.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/android/android_context_vulkan_impeller.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/android/android_context_vulkan_impeller.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/android_context_vk_impeller.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/android_context_vk_impeller.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/android_display.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/android_display.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/android_egl_surface.cc + ../../../flutter/LICENSE @@ -43307,8 +43307,8 @@ ORIGIN: ../../../flutter/shell/platform/android/android_surface_gl_skia.cc + ../ ORIGIN: ../../../flutter/shell/platform/android/android_surface_gl_skia.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/android_surface_software.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/android_surface_software.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/android/android_surface_vulkan_impeller.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/android/android_surface_vulkan_impeller.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/android_surface_vk_impeller.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/android_surface_vk_impeller.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/apk_asset_provider.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/apk_asset_provider.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/context/android_context.cc + ../../../flutter/LICENSE @@ -43323,8 +43323,12 @@ ORIGIN: ../../../flutter/shell/platform/android/image_external_texture.cc + ../. ORIGIN: ../../../flutter/shell/platform/android/image_external_texture.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_vk.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_vk.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl_impeller.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl_impeller.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl_skia.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl_skia.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_vk_impeller.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_vk_impeller.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/image_lru.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/image_lru.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/Build.java + ../../../flutter/LICENSE @@ -43496,8 +43500,10 @@ ORIGIN: ../../../flutter/shell/platform/android/surface/snapshot_surface_produce ORIGIN: ../../../flutter/shell/platform/android/surface/snapshot_surface_producer.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl_skia.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl_skia.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/vsync_waiter_android.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/vsync_waiter_android.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/common/accessibility_bridge.cc + ../../../flutter/LICENSE @@ -46163,8 +46169,8 @@ FILE: ../../../flutter/shell/platform/android/android_context_gl_impeller.cc FILE: ../../../flutter/shell/platform/android/android_context_gl_impeller.h FILE: ../../../flutter/shell/platform/android/android_context_gl_skia.cc FILE: ../../../flutter/shell/platform/android/android_context_gl_skia.h -FILE: ../../../flutter/shell/platform/android/android_context_vulkan_impeller.cc -FILE: ../../../flutter/shell/platform/android/android_context_vulkan_impeller.h +FILE: ../../../flutter/shell/platform/android/android_context_vk_impeller.cc +FILE: ../../../flutter/shell/platform/android/android_context_vk_impeller.h FILE: ../../../flutter/shell/platform/android/android_display.cc FILE: ../../../flutter/shell/platform/android/android_display.h FILE: ../../../flutter/shell/platform/android/android_egl_surface.cc @@ -46182,8 +46188,8 @@ FILE: ../../../flutter/shell/platform/android/android_surface_gl_skia.cc FILE: ../../../flutter/shell/platform/android/android_surface_gl_skia.h FILE: ../../../flutter/shell/platform/android/android_surface_software.cc FILE: ../../../flutter/shell/platform/android/android_surface_software.h -FILE: ../../../flutter/shell/platform/android/android_surface_vulkan_impeller.cc -FILE: ../../../flutter/shell/platform/android/android_surface_vulkan_impeller.h +FILE: ../../../flutter/shell/platform/android/android_surface_vk_impeller.cc +FILE: ../../../flutter/shell/platform/android/android_surface_vk_impeller.h FILE: ../../../flutter/shell/platform/android/apk_asset_provider.cc FILE: ../../../flutter/shell/platform/android/apk_asset_provider.h FILE: ../../../flutter/shell/platform/android/context/android_context.cc @@ -46198,8 +46204,12 @@ FILE: ../../../flutter/shell/platform/android/image_external_texture.cc FILE: ../../../flutter/shell/platform/android/image_external_texture.h FILE: ../../../flutter/shell/platform/android/image_external_texture_gl.cc FILE: ../../../flutter/shell/platform/android/image_external_texture_gl.h -FILE: ../../../flutter/shell/platform/android/image_external_texture_vk.cc -FILE: ../../../flutter/shell/platform/android/image_external_texture_vk.h +FILE: ../../../flutter/shell/platform/android/image_external_texture_gl_impeller.cc +FILE: ../../../flutter/shell/platform/android/image_external_texture_gl_impeller.h +FILE: ../../../flutter/shell/platform/android/image_external_texture_gl_skia.cc +FILE: ../../../flutter/shell/platform/android/image_external_texture_gl_skia.h +FILE: ../../../flutter/shell/platform/android/image_external_texture_vk_impeller.cc +FILE: ../../../flutter/shell/platform/android/image_external_texture_vk_impeller.h FILE: ../../../flutter/shell/platform/android/image_lru.cc FILE: ../../../flutter/shell/platform/android/image_lru.h FILE: ../../../flutter/shell/platform/android/io/flutter/Build.java @@ -46382,8 +46392,10 @@ FILE: ../../../flutter/shell/platform/android/surface/snapshot_surface_producer. FILE: ../../../flutter/shell/platform/android/surface/snapshot_surface_producer.h FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture.cc FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture.h -FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl.cc -FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl.h +FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.cc +FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.h +FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl_skia.cc +FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl_skia.h FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.cc FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.h FILE: ../../../flutter/shell/platform/common/accessibility_bridge.cc diff --git a/engine/src/flutter/shell/platform/android/BUILD.gn b/engine/src/flutter/shell/platform/android/BUILD.gn index 522b2c9826..d00643c367 100644 --- a/engine/src/flutter/shell/platform/android/BUILD.gn +++ b/engine/src/flutter/shell/platform/android/BUILD.gn @@ -84,8 +84,8 @@ source_set("flutter_shell_native_src") { "android_context_gl_impeller.h", "android_context_gl_skia.cc", "android_context_gl_skia.h", - "android_context_vulkan_impeller.cc", - "android_context_vulkan_impeller.h", + "android_context_vk_impeller.cc", + "android_context_vk_impeller.h", "android_display.cc", "android_display.h", "android_egl_surface.cc", @@ -100,8 +100,8 @@ source_set("flutter_shell_native_src") { "android_surface_gl_skia.h", "android_surface_software.cc", "android_surface_software.h", - "android_surface_vulkan_impeller.cc", - "android_surface_vulkan_impeller.h", + "android_surface_vk_impeller.cc", + "android_surface_vk_impeller.h", "apk_asset_provider.cc", "apk_asset_provider.h", "flutter_main.cc", @@ -110,8 +110,12 @@ source_set("flutter_shell_native_src") { "image_external_texture.h", "image_external_texture_gl.cc", "image_external_texture_gl.h", - "image_external_texture_vk.cc", - "image_external_texture_vk.h", + "image_external_texture_gl_impeller.cc", + "image_external_texture_gl_impeller.h", + "image_external_texture_gl_skia.cc", + "image_external_texture_gl_skia.h", + "image_external_texture_vk_impeller.cc", + "image_external_texture_vk_impeller.h", "image_lru.cc", "image_lru.h", "library_loader.cc", @@ -125,8 +129,10 @@ source_set("flutter_shell_native_src") { "platform_view_android_jni_impl.h", "surface_texture_external_texture.cc", "surface_texture_external_texture.h", - "surface_texture_external_texture_gl.cc", - "surface_texture_external_texture_gl.h", + "surface_texture_external_texture_gl_impeller.cc", + "surface_texture_external_texture_gl_impeller.h", + "surface_texture_external_texture_gl_skia.cc", + "surface_texture_external_texture_gl_skia.h", "vsync_waiter_android.cc", "vsync_waiter_android.h", ] diff --git a/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.cc b/engine/src/flutter/shell/platform/android/android_context_vk_impeller.cc similarity index 88% rename from engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.cc rename to engine/src/flutter/shell/platform/android/android_context_vk_impeller.cc index ecbeea6405..b81f9cb6b1 100644 --- a/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.cc +++ b/engine/src/flutter/shell/platform/android/android_context_vk_impeller.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/shell/platform/android/android_context_vulkan_impeller.h" +#include "flutter/shell/platform/android/android_context_vk_impeller.h" #include "flutter/fml/paths.h" #include "flutter/impeller/entity/vk/entity_shaders_vk.h" @@ -71,10 +71,9 @@ static std::shared_ptr CreateImpellerContext( return context; } -AndroidContextVulkanImpeller::AndroidContextVulkanImpeller( - bool enable_validation, - bool enable_gpu_tracing, - bool quiet) +AndroidContextVKImpeller::AndroidContextVKImpeller(bool enable_validation, + bool enable_gpu_tracing, + bool quiet) : AndroidContext(AndroidRenderingAPI::kImpellerVulkan), vulkan_dylib_(fml::NativeLibrary::Create("libvulkan.so")) { auto impeller_context = CreateImpellerContext( @@ -83,9 +82,9 @@ AndroidContextVulkanImpeller::AndroidContextVulkanImpeller( is_valid_ = !!impeller_context; } -AndroidContextVulkanImpeller::~AndroidContextVulkanImpeller() = default; +AndroidContextVKImpeller::~AndroidContextVKImpeller() = default; -bool AndroidContextVulkanImpeller::IsValid() const { +bool AndroidContextVKImpeller::IsValid() const { return is_valid_; } diff --git a/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.h b/engine/src/flutter/shell/platform/android/android_context_vk_impeller.h similarity index 50% rename from engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.h rename to engine/src/flutter/shell/platform/android/android_context_vk_impeller.h index cd9be6946a..afad4001bb 100644 --- a/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.h +++ b/engine/src/flutter/shell/platform/android/android_context_vk_impeller.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_VULKAN_IMPELLER_H_ -#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_VULKAN_IMPELLER_H_ +#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_VK_IMPELLER_H_ +#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_VK_IMPELLER_H_ #include "flutter/fml/concurrent_message_loop.h" #include "flutter/fml/macros.h" @@ -12,13 +12,13 @@ namespace flutter { -class AndroidContextVulkanImpeller : public AndroidContext { +class AndroidContextVKImpeller : public AndroidContext { public: - AndroidContextVulkanImpeller(bool enable_validation, - bool enable_gpu_tracing, - bool quiet = false); + AndroidContextVKImpeller(bool enable_validation, + bool enable_gpu_tracing, + bool quiet = false); - ~AndroidContextVulkanImpeller(); + ~AndroidContextVKImpeller(); // |AndroidContext| bool IsValid() const override; @@ -27,9 +27,9 @@ class AndroidContextVulkanImpeller : public AndroidContext { fml::RefPtr vulkan_dylib_; bool is_valid_ = false; - FML_DISALLOW_COPY_AND_ASSIGN(AndroidContextVulkanImpeller); + FML_DISALLOW_COPY_AND_ASSIGN(AndroidContextVKImpeller); }; } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_VULKAN_IMPELLER_H_ +#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_VK_IMPELLER_H_ diff --git a/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.cc b/engine/src/flutter/shell/platform/android/android_surface_vk_impeller.cc similarity index 74% rename from engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.cc rename to engine/src/flutter/shell/platform/android/android_surface_vk_impeller.cc index 9395709043..8dc12a78ac 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.cc +++ b/engine/src/flutter/shell/platform/android/android_surface_vk_impeller.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/shell/platform/android/android_surface_vulkan_impeller.h" +#include "flutter/shell/platform/android/android_surface_vk_impeller.h" #include #include @@ -17,8 +17,8 @@ namespace flutter { -AndroidSurfaceVulkanImpeller::AndroidSurfaceVulkanImpeller( - const std::shared_ptr& android_context) { +AndroidSurfaceVKImpeller::AndroidSurfaceVKImpeller( + const std::shared_ptr& android_context) { is_valid_ = android_context->IsValid(); auto& context_vk = @@ -28,17 +28,17 @@ AndroidSurfaceVulkanImpeller::AndroidSurfaceVulkanImpeller( std::make_unique(surface_context_vk_); } -AndroidSurfaceVulkanImpeller::~AndroidSurfaceVulkanImpeller() = default; +AndroidSurfaceVKImpeller::~AndroidSurfaceVKImpeller() = default; -bool AndroidSurfaceVulkanImpeller::IsValid() const { +bool AndroidSurfaceVKImpeller::IsValid() const { return is_valid_; } -void AndroidSurfaceVulkanImpeller::TeardownOnScreenContext() { +void AndroidSurfaceVKImpeller::TeardownOnScreenContext() { // Nothing to do. } -std::unique_ptr AndroidSurfaceVulkanImpeller::CreateGPUSurface( +std::unique_ptr AndroidSurfaceVKImpeller::CreateGPUSurface( GrDirectContext* gr_context) { if (!IsValid()) { return nullptr; @@ -66,21 +66,21 @@ std::unique_ptr AndroidSurfaceVulkanImpeller::CreateGPUSurface( return gpu_surface; } -bool AndroidSurfaceVulkanImpeller::OnScreenSurfaceResize(const SkISize& size) { +bool AndroidSurfaceVKImpeller::OnScreenSurfaceResize(const SkISize& size) { surface_context_vk_->UpdateSurfaceSize( impeller::ISize{size.width(), size.height()}); return true; } -bool AndroidSurfaceVulkanImpeller::ResourceContextMakeCurrent() { +bool AndroidSurfaceVKImpeller::ResourceContextMakeCurrent() { return true; } -bool AndroidSurfaceVulkanImpeller::ResourceContextClearCurrent() { +bool AndroidSurfaceVKImpeller::ResourceContextClearCurrent() { return true; } -bool AndroidSurfaceVulkanImpeller::SetNativeWindow( +bool AndroidSurfaceVKImpeller::SetNativeWindow( fml::RefPtr window) { if (window && (native_window_ == window)) { return OnScreenSurfaceResize(window->GetSize()); @@ -106,7 +106,7 @@ bool AndroidSurfaceVulkanImpeller::SetNativeWindow( } std::shared_ptr -AndroidSurfaceVulkanImpeller::GetImpellerContext() { +AndroidSurfaceVKImpeller::GetImpellerContext() { return surface_context_vk_; } diff --git a/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.h b/engine/src/flutter/shell/platform/android/android_surface_vk_impeller.h similarity index 73% rename from engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.h rename to engine/src/flutter/shell/platform/android/android_surface_vk_impeller.h index d348d51b47..01dde08440 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.h +++ b/engine/src/flutter/shell/platform/android/android_surface_vk_impeller.h @@ -2,25 +2,25 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_VULKAN_IMPELLER_H_ -#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_VULKAN_IMPELLER_H_ +#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_VK_IMPELLER_H_ +#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_VK_IMPELLER_H_ #include "flutter/fml/concurrent_message_loop.h" #include "flutter/fml/macros.h" #include "flutter/impeller/renderer/backend/vulkan/surface_context_vk.h" -#include "flutter/shell/platform/android/android_context_vulkan_impeller.h" +#include "flutter/shell/platform/android/android_context_vk_impeller.h" #include "flutter/shell/platform/android/surface/android_native_window.h" #include "flutter/shell/platform/android/surface/android_surface.h" #include "shell/gpu/gpu_surface_vulkan_impeller.h" namespace flutter { -class AndroidSurfaceVulkanImpeller : public AndroidSurface { +class AndroidSurfaceVKImpeller : public AndroidSurface { public: - explicit AndroidSurfaceVulkanImpeller( - const std::shared_ptr& android_context); + explicit AndroidSurfaceVKImpeller( + const std::shared_ptr& android_context); - ~AndroidSurfaceVulkanImpeller() override; + ~AndroidSurfaceVKImpeller() override; // |AndroidSurface| bool IsValid() const override; @@ -57,9 +57,9 @@ class AndroidSurfaceVulkanImpeller : public AndroidSurface { bool is_valid_ = false; - FML_DISALLOW_COPY_AND_ASSIGN(AndroidSurfaceVulkanImpeller); + FML_DISALLOW_COPY_AND_ASSIGN(AndroidSurfaceVKImpeller); }; } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_VULKAN_IMPELLER_H_ +#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_VK_IMPELLER_H_ diff --git a/engine/src/flutter/shell/platform/android/flutter_main.cc b/engine/src/flutter/shell/platform/android/flutter_main.cc index 0a2dfc6e0d..20bbd35bbf 100644 --- a/engine/src/flutter/shell/platform/android/flutter_main.cc +++ b/engine/src/flutter/shell/platform/android/flutter_main.cc @@ -23,7 +23,7 @@ #include "flutter/runtime/dart_vm.h" #include "flutter/shell/common/shell.h" #include "flutter/shell/common/switches.h" -#include "flutter/shell/platform/android/android_context_vulkan_impeller.h" +#include "flutter/shell/platform/android/android_context_vk_impeller.h" #include "flutter/shell/platform/android/flutter_main.h" #include "impeller/base/validation.h" #include "impeller/toolkit/android/proc_table.h" @@ -269,7 +269,7 @@ AndroidRenderingAPI FlutterMain::SelectedRenderingAPI( // Determine if Vulkan is supported by creating a Vulkan context and // checking if it is valid. impeller::ScopedValidationDisable disable_validation; - auto vulkan_backend = std::make_unique( + auto vulkan_backend = std::make_unique( /*enable_vulkan_validation=*/false, /*enable_vulkan_gpu_tracing=*/false, /*quiet=*/true); diff --git a/engine/src/flutter/shell/platform/android/image_external_texture.cc b/engine/src/flutter/shell/platform/android/image_external_texture.cc index 4c9735ccc0..909f7ae348 100644 --- a/engine/src/flutter/shell/platform/android/image_external_texture.cc +++ b/engine/src/flutter/shell/platform/android/image_external_texture.cc @@ -21,6 +21,8 @@ ImageExternalTexture::ImageExternalTexture( image_texture_entry_(image_texture_entry), jni_facade_(jni_facade) {} +ImageExternalTexture::~ImageExternalTexture() = default; + // Implementing flutter::Texture. void ImageExternalTexture::Paint(PaintContext& context, const SkRect& bounds, diff --git a/engine/src/flutter/shell/platform/android/image_external_texture.h b/engine/src/flutter/shell/platform/android/image_external_texture.h index 02ccdd9139..fbabbf6a4c 100644 --- a/engine/src/flutter/shell/platform/android/image_external_texture.h +++ b/engine/src/flutter/shell/platform/android/image_external_texture.h @@ -16,8 +16,23 @@ namespace flutter { -// External texture peered to a sequence of android.hardware.HardwareBuffers. -// +//------------------------------------------------------------------------------ +/// @brief External texture peered to a sequence of +/// android.hardware.HardwareBuffers. +/// +/// Android Hardware Buffers are available on newer versions of +/// Android (API 29 and above). +/// +/// This is an abstract base class and graphics packages provide +/// concrete implementations of this class that bind hardware +/// buffers to their own package-specific implementations of +/// textures (SkImages, impeller::Texture, etc...). +/// +/// Android Hardware Buffers allow binding to both OpenGL and Vulkan +/// client-rendering APIs in a zero copy manner. Because of this +/// graphics packages that support OpenGL and Vulkan can have +/// multiple subclasses for each supported client-rendering API. +/// class ImageExternalTexture : public flutter::Texture { public: explicit ImageExternalTexture( @@ -25,8 +40,48 @@ class ImageExternalTexture : public flutter::Texture { const fml::jni::ScopedJavaGlobalRef& image_texture_entry, const std::shared_ptr& jni_facade); - virtual ~ImageExternalTexture() = default; + // |flutter::Texture| + virtual ~ImageExternalTexture(); + protected: + //---------------------------------------------------------------------------- + /// @brief Subclasses override this method to bind the latest + /// representation of the hardware buffer wrapped by this texture + /// instance to their own graphics package specific texture + /// classes (SkImage, impeller::Texture, etc...). + /// + /// After a call to this method, attachment state of this instance + /// must be kAttached. That is the responsibility of the subclass. + /// + /// @param context The context + /// @param[in] bounds The bounds + /// + virtual void ProcessFrame(PaintContext& context, const SkRect& bounds) = 0; + + virtual void Attach(PaintContext& context) = 0; + + virtual void Detach() = 0; + + JavaLocalRef AcquireLatestImage(); + + void CloseImage(const fml::jni::JavaRef& image); + + JavaLocalRef HardwareBufferFor(const fml::jni::JavaRef& image); + + void CloseHardwareBuffer(const fml::jni::JavaRef& hardware_buffer); + + AHardwareBuffer* AHardwareBufferFor( + const fml::jni::JavaRef& hardware_buffer); + + fml::jni::ScopedJavaGlobalRef image_texture_entry_; + std::shared_ptr jni_facade_; + + enum class AttachmentState { kUninitialized, kAttached, kDetached }; + AttachmentState state_ = AttachmentState::kUninitialized; + sk_sp dl_image_; + ImageLRU image_lru_ = ImageLRU(); + + private: // |flutter::Texture|. void Paint(PaintContext& context, const SkRect& bounds, @@ -45,26 +100,6 @@ class ImageExternalTexture : public flutter::Texture { // |flutter::ContextListener| void OnGrContextDestroyed() override; - protected: - virtual void Attach(PaintContext& context) = 0; - virtual void Detach() = 0; - virtual void ProcessFrame(PaintContext& context, const SkRect& bounds) = 0; - - JavaLocalRef AcquireLatestImage(); - void CloseImage(const fml::jni::JavaRef& image); - JavaLocalRef HardwareBufferFor(const fml::jni::JavaRef& image); - void CloseHardwareBuffer(const fml::jni::JavaRef& hardware_buffer); - AHardwareBuffer* AHardwareBufferFor( - const fml::jni::JavaRef& hardware_buffer); - - fml::jni::ScopedJavaGlobalRef image_texture_entry_; - std::shared_ptr jni_facade_; - - enum class AttachmentState { kUninitialized, kAttached, kDetached }; - AttachmentState state_ = AttachmentState::kUninitialized; - sk_sp dl_image_; - ImageLRU image_lru_ = ImageLRU(); - FML_DISALLOW_COPY_AND_ASSIGN(ImageExternalTexture); }; diff --git a/engine/src/flutter/shell/platform/android/image_external_texture_gl.cc b/engine/src/flutter/shell/platform/android/image_external_texture_gl.cc index 88792d73d8..58ac4edd5a 100644 --- a/engine/src/flutter/shell/platform/android/image_external_texture_gl.cc +++ b/engine/src/flutter/shell/platform/android/image_external_texture_gl.cc @@ -111,103 +111,4 @@ impeller::UniqueEGLImageKHR ImageExternalTextureGL::CreateEGLImage( return impeller::UniqueEGLImageKHR(maybe_image); } -ImageExternalTextureGLSkia::ImageExternalTextureGLSkia( - const std::shared_ptr& context, - int64_t id, - const fml::jni::ScopedJavaGlobalRef& image_texture_entry, - const std::shared_ptr& jni_facade) - : ImageExternalTextureGL(id, image_texture_entry, jni_facade) {} - -void ImageExternalTextureGLSkia::Attach(PaintContext& context) { - if (state_ == AttachmentState::kUninitialized) { - // After this call state_ will be AttachmentState::kAttached and egl_image_ - // will have been created if we still have an Image associated with us. - ImageExternalTextureGL::Attach(context); - } -} - -void ImageExternalTextureGLSkia::Detach() { - ImageExternalTextureGL::Detach(); -} - -void ImageExternalTextureGLSkia::BindImageToTexture( - const impeller::UniqueEGLImageKHR& image, - GLuint tex) { - if (!image.is_valid() || tex == 0) { - return; - } - glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex); - glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, - (GLeglImageOES)image.get().image); -} - -sk_sp ImageExternalTextureGLSkia::CreateDlImage( - PaintContext& context, - const SkRect& bounds, - std::optional id, - impeller::UniqueEGLImageKHR&& egl_image) { - GLuint texture_name; - glGenTextures(1, &texture_name); - auto gl_texture = impeller::GLTexture{texture_name}; - impeller::UniqueGLTexture unique_texture; - unique_texture.reset(gl_texture); - - BindImageToTexture(egl_image, unique_texture.get().texture_name); - GrGLTextureInfo textureInfo = { - GL_TEXTURE_EXTERNAL_OES, unique_texture.get().texture_name, GL_RGBA8_OES}; - auto backendTexture = - GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo); - - gl_entries_[id.value_or(0)] = GlEntry{.egl_image = std::move(egl_image), - .texture = std::move(unique_texture)}; - return DlImage::Make(SkImages::BorrowTextureFrom( - context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin, - kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr)); -} - -ImageExternalTextureGLImpeller::ImageExternalTextureGLImpeller( - const std::shared_ptr& context, - int64_t id, - const fml::jni::ScopedJavaGlobalRef& image_textury_entry, - const std::shared_ptr& jni_facade) - : ImageExternalTextureGL(id, image_textury_entry, jni_facade), - impeller_context_(context) {} - -void ImageExternalTextureGLImpeller::Detach() {} - -void ImageExternalTextureGLImpeller::Attach(PaintContext& context) { - if (state_ == AttachmentState::kUninitialized) { - ImageExternalTextureGL::Attach(context); - } -} - -sk_sp ImageExternalTextureGLImpeller::CreateDlImage( - PaintContext& context, - const SkRect& bounds, - std::optional id, - impeller::UniqueEGLImageKHR&& egl_image) { - impeller::TextureDescriptor desc; - 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.mip_count = 1; - auto texture = std::make_shared( - impeller_context_->GetReactor(), desc, - impeller::TextureGLES::IsWrapped::kWrapped); - texture->SetCoordinateSystem( - impeller::TextureCoordinateSystem::kUploadFromHost); - if (!texture->Bind()) { - return nullptr; - } - // Associate the hardware buffer image with the texture. - glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, - (GLeglImageOES)egl_image.get().image); - gl_entries_[id.value_or(0)] = GlEntry{ - .egl_image = std::move(egl_image), - }; - return impeller::DlImageImpeller::Make(texture); -} - } // namespace flutter diff --git a/engine/src/flutter/shell/platform/android/image_external_texture_gl.h b/engine/src/flutter/shell/platform/android/image_external_texture_gl.h index 995592c778..9f923e816d 100644 --- a/engine/src/flutter/shell/platform/android/image_external_texture_gl.h +++ b/engine/src/flutter/shell/platform/android/image_external_texture_gl.h @@ -5,18 +5,13 @@ #ifndef FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_H_ #define FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_H_ +#include +#include #include -#include "flutter/fml/platform/android/scoped_java_ref.h" -#include "flutter/shell/platform/android/image_external_texture.h" - -#include "flutter/impeller/renderer/backend/gles/context_gles.h" -#include "flutter/impeller/renderer/backend/gles/gles.h" -#include "flutter/impeller/renderer/backend/gles/texture_gles.h" -#include "flutter/impeller/toolkit/egl/egl.h" #include "flutter/impeller/toolkit/egl/image.h" #include "flutter/impeller/toolkit/gles/texture.h" -#include "flutter/shell/platform/android/android_context_gl_skia.h" +#include "flutter/shell/platform/android/image_external_texture.h" namespace flutter { @@ -28,12 +23,14 @@ class ImageExternalTextureGL : public ImageExternalTexture { const std::shared_ptr& jni_facade); protected: + // |ImageExternalTexture| void Attach(PaintContext& context) override; + + // |ImageExternalTexture| void Detach() override; + + // |ImageExternalTexture| void ProcessFrame(PaintContext& context, const SkRect& bounds) override; - void UpdateImage(JavaLocalRef& hardware_buffer, - const SkRect& bounds, - PaintContext& context); virtual sk_sp CreateDlImage( PaintContext& context, @@ -41,6 +38,10 @@ class ImageExternalTextureGL : public ImageExternalTexture { std::optional id, impeller::UniqueEGLImageKHR&& egl_image) = 0; + void UpdateImage(JavaLocalRef& hardware_buffer, + const SkRect& bounds, + PaintContext& context); + impeller::UniqueEGLImageKHR CreateEGLImage(AHardwareBuffer* buffer); struct GlEntry { @@ -56,53 +57,6 @@ class ImageExternalTextureGL : public ImageExternalTexture { FML_DISALLOW_COPY_AND_ASSIGN(ImageExternalTextureGL); }; -class ImageExternalTextureGLSkia : public ImageExternalTextureGL { - public: - ImageExternalTextureGLSkia( - const std::shared_ptr& context, - int64_t id, - const fml::jni::ScopedJavaGlobalRef& image_textury_entry, - const std::shared_ptr& jni_facade); - - private: - void Attach(PaintContext& context) override; - void Detach() override; - - void BindImageToTexture(const impeller::UniqueEGLImageKHR& image, GLuint tex); - - sk_sp CreateDlImage( - PaintContext& context, - const SkRect& bounds, - std::optional id, - impeller::UniqueEGLImageKHR&& egl_image) override; - - FML_DISALLOW_COPY_AND_ASSIGN(ImageExternalTextureGLSkia); -}; - -class ImageExternalTextureGLImpeller : public ImageExternalTextureGL { - public: - ImageExternalTextureGLImpeller( - const std::shared_ptr& context, - int64_t id, - const fml::jni::ScopedJavaGlobalRef& - hardware_buffer_texture_entry, - const std::shared_ptr& jni_facade); - - private: - void Attach(PaintContext& context) override; - void Detach() override; - - sk_sp CreateDlImage( - PaintContext& context, - const SkRect& bounds, - std::optional id, - impeller::UniqueEGLImageKHR&& egl_image) override; - - const std::shared_ptr impeller_context_; - - FML_DISALLOW_COPY_AND_ASSIGN(ImageExternalTextureGLImpeller); -}; - } // namespace flutter #endif // FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_H_ diff --git a/engine/src/flutter/shell/platform/android/image_external_texture_gl_impeller.cc b/engine/src/flutter/shell/platform/android/image_external_texture_gl_impeller.cc new file mode 100644 index 0000000000..f14fea8882 --- /dev/null +++ b/engine/src/flutter/shell/platform/android/image_external_texture_gl_impeller.cc @@ -0,0 +1,57 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/android/image_external_texture_gl_impeller.h" + +#include "flutter/impeller/display_list/dl_image_impeller.h" +#include "flutter/impeller/renderer/backend/gles/texture_gles.h" + +namespace flutter { + +ImageExternalTextureGLImpeller::ImageExternalTextureGLImpeller( + const std::shared_ptr& context, + int64_t id, + const fml::jni::ScopedJavaGlobalRef& image_textury_entry, + const std::shared_ptr& jni_facade) + : ImageExternalTextureGL(id, image_textury_entry, jni_facade), + impeller_context_(context) {} + +void ImageExternalTextureGLImpeller::Detach() {} + +void ImageExternalTextureGLImpeller::Attach(PaintContext& context) { + if (state_ == AttachmentState::kUninitialized) { + ImageExternalTextureGL::Attach(context); + } +} + +sk_sp ImageExternalTextureGLImpeller::CreateDlImage( + PaintContext& context, + const SkRect& bounds, + std::optional id, + impeller::UniqueEGLImageKHR&& egl_image) { + impeller::TextureDescriptor desc; + 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.mip_count = 1; + auto texture = std::make_shared( + impeller_context_->GetReactor(), desc, + impeller::TextureGLES::IsWrapped::kWrapped); + texture->SetCoordinateSystem( + impeller::TextureCoordinateSystem::kUploadFromHost); + if (!texture->Bind()) { + return nullptr; + } + // Associate the hardware buffer image with the texture. + glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, + (GLeglImageOES)egl_image.get().image); + gl_entries_[id.value_or(0)] = GlEntry{ + .egl_image = std::move(egl_image), + }; + return impeller::DlImageImpeller::Make(texture); +} + +} // namespace flutter diff --git a/engine/src/flutter/shell/platform/android/image_external_texture_gl_impeller.h b/engine/src/flutter/shell/platform/android/image_external_texture_gl_impeller.h new file mode 100644 index 0000000000..05771e0f34 --- /dev/null +++ b/engine/src/flutter/shell/platform/android/image_external_texture_gl_impeller.h @@ -0,0 +1,48 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_IMPELLER_H_ +#define FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_IMPELLER_H_ + +#include +#include + +#include "flutter/fml/macros.h" +#include "flutter/impeller/renderer/backend/gles/context_gles.h" +#include "flutter/shell/platform/android/image_external_texture_gl.h" +#include "flutter/shell/platform/android/jni/platform_view_android_jni.h" + +namespace flutter { + +class ImageExternalTextureGLImpeller : public ImageExternalTextureGL { + public: + ImageExternalTextureGLImpeller( + const std::shared_ptr& context, + int64_t id, + const fml::jni::ScopedJavaGlobalRef& + hardware_buffer_texture_entry, + const std::shared_ptr& jni_facade); + + private: + // |ImageExternalTexture| + void Attach(PaintContext& context) override; + + // |ImageExternalTexture| + void Detach() override; + + // |ImageExternalTextureGL| + sk_sp CreateDlImage( + PaintContext& context, + const SkRect& bounds, + std::optional id, + impeller::UniqueEGLImageKHR&& egl_image) override; + + const std::shared_ptr impeller_context_; + + FML_DISALLOW_COPY_AND_ASSIGN(ImageExternalTextureGLImpeller); +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_IMPELLER_H_ diff --git a/engine/src/flutter/shell/platform/android/image_external_texture_gl_skia.cc b/engine/src/flutter/shell/platform/android/image_external_texture_gl_skia.cc new file mode 100644 index 0000000000..3d9d6adb34 --- /dev/null +++ b/engine/src/flutter/shell/platform/android/image_external_texture_gl_skia.cc @@ -0,0 +1,66 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/android/image_external_texture_gl_skia.h" + +#include "flutter/third_party/skia/include/gpu/ganesh/SkImageGanesh.h" +#include "flutter/third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h" + +namespace flutter { + +ImageExternalTextureGLSkia::ImageExternalTextureGLSkia( + const std::shared_ptr& context, + int64_t id, + const fml::jni::ScopedJavaGlobalRef& image_texture_entry, + const std::shared_ptr& jni_facade) + : ImageExternalTextureGL(id, image_texture_entry, jni_facade) {} + +void ImageExternalTextureGLSkia::Attach(PaintContext& context) { + if (state_ == AttachmentState::kUninitialized) { + // After this call state_ will be AttachmentState::kAttached and egl_image_ + // will have been created if we still have an Image associated with us. + ImageExternalTextureGL::Attach(context); + } +} + +void ImageExternalTextureGLSkia::Detach() { + ImageExternalTextureGL::Detach(); +} + +void ImageExternalTextureGLSkia::BindImageToTexture( + const impeller::UniqueEGLImageKHR& image, + GLuint tex) { + if (!image.is_valid() || tex == 0) { + return; + } + glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex); + glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, + (GLeglImageOES)image.get().image); +} + +sk_sp ImageExternalTextureGLSkia::CreateDlImage( + PaintContext& context, + const SkRect& bounds, + std::optional id, + impeller::UniqueEGLImageKHR&& egl_image) { + GLuint texture_name; + glGenTextures(1, &texture_name); + auto gl_texture = impeller::GLTexture{texture_name}; + impeller::UniqueGLTexture unique_texture; + unique_texture.reset(gl_texture); + + BindImageToTexture(egl_image, unique_texture.get().texture_name); + GrGLTextureInfo textureInfo = { + GL_TEXTURE_EXTERNAL_OES, unique_texture.get().texture_name, GL_RGBA8_OES}; + auto backendTexture = + GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo); + + gl_entries_[id.value_or(0)] = GlEntry{.egl_image = std::move(egl_image), + .texture = std::move(unique_texture)}; + return DlImage::Make(SkImages::BorrowTextureFrom( + context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin, + kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr)); +} + +} // namespace flutter diff --git a/engine/src/flutter/shell/platform/android/image_external_texture_gl_skia.h b/engine/src/flutter/shell/platform/android/image_external_texture_gl_skia.h new file mode 100644 index 0000000000..df181f2add --- /dev/null +++ b/engine/src/flutter/shell/platform/android/image_external_texture_gl_skia.h @@ -0,0 +1,45 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_SKIA_H_ +#define FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_SKIA_H_ + +#include +#include + +#include "flutter/shell/platform/android/android_context_gl_skia.h" +#include "flutter/shell/platform/android/image_external_texture_gl.h" + +namespace flutter { + +class ImageExternalTextureGLSkia : public ImageExternalTextureGL { + public: + ImageExternalTextureGLSkia( + const std::shared_ptr& context, + int64_t id, + const fml::jni::ScopedJavaGlobalRef& image_textury_entry, + const std::shared_ptr& jni_facade); + + private: + // |ImageExternalTexture| + void Attach(PaintContext& context) override; + + // |ImageExternalTexture| + void Detach() override; + + // |ImageExternalTextureGL| + sk_sp CreateDlImage( + PaintContext& context, + const SkRect& bounds, + std::optional id, + impeller::UniqueEGLImageKHR&& egl_image) override; + + void BindImageToTexture(const impeller::UniqueEGLImageKHR& image, GLuint tex); + + FML_DISALLOW_COPY_AND_ASSIGN(ImageExternalTextureGLSkia); +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_SKIA_H_ diff --git a/engine/src/flutter/shell/platform/android/image_external_texture_vk.cc b/engine/src/flutter/shell/platform/android/image_external_texture_vk_impeller.cc similarity index 89% rename from engine/src/flutter/shell/platform/android/image_external_texture_vk.cc rename to engine/src/flutter/shell/platform/android/image_external_texture_vk_impeller.cc index 88574548d6..aefeb7eb00 100644 --- a/engine/src/flutter/shell/platform/android/image_external_texture_vk.cc +++ b/engine/src/flutter/shell/platform/android/image_external_texture_vk_impeller.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/shell/platform/android/image_external_texture_vk.h" +#include "flutter/shell/platform/android/image_external_texture_vk_impeller.h" #include @@ -17,7 +17,7 @@ namespace flutter { -ImageExternalTextureVK::ImageExternalTextureVK( +ImageExternalTextureVKImpeller::ImageExternalTextureVKImpeller( const std::shared_ptr& impeller_context, int64_t id, const fml::jni::ScopedJavaGlobalRef& image_texture_entry, @@ -25,19 +25,19 @@ ImageExternalTextureVK::ImageExternalTextureVK( : ImageExternalTexture(id, image_texture_entry, jni_facade), impeller_context_(impeller_context) {} -ImageExternalTextureVK::~ImageExternalTextureVK() {} +ImageExternalTextureVKImpeller::~ImageExternalTextureVKImpeller() {} -void ImageExternalTextureVK::Attach(PaintContext& context) { +void ImageExternalTextureVKImpeller::Attach(PaintContext& context) { if (state_ == AttachmentState::kUninitialized) { // First processed frame we are attached. state_ = AttachmentState::kAttached; } } -void ImageExternalTextureVK::Detach() {} +void ImageExternalTextureVKImpeller::Detach() {} -void ImageExternalTextureVK::ProcessFrame(PaintContext& context, - const SkRect& bounds) { +void ImageExternalTextureVKImpeller::ProcessFrame(PaintContext& context, + const SkRect& bounds) { JavaLocalRef image = AcquireLatestImage(); if (image.is_null()) { return; diff --git a/engine/src/flutter/shell/platform/android/image_external_texture_vk.h b/engine/src/flutter/shell/platform/android/image_external_texture_vk_impeller.h similarity index 82% rename from engine/src/flutter/shell/platform/android/image_external_texture_vk.h rename to engine/src/flutter/shell/platform/android/image_external_texture_vk_impeller.h index e702671fe8..70f5320689 100644 --- a/engine/src/flutter/shell/platform/android/image_external_texture_vk.h +++ b/engine/src/flutter/shell/platform/android/image_external_texture_vk_impeller.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_VK_H_ -#define FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_VK_H_ +#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_VK_IMPELLER_H_ +#define FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_VK_IMPELLER_H_ #include #include @@ -12,20 +12,20 @@ #include "flutter/impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.h" #include "flutter/impeller/renderer/backend/vulkan/context_vk.h" #include "flutter/impeller/renderer/backend/vulkan/vk.h" -#include "flutter/shell/platform/android/android_context_vulkan_impeller.h" +#include "flutter/shell/platform/android/android_context_vk_impeller.h" namespace flutter { -class ImageExternalTextureVK : public ImageExternalTexture { +class ImageExternalTextureVKImpeller : public ImageExternalTexture { public: - ImageExternalTextureVK( + ImageExternalTextureVKImpeller( const std::shared_ptr& impeller_context, int64_t id, const fml::jni::ScopedJavaGlobalRef& hardware_buffer_texture_entry, const std::shared_ptr& jni_facade); - ~ImageExternalTextureVK() override; + ~ImageExternalTextureVKImpeller() override; private: void Attach(PaintContext& context) override; @@ -37,4 +37,4 @@ class ImageExternalTextureVK : public ImageExternalTexture { } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_VK_H_ +#endif // FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_VK_IMPELLER_H_ diff --git a/engine/src/flutter/shell/platform/android/platform_view_android.cc b/engine/src/flutter/shell/platform/android/platform_view_android.cc index b16179dde2..704f69978c 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android.cc @@ -14,16 +14,18 @@ #include "flutter/shell/gpu/gpu_surface_gl_delegate.h" #include "flutter/shell/platform/android/android_context_gl_impeller.h" #include "flutter/shell/platform/android/android_context_gl_skia.h" -#include "flutter/shell/platform/android/android_context_vulkan_impeller.h" +#include "flutter/shell/platform/android/android_context_vk_impeller.h" #include "flutter/shell/platform/android/android_surface_gl_impeller.h" #include "flutter/shell/platform/android/android_surface_gl_skia.h" #include "flutter/shell/platform/android/android_surface_software.h" -#include "flutter/shell/platform/android/image_external_texture_gl.h" -#include "flutter/shell/platform/android/surface_texture_external_texture_gl.h" +#include "flutter/shell/platform/android/image_external_texture_gl_impeller.h" +#include "flutter/shell/platform/android/image_external_texture_gl_skia.h" +#include "flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.h" +#include "flutter/shell/platform/android/surface_texture_external_texture_gl_skia.h" #include "fml/logging.h" #if IMPELLER_ENABLE_VULKAN // b/258506856 for why this is behind an if -#include "flutter/shell/platform/android/android_surface_vulkan_impeller.h" -#include "flutter/shell/platform/android/image_external_texture_vk.h" +#include "flutter/shell/platform/android/android_surface_vk_impeller.h" +#include "flutter/shell/platform/android/image_external_texture_vk_impeller.h" #endif #include "flutter/shell/platform/android/context/android_context.h" #include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h" @@ -53,9 +55,8 @@ std::unique_ptr AndroidSurfaceFactoryImpl::CreateSurface() { return std::make_unique( std::static_pointer_cast(android_context_)); case AndroidRenderingAPI::kImpellerVulkan: - return std::make_unique( - std::static_pointer_cast( - android_context_)); + return std::make_unique( + std::static_pointer_cast(android_context_)); } FML_UNREACHABLE(); } @@ -75,7 +76,7 @@ static std::shared_ptr CreateAndroidContext( std::make_unique(), enable_opengl_gpu_tracing); case AndroidRenderingAPI::kImpellerVulkan: - return std::make_unique( + return std::make_unique( enable_vulkan_validation, enable_vulkan_gpu_tracing); case AndroidRenderingAPI::kSkiaOpenGLES: return std::make_unique( @@ -276,14 +277,14 @@ void PlatformViewAndroid::RegisterExternalTexture( switch (android_context_->RenderingApi()) { case AndroidRenderingAPI::kImpellerOpenGLES: // Impeller GLES. - RegisterTexture(std::make_shared( + RegisterTexture(std::make_shared( std::static_pointer_cast( android_context_->GetImpellerContext()), texture_id, surface_texture, jni_facade_)); break; case AndroidRenderingAPI::kSkiaOpenGLES: // Legacy GL. - RegisterTexture(std::make_shared( + RegisterTexture(std::make_shared( texture_id, surface_texture, jni_facade_)); break; case AndroidRenderingAPI::kSoftware: @@ -316,7 +317,7 @@ void PlatformViewAndroid::RegisterImageTexture( texture_id, image_texture_entry, jni_facade_)); break; case AndroidRenderingAPI::kImpellerVulkan: - RegisterTexture(std::make_shared( + RegisterTexture(std::make_shared( std::static_pointer_cast( android_context_->GetImpellerContext()), texture_id, image_texture_entry, jni_facade_)); diff --git a/engine/src/flutter/shell/platform/android/platform_view_android_jni_impl.cc b/engine/src/flutter/shell/platform/android/platform_view_android_jni_impl.cc index 0b4ed2ca1f..978a56e24e 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android_jni_impl.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android_jni_impl.cc @@ -33,7 +33,6 @@ #include "flutter/shell/platform/android/image_external_texture_gl.h" #include "flutter/shell/platform/android/jni/platform_view_android_jni.h" #include "flutter/shell/platform/android/platform_view_android.h" -#include "flutter/shell/platform/android/surface_texture_external_texture_gl.h" #define ANDROID_SHELL_HOLDER \ (reinterpret_cast(shell_holder)) diff --git a/engine/src/flutter/shell/platform/android/surface_texture_external_texture.h b/engine/src/flutter/shell/platform/android/surface_texture_external_texture.h index e3400a1a64..289d13a054 100644 --- a/engine/src/flutter/shell/platform/android/surface_texture_external_texture.h +++ b/engine/src/flutter/shell/platform/android/surface_texture_external_texture.h @@ -12,7 +12,23 @@ namespace flutter { -// External texture peered to an android.graphics.SurfaceTexture. +//------------------------------------------------------------------------------ +/// @brief Instances of external textures peered to +/// `android.graphics.SurfaceTexture`. +/// +/// SurfaceTextures are used on older versions of Android (API < +/// 29). On newer versions, the Android Hardware Buffer backend +/// `flutter::ImageExternalTexture` instances are used instead. +/// +/// Due to the way surface textures are designed, it is not possible +/// to have a Vulkan renderer interoperate with such textures. +/// Consequently, both Skia and Impeller only have OpenGL +/// implementations for these kinds of textures. +/// +/// This is an abstract base class. Minimally, subclasses override +/// the pure virtual `ProcessFrame` method to bind the package +/// specific texture implementation to the surface texture. +/// class SurfaceTextureExternalTexture : public flutter::Texture { public: SurfaceTextureExternalTexture( @@ -20,29 +36,45 @@ class SurfaceTextureExternalTexture : public flutter::Texture { const fml::jni::ScopedJavaGlobalRef& surface_texture, const std::shared_ptr& jni_facade); + // |Texture| ~SurfaceTextureExternalTexture() override; - void Paint(PaintContext& context, - const SkRect& bounds, - bool freeze, - const DlImageSampling sampling) override; - - void OnGrContextCreated() override; - - void OnGrContextDestroyed() override; - - void MarkNewFrameAvailable() override; - - void OnTextureUnregistered() override; - protected: + //---------------------------------------------------------------------------- + /// @brief Subclasses override this method to bind the OpenGL texture + /// resource represented by this surface texture to the package + /// specific texture (SkImage, impeller::Texture, etc...). + /// + /// @important The state of texture should be AttachmentState::kAttached + /// after a call to this method. That is the responsibility of the + /// subclass. + /// + /// @param context The context. + /// @param[in] bounds The bounds of the texture. + /// virtual void ProcessFrame(PaintContext& context, const SkRect& bounds) = 0; + + //---------------------------------------------------------------------------- + /// @brief Provides an opportunity for the subclasses to sever the + /// connection between the OpenGL texture resource represented by + /// this surface texture and the underlying package handle + /// (SkImage, impeller::Texture, etc...). + /// virtual void Detach(); void Attach(int gl_tex_id); + bool ShouldUpdate(); + + //---------------------------------------------------------------------------- + /// @brief Update the surface texture contents and transformation matrix. + /// void Update(); + //---------------------------------------------------------------------------- + /// @brief Specifies how this instance is bound to the underlying surface + /// texture. + /// enum class AttachmentState { kUninitialized, kAttached, kDetached }; std::shared_ptr jni_facade_; @@ -51,6 +83,25 @@ class SurfaceTextureExternalTexture : public flutter::Texture { SkMatrix transform_; sk_sp dl_image_; + private: + // |Texture| + void Paint(PaintContext& context, + const SkRect& bounds, + bool freeze, + const DlImageSampling sampling) override; + + // |ContextListener| + void OnGrContextCreated() override; + + // |ContextListener| + void OnGrContextDestroyed() override; + + // |Texture| + void MarkNewFrameAvailable() override; + + // |Texture| + void OnTextureUnregistered() override; + FML_DISALLOW_COPY_AND_ASSIGN(SurfaceTextureExternalTexture); }; diff --git a/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl.cc b/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl.cc deleted file mode 100644 index b1cadee7f3..0000000000 --- a/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl.cc +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/shell/platform/android/surface_texture_external_texture_gl.h" - -#include - -#include "flutter/display_list/effects/dl_color_source.h" -#include "impeller/display_list/dl_image_impeller.h" -#include "shell/platform/android/surface_texture_external_texture.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/GrBackendSurface.h" -#include "third_party/skia/include/gpu/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/gl/GrGLTypes.h" - -namespace flutter { - -SurfaceTextureExternalTextureGL::SurfaceTextureExternalTextureGL( - int64_t id, - const fml::jni::ScopedJavaGlobalRef& surface_texture, - const std::shared_ptr& jni_facade) - : SurfaceTextureExternalTexture(id, surface_texture, jni_facade) {} - -SurfaceTextureExternalTextureGL::~SurfaceTextureExternalTextureGL() { - if (texture_name_ != 0) { - glDeleteTextures(1, &texture_name_); - } -} - -void SurfaceTextureExternalTextureGL::ProcessFrame(PaintContext& context, - const SkRect& bounds) { - if (state_ == AttachmentState::kUninitialized) { - // Generate the texture handle. - glGenTextures(1, &texture_name_); - Attach(texture_name_); - } - FML_CHECK(state_ == AttachmentState::kAttached); - - // Updates the texture contents and transformation matrix. - Update(); - - // Create a - GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_, - GL_RGBA8_OES}; - auto backendTexture = - GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo); - dl_image_ = DlImage::Make(SkImages::BorrowTextureFrom( - context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin, - kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr)); -} - -void SurfaceTextureExternalTextureGL::Detach() { - SurfaceTextureExternalTexture::Detach(); - if (texture_name_ != 0) { - glDeleteTextures(1, &texture_name_); - texture_name_ = 0; - } -} - -SurfaceTextureExternalTextureImpellerGL:: - SurfaceTextureExternalTextureImpellerGL( - const std::shared_ptr& context, - int64_t id, - const fml::jni::ScopedJavaGlobalRef& surface_texture, - const std::shared_ptr& jni_facade) - : SurfaceTextureExternalTexture(id, surface_texture, jni_facade), - impeller_context_(context) {} - -SurfaceTextureExternalTextureImpellerGL:: - ~SurfaceTextureExternalTextureImpellerGL() {} - -void SurfaceTextureExternalTextureImpellerGL::ProcessFrame( - PaintContext& context, - const SkRect& bounds) { - if (state_ == AttachmentState::kUninitialized) { - // Generate the texture handle. - impeller::TextureDescriptor desc; - 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.mip_count = 1; - texture_ = std::make_shared( - impeller_context_->GetReactor(), desc, - impeller::TextureGLES::IsWrapped::kWrapped); - texture_->SetCoordinateSystem( - impeller::TextureCoordinateSystem::kUploadFromHost); - auto maybe_handle = texture_->GetGLHandle(); - if (!maybe_handle.has_value()) { - FML_LOG(ERROR) << "Could not get GL handle from impeller::TextureGLES!"; - return; - } - Attach(maybe_handle.value()); - } - FML_CHECK(state_ == AttachmentState::kAttached); - - // Updates the texture contents and transformation matrix. - Update(); - - dl_image_ = impeller::DlImageImpeller::Make(texture_); -} - -void SurfaceTextureExternalTextureImpellerGL::Detach() { - SurfaceTextureExternalTexture::Detach(); - texture_.reset(); -} - -} // namespace flutter diff --git a/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.cc b/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.cc new file mode 100644 index 0000000000..227610a524 --- /dev/null +++ b/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.cc @@ -0,0 +1,60 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.h" + +#include "flutter/impeller/display_list/dl_image_impeller.h" + +namespace flutter { + +SurfaceTextureExternalTextureGLImpeller:: + SurfaceTextureExternalTextureGLImpeller( + const std::shared_ptr& context, + int64_t id, + const fml::jni::ScopedJavaGlobalRef& surface_texture, + const std::shared_ptr& jni_facade) + : SurfaceTextureExternalTexture(id, surface_texture, jni_facade), + impeller_context_(context) {} + +SurfaceTextureExternalTextureGLImpeller:: + ~SurfaceTextureExternalTextureGLImpeller() = default; + +void SurfaceTextureExternalTextureGLImpeller::ProcessFrame( + PaintContext& context, + const SkRect& bounds) { + if (state_ == AttachmentState::kUninitialized) { + // Generate the texture handle. + impeller::TextureDescriptor desc; + 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.mip_count = 1; + texture_ = std::make_shared( + impeller_context_->GetReactor(), desc, + impeller::TextureGLES::IsWrapped::kWrapped); + texture_->SetCoordinateSystem( + impeller::TextureCoordinateSystem::kUploadFromHost); + auto maybe_handle = texture_->GetGLHandle(); + if (!maybe_handle.has_value()) { + FML_LOG(ERROR) << "Could not get GL handle from impeller::TextureGLES!"; + return; + } + Attach(maybe_handle.value()); + } + FML_CHECK(state_ == AttachmentState::kAttached); + + // Updates the texture contents and transformation matrix. + Update(); + + dl_image_ = impeller::DlImageImpeller::Make(texture_); +} + +void SurfaceTextureExternalTextureGLImpeller::Detach() { + SurfaceTextureExternalTexture::Detach(); + texture_.reset(); +} + +} // namespace flutter diff --git a/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl.h b/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.h similarity index 51% rename from engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl.h rename to engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.h index bbe50655a1..bd291f827f 100644 --- a/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl.h +++ b/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_impeller.h @@ -2,63 +2,47 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_GL_H_ -#define FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_GL_H_ +#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_GL_IMPELLER_H_ +#define FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_GL_IMPELLER_H_ -#include "flutter/shell/platform/android/surface_texture_external_texture.h" +#include +#include "flutter/fml/macros.h" #include "flutter/impeller/renderer/backend/gles/context_gles.h" -#include "flutter/impeller/renderer/backend/gles/gles.h" #include "flutter/impeller/renderer/backend/gles/texture_gles.h" -#include "flutter/impeller/toolkit/egl/egl.h" -#include "flutter/impeller/toolkit/egl/image.h" -#include "flutter/impeller/toolkit/gles/texture.h" - -#include "flutter/impeller/renderer/backend/gles/context_gles.h" +#include "flutter/shell/platform/android/surface_texture_external_texture.h" namespace flutter { -class SurfaceTextureExternalTextureGL : public SurfaceTextureExternalTexture { - public: - SurfaceTextureExternalTextureGL( - int64_t id, - const fml::jni::ScopedJavaGlobalRef& surface_texture, - const std::shared_ptr& jni_facade); - - ~SurfaceTextureExternalTextureGL() override; - - private: - virtual void ProcessFrame(PaintContext& context, - const SkRect& bounds) override; - virtual void Detach() override; - - GLuint texture_name_ = 0; - - FML_DISALLOW_COPY_AND_ASSIGN(SurfaceTextureExternalTextureGL); -}; - -class SurfaceTextureExternalTextureImpellerGL +//------------------------------------------------------------------------------ +/// @brief Binds the surface texture to an Impeller texture. +/// +class SurfaceTextureExternalTextureGLImpeller : public SurfaceTextureExternalTexture { public: - SurfaceTextureExternalTextureImpellerGL( + SurfaceTextureExternalTextureGLImpeller( const std::shared_ptr& context, int64_t id, const fml::jni::ScopedJavaGlobalRef& surface_texture, const std::shared_ptr& jni_facade); - ~SurfaceTextureExternalTextureImpellerGL() override; + // |SurfaceTextureExternalTexture| + ~SurfaceTextureExternalTextureGLImpeller() override; private: + // |SurfaceTextureExternalTexture| virtual void ProcessFrame(PaintContext& context, const SkRect& bounds) override; + + // |SurfaceTextureExternalTexture| virtual void Detach() override; const std::shared_ptr impeller_context_; std::shared_ptr texture_; - FML_DISALLOW_COPY_AND_ASSIGN(SurfaceTextureExternalTextureImpellerGL); + FML_DISALLOW_COPY_AND_ASSIGN(SurfaceTextureExternalTextureGLImpeller); }; } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_GL_H_ +#endif // FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_GL_IMPELLER_H_ diff --git a/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_skia.cc b/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_skia.cc new file mode 100644 index 0000000000..307217271f --- /dev/null +++ b/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_skia.cc @@ -0,0 +1,60 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/android/surface_texture_external_texture_gl_skia.h" + +#include +#define GL_GLEXT_PROTOTYPES +#include + +#include "flutter/third_party/skia/include/gpu/GrBackendSurface.h" +#include "flutter/third_party/skia/include/gpu/GrDirectContext.h" +#include "flutter/third_party/skia/include/gpu/ganesh/SkImageGanesh.h" +#include "flutter/third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h" +#include "flutter/third_party/skia/include/gpu/gl/GrGLTypes.h" + +namespace flutter { + +SurfaceTextureExternalTextureGLSkia::SurfaceTextureExternalTextureGLSkia( + int64_t id, + const fml::jni::ScopedJavaGlobalRef& surface_texture, + const std::shared_ptr& jni_facade) + : SurfaceTextureExternalTexture(id, surface_texture, jni_facade) {} + +SurfaceTextureExternalTextureGLSkia::~SurfaceTextureExternalTextureGLSkia() { + if (texture_name_ != 0) { + glDeleteTextures(1, &texture_name_); + } +} + +void SurfaceTextureExternalTextureGLSkia::ProcessFrame(PaintContext& context, + const SkRect& bounds) { + if (state_ == AttachmentState::kUninitialized) { + // Generate the texture handle. + glGenTextures(1, &texture_name_); + Attach(texture_name_); + } + FML_CHECK(state_ == AttachmentState::kAttached); + + // Updates the texture contents and transformation matrix. + Update(); + + GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_, + GL_RGBA8_OES}; + auto backendTexture = + GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo); + dl_image_ = DlImage::Make(SkImages::BorrowTextureFrom( + context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin, + kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr)); +} + +void SurfaceTextureExternalTextureGLSkia::Detach() { + SurfaceTextureExternalTexture::Detach(); + if (texture_name_ != 0) { + glDeleteTextures(1, &texture_name_); + texture_name_ = 0; + } +} + +} // namespace flutter diff --git a/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_skia.h b/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_skia.h new file mode 100644 index 0000000000..75ddfe637c --- /dev/null +++ b/engine/src/flutter/shell/platform/android/surface_texture_external_texture_gl_skia.h @@ -0,0 +1,43 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_GL_SKIA_H_ +#define FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_GL_SKIA_H_ + +#include + +#include "flutter/shell/platform/android/surface_texture_external_texture.h" + +namespace flutter { + +//------------------------------------------------------------------------------ +/// @brief Binds the surface texture to a Skia SkImage. +/// +class SurfaceTextureExternalTextureGLSkia + : public SurfaceTextureExternalTexture { + public: + SurfaceTextureExternalTextureGLSkia( + int64_t id, + const fml::jni::ScopedJavaGlobalRef& surface_texture, + const std::shared_ptr& jni_facade); + + // |SurfaceTextureExternalTexture| + ~SurfaceTextureExternalTextureGLSkia() override; + + private: + // |SurfaceTextureExternalTexture| + virtual void ProcessFrame(PaintContext& context, + const SkRect& bounds) override; + + // |SurfaceTextureExternalTexture| + virtual void Detach() override; + + GLuint texture_name_ = 0; + + FML_DISALLOW_COPY_AND_ASSIGN(SurfaceTextureExternalTextureGLSkia); +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_ANDROID_SURFACE_TEXTURE_EXTERNAL_TEXTURE_GL_SKIA_H_