• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.systemui.animation
2 
3 import android.view.View
4 import android.window.SurfaceSyncer
5 
6 /** A util class to synchronize 2 view roots. */
7 // TODO(b/200284684): Remove this class.
8 object ViewRootSync {
9     private var surfaceSyncer: SurfaceSyncer? = null
10 
11     /**
12      * Synchronize the next draw between the view roots of [view] and [otherView], then run [then].
13      *
14      * Note that in some cases, the synchronization might not be possible (e.g. WM consumed the next
15      * transactions) or disabled (temporarily, on low ram devices). In this case, [then] will be
16      * called without synchronizing.
17      */
synchronizeNextDrawnull18     fun synchronizeNextDraw(view: View, otherView: View, then: () -> Unit) {
19         if (
20             !view.isAttachedToWindow ||
21                 view.viewRootImpl == null ||
22                 !otherView.isAttachedToWindow ||
23                 otherView.viewRootImpl == null ||
24                 view.viewRootImpl == otherView.viewRootImpl
25         ) {
26             // No need to synchronize if either the touch surface or dialog view is not attached
27             // to a window.
28             then()
29             return
30         }
31 
32         surfaceSyncer =
33             SurfaceSyncer().apply {
34                 val syncId = setupSync(Runnable { then() })
35                 addToSync(syncId, view)
36                 addToSync(syncId, otherView)
37                 markSyncReady(syncId)
38             }
39     }
40 
41     /** A Java-friendly API for [synchronizeNextDraw]. */
42     @JvmStatic
synchronizeNextDrawnull43     fun synchronizeNextDraw(view: View, otherView: View, then: Runnable) {
44         synchronizeNextDraw(view, otherView, then::run)
45     }
46 }
47