This repository has been archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement PlatformViewsController. (#5722)
Each platform view created (by a plugin supplied factory) is attached to a virtual display. The virtual displays are controlled by VirtualDisplayController objects. The PlatformViewsController maintains a mapping from a platform view's id to its VirtualDisplayController, which allows it to operate on the virtual display for a given platform view ID when asked so over the method channel. This is using API level 20 APIs, on lower API levels all platform views method channel calls are noops. We can make this work on API 19 with some refactoring to the TextureRegistry (allow the engine Java code to recycle a texture entry id). This CL also adds a platform view id parameter to the PlatformViewFactory#create() method. This allows plugins to route platform channel messages to specific instances of a platform view. TBD in future CLs: * Forward touch events to the platform views. * Support accessibility for platform views. flutter/flutter#19030
- remove.1.2.3
- 3.28.0-1.0.pre
- 3.28.0-0.1.pre
- 3.27.4
- 3.27.3
- 3.27.2
- 3.27.1
- 3.27.0
- 3.27.0-0.2.pre
- 3.27.0-0.1.pre
- 3.26.0-0.1.pre
- 3.25.0-0.1.pre
- 3.24.5
- 3.24.4
- 3.24.3
- 3.24.2
- 3.24.1
- 3.24.0
- 3.24.0-0.2.pre
- 3.24.0-0.1.pre
- 3.24.0-0.0.pre
- 3.23.0-12.0.pre
- 3.23.0-11.0.pre
- 3.23.0-10.0.pre
- 3.23.0-9.0.pre
- 3.23.0-8.0.pre
- 3.23.0-7.0.pre
- 3.23.0-6.0.pre
- 3.23.0-5.0.pre
- 3.23.0-4.0.pre
- 3.23.0-3.0.pre
- 3.23.0-2.0.pre
- 3.23.0-1.0.pre
- 3.23.0-0.1.pre
- 3.23.0-0.0.pre
- 3.22.3
- 3.22.2
- 3.22.1
- 3.22.0
- 3.22.0-45.0.pre
- 3.22.0-44.0.pre
- 3.22.0-43.0.pre
- 3.22.0-42.0.pre
- 3.22.0-41.0.pre
- 3.22.0-40.0.pre
- 3.22.0-39.0.pre
- 3.22.0-38.0.pre
- 3.22.0-37.0.pre
- 3.22.0-35.0.pre
- 3.22.0-34.0.pre
- 3.22.0-33.0.pre
- 3.22.0-32.0.pre
- 3.22.0-31.0.pre
- 3.22.0-30.0.pre
- 3.22.0-29.0.pre
- 3.22.0-28.0.pre
- 3.22.0-27.0.pre
- 3.22.0-26.0.pre
- 3.22.0-25.0.pre
- 3.22.0-24.0.pre
- 3.22.0-23.0.pre
- 3.22.0-22.0.pre
- 3.22.0-21.0.pre
- 3.22.0-20.0.pre
- 3.22.0-19.0.pre
- 3.22.0-18.0.pre
- 3.22.0-17.0.pre
- 3.22.0-15.0.pre
- 3.22.0-14.0.pre
- 3.22.0-13.0.pre
- 3.22.0-12.0.pre
- 3.22.0-11.0.pre
- 3.22.0-10.0.pre
- 3.22.0-9.0.pre
- 3.22.0-8.0.pre
- 3.22.0-7.0.pre
- 3.22.0-6.0.pre
- 3.22.0-5.0.pre
- 3.22.0-4.0.pre
- 3.22.0-3.0.pre
- 3.22.0-2.0.pre
- 3.22.0-1.0.pre
- 3.22.0-0.3.pre
- 3.22.0-0.2.pre
- 3.22.0-0.1.pre
- 3.22.0-0.0.pre
- 3.21.0-16.0.pre
- 3.21.0-15.0.pre
- 3.21.0-14.0.pre
- 3.21.0-13.0.pre
- 3.21.0-12.0.pre
- 3.21.0-11.0.pre
- 3.21.0-10.0.pre
- 3.21.0-9.0.pre
- 3.21.0-8.0.pre
- 3.21.0-7.0.pre
- 3.21.0-6.0.pre
- 3.21.0-4.0.pre
- 3.21.0-3.0.pre
- 3.21.0-1.0.pre
- 3.21.0-0.1.pre
- 3.21.0-0.0.pre
- 3.20.0-16.0.pre
- 3.20.0-15.0.pre
- 3.20.0-14.0.pre
- 3.20.0-12.0.pre
- 3.20.0-11.0.pre
- 3.20.0-10.0.pre
- 3.20.0-9.0.pre
- 3.20.0-8.0.pre
- 3.20.0-6.0.pre
- 3.20.0-5.0.pre
- 3.20.0-3.0.pre
- 3.20.0-2.0.pre
- 3.20.0-1.2.pre
- 3.20.0-1.1.pre
- 3.20.0-1.0.pre
- 3.20.0-0.0.pre
- 3.19.6
- 3.19.5
- 3.19.4
- 3.19.3
- 3.19.2
- 3.19.1
- 3.19.0
- 3.19.0-14.0.pre
- 3.19.0-13.0.pre
- 3.19.0-12.0.pre
- 3.19.0-10.0.pre
- 3.19.0-9.0.pre
- 3.19.0-8.0.pre
- 3.19.0-7.0.pre
- 3.19.0-6.0.pre
- 3.19.0-5.0.pre
- 3.19.0-4.0.pre
- 3.19.0-3.0.pre
- 3.19.0-2.0.pre
- 3.19.0-1.0.pre
- 3.19.0-0.4.pre
- 3.19.0-0.3.pre
- 3.19.0-0.2.pre
- 3.19.0-0.1.pre
- 3.18.0-18.0.pre
- 3.18.0-17.0.pre
- 3.18.0-13.0.pre
- 3.18.0-10.0.pre
- 3.18.0-6.0.pre
- 3.18.0-4.0.pre
- 3.18.0-2.0.pre
- 3.18.0-1.0.pre
- 3.18.0-0.2.pre
- 3.18.0-0.1.pre
- 3.18.0-0.0.pre
- 3.17.0-19.0.pre
- 3.17.0-18.0.pre
- 3.17.0-17.0.pre
- 3.17.0-16.0.pre
- 3.17.0-15.0.pre
- 3.17.0-14.0.pre
- 3.17.0-13.0.pre
- 3.17.0-12.0.pre
- 3.17.0-11.0.pre
- 3.17.0-10.0.pre
- 3.17.0-9.0.pre
- 3.17.0-8.0.pre
- 3.17.0-4.0.pre
- 3.17.0-3.0.pre
- 3.17.0-2.0.pre
- 3.17.0-1.0.pre
- 3.17.0-0.1.pre
- 3.17.0-0.0.pre
- 3.16.9
- 3.16.8
- 3.16.7
- 3.16.6
- 3.16.5
- 3.16.4
- 3.16.3
- 3.16.2
- 3.16.1
- 3.16.0
- 3.16.0-22.0.pre
- 3.16.0-21.0.pre
- 3.16.0-20.0.pre
- 3.16.0-19.0.pre
- 3.16.0-17.0.pre
- 3.16.0-16.0.pre
- 3.16.0-14.0.pre
- 3.16.0-13.0.pre
- 3.16.0-12.0.pre
- 3.16.0-11.0.pre
- 3.16.0-10.0.pre
- 3.16.0-9.0.pre
- 3.16.0-8.0.pre
- 3.16.0-7.0.pre
- 3.16.0-6.0.pre
- 3.16.0-5.0.pre
- 3.16.0-4.0.pre
- 3.16.0-2.0.pre
- 3.16.0-1.0.pre
- 3.16.0-0.5.pre
- 3.16.0-0.4.pre
- 3.16.0-0.3.pre
- 3.16.0-0.2.pre
- 3.16.0-0.1.pre
- 3.16.0-0.0.pre
- 3.15.0-15.2.pre
- 3.15.0-15.1.pre
- 3.15.0-12.0.pre
- 3.15.0-10.0.pre
- 3.15.0-9.0.pre
- 3.15.0-8.0.pre
- 3.15.0-7.0.pre
- 3.15.0-6.0.pre
- 3.15.0-5.0.pre
- 3.15.0-4.0.pre
- 3.15.0-3.0.pre
- 3.15.0-2.0.pre
- 3.15.0-1.0.pre
- 3.15.0-0.0.pre
- 3.14.0-14.0.pre
- 3.14.0-13.0.pre
- 3.14.0-12.0.pre
- 3.14.0-11.0.pre
- 3.14.0-8.0.pre
- 3.14.0-7.0.pre
- 3.14.0-6.0.pre
- 3.14.0-5.0.pre
- 3.14.0-4.0.pre
- 3.14.0-3.0.pre
- 3.14.0-2.0.pre
- 3.14.0-1.0.pre
- 3.14.0-0.2.pre
- 3.14.0-0.1.pre
- 3.14.0-0.0.pre
- 3.13.9
- 3.13.8
- 3.13.7
- 3.13.6
- 3.13.5
- 3.13.4
- 3.13.3
- 3.13.2
- 3.13.1
- 3.13.0
- 3.13.0-18.0.pre
- 3.13.0-17.0.pre
- 3.13.0-16.0.pre
- 3.13.0-15.0.pre
- 3.13.0-14.0.pre
- 3.13.0-13.0.pre
- 3.13.0-12.0.pre
- 3.13.0-11.0.pre
- 3.13.0-10.0.pre
- 3.13.0-9.0.pre
- 3.13.0-8.0.pre
- 3.13.0-7.0.pre
- 3.13.0-6.0.pre
- 3.13.0-5.0.pre
- 3.13.0-4.0.pre
- 3.13.0-3.0.pre
- 3.13.0-2.0.pre
- 3.13.0-1.0.pre
- 3.13.0-0.4.pre
- 3.13.0-0.3.pre
- 3.13.0-0.2.pre
- 3.13.0-0.1.pre
- 3.13.0-0.0.pre
- 3.12.0
- 3.12.0-14.0.pre
- 3.12.0-13.0.pre
- 3.12.0-12.0.pre
- 3.12.0-11.0.pre
- 3.12.0-10.0.pre
- 3.12.0-9.0.pre
- 3.12.0-8.0.pre
- 3.12.0-7.0.pre
- 3.12.0-6.0.pre
- 3.12.0-3.0.pre
- 3.12.0-2.0.pre
- 3.12.0-1.1.pre
- 3.12.0-1.0.pre
- 3.12.0-0.0.pre
- 3.11.0-19.0.pre
- 3.11.0-17.0.pre
- 3.11.0-15.0.pre
- 3.11.0-14.0.pre
- 3.11.0-13.0.pre
- 3.11.0-12.0.pre
- 3.11.0-11.0.pre
- 3.11.0-10.0.pre
- 3.11.0-9.0.pre
- 3.11.0-5.0.pre
- 3.11.0-4.0.pre
- 3.11.0-1.0.pre
- 3.11.0-0.1.pre
- 3.11.0-0.0.pre
- 3.10.7
- 3.10.6
- 3.10.5
- 3.10.4
- 3.10.3
- 3.10.2
- 3.10.1
- 3.10.0
- 3.10.0-18.0.pre
- 3.10.0-17.0.pre
- 3.10.0-16.0.pre
- 3.10.0-15.0.pre
- 3.10.0-14.0.pre
- 3.10.0-13.0.pre
- 3.10.0-11.0.pre
- 3.10.0-9.0.pre
- 3.10.0-8.0.pre
- 3.10.0-7.0.pre
- 3.10.0-6.0.pre
- 3.10.0-5.0.pre
- 3.10.0-4.0.pre
- 3.10.0-3.0.pre
- 3.10.0-2.0.pre
- 3.10.0-1.5.pre
- 3.10.0-1.4.pre
- 3.10.0-1.3.pre
- 3.10.0-1.0.pre
- 3.9.0-21.0.pre
- 3.9.0-20.0.pre
- 3.9.0-19.0.pre
- 3.9.0-18.0.pre
- 3.9.0-17.0.pre
- 3.9.0-16.0.pre
- 3.9.0-15.0.pre
- 3.9.0-14.0.pre
- 3.9.0-12.0.pre
- 3.9.0-11.0.pre
- 3.9.0-10.0.pre
- 3.9.0-9.0.pre
- 3.9.0-8.0.pre
- 3.9.0-7.0.pre
- 3.9.0-6.0.pre
- 3.9.0-0.2.pre
- 3.9.0-0.0.pre
- 3.8.0-18.0.pre
- 3.8.0-17.0.pre
- 3.8.0-16.0.pre
- 3.8.0-15.0.pre
- 3.8.0-14.0.pre
- 3.8.0-13.0.pre
- 3.8.0-12.0.pre
- 3.8.0-11.0.pre
- 3.8.0-10.1.pre
- 3.8.0-10.0.pre
- 3.8.0-9.0.pre
- 3.8.0-8.0.pre
- 3.8.0-7.0.pre
- 3.8.0-6.0.pre
- 3.8.0-5.0.pre
- 3.8.0-4.0.pre
- 3.8.0-3.0.pre
- 3.8.0-2.0.pre
- 3.8.0-1.0.pre
- 3.8.0-0.0.pre
- 3.7.12
- 3.7.10
- 3.7.9
- 3.7.8
- 3.7.7
- 3.7.6
- 3.7.5
- 3.7.4
- 3.7.0-31.0.pre
- 3.7.0-30.0.pre
- 3.7.0-29.0.pre
- 3.7.0-28.0.pre
- 3.7.0-27.0.pre
- 3.7.0-26.0.pre
- 3.7.0-25.0.pre
- 3.7.0-24.0.pre
Showing
7 changed files
with
298 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugin.platform; | ||
|
||
import android.annotation.TargetApi; | ||
import android.app.Presentation; | ||
import android.content.Context; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.view.Display; | ||
import android.widget.FrameLayout; | ||
|
||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) | ||
class SingleViewPresentation extends Presentation { | ||
private final PlatformViewFactory mViewFactory; | ||
|
||
private PlatformView mView; | ||
private int mViewId; | ||
|
||
// As the root view of a display cannot be detached, we use this mContainer | ||
// as the root, and attach mView to it. This allows us to detach mView. | ||
private FrameLayout mContainer; | ||
|
||
/** | ||
* Creates a presentation that will use the view factory to create a new | ||
* platform view in the presentation's onCreate, and attach it. | ||
*/ | ||
public SingleViewPresentation(Context outerContext, Display display, PlatformViewFactory viewFactory, int viewId) { | ||
super(outerContext, display); | ||
mViewFactory = viewFactory; | ||
mViewId = viewId; | ||
} | ||
|
||
/** | ||
* Creates a presentation that will attach an already existing view as | ||
* its root view. | ||
* | ||
* <p>The display's density must match the density of the context used | ||
* when the view was created. | ||
*/ | ||
public SingleViewPresentation(Context outerContext, Display display, PlatformView view) { | ||
super(outerContext, display); | ||
mViewFactory = null; | ||
mView = view; | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
if (mView == null) { | ||
mView = mViewFactory.create(getContext(), mViewId); | ||
} | ||
mContainer = new FrameLayout(getContext()); | ||
mContainer.addView(mView.getView()); | ||
setContentView(mContainer); | ||
} | ||
|
||
public PlatformView detachView() { | ||
mContainer.removeView(mView.getView()); | ||
return mView; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugin.platform; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Context; | ||
import android.graphics.SurfaceTexture; | ||
import android.hardware.display.DisplayManager; | ||
import android.hardware.display.VirtualDisplay; | ||
import android.os.Build; | ||
import android.view.Surface; | ||
import android.view.View; | ||
|
||
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH) | ||
class VirtualDisplayController { | ||
|
||
public static VirtualDisplayController create( | ||
Context context, | ||
PlatformViewFactory viewFactory, | ||
SurfaceTexture surfaceTexture, | ||
int width, | ||
int height, | ||
int viewId | ||
) { | ||
surfaceTexture.setDefaultBufferSize(width, height); | ||
Surface surface = new Surface(surfaceTexture); | ||
DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); | ||
|
||
int densityDpi = context.getResources().getDisplayMetrics().densityDpi; | ||
VirtualDisplay virtualDisplay = displayManager.createVirtualDisplay( | ||
"flutter-vd", | ||
width, | ||
height, | ||
densityDpi, | ||
surface, | ||
0 | ||
); | ||
|
||
if (virtualDisplay == null) { | ||
return null; | ||
} | ||
|
||
return new VirtualDisplayController(context, virtualDisplay, viewFactory, surface, surfaceTexture, viewId); | ||
} | ||
|
||
private final Context mContext; | ||
private final int mDensityDpi; | ||
private final SurfaceTexture mSurfaceTexture; | ||
private VirtualDisplay mVirtualDisplay; | ||
private SingleViewPresentation mPresentation; | ||
private Surface mSurface; | ||
|
||
|
||
private VirtualDisplayController( | ||
Context context, | ||
VirtualDisplay virtualDisplay, | ||
PlatformViewFactory viewFactory, | ||
Surface surface, | ||
SurfaceTexture surfaceTexture, | ||
int viewId | ||
) { | ||
mSurfaceTexture = surfaceTexture; | ||
mSurface = surface; | ||
mContext = context; | ||
mVirtualDisplay = virtualDisplay; | ||
mDensityDpi = context.getResources().getDisplayMetrics().densityDpi; | ||
mPresentation = new SingleViewPresentation(context, mVirtualDisplay.getDisplay(), viewFactory, viewId); | ||
mPresentation.show(); | ||
} | ||
|
||
public void resize(int width, int height) { | ||
PlatformView view = mPresentation.detachView(); | ||
mPresentation.hide(); | ||
// We detach the surface to prevent it being destroyed when releasing the vd. | ||
// | ||
// setSurface is only available starting API 20. We could support API 19 by re-creating a new | ||
// SurfaceTexture here. This will require refactoring the TextureRegistry to allow recycling texture | ||
// entry IDs. | ||
mVirtualDisplay.setSurface(null); | ||
mVirtualDisplay.release(); | ||
|
||
mSurfaceTexture.setDefaultBufferSize(width, height); | ||
DisplayManager displayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE); | ||
mVirtualDisplay = displayManager.createVirtualDisplay( | ||
"flutter-vd", | ||
width, | ||
height, | ||
mDensityDpi, | ||
mSurface, | ||
0 | ||
); | ||
mPresentation = new SingleViewPresentation(mContext, mVirtualDisplay.getDisplay(), view); | ||
mPresentation.show(); | ||
} | ||
|
||
public void dispose() { | ||
mPresentation.detachView().dispose(); | ||
mVirtualDisplay.release(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters