mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[android] Platform view creates external view embedder (flutter/engine#22360)
This commit is contained in:
parent
22dbf91bc2
commit
0b4d2a8c36
@ -119,7 +119,7 @@ bool AndroidEGLSurface::IsValid() const {
|
||||
return surface_ != EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
bool AndroidEGLSurface::MakeCurrent() {
|
||||
bool AndroidEGLSurface::MakeCurrent() const {
|
||||
if (eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) {
|
||||
FML_LOG(ERROR) << "Could not make the context current";
|
||||
LogLastEGLError();
|
||||
@ -235,7 +235,7 @@ bool AndroidContextGL::IsValid() const {
|
||||
return valid_;
|
||||
}
|
||||
|
||||
bool AndroidContextGL::ClearCurrent() {
|
||||
bool AndroidContextGL::ClearCurrent() const {
|
||||
if (eglGetCurrentContext() != context_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ class AndroidEGLSurface {
|
||||
///
|
||||
/// @return Whether the surface was made current.
|
||||
///
|
||||
bool MakeCurrent();
|
||||
bool MakeCurrent() const;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief This only applies to on-screen surfaces such as those created
|
||||
@ -108,7 +108,7 @@ class AndroidContextGL : public AndroidContext {
|
||||
//----------------------------------------------------------------------------
|
||||
/// @return Whether the current context was successfully clear.
|
||||
///
|
||||
bool ClearCurrent();
|
||||
bool ClearCurrent() const;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Create a new EGLContext using the same EGLConfig.
|
||||
|
||||
@ -20,17 +20,14 @@ constexpr char kEmulatorRendererPrefix[] =
|
||||
} // anonymous namespace
|
||||
|
||||
AndroidSurfaceGL::AndroidSurfaceGL(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder)
|
||||
: external_view_embedder_(external_view_embedder),
|
||||
android_context_(
|
||||
std::static_pointer_cast<AndroidContextGL>(android_context)),
|
||||
const AndroidContext& android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade)
|
||||
: android_context_(static_cast<const AndroidContextGL&>(android_context)),
|
||||
native_window_(nullptr),
|
||||
onscreen_surface_(nullptr),
|
||||
offscreen_surface_(nullptr) {
|
||||
// Acquire the offscreen surface.
|
||||
offscreen_surface_ = android_context_->CreateOffscreenSurface();
|
||||
offscreen_surface_ = android_context_.CreateOffscreenSurface();
|
||||
if (!offscreen_surface_->IsValid()) {
|
||||
offscreen_surface_ = nullptr;
|
||||
}
|
||||
@ -42,12 +39,12 @@ void AndroidSurfaceGL::TeardownOnScreenContext() {
|
||||
// When the onscreen surface is destroyed, the context and the surface
|
||||
// instance should be deleted. Issue:
|
||||
// https://github.com/flutter/flutter/issues/64414
|
||||
android_context_->ClearCurrent();
|
||||
android_context_.ClearCurrent();
|
||||
onscreen_surface_ = nullptr;
|
||||
}
|
||||
|
||||
bool AndroidSurfaceGL::IsValid() const {
|
||||
return offscreen_surface_ && android_context_->IsValid();
|
||||
return offscreen_surface_ && android_context_.IsValid();
|
||||
}
|
||||
|
||||
std::unique_ptr<Surface> AndroidSurfaceGL::CreateGPUSurface(
|
||||
@ -67,12 +64,12 @@ bool AndroidSurfaceGL::OnScreenSurfaceResize(const SkISize& size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
android_context_->ClearCurrent();
|
||||
android_context_.ClearCurrent();
|
||||
|
||||
// Ensure the destructor is called since it destroys the `EGLSurface` before
|
||||
// creating a new onscreen surface.
|
||||
onscreen_surface_ = nullptr;
|
||||
onscreen_surface_ = android_context_->CreateOnscreenSurface(native_window_);
|
||||
onscreen_surface_ = android_context_.CreateOnscreenSurface(native_window_);
|
||||
if (!onscreen_surface_->IsValid()) {
|
||||
FML_LOG(ERROR) << "Unable to create EGL window surface on resize.";
|
||||
return false;
|
||||
@ -88,7 +85,7 @@ bool AndroidSurfaceGL::ResourceContextMakeCurrent() {
|
||||
|
||||
bool AndroidSurfaceGL::ResourceContextClearCurrent() {
|
||||
FML_DCHECK(IsValid());
|
||||
return android_context_->ClearCurrent();
|
||||
return android_context_.ClearCurrent();
|
||||
}
|
||||
|
||||
bool AndroidSurfaceGL::SetNativeWindow(
|
||||
@ -100,7 +97,7 @@ bool AndroidSurfaceGL::SetNativeWindow(
|
||||
// creating a new onscreen surface.
|
||||
onscreen_surface_ = nullptr;
|
||||
// Create the onscreen surface.
|
||||
onscreen_surface_ = android_context_->CreateOnscreenSurface(window);
|
||||
onscreen_surface_ = android_context_.CreateOnscreenSurface(window);
|
||||
if (!onscreen_surface_->IsValid()) {
|
||||
return false;
|
||||
}
|
||||
@ -117,7 +114,7 @@ std::unique_ptr<GLContextResult> AndroidSurfaceGL::GLContextMakeCurrent() {
|
||||
|
||||
bool AndroidSurfaceGL::GLContextClearCurrent() {
|
||||
FML_DCHECK(IsValid());
|
||||
return android_context_->ClearCurrent();
|
||||
return android_context_.ClearCurrent();
|
||||
}
|
||||
|
||||
bool AndroidSurfaceGL::GLContextPresent(uint32_t fbo_id) {
|
||||
@ -146,7 +143,7 @@ sk_sp<const GrGLInterface> AndroidSurfaceGL::GetGLInterface() const {
|
||||
reinterpret_cast<const char*>(glGetString(GL_RENDERER));
|
||||
if (gl_renderer && strncmp(gl_renderer, kEmulatorRendererPrefix,
|
||||
strlen(kEmulatorRendererPrefix)) == 0) {
|
||||
EGLContext new_context = android_context_->CreateNewContext();
|
||||
EGLContext new_context = android_context_.CreateNewContext();
|
||||
if (new_context != EGL_NO_CONTEXT) {
|
||||
EGLContext old_context = eglGetCurrentContext();
|
||||
EGLDisplay display = eglGetCurrentDisplay();
|
||||
|
||||
@ -13,7 +13,6 @@
|
||||
#include "flutter/shell/gpu/gpu_surface_gl.h"
|
||||
#include "flutter/shell/platform/android/android_context_gl.h"
|
||||
#include "flutter/shell/platform/android/android_environment_gl.h"
|
||||
#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
|
||||
#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
|
||||
#include "flutter/shell/platform/android/surface/android_surface.h"
|
||||
|
||||
@ -22,10 +21,8 @@ namespace flutter {
|
||||
class AndroidSurfaceGL final : public GPUSurfaceGLDelegate,
|
||||
public AndroidSurface {
|
||||
public:
|
||||
AndroidSurfaceGL(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder);
|
||||
AndroidSurfaceGL(const AndroidContext& android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
|
||||
|
||||
~AndroidSurfaceGL() override;
|
||||
|
||||
@ -67,8 +64,7 @@ class AndroidSurfaceGL final : public GPUSurfaceGLDelegate,
|
||||
sk_sp<const GrGLInterface> GetGLInterface() const override;
|
||||
|
||||
private:
|
||||
const std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
const std::shared_ptr<AndroidContextGL> android_context_;
|
||||
const AndroidContextGL& android_context_;
|
||||
|
||||
fml::RefPtr<AndroidNativeWindow> native_window_;
|
||||
std::unique_ptr<AndroidEGLSurface> onscreen_surface_;
|
||||
|
||||
@ -38,10 +38,8 @@ bool GetSkColorType(int32_t buffer_format,
|
||||
} // anonymous namespace
|
||||
|
||||
AndroidSurfaceSoftware::AndroidSurfaceSoftware(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder)
|
||||
: external_view_embedder_(external_view_embedder) {
|
||||
const AndroidContext& android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
GetSkColorType(WINDOW_FORMAT_RGBA_8888, &target_color_type_,
|
||||
&target_alpha_type_);
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
#include "flutter/fml/platform/android/jni_weak_ref.h"
|
||||
#include "flutter/fml/platform/android/scoped_java_ref.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_software.h"
|
||||
#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
|
||||
#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
|
||||
#include "flutter/shell/platform/android/surface/android_surface.h"
|
||||
|
||||
@ -18,10 +17,8 @@ namespace flutter {
|
||||
class AndroidSurfaceSoftware final : public AndroidSurface,
|
||||
public GPUSurfaceSoftwareDelegate {
|
||||
public:
|
||||
AndroidSurfaceSoftware(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder);
|
||||
AndroidSurfaceSoftware(const AndroidContext& android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
|
||||
|
||||
~AndroidSurfaceSoftware() override;
|
||||
|
||||
@ -54,8 +51,6 @@ class AndroidSurfaceSoftware final : public AndroidSurface,
|
||||
bool PresentBackingStore(sk_sp<SkSurface> backing_store) override;
|
||||
|
||||
private:
|
||||
const std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
|
||||
sk_sp<SkSurface> sk_surface_;
|
||||
fml::RefPtr<AndroidNativeWindow> native_window_;
|
||||
SkColorType target_color_type_;
|
||||
|
||||
@ -13,11 +13,9 @@
|
||||
namespace flutter {
|
||||
|
||||
AndroidSurfaceVulkan::AndroidSurfaceVulkan(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder)
|
||||
: external_view_embedder_(external_view_embedder),
|
||||
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {}
|
||||
const AndroidContext& android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade)
|
||||
: proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {}
|
||||
|
||||
AndroidSurfaceVulkan::~AndroidSurfaceVulkan() = default;
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_vulkan_delegate.h"
|
||||
#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
|
||||
#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
|
||||
#include "flutter/shell/platform/android/surface/android_surface.h"
|
||||
#include "flutter/vulkan/vulkan_window.h"
|
||||
@ -21,10 +20,8 @@ namespace flutter {
|
||||
class AndroidSurfaceVulkan : public AndroidSurface,
|
||||
public GPUSurfaceVulkanDelegate {
|
||||
public:
|
||||
AndroidSurfaceVulkan(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder);
|
||||
AndroidSurfaceVulkan(const AndroidContext& android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
|
||||
|
||||
~AndroidSurfaceVulkan() override;
|
||||
|
||||
@ -54,7 +51,6 @@ class AndroidSurfaceVulkan : public AndroidSurface,
|
||||
fml::RefPtr<vulkan::VulkanProcTable> vk() override;
|
||||
|
||||
private:
|
||||
const std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
fml::RefPtr<vulkan::VulkanProcTable> proc_table_;
|
||||
fml::RefPtr<AndroidNativeWindow> native_window_;
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ enum class AndroidRenderingAPI {
|
||||
///
|
||||
class AndroidContext {
|
||||
public:
|
||||
AndroidContext(AndroidRenderingAPI rendering_api);
|
||||
explicit AndroidContext(AndroidRenderingAPI rendering_api);
|
||||
|
||||
~AndroidContext();
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
namespace flutter {
|
||||
|
||||
AndroidExternalViewEmbedder::AndroidExternalViewEmbedder(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
const AndroidContext& android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidSurfaceFactory> surface_factory)
|
||||
: ExternalViewEmbedder(),
|
||||
|
||||
@ -30,7 +30,7 @@ namespace flutter {
|
||||
class AndroidExternalViewEmbedder final : public ExternalViewEmbedder {
|
||||
public:
|
||||
AndroidExternalViewEmbedder(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
const AndroidContext& android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidSurfaceFactory> surface_factory);
|
||||
|
||||
@ -88,7 +88,7 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder {
|
||||
static const int kDefaultMergedLeaseDuration = 10;
|
||||
|
||||
// Provides metadata to the Android surfaces.
|
||||
const std::shared_ptr<AndroidContext> android_context_;
|
||||
const AndroidContext& android_context_;
|
||||
|
||||
// Allows to call methods in Java.
|
||||
const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
|
||||
|
||||
@ -90,8 +90,9 @@ fml::RefPtr<fml::RasterThreadMerger> GetThreadMergerFromRasterThread() {
|
||||
TEST(AndroidExternalViewEmbedder, GetCurrentCanvases) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, jni_mock, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, nullptr);
|
||||
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
|
||||
|
||||
EXPECT_CALL(*jni_mock, FlutterViewBeginFrame());
|
||||
@ -112,8 +113,9 @@ TEST(AndroidExternalViewEmbedder, GetCurrentCanvases) {
|
||||
TEST(AndroidExternalViewEmbedder, GetCurrentCanvases__CompositeOrder) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, jni_mock, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, nullptr);
|
||||
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
|
||||
|
||||
EXPECT_CALL(*jni_mock, FlutterViewBeginFrame());
|
||||
@ -132,8 +134,9 @@ TEST(AndroidExternalViewEmbedder, GetCurrentCanvases__CompositeOrder) {
|
||||
}
|
||||
|
||||
TEST(AndroidExternalViewEmbedder, CompositeEmbeddedView) {
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, nullptr, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, nullptr, nullptr);
|
||||
|
||||
ASSERT_EQ(nullptr, embedder->CompositeEmbeddedView(0));
|
||||
embedder->PrerollCompositeEmbeddedView(
|
||||
@ -147,8 +150,9 @@ TEST(AndroidExternalViewEmbedder, CompositeEmbeddedView) {
|
||||
}
|
||||
|
||||
TEST(AndroidExternalViewEmbedder, CancelFrame) {
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, nullptr, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, nullptr, nullptr);
|
||||
|
||||
embedder->PrerollCompositeEmbeddedView(
|
||||
0, std::make_unique<EmbeddedViewParams>());
|
||||
@ -160,8 +164,9 @@ TEST(AndroidExternalViewEmbedder, CancelFrame) {
|
||||
|
||||
TEST(AndroidExternalViewEmbedder, RasterizerRunsOnPlatformThread) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, jni_mock, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, nullptr);
|
||||
|
||||
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
|
||||
ASSERT_FALSE(raster_thread_merger->IsMerged());
|
||||
@ -191,8 +196,9 @@ TEST(AndroidExternalViewEmbedder, RasterizerRunsOnPlatformThread) {
|
||||
|
||||
TEST(AndroidExternalViewEmbedder, RasterizerRunsOnRasterizerThread) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, jni_mock, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, nullptr);
|
||||
|
||||
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
|
||||
ASSERT_FALSE(raster_thread_merger->IsMerged());
|
||||
@ -209,8 +215,9 @@ TEST(AndroidExternalViewEmbedder, RasterizerRunsOnRasterizerThread) {
|
||||
TEST(AndroidExternalViewEmbedder, PlatformViewRect) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, jni_mock, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, nullptr);
|
||||
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
|
||||
|
||||
EXPECT_CALL(*jni_mock, FlutterViewBeginFrame());
|
||||
@ -234,8 +241,9 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRect) {
|
||||
TEST(AndroidExternalViewEmbedder, PlatformViewRect__ChangedParams) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, jni_mock, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, nullptr);
|
||||
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
|
||||
|
||||
EXPECT_CALL(*jni_mock, FlutterViewBeginFrame());
|
||||
@ -270,8 +278,7 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRect__ChangedParams) {
|
||||
|
||||
TEST(AndroidExternalViewEmbedder, SubmitFrame) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
auto android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
@ -470,8 +477,9 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) {
|
||||
TEST(AndroidExternalViewEmbedder, DoesNotCallJNIPlatformThreadOnlyMethods) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, jni_mock, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, nullptr);
|
||||
|
||||
// While on the raster thread, don't make JNI calls as these methods can only
|
||||
// run on the platform thread.
|
||||
@ -487,8 +495,6 @@ TEST(AndroidExternalViewEmbedder, DoesNotCallJNIPlatformThreadOnlyMethods) {
|
||||
|
||||
TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
auto android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
@ -516,6 +522,7 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) {
|
||||
return android_surface_mock;
|
||||
});
|
||||
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, surface_factory);
|
||||
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
|
||||
@ -568,8 +575,7 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) {
|
||||
|
||||
TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
auto android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
@ -651,16 +657,17 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) {
|
||||
|
||||
TEST(AndroidExternalViewEmbedder, SupportsDynamicThreadMerging) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, jni_mock, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, nullptr);
|
||||
ASSERT_TRUE(embedder->SupportsDynamicThreadMerging());
|
||||
}
|
||||
|
||||
TEST(AndroidExternalViewEmbedder, DisableThreadMerger) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
auto embedder =
|
||||
std::make_unique<AndroidExternalViewEmbedder>(nullptr, jni_mock, nullptr);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, nullptr);
|
||||
|
||||
auto raster_thread_merger = GetThreadMergerFromRasterThread();
|
||||
ASSERT_FALSE(raster_thread_merger->IsMerged());
|
||||
|
||||
@ -21,7 +21,7 @@ SurfacePool::~SurfacePool() = default;
|
||||
|
||||
std::shared_ptr<OverlayLayer> SurfacePool::GetLayer(
|
||||
GrDirectContext* gr_context,
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
const AndroidContext& android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidSurfaceFactory> surface_factory) {
|
||||
// Destroy current layers in the pool if the frame size has changed.
|
||||
|
||||
@ -53,7 +53,7 @@ class SurfacePool {
|
||||
// `available_layer_index_`.
|
||||
std::shared_ptr<OverlayLayer> GetLayer(
|
||||
GrDirectContext* gr_context,
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
const AndroidContext& android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidSurfaceFactory> surface_factory);
|
||||
|
||||
|
||||
@ -39,8 +39,7 @@ TEST(SurfacePool, GetLayer__AllocateOneLayer) {
|
||||
auto pool = std::make_unique<SurfacePool>();
|
||||
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
auto android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
@ -69,8 +68,7 @@ TEST(SurfacePool, GetUnusedLayers) {
|
||||
auto pool = std::make_unique<SurfacePool>();
|
||||
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
auto android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
@ -108,8 +106,7 @@ TEST(SurfacePool, GetLayer__Recycle) {
|
||||
ByMove(std::make_unique<PlatformViewAndroidJNI::OverlayMetadata>(
|
||||
0, window))));
|
||||
|
||||
auto android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
|
||||
auto gr_context_2 = GrDirectContext::MakeMock(nullptr);
|
||||
auto surface_factory = std::make_shared<TestAndroidSurfaceFactory>(
|
||||
@ -145,8 +142,7 @@ TEST(SurfacePool, GetLayer__AllocateTwoLayers) {
|
||||
auto pool = std::make_unique<SurfacePool>();
|
||||
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
auto android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
@ -186,8 +182,7 @@ TEST(SurfacePool, DestroyLayers) {
|
||||
pool->DestroyLayers(jni_mock);
|
||||
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
auto android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
EXPECT_CALL(*jni_mock, FlutterViewCreateOverlaySurface())
|
||||
@ -218,8 +213,7 @@ TEST(SurfacePool, DestroyLayers__frameSizeChanged) {
|
||||
auto jni_mock = std::make_shared<JNIMock>();
|
||||
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
auto android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
|
||||
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
|
||||
|
||||
@ -29,32 +29,23 @@
|
||||
namespace flutter {
|
||||
|
||||
AndroidSurfaceFactoryImpl::AndroidSurfaceFactoryImpl(
|
||||
std::shared_ptr<AndroidContext> context,
|
||||
const AndroidContext& context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade)
|
||||
: android_context_(context), jni_facade_(jni_facade) {}
|
||||
|
||||
AndroidSurfaceFactoryImpl::~AndroidSurfaceFactoryImpl() = default;
|
||||
|
||||
void AndroidSurfaceFactoryImpl::SetExternalViewEmbedder(
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder) {
|
||||
external_view_embedder_ = external_view_embedder;
|
||||
}
|
||||
|
||||
std::unique_ptr<AndroidSurface> AndroidSurfaceFactoryImpl::CreateSurface() {
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder =
|
||||
external_view_embedder_.lock();
|
||||
FML_CHECK(external_view_embedder);
|
||||
switch (android_context_->RenderingApi()) {
|
||||
switch (android_context_.RenderingApi()) {
|
||||
case AndroidRenderingAPI::kSoftware:
|
||||
return std::make_unique<AndroidSurfaceSoftware>(
|
||||
android_context_, jni_facade_, external_view_embedder);
|
||||
return std::make_unique<AndroidSurfaceSoftware>(android_context_,
|
||||
jni_facade_);
|
||||
case AndroidRenderingAPI::kOpenGLES:
|
||||
return std::make_unique<AndroidSurfaceGL>(android_context_, jni_facade_,
|
||||
external_view_embedder);
|
||||
return std::make_unique<AndroidSurfaceGL>(android_context_, jni_facade_);
|
||||
case AndroidRenderingAPI::kVulkan:
|
||||
#if SHELL_ENABLE_VULKAN
|
||||
return std::make_unique<AndroidSurfaceVulkan>(
|
||||
android_context_, jni_facade_, external_view_embedder);
|
||||
return std::make_unique<AndroidSurfaceVulkan>(android_context_,
|
||||
jni_facade_);
|
||||
#endif // SHELL_ENABLE_VULKAN
|
||||
default:
|
||||
return nullptr;
|
||||
@ -70,28 +61,24 @@ PlatformViewAndroid::PlatformViewAndroid(
|
||||
: PlatformView(delegate, std::move(task_runners)),
|
||||
jni_facade_(jni_facade),
|
||||
platform_view_android_delegate_(jni_facade) {
|
||||
std::shared_ptr<AndroidContext> android_context;
|
||||
if (use_software_rendering) {
|
||||
android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
android_context_ =
|
||||
std::make_unique<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
} else {
|
||||
#if SHELL_ENABLE_VULKAN
|
||||
android_context =
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kVulkan);
|
||||
android_context_ =
|
||||
std::make_unique<AndroidContext>(AndroidRenderingAPI::kVulkan);
|
||||
#else // SHELL_ENABLE_VULKAN
|
||||
android_context = std::make_shared<AndroidContextGL>(
|
||||
android_context_ = std::make_unique<AndroidContextGL>(
|
||||
AndroidRenderingAPI::kOpenGLES,
|
||||
fml::MakeRefCounted<AndroidEnvironmentGL>());
|
||||
#endif // SHELL_ENABLE_VULKAN
|
||||
}
|
||||
FML_CHECK(android_context && android_context->IsValid())
|
||||
FML_CHECK(android_context_ && android_context_->IsValid())
|
||||
<< "Could not create an Android context.";
|
||||
|
||||
surface_factory_ =
|
||||
std::make_shared<AndroidSurfaceFactoryImpl>(android_context, jni_facade);
|
||||
external_view_embedder_ = std::make_shared<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_facade, surface_factory_);
|
||||
surface_factory_->SetExternalViewEmbedder(external_view_embedder_);
|
||||
surface_factory_ = std::make_shared<AndroidSurfaceFactoryImpl>(
|
||||
*android_context_, jni_facade);
|
||||
|
||||
android_surface_ = surface_factory_->CreateSurface();
|
||||
FML_CHECK(android_surface_ && android_surface_->IsValid())
|
||||
@ -310,7 +297,8 @@ std::unique_ptr<Surface> PlatformViewAndroid::CreateRenderingSurface() {
|
||||
// |PlatformView|
|
||||
std::shared_ptr<ExternalViewEmbedder>
|
||||
PlatformViewAndroid::CreateExternalViewEmbedder() {
|
||||
return external_view_embedder_;
|
||||
return std::make_shared<AndroidExternalViewEmbedder>(
|
||||
*android_context_, jni_facade_, surface_factory_);
|
||||
}
|
||||
|
||||
// |PlatformView|
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include "flutter/fml/platform/android/scoped_java_ref.h"
|
||||
#include "flutter/lib/ui/window/platform_message.h"
|
||||
#include "flutter/shell/common/platform_view.h"
|
||||
#include "flutter/shell/platform/android/context/android_context.h"
|
||||
#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
|
||||
#include "flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.h"
|
||||
#include "flutter/shell/platform/android/surface/android_native_window.h"
|
||||
@ -24,18 +25,15 @@ namespace flutter {
|
||||
|
||||
class AndroidSurfaceFactoryImpl : public AndroidSurfaceFactory {
|
||||
public:
|
||||
AndroidSurfaceFactoryImpl(std::shared_ptr<AndroidContext> context,
|
||||
AndroidSurfaceFactoryImpl(const AndroidContext& context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
|
||||
|
||||
~AndroidSurfaceFactoryImpl() override;
|
||||
|
||||
std::unique_ptr<AndroidSurface> CreateSurface() override;
|
||||
|
||||
void SetExternalViewEmbedder(
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder);
|
||||
|
||||
private:
|
||||
std::shared_ptr<AndroidContext> android_context_;
|
||||
const AndroidContext& android_context_;
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
|
||||
std::weak_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
};
|
||||
@ -98,7 +96,7 @@ class PlatformViewAndroid final : public PlatformView {
|
||||
|
||||
private:
|
||||
const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
std::unique_ptr<AndroidContext> android_context_;
|
||||
std::shared_ptr<AndroidSurfaceFactoryImpl> surface_factory_;
|
||||
|
||||
PlatformViewAndroidDelegate platform_view_android_delegate_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user