77
88import android .content .Context ;
99import android .content .res .AssetManager ;
10+ import android .graphics .SurfaceTexture ;
1011import android .util .SparseArray ;
1112import android .view .MotionEvent ;
1213import android .view .Surface ;
1314import android .view .SurfaceHolder ;
1415import android .view .SurfaceView ;
1516import android .view .View ;
1617import android .view .ViewParent ;
18+ import android .widget .FrameLayout .LayoutParams ;
1719import io .flutter .embedding .android .FlutterImageView ;
1820import io .flutter .embedding .android .FlutterView ;
1921import io .flutter .embedding .android .MotionEventTracker ;
3234import io .flutter .plugin .common .MethodCall ;
3335import io .flutter .plugin .common .StandardMethodCodec ;
3436import io .flutter .plugin .localization .LocalizationPlugin ;
37+ import io .flutter .view .TextureRegistry ;
3538import java .nio .ByteBuffer ;
3639import java .util .Arrays ;
3740import java .util .HashMap ;
@@ -232,7 +235,7 @@ public void getPlatformViewById__hybridComposition() {
232235 attach (jni , platformViewsController );
233236
234237 // Simulate create call from the framework.
235- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
238+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
236239
237240 platformViewsController .initializePlatformViewIfNeeded (platformViewId );
238241
@@ -259,7 +262,7 @@ public void createPlatformViewMessage__initializesAndroidView() {
259262 attach (jni , platformViewsController );
260263
261264 // Simulate create call from the framework.
262- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
265+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
263266 verify (viewFactory , times (1 )).create (any (), eq (platformViewId ), any ());
264267 }
265268
@@ -281,7 +284,7 @@ public void createPlatformViewMessage__throwsIfViewIsNull() {
281284 attach (jni , platformViewsController );
282285
283286 // Simulate create call from the framework.
284- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
287+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
285288 assertEquals (ShadowFlutterJNI .getResponses ().size (), 1 );
286289
287290 assertThrows (
@@ -301,15 +304,20 @@ public void onDetachedFromJNI_clearsPlatformViewContext() {
301304
302305 PlatformViewFactory viewFactory = mock (PlatformViewFactory .class );
303306 PlatformView platformView = mock (PlatformView .class );
304- when (platformView .getView ()).thenReturn (null );
307+
308+ View pv = mock (View .class );
309+ when (pv .getLayoutParams ()).thenReturn (new LayoutParams (1 , 1 ));
310+
311+ when (platformView .getView ()).thenReturn (pv );
305312 when (viewFactory .create (any (), eq (platformViewId ), any ())).thenReturn (platformView );
306313 platformViewsController .getRegistry ().registerViewFactory ("testType" , viewFactory );
307314
308315 FlutterJNI jni = new FlutterJNI ();
309316 attach (jni , platformViewsController );
310317
311318 // Simulate create call from the framework.
312- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
319+ createPlatformView (
320+ jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ false );
313321
314322 assertFalse (platformViewsController .contextToPlatformView .isEmpty ());
315323 platformViewsController .onDetachedFromJNI ();
@@ -326,15 +334,20 @@ public void onPreEngineRestart_clearsPlatformViewContext() {
326334
327335 PlatformViewFactory viewFactory = mock (PlatformViewFactory .class );
328336 PlatformView platformView = mock (PlatformView .class );
329- when (platformView .getView ()).thenReturn (null );
337+
338+ View pv = mock (View .class );
339+ when (pv .getLayoutParams ()).thenReturn (new LayoutParams (1 , 1 ));
340+
341+ when (platformView .getView ()).thenReturn (pv );
330342 when (viewFactory .create (any (), eq (platformViewId ), any ())).thenReturn (platformView );
331343 platformViewsController .getRegistry ().registerViewFactory ("testType" , viewFactory );
332344
333345 FlutterJNI jni = new FlutterJNI ();
334346 attach (jni , platformViewsController );
335347
336348 // Simulate create call from the framework.
337- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
349+ createPlatformView (
350+ jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ false );
338351
339352 assertFalse (platformViewsController .contextToPlatformView .isEmpty ());
340353 platformViewsController .onDetachedFromJNI ();
@@ -361,7 +374,7 @@ public void createPlatformViewMessage__throwsIfViewHasParent() {
361374 attach (jni , platformViewsController );
362375
363376 // Simulate create call from the framework.
364- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
377+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
365378 assertEquals (ShadowFlutterJNI .getResponses ().size (), 1 );
366379
367380 assertThrows (
@@ -393,7 +406,7 @@ public void disposeAndroidView__hybridComposition() {
393406 attach (jni , platformViewsController );
394407
395408 // Simulate create call from the framework.
396- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
409+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
397410 platformViewsController .initializePlatformViewIfNeeded (platformViewId );
398411
399412 assertNotNull (androidView .getParent ());
@@ -404,7 +417,7 @@ public void disposeAndroidView__hybridComposition() {
404417 assertNull (androidView .getParent ());
405418
406419 // Simulate create call from the framework.
407- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
420+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
408421 platformViewsController .initializePlatformViewIfNeeded (platformViewId );
409422
410423 assertNotNull (androidView .getParent ());
@@ -434,7 +447,7 @@ public void onEndFrame__destroysOverlaySurfaceAfterFrameOnFlutterSurfaceView() {
434447 jni .onFirstFrame ();
435448
436449 // Simulate create call from the framework.
437- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
450+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
438451
439452 // Produce a frame that displays a platform view and an overlay surface.
440453 platformViewsController .onBeginFrame ();
@@ -497,7 +510,7 @@ public void onEndFrame__removesPlatformView() {
497510 jni .onFirstFrame ();
498511
499512 // Simulate create call from the framework.
500- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
513+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
501514
502515 // Simulate first frame from the framework.
503516 jni .onFirstFrame ();
@@ -534,7 +547,7 @@ public void onEndFrame__removesPlatformViewParent() {
534547 jni .onFirstFrame ();
535548
536549 // Simulate create call from the framework.
537- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
550+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
538551 platformViewsController .initializePlatformViewIfNeeded (platformViewId );
539552 assertEquals (flutterView .getChildCount (), 2 );
540553
@@ -570,7 +583,7 @@ public void detach__destroysOverlaySurfaces() {
570583 jni .onFirstFrame ();
571584
572585 // Simulate create call from the framework.
573- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
586+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
574587
575588 // Produce a frame that displays a platform view and an overlay surface.
576589 platformViewsController .onBeginFrame ();
@@ -703,7 +716,7 @@ public void convertPlatformViewRenderSurfaceAsDefault() {
703716 jni .onFirstFrame ();
704717
705718 // Simulate create call from the framework.
706- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
719+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
707720
708721 // Produce a frame that displays a platform view and an overlay surface.
709722 platformViewsController .onBeginFrame ();
@@ -752,7 +765,7 @@ public void dontConverRenderSurfaceWhenFlagIsTrue() {
752765 synchronizeToNativeViewHierarchy (jni , platformViewsController , false );
753766
754767 // Simulate create call from the framework.
755- createPlatformView (jni , platformViewsController , platformViewId , "testType" );
768+ createPlatformView (jni , platformViewsController , platformViewId , "testType" , /* hybrid=*/ true );
756769
757770 // Produce a frame that displays a platform view and an overlay surface.
758771 platformViewsController .onBeginFrame ();
@@ -784,12 +797,16 @@ private static void createPlatformView(
784797 FlutterJNI jni ,
785798 PlatformViewsController platformViewsController ,
786799 int platformViewId ,
787- String viewType ) {
800+ String viewType ,
801+ boolean hybrid ) {
788802 final Map <String , Object > platformViewCreateArguments = new HashMap <>();
789- platformViewCreateArguments .put ("hybrid" , true );
803+ platformViewCreateArguments .put ("hybrid" , hybrid );
790804 platformViewCreateArguments .put ("id" , platformViewId );
791805 platformViewCreateArguments .put ("viewType" , viewType );
792806 platformViewCreateArguments .put ("direction" , 0 );
807+ platformViewCreateArguments .put ("width" , 1.0 );
808+ platformViewCreateArguments .put ("height" , 1.0 );
809+
793810 final MethodCall platformCreateMethodCall =
794811 new MethodCall ("create" , platformViewCreateArguments );
795812
@@ -826,7 +843,30 @@ private static FlutterView attach(
826843 executor .onAttachedToJNI ();
827844
828845 final Context context = RuntimeEnvironment .application .getApplicationContext ();
829- platformViewsController .attach (context , null , executor );
846+ final TextureRegistry registry =
847+ new TextureRegistry () {
848+ public void TextureRegistry () {}
849+
850+ @ Override
851+ public SurfaceTextureEntry createSurfaceTexture () {
852+ return new SurfaceTextureEntry () {
853+ @ Override
854+ public SurfaceTexture surfaceTexture () {
855+ return mock (SurfaceTexture .class );
856+ }
857+
858+ @ Override
859+ public long id () {
860+ return 0 ;
861+ }
862+
863+ @ Override
864+ public void release () {}
865+ };
866+ }
867+ };
868+
869+ platformViewsController .attach (context , registry , executor );
830870
831871 final FlutterView view =
832872 new FlutterView (context , FlutterView .RenderMode .surface ) {
0 commit comments