[android] Refactor surface factory and wire in external view embedder (flutter/engine#21839)
This commit is contained in:
@@ -22,11 +22,8 @@ constexpr char kEmulatorRendererPrefix[] =
|
||||
AndroidSurfaceGL::AndroidSurfaceGL(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
const AndroidSurface::Factory& surface_factory)
|
||||
: external_view_embedder_(
|
||||
std::make_unique<AndroidExternalViewEmbedder>(android_context,
|
||||
jni_facade,
|
||||
surface_factory)),
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder)
|
||||
: external_view_embedder_(external_view_embedder),
|
||||
android_context_(
|
||||
std::static_pointer_cast<AndroidContextGL>(android_context)),
|
||||
native_window_(nullptr),
|
||||
|
||||
@@ -22,9 +22,10 @@ namespace flutter {
|
||||
class AndroidSurfaceGL final : public GPUSurfaceGLDelegate,
|
||||
public AndroidSurface {
|
||||
public:
|
||||
AndroidSurfaceGL(std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
const AndroidSurface::Factory& surface_factory);
|
||||
AndroidSurfaceGL(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder);
|
||||
|
||||
~AndroidSurfaceGL() override;
|
||||
|
||||
@@ -69,7 +70,7 @@ class AndroidSurfaceGL final : public GPUSurfaceGLDelegate,
|
||||
sk_sp<const GrGLInterface> GetGLInterface() const override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
const std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
const std::shared_ptr<AndroidContextGL> android_context_;
|
||||
|
||||
fml::RefPtr<AndroidNativeWindow> native_window_;
|
||||
|
||||
@@ -40,11 +40,8 @@ bool GetSkColorType(int32_t buffer_format,
|
||||
AndroidSurfaceSoftware::AndroidSurfaceSoftware(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
AndroidSurface::Factory surface_factory)
|
||||
: external_view_embedder_(
|
||||
std::make_unique<AndroidExternalViewEmbedder>(android_context,
|
||||
jni_facade,
|
||||
surface_factory)) {
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder)
|
||||
: external_view_embedder_(external_view_embedder) {
|
||||
GetSkColorType(WINDOW_FORMAT_RGBA_8888, &target_color_type_,
|
||||
&target_alpha_type_);
|
||||
}
|
||||
|
||||
@@ -18,9 +18,10 @@ namespace flutter {
|
||||
class AndroidSurfaceSoftware final : public AndroidSurface,
|
||||
public GPUSurfaceSoftwareDelegate {
|
||||
public:
|
||||
AndroidSurfaceSoftware(std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
AndroidSurface::Factory surface_factory);
|
||||
AndroidSurfaceSoftware(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder);
|
||||
|
||||
~AndroidSurfaceSoftware() override;
|
||||
|
||||
@@ -56,7 +57,7 @@ class AndroidSurfaceSoftware final : public AndroidSurface,
|
||||
ExternalViewEmbedder* GetExternalViewEmbedder() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
const std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
|
||||
sk_sp<SkSurface> sk_surface_;
|
||||
fml::RefPtr<AndroidNativeWindow> native_window_;
|
||||
|
||||
@@ -15,11 +15,8 @@ namespace flutter {
|
||||
AndroidSurfaceVulkan::AndroidSurfaceVulkan(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
AndroidSurface::Factory surface_factory)
|
||||
: external_view_embedder_(
|
||||
std::make_unique<AndroidExternalViewEmbedder>(android_context,
|
||||
jni_facade,
|
||||
surface_factory)),
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder)
|
||||
: external_view_embedder_(external_view_embedder),
|
||||
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {}
|
||||
|
||||
AndroidSurfaceVulkan::~AndroidSurfaceVulkan() = default;
|
||||
|
||||
@@ -21,9 +21,10 @@ namespace flutter {
|
||||
class AndroidSurfaceVulkan : public AndroidSurface,
|
||||
public GPUSurfaceVulkanDelegate {
|
||||
public:
|
||||
AndroidSurfaceVulkan(std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
AndroidSurface::Factory surface_factory);
|
||||
AndroidSurfaceVulkan(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder);
|
||||
|
||||
~AndroidSurfaceVulkan() override;
|
||||
|
||||
@@ -56,8 +57,7 @@ class AndroidSurfaceVulkan : public AndroidSurface,
|
||||
fml::RefPtr<vulkan::VulkanProcTable> vk() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
|
||||
const std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
fml::RefPtr<vulkan::VulkanProcTable> proc_table_;
|
||||
fml::RefPtr<AndroidNativeWindow> native_window_;
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ executable("android_external_view_embedder_unittests") {
|
||||
"//flutter/flow",
|
||||
"//flutter/shell/gpu:gpu_surface_gl",
|
||||
"//flutter/shell/platform/android/jni:jni_mock",
|
||||
"//flutter/shell/platform/android/surface",
|
||||
"//flutter/shell/platform/android/surface:surface_mock",
|
||||
"//flutter/testing",
|
||||
"//flutter/testing:dart",
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
|
||||
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "flutter/shell/platform/android/surface/android_surface.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
AndroidExternalViewEmbedder::AndroidExternalViewEmbedder(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
const AndroidSurface::Factory& surface_factory)
|
||||
std::shared_ptr<AndroidSurfaceFactory> surface_factory)
|
||||
: ExternalViewEmbedder(),
|
||||
android_context_(android_context),
|
||||
jni_facade_(jni_facade),
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "flutter/shell/platform/android/context/android_context.h"
|
||||
#include "flutter/shell/platform/android/external_view_embedder/surface_pool.h"
|
||||
#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
|
||||
#include "flutter/shell/platform/android/surface/android_surface.h"
|
||||
#include "third_party/skia/include/core/SkPictureRecorder.h"
|
||||
|
||||
namespace flutter {
|
||||
@@ -31,7 +32,7 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder {
|
||||
AndroidExternalViewEmbedder(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
const AndroidSurface::Factory& surface_factory);
|
||||
std::shared_ptr<AndroidSurfaceFactory> surface_factory);
|
||||
|
||||
// |ExternalViewEmbedder|
|
||||
void PrerollCompositeEmbeddedView(
|
||||
@@ -93,7 +94,7 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder {
|
||||
const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
|
||||
|
||||
// Allows to create surfaces.
|
||||
const AndroidSurface::Factory surface_factory_;
|
||||
const std::shared_ptr<AndroidSurfaceFactory> surface_factory_;
|
||||
|
||||
// Holds surfaces. Allows to recycle surfaces or allocate new ones.
|
||||
const std::unique_ptr<SurfacePool> surface_pool_;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "flutter/shell/platform/android/surface/android_surface_mock.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "shell/platform/android/surface/android_surface.h"
|
||||
#include "third_party/skia/include/gpu/GrDirectContext.h"
|
||||
|
||||
namespace flutter {
|
||||
@@ -21,6 +22,24 @@ namespace testing {
|
||||
using ::testing::ByMove;
|
||||
using ::testing::Return;
|
||||
|
||||
class TestAndroidSurfaceFactory : public AndroidSurfaceFactory {
|
||||
public:
|
||||
using TestSurfaceProducer =
|
||||
std::function<std::unique_ptr<AndroidSurface>(void)>;
|
||||
explicit TestAndroidSurfaceFactory(TestSurfaceProducer&& surface_producer) {
|
||||
surface_producer_ = surface_producer;
|
||||
}
|
||||
|
||||
~TestAndroidSurfaceFactory() override = default;
|
||||
|
||||
std::unique_ptr<AndroidSurface> CreateSurface() override {
|
||||
return surface_producer_();
|
||||
}
|
||||
|
||||
private:
|
||||
TestSurfaceProducer surface_producer_;
|
||||
};
|
||||
|
||||
class SurfaceMock : public Surface {
|
||||
public:
|
||||
MOCK_METHOD(bool, IsValid, (), (override));
|
||||
@@ -263,10 +282,8 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) {
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
auto frame_size = SkISize::Make(1000, 1000);
|
||||
auto surface_factory =
|
||||
[gr_context, window, frame_size](
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
auto surface_factory = std::make_shared<TestAndroidSurfaceFactory>(
|
||||
[gr_context, window, frame_size]() {
|
||||
auto surface_frame_1 = std::make_unique<SurfaceFrame>(
|
||||
SkSurface::MakeNull(1000, 1000), false,
|
||||
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
|
||||
@@ -293,7 +310,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) {
|
||||
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
|
||||
|
||||
return android_surface_mock;
|
||||
};
|
||||
});
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, surface_factory);
|
||||
|
||||
@@ -482,10 +499,8 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) {
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
auto frame_size = SkISize::Make(1000, 1000);
|
||||
auto surface_factory =
|
||||
[gr_context, window, frame_size](
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
auto surface_factory = std::make_shared<TestAndroidSurfaceFactory>(
|
||||
[gr_context, window, frame_size]() {
|
||||
auto surface_frame_1 = std::make_unique<SurfaceFrame>(
|
||||
SkSurface::MakeNull(1000, 1000), false,
|
||||
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
|
||||
@@ -505,7 +520,7 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) {
|
||||
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
|
||||
|
||||
return android_surface_mock;
|
||||
};
|
||||
});
|
||||
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, surface_factory);
|
||||
@@ -565,10 +580,8 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) {
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
auto gr_context = GrDirectContext::MakeMock(nullptr);
|
||||
auto frame_size = SkISize::Make(1000, 1000);
|
||||
auto surface_factory =
|
||||
[gr_context, window, frame_size](
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
auto surface_factory = std::make_shared<TestAndroidSurfaceFactory>(
|
||||
[gr_context, window, frame_size]() {
|
||||
auto surface_frame_1 = std::make_unique<SurfaceFrame>(
|
||||
SkSurface::MakeNull(1000, 1000), false,
|
||||
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
|
||||
@@ -588,7 +601,7 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) {
|
||||
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
|
||||
|
||||
return android_surface_mock;
|
||||
};
|
||||
});
|
||||
|
||||
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
|
||||
android_context, jni_mock, surface_factory);
|
||||
|
||||
@@ -23,7 +23,7 @@ std::shared_ptr<OverlayLayer> SurfacePool::GetLayer(
|
||||
GrDirectContext* gr_context,
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
const AndroidSurface::Factory& surface_factory) {
|
||||
std::shared_ptr<AndroidSurfaceFactory> surface_factory) {
|
||||
// Destroy current layers in the pool if the frame size has changed.
|
||||
if (requested_frame_size_ != current_frame_size_) {
|
||||
DestroyLayers(jni_facade);
|
||||
@@ -33,7 +33,7 @@ std::shared_ptr<OverlayLayer> SurfacePool::GetLayer(
|
||||
// Allocate a new surface if there isn't one available.
|
||||
if (available_layer_index_ >= layers_.size()) {
|
||||
std::unique_ptr<AndroidSurface> android_surface =
|
||||
surface_factory(android_context, jni_facade);
|
||||
surface_factory->CreateSurface();
|
||||
|
||||
FML_CHECK(android_surface && android_surface->IsValid())
|
||||
<< "Could not create an OpenGL, Vulkan or Software surface to setup "
|
||||
|
||||
@@ -55,7 +55,7 @@ class SurfacePool {
|
||||
GrDirectContext* gr_context,
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
|
||||
const AndroidSurface::Factory& surface_factory);
|
||||
std::shared_ptr<AndroidSurfaceFactory> surface_factory);
|
||||
|
||||
// Gets the layers in the pool that aren't currently used.
|
||||
// This method doesn't mark the layers as unused.
|
||||
|
||||
@@ -18,6 +18,24 @@ namespace testing {
|
||||
using ::testing::ByMove;
|
||||
using ::testing::Return;
|
||||
|
||||
class TestAndroidSurfaceFactory : public AndroidSurfaceFactory {
|
||||
public:
|
||||
using TestSurfaceProducer =
|
||||
std::function<std::unique_ptr<AndroidSurface>(void)>;
|
||||
explicit TestAndroidSurfaceFactory(TestSurfaceProducer&& surface_producer) {
|
||||
surface_producer_ = surface_producer;
|
||||
}
|
||||
|
||||
~TestAndroidSurfaceFactory() override = default;
|
||||
|
||||
std::unique_ptr<AndroidSurface> CreateSurface() override {
|
||||
return surface_producer_();
|
||||
}
|
||||
|
||||
private:
|
||||
TestSurfaceProducer surface_producer_;
|
||||
};
|
||||
|
||||
TEST(SurfacePool, GetLayer__AllocateOneLayer) {
|
||||
auto pool = std::make_unique<SurfacePool>();
|
||||
|
||||
@@ -33,14 +51,13 @@ TEST(SurfacePool, GetLayer__AllocateOneLayer) {
|
||||
0, window))));
|
||||
|
||||
auto surface_factory =
|
||||
[gr_context, window](std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
|
||||
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
|
||||
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()));
|
||||
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
|
||||
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
|
||||
return android_surface_mock;
|
||||
};
|
||||
});
|
||||
auto layer = pool->GetLayer(gr_context.get(), android_context, jni_mock,
|
||||
surface_factory);
|
||||
|
||||
@@ -64,14 +81,13 @@ TEST(SurfacePool, GetUnusedLayers) {
|
||||
0, window))));
|
||||
|
||||
auto surface_factory =
|
||||
[gr_context, window](std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
|
||||
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
|
||||
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()));
|
||||
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
|
||||
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
|
||||
return android_surface_mock;
|
||||
};
|
||||
});
|
||||
auto layer = pool->GetLayer(gr_context.get(), android_context, jni_mock,
|
||||
surface_factory);
|
||||
ASSERT_EQ(0UL, pool->GetUnusedLayers().size());
|
||||
@@ -97,10 +113,8 @@ TEST(SurfacePool, GetLayer__Recycle) {
|
||||
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
|
||||
auto gr_context_2 = GrDirectContext::MakeMock(nullptr);
|
||||
auto surface_factory =
|
||||
[gr_context_1, gr_context_2, window](
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
auto surface_factory = std::make_shared<TestAndroidSurfaceFactory>(
|
||||
[gr_context_1, gr_context_2, window]() {
|
||||
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
|
||||
// Allocate two GPU surfaces for each gr context.
|
||||
EXPECT_CALL(*android_surface_mock,
|
||||
@@ -111,7 +125,7 @@ TEST(SurfacePool, GetLayer__Recycle) {
|
||||
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
|
||||
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
|
||||
return android_surface_mock;
|
||||
};
|
||||
});
|
||||
auto layer_1 = pool->GetLayer(gr_context_1.get(), android_context, jni_mock,
|
||||
surface_factory);
|
||||
|
||||
@@ -147,14 +161,13 @@ TEST(SurfacePool, GetLayer__AllocateTwoLayers) {
|
||||
1, window))));
|
||||
|
||||
auto surface_factory =
|
||||
[gr_context, window](std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
|
||||
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
|
||||
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()));
|
||||
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
|
||||
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
|
||||
return android_surface_mock;
|
||||
};
|
||||
});
|
||||
auto layer_1 = pool->GetLayer(gr_context.get(), android_context, jni_mock,
|
||||
surface_factory);
|
||||
auto layer_2 = pool->GetLayer(gr_context.get(), android_context, jni_mock,
|
||||
@@ -185,14 +198,13 @@ TEST(SurfacePool, DestroyLayers) {
|
||||
0, window))));
|
||||
|
||||
auto surface_factory =
|
||||
[gr_context, window](std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
|
||||
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
|
||||
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()));
|
||||
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
|
||||
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
|
||||
return android_surface_mock;
|
||||
};
|
||||
});
|
||||
pool->GetLayer(gr_context.get(), android_context, jni_mock, surface_factory);
|
||||
|
||||
EXPECT_CALL(*jni_mock, FlutterViewDestroyOverlaySurfaces());
|
||||
@@ -213,14 +225,13 @@ TEST(SurfacePool, DestroyLayers__frameSizeChanged) {
|
||||
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
|
||||
|
||||
auto surface_factory =
|
||||
[gr_context, window](std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
|
||||
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
|
||||
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()));
|
||||
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
|
||||
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
|
||||
return android_surface_mock;
|
||||
};
|
||||
});
|
||||
pool->SetFrameSize(SkISize::Make(10, 10));
|
||||
EXPECT_CALL(*jni_mock, FlutterViewDestroyOverlaySurfaces()).Times(0);
|
||||
EXPECT_CALL(*jni_mock, FlutterViewCreateOverlaySurface())
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "flutter/shell/platform/android/android_external_texture_gl.h"
|
||||
#include "flutter/shell/platform/android/android_surface_gl.h"
|
||||
#include "flutter/shell/platform/android/android_surface_software.h"
|
||||
#include "shell/platform/android/external_view_embedder/external_view_embedder.h"
|
||||
#include "shell/platform/android/surface/android_surface.h"
|
||||
|
||||
#if SHELL_ENABLE_VULKAN
|
||||
#include "flutter/shell/platform/android/android_surface_vulkan.h"
|
||||
@@ -26,22 +28,35 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
std::unique_ptr<AndroidSurface> SurfaceFactory(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
AndroidSurfaceFactoryImpl::AndroidSurfaceFactoryImpl(
|
||||
std::shared_ptr<AndroidContext> context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
|
||||
FML_CHECK(SurfaceFactory);
|
||||
switch (android_context->RenderingApi()) {
|
||||
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() {
|
||||
FML_CHECK(external_view_embedder_);
|
||||
switch (android_context_->RenderingApi()) {
|
||||
case AndroidRenderingAPI::kSoftware:
|
||||
return std::make_unique<AndroidSurfaceSoftware>(
|
||||
android_context, jni_facade, SurfaceFactory);
|
||||
android_context_, jni_facade_, external_view_embedder_);
|
||||
case AndroidRenderingAPI::kOpenGLES:
|
||||
return std::make_unique<AndroidSurfaceGL>(android_context, jni_facade,
|
||||
SurfaceFactory);
|
||||
return std::make_unique<AndroidSurfaceGL>(android_context_, jni_facade_,
|
||||
external_view_embedder_);
|
||||
case AndroidRenderingAPI::kVulkan:
|
||||
#if SHELL_ENABLE_VULKAN
|
||||
return std::make_unique<AndroidSurfaceVulkan>(android_context, jni_facade,
|
||||
SurfaceFactory);
|
||||
return std::make_unique<AndroidSurfaceVulkan>(
|
||||
android_context_, jni_facade_, external_view_embedder_);
|
||||
#endif // SHELL_ENABLE_VULKAN
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
@@ -72,7 +87,13 @@ PlatformViewAndroid::PlatformViewAndroid(
|
||||
FML_CHECK(android_context && android_context->IsValid())
|
||||
<< "Could not create an Android context.";
|
||||
|
||||
android_surface_ = SurfaceFactory(std::move(android_context), jni_facade);
|
||||
surface_factory_ =
|
||||
std::make_shared<AndroidSurfaceFactoryImpl>(android_context, jni_facade);
|
||||
surface_factory_->SetExternalViewEmbedder(
|
||||
std::make_shared<AndroidExternalViewEmbedder>(android_context, jni_facade,
|
||||
surface_factory_));
|
||||
|
||||
android_surface_ = surface_factory_->CreateSurface();
|
||||
FML_CHECK(android_surface_ && android_surface_->IsValid())
|
||||
<< "Could not create an OpenGL, Vulkan or Software surface to setup "
|
||||
"rendering.";
|
||||
|
||||
@@ -22,6 +22,25 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
class AndroidSurfaceFactoryImpl : public AndroidSurfaceFactory {
|
||||
public:
|
||||
AndroidSurfaceFactoryImpl(std::shared_ptr<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_;
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
|
||||
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
|
||||
|
||||
};
|
||||
|
||||
class PlatformViewAndroid final : public PlatformView {
|
||||
public:
|
||||
static bool Register(JNIEnv* env);
|
||||
@@ -80,6 +99,7 @@ class PlatformViewAndroid final : public PlatformView {
|
||||
|
||||
private:
|
||||
const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
|
||||
std::shared_ptr<AndroidSurfaceFactoryImpl> surface_factory_;
|
||||
|
||||
PlatformViewAndroidDelegate platform_view_android_delegate_;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_H_
|
||||
|
||||
#include "flutter/flow/embedded_views.h"
|
||||
#include "flutter/flow/surface.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/platform/android/context/android_context.h"
|
||||
@@ -14,12 +15,10 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
class AndroidExternalViewEmbedder;
|
||||
|
||||
class AndroidSurface {
|
||||
public:
|
||||
using Factory = std::function<std::unique_ptr<AndroidSurface>(
|
||||
std::shared_ptr<AndroidContext> android_context,
|
||||
std::shared_ptr<PlatformViewAndroidJNI> jni_facade)>;
|
||||
|
||||
virtual ~AndroidSurface();
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
@@ -38,6 +37,15 @@ class AndroidSurface {
|
||||
virtual bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) = 0;
|
||||
};
|
||||
|
||||
class AndroidSurfaceFactory {
|
||||
public:
|
||||
AndroidSurfaceFactory() = default;
|
||||
|
||||
virtual ~AndroidSurfaceFactory() = default;
|
||||
|
||||
virtual std::unique_ptr<AndroidSurface> CreateSurface() = 0;
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_H_
|
||||
|
||||
Reference in New Issue
Block a user