@@ -114,24 +114,30 @@ public void reparentToSurface(Surface parentSurface, int width, int height) {
114114 try {
115115 synchronized (transaction ) {
116116 if (parentSurface == null ) {
117- // Hide the video surface
117+ // Hide the video surface by reparenting to null
118118 transaction
119119 .reparent (surfaceControl , null )
120120 .setBufferSize (surfaceControl , 0 , 0 )
121121 .setVisibility (surfaceControl , false );
122+ android .util .Log .v ("SurfaceControlHelper" , "Video surface hidden using SurfaceControl reparenting" );
122123 } else {
123- // Get the SurfaceControl from the parent surface and reparent our video surface to it
124- SurfaceControl parentSurfaceControl = parentSurface .getSurfaceControl ();
124+ // For now, since we can't reliably get SurfaceControl from arbitrary Surface objects,
125+ // we'll use a hybrid approach: set optimal buffer size and show the surface,
126+ // but fall back to standard surface switching for the actual targeting
125127 transaction
126- .reparent (surfaceControl , parentSurfaceControl )
127128 .setBufferSize (surfaceControl , width , height )
128129 .setVisibility (surfaceControl , true );
130+ transaction .apply ();
131+
132+ // Use standard surface switching for targeting the new surface
133+ switchToSurface (parentSurface );
134+ android .util .Log .v ("SurfaceControlHelper" , "Surface switched with SurfaceControl optimizations (buffer size: " + width + "x" + height + ")" );
135+ return ;
129136 }
130137 transaction .apply ();
131138 }
132- android .util .Log .v ("SurfaceControlHelper" , "Surface reparented successfully using SurfaceControl" );
133139 } catch (Exception e ) {
134- android .util .Log .w ("SurfaceControlHelper" , "SurfaceControl reparent failed, falling back to standard method" , e );
140+ android .util .Log .w ("SurfaceControlHelper" , "SurfaceControl operation failed, falling back to standard method" , e );
135141 // Fallback to legacy method
136142 switchToSurface (parentSurface );
137143 }
0 commit comments