Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Package Functions | Package Attributes | List of all members
io.flutter.plugin.platform.VirtualDisplayController Class Reference

Classes

class  OneTimeOnDrawListener
 

Public Member Functions

int getRenderTargetWidth ()
 
int getRenderTargetHeight ()
 
void resize (final int width, final int height, final Runnable onNewSizeFrameAvailable)
 
void dispose ()
 
View getView ()
 
void dispatchTouchEvent (MotionEvent event)
 

Static Public Member Functions

static VirtualDisplayController create (Context context, AccessibilityEventsDelegate accessibilityEventsDelegate, PlatformView view, PlatformViewRenderTarget renderTarget, int width, int height, int viewId, Object createParams, OnFocusChangeListener focusChangeListener)
 

Package Functions

void onFlutterViewAttached (@NonNull View flutterView)
 
void onFlutterViewDetached ()
 
void onInputConnectionLocked ()
 
void onInputConnectionUnlocked ()
 

Package Attributes

SingleViewPresentation presentation
 

Detailed Description

Definition at line 23 of file VirtualDisplayController.java.

Member Function Documentation

◆ create()

static VirtualDisplayController io.flutter.plugin.platform.VirtualDisplayController.create ( Context  context,
AccessibilityEventsDelegate  accessibilityEventsDelegate,
PlatformView  view,
PlatformViewRenderTarget  renderTarget,
int  width,
int  height,
int  viewId,
Object  createParams,
OnFocusChangeListener  focusChangeListener 
)
inlinestatic

Definition at line 35 of file VirtualDisplayController.java.

44 {
45 if (width == 0 || height == 0) {
46 return null;
47 }
48
49 DisplayManager displayManager =
50 (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
51 final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
52
53 // Virtual Display crashes for some PlatformViews if the width or height is bigger
54 // than the physical screen size. We have tried to clamp or scale down the size to prevent
55 // the crash, but both solutions lead to unwanted behavior because the
56 // AndroidPlatformView(https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/platform_view.dart#L677) widget doesn't
57 // scale or clamp, which leads to a mismatch between the size of the widget and the size of
58 // virtual display.
59 // This mismatch leads to some test failures: https://github.com/flutter/flutter/issues/106750
60 // TODO(cyanglaz): find a way to prevent the crash without introducing size mistach betewen
61 // virtual display and AndroidPlatformView widget.
62 // https://github.com/flutter/flutter/issues/93115
63 renderTarget.resize(width, height);
64 int flags = 0;
65 VirtualDisplay virtualDisplay =
66 displayManager.createVirtualDisplay(
67 "flutter-vd#" + viewId,
68 width,
69 height,
70 metrics.densityDpi,
71 renderTarget.getSurface(),
72 flags,
73 callback,
74 null /* handler */);
75
76 if (virtualDisplay == null) {
77 return null;
78 }
79 VirtualDisplayController controller =
80 new VirtualDisplayController(
81 context,
82 accessibilityEventsDelegate,
83 virtualDisplay,
84 view,
85 renderTarget,
86 focusChangeListener,
87 viewId,
88 createParams);
89 return controller;
90 }
FlutterSemanticsFlag flags
int32_t height
int32_t width

◆ dispatchTouchEvent()

void io.flutter.plugin.platform.VirtualDisplayController.dispatchTouchEvent ( MotionEvent  event)
inline

Dispatches a motion event to the presentation for this controller.

Definition at line 282 of file VirtualDisplayController.java.

282 {
283 if (presentation == null) return;
284 presentation.dispatchTouchEvent(event);
285 }
FlKeyEvent * event

◆ dispose()

void io.flutter.plugin.platform.VirtualDisplayController.dispose ( )
inline

Definition at line 226 of file VirtualDisplayController.java.

226 {
227 // Fix rare crash on HuaWei device described in: https://github.com/flutter/engine/pull/9192
228 presentation.cancel();
230 virtualDisplay.release();
231 renderTarget.release();
232 }

◆ getRenderTargetHeight()

int io.flutter.plugin.platform.VirtualDisplayController.getRenderTargetHeight ( )
inline

Definition at line 137 of file VirtualDisplayController.java.

137 {
138 if (renderTarget != null) {
139 return renderTarget.getHeight();
140 }
141 return 0;
142 }

◆ getRenderTargetWidth()

int io.flutter.plugin.platform.VirtualDisplayController.getRenderTargetWidth ( )
inline

Definition at line 130 of file VirtualDisplayController.java.

130 {
131 if (renderTarget != null) {
132 return renderTarget.getWidth();
133 }
134 return 0;
135 }

◆ getView()

View io.flutter.plugin.platform.VirtualDisplayController.getView ( )
inline

Definition at line 275 of file VirtualDisplayController.java.

275 {
276 if (presentation == null) return null;
277 PlatformView platformView = presentation.getView();
278 return platformView.getView();
279 }

◆ onFlutterViewAttached()

void io.flutter.plugin.platform.VirtualDisplayController.onFlutterViewAttached ( @NonNull View  flutterView)
inlinepackage

See PlatformView#onFlutterViewAttached(View)

Definition at line 246 of file VirtualDisplayController.java.

246 {
247 if (presentation == null || presentation.getView() == null) {
248 return;
249 }
251 }
default void onFlutterViewAttached(@NonNull View flutterView)

◆ onFlutterViewDetached()

void io.flutter.plugin.platform.VirtualDisplayController.onFlutterViewDetached ( )
inlinepackage

See PlatformView#onFlutterViewDetached()

Definition at line 254 of file VirtualDisplayController.java.

254 {
255 if (presentation == null || presentation.getView() == null) {
256 return;
257 }
259 }

◆ onInputConnectionLocked()

void io.flutter.plugin.platform.VirtualDisplayController.onInputConnectionLocked ( )
inlinepackage

Definition at line 261 of file VirtualDisplayController.java.

261 {
262 if (presentation == null || presentation.getView() == null) {
263 return;
264 }
266 }

◆ onInputConnectionUnlocked()

void io.flutter.plugin.platform.VirtualDisplayController.onInputConnectionUnlocked ( )
inlinepackage

Definition at line 268 of file VirtualDisplayController.java.

268 {
269 if (presentation == null || presentation.getView() == null) {
270 return;
271 }
273 }

◆ resize()

void io.flutter.plugin.platform.VirtualDisplayController.resize ( final int  width,
final int  height,
final Runnable  onNewSizeFrameAvailable 
)
inline

Definition at line 144 of file VirtualDisplayController.java.

144 {
145 // When 'hot reload', although the resize method is triggered, the size of the native View has
146 // not changed.
148 getView().postDelayed(onNewSizeFrameAvailable, 0);
149 return;
150 }
151 if (Build.VERSION.SDK_INT >= API_LEVELS.API_31) {
152 resize31(getView(), width, height, onNewSizeFrameAvailable);
153 return;
154 }
155 boolean isFocused = getView().isFocused();
156 final SingleViewPresentation.PresentationState presentationState = presentation.detachState();
157 // We detach the surface to prevent it being destroyed when releasing the vd.
158 virtualDisplay.setSurface(null);
159 virtualDisplay.release();
160
161 final DisplayManager displayManager =
162 (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
163 renderTarget.resize(width, height);
164 int flags = 0;
165 virtualDisplay =
166 displayManager.createVirtualDisplay(
167 "flutter-vd#" + viewId,
168 width,
169 height,
170 densityDpi,
171 renderTarget.getSurface(),
172 flags,
173 callback,
174 null /* handler */);
175
176 final View embeddedView = getView();
177 // There's a bug in Android version older than O where view tree observer onDrawListeners don't
178 // get properly
179 // merged when attaching to window, as a workaround we register the on draw listener after the
180 // view is attached.
181 embeddedView.addOnAttachStateChangeListener(
182 new View.OnAttachStateChangeListener() {
183 @Override
184 public void onViewAttachedToWindow(View v) {
185 OneTimeOnDrawListener.schedule(
186 embeddedView,
187 new Runnable() {
188 @Override
189 public void run() {
190 // We need some delay here until the frame propagates through the vd surface to
191 // the texture,
192 // 128ms was picked pretty arbitrarily based on trial and error.
193 // As long as we invoke the runnable after a new frame is available we avoid the
194 // scaling jank
195 // described in: https://github.com/flutter/flutter/issues/19572
196 // We should ideally run onNewSizeFrameAvailable ASAP to make the embedded view
197 // more responsive
198 // following a resize.
199 embeddedView.postDelayed(onNewSizeFrameAvailable, 128);
200 }
201 });
202 embeddedView.removeOnAttachStateChangeListener(this);
203 }
204
205 @Override
206 public void onViewDetachedFromWindow(View v) {}
207 });
208
209 // Create a new SingleViewPresentation and show() it before we cancel() the existing
210 // presentation. Calling show() and cancel() in this order fixes
211 // https://github.com/flutter/flutter/issues/26345 and maintains seamless transition
212 // of the contents of the presentation.
213 SingleViewPresentation newPresentation =
214 new SingleViewPresentation(
215 context,
216 virtualDisplay.getDisplay(),
217 accessibilityEventsDelegate,
218 presentationState,
219 focusChangeListener,
220 isFocused);
221 newPresentation.show();
222 presentation.cancel();
223 presentation = newPresentation;
224 }
Build(configs, env, options)
Definition build.py:232

Member Data Documentation

◆ presentation

SingleViewPresentation io.flutter.plugin.platform.VirtualDisplayController.presentation
package

Definition at line 92 of file VirtualDisplayController.java.


The documentation for this class was generated from the following file: