[Impeller] Refactor and document Android rendering related TUs. (flutter/engine#53802)

No change in functionality. The updates:

* HeaderDoc comments have been added to the major rendering related TUs. However, not all comments are complete. I only documented the stuff I understood. For instance, it isn't clear how/why some subclasses use Attach/Detach while other use ProcessFrame. I intend to document as I go.
* Each package specific subclass is now in its own TU.
* Some subclasses used to be Skia specific. We added an Impeller variant but didn't rename to Skia TU. This has been patched.
This commit is contained in:
Chinmay Garde
2024-07-12 12:08:15 -07:00
committed by GitHub
parent 93de0249f9
commit 8837250654
25 changed files with 640 additions and 432 deletions

View File

@@ -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

View File

@@ -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",
]

View File

@@ -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<impeller::Context> 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_;
}

View File

@@ -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<fml::NativeLibrary> 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_

View File

@@ -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 <memory>
#include <utility>
@@ -17,8 +17,8 @@
namespace flutter {
AndroidSurfaceVulkanImpeller::AndroidSurfaceVulkanImpeller(
const std::shared_ptr<AndroidContextVulkanImpeller>& android_context) {
AndroidSurfaceVKImpeller::AndroidSurfaceVKImpeller(
const std::shared_ptr<AndroidContextVKImpeller>& android_context) {
is_valid_ = android_context->IsValid();
auto& context_vk =
@@ -28,17 +28,17 @@ AndroidSurfaceVulkanImpeller::AndroidSurfaceVulkanImpeller(
std::make_unique<GPUSurfaceVulkanImpeller>(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<Surface> AndroidSurfaceVulkanImpeller::CreateGPUSurface(
std::unique_ptr<Surface> AndroidSurfaceVKImpeller::CreateGPUSurface(
GrDirectContext* gr_context) {
if (!IsValid()) {
return nullptr;
@@ -66,21 +66,21 @@ std::unique_ptr<Surface> 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<AndroidNativeWindow> window) {
if (window && (native_window_ == window)) {
return OnScreenSurfaceResize(window->GetSize());
@@ -106,7 +106,7 @@ bool AndroidSurfaceVulkanImpeller::SetNativeWindow(
}
std::shared_ptr<impeller::Context>
AndroidSurfaceVulkanImpeller::GetImpellerContext() {
AndroidSurfaceVKImpeller::GetImpellerContext() {
return surface_context_vk_;
}

View File

@@ -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<AndroidContextVulkanImpeller>& android_context);
explicit AndroidSurfaceVKImpeller(
const std::shared_ptr<AndroidContextVKImpeller>& 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_

View File

@@ -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<AndroidContextVulkanImpeller>(
auto vulkan_backend = std::make_unique<AndroidContextVKImpeller>(
/*enable_vulkan_validation=*/false,
/*enable_vulkan_gpu_tracing=*/false,
/*quiet=*/true);

View File

@@ -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,

View File

@@ -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<jobject>& image_texture_entry,
const std::shared_ptr<PlatformViewAndroidJNI>& 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<jobject>& image);
JavaLocalRef HardwareBufferFor(const fml::jni::JavaRef<jobject>& image);
void CloseHardwareBuffer(const fml::jni::JavaRef<jobject>& hardware_buffer);
AHardwareBuffer* AHardwareBufferFor(
const fml::jni::JavaRef<jobject>& hardware_buffer);
fml::jni::ScopedJavaGlobalRef<jobject> image_texture_entry_;
std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
enum class AttachmentState { kUninitialized, kAttached, kDetached };
AttachmentState state_ = AttachmentState::kUninitialized;
sk_sp<flutter::DlImage> 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<jobject>& image);
JavaLocalRef HardwareBufferFor(const fml::jni::JavaRef<jobject>& image);
void CloseHardwareBuffer(const fml::jni::JavaRef<jobject>& hardware_buffer);
AHardwareBuffer* AHardwareBufferFor(
const fml::jni::JavaRef<jobject>& hardware_buffer);
fml::jni::ScopedJavaGlobalRef<jobject> image_texture_entry_;
std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
enum class AttachmentState { kUninitialized, kAttached, kDetached };
AttachmentState state_ = AttachmentState::kUninitialized;
sk_sp<flutter::DlImage> dl_image_;
ImageLRU image_lru_ = ImageLRU();
FML_DISALLOW_COPY_AND_ASSIGN(ImageExternalTexture);
};

View File

@@ -111,103 +111,4 @@ impeller::UniqueEGLImageKHR ImageExternalTextureGL::CreateEGLImage(
return impeller::UniqueEGLImageKHR(maybe_image);
}
ImageExternalTextureGLSkia::ImageExternalTextureGLSkia(
const std::shared_ptr<AndroidContextGLSkia>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& image_texture_entry,
const std::shared_ptr<PlatformViewAndroidJNI>& 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<flutter::DlImage> ImageExternalTextureGLSkia::CreateDlImage(
PaintContext& context,
const SkRect& bounds,
std::optional<HardwareBufferKey> 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<impeller::ContextGLES>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& image_textury_entry,
const std::shared_ptr<PlatformViewAndroidJNI>& 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<flutter::DlImage> ImageExternalTextureGLImpeller::CreateDlImage(
PaintContext& context,
const SkRect& bounds,
std::optional<HardwareBufferKey> 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<int>(bounds.width()),
static_cast<int>(bounds.height())};
desc.mip_count = 1;
auto texture = std::make_shared<impeller::TextureGLES>(
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

View File

@@ -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 <memory>
#include <optional>
#include <unordered_map>
#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<PlatformViewAndroidJNI>& 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<flutter::DlImage> CreateDlImage(
PaintContext& context,
@@ -41,6 +38,10 @@ class ImageExternalTextureGL : public ImageExternalTexture {
std::optional<HardwareBufferKey> 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<AndroidContextGLSkia>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& image_textury_entry,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade);
private:
void Attach(PaintContext& context) override;
void Detach() override;
void BindImageToTexture(const impeller::UniqueEGLImageKHR& image, GLuint tex);
sk_sp<flutter::DlImage> CreateDlImage(
PaintContext& context,
const SkRect& bounds,
std::optional<HardwareBufferKey> id,
impeller::UniqueEGLImageKHR&& egl_image) override;
FML_DISALLOW_COPY_AND_ASSIGN(ImageExternalTextureGLSkia);
};
class ImageExternalTextureGLImpeller : public ImageExternalTextureGL {
public:
ImageExternalTextureGLImpeller(
const std::shared_ptr<impeller::ContextGLES>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>&
hardware_buffer_texture_entry,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade);
private:
void Attach(PaintContext& context) override;
void Detach() override;
sk_sp<flutter::DlImage> CreateDlImage(
PaintContext& context,
const SkRect& bounds,
std::optional<HardwareBufferKey> id,
impeller::UniqueEGLImageKHR&& egl_image) override;
const std::shared_ptr<impeller::ContextGLES> impeller_context_;
FML_DISALLOW_COPY_AND_ASSIGN(ImageExternalTextureGLImpeller);
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_H_

View File

@@ -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<impeller::ContextGLES>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& image_textury_entry,
const std::shared_ptr<PlatformViewAndroidJNI>& 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<flutter::DlImage> ImageExternalTextureGLImpeller::CreateDlImage(
PaintContext& context,
const SkRect& bounds,
std::optional<HardwareBufferKey> 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<int>(bounds.width()),
static_cast<int>(bounds.height())};
desc.mip_count = 1;
auto texture = std::make_shared<impeller::TextureGLES>(
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

View File

@@ -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 <memory>
#include <optional>
#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<impeller::ContextGLES>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>&
hardware_buffer_texture_entry,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade);
private:
// |ImageExternalTexture|
void Attach(PaintContext& context) override;
// |ImageExternalTexture|
void Detach() override;
// |ImageExternalTextureGL|
sk_sp<flutter::DlImage> CreateDlImage(
PaintContext& context,
const SkRect& bounds,
std::optional<HardwareBufferKey> id,
impeller::UniqueEGLImageKHR&& egl_image) override;
const std::shared_ptr<impeller::ContextGLES> impeller_context_;
FML_DISALLOW_COPY_AND_ASSIGN(ImageExternalTextureGLImpeller);
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_EXTERNAL_TEXTURE_GL_IMPELLER_H_

View File

@@ -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<AndroidContextGLSkia>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& image_texture_entry,
const std::shared_ptr<PlatformViewAndroidJNI>& 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<flutter::DlImage> ImageExternalTextureGLSkia::CreateDlImage(
PaintContext& context,
const SkRect& bounds,
std::optional<HardwareBufferKey> 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

View File

@@ -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 <memory>
#include <optional>
#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<AndroidContextGLSkia>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& image_textury_entry,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade);
private:
// |ImageExternalTexture|
void Attach(PaintContext& context) override;
// |ImageExternalTexture|
void Detach() override;
// |ImageExternalTextureGL|
sk_sp<flutter::DlImage> CreateDlImage(
PaintContext& context,
const SkRect& bounds,
std::optional<HardwareBufferKey> 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_

View File

@@ -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 <cstdint>
@@ -17,7 +17,7 @@
namespace flutter {
ImageExternalTextureVK::ImageExternalTextureVK(
ImageExternalTextureVKImpeller::ImageExternalTextureVKImpeller(
const std::shared_ptr<impeller::ContextVK>& impeller_context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& 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;

View File

@@ -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 <cstdint>
#include <utility>
@@ -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::ContextVK>& impeller_context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>&
hardware_buffer_texture_entry,
const std::shared_ptr<PlatformViewAndroidJNI>& 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_

View File

@@ -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<AndroidSurface> AndroidSurfaceFactoryImpl::CreateSurface() {
return std::make_unique<AndroidSurfaceGLSkia>(
std::static_pointer_cast<AndroidContextGLSkia>(android_context_));
case AndroidRenderingAPI::kImpellerVulkan:
return std::make_unique<AndroidSurfaceVulkanImpeller>(
std::static_pointer_cast<AndroidContextVulkanImpeller>(
android_context_));
return std::make_unique<AndroidSurfaceVKImpeller>(
std::static_pointer_cast<AndroidContextVKImpeller>(android_context_));
}
FML_UNREACHABLE();
}
@@ -75,7 +76,7 @@ static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
std::make_unique<impeller::egl::Display>(),
enable_opengl_gpu_tracing);
case AndroidRenderingAPI::kImpellerVulkan:
return std::make_unique<AndroidContextVulkanImpeller>(
return std::make_unique<AndroidContextVKImpeller>(
enable_vulkan_validation, enable_vulkan_gpu_tracing);
case AndroidRenderingAPI::kSkiaOpenGLES:
return std::make_unique<AndroidContextGLSkia>(
@@ -276,14 +277,14 @@ void PlatformViewAndroid::RegisterExternalTexture(
switch (android_context_->RenderingApi()) {
case AndroidRenderingAPI::kImpellerOpenGLES:
// Impeller GLES.
RegisterTexture(std::make_shared<SurfaceTextureExternalTextureImpellerGL>(
RegisterTexture(std::make_shared<SurfaceTextureExternalTextureGLImpeller>(
std::static_pointer_cast<impeller::ContextGLES>(
android_context_->GetImpellerContext()),
texture_id, surface_texture, jni_facade_));
break;
case AndroidRenderingAPI::kSkiaOpenGLES:
// Legacy GL.
RegisterTexture(std::make_shared<SurfaceTextureExternalTextureGL>(
RegisterTexture(std::make_shared<SurfaceTextureExternalTextureGLSkia>(
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<ImageExternalTextureVK>(
RegisterTexture(std::make_shared<ImageExternalTextureVKImpeller>(
std::static_pointer_cast<impeller::ContextVK>(
android_context_->GetImpellerContext()),
texture_id, image_texture_entry, jni_facade_));

View File

@@ -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<AndroidShellHolder*>(shell_holder))

View File

@@ -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<jobject>& surface_texture,
const std::shared_ptr<PlatformViewAndroidJNI>& 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<PlatformViewAndroidJNI> jni_facade_;
@@ -51,6 +83,25 @@ class SurfaceTextureExternalTexture : public flutter::Texture {
SkMatrix transform_;
sk_sp<flutter::DlImage> 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);
};

View File

@@ -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 <utility>
#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<jobject>& surface_texture,
const std::shared_ptr<PlatformViewAndroidJNI>& 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<impeller::ContextGLES>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture,
const std::shared_ptr<PlatformViewAndroidJNI>& 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<int>(bounds.width()),
static_cast<int>(bounds.height())};
desc.mip_count = 1;
texture_ = std::make_shared<impeller::TextureGLES>(
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

View File

@@ -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<impeller::ContextGLES>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture,
const std::shared_ptr<PlatformViewAndroidJNI>& 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<int>(bounds.width()),
static_cast<int>(bounds.height())};
desc.mip_count = 1;
texture_ = std::make_shared<impeller::TextureGLES>(
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

View File

@@ -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 <memory>
#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<jobject>& surface_texture,
const std::shared_ptr<PlatformViewAndroidJNI>& 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<impeller::ContextGLES>& context,
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture,
const std::shared_ptr<PlatformViewAndroidJNI>& 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::ContextGLES> impeller_context_;
std::shared_ptr<impeller::TextureGLES> 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_

View File

@@ -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 <GLES2/gl2.h>
#define GL_GLEXT_PROTOTYPES
#include <GLES2/gl2ext.h>
#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<jobject>& surface_texture,
const std::shared_ptr<PlatformViewAndroidJNI>& 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

View File

@@ -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 <memory>
#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<jobject>& surface_texture,
const std::shared_ptr<PlatformViewAndroidJNI>& 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_