Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions shell/platform/android/android_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 5 additions & 4 deletions shell/platform/android/android_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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_;
Expand Down
7 changes: 2 additions & 5 deletions shell/platform/android/android_surface_software.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down
9 changes: 5 additions & 4 deletions shell/platform/android/android_surface_software.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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_;
Expand Down
7 changes: 2 additions & 5 deletions shell/platform/android/android_surface_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions shell/platform/android/android_surface_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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_;

Expand Down
1 change: 1 addition & 0 deletions shell/platform/android/external_view_embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(
Expand Down Expand Up @@ -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_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/android/external_view_embedder/surface_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading