@@ -18,6 +18,25 @@ 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+ : AndroidSurfaceFactory(nullptr , nullptr ) {
27+ surface_producer_ = surface_producer;
28+ }
29+
30+ ~TestAndroidSurfaceFactory () override = default ;
31+
32+ std::unique_ptr<AndroidSurface> CreateSurface () override {
33+ return surface_producer_ ();
34+ }
35+
36+ private:
37+ TestSurfaceProducer surface_producer_;
38+ };
39+
2140TEST (SurfacePool, GetLayer__AllocateOneLayer) {
2241 auto pool = std::make_unique<SurfacePool>();
2342
@@ -33,14 +52,13 @@ TEST(SurfacePool, GetLayer__AllocateOneLayer) {
3352 0 , window))));
3453
3554 auto surface_factory =
36- [gr_context, window](std::shared_ptr<AndroidContext> android_context,
37- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
55+ std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
3856 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
3957 EXPECT_CALL (*android_surface_mock, CreateGPUSurface (gr_context.get ()));
4058 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
4159 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
4260 return android_surface_mock;
43- };
61+ }) ;
4462 auto layer = pool->GetLayer (gr_context.get (), android_context, jni_mock,
4563 surface_factory);
4664
@@ -64,14 +82,13 @@ TEST(SurfacePool, GetUnusedLayers) {
6482 0 , window))));
6583
6684 auto surface_factory =
67- [gr_context, window](std::shared_ptr<AndroidContext> android_context,
68- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
85+ std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
6986 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
7087 EXPECT_CALL (*android_surface_mock, CreateGPUSurface (gr_context.get ()));
7188 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
7289 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
7390 return android_surface_mock;
74- };
91+ }) ;
7592 auto layer = pool->GetLayer (gr_context.get (), android_context, jni_mock,
7693 surface_factory);
7794 ASSERT_EQ (0UL , pool->GetUnusedLayers ().size ());
@@ -97,10 +114,8 @@ TEST(SurfacePool, GetLayer__Recycle) {
97114 std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware );
98115
99116 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) {
117+ auto surface_factory = std::make_shared<TestAndroidSurfaceFactory>(
118+ [gr_context_1, gr_context_2, window]() {
104119 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
105120 // Allocate two GPU surfaces for each gr context.
106121 EXPECT_CALL (*android_surface_mock,
@@ -111,7 +126,7 @@ TEST(SurfacePool, GetLayer__Recycle) {
111126 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
112127 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
113128 return android_surface_mock;
114- };
129+ }) ;
115130 auto layer_1 = pool->GetLayer (gr_context_1.get (), android_context, jni_mock,
116131 surface_factory);
117132
@@ -147,14 +162,13 @@ TEST(SurfacePool, GetLayer__AllocateTwoLayers) {
147162 1 , window))));
148163
149164 auto surface_factory =
150- [gr_context, window](std::shared_ptr<AndroidContext> android_context,
151- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
165+ std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
152166 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
153167 EXPECT_CALL (*android_surface_mock, CreateGPUSurface (gr_context.get ()));
154168 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
155169 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
156170 return android_surface_mock;
157- };
171+ }) ;
158172 auto layer_1 = pool->GetLayer (gr_context.get (), android_context, jni_mock,
159173 surface_factory);
160174 auto layer_2 = pool->GetLayer (gr_context.get (), android_context, jni_mock,
@@ -185,14 +199,13 @@ TEST(SurfacePool, DestroyLayers) {
185199 0 , window))));
186200
187201 auto surface_factory =
188- [gr_context, window](std::shared_ptr<AndroidContext> android_context,
189- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
202+ std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
190203 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
191204 EXPECT_CALL (*android_surface_mock, CreateGPUSurface (gr_context.get ()));
192205 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
193206 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
194207 return android_surface_mock;
195- };
208+ }) ;
196209 pool->GetLayer (gr_context.get (), android_context, jni_mock, surface_factory);
197210
198211 EXPECT_CALL (*jni_mock, FlutterViewDestroyOverlaySurfaces ());
@@ -213,14 +226,13 @@ TEST(SurfacePool, DestroyLayers__frameSizeChanged) {
213226 auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr );
214227
215228 auto surface_factory =
216- [gr_context, window](std::shared_ptr<AndroidContext> android_context,
217- std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
229+ std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
218230 auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
219231 EXPECT_CALL (*android_surface_mock, CreateGPUSurface (gr_context.get ()));
220232 EXPECT_CALL (*android_surface_mock, SetNativeWindow (window));
221233 EXPECT_CALL (*android_surface_mock, IsValid ()).WillOnce (Return (true ));
222234 return android_surface_mock;
223- };
235+ }) ;
224236 pool->SetFrameSize (SkISize::Make (10 , 10 ));
225237 EXPECT_CALL (*jni_mock, FlutterViewDestroyOverlaySurfaces ()).Times (0 );
226238 EXPECT_CALL (*jni_mock, FlutterViewCreateOverlaySurface ())
0 commit comments