@@ -18,6 +18,24 @@ namespace testing {
1818using ::testing::ByMove;
1919using ::testing::Return;
2020
21+ class TestAndroidSurfaceFactory : public AndroidSurfaceFactory {
22+ public:
23+ using TestSurfaceProducer =
24+ std::function<std::unique_ptr<AndroidSurface>(void )>;
25+ explicit TestAndroidSurfaceFactory (TestSurfaceProducer&& surface_producer) {
26+ surface_producer_ = surface_producer;
27+ }
28+
29+ ~TestAndroidSurfaceFactory () override = default ;
30+
31+ std::unique_ptr<AndroidSurface> CreateSurface () override {
32+ return surface_producer_ ();
33+ }
34+
35+ private:
36+ TestSurfaceProducer surface_producer_;
37+ };
38+
2139TEST (SurfacePool, GetLayer__AllocateOneLayer) {
2240 auto pool = std::make_unique<SurfacePool>();
2341
@@ -33,14 +51,13 @@ TEST(SurfacePool, GetLayer__AllocateOneLayer) {
3351 0 , window))));
3452
3553 auto surface_factory =
36- [gr_context, window](std::shared_ptr<AndroidContext> android_context,
37- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
54+ std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
3855 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
3956 EXPECT_CALL (*android_surface_mock, CreateGPUSurface (gr_context.get ()));
4057 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
4158 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
4259 return android_surface_mock;
43- };
60+ }) ;
4461 auto layer = pool->GetLayer (gr_context.get (), android_context, jni_mock,
4562 surface_factory);
4663
@@ -64,14 +81,13 @@ TEST(SurfacePool, GetUnusedLayers) {
6481 0 , window))));
6582
6683 auto surface_factory =
67- [gr_context, window](std::shared_ptr<AndroidContext> android_context,
68- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
84+ std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
6985 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
7086 EXPECT_CALL (*android_surface_mock, CreateGPUSurface (gr_context.get ()));
7187 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
7288 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
7389 return android_surface_mock;
74- };
90+ }) ;
7591 auto layer = pool->GetLayer (gr_context.get (), android_context, jni_mock,
7692 surface_factory);
7793 ASSERT_EQ (0UL , pool->GetUnusedLayers ().size ());
@@ -97,10 +113,8 @@ TEST(SurfacePool, GetLayer__Recycle) {
97113 std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware );
98114
99115 auto gr_context_2 = GrDirectContext::MakeMock (nullptr );
100- auto surface_factory =
101- [gr_context_1, gr_context_2, window](
102- std::shared_ptr<AndroidContext> android_context,
103- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
116+ auto surface_factory = std::make_shared<TestAndroidSurfaceFactory>(
117+ [gr_context_1, gr_context_2, window]() {
104118 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
105119 // Allocate two GPU surfaces for each gr context.
106120 EXPECT_CALL (*android_surface_mock,
@@ -111,7 +125,7 @@ TEST(SurfacePool, GetLayer__Recycle) {
111125 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
112126 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
113127 return android_surface_mock;
114- };
128+ }) ;
115129 auto layer_1 = pool->GetLayer (gr_context_1.get (), android_context, jni_mock,
116130 surface_factory);
117131
@@ -147,14 +161,13 @@ TEST(SurfacePool, GetLayer__AllocateTwoLayers) {
147161 1 , window))));
148162
149163 auto surface_factory =
150- [gr_context, window](std::shared_ptr<AndroidContext> android_context,
151- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
164+ std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
152165 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
153166 EXPECT_CALL (*android_surface_mock, CreateGPUSurface (gr_context.get ()));
154167 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
155168 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
156169 return android_surface_mock;
157- };
170+ }) ;
158171 auto layer_1 = pool->GetLayer (gr_context.get (), android_context, jni_mock,
159172 surface_factory);
160173 auto layer_2 = pool->GetLayer (gr_context.get (), android_context, jni_mock,
@@ -185,14 +198,13 @@ TEST(SurfacePool, DestroyLayers) {
185198 0 , window))));
186199
187200 auto surface_factory =
188- [gr_context, window](std::shared_ptr<AndroidContext> android_context,
189- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
201+ std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
190202 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
191203 EXPECT_CALL (*android_surface_mock, CreateGPUSurface (gr_context.get ()));
192204 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
193205 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
194206 return android_surface_mock;
195- };
207+ }) ;
196208 pool->GetLayer (gr_context.get (), android_context, jni_mock, surface_factory);
197209
198210 EXPECT_CALL (*jni_mock, FlutterViewDestroyOverlaySurfaces ());
@@ -213,14 +225,13 @@ TEST(SurfacePool, DestroyLayers__frameSizeChanged) {
213225 auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr );
214226
215227 auto surface_factory =
216- [gr_context, window](std::shared_ptr<AndroidContext> android_context,
217- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
228+ std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
218229 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
219230 EXPECT_CALL (*android_surface_mock, CreateGPUSurface (gr_context.get ()));
220231 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
221232 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
222233 return android_surface_mock;
223- };
234+ }) ;
224235 pool->SetFrameSize (SkISize::Make (10 , 10 ));
225236 EXPECT_CALL (*jni_mock, FlutterViewDestroyOverlaySurfaces ()).Times (0 );
226237 EXPECT_CALL (*jni_mock, FlutterViewCreateOverlaySurface ())
0 commit comments