summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/sidecar/SettingsSidecarImpl.java6
-rw-r--r--libs/WindowManager/Shell/Android.bp94
-rw-r--r--libs/WindowManager/Shell/proto/wm_shell_trace.proto27
-rw-r--r--libs/WindowManager/Shell/res/anim/forced_resizable_enter.xml21
-rw-r--r--libs/WindowManager/Shell/res/anim/forced_resizable_exit.xml22
-rw-r--r--libs/WindowManager/Shell/res/anim/tv_pip_controls_focus_gain_animation.xml20
-rw-r--r--libs/WindowManager/Shell/res/anim/tv_pip_controls_focus_loss_animation.xml20
-rw-r--r--libs/WindowManager/Shell/res/anim/tv_pip_menu_fade_in_animation.xml20
-rw-r--r--libs/WindowManager/Shell/res/anim/tv_pip_menu_fade_out_animation.xml20
-rw-r--r--libs/WindowManager/Shell/res/drawable-hdpi/one_handed_tutorial.pngbin0 -> 1766 bytes
-rw-r--r--libs/WindowManager/Shell/res/drawable/floating_dismiss_gradient.xml25
-rw-r--r--libs/WindowManager/Shell/res/drawable/floating_dismiss_gradient_transition.xml20
-rw-r--r--libs/WindowManager/Shell/res/drawable/pip_expand.xml28
-rw-r--r--libs/WindowManager/Shell/res/drawable/pip_ic_close_white.xml25
-rw-r--r--libs/WindowManager/Shell/res/drawable/pip_ic_fullscreen_white.xml25
-rw-r--r--libs/WindowManager/Shell/res/drawable/pip_ic_pause_white.xml26
-rw-r--r--libs/WindowManager/Shell/res/drawable/pip_ic_play_arrow_white.xml26
-rw-r--r--libs/WindowManager/Shell/res/drawable/pip_ic_settings.xml28
-rw-r--r--libs/WindowManager/Shell/res/drawable/pip_icon.xml25
-rw-r--r--libs/WindowManager/Shell/res/drawable/pip_resize_handle.xml29
-rw-r--r--libs/WindowManager/Shell/res/drawable/tv_pip_button_focused.xml18
-rw-r--r--libs/WindowManager/Shell/res/layout/divider.xml21
-rw-r--r--libs/WindowManager/Shell/res/layout/docked_stack_divider.xml38
-rw-r--r--libs/WindowManager/Shell/res/layout/forced_resizable_activity.xml26
-rw-r--r--libs/WindowManager/Shell/res/layout/one_handed_tutorial.xml67
-rw-r--r--libs/WindowManager/Shell/res/layout/pip_menu.xml100
-rw-r--r--libs/WindowManager/Shell/res/layout/pip_menu_action.xml23
-rw-r--r--libs/WindowManager/Shell/res/layout/tv_pip_control_button.xml50
-rw-r--r--libs/WindowManager/Shell/res/layout/tv_pip_controls.xml43
-rw-r--r--libs/WindowManager/Shell/res/layout/tv_pip_custom_control.xml21
-rw-r--r--libs/WindowManager/Shell/res/layout/tv_pip_menu.xml31
-rw-r--r--libs/WindowManager/Shell/res/raw/wm_shell_protolog.json46
-rw-r--r--libs/WindowManager/Shell/res/values-land/dimens.xml21
-rw-r--r--libs/WindowManager/Shell/res/values-land/styles.xml35
-rw-r--r--libs/WindowManager/Shell/res/values-sw600dp/config.xml25
-rw-r--r--libs/WindowManager/Shell/res/values-tvdpi/dimen.xml22
-rw-r--r--libs/WindowManager/Shell/res/values/colors.xml25
-rw-r--r--libs/WindowManager/Shell/res/values/config.xml48
-rw-r--r--libs/WindowManager/Shell/res/values/dimen.xml69
-rw-r--r--libs/WindowManager/Shell/res/values/ids.xml26
-rw-r--r--libs/WindowManager/Shell/res/values/strings.xml96
-rw-r--r--libs/WindowManager/Shell/res/values/strings_tv.xml34
-rw-r--r--libs/WindowManager/Shell/res/values/styles.xml49
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java184
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/animation/FlingAnimationUtils.java423
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/animation/Interpolators.java45
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayChangeController.java109
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayController.java273
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java497
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java511
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/SyncTransactionQueue.java176
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java389
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/TransactionPool.java50
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java80
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedAnimationCallback.java51
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedAnimationController.java302
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java440
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedDisplayAreaOrganizer.java368
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedEvents.java276
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedGestureHandler.java269
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedSettingsUtil.java144
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedSurfaceTransactionHelper.java88
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedThread.java62
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTimeoutHandler.java159
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTouchHandler.java173
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTransitionCallback.java37
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTutorialHandler.java195
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java92
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java138
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerHandleView.java146
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerImeController.java415
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerState.java (renamed from libs/WindowManager/Shell/tests/src/com/android/wm/shell/tests/WindowManagerShellTest.java)27
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerView.java1374
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerWindowManager.java115
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ForcedResizableInfoActivity.java108
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ForcedResizableInfoActivityController.java148
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/MinimizedDockShadow.java99
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitDisplayLayout.java313
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreen.java91
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java546
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenTaskOrganizer.java232
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/WindowManagerProxy.java369
-rw-r--r--libs/WindowManager/Shell/tests/README.md15
-rw-r--r--libs/WindowManager/Shell/tests/flicker/Android.bp34
-rw-r--r--libs/WindowManager/Shell/tests/flicker/AndroidManifest.xml43
-rw-r--r--libs/WindowManager/Shell/tests/flicker/AndroidTest.xml40
-rw-r--r--libs/WindowManager/Shell/tests/flicker/README.md10
-rw-r--r--libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/CommonAssertions.kt153
-rw-r--r--libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/FlickerTestBase.kt130
-rw-r--r--libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/NonRotationTestBase.kt36
-rw-r--r--libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/helpers/FlickerAppHelper.kt31
-rw-r--r--libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/helpers/PipAppHelper.kt45
-rw-r--r--libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/EnterPipTest.kt121
-rw-r--r--libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/PipTestBase.kt31
-rw-r--r--libs/WindowManager/Shell/tests/flicker/test-apps/Android.bp0
-rw-r--r--libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/Android.bp20
-rw-r--r--libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/AndroidManifest.xml37
-rw-r--r--libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/res/layout/activity_pip.xml26
-rw-r--r--libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/src/com/android/wm/shell/flicker/testapp/PipActivity.java45
-rw-r--r--libs/WindowManager/Shell/tests/unittest/Android.bp (renamed from libs/WindowManager/Shell/tests/Android.bp)6
-rw-r--r--libs/WindowManager/Shell/tests/unittest/AndroidManifest.xml (renamed from libs/WindowManager/Shell/tests/AndroidManifest.xml)0
-rw-r--r--libs/WindowManager/Shell/tests/unittest/AndroidTest.xml (renamed from libs/WindowManager/Shell/tests/AndroidTest.xml)4
-rw-r--r--libs/WindowManager/Shell/tests/unittest/res/values/config.xml (renamed from libs/WindowManager/Shell/tests/res/values/config.xml)0
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/ShellTaskOrganizerTests.java138
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayLayoutTest.java140
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedAnimationControllerTest.java71
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedControllerTest.java190
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedDisplayAreaOrganizerTest.java286
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedEventsTest.java105
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedGestureHandlerTest.java93
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedSettingsUtilTest.java111
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTestCase.java104
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTimeoutHandlerTest.java105
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTouchHandlerTest.java69
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTutorialHandlerTest.java66
-rw-r--r--libs/androidfw/Android.bp1
-rw-r--r--libs/androidfw/BackupHelpers.cpp2
-rw-r--r--libs/androidfw/include/androidfw/BackupHelpers.h2
-rw-r--r--libs/androidfw/include/androidfw/ResourceTypes.h4
-rw-r--r--libs/androidfw/tests/BackupHelpers_test.cpp63
-rw-r--r--libs/hostgraphics/Android.bp6
-rw-r--r--libs/hwui/Android.bp62
-rw-r--r--libs/hwui/AnimationContext.h16
-rw-r--r--libs/hwui/Animator.h54
-rw-r--r--libs/hwui/AnimatorManager.h2
-rw-r--r--libs/hwui/AutoBackendTextureRelease.cpp10
-rw-r--r--libs/hwui/AutoBackendTextureRelease.h9
-rw-r--r--libs/hwui/CanvasTransform.cpp1
-rw-r--r--libs/hwui/ColorMode.h34
-rw-r--r--libs/hwui/DamageAccumulator.h2
-rw-r--r--libs/hwui/DeferredLayerUpdater.cpp2
-rw-r--r--libs/hwui/DeferredLayerUpdater.h18
-rw-r--r--libs/hwui/DeviceInfo.cpp129
-rw-r--r--libs/hwui/DeviceInfo.h53
-rw-r--r--libs/hwui/FrameInfo.h2
-rw-r--r--libs/hwui/HardwareBitmapUploader.cpp192
-rw-r--r--libs/hwui/HardwareBitmapUploader.h2
-rw-r--r--libs/hwui/Interpolator.h22
-rw-r--r--libs/hwui/Matrix.h2
-rw-r--r--libs/hwui/PathParser.h10
-rw-r--r--libs/hwui/Properties.cpp1
-rw-r--r--libs/hwui/Properties.h16
-rw-r--r--libs/hwui/PropertyValuesAnimatorSet.h2
-rw-r--r--libs/hwui/PropertyValuesHolder.h18
-rw-r--r--libs/hwui/Readback.cpp7
-rw-r--r--libs/hwui/RecordingCanvas.cpp67
-rw-r--r--libs/hwui/RecordingCanvas.h20
-rw-r--r--libs/hwui/RenderNode.h22
-rw-r--r--libs/hwui/RenderProperties.h4
-rw-r--r--libs/hwui/RootRenderNode.h19
-rw-r--r--libs/hwui/SkiaCanvas.cpp13
-rw-r--r--libs/hwui/SkiaCanvas.h6
-rw-r--r--libs/hwui/VectorDrawable.cpp7
-rw-r--r--libs/hwui/VectorDrawable.h28
-rw-r--r--libs/hwui/apex/java/android/graphics/ColorMatrix.java288
-rw-r--r--libs/hwui/apex/jni_runtime.cpp19
-rw-r--r--libs/hwui/api/current.txt23
-rw-r--r--libs/hwui/api/module-lib-current.txt1
-rw-r--r--libs/hwui/api/module-lib-removed.txt1
-rw-r--r--libs/hwui/api/removed.txt1
-rw-r--r--libs/hwui/api/system-current.txt1
-rw-r--r--libs/hwui/api/system-removed.txt1
-rw-r--r--libs/hwui/hwui/AnimatedImageDrawable.h2
-rw-r--r--libs/hwui/hwui/Bitmap.cpp40
-rw-r--r--libs/hwui/hwui/Bitmap.h16
-rw-r--r--libs/hwui/hwui/Canvas.cpp2
-rw-r--r--libs/hwui/hwui/Canvas.h6
-rw-r--r--libs/hwui/hwui/MinikinSkia.cpp16
-rw-r--r--libs/hwui/hwui/MinikinUtils.h14
-rw-r--r--libs/hwui/hwui/Paint.h11
-rw-r--r--libs/hwui/hwui/PaintImpl.cpp27
-rwxr-xr-xlibs/hwui/jni/Bitmap.cpp447
-rw-r--r--libs/hwui/jni/BitmapFactory.cpp11
-rw-r--r--libs/hwui/jni/BitmapRegionDecoder.cpp82
-rw-r--r--libs/hwui/jni/CreateJavaOutputStreamAdaptor.cpp21
-rw-r--r--libs/hwui/jni/CreateJavaOutputStreamAdaptor.h8
-rw-r--r--libs/hwui/jni/FontFamily.cpp12
-rw-r--r--libs/hwui/jni/Graphics.cpp2
-rw-r--r--libs/hwui/jni/GraphicsJNI.h15
-rw-r--r--libs/hwui/jni/ImageDecoder.cpp5
-rw-r--r--libs/hwui/jni/Movie.cpp8
-rw-r--r--libs/hwui/jni/Paint.cpp14
-rw-r--r--libs/hwui/jni/Picture.cpp2
-rw-r--r--libs/hwui/jni/Shader.cpp169
-rw-r--r--libs/hwui/jni/Utils.cpp4
-rw-r--r--libs/hwui/jni/Utils.h5
-rw-r--r--libs/hwui/jni/android_graphics_DisplayListCanvas.cpp44
-rw-r--r--libs/hwui/jni/android_graphics_HardwareRenderer.cpp184
-rw-r--r--libs/hwui/jni/android_graphics_TextureLayer.cpp4
-rw-r--r--libs/hwui/jni/android_graphics_drawable_VectorDrawable.cpp4
-rw-r--r--libs/hwui/jni/fonts/Font.cpp12
-rw-r--r--libs/hwui/libhwui.map.txt70
-rw-r--r--libs/hwui/pipeline/skia/FunctorDrawable.h31
-rw-r--r--libs/hwui/pipeline/skia/GLFunctorDrawable.cpp21
-rw-r--r--libs/hwui/pipeline/skia/GLFunctorDrawable.h2
-rw-r--r--libs/hwui/pipeline/skia/LayerDrawable.cpp10
-rw-r--r--libs/hwui/pipeline/skia/LayerDrawable.h8
-rw-r--r--libs/hwui/pipeline/skia/ShaderCache.h2
-rw-r--r--libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp2
-rw-r--r--libs/hwui/pipeline/skia/SkiaPipeline.cpp32
-rw-r--r--libs/hwui/pipeline/skia/SkiaPipeline.h4
-rw-r--r--libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp25
-rw-r--r--libs/hwui/pipeline/skia/SkiaRecordingCanvas.h5
-rw-r--r--libs/hwui/pipeline/skia/VkFunctorDrawable.cpp9
-rw-r--r--libs/hwui/pipeline/skia/VkFunctorDrawable.h1
-rw-r--r--libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp71
-rw-r--r--libs/hwui/pipeline/skia/VkInteropFunctorDrawable.h11
-rw-r--r--libs/hwui/renderthread/CacheManager.cpp7
-rw-r--r--libs/hwui/renderthread/CanvasContext.cpp11
-rw-r--r--libs/hwui/renderthread/CanvasContext.h8
-rw-r--r--libs/hwui/renderthread/EglManager.cpp116
-rw-r--r--libs/hwui/renderthread/EglManager.h5
-rw-r--r--libs/hwui/renderthread/IRenderPipeline.h11
-rw-r--r--libs/hwui/renderthread/ReliableSurface.cpp28
-rw-r--r--libs/hwui/renderthread/ReliableSurface.h4
-rw-r--r--libs/hwui/renderthread/RenderProxy.cpp22
-rw-r--r--libs/hwui/renderthread/RenderProxy.h107
-rw-r--r--libs/hwui/renderthread/RenderTask.h8
-rw-r--r--libs/hwui/renderthread/RenderThread.cpp27
-rw-r--r--libs/hwui/renderthread/RenderThread.h14
-rw-r--r--libs/hwui/renderthread/VulkanManager.cpp119
-rw-r--r--libs/hwui/renderthread/VulkanManager.h36
-rw-r--r--libs/hwui/renderthread/VulkanSurface.cpp10
-rw-r--r--libs/hwui/renderthread/VulkanSurface.h11
-rw-r--r--libs/hwui/service/GraphicsStatsService.h22
-rw-r--r--libs/hwui/shader/BitmapShader.cpp31
-rw-r--r--libs/hwui/shader/BitmapShader.h39
-rw-r--r--libs/hwui/shader/BlurShader.cpp40
-rw-r--r--libs/hwui/shader/BlurShader.h42
-rw-r--r--libs/hwui/shader/ComposeShader.cpp51
-rw-r--r--libs/hwui/shader/ComposeShader.h43
-rw-r--r--libs/hwui/shader/LinearGradientShader.cpp39
-rw-r--r--libs/hwui/shader/LinearGradientShader.h42
-rw-r--r--libs/hwui/shader/RadialGradientShader.cpp38
-rw-r--r--libs/hwui/shader/RadialGradientShader.h42
-rw-r--r--libs/hwui/shader/RuntimeShader.cpp36
-rw-r--r--libs/hwui/shader/RuntimeShader.h40
-rw-r--r--libs/hwui/shader/Shader.cpp87
-rw-r--r--libs/hwui/shader/Shader.h84
-rw-r--r--libs/hwui/shader/SweepGradientShader.cpp38
-rw-r--r--libs/hwui/shader/SweepGradientShader.h41
-rw-r--r--libs/hwui/tests/common/TestUtils.h24
-rw-r--r--libs/hwui/tests/common/scenes/BitmapShaders.cpp22
-rw-r--r--libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp47
-rw-r--r--libs/hwui/tests/common/scenes/ListOfFadedTextAnimation.cpp24
-rw-r--r--libs/hwui/tests/common/scenes/MagnifierAnimation.cpp4
-rw-r--r--libs/hwui/tests/common/scenes/RecentsAnimation.cpp4
-rw-r--r--libs/hwui/tests/common/scenes/RectGridAnimation.cpp4
-rw-r--r--libs/hwui/tests/common/scenes/RoundRectClippingAnimation.cpp4
-rw-r--r--libs/hwui/tests/common/scenes/ShadowGrid2Animation.cpp4
-rw-r--r--libs/hwui/tests/common/scenes/ShadowGridAnimation.cpp4
-rw-r--r--libs/hwui/tests/common/scenes/ShadowShaderAnimation.cpp4
-rw-r--r--libs/hwui/tests/common/scenes/SimpleColorMatrixAnimation.cpp11
-rw-r--r--libs/hwui/tests/common/scenes/SimpleGradientAnimation.cpp22
-rw-r--r--libs/hwui/tests/common/scenes/TvApp.cpp4
-rw-r--r--libs/hwui/tests/microbench/DisplayListCanvasBench.cpp4
-rwxr-xr-xlibs/hwui/tests/scripts/prep_generic.sh209
-rw-r--r--libs/hwui/tests/unit/CacheManagerTests.cpp6
-rw-r--r--libs/hwui/tests/unit/CanvasContextTests.cpp11
-rw-r--r--libs/hwui/tests/unit/FatalTestCanvas.h15
-rw-r--r--libs/hwui/tests/unit/RenderNodeDrawableTests.cpp24
-rw-r--r--libs/hwui/tests/unit/RenderNodeTests.cpp50
-rw-r--r--libs/hwui/tests/unit/SkiaCanvasTests.cpp4
-rw-r--r--libs/hwui/tests/unit/SkiaDisplayListTests.cpp17
-rw-r--r--libs/hwui/tests/unit/VectorDrawableTests.cpp21
-rw-r--r--libs/hwui/utils/Blur.h4
-rw-r--r--libs/hwui/utils/Color.cpp61
-rw-r--r--libs/hwui/utils/Color.h16
-rw-r--r--libs/hwui/utils/MathUtils.h4
-rw-r--r--libs/hwui/utils/NdkUtils.cpp (renamed from libs/hwui/GlFunctorLifecycleListener.h)20
-rw-r--r--libs/hwui/utils/NdkUtils.h38
-rw-r--r--libs/hwui/utils/VectorDrawableUtils.h6
-rw-r--r--libs/usb/tests/AccessoryChat/AndroidManifest.xml20
273 files changed, 16414 insertions, 1613 deletions
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/sidecar/SettingsSidecarImpl.java b/libs/WindowManager/Jetpack/src/androidx/window/sidecar/SettingsSidecarImpl.java
index 92e575804bbe..ca3a5112bc55 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/sidecar/SettingsSidecarImpl.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/sidecar/SettingsSidecarImpl.java
@@ -192,7 +192,7 @@ class SettingsSidecarImpl extends StubSidecar {
Rect featureRect = new Rect(left, top, right, bottom);
rotateRectToDisplayRotation(featureRect, displayId);
transformToWindowSpaceRect(featureRect, windowToken);
- if (!featureRect.isEmpty()) {
+ if (isNotZero(featureRect)) {
SidecarDisplayFeature feature = new SidecarDisplayFeature();
feature.setRect(featureRect);
feature.setType(type);
@@ -207,6 +207,10 @@ class SettingsSidecarImpl extends StubSidecar {
return features;
}
+ private static boolean isNotZero(Rect rect) {
+ return rect.height() > 0 || rect.width() > 0;
+ }
+
@Override
protected void onListenersChanged() {
if (mSettingsObserver == null) {
diff --git a/libs/WindowManager/Shell/Android.bp b/libs/WindowManager/Shell/Android.bp
index b8934dc8c583..1591b0616262 100644
--- a/libs/WindowManager/Shell/Android.bp
+++ b/libs/WindowManager/Shell/Android.bp
@@ -12,18 +12,100 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// Begin ProtoLog
+java_library {
+ name: "wm_shell_protolog-groups",
+ srcs: [
+ "src/com/android/wm/shell/protolog/ShellProtoLogGroup.java",
+ ":protolog-common-src",
+ ],
+}
+
+filegroup {
+ name: "wm_shell-sources",
+ srcs: ["src/**/*.java"],
+ path: "src",
+}
+
+genrule {
+ name: "wm_shell_protolog_src",
+ srcs: [
+ ":wm_shell_protolog-groups",
+ ":wm_shell-sources",
+ ],
+ tools: ["protologtool"],
+ cmd: "$(location protologtool) transform-protolog-calls " +
+ "--protolog-class com.android.internal.protolog.common.ProtoLog " +
+ "--protolog-impl-class com.android.wm.shell.protolog.ShellProtoLogImpl " +
+ "--protolog-cache-class com.android.wm.shell.protolog.ShellProtoLogCache " +
+ "--loggroups-class com.android.wm.shell.protolog.ShellProtoLogGroup " +
+ "--loggroups-jar $(location :wm_shell_protolog-groups) " +
+ "--output-srcjar $(out) " +
+ "$(locations :wm_shell-sources)",
+ out: ["wm_shell_protolog.srcjar"],
+}
+
+genrule {
+ name: "generate-wm_shell_protolog.json",
+ srcs: [
+ ":wm_shell_protolog-groups",
+ ":wm_shell-sources",
+ ],
+ tools: ["protologtool"],
+ cmd: "$(location protologtool) generate-viewer-config " +
+ "--protolog-class com.android.internal.protolog.common.ProtoLog " +
+ "--loggroups-class com.android.wm.shell.protolog.ShellProtoLogGroup " +
+ "--loggroups-jar $(location :wm_shell_protolog-groups) " +
+ "--viewer-conf $(out) " +
+ "$(locations :wm_shell-sources)",
+ out: ["wm_shell_protolog.json"],
+}
+
+filegroup {
+ name: "wm_shell_protolog.json",
+ srcs: ["res/raw/wm_shell_protolog.json"],
+}
+
+genrule {
+ name: "checked-wm_shell_protolog.json",
+ srcs: [
+ ":generate-wm_shell_protolog.json",
+ ":wm_shell_protolog.json",
+ ],
+ cmd: "cp $(location :generate-wm_shell_protolog.json) $(out) && " +
+ "{ ! (diff $(out) $(location :wm_shell_protolog.json) | grep -q '^<') || " +
+ "{ echo -e '\\n\\n################################################################\\n#\\n" +
+ "# ERROR: ProtoLog viewer config is stale. To update it, run:\\n#\\n" +
+ "# cp $(location :generate-wm_shell_protolog.json) " +
+ "$(location :wm_shell_protolog.json)\\n#\\n" +
+ "################################################################\\n\\n' >&2 && false; } }",
+ out: ["wm_shell_protolog.json"],
+}
+// End ProtoLog
+
+java_library {
+ name: "WindowManager-Shell-proto",
+
+ srcs: ["proto/*.proto"],
+
+ proto: {
+ type: "nano",
+ },
+}
+
android_library {
name: "WindowManager-Shell",
srcs: [
- "src/**/*.java",
+ ":wm_shell_protolog_src",
"src/**/I*.aidl",
],
resource_dirs: [
"res",
],
+ static_libs: [
+ "protolog-lib",
+ "WindowManager-Shell-proto",
+ "androidx.appcompat_appcompat",
+ ],
manifest: "AndroidManifest.xml",
-
- platform_apis: true,
- sdk_version: "current",
- min_sdk_version: "system_current",
-}
+} \ No newline at end of file
diff --git a/libs/WindowManager/Shell/proto/wm_shell_trace.proto b/libs/WindowManager/Shell/proto/wm_shell_trace.proto
new file mode 100644
index 000000000000..b9e72525f32b
--- /dev/null
+++ b/libs/WindowManager/Shell/proto/wm_shell_trace.proto
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto2";
+
+package com.android.wm.shell;
+
+option java_multiple_files = true;
+
+message WmShellTraceProto {
+
+ // Not used, just a test value
+ optional bool test_value = 1;
+}
diff --git a/libs/WindowManager/Shell/res/anim/forced_resizable_enter.xml b/libs/WindowManager/Shell/res/anim/forced_resizable_enter.xml
new file mode 100644
index 000000000000..01b8fdbe4437
--- /dev/null
+++ b/libs/WindowManager/Shell/res/anim/forced_resizable_enter.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2016 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<alpha xmlns:android="http://schemas.android.com/apk/res/android"
+ android:fromAlpha="0.0"
+ android:toAlpha="1.0"
+ android:interpolator="@android:interpolator/linear_out_slow_in"
+ android:duration="280" />
diff --git a/libs/WindowManager/Shell/res/anim/forced_resizable_exit.xml b/libs/WindowManager/Shell/res/anim/forced_resizable_exit.xml
new file mode 100644
index 000000000000..6f316a75dbed
--- /dev/null
+++ b/libs/WindowManager/Shell/res/anim/forced_resizable_exit.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2016 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<alpha xmlns:android="http://schemas.android.com/apk/res/android"
+ android:fromAlpha="1.0"
+ android:toAlpha="0.0"
+ android:duration="160"
+ android:interpolator="@android:interpolator/fast_out_linear_in"
+ android:zAdjustment="top"/> \ No newline at end of file
diff --git a/libs/WindowManager/Shell/res/anim/tv_pip_controls_focus_gain_animation.xml b/libs/WindowManager/Shell/res/anim/tv_pip_controls_focus_gain_animation.xml
new file mode 100644
index 000000000000..29d9b257cc59
--- /dev/null
+++ b/libs/WindowManager/Shell/res/anim/tv_pip_controls_focus_gain_animation.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:propertyName="alpha"
+ android:valueTo="1"
+ android:interpolator="@android:interpolator/fast_out_slow_in"
+ android:duration="100" />
diff --git a/libs/WindowManager/Shell/res/anim/tv_pip_controls_focus_loss_animation.xml b/libs/WindowManager/Shell/res/anim/tv_pip_controls_focus_loss_animation.xml
new file mode 100644
index 000000000000..70f553b89657
--- /dev/null
+++ b/libs/WindowManager/Shell/res/anim/tv_pip_controls_focus_loss_animation.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:propertyName="alpha"
+ android:valueTo="0"
+ android:interpolator="@android:interpolator/fast_out_slow_in"
+ android:duration="100" />
diff --git a/libs/WindowManager/Shell/res/anim/tv_pip_menu_fade_in_animation.xml b/libs/WindowManager/Shell/res/anim/tv_pip_menu_fade_in_animation.xml
new file mode 100644
index 000000000000..29d9b257cc59
--- /dev/null
+++ b/libs/WindowManager/Shell/res/anim/tv_pip_menu_fade_in_animation.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:propertyName="alpha"
+ android:valueTo="1"
+ android:interpolator="@android:interpolator/fast_out_slow_in"
+ android:duration="100" />
diff --git a/libs/WindowManager/Shell/res/anim/tv_pip_menu_fade_out_animation.xml b/libs/WindowManager/Shell/res/anim/tv_pip_menu_fade_out_animation.xml
new file mode 100644
index 000000000000..70f553b89657
--- /dev/null
+++ b/libs/WindowManager/Shell/res/anim/tv_pip_menu_fade_out_animation.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:propertyName="alpha"
+ android:valueTo="0"
+ android:interpolator="@android:interpolator/fast_out_slow_in"
+ android:duration="100" />
diff --git a/libs/WindowManager/Shell/res/drawable-hdpi/one_handed_tutorial.png b/libs/WindowManager/Shell/res/drawable-hdpi/one_handed_tutorial.png
new file mode 100644
index 000000000000..6c1f1cfdea7c
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable-hdpi/one_handed_tutorial.png
Binary files differ
diff --git a/libs/WindowManager/Shell/res/drawable/floating_dismiss_gradient.xml b/libs/WindowManager/Shell/res/drawable/floating_dismiss_gradient.xml
new file mode 100644
index 000000000000..8b3057d5841e
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/floating_dismiss_gradient.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<shape
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <gradient
+ android:angle="270"
+ android:startColor="#00000000"
+ android:endColor="#77000000"
+ android:type="linear" />
+</shape> \ No newline at end of file
diff --git a/libs/WindowManager/Shell/res/drawable/floating_dismiss_gradient_transition.xml b/libs/WindowManager/Shell/res/drawable/floating_dismiss_gradient_transition.xml
new file mode 100644
index 000000000000..772d0a5ea89b
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/floating_dismiss_gradient_transition.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<transition xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@android:color/transparent" />
+ <item android:drawable="@drawable/floating_dismiss_gradient" />
+</transition> \ No newline at end of file
diff --git a/libs/WindowManager/Shell/res/drawable/pip_expand.xml b/libs/WindowManager/Shell/res/drawable/pip_expand.xml
new file mode 100644
index 000000000000..c99d81934aab
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/pip_expand.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="36dp"
+ android:height="36dp"
+ android:viewportWidth="36"
+ android:viewportHeight="36">
+
+ <path
+ android:pathData="M0 0h36v36H0z" />
+ <path
+ android:fillColor="#FFFFFF"
+ android:pathData="M10 21H7v8h8v-3h-5v-5zm-3-6h3v-5h5V7H7v8zm19 11h-5v3h8v-8h-3v5zM21
+7v3h5v5h3V7h-8z" />
+</vector> \ No newline at end of file
diff --git a/libs/WindowManager/Shell/res/drawable/pip_ic_close_white.xml b/libs/WindowManager/Shell/res/drawable/pip_ic_close_white.xml
new file mode 100644
index 000000000000..bcc850a854de
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/pip_ic_close_white.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24.0dp"
+ android:height="24.0dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:pathData="M19.000000,6.400000l-1.400000,-1.400000 -5.600000,5.600000 -5.600000,-5.600000 -1.400000,1.400000 5.600000,5.600000 -5.600000,5.600000 1.400000,1.400000 5.600000,-5.600000 5.600000,5.600000 1.400000,-1.400000 -5.600000,-5.600000z"
+ android:fillColor="#FFFFFFFF"/>
+</vector>
diff --git a/libs/WindowManager/Shell/res/drawable/pip_ic_fullscreen_white.xml b/libs/WindowManager/Shell/res/drawable/pip_ic_fullscreen_white.xml
new file mode 100644
index 000000000000..56699dc04e10
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/pip_ic_fullscreen_white.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FFFFFF"
+ android:pathData="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" />
+</vector>
diff --git a/libs/WindowManager/Shell/res/drawable/pip_ic_pause_white.xml b/libs/WindowManager/Shell/res/drawable/pip_ic_pause_white.xml
new file mode 100644
index 000000000000..ef9b2d9c1c63
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/pip_ic_pause_white.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+
+ <path
+ android:fillColor="#FFFFFF"
+ android:pathData="M6 19h4V5H6v14zm8-14v14h4V5h-4z" />
+</vector>
diff --git a/libs/WindowManager/Shell/res/drawable/pip_ic_play_arrow_white.xml b/libs/WindowManager/Shell/res/drawable/pip_ic_play_arrow_white.xml
new file mode 100644
index 000000000000..f12d2cbebc87
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/pip_ic_play_arrow_white.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+
+ <path
+ android:fillColor="#FFFFFF"
+ android:pathData="M8 5v14l11-7z" />
+</vector>
diff --git a/libs/WindowManager/Shell/res/drawable/pip_ic_settings.xml b/libs/WindowManager/Shell/res/drawable/pip_ic_settings.xml
new file mode 100644
index 000000000000..b61e98ce2f9f
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/pip_ic_settings.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M13.85,22.25h-3.7c-0.74,0 -1.36,-0.54 -1.45,-1.27l-0.27,-1.89c-0.27,-0.14 -0.53,-0.29 -0.79,-0.46l-1.8,0.72c-0.7,0.26 -1.47,-0.03 -1.81,-0.65L2.2,15.53c-0.35,-0.66 -0.2,-1.44 0.36,-1.88l1.53,-1.19c-0.01,-0.15 -0.02,-0.3 -0.02,-0.46c0,-0.15 0.01,-0.31 0.02,-0.46l-1.52,-1.19C1.98,9.9 1.83,9.09 2.2,8.47l1.85,-3.19c0.34,-0.62 1.11,-0.9 1.79,-0.63l1.81,0.73c0.26,-0.17 0.52,-0.32 0.78,-0.46l0.27,-1.91c0.09,-0.7 0.71,-1.25 1.44,-1.25h3.7c0.74,0 1.36,0.54 1.45,1.27l0.27,1.89c0.27,0.14 0.53,0.29 0.79,0.46l1.8,-0.72c0.71,-0.26 1.48,0.03 1.82,0.65l1.84,3.18c0.36,0.66 0.2,1.44 -0.36,1.88l-1.52,1.19c0.01,0.15 0.02,0.3 0.02,0.46s-0.01,0.31 -0.02,0.46l1.52,1.19c0.56,0.45 0.72,1.23 0.37,1.86l-1.86,3.22c-0.34,0.62 -1.11,0.9 -1.8,0.63l-1.8,-0.72c-0.26,0.17 -0.52,0.32 -0.78,0.46l-0.27,1.91C15.21,21.71 14.59,22.25 13.85,22.25zM13.32,20.72c0,0.01 0,0.01 0,0.02L13.32,20.72zM10.68,20.7l0,0.02C10.69,20.72 10.69,20.71 10.68,20.7zM10.62,20.25h2.76l0.37,-2.55l0.53,-0.22c0.44,-0.18 0.88,-0.44 1.34,-0.78l0.45,-0.34l2.38,0.96l1.38,-2.4l-2.03,-1.58l0.07,-0.56c0.03,-0.26 0.06,-0.51 0.06,-0.78c0,-0.27 -0.03,-0.53 -0.06,-0.78l-0.07,-0.56l2.03,-1.58l-1.39,-2.4l-2.39,0.96l-0.45,-0.35c-0.42,-0.32 -0.87,-0.58 -1.33,-0.77L13.75,6.3l-0.37,-2.55h-2.76L10.25,6.3L9.72,6.51C9.28,6.7 8.84,6.95 8.38,7.3L7.93,7.63L5.55,6.68L4.16,9.07l2.03,1.58l-0.07,0.56C6.09,11.47 6.06,11.74 6.06,12c0,0.26 0.02,0.53 0.06,0.78l0.07,0.56l-2.03,1.58l1.38,2.4l2.39,-0.96l0.45,0.35c0.43,0.33 0.86,0.58 1.33,0.77l0.53,0.22L10.62,20.25zM18.22,17.72c0,0.01 -0.01,0.02 -0.01,0.03L18.22,17.72zM5.77,17.71l0.01,0.02C5.78,17.72 5.77,17.71 5.77,17.71zM3.93,9.47L3.93,9.47C3.93,9.47 3.93,9.47 3.93,9.47zM18.22,6.27c0,0.01 0.01,0.02 0.01,0.02L18.22,6.27zM5.79,6.25L5.78,6.27C5.78,6.27 5.79,6.26 5.79,6.25zM13.31,3.28c0,0.01 0,0.01 0,0.02L13.31,3.28zM10.69,3.26l0,0.02C10.69,3.27 10.69,3.27 10.69,3.26z"/>
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M12,12m-3.5,0a3.5,3.5 0,1 1,7 0a3.5,3.5 0,1 1,-7 0"/>
+</vector>
diff --git a/libs/WindowManager/Shell/res/drawable/pip_icon.xml b/libs/WindowManager/Shell/res/drawable/pip_icon.xml
new file mode 100644
index 000000000000..b19d907d1ff3
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/pip_icon.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="36dp"
+ android:height="36dp"
+ android:viewportWidth="25"
+ android:viewportHeight="25">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M19,7h-8v6h8L19,7zM21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,1.98 2,1.98h18c1.1,0 2,-0.88 2,-1.98L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19.01L3,19.01L3,4.98h18v14.03z"/>
+</vector> \ No newline at end of file
diff --git a/libs/WindowManager/Shell/res/drawable/pip_resize_handle.xml b/libs/WindowManager/Shell/res/drawable/pip_resize_handle.xml
new file mode 100644
index 000000000000..4d1e080cf466
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/pip_resize_handle.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="12.0dp"
+ android:height="12.0dp"
+ android:viewportWidth="12"
+ android:viewportHeight="12">
+ <group
+ android:translateX="12"
+ android:rotation="90">
+ <path
+ android:fillColor="#FFFFFF"
+ android:pathData="M3.41421 0L2 1.41422L10.4853 9.8995L11.8995 8.48528L3.41421 0ZM2.41421 4.24268L1 5.65689L6.65685 11.3137L8.07107 9.89953L2.41421 4.24268Z" />
+ </group>
+</vector>
diff --git a/libs/WindowManager/Shell/res/drawable/tv_pip_button_focused.xml b/libs/WindowManager/Shell/res/drawable/tv_pip_button_focused.xml
new file mode 100644
index 000000000000..cce13035dba7
--- /dev/null
+++ b/libs/WindowManager/Shell/res/drawable/tv_pip_button_focused.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="#9AFFFFFF" android:radius="17dp" />
diff --git a/libs/WindowManager/Shell/res/layout/divider.xml b/libs/WindowManager/Shell/res/layout/divider.xml
new file mode 100644
index 000000000000..f1f0df054240
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/divider.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<View xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="72dp"
+ android:layout_height="1dp"
+ android:layout_marginTop="8dp"
+ android:background="?android:attr/colorForeground"
+ android:alpha="?android:attr/disabledAlpha" />
diff --git a/libs/WindowManager/Shell/res/layout/docked_stack_divider.xml b/libs/WindowManager/Shell/res/layout/docked_stack_divider.xml
new file mode 100644
index 000000000000..ad870252d819
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/docked_stack_divider.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<com.android.wm.shell.splitscreen.DividerView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent">
+
+ <View
+ style="@style/DockedDividerBackground"
+ android:id="@+id/docked_divider_background"
+ android:background="@color/docked_divider_background"/>
+
+ <com.android.wm.shell.splitscreen.MinimizedDockShadow
+ style="@style/DockedDividerMinimizedShadow"
+ android:id="@+id/minimized_dock_shadow"
+ android:alpha="0"/>">
+
+ <com.android.wm.shell.splitscreen.DividerHandleView
+ style="@style/DockedDividerHandle"
+ android:id="@+id/docked_divider_handle"
+ android:contentDescription="@string/accessibility_divider"
+ android:background="@null"/>
+
+</com.android.wm.shell.splitscreen.DividerView>
diff --git a/libs/WindowManager/Shell/res/layout/forced_resizable_activity.xml b/libs/WindowManager/Shell/res/layout/forced_resizable_activity.xml
new file mode 100644
index 000000000000..3c778c431a2e
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/forced_resizable_activity.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2016 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <include
+ layout="@*android:layout/transient_notification"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"/>
+</FrameLayout> \ No newline at end of file
diff --git a/libs/WindowManager/Shell/res/layout/one_handed_tutorial.xml b/libs/WindowManager/Shell/res/layout/one_handed_tutorial.xml
new file mode 100644
index 000000000000..dc54caf0f14a
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/one_handed_tutorial.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Copyright (C) 2020 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/one_handed_tutorial_layout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:gravity="center_horizontal | center_vertical"
+ android:background="@android:color/transparent">
+
+ <ImageView
+ android:id="@+id/one_handed_tutorial_image"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="6dp"
+ android:layout_marginBottom="0dp"
+ android:gravity="center_horizontal"
+ android:src="@drawable/one_handed_tutorial"
+ android:scaleType="centerInside" />
+
+ <TextView
+ android:id="@+id/one_handed_tutorial_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="6dp"
+ android:layout_marginBottom="0dp"
+ android:gravity="center_horizontal"
+ android:textAlignment="center"
+ android:fontFamily="google-sans-medium"
+ android:text="@string/one_handed_tutorial_title"
+ android:textSize="16sp"
+ android:textStyle="bold"
+ android:textColor="@android:color/white"/>
+
+ <TextView
+ android:id="@+id/one_handed_tutorial_description"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="6dp"
+ android:layout_marginBottom="0dp"
+ android:layout_marginStart="86dp"
+ android:layout_marginEnd="86dp"
+ android:gravity="center_horizontal"
+ android:fontFamily="roboto-regular"
+ android:text="@string/one_handed_tutorial_description"
+ android:textAlignment="center"
+ android:textSize="14sp"
+ android:textStyle="normal"
+ android:alpha="0.7"
+ android:textColor="@android:color/white"/>
+</LinearLayout>
diff --git a/libs/WindowManager/Shell/res/layout/pip_menu.xml b/libs/WindowManager/Shell/res/layout/pip_menu.xml
new file mode 100644
index 000000000000..2e0a5e09e34f
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/pip_menu.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/background"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <!-- Menu layout -->
+ <FrameLayout
+ android:id="@+id/menu_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:forceHasOverlappingRendering="false"
+ android:accessibilityTraversalAfter="@id/dismiss">
+
+ <!-- The margins for this container is calculated in the code depending on whether the
+ actions_container is visible. -->
+ <FrameLayout
+ android:id="@+id/expand_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <ImageButton
+ android:id="@+id/expand_button"
+ android:layout_width="60dp"
+ android:layout_height="60dp"
+ android:layout_gravity="center"
+ android:contentDescription="@string/pip_phone_expand"
+ android:padding="10dp"
+ android:src="@drawable/pip_expand"
+ android:background="?android:selectableItemBackgroundBorderless" />
+ </FrameLayout>
+
+ <FrameLayout
+ android:id="@+id/actions_container"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/pip_action_size"
+ android:layout_gravity="bottom"
+ android:visibility="invisible">
+ <LinearLayout
+ android:id="@+id/actions_group"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_gravity="center_horizontal"
+ android:orientation="horizontal"
+ android:divider="@android:color/transparent"
+ android:showDividers="middle" />
+ </FrameLayout>
+ </FrameLayout>
+
+ <LinearLayout
+ android:id="@+id/top_end_container"
+ android:layout_gravity="top|end"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <ImageButton
+ android:id="@+id/settings"
+ android:layout_width="@dimen/pip_action_size"
+ android:layout_height="@dimen/pip_action_size"
+ android:padding="@dimen/pip_action_padding"
+ android:contentDescription="@string/pip_phone_settings"
+ android:src="@drawable/pip_ic_settings"
+ android:background="?android:selectableItemBackgroundBorderless" />
+
+ <ImageButton
+ android:id="@+id/dismiss"
+ android:layout_width="@dimen/pip_action_size"
+ android:layout_height="@dimen/pip_action_size"
+ android:padding="@dimen/pip_action_padding"
+ android:contentDescription="@string/pip_phone_close"
+ android:src="@drawable/pip_ic_close_white"
+ android:background="?android:selectableItemBackgroundBorderless" />
+ </LinearLayout>
+
+ <!--TODO (b/156917828): Add content description for a11y purposes?-->
+ <ImageButton
+ android:id="@+id/resize_handle"
+ android:layout_width="@dimen/pip_resize_handle_size"
+ android:layout_height="@dimen/pip_resize_handle_size"
+ android:layout_gravity="top|start"
+ android:layout_margin="@dimen/pip_resize_handle_margin"
+ android:padding="@dimen/pip_resize_handle_padding"
+ android:src="@drawable/pip_resize_handle"
+ android:background="?android:selectableItemBackgroundBorderless" />
+</FrameLayout>
diff --git a/libs/WindowManager/Shell/res/layout/pip_menu_action.xml b/libs/WindowManager/Shell/res/layout/pip_menu_action.xml
new file mode 100644
index 000000000000..7a026ca63f50
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/pip_menu_action.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<ImageButton
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="@dimen/pip_action_size"
+ android:layout_height="@dimen/pip_action_size"
+ android:padding="@dimen/pip_action_padding"
+ android:background="?android:selectableItemBackgroundBorderless"
+ android:forceHasOverlappingRendering="false" />
diff --git a/libs/WindowManager/Shell/res/layout/tv_pip_control_button.xml b/libs/WindowManager/Shell/res/layout/tv_pip_control_button.xml
new file mode 100644
index 000000000000..72287c144bed
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/tv_pip_control_button.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- Layout for {@link com.android.systemui.pip.tv.PipControlButtonView}. -->
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <ImageView android:id="@+id/button"
+ android:layout_width="34dp"
+ android:layout_height="34dp"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:focusable="true"
+ android:src="@drawable/tv_pip_button_focused"
+ android:importantForAccessibility="yes" />
+
+ <ImageView android:id="@+id/icon"
+ android:layout_width="34dp"
+ android:layout_height="34dp"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:padding="5dp"
+ android:importantForAccessibility="no" />
+
+ <TextView android:id="@+id/desc"
+ android:layout_width="100dp"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/icon"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="3dp"
+ android:gravity="center"
+ android:text="@string/pip_fullscreen"
+ android:alpha="0"
+ android:fontFamily="sans-serif"
+ android:textSize="12sp"
+ android:textColor="#EEEEEE"
+ android:importantForAccessibility="no" />
+</merge>
diff --git a/libs/WindowManager/Shell/res/layout/tv_pip_controls.xml b/libs/WindowManager/Shell/res/layout/tv_pip_controls.xml
new file mode 100644
index 000000000000..22e0452d620d
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/tv_pip_controls.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- Layout for {@link com.android.systemui.pip.tv.PipControlsView}. -->
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <com.android.systemui.pip.tv.PipControlButtonView
+ android:id="@+id/full_button"
+ android:layout_width="@dimen/picture_in_picture_button_width"
+ android:layout_height="wrap_content"
+ android:src="@drawable/pip_ic_fullscreen_white"
+ android:text="@string/pip_fullscreen" />
+
+ <com.android.systemui.pip.tv.PipControlButtonView
+ android:id="@+id/close_button"
+ android:layout_width="@dimen/picture_in_picture_button_width"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/picture_in_picture_button_start_margin"
+ android:src="@drawable/pip_ic_close_white"
+ android:text="@string/pip_close" />
+
+ <com.android.systemui.pip.tv.PipControlButtonView
+ android:id="@+id/play_pause_button"
+ android:layout_width="@dimen/picture_in_picture_button_width"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/picture_in_picture_button_start_margin"
+ android:src="@drawable/pip_ic_pause_white"
+ android:text="@string/pip_pause"
+ android:visibility="gone" />
+</merge>
diff --git a/libs/WindowManager/Shell/res/layout/tv_pip_custom_control.xml b/libs/WindowManager/Shell/res/layout/tv_pip_custom_control.xml
new file mode 100644
index 000000000000..e6cd1122ca77
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/tv_pip_custom_control.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<com.android.systemui.pip.tv.PipControlButtonView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="@dimen/picture_in_picture_button_width"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/picture_in_picture_button_start_margin" />
diff --git a/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml b/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml
new file mode 100644
index 000000000000..a049787b40b9
--- /dev/null
+++ b/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="horizontal"
+ android:paddingTop="350dp"
+ android:background="#CC000000"
+ android:gravity="top|center_horizontal"
+ android:clipChildren="false">
+
+ <com.android.systemui.pip.tv.PipControlsView
+ android:id="@+id/pip_controls"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:alpha="0" />
+</LinearLayout>
diff --git a/libs/WindowManager/Shell/res/raw/wm_shell_protolog.json b/libs/WindowManager/Shell/res/raw/wm_shell_protolog.json
new file mode 100644
index 000000000000..7242793580f9
--- /dev/null
+++ b/libs/WindowManager/Shell/res/raw/wm_shell_protolog.json
@@ -0,0 +1,46 @@
+{
+ "version": "1.0.0",
+ "messages": {
+ "-1340279385": {
+ "message": "Remove listener=%s",
+ "level": "VERBOSE",
+ "group": "WM_SHELL_TASK_ORG",
+ "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
+ },
+ "-880817403": {
+ "message": "Task vanished taskId=%d",
+ "level": "VERBOSE",
+ "group": "WM_SHELL_TASK_ORG",
+ "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
+ },
+ "-460572385": {
+ "message": "Task appeared taskId=%d",
+ "level": "VERBOSE",
+ "group": "WM_SHELL_TASK_ORG",
+ "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
+ },
+ "-242812822": {
+ "message": "Add listener for modes=%s listener=%s",
+ "level": "VERBOSE",
+ "group": "WM_SHELL_TASK_ORG",
+ "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
+ },
+ "157713005": {
+ "message": "Task info changed taskId=%d",
+ "level": "VERBOSE",
+ "group": "WM_SHELL_TASK_ORG",
+ "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
+ },
+ "980952660": {
+ "message": "Task root back pressed taskId=%d",
+ "level": "VERBOSE",
+ "group": "WM_SHELL_TASK_ORG",
+ "at": "com\/android\/wm\/shell\/ShellTaskOrganizer.java"
+ }
+ },
+ "groups": {
+ "WM_SHELL_TASK_ORG": {
+ "tag": "WindowManagerShell"
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/res/values-land/dimens.xml b/libs/WindowManager/Shell/res/values-land/dimens.xml
new file mode 100644
index 000000000000..77a601ddf440
--- /dev/null
+++ b/libs/WindowManager/Shell/res/values-land/dimens.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (c) 2020, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+-->
+<resources>
+ <dimen name="docked_divider_handle_width">2dp</dimen>
+ <dimen name="docked_divider_handle_height">16dp</dimen>
+</resources> \ No newline at end of file
diff --git a/libs/WindowManager/Shell/res/values-land/styles.xml b/libs/WindowManager/Shell/res/values-land/styles.xml
new file mode 100644
index 000000000000..863bb69d4034
--- /dev/null
+++ b/libs/WindowManager/Shell/res/values-land/styles.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <style name="DockedDividerBackground">
+ <item name="android:layout_width">10dp</item>
+ <item name="android:layout_height">match_parent</item>
+ <item name="android:layout_gravity">center_horizontal</item>
+ </style>
+
+ <style name="DockedDividerHandle">
+ <item name="android:layout_gravity">center_vertical</item>
+ <item name="android:layout_width">48dp</item>
+ <item name="android:layout_height">96dp</item>
+ </style>
+
+ <style name="DockedDividerMinimizedShadow">
+ <item name="android:layout_width">8dp</item>
+ <item name="android:layout_height">match_parent</item>
+ </style>
+</resources>
+
diff --git a/libs/WindowManager/Shell/res/values-sw600dp/config.xml b/libs/WindowManager/Shell/res/values-sw600dp/config.xml
new file mode 100644
index 000000000000..f194532f1e0d
--- /dev/null
+++ b/libs/WindowManager/Shell/res/values-sw600dp/config.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2020, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<!-- These resources are around just to allow their values to be customized
+ for different hardware and product builds. -->
+<resources>
+ <!-- Animation duration when using long press on recents to dock -->
+ <integer name="long_press_dock_anim_duration">290</integer>
+</resources> \ No newline at end of file
diff --git a/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml b/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml
new file mode 100644
index 000000000000..7920fd237a08
--- /dev/null
+++ b/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <!-- The dimensions to user for picture-in-picture action buttons. -->
+ <dimen name="picture_in_picture_button_width">100dp</dimen>
+ <dimen name="picture_in_picture_button_start_margin">-50dp</dimen>
+</resources>
+
diff --git a/libs/WindowManager/Shell/res/values/colors.xml b/libs/WindowManager/Shell/res/values/colors.xml
new file mode 100644
index 000000000000..6a19083e3788
--- /dev/null
+++ b/libs/WindowManager/Shell/res/values/colors.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright 2020, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<resources>
+ <color name="docked_divider_background">#ff000000</color>
+ <color name="docked_divider_handle">#ffffff</color>
+ <drawable name="forced_resizable_background">#59000000</drawable>
+ <color name="minimize_dock_shadow_start">#60000000</color>
+ <color name="minimize_dock_shadow_end">#00000000</color>
+</resources> \ No newline at end of file
diff --git a/libs/WindowManager/Shell/res/values/config.xml b/libs/WindowManager/Shell/res/values/config.xml
index c894eb0133b5..63b0f6ffbec3 100644
--- a/libs/WindowManager/Shell/res/values/config.xml
+++ b/libs/WindowManager/Shell/res/values/config.xml
@@ -1,21 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
-/*
-** Copyright 2019, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
<resources>
-</resources> \ No newline at end of file
+ <!-- Animation duration for resizing of PIP when entering/exiting. -->
+ <integer name="config_pipResizeAnimationDuration">425</integer>
+
+ <!-- Allow dragging the PIP to a location to close it -->
+ <bool name="config_pipEnableDismissDragToEdge">true</bool>
+
+ <!-- Allow PIP to resize to a slightly bigger state upon touch/showing the menu -->
+ <bool name="config_pipEnableResizeForMenu">true</bool>
+
+ <!-- Allow PIP to enable round corner, see also R.dimen.pip_corner_radius -->
+ <bool name="config_pipEnableRoundCorner">false</bool>
+
+ <!-- Animation duration when using long press on recents to dock -->
+ <integer name="long_press_dock_anim_duration">250</integer>
+
+ <!-- Allow one handed to enable round corner -->
+ <bool name="config_one_handed_enable_round_corner">true</bool>
+</resources>
diff --git a/libs/WindowManager/Shell/res/values/dimen.xml b/libs/WindowManager/Shell/res/values/dimen.xml
new file mode 100644
index 000000000000..7fb641a4b06e
--- /dev/null
+++ b/libs/WindowManager/Shell/res/values/dimen.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <dimen name="dismiss_circle_size">52dp</dimen>
+
+ <!-- The height of the gradient indicating the dismiss edge when moving a PIP. -->
+ <dimen name="floating_dismiss_gradient_height">250dp</dimen>
+
+ <!-- The padding around a PiP actions. -->
+ <dimen name="pip_action_padding">12dp</dimen>
+
+ <!-- The height of the PiP actions container in which the actions are vertically centered. -->
+ <dimen name="pip_action_size">48dp</dimen>
+
+ <!-- The padding between actions in the PiP in landscape Note that the PiP does not reflect
+ the configuration of the device, so we can't use -land resources. -->
+ <dimen name="pip_between_action_padding_land">8dp</dimen>
+
+ <!-- The buffer to use when calculating whether the pip is in an adjust zone. -->
+ <dimen name="pip_bottom_offset_buffer">1dp</dimen>
+
+ <!-- The corner radius for PiP window. -->
+ <dimen name="pip_corner_radius">8dp</dimen>
+
+ <!-- The bottom margin of the PIP drag to dismiss info text shown when moving a PIP. -->
+ <dimen name="pip_dismiss_text_bottom_margin">24dp</dimen>
+
+ <!-- The bottom margin of the expand container when there are actions.
+ Equal to pip_action_size - pip_action_padding. -->
+ <dimen name="pip_expand_container_edge_margin">30dp</dimen>
+
+ <!-- The shortest-edge size of the expanded PiP. -->
+ <dimen name="pip_expanded_shortest_edge_size">160dp</dimen>
+
+ <!-- The additional offset to apply to the IME animation to account for the input field. -->
+ <dimen name="pip_ime_offset">48dp</dimen>
+
+ <!-- The touchable/draggable edge size for PIP resize. -->
+ <dimen name="pip_resize_edge_size">48dp</dimen>
+
+ <!-- PIP Resize handle size, margin and padding. -->
+ <dimen name="pip_resize_handle_size">12dp</dimen>
+ <dimen name="pip_resize_handle_margin">4dp</dimen>
+ <dimen name="pip_resize_handle_padding">0dp</dimen>
+
+ <!-- How high we lift the divider when touching -->
+ <dimen name="docked_stack_divider_lift_elevation">4dp</dimen>
+
+ <dimen name="docked_divider_handle_width">16dp</dimen>
+ <dimen name="docked_divider_handle_height">2dp</dimen>
+
+ <!-- One-Handed Mode -->
+ <!-- Threshold for dragging distance to enable one-handed mode -->
+ <dimen name="gestures_onehanded_drag_threshold">20dp</dimen>
+</resources>
diff --git a/libs/WindowManager/Shell/res/values/ids.xml b/libs/WindowManager/Shell/res/values/ids.xml
new file mode 100644
index 000000000000..fb892388cf74
--- /dev/null
+++ b/libs/WindowManager/Shell/res/values/ids.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <item type="id" name="action_pip_resize" />
+
+ <!-- Accessibility actions for the docked stack divider -->
+ <item type="id" name="action_move_tl_full" />
+ <item type="id" name="action_move_tl_70" />
+ <item type="id" name="action_move_tl_50" />
+ <item type="id" name="action_move_tl_30" />
+ <item type="id" name="action_move_rb_full" />
+</resources>
diff --git a/libs/WindowManager/Shell/res/values/strings.xml b/libs/WindowManager/Shell/res/values/strings.xml
new file mode 100644
index 000000000000..b6668fbe4872
--- /dev/null
+++ b/libs/WindowManager/Shell/res/values/strings.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Label for PIP close button [CHAR LIMIT=NONE]-->
+ <string name="pip_phone_close">Close</string>
+
+ <!-- Making the PIP fullscreen [CHAR LIMIT=25] -->
+ <string name="pip_phone_expand">Expand</string>
+
+ <!-- Label for PIP settings button [CHAR LIMIT=NONE]-->
+ <string name="pip_phone_settings">Settings</string>
+
+ <!-- Title of menu shown over picture-in-picture. Used for accessibility. -->
+ <string name="pip_menu_title">Menu</string>
+
+ <!-- PiP BTW notification title. [CHAR LIMIT=50] -->
+ <string name="pip_notification_title"><xliff:g id="name" example="Google Maps">%s</xliff:g> is in picture-in-picture</string>
+
+ <!-- PiP BTW notification description. [CHAR LIMIT=NONE] -->
+ <string name="pip_notification_message">If you don\'t want <xliff:g id="name" example="Google Maps">%s</xliff:g> to use this feature, tap to open settings and turn it off.</string>
+
+ <!-- Button to play the current media on picture-in-picture (PIP) [CHAR LIMIT=30] -->
+ <string name="pip_play">Play</string>
+
+ <!-- Button to pause the current media on picture-in-picture (PIP) [CHAR LIMIT=30] -->
+ <string name="pip_pause">Pause</string>
+
+ <!-- Button to skip to the next media on picture-in-picture (PIP) [CHAR LIMIT=30] -->
+ <string name="pip_skip_to_next">Skip to next</string>
+
+ <!-- Button to skip to the prev media on picture-in-picture (PIP) [CHAR LIMIT=30] -->
+ <string name="pip_skip_to_prev">Skip to previous</string>
+
+ <!-- Accessibility action for resizing PIP [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_pip_resize">Resize</string>
+
+ <!-- TODO Deprecated. Label for PIP action to Minimize the PIP. DO NOT TRANSLATE [CHAR LIMIT=25] -->
+ <string name="pip_phone_minimize">Minimize</string>
+
+ <!-- TODO Deprecated. Label for PIP the drag to dismiss hint. DO NOT TRANSLATE [CHAR LIMIT=NONE]-->
+ <string name="pip_phone_dismiss_hint">Drag down to dismiss</string>
+
+ <!-- Multi-Window strings -->
+ <!-- Text that gets shown on top of current activity to inform the user that the system force-resized the current activity to be displayed in split-screen and that things might crash/not work properly [CHAR LIMIT=NONE] -->
+ <string name="dock_forced_resizable">App may not work with split-screen.</string>
+ <!-- Warning message when we try to dock a non-resizeable task and launch it in fullscreen instead. -->
+ <string name="dock_non_resizeble_failed_to_dock_text">App does not support split-screen.</string>
+ <!-- Text that gets shown on top of current activity to inform the user that the system force-resized the current activity to be displayed on a secondary display and that things might crash/not work properly [CHAR LIMIT=NONE] -->
+ <string name="forced_resizable_secondary_display">App may not work on a secondary display.</string>
+ <!-- Warning message when we try to launch a non-resizeable activity on a secondary display and launch it on the primary instead. -->
+ <string name="activity_launch_on_secondary_display_failed_text">App does not support launch on secondary displays.</string>
+
+ <!-- Accessibility label for the divider that separates the windows in split-screen mode [CHAR LIMIT=NONE] -->
+ <string name="accessibility_divider">Split-screen divider</string>
+
+ <!-- Accessibility action for moving docked stack divider to make the left screen full screen [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_divider_left_full">Left full screen</string>
+ <!-- Accessibility action for moving docked stack divider to make the left screen 70% [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_divider_left_70">Left 70%</string>
+ <!-- Accessibility action for moving docked stack divider to make the left screen 50% [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_divider_left_50">Left 50%</string>
+ <!-- Accessibility action for moving docked stack divider to make the left screen 30% [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_divider_left_30">Left 30%</string>
+ <!-- Accessibility action for moving docked stack divider to make the right screen full screen [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_divider_right_full">Right full screen</string>
+
+ <!-- Accessibility action for moving docked stack divider to make the top screen full screen [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_divider_top_full">Top full screen</string>
+ <!-- Accessibility action for moving docked stack divider to make the top screen 70% [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_divider_top_70">Top 70%</string>
+ <!-- Accessibility action for moving docked stack divider to make the top screen 50% [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_divider_top_50">Top 50%</string>
+ <!-- Accessibility action for moving docked stack divider to make the top screen 30% [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_divider_top_30">Top 30%</string>
+ <!-- Accessibility action for moving docked stack divider to make the bottom screen full screen [CHAR LIMIT=NONE] -->
+ <string name="accessibility_action_divider_bottom_full">Bottom full screen</string>
+
+ <!-- One-Handed Tutorial title [CHAR LIMIT=60] -->
+ <string name="one_handed_tutorial_title">Using one-handed mode</string>
+ <!-- One-Handed Tutorial description [CHAR LIMIT=NONE] -->
+ <string name="one_handed_tutorial_description">To exit, swipe up from the bottom of the screen or tap anywhere above the app</string>
+</resources>
diff --git a/libs/WindowManager/Shell/res/values/strings_tv.xml b/libs/WindowManager/Shell/res/values/strings_tv.xml
new file mode 100644
index 000000000000..2dfdcabaa931
--- /dev/null
+++ b/libs/WindowManager/Shell/res/values/strings_tv.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Picture-in-Picture (PIP) notification -->
+ <!-- Title for the notification channel for TV PIP controls. [CHAR LIMIT=NONE] -->
+ <string name="notification_channel_tv_pip">Picture-in-Picture</string>
+
+ <!-- Title of the picture-in-picture (PIP) notification title
+ when the media doesn't have title [CHAR LIMIT=NONE] -->
+ <string name="pip_notification_unknown_title">(No title program)</string>
+
+ <!-- Picture-in-Picture (PIP) menu -->
+ <eat-comment />
+ <!-- Button to close picture-in-picture (PIP) in PIP menu [CHAR LIMIT=30] -->
+ <string name="pip_close">Close PIP</string>
+
+ <!-- Button to move picture-in-picture (PIP) screen to the fullscreen in PIP menu [CHAR LIMIT=30] -->
+ <string name="pip_fullscreen">Full screen</string>
+</resources>
+
diff --git a/libs/WindowManager/Shell/res/values/styles.xml b/libs/WindowManager/Shell/res/values/styles.xml
new file mode 100644
index 000000000000..fffcd33f7992
--- /dev/null
+++ b/libs/WindowManager/Shell/res/values/styles.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- Theme used for the activity that shows when the system forced an app to be resizable -->
+ <style name="ForcedResizableTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
+ <item name="android:windowBackground">@drawable/forced_resizable_background</item>
+ <item name="android:statusBarColor">@android:color/transparent</item>
+ <item name="android:windowAnimationStyle">@style/Animation.ForcedResizable</item>
+ </style>
+
+ <style name="Animation.ForcedResizable" parent="@android:style/Animation">
+ <item name="android:activityOpenEnterAnimation">@anim/forced_resizable_enter</item>
+
+ <!-- If the target stack doesn't have focus, we do a task to front animation. -->
+ <item name="android:taskToFrontEnterAnimation">@anim/forced_resizable_enter</item>
+ <item name="android:activityCloseExitAnimation">@anim/forced_resizable_exit</item>
+ </style>
+
+ <style name="DockedDividerBackground">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">10dp</item>
+ <item name="android:layout_gravity">center_vertical</item>
+ </style>
+
+ <style name="DockedDividerMinimizedShadow">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">8dp</item>
+ </style>
+
+ <style name="DockedDividerHandle">
+ <item name="android:layout_gravity">center_horizontal</item>
+ <item name="android:layout_width">96dp</item>
+ <item name="android:layout_height">48dp</item>
+ </style>
+</resources>
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java
new file mode 100644
index 000000000000..f9ba695c8503
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell;
+
+import android.app.ActivityManager.RunningTaskInfo;
+import android.util.Log;
+import android.util.Pair;
+import android.util.SparseArray;
+import android.view.SurfaceControl;
+import android.window.ITaskOrganizerController;
+import android.window.TaskOrganizer;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.protolog.common.ProtoLog;
+import com.android.wm.shell.protolog.ShellProtoLogGroup;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * Unified task organizer for all components in the shell.
+ * TODO(b/167582004): may consider consolidating this class and TaskOrganizer
+ */
+public class ShellTaskOrganizer extends TaskOrganizer {
+
+ private static final String TAG = "ShellTaskOrganizer";
+
+ /**
+ * Callbacks for when the tasks change in the system.
+ */
+ public interface TaskListener {
+ default void onTaskAppeared(RunningTaskInfo taskInfo, SurfaceControl leash) {}
+ default void onTaskInfoChanged(RunningTaskInfo taskInfo) {}
+ default void onTaskVanished(RunningTaskInfo taskInfo) {}
+ default void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) {}
+ }
+
+ private final SparseArray<ArrayList<TaskListener>> mListenersByWindowingMode =
+ new SparseArray<>();
+
+ // Keeps track of all the tasks reported to this organizer (changes in windowing mode will
+ // require us to report to both old and new listeners)
+ private final SparseArray<Pair<RunningTaskInfo, SurfaceControl>> mTasks = new SparseArray<>();
+
+ public ShellTaskOrganizer() {
+ super();
+ }
+
+ @VisibleForTesting
+ ShellTaskOrganizer(ITaskOrganizerController taskOrganizerController) {
+ super(taskOrganizerController);
+ }
+
+ /**
+ * Adds a listener for tasks in a specific windowing mode.
+ */
+ public void addListener(TaskListener listener, int... windowingModes) {
+ ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TASK_ORG, "Add listener for modes=%s listener=%s",
+ Arrays.toString(windowingModes), listener);
+ for (int winMode : windowingModes) {
+ ArrayList<TaskListener> listeners = mListenersByWindowingMode.get(winMode);
+ if (listeners == null) {
+ listeners = new ArrayList<>();
+ mListenersByWindowingMode.put(winMode, listeners);
+ }
+ if (listeners.contains(listener)) {
+ Log.w(TAG, "Listener already exists");
+ return;
+ }
+ listeners.add(listener);
+
+ // Notify the listener of all existing tasks in that windowing mode
+ for (int i = mTasks.size() - 1; i >= 0; i--) {
+ Pair<RunningTaskInfo, SurfaceControl> data = mTasks.valueAt(i);
+ int taskWinMode = data.first.configuration.windowConfiguration.getWindowingMode();
+ if (taskWinMode == winMode) {
+ listener.onTaskAppeared(data.first, data.second);
+ }
+ }
+ }
+ }
+
+ /**
+ * Removes a registered listener.
+ */
+ public void removeListener(TaskListener listener) {
+ ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TASK_ORG, "Remove listener=%s", listener);
+ for (int i = 0; i < mListenersByWindowingMode.size(); i++) {
+ mListenersByWindowingMode.valueAt(i).remove(listener);
+ }
+ }
+
+ @Override
+ public void onTaskAppeared(RunningTaskInfo taskInfo, SurfaceControl leash) {
+ ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TASK_ORG, "Task appeared taskId=%d",
+ taskInfo.taskId);
+ mTasks.put(taskInfo.taskId, new Pair<>(taskInfo, leash));
+ ArrayList<TaskListener> listeners = mListenersByWindowingMode.get(
+ getWindowingMode(taskInfo));
+ if (listeners != null) {
+ for (int i = listeners.size() - 1; i >= 0; i--) {
+ listeners.get(i).onTaskAppeared(taskInfo, leash);
+ }
+ }
+ }
+
+ @Override
+ public void onTaskInfoChanged(RunningTaskInfo taskInfo) {
+ ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TASK_ORG, "Task info changed taskId=%d",
+ taskInfo.taskId);
+ Pair<RunningTaskInfo, SurfaceControl> data = mTasks.get(taskInfo.taskId);
+ int winMode = getWindowingMode(taskInfo);
+ int prevWinMode = getWindowingMode(data.first);
+ if (prevWinMode != -1 && prevWinMode != winMode) {
+ // TODO: We currently send vanished/appeared as the task moves between win modes, but
+ // we should consider adding a different mode-changed callback
+ ArrayList<TaskListener> listeners = mListenersByWindowingMode.get(prevWinMode);
+ if (listeners != null) {
+ for (int i = listeners.size() - 1; i >= 0; i--) {
+ listeners.get(i).onTaskVanished(taskInfo);
+ }
+ }
+ listeners = mListenersByWindowingMode.get(winMode);
+ if (listeners != null) {
+ SurfaceControl leash = data.second;
+ for (int i = listeners.size() - 1; i >= 0; i--) {
+ listeners.get(i).onTaskAppeared(taskInfo, leash);
+ }
+ }
+ } else {
+ ArrayList<TaskListener> listeners = mListenersByWindowingMode.get(winMode);
+ if (listeners != null) {
+ for (int i = listeners.size() - 1; i >= 0; i--) {
+ listeners.get(i).onTaskInfoChanged(taskInfo);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) {
+ ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TASK_ORG, "Task root back pressed taskId=%d",
+ taskInfo.taskId);
+ ArrayList<TaskListener> listeners = mListenersByWindowingMode.get(
+ getWindowingMode(taskInfo));
+ if (listeners != null) {
+ for (int i = listeners.size() - 1; i >= 0; i--) {
+ listeners.get(i).onBackPressedOnTaskRoot(taskInfo);
+ }
+ }
+ }
+
+ @Override
+ public void onTaskVanished(RunningTaskInfo taskInfo) {
+ ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TASK_ORG, "Task vanished taskId=%d",
+ taskInfo.taskId);
+ int prevWinMode = getWindowingMode(mTasks.get(taskInfo.taskId).first);
+ mTasks.remove(taskInfo.taskId);
+ ArrayList<TaskListener> listeners = mListenersByWindowingMode.get(prevWinMode);
+ if (listeners != null) {
+ for (int i = listeners.size() - 1; i >= 0; i--) {
+ listeners.get(i).onTaskVanished(taskInfo);
+ }
+ }
+ }
+
+ private int getWindowingMode(RunningTaskInfo taskInfo) {
+ return taskInfo.configuration.windowConfiguration.getWindowingMode();
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/animation/FlingAnimationUtils.java b/libs/WindowManager/Shell/src/com/android/wm/shell/animation/FlingAnimationUtils.java
new file mode 100644
index 000000000000..357f777e1270
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/animation/FlingAnimationUtils.java
@@ -0,0 +1,423 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.animation;
+
+import android.animation.Animator;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.ViewPropertyAnimator;
+import android.view.animation.Interpolator;
+import android.view.animation.PathInterpolator;
+
+/**
+ * Utility class to calculate general fling animation when the finger is released.
+ */
+public class FlingAnimationUtils {
+
+ private static final String TAG = "FlingAnimationUtils";
+
+ private static final float LINEAR_OUT_SLOW_IN_X2 = 0.35f;
+ private static final float LINEAR_OUT_SLOW_IN_X2_MAX = 0.68f;
+ private static final float LINEAR_OUT_FASTER_IN_X2 = 0.5f;
+ private static final float LINEAR_OUT_FASTER_IN_Y2_MIN = 0.4f;
+ private static final float LINEAR_OUT_FASTER_IN_Y2_MAX = 0.5f;
+ private static final float MIN_VELOCITY_DP_PER_SECOND = 250;
+ private static final float HIGH_VELOCITY_DP_PER_SECOND = 3000;
+
+ private static final float LINEAR_OUT_SLOW_IN_START_GRADIENT = 0.75f;
+ private final float mSpeedUpFactor;
+ private final float mY2;
+
+ private float mMinVelocityPxPerSecond;
+ private float mMaxLengthSeconds;
+ private float mHighVelocityPxPerSecond;
+ private float mLinearOutSlowInX2;
+
+ private AnimatorProperties mAnimatorProperties = new AnimatorProperties();
+ private PathInterpolator mInterpolator;
+ private float mCachedStartGradient = -1;
+ private float mCachedVelocityFactor = -1;
+
+ public FlingAnimationUtils(DisplayMetrics displayMetrics, float maxLengthSeconds) {
+ this(displayMetrics, maxLengthSeconds, 0.0f);
+ }
+
+ /**
+ * @param maxLengthSeconds the longest duration an animation can become in seconds
+ * @param speedUpFactor a factor from 0 to 1 how much the slow down should be shifted towards
+ * the end of the animation. 0 means it's at the beginning and no
+ * acceleration will take place.
+ */
+ public FlingAnimationUtils(DisplayMetrics displayMetrics, float maxLengthSeconds,
+ float speedUpFactor) {
+ this(displayMetrics, maxLengthSeconds, speedUpFactor, -1.0f, 1.0f);
+ }
+
+ /**
+ * @param maxLengthSeconds the longest duration an animation can become in seconds
+ * @param speedUpFactor a factor from 0 to 1 how much the slow down should be shifted towards
+ * the end of the animation. 0 means it's at the beginning and no
+ * acceleration will take place.
+ * @param x2 the x value to take for the second point of the bezier spline. If a
+ * value below 0 is provided, the value is automatically calculated.
+ * @param y2 the y value to take for the second point of the bezier spline
+ */
+ public FlingAnimationUtils(DisplayMetrics displayMetrics, float maxLengthSeconds,
+ float speedUpFactor, float x2, float y2) {
+ mMaxLengthSeconds = maxLengthSeconds;
+ mSpeedUpFactor = speedUpFactor;
+ if (x2 < 0) {
+ mLinearOutSlowInX2 = interpolate(LINEAR_OUT_SLOW_IN_X2,
+ LINEAR_OUT_SLOW_IN_X2_MAX,
+ mSpeedUpFactor);
+ } else {
+ mLinearOutSlowInX2 = x2;
+ }
+ mY2 = y2;
+
+ mMinVelocityPxPerSecond = MIN_VELOCITY_DP_PER_SECOND * displayMetrics.density;
+ mHighVelocityPxPerSecond = HIGH_VELOCITY_DP_PER_SECOND * displayMetrics.density;
+ }
+
+ /**
+ * Applies the interpolator and length to the animator, such that the fling animation is
+ * consistent with the finger motion.
+ *
+ * @param animator the animator to apply
+ * @param currValue the current value
+ * @param endValue the end value of the animator
+ * @param velocity the current velocity of the motion
+ */
+ public void apply(Animator animator, float currValue, float endValue, float velocity) {
+ apply(animator, currValue, endValue, velocity, Math.abs(endValue - currValue));
+ }
+
+ /**
+ * Applies the interpolator and length to the animator, such that the fling animation is
+ * consistent with the finger motion.
+ *
+ * @param animator the animator to apply
+ * @param currValue the current value
+ * @param endValue the end value of the animator
+ * @param velocity the current velocity of the motion
+ */
+ public void apply(ViewPropertyAnimator animator, float currValue, float endValue,
+ float velocity) {
+ apply(animator, currValue, endValue, velocity, Math.abs(endValue - currValue));
+ }
+
+ /**
+ * Applies the interpolator and length to the animator, such that the fling animation is
+ * consistent with the finger motion.
+ *
+ * @param animator the animator to apply
+ * @param currValue the current value
+ * @param endValue the end value of the animator
+ * @param velocity the current velocity of the motion
+ * @param maxDistance the maximum distance for this interaction; the maximum animation length
+ * gets multiplied by the ratio between the actual distance and this value
+ */
+ public void apply(Animator animator, float currValue, float endValue, float velocity,
+ float maxDistance) {
+ AnimatorProperties properties = getProperties(currValue, endValue, velocity,
+ maxDistance);
+ animator.setDuration(properties.mDuration);
+ animator.setInterpolator(properties.mInterpolator);
+ }
+
+ /**
+ * Applies the interpolator and length to the animator, such that the fling animation is
+ * consistent with the finger motion.
+ *
+ * @param animator the animator to apply
+ * @param currValue the current value
+ * @param endValue the end value of the animator
+ * @param velocity the current velocity of the motion
+ * @param maxDistance the maximum distance for this interaction; the maximum animation length
+ * gets multiplied by the ratio between the actual distance and this value
+ */
+ public void apply(ViewPropertyAnimator animator, float currValue, float endValue,
+ float velocity, float maxDistance) {
+ AnimatorProperties properties = getProperties(currValue, endValue, velocity,
+ maxDistance);
+ animator.setDuration(properties.mDuration);
+ animator.setInterpolator(properties.mInterpolator);
+ }
+
+ private AnimatorProperties getProperties(float currValue,
+ float endValue, float velocity, float maxDistance) {
+ float maxLengthSeconds = (float) (mMaxLengthSeconds
+ * Math.sqrt(Math.abs(endValue - currValue) / maxDistance));
+ float diff = Math.abs(endValue - currValue);
+ float velAbs = Math.abs(velocity);
+ float velocityFactor = mSpeedUpFactor == 0.0f
+ ? 1.0f : Math.min(velAbs / HIGH_VELOCITY_DP_PER_SECOND, 1.0f);
+ float startGradient = interpolate(LINEAR_OUT_SLOW_IN_START_GRADIENT,
+ mY2 / mLinearOutSlowInX2, velocityFactor);
+ float durationSeconds = startGradient * diff / velAbs;
+ Interpolator slowInInterpolator = getInterpolator(startGradient, velocityFactor);
+ if (durationSeconds <= maxLengthSeconds) {
+ mAnimatorProperties.mInterpolator = slowInInterpolator;
+ } else if (velAbs >= mMinVelocityPxPerSecond) {
+
+ // Cross fade between fast-out-slow-in and linear interpolator with current velocity.
+ durationSeconds = maxLengthSeconds;
+ VelocityInterpolator velocityInterpolator = new VelocityInterpolator(
+ durationSeconds, velAbs, diff);
+ InterpolatorInterpolator superInterpolator = new InterpolatorInterpolator(
+ velocityInterpolator, slowInInterpolator, Interpolators.LINEAR_OUT_SLOW_IN);
+ mAnimatorProperties.mInterpolator = superInterpolator;
+ } else {
+
+ // Just use a normal interpolator which doesn't take the velocity into account.
+ durationSeconds = maxLengthSeconds;
+ mAnimatorProperties.mInterpolator = Interpolators.FAST_OUT_SLOW_IN;
+ }
+ mAnimatorProperties.mDuration = (long) (durationSeconds * 1000);
+ return mAnimatorProperties;
+ }
+
+ private Interpolator getInterpolator(float startGradient, float velocityFactor) {
+ if (Float.isNaN(velocityFactor)) {
+ Log.e(TAG, "Invalid velocity factor", new Throwable());
+ return Interpolators.LINEAR_OUT_SLOW_IN;
+ }
+ if (startGradient != mCachedStartGradient
+ || velocityFactor != mCachedVelocityFactor) {
+ float speedup = mSpeedUpFactor * (1.0f - velocityFactor);
+ float x1 = speedup;
+ float y1 = speedup * startGradient;
+ float x2 = mLinearOutSlowInX2;
+ float y2 = mY2;
+ try {
+ mInterpolator = new PathInterpolator(x1, y1, x2, y2);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Illegal path with "
+ + "x1=" + x1 + " y1=" + y1 + " x2=" + x2 + " y2=" + y2, e);
+ }
+ mCachedStartGradient = startGradient;
+ mCachedVelocityFactor = velocityFactor;
+ }
+ return mInterpolator;
+ }
+
+ /**
+ * Applies the interpolator and length to the animator, such that the fling animation is
+ * consistent with the finger motion for the case when the animation is making something
+ * disappear.
+ *
+ * @param animator the animator to apply
+ * @param currValue the current value
+ * @param endValue the end value of the animator
+ * @param velocity the current velocity of the motion
+ * @param maxDistance the maximum distance for this interaction; the maximum animation length
+ * gets multiplied by the ratio between the actual distance and this value
+ */
+ public void applyDismissing(Animator animator, float currValue, float endValue,
+ float velocity, float maxDistance) {
+ AnimatorProperties properties = getDismissingProperties(currValue, endValue, velocity,
+ maxDistance);
+ animator.setDuration(properties.mDuration);
+ animator.setInterpolator(properties.mInterpolator);
+ }
+
+ /**
+ * Applies the interpolator and length to the animator, such that the fling animation is
+ * consistent with the finger motion for the case when the animation is making something
+ * disappear.
+ *
+ * @param animator the animator to apply
+ * @param currValue the current value
+ * @param endValue the end value of the animator
+ * @param velocity the current velocity of the motion
+ * @param maxDistance the maximum distance for this interaction; the maximum animation length
+ * gets multiplied by the ratio between the actual distance and this value
+ */
+ public void applyDismissing(ViewPropertyAnimator animator, float currValue, float endValue,
+ float velocity, float maxDistance) {
+ AnimatorProperties properties = getDismissingProperties(currValue, endValue, velocity,
+ maxDistance);
+ animator.setDuration(properties.mDuration);
+ animator.setInterpolator(properties.mInterpolator);
+ }
+
+ private AnimatorProperties getDismissingProperties(float currValue, float endValue,
+ float velocity, float maxDistance) {
+ float maxLengthSeconds = (float) (mMaxLengthSeconds
+ * Math.pow(Math.abs(endValue - currValue) / maxDistance, 0.5f));
+ float diff = Math.abs(endValue - currValue);
+ float velAbs = Math.abs(velocity);
+ float y2 = calculateLinearOutFasterInY2(velAbs);
+
+ float startGradient = y2 / LINEAR_OUT_FASTER_IN_X2;
+ Interpolator mLinearOutFasterIn = new PathInterpolator(0, 0, LINEAR_OUT_FASTER_IN_X2, y2);
+ float durationSeconds = startGradient * diff / velAbs;
+ if (durationSeconds <= maxLengthSeconds) {
+ mAnimatorProperties.mInterpolator = mLinearOutFasterIn;
+ } else if (velAbs >= mMinVelocityPxPerSecond) {
+
+ // Cross fade between linear-out-faster-in and linear interpolator with current
+ // velocity.
+ durationSeconds = maxLengthSeconds;
+ VelocityInterpolator velocityInterpolator = new VelocityInterpolator(
+ durationSeconds, velAbs, diff);
+ InterpolatorInterpolator superInterpolator = new InterpolatorInterpolator(
+ velocityInterpolator, mLinearOutFasterIn, Interpolators.LINEAR_OUT_SLOW_IN);
+ mAnimatorProperties.mInterpolator = superInterpolator;
+ } else {
+
+ // Just use a normal interpolator which doesn't take the velocity into account.
+ durationSeconds = maxLengthSeconds;
+ mAnimatorProperties.mInterpolator = Interpolators.FAST_OUT_LINEAR_IN;
+ }
+ mAnimatorProperties.mDuration = (long) (durationSeconds * 1000);
+ return mAnimatorProperties;
+ }
+
+ /**
+ * Calculates the y2 control point for a linear-out-faster-in path interpolator depending on the
+ * velocity. The faster the velocity, the more "linear" the interpolator gets.
+ *
+ * @param velocity the velocity of the gesture.
+ * @return the y2 control point for a cubic bezier path interpolator
+ */
+ private float calculateLinearOutFasterInY2(float velocity) {
+ float t = (velocity - mMinVelocityPxPerSecond)
+ / (mHighVelocityPxPerSecond - mMinVelocityPxPerSecond);
+ t = Math.max(0, Math.min(1, t));
+ return (1 - t) * LINEAR_OUT_FASTER_IN_Y2_MIN + t * LINEAR_OUT_FASTER_IN_Y2_MAX;
+ }
+
+ /**
+ * @return the minimum velocity a gesture needs to have to be considered a fling
+ */
+ public float getMinVelocityPxPerSecond() {
+ return mMinVelocityPxPerSecond;
+ }
+
+ /**
+ * An interpolator which interpolates two interpolators with an interpolator.
+ */
+ private static final class InterpolatorInterpolator implements Interpolator {
+
+ private Interpolator mInterpolator1;
+ private Interpolator mInterpolator2;
+ private Interpolator mCrossfader;
+
+ InterpolatorInterpolator(Interpolator interpolator1, Interpolator interpolator2,
+ Interpolator crossfader) {
+ mInterpolator1 = interpolator1;
+ mInterpolator2 = interpolator2;
+ mCrossfader = crossfader;
+ }
+
+ @Override
+ public float getInterpolation(float input) {
+ float t = mCrossfader.getInterpolation(input);
+ return (1 - t) * mInterpolator1.getInterpolation(input)
+ + t * mInterpolator2.getInterpolation(input);
+ }
+ }
+
+ /**
+ * An interpolator which interpolates with a fixed velocity.
+ */
+ private static final class VelocityInterpolator implements Interpolator {
+
+ private float mDurationSeconds;
+ private float mVelocity;
+ private float mDiff;
+
+ private VelocityInterpolator(float durationSeconds, float velocity, float diff) {
+ mDurationSeconds = durationSeconds;
+ mVelocity = velocity;
+ mDiff = diff;
+ }
+
+ @Override
+ public float getInterpolation(float input) {
+ float time = input * mDurationSeconds;
+ return time * mVelocity / mDiff;
+ }
+ }
+
+ private static class AnimatorProperties {
+ Interpolator mInterpolator;
+ long mDuration;
+ }
+
+ /** Builder for {@link #FlingAnimationUtils}. */
+ public static class Builder {
+ private final DisplayMetrics mDisplayMetrics;
+ float mMaxLengthSeconds;
+ float mSpeedUpFactor;
+ float mX2;
+ float mY2;
+
+ public Builder(DisplayMetrics displayMetrics) {
+ mDisplayMetrics = displayMetrics;
+ reset();
+ }
+
+ /** Sets the longest duration an animation can become in seconds. */
+ public Builder setMaxLengthSeconds(float maxLengthSeconds) {
+ mMaxLengthSeconds = maxLengthSeconds;
+ return this;
+ }
+
+ /**
+ * Sets the factor for how much the slow down should be shifted towards the end of the
+ * animation.
+ */
+ public Builder setSpeedUpFactor(float speedUpFactor) {
+ mSpeedUpFactor = speedUpFactor;
+ return this;
+ }
+
+ /** Sets the x value to take for the second point of the bezier spline. */
+ public Builder setX2(float x2) {
+ mX2 = x2;
+ return this;
+ }
+
+ /** Sets the y value to take for the second point of the bezier spline. */
+ public Builder setY2(float y2) {
+ mY2 = y2;
+ return this;
+ }
+
+ /** Resets all parameters of the builder. */
+ public Builder reset() {
+ mMaxLengthSeconds = 0;
+ mSpeedUpFactor = 0.0f;
+ mX2 = -1.0f;
+ mY2 = 1.0f;
+
+ return this;
+ }
+
+ /** Builds {@link #FlingAnimationUtils}. */
+ public FlingAnimationUtils build() {
+ return new FlingAnimationUtils(mDisplayMetrics, mMaxLengthSeconds, mSpeedUpFactor,
+ mX2, mY2);
+ }
+ }
+
+ private static float interpolate(float start, float end, float amount) {
+ return start * (1.0f - amount) + end * amount;
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/animation/Interpolators.java b/libs/WindowManager/Shell/src/com/android/wm/shell/animation/Interpolators.java
new file mode 100644
index 000000000000..b794b91568fc
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/animation/Interpolators.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.animation;
+
+import android.view.animation.Interpolator;
+import android.view.animation.PathInterpolator;
+
+/**
+ * Common interpolators used in wm shell library.
+ */
+public class Interpolators {
+ /**
+ * Interpolator for fast out linear in animation.
+ */
+ public static final Interpolator FAST_OUT_LINEAR_IN = new PathInterpolator(0.4f, 0f, 1f, 1f);
+
+ /**
+ * Interpolator for fast out slow in animation.
+ */
+ public static final Interpolator FAST_OUT_SLOW_IN = new PathInterpolator(0.4f, 0f, 0.2f, 1f);
+
+ /**
+ * Interpolator for linear out slow in animation.
+ */
+ public static final Interpolator LINEAR_OUT_SLOW_IN = new PathInterpolator(0f, 0f, 0.2f, 1f);
+
+ /**
+ * Interpolator to be used when animating a move based on a click. Pair with enough duration.
+ */
+ public static final Interpolator TOUCH_RESPONSE = new PathInterpolator(0.3f, 0f, 0.1f, 1f);
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayChangeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayChangeController.java
new file mode 100644
index 000000000000..3263f79888d6
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayChangeController.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.common;
+
+import android.os.Handler;
+import android.os.RemoteException;
+import android.view.IDisplayWindowRotationCallback;
+import android.view.IDisplayWindowRotationController;
+import android.view.IWindowManager;
+import android.window.WindowContainerTransaction;
+
+import java.util.ArrayList;
+
+/**
+ * This module deals with display rotations coming from WM. When WM starts a rotation: after it has
+ * frozen the screen, it will call into this class. This will then call all registered local
+ * controllers and give them a chance to queue up task changes to be applied synchronously with that
+ * rotation.
+ */
+public class DisplayChangeController {
+
+ private final Handler mHandler;
+ private final IWindowManager mWmService;
+
+ private final ArrayList<OnDisplayChangingListener> mRotationListener =
+ new ArrayList<>();
+ private final ArrayList<OnDisplayChangingListener> mTmpListeners = new ArrayList<>();
+
+ private final IDisplayWindowRotationController mDisplayRotationController =
+ new IDisplayWindowRotationController.Stub() {
+ @Override
+ public void onRotateDisplay(int displayId, final int fromRotation,
+ final int toRotation, IDisplayWindowRotationCallback callback) {
+ mHandler.post(() -> {
+ WindowContainerTransaction t = new WindowContainerTransaction();
+ synchronized (mRotationListener) {
+ mTmpListeners.clear();
+ // Make a local copy in case the handlers add/remove themselves.
+ mTmpListeners.addAll(mRotationListener);
+ }
+ for (OnDisplayChangingListener c : mTmpListeners) {
+ c.onRotateDisplay(displayId, fromRotation, toRotation, t);
+ }
+ try {
+ callback.continueRotateDisplay(toRotation, t);
+ } catch (RemoteException e) {
+ }
+ });
+ }
+ };
+
+ public DisplayChangeController(Handler mainHandler, IWindowManager wmService) {
+ mHandler = mainHandler;
+ mWmService = wmService;
+ try {
+ mWmService.setDisplayWindowRotationController(mDisplayRotationController);
+ } catch (RemoteException e) {
+ throw new RuntimeException("Unable to register rotation controller");
+ }
+ }
+
+ /**
+ * Adds a display rotation controller.
+ */
+ public void addRotationListener(OnDisplayChangingListener listener) {
+ synchronized (mRotationListener) {
+ mRotationListener.add(listener);
+ }
+ }
+
+ /**
+ * Removes a display rotation controller.
+ */
+ public void removeRotationListener(OnDisplayChangingListener listener) {
+ synchronized (mRotationListener) {
+ mRotationListener.remove(listener);
+ }
+ }
+
+ /**
+ * Give a listener a chance to queue up configuration changes to execute as part of a
+ * display rotation. The contents of {@link #onRotateDisplay} must run synchronously.
+ */
+ public interface OnDisplayChangingListener {
+ /**
+ * Called before the display is rotated. Contents of this method must run synchronously.
+ * @param displayId Id of display that is rotating.
+ * @param fromRotation starting rotation of the display.
+ * @param toRotation target rotation of the display (after rotating).
+ * @param t A task transaction to populate.
+ */
+ void onRotateDisplay(int displayId, int fromRotation, int toRotation,
+ WindowContainerTransaction t);
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayController.java
new file mode 100644
index 000000000000..418973204add
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayController.java
@@ -0,0 +1,273 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.common;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.hardware.display.DisplayManager;
+import android.os.Handler;
+import android.os.RemoteException;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.view.Display;
+import android.view.IDisplayWindowListener;
+import android.view.IWindowManager;
+
+import com.android.wm.shell.common.DisplayChangeController.OnDisplayChangingListener;
+
+import java.util.ArrayList;
+
+/**
+ * This module deals with display rotations coming from WM. When WM starts a rotation: after it has
+ * frozen the screen, it will call into this class. This will then call all registered local
+ * controllers and give them a chance to queue up task changes to be applied synchronously with that
+ * rotation.
+ */
+public class DisplayController {
+ private static final String TAG = "DisplayController";
+
+ private final Handler mHandler;
+ private final Context mContext;
+ private final IWindowManager mWmService;
+ private final DisplayChangeController mChangeController;
+
+ private final SparseArray<DisplayRecord> mDisplays = new SparseArray<>();
+ private final ArrayList<OnDisplaysChangedListener> mDisplayChangedListeners = new ArrayList<>();
+
+ /**
+ * Gets a display by id from DisplayManager.
+ */
+ public Display getDisplay(int displayId) {
+ final DisplayManager displayManager = mContext.getSystemService(DisplayManager.class);
+ return displayManager.getDisplay(displayId);
+ }
+
+ private final IDisplayWindowListener mDisplayContainerListener =
+ new IDisplayWindowListener.Stub() {
+ @Override
+ public void onDisplayAdded(int displayId) {
+ mHandler.post(() -> {
+ synchronized (mDisplays) {
+ if (mDisplays.get(displayId) != null) {
+ return;
+ }
+ Display display = getDisplay(displayId);
+ if (display == null) {
+ // It's likely that the display is private to some app and thus not
+ // accessible by system-ui.
+ return;
+ }
+ DisplayRecord record = new DisplayRecord();
+ record.mDisplayId = displayId;
+ record.mContext = (displayId == Display.DEFAULT_DISPLAY) ? mContext
+ : mContext.createDisplayContext(display);
+ record.mDisplayLayout = new DisplayLayout(record.mContext, display);
+ mDisplays.put(displayId, record);
+ for (int i = 0; i < mDisplayChangedListeners.size(); ++i) {
+ mDisplayChangedListeners.get(i).onDisplayAdded(displayId);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onDisplayConfigurationChanged(int displayId, Configuration newConfig) {
+ mHandler.post(() -> {
+ synchronized (mDisplays) {
+ DisplayRecord dr = mDisplays.get(displayId);
+ if (dr == null) {
+ Slog.w(TAG, "Skipping Display Configuration change on non-added"
+ + " display.");
+ return;
+ }
+ Display display = getDisplay(displayId);
+ if (display == null) {
+ Slog.w(TAG, "Skipping Display Configuration change on invalid"
+ + " display. It may have been removed.");
+ return;
+ }
+ Context perDisplayContext = mContext;
+ if (displayId != Display.DEFAULT_DISPLAY) {
+ perDisplayContext = mContext.createDisplayContext(display);
+ }
+ dr.mContext = perDisplayContext.createConfigurationContext(newConfig);
+ dr.mDisplayLayout = new DisplayLayout(dr.mContext, display);
+ for (int i = 0; i < mDisplayChangedListeners.size(); ++i) {
+ mDisplayChangedListeners.get(i).onDisplayConfigurationChanged(
+ displayId, newConfig);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onDisplayRemoved(int displayId) {
+ mHandler.post(() -> {
+ synchronized (mDisplays) {
+ if (mDisplays.get(displayId) == null) {
+ return;
+ }
+ for (int i = mDisplayChangedListeners.size() - 1; i >= 0; --i) {
+ mDisplayChangedListeners.get(i).onDisplayRemoved(displayId);
+ }
+ mDisplays.remove(displayId);
+ }
+ });
+ }
+
+ @Override
+ public void onFixedRotationStarted(int displayId, int newRotation) {
+ mHandler.post(() -> {
+ synchronized (mDisplays) {
+ if (mDisplays.get(displayId) == null || getDisplay(displayId) == null) {
+ Slog.w(TAG, "Skipping onFixedRotationStarted on unknown"
+ + " display, displayId=" + displayId);
+ return;
+ }
+ for (int i = mDisplayChangedListeners.size() - 1; i >= 0; --i) {
+ mDisplayChangedListeners.get(i).onFixedRotationStarted(
+ displayId, newRotation);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onFixedRotationFinished(int displayId) {
+ mHandler.post(() -> {
+ synchronized (mDisplays) {
+ if (mDisplays.get(displayId) == null || getDisplay(displayId) == null) {
+ Slog.w(TAG, "Skipping onFixedRotationFinished on unknown"
+ + " display, displayId=" + displayId);
+ return;
+ }
+ for (int i = mDisplayChangedListeners.size() - 1; i >= 0; --i) {
+ mDisplayChangedListeners.get(i).onFixedRotationFinished(displayId);
+ }
+ }
+ });
+ }
+ };
+
+ public DisplayController(Context context, Handler handler,
+ IWindowManager wmService) {
+ mHandler = handler;
+ mContext = context;
+ mWmService = wmService;
+ mChangeController = new DisplayChangeController(mHandler, mWmService);
+ try {
+ mWmService.registerDisplayWindowListener(mDisplayContainerListener);
+ } catch (RemoteException e) {
+ throw new RuntimeException("Unable to register hierarchy listener");
+ }
+ }
+
+ /**
+ * Gets the DisplayLayout associated with a display.
+ */
+ public @Nullable DisplayLayout getDisplayLayout(int displayId) {
+ final DisplayRecord r = mDisplays.get(displayId);
+ return r != null ? r.mDisplayLayout : null;
+ }
+
+ /**
+ * Gets a display-specific context for a display.
+ */
+ public @Nullable Context getDisplayContext(int displayId) {
+ final DisplayRecord r = mDisplays.get(displayId);
+ return r != null ? r.mContext : null;
+ }
+
+ /**
+ * Add a display window-container listener. It will get notified whenever a display's
+ * configuration changes or when displays are added/removed from the WM hierarchy.
+ */
+ public void addDisplayWindowListener(OnDisplaysChangedListener listener) {
+ synchronized (mDisplays) {
+ if (mDisplayChangedListeners.contains(listener)) {
+ return;
+ }
+ mDisplayChangedListeners.add(listener);
+ for (int i = 0; i < mDisplays.size(); ++i) {
+ listener.onDisplayAdded(mDisplays.keyAt(i));
+ }
+ }
+ }
+
+ /**
+ * Remove a display window-container listener.
+ */
+ public void removeDisplayWindowListener(OnDisplaysChangedListener listener) {
+ synchronized (mDisplays) {
+ mDisplayChangedListeners.remove(listener);
+ }
+ }
+
+ /**
+ * Adds a display rotation controller.
+ */
+ public void addDisplayChangingController(OnDisplayChangingListener controller) {
+ mChangeController.addRotationListener(controller);
+ }
+
+ /**
+ * Removes a display rotation controller.
+ */
+ public void removeDisplayChangingController(OnDisplayChangingListener controller) {
+ mChangeController.removeRotationListener(controller);
+ }
+
+ private static class DisplayRecord {
+ int mDisplayId;
+ Context mContext;
+ DisplayLayout mDisplayLayout;
+ }
+
+ /**
+ * Gets notified when a display is added/removed to the WM hierarchy and when a display's
+ * window-configuration changes.
+ *
+ * @see IDisplayWindowListener
+ */
+ public interface OnDisplaysChangedListener {
+ /**
+ * Called when a display has been added to the WM hierarchy.
+ */
+ default void onDisplayAdded(int displayId) {}
+
+ /**
+ * Called when a display's window-container configuration changes.
+ */
+ default void onDisplayConfigurationChanged(int displayId, Configuration newConfig) {}
+
+ /**
+ * Called when a display is removed.
+ */
+ default void onDisplayRemoved(int displayId) {}
+
+ /**
+ * Called when fixed rotation on a display is started.
+ */
+ default void onFixedRotationStarted(int displayId, int newRotation) {}
+
+ /**
+ * Called when fixed rotation on a display is finished.
+ */
+ default void onFixedRotationFinished(int displayId) {}
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java
new file mode 100644
index 000000000000..283fd8d997c9
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java
@@ -0,0 +1,497 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.common;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ValueAnimator;
+import android.annotation.IntDef;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.view.IDisplayWindowInsetsController;
+import android.view.IWindowManager;
+import android.view.InsetsSource;
+import android.view.InsetsSourceControl;
+import android.view.InsetsState;
+import android.view.Surface;
+import android.view.SurfaceControl;
+import android.view.WindowInsets;
+import android.view.animation.Interpolator;
+import android.view.animation.PathInterpolator;
+
+import com.android.internal.view.IInputMethodManager;
+
+import java.util.ArrayList;
+
+/**
+ * Manages IME control at the display-level. This occurs when IME comes up in multi-window mode.
+ */
+public class DisplayImeController implements DisplayController.OnDisplaysChangedListener {
+ private static final String TAG = "DisplayImeController";
+
+ private static final boolean DEBUG = false;
+
+ // NOTE: All these constants came from InsetsController.
+ public static final int ANIMATION_DURATION_SHOW_MS = 275;
+ public static final int ANIMATION_DURATION_HIDE_MS = 340;
+ public static final Interpolator INTERPOLATOR = new PathInterpolator(0.4f, 0f, 0.2f, 1f);
+ private static final int DIRECTION_NONE = 0;
+ private static final int DIRECTION_SHOW = 1;
+ private static final int DIRECTION_HIDE = 2;
+ private static final int FLOATING_IME_BOTTOM_INSET = -80;
+
+ protected final IWindowManager mWmService;
+ protected final Handler mHandler;
+ private final TransactionPool mTransactionPool;
+ private final DisplayController mDisplayController;
+ private final SparseArray<PerDisplay> mImePerDisplay = new SparseArray<>();
+ private final ArrayList<ImePositionProcessor> mPositionProcessors = new ArrayList<>();
+
+ public DisplayImeController(IWindowManager wmService, DisplayController displayController,
+ Handler mainHandler, TransactionPool transactionPool) {
+ mHandler = mainHandler;
+ mWmService = wmService;
+ mTransactionPool = transactionPool;
+ mDisplayController = displayController;
+ }
+
+ /** Starts monitor displays changes and set insets controller for each displays. */
+ public void startMonitorDisplays() {
+ mDisplayController.addDisplayWindowListener(this);
+ }
+
+ @Override
+ public void onDisplayAdded(int displayId) {
+ // Add's a system-ui window-manager specifically for ime. This type is special because
+ // WM will defer IME inset handling to it in multi-window scenarious.
+ PerDisplay pd = new PerDisplay(displayId,
+ mDisplayController.getDisplayLayout(displayId).rotation());
+ try {
+ mWmService.setDisplayWindowInsetsController(displayId, pd);
+ } catch (RemoteException e) {
+ Slog.w(TAG, "Unable to set insets controller on display " + displayId);
+ }
+ mImePerDisplay.put(displayId, pd);
+ }
+
+ @Override
+ public void onDisplayConfigurationChanged(int displayId, Configuration newConfig) {
+ PerDisplay pd = mImePerDisplay.get(displayId);
+ if (pd == null) {
+ return;
+ }
+ if (mDisplayController.getDisplayLayout(displayId).rotation()
+ != pd.mRotation && isImeShowing(displayId)) {
+ pd.startAnimation(true, false /* forceRestart */);
+ }
+ }
+
+ @Override
+ public void onDisplayRemoved(int displayId) {
+ try {
+ mWmService.setDisplayWindowInsetsController(displayId, null);
+ } catch (RemoteException e) {
+ Slog.w(TAG, "Unable to remove insets controller on display " + displayId);
+ }
+ mImePerDisplay.remove(displayId);
+ }
+
+ private boolean isImeShowing(int displayId) {
+ PerDisplay pd = mImePerDisplay.get(displayId);
+ if (pd == null) {
+ return false;
+ }
+ final InsetsSource imeSource = pd.mInsetsState.getSource(InsetsState.ITYPE_IME);
+ return imeSource != null && pd.mImeSourceControl != null && imeSource.isVisible();
+ }
+
+ private void dispatchPositionChanged(int displayId, int imeTop,
+ SurfaceControl.Transaction t) {
+ synchronized (mPositionProcessors) {
+ for (ImePositionProcessor pp : mPositionProcessors) {
+ pp.onImePositionChanged(displayId, imeTop, t);
+ }
+ }
+ }
+
+ @ImePositionProcessor.ImeAnimationFlags
+ private int dispatchStartPositioning(int displayId, int hiddenTop, int shownTop,
+ boolean show, boolean isFloating, SurfaceControl.Transaction t) {
+ synchronized (mPositionProcessors) {
+ int flags = 0;
+ for (ImePositionProcessor pp : mPositionProcessors) {
+ flags |= pp.onImeStartPositioning(
+ displayId, hiddenTop, shownTop, show, isFloating, t);
+ }
+ return flags;
+ }
+ }
+
+ private void dispatchEndPositioning(int displayId, boolean cancel,
+ SurfaceControl.Transaction t) {
+ synchronized (mPositionProcessors) {
+ for (ImePositionProcessor pp : mPositionProcessors) {
+ pp.onImeEndPositioning(displayId, cancel, t);
+ }
+ }
+ }
+
+ /**
+ * Adds an {@link ImePositionProcessor} to be called during ime position updates.
+ */
+ public void addPositionProcessor(ImePositionProcessor processor) {
+ synchronized (mPositionProcessors) {
+ if (mPositionProcessors.contains(processor)) {
+ return;
+ }
+ mPositionProcessors.add(processor);
+ }
+ }
+
+ /**
+ * Removes an {@link ImePositionProcessor} to be called during ime position updates.
+ */
+ public void removePositionProcessor(ImePositionProcessor processor) {
+ synchronized (mPositionProcessors) {
+ mPositionProcessors.remove(processor);
+ }
+ }
+
+ class PerDisplay extends IDisplayWindowInsetsController.Stub {
+ final int mDisplayId;
+ final InsetsState mInsetsState = new InsetsState();
+ InsetsSourceControl mImeSourceControl = null;
+ int mAnimationDirection = DIRECTION_NONE;
+ ValueAnimator mAnimation = null;
+ int mRotation = Surface.ROTATION_0;
+ boolean mImeShowing = false;
+ final Rect mImeFrame = new Rect();
+ boolean mAnimateAlpha = true;
+
+ PerDisplay(int displayId, int initialRotation) {
+ mDisplayId = displayId;
+ mRotation = initialRotation;
+ }
+
+ @Override
+ public void insetsChanged(InsetsState insetsState) {
+ mHandler.post(() -> {
+ if (mInsetsState.equals(insetsState)) {
+ return;
+ }
+
+ final InsetsSource newSource = insetsState.getSource(InsetsState.ITYPE_IME);
+ final Rect newFrame = newSource.getFrame();
+ final Rect oldFrame = mInsetsState.getSource(InsetsState.ITYPE_IME).getFrame();
+
+ mInsetsState.set(insetsState, true /* copySources */);
+ if (mImeShowing && !newFrame.equals(oldFrame) && newSource.isVisible()) {
+ if (DEBUG) Slog.d(TAG, "insetsChanged when IME showing, restart animation");
+ startAnimation(mImeShowing, true /* forceRestart */);
+ }
+ });
+ }
+
+ @Override
+ public void insetsControlChanged(InsetsState insetsState,
+ InsetsSourceControl[] activeControls) {
+ insetsChanged(insetsState);
+ if (activeControls != null) {
+ for (InsetsSourceControl activeControl : activeControls) {
+ if (activeControl == null) {
+ continue;
+ }
+ if (activeControl.getType() == InsetsState.ITYPE_IME) {
+ mHandler.post(() -> {
+ final Point lastSurfacePosition = mImeSourceControl != null
+ ? mImeSourceControl.getSurfacePosition() : null;
+ mImeSourceControl = activeControl;
+ if (!activeControl.getSurfacePosition().equals(lastSurfacePosition)
+ && mAnimation != null) {
+ startAnimation(mImeShowing, true /* forceRestart */);
+ } else if (!mImeShowing) {
+ removeImeSurface();
+ }
+ });
+ }
+ }
+ }
+ }
+
+ @Override
+ public void showInsets(int types, boolean fromIme) {
+ if ((types & WindowInsets.Type.ime()) == 0) {
+ return;
+ }
+ if (DEBUG) Slog.d(TAG, "Got showInsets for ime");
+ mHandler.post(() -> startAnimation(true /* show */, false /* forceRestart */));
+ }
+
+ @Override
+ public void hideInsets(int types, boolean fromIme) {
+ if ((types & WindowInsets.Type.ime()) == 0) {
+ return;
+ }
+ if (DEBUG) Slog.d(TAG, "Got hideInsets for ime");
+ mHandler.post(() -> startAnimation(false /* show */, false /* forceRestart */));
+ }
+
+ @Override
+ public void topFocusedWindowChanged(String packageName) {
+ // no-op
+ }
+
+ /**
+ * Sends the local visibility state back to window manager. Needed for legacy adjustForIme.
+ */
+ private void setVisibleDirectly(boolean visible) {
+ mInsetsState.getSource(InsetsState.ITYPE_IME).setVisible(visible);
+ try {
+ mWmService.modifyDisplayWindowInsets(mDisplayId, mInsetsState);
+ } catch (RemoteException e) {
+ }
+ }
+
+ private int imeTop(float surfaceOffset) {
+ return mImeFrame.top + (int) surfaceOffset;
+ }
+
+ private boolean calcIsFloating(InsetsSource imeSource) {
+ final Rect frame = imeSource.getFrame();
+ if (frame.height() == 0) {
+ return true;
+ }
+ // Some Floating Input Methods will still report a frame, but the frame is actually
+ // a nav-bar inset created by WM and not part of the IME (despite being reported as
+ // an IME inset). For now, we assume that no non-floating IME will be <= this nav bar
+ // frame height so any reported frame that is <= nav-bar frame height is assumed to
+ // be floating.
+ return frame.height() <= mDisplayController.getDisplayLayout(mDisplayId)
+ .navBarFrameHeight();
+ }
+
+ private void startAnimation(final boolean show, final boolean forceRestart) {
+ final InsetsSource imeSource = mInsetsState.getSource(InsetsState.ITYPE_IME);
+ if (imeSource == null || mImeSourceControl == null) {
+ return;
+ }
+ final Rect newFrame = imeSource.getFrame();
+ final boolean isFloating = calcIsFloating(imeSource) && show;
+ if (isFloating) {
+ // This is a "floating" or "expanded" IME, so to get animations, just
+ // pretend the ime has some size just below the screen.
+ mImeFrame.set(newFrame);
+ final int floatingInset = (int) (mDisplayController.getDisplayLayout(mDisplayId)
+ .density() * FLOATING_IME_BOTTOM_INSET);
+ mImeFrame.bottom -= floatingInset;
+ } else if (newFrame.height() != 0) {
+ // Don't set a new frame if it's empty and hiding -- this maintains continuity
+ mImeFrame.set(newFrame);
+ }
+ if (DEBUG) {
+ Slog.d(TAG, "Run startAnim show:" + show + " was:"
+ + (mAnimationDirection == DIRECTION_SHOW ? "SHOW"
+ : (mAnimationDirection == DIRECTION_HIDE ? "HIDE" : "NONE")));
+ }
+ if (!forceRestart && (mAnimationDirection == DIRECTION_SHOW && show)
+ || (mAnimationDirection == DIRECTION_HIDE && !show)) {
+ return;
+ }
+ boolean seek = false;
+ float seekValue = 0;
+ if (mAnimation != null) {
+ if (mAnimation.isRunning()) {
+ seekValue = (float) mAnimation.getAnimatedValue();
+ seek = true;
+ }
+ mAnimation.cancel();
+ }
+ final float defaultY = mImeSourceControl.getSurfacePosition().y;
+ final float x = mImeSourceControl.getSurfacePosition().x;
+ final float hiddenY = defaultY + mImeFrame.height();
+ final float shownY = defaultY;
+ final float startY = show ? hiddenY : shownY;
+ final float endY = show ? shownY : hiddenY;
+ if (mAnimationDirection == DIRECTION_NONE && mImeShowing && show) {
+ // IME is already showing, so set seek to end
+ seekValue = shownY;
+ seek = true;
+ }
+ mAnimationDirection = show ? DIRECTION_SHOW : DIRECTION_HIDE;
+ mImeShowing = show;
+ mAnimation = ValueAnimator.ofFloat(startY, endY);
+ mAnimation.setDuration(
+ show ? ANIMATION_DURATION_SHOW_MS : ANIMATION_DURATION_HIDE_MS);
+ if (seek) {
+ mAnimation.setCurrentFraction((seekValue - startY) / (endY - startY));
+ }
+
+ mAnimation.addUpdateListener(animation -> {
+ SurfaceControl.Transaction t = mTransactionPool.acquire();
+ float value = (float) animation.getAnimatedValue();
+ t.setPosition(mImeSourceControl.getLeash(), x, value);
+ final float alpha = (mAnimateAlpha || isFloating)
+ ? (value - hiddenY) / (shownY - hiddenY) : 1.f;
+ t.setAlpha(mImeSourceControl.getLeash(), alpha);
+ dispatchPositionChanged(mDisplayId, imeTop(value), t);
+ t.apply();
+ mTransactionPool.release(t);
+ });
+ mAnimation.setInterpolator(INTERPOLATOR);
+ mAnimation.addListener(new AnimatorListenerAdapter() {
+ private boolean mCancelled = false;
+
+ @Override
+ public void onAnimationStart(Animator animation) {
+ SurfaceControl.Transaction t = mTransactionPool.acquire();
+ t.setPosition(mImeSourceControl.getLeash(), x, startY);
+ if (DEBUG) {
+ Slog.d(TAG, "onAnimationStart d:" + mDisplayId + " top:"
+ + imeTop(hiddenY) + "->" + imeTop(shownY)
+ + " showing:" + (mAnimationDirection == DIRECTION_SHOW));
+ }
+ int flags = dispatchStartPositioning(mDisplayId, imeTop(hiddenY),
+ imeTop(shownY), mAnimationDirection == DIRECTION_SHOW, isFloating, t);
+ mAnimateAlpha = (flags & ImePositionProcessor.IME_ANIMATION_NO_ALPHA) == 0;
+ final float alpha = (mAnimateAlpha || isFloating)
+ ? (startY - hiddenY) / (shownY - hiddenY)
+ : 1.f;
+ t.setAlpha(mImeSourceControl.getLeash(), alpha);
+ if (mAnimationDirection == DIRECTION_SHOW) {
+ t.show(mImeSourceControl.getLeash());
+ }
+ t.apply();
+ mTransactionPool.release(t);
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ mCancelled = true;
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ if (DEBUG) Slog.d(TAG, "onAnimationEnd " + mCancelled);
+ SurfaceControl.Transaction t = mTransactionPool.acquire();
+ if (!mCancelled) {
+ t.setPosition(mImeSourceControl.getLeash(), x, endY);
+ t.setAlpha(mImeSourceControl.getLeash(), 1.f);
+ }
+ dispatchEndPositioning(mDisplayId, mCancelled, t);
+ if (mAnimationDirection == DIRECTION_HIDE && !mCancelled) {
+ t.hide(mImeSourceControl.getLeash());
+ removeImeSurface();
+ }
+ t.apply();
+ mTransactionPool.release(t);
+
+ mAnimationDirection = DIRECTION_NONE;
+ mAnimation = null;
+ }
+ });
+ if (!show) {
+ // When going away, queue up insets change first, otherwise any bounds changes
+ // can have a "flicker" of ime-provided insets.
+ setVisibleDirectly(false /* visible */);
+ }
+ mAnimation.start();
+ if (show) {
+ // When showing away, queue up insets change last, otherwise any bounds changes
+ // can have a "flicker" of ime-provided insets.
+ setVisibleDirectly(true /* visible */);
+ }
+ }
+ }
+
+ void removeImeSurface() {
+ final IInputMethodManager imms = getImms();
+ if (imms != null) {
+ try {
+ // Remove the IME surface to make the insets invisible for
+ // non-client controlled insets.
+ imms.removeImeSurface();
+ } catch (RemoteException e) {
+ Slog.e(TAG, "Failed to remove IME surface.", e);
+ }
+ }
+ }
+
+ /**
+ * Allows other things to synchronize with the ime position
+ */
+ public interface ImePositionProcessor {
+ /**
+ * Indicates that ime shouldn't animate alpha. It will always be opaque. Used when stuff
+ * behind the IME shouldn't be visible (for example during split-screen adjustment where
+ * there is nothing behind the ime).
+ */
+ int IME_ANIMATION_NO_ALPHA = 1;
+
+ /** @hide */
+ @IntDef(prefix = {"IME_ANIMATION_"}, value = {
+ IME_ANIMATION_NO_ALPHA,
+ })
+ @interface ImeAnimationFlags {
+ }
+
+ /**
+ * Called when the IME position is starting to animate.
+ *
+ * @param hiddenTop The y position of the top of the IME surface when it is hidden.
+ * @param shownTop The y position of the top of the IME surface when it is shown.
+ * @param showing {@code true} when we are animating from hidden to shown, {@code false}
+ * when animating from shown to hidden.
+ * @param isFloating {@code true} when the ime is a floating ime (doesn't inset).
+ * @return flags that may alter how ime itself is animated (eg. no-alpha).
+ */
+ @ImeAnimationFlags
+ default int onImeStartPositioning(int displayId, int hiddenTop, int shownTop,
+ boolean showing, boolean isFloating, SurfaceControl.Transaction t) {
+ return 0;
+ }
+
+ /**
+ * Called when the ime position changed. This is expected to be a synchronous call on the
+ * animation thread. Operations can be added to the transaction to be applied in sync.
+ *
+ * @param imeTop The current y position of the top of the IME surface.
+ */
+ default void onImePositionChanged(int displayId, int imeTop, SurfaceControl.Transaction t) {
+ }
+
+ /**
+ * Called when the IME position is done animating.
+ *
+ * @param cancel {@code true} if this was cancelled. This implies another start is coming.
+ */
+ default void onImeEndPositioning(int displayId, boolean cancel,
+ SurfaceControl.Transaction t) {
+ }
+ }
+
+ public IInputMethodManager getImms() {
+ return IInputMethodManager.Stub.asInterface(
+ ServiceManager.getService(Context.INPUT_METHOD_SERVICE));
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java
new file mode 100644
index 000000000000..3181dbf74ace
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java
@@ -0,0 +1,511 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.common;
+
+import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
+import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
+import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
+import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
+import static android.os.Process.SYSTEM_UID;
+import static android.provider.Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS;
+import static android.view.Display.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS;
+import static android.view.Surface.ROTATION_0;
+import static android.view.Surface.ROTATION_270;
+import static android.view.Surface.ROTATION_90;
+
+import android.annotation.IntDef;
+import android.annotation.NonNull;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Insets;
+import android.graphics.Rect;
+import android.os.SystemProperties;
+import android.provider.Settings;
+import android.util.DisplayMetrics;
+import android.util.RotationUtils;
+import android.util.Size;
+import android.view.Display;
+import android.view.DisplayCutout;
+import android.view.DisplayInfo;
+import android.view.Gravity;
+import android.view.Surface;
+
+import com.android.internal.R;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Contains information about the layout-properties of a display. This refers to internal layout
+ * like insets/cutout/rotation. In general, this can be thought of as the shell analog to
+ * DisplayPolicy.
+ */
+public class DisplayLayout {
+ @IntDef(prefix = { "NAV_BAR_" }, value = {
+ NAV_BAR_LEFT,
+ NAV_BAR_RIGHT,
+ NAV_BAR_BOTTOM,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface NavBarPosition {}
+
+ // Navigation bar position values
+ public static final int NAV_BAR_LEFT = 1 << 0;
+ public static final int NAV_BAR_RIGHT = 1 << 1;
+ public static final int NAV_BAR_BOTTOM = 1 << 2;
+
+ private int mUiMode;
+ private int mWidth;
+ private int mHeight;
+ private DisplayCutout mCutout;
+ private int mRotation;
+ private int mDensityDpi;
+ private final Rect mNonDecorInsets = new Rect();
+ private final Rect mStableInsets = new Rect();
+ private boolean mHasNavigationBar = false;
+ private boolean mHasStatusBar = false;
+ private int mNavBarFrameHeight = 0;
+
+ /**
+ * Create empty layout.
+ */
+ public DisplayLayout() {
+ }
+
+ /**
+ * Construct a custom display layout using a DisplayInfo.
+ * @param info
+ * @param res
+ */
+ public DisplayLayout(DisplayInfo info, Resources res, boolean hasNavigationBar,
+ boolean hasStatusBar) {
+ init(info, res, hasNavigationBar, hasStatusBar);
+ }
+
+ /**
+ * Construct a display layout based on a live display.
+ * @param context Used for resources.
+ */
+ public DisplayLayout(@NonNull Context context, @NonNull Display rawDisplay) {
+ final int displayId = rawDisplay.getDisplayId();
+ DisplayInfo info = new DisplayInfo();
+ rawDisplay.getDisplayInfo(info);
+ init(info, context.getResources(), hasNavigationBar(info, context, displayId),
+ hasStatusBar(displayId));
+ }
+
+ public DisplayLayout(DisplayLayout dl) {
+ set(dl);
+ }
+
+ /** sets this DisplayLayout to a copy of another on. */
+ public void set(DisplayLayout dl) {
+ mUiMode = dl.mUiMode;
+ mWidth = dl.mWidth;
+ mHeight = dl.mHeight;
+ mCutout = dl.mCutout;
+ mRotation = dl.mRotation;
+ mDensityDpi = dl.mDensityDpi;
+ mHasNavigationBar = dl.mHasNavigationBar;
+ mHasStatusBar = dl.mHasStatusBar;
+ mNonDecorInsets.set(dl.mNonDecorInsets);
+ mStableInsets.set(dl.mStableInsets);
+ }
+
+ private void init(DisplayInfo info, Resources res, boolean hasNavigationBar,
+ boolean hasStatusBar) {
+ mUiMode = res.getConfiguration().uiMode;
+ mWidth = info.logicalWidth;
+ mHeight = info.logicalHeight;
+ mRotation = info.rotation;
+ mCutout = info.displayCutout;
+ mDensityDpi = info.logicalDensityDpi;
+ mHasNavigationBar = hasNavigationBar;
+ mHasStatusBar = hasStatusBar;
+ recalcInsets(res);
+ }
+
+ private void recalcInsets(Resources res) {
+ computeNonDecorInsets(res, mRotation, mWidth, mHeight, mCutout, mUiMode, mNonDecorInsets,
+ mHasNavigationBar);
+ mStableInsets.set(mNonDecorInsets);
+ if (mHasStatusBar) {
+ convertNonDecorInsetsToStableInsets(res, mStableInsets, mWidth, mHeight, mHasStatusBar);
+ }
+ mNavBarFrameHeight = getNavigationBarFrameHeight(res, mWidth > mHeight);
+ }
+
+ /**
+ * Apply a rotation to this layout and its parameters.
+ * @param res
+ * @param targetRotation
+ */
+ public void rotateTo(Resources res, @Surface.Rotation int targetRotation) {
+ final int rotationDelta = (targetRotation - mRotation + 4) % 4;
+ final boolean changeOrient = (rotationDelta % 2) != 0;
+
+ final int origWidth = mWidth;
+ final int origHeight = mHeight;
+
+ mRotation = targetRotation;
+ if (changeOrient) {
+ mWidth = origHeight;
+ mHeight = origWidth;
+ }
+
+ if (mCutout != null && !mCutout.isEmpty()) {
+ mCutout = calculateDisplayCutoutForRotation(mCutout, rotationDelta, origWidth,
+ origHeight);
+ }
+
+ recalcInsets(res);
+ }
+
+ /** Get this layout's non-decor insets. */
+ public Rect nonDecorInsets() {
+ return mNonDecorInsets;
+ }
+
+ /** Get this layout's stable insets. */
+ public Rect stableInsets() {
+ return mStableInsets;
+ }
+
+ /** Get this layout's width. */
+ public int width() {
+ return mWidth;
+ }
+
+ /** Get this layout's height. */
+ public int height() {
+ return mHeight;
+ }
+
+ /** Get this layout's display rotation. */
+ public int rotation() {
+ return mRotation;
+ }
+
+ /** Get this layout's display density. */
+ public int densityDpi() {
+ return mDensityDpi;
+ }
+
+ /** Get the density scale for the display. */
+ public float density() {
+ return mDensityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
+ }
+
+ /** Get whether this layout is landscape. */
+ public boolean isLandscape() {
+ return mWidth > mHeight;
+ }
+
+ /** Get the navbar frame height (used by ime). */
+ public int navBarFrameHeight() {
+ return mNavBarFrameHeight;
+ }
+
+ /** Gets the orientation of this layout */
+ public int getOrientation() {
+ return (mWidth > mHeight) ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT;
+ }
+
+ /** Gets the calculated stable-bounds for this layout */
+ public void getStableBounds(Rect outBounds) {
+ outBounds.set(0, 0, mWidth, mHeight);
+ outBounds.inset(mStableInsets);
+ }
+
+ /**
+ * Gets navigation bar position for this layout
+ * @return Navigation bar position for this layout.
+ */
+ public @NavBarPosition int getNavigationBarPosition(Resources res) {
+ return navigationBarPosition(res, mWidth, mHeight, mRotation);
+ }
+
+ /**
+ * Rotates bounds as if parentBounds and bounds are a group. The group is rotated by `delta`
+ * 90-degree counter-clockwise increments. This assumes that parentBounds is at 0,0 and
+ * remains at 0,0 after rotation.
+ *
+ * Only 'bounds' is mutated.
+ */
+ public static void rotateBounds(Rect inOutBounds, Rect parentBounds, int delta) {
+ int rdelta = ((delta % 4) + 4) % 4;
+ int origLeft = inOutBounds.left;
+ switch (rdelta) {
+ case 0:
+ return;
+ case 1:
+ inOutBounds.left = inOutBounds.top;
+ inOutBounds.top = parentBounds.right - inOutBounds.right;
+ inOutBounds.right = inOutBounds.bottom;
+ inOutBounds.bottom = parentBounds.right - origLeft;
+ return;
+ case 2:
+ inOutBounds.left = parentBounds.right - inOutBounds.right;
+ inOutBounds.right = parentBounds.right - origLeft;
+ return;
+ case 3:
+ inOutBounds.left = parentBounds.bottom - inOutBounds.bottom;
+ inOutBounds.bottom = inOutBounds.right;
+ inOutBounds.right = parentBounds.bottom - inOutBounds.top;
+ inOutBounds.top = origLeft;
+ return;
+ }
+ }
+
+ /**
+ * Calculates the stable insets if we already have the non-decor insets.
+ */
+ private static void convertNonDecorInsetsToStableInsets(Resources res, Rect inOutInsets,
+ int displayWidth, int displayHeight, boolean hasStatusBar) {
+ if (!hasStatusBar) {
+ return;
+ }
+ int statusBarHeight = getStatusBarHeight(displayWidth > displayHeight, res);
+ inOutInsets.top = Math.max(inOutInsets.top, statusBarHeight);
+ }
+
+ /**
+ * Calculates the insets for the areas that could never be removed in Honeycomb, i.e. system
+ * bar or button bar.
+ *
+ * @param displayRotation the current display rotation
+ * @param displayWidth the current display width
+ * @param displayHeight the current display height
+ * @param displayCutout the current display cutout
+ * @param outInsets the insets to return
+ */
+ static void computeNonDecorInsets(Resources res, int displayRotation, int displayWidth,
+ int displayHeight, DisplayCutout displayCutout, int uiMode, Rect outInsets,
+ boolean hasNavigationBar) {
+ outInsets.setEmpty();
+
+ // Only navigation bar
+ if (hasNavigationBar) {
+ int position = navigationBarPosition(res, displayWidth, displayHeight, displayRotation);
+ int navBarSize =
+ getNavigationBarSize(res, position, displayWidth > displayHeight, uiMode);
+ if (position == NAV_BAR_BOTTOM) {
+ outInsets.bottom = navBarSize;
+ } else if (position == NAV_BAR_RIGHT) {
+ outInsets.right = navBarSize;
+ } else if (position == NAV_BAR_LEFT) {
+ outInsets.left = navBarSize;
+ }
+ }
+
+ if (displayCutout != null) {
+ outInsets.left += displayCutout.getSafeInsetLeft();
+ outInsets.top += displayCutout.getSafeInsetTop();
+ outInsets.right += displayCutout.getSafeInsetRight();
+ outInsets.bottom += displayCutout.getSafeInsetBottom();
+ }
+ }
+
+ /**
+ * Calculates the stable insets without running a layout.
+ *
+ * @param displayRotation the current display rotation
+ * @param displayWidth the current display width
+ * @param displayHeight the current display height
+ * @param displayCutout the current display cutout
+ * @param outInsets the insets to return
+ */
+ static void computeStableInsets(Resources res, int displayRotation, int displayWidth,
+ int displayHeight, DisplayCutout displayCutout, int uiMode, Rect outInsets,
+ boolean hasNavigationBar, boolean hasStatusBar) {
+ outInsets.setEmpty();
+
+ // Navigation bar and status bar.
+ computeNonDecorInsets(res, displayRotation, displayWidth, displayHeight, displayCutout,
+ uiMode, outInsets, hasNavigationBar);
+ convertNonDecorInsetsToStableInsets(res, outInsets, displayWidth, displayHeight,
+ hasStatusBar);
+ }
+
+ /** Retrieve the statusbar height from resources. */
+ static int getStatusBarHeight(boolean landscape, Resources res) {
+ return landscape ? res.getDimensionPixelSize(
+ com.android.internal.R.dimen.status_bar_height_landscape)
+ : res.getDimensionPixelSize(
+ com.android.internal.R.dimen.status_bar_height_portrait);
+ }
+
+ /** Calculate the DisplayCutout for a particular display size/rotation. */
+ public static DisplayCutout calculateDisplayCutoutForRotation(
+ DisplayCutout cutout, int rotation, int displayWidth, int displayHeight) {
+ if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
+ return null;
+ }
+ final Insets waterfallInsets =
+ RotationUtils.rotateInsets(cutout.getWaterfallInsets(), rotation);
+ if (rotation == ROTATION_0) {
+ return computeSafeInsets(cutout, displayWidth, displayHeight);
+ }
+ final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
+ Rect[] cutoutRects = cutout.getBoundingRectsAll();
+ final Rect[] newBounds = new Rect[cutoutRects.length];
+ final Rect displayBounds = new Rect(0, 0, displayWidth, displayHeight);
+ for (int i = 0; i < cutoutRects.length; ++i) {
+ final Rect rect = new Rect(cutoutRects[i]);
+ if (!rect.isEmpty()) {
+ rotateBounds(rect, displayBounds, rotation);
+ }
+ newBounds[getBoundIndexFromRotation(i, rotation)] = rect;
+ }
+ return computeSafeInsets(
+ DisplayCutout.fromBoundsAndWaterfall(newBounds, waterfallInsets),
+ rotated ? displayHeight : displayWidth,
+ rotated ? displayWidth : displayHeight);
+ }
+
+ private static int getBoundIndexFromRotation(int index, int rotation) {
+ return (index - rotation) < 0
+ ? index - rotation + DisplayCutout.BOUNDS_POSITION_LENGTH
+ : index - rotation;
+ }
+
+ /** Calculate safe insets. */
+ public static DisplayCutout computeSafeInsets(DisplayCutout inner,
+ int displayWidth, int displayHeight) {
+ if (inner == DisplayCutout.NO_CUTOUT) {
+ return null;
+ }
+
+ final Size displaySize = new Size(displayWidth, displayHeight);
+ final Rect safeInsets = computeSafeInsets(displaySize, inner);
+ return inner.replaceSafeInsets(safeInsets);
+ }
+
+ private static Rect computeSafeInsets(
+ Size displaySize, DisplayCutout cutout) {
+ if (displaySize.getWidth() == displaySize.getHeight()) {
+ throw new UnsupportedOperationException("not implemented: display=" + displaySize
+ + " cutout=" + cutout);
+ }
+
+ int leftInset = Math.max(cutout.getWaterfallInsets().left,
+ findCutoutInsetForSide(displaySize, cutout.getBoundingRectLeft(), Gravity.LEFT));
+ int topInset = Math.max(cutout.getWaterfallInsets().top,
+ findCutoutInsetForSide(displaySize, cutout.getBoundingRectTop(), Gravity.TOP));
+ int rightInset = Math.max(cutout.getWaterfallInsets().right,
+ findCutoutInsetForSide(displaySize, cutout.getBoundingRectRight(), Gravity.RIGHT));
+ int bottomInset = Math.max(cutout.getWaterfallInsets().bottom,
+ findCutoutInsetForSide(displaySize, cutout.getBoundingRectBottom(),
+ Gravity.BOTTOM));
+
+ return new Rect(leftInset, topInset, rightInset, bottomInset);
+ }
+
+ private static int findCutoutInsetForSide(Size display, Rect boundingRect, int gravity) {
+ if (boundingRect.isEmpty()) {
+ return 0;
+ }
+
+ int inset = 0;
+ switch (gravity) {
+ case Gravity.TOP:
+ return Math.max(inset, boundingRect.bottom);
+ case Gravity.BOTTOM:
+ return Math.max(inset, display.getHeight() - boundingRect.top);
+ case Gravity.LEFT:
+ return Math.max(inset, boundingRect.right);
+ case Gravity.RIGHT:
+ return Math.max(inset, display.getWidth() - boundingRect.left);
+ default:
+ throw new IllegalArgumentException("unknown gravity: " + gravity);
+ }
+ }
+
+ static boolean hasNavigationBar(DisplayInfo info, Context context, int displayId) {
+ if (displayId == Display.DEFAULT_DISPLAY) {
+ // Allow a system property to override this. Used by the emulator.
+ final String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
+ if ("1".equals(navBarOverride)) {
+ return false;
+ } else if ("0".equals(navBarOverride)) {
+ return true;
+ }
+ return context.getResources().getBoolean(R.bool.config_showNavigationBar);
+ } else {
+ boolean isUntrustedVirtualDisplay = info.type == Display.TYPE_VIRTUAL
+ && info.ownerUid != SYSTEM_UID;
+ final ContentResolver resolver = context.getContentResolver();
+ boolean forceDesktopOnExternal = Settings.Global.getInt(resolver,
+ DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, 0) != 0;
+
+ return ((info.flags & FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0
+ || (forceDesktopOnExternal && !isUntrustedVirtualDisplay));
+ // TODO(b/142569966): make sure VR2D and DisplayWindowSettings are moved here somehow.
+ }
+ }
+
+ static boolean hasStatusBar(int displayId) {
+ return displayId == Display.DEFAULT_DISPLAY;
+ }
+
+ /** Retrieve navigation bar position from resources based on rotation and size. */
+ public static @NavBarPosition int navigationBarPosition(Resources res, int displayWidth,
+ int displayHeight, int rotation) {
+ boolean navBarCanMove = displayWidth != displayHeight && res.getBoolean(
+ com.android.internal.R.bool.config_navBarCanMove);
+ if (navBarCanMove && displayWidth > displayHeight) {
+ if (rotation == Surface.ROTATION_90) {
+ return NAV_BAR_RIGHT;
+ } else {
+ return NAV_BAR_LEFT;
+ }
+ }
+ return NAV_BAR_BOTTOM;
+ }
+
+ /** Retrieve navigation bar size from resources based on side/orientation/ui-mode */
+ public static int getNavigationBarSize(Resources res, int navBarSide, boolean landscape,
+ int uiMode) {
+ final boolean carMode = (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR;
+ if (carMode) {
+ if (navBarSide == NAV_BAR_BOTTOM) {
+ return res.getDimensionPixelSize(landscape
+ ? R.dimen.navigation_bar_height_landscape_car_mode
+ : R.dimen.navigation_bar_height_car_mode);
+ } else {
+ return res.getDimensionPixelSize(R.dimen.navigation_bar_width_car_mode);
+ }
+
+ } else {
+ if (navBarSide == NAV_BAR_BOTTOM) {
+ return res.getDimensionPixelSize(landscape
+ ? R.dimen.navigation_bar_height_landscape
+ : R.dimen.navigation_bar_height);
+ } else {
+ return res.getDimensionPixelSize(R.dimen.navigation_bar_width);
+ }
+ }
+ }
+
+ /** @see com.android.server.wm.DisplayPolicy#getNavigationBarFrameHeight */
+ public static int getNavigationBarFrameHeight(Resources res, boolean landscape) {
+ return res.getDimensionPixelSize(landscape
+ ? R.dimen.navigation_bar_frame_height_landscape
+ : R.dimen.navigation_bar_frame_height);
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SyncTransactionQueue.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SyncTransactionQueue.java
new file mode 100644
index 000000000000..9cb125087cd9
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SyncTransactionQueue.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.common;
+
+import android.annotation.NonNull;
+import android.os.Handler;
+import android.util.Slog;
+import android.view.SurfaceControl;
+import android.window.WindowContainerTransaction;
+import android.window.WindowContainerTransactionCallback;
+import android.window.WindowOrganizer;
+
+import java.util.ArrayList;
+
+/**
+ * Helper for serializing sync-transactions and corresponding callbacks.
+ */
+public final class SyncTransactionQueue {
+ private static final boolean DEBUG = false;
+ private static final String TAG = "SyncTransactionQueue";
+
+ // Just a little longer than the sync-engine timeout of 5s
+ private static final int REPLY_TIMEOUT = 5300;
+
+ private final TransactionPool mTransactionPool;
+ private final Handler mHandler;
+
+ // Sync Transactions currently don't support nesting or interleaving properly, so
+ // queue up transactions to run them serially.
+ private final ArrayList<SyncCallback> mQueue = new ArrayList<>();
+
+ private SyncCallback mInFlight = null;
+ private final ArrayList<TransactionRunnable> mRunnables = new ArrayList<>();
+
+ private final Runnable mOnReplyTimeout = () -> {
+ synchronized (mQueue) {
+ if (mInFlight != null && mQueue.contains(mInFlight)) {
+ Slog.w(TAG, "Sync Transaction timed-out: " + mInFlight.mWCT);
+ mInFlight.onTransactionReady(mInFlight.mId, new SurfaceControl.Transaction());
+ }
+ }
+ };
+
+ public SyncTransactionQueue(TransactionPool pool, Handler handler) {
+ mTransactionPool = pool;
+ mHandler = handler;
+ }
+
+ /**
+ * Queues a sync transaction to be sent serially to WM.
+ */
+ public void queue(WindowContainerTransaction wct) {
+ SyncCallback cb = new SyncCallback(wct);
+ synchronized (mQueue) {
+ if (DEBUG) Slog.d(TAG, "Queueing up " + wct);
+ mQueue.add(cb);
+ if (mQueue.size() == 1) {
+ cb.send();
+ }
+ }
+ }
+
+ /**
+ * Queues a sync transaction only if there are already sync transaction(s) queued or in flight.
+ * Otherwise just returns without queueing.
+ * @return {@code true} if queued, {@code false} if not.
+ */
+ public boolean queueIfWaiting(WindowContainerTransaction wct) {
+ synchronized (mQueue) {
+ if (mQueue.isEmpty()) {
+ if (DEBUG) Slog.d(TAG, "Nothing in queue, so skip queueing up " + wct);
+ return false;
+ }
+ if (DEBUG) Slog.d(TAG, "Queue is non-empty, so queueing up " + wct);
+ SyncCallback cb = new SyncCallback(wct);
+ mQueue.add(cb);
+ if (mQueue.size() == 1) {
+ cb.send();
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Runs a runnable in sync with sync transactions (ie. when the current in-flight transaction
+ * returns. If there are no transactions in-flight, runnable executes immediately.
+ */
+ public void runInSync(TransactionRunnable runnable) {
+ synchronized (mQueue) {
+ if (DEBUG) Slog.d(TAG, "Run in sync. mInFlight=" + mInFlight);
+ if (mInFlight != null) {
+ mRunnables.add(runnable);
+ return;
+ }
+ }
+ SurfaceControl.Transaction t = mTransactionPool.acquire();
+ runnable.runWithTransaction(t);
+ t.apply();
+ mTransactionPool.release(t);
+ }
+
+ // Synchronized on mQueue
+ private void onTransactionReceived(@NonNull SurfaceControl.Transaction t) {
+ if (DEBUG) Slog.d(TAG, " Running " + mRunnables.size() + " sync runnables");
+ for (int i = 0, n = mRunnables.size(); i < n; ++i) {
+ mRunnables.get(i).runWithTransaction(t);
+ }
+ mRunnables.clear();
+ t.apply();
+ t.close();
+ }
+
+ /** Task to run with transaction. */
+ public interface TransactionRunnable {
+ /** Runs with transaction. */
+ void runWithTransaction(SurfaceControl.Transaction t);
+ }
+
+ private class SyncCallback extends WindowContainerTransactionCallback {
+ int mId = -1;
+ final WindowContainerTransaction mWCT;
+
+ SyncCallback(WindowContainerTransaction wct) {
+ mWCT = wct;
+ }
+
+ // Must be sychronized on mQueue
+ void send() {
+ if (mInFlight != null) {
+ throw new IllegalStateException("Sync Transactions must be serialized. In Flight: "
+ + mInFlight.mId + " - " + mInFlight.mWCT);
+ }
+ mInFlight = this;
+ if (DEBUG) Slog.d(TAG, "Sending sync transaction: " + mWCT);
+ mId = new WindowOrganizer().applySyncTransaction(mWCT, this);
+ if (DEBUG) Slog.d(TAG, " Sent sync transaction. Got id=" + mId);
+ mHandler.postDelayed(mOnReplyTimeout, REPLY_TIMEOUT);
+ }
+
+ @Override
+ public void onTransactionReady(int id,
+ @NonNull SurfaceControl.Transaction t) {
+ mHandler.post(() -> {
+ synchronized (mQueue) {
+ if (mId != id) {
+ Slog.e(TAG, "Got an unexpected onTransactionReady. Expected "
+ + mId + " but got " + id);
+ return;
+ }
+ mInFlight = null;
+ mHandler.removeCallbacks(mOnReplyTimeout);
+ if (DEBUG) Slog.d(TAG, "onTransactionReady id=" + mId);
+ mQueue.remove(this);
+ onTransactionReceived(t);
+ if (!mQueue.isEmpty()) {
+ mQueue.get(0).send();
+ }
+ }
+ });
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java
new file mode 100644
index 000000000000..b4620e27e68c
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java
@@ -0,0 +1,389 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.common;
+
+import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
+
+import android.annotation.NonNull;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.graphics.Point;
+import android.graphics.Region;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.util.MergedConfiguration;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.view.Display;
+import android.view.DragEvent;
+import android.view.IScrollCaptureController;
+import android.view.IWindow;
+import android.view.IWindowManager;
+import android.view.IWindowSession;
+import android.view.IWindowSessionCallback;
+import android.view.InsetsSourceControl;
+import android.view.InsetsState;
+import android.view.SurfaceControl;
+import android.view.SurfaceControlViewHost;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.view.WindowlessWindowManager;
+import android.window.ClientWindowFrames;
+
+import com.android.internal.os.IResultReceiver;
+
+import java.util.HashMap;
+
+/**
+ * Represents the "windowing" layer of the WM Shell. This layer allows shell components to place and
+ * manipulate windows without talking to WindowManager.
+ */
+public class SystemWindows {
+ private static final String TAG = "SystemWindows";
+
+ private final SparseArray<PerDisplay> mPerDisplay = new SparseArray<>();
+ private final HashMap<View, SurfaceControlViewHost> mViewRoots = new HashMap<>();
+ private final DisplayController mDisplayController;
+ private final IWindowManager mWmService;
+ private IWindowSession mSession;
+
+ private final DisplayController.OnDisplaysChangedListener mDisplayListener =
+ new DisplayController.OnDisplaysChangedListener() {
+ @Override
+ public void onDisplayAdded(int displayId) { }
+
+ @Override
+ public void onDisplayConfigurationChanged(int displayId, Configuration newConfig) {
+ PerDisplay pd = mPerDisplay.get(displayId);
+ if (pd == null) {
+ return;
+ }
+ pd.updateConfiguration(newConfig);
+ }
+
+ @Override
+ public void onDisplayRemoved(int displayId) { }
+ };
+
+ public SystemWindows(DisplayController displayController, IWindowManager wmService) {
+ mWmService = wmService;
+ mDisplayController = displayController;
+ mDisplayController.addDisplayWindowListener(mDisplayListener);
+ try {
+ mSession = wmService.openSession(
+ new IWindowSessionCallback.Stub() {
+ @Override
+ public void onAnimatorScaleChanged(float scale) {}
+ });
+ } catch (RemoteException e) {
+ Slog.e(TAG, "Unable to create layer", e);
+ }
+ }
+
+ /**
+ * Adds a view to system-ui window management.
+ */
+ public void addView(View view, WindowManager.LayoutParams attrs, int displayId,
+ int windowType) {
+ PerDisplay pd = mPerDisplay.get(displayId);
+ if (pd == null) {
+ pd = new PerDisplay(displayId);
+ mPerDisplay.put(displayId, pd);
+ }
+ pd.addView(view, attrs, windowType);
+ }
+
+ /**
+ * Removes a view from system-ui window management.
+ * @param view
+ */
+ public void removeView(View view) {
+ SurfaceControlViewHost root = mViewRoots.remove(view);
+ root.release();
+ }
+
+ /**
+ * Updates the layout params of a view.
+ */
+ public void updateViewLayout(@NonNull View view, ViewGroup.LayoutParams params) {
+ SurfaceControlViewHost root = mViewRoots.get(view);
+ if (root == null || !(params instanceof WindowManager.LayoutParams)) {
+ return;
+ }
+ view.setLayoutParams(params);
+ root.relayout((WindowManager.LayoutParams) params);
+ }
+
+ /**
+ * Sets the touchable region of a view's window. This will be cropped to the window size.
+ * @param view
+ * @param region
+ */
+ public void setTouchableRegion(@NonNull View view, Region region) {
+ SurfaceControlViewHost root = mViewRoots.get(view);
+ if (root == null) {
+ return;
+ }
+ WindowlessWindowManager wwm = root.getWindowlessWM();
+ if (!(wwm instanceof SysUiWindowManager)) {
+ return;
+ }
+ ((SysUiWindowManager) wwm).setTouchableRegionForWindow(view, region);
+ }
+
+ /**
+ * Adds a root for system-ui window management with no views. Only useful for IME.
+ */
+ public void addRoot(int displayId, int windowType) {
+ PerDisplay pd = mPerDisplay.get(displayId);
+ if (pd == null) {
+ pd = new PerDisplay(displayId);
+ mPerDisplay.put(displayId, pd);
+ }
+ pd.addRoot(windowType);
+ }
+
+ /**
+ * Get the IWindow token for a specific root.
+ *
+ * @param windowType A window type from {@link WindowManager}.
+ */
+ IWindow getWindow(int displayId, int windowType) {
+ PerDisplay pd = mPerDisplay.get(displayId);
+ if (pd == null) {
+ return null;
+ }
+ return pd.getWindow(windowType);
+ }
+
+ /**
+ * Gets the SurfaceControl associated with a root view. This is the same surface that backs the
+ * ViewRootImpl.
+ */
+ public SurfaceControl getViewSurface(View rootView) {
+ for (int i = 0; i < mPerDisplay.size(); ++i) {
+ for (int iWm = 0; iWm < mPerDisplay.valueAt(i).mWwms.size(); ++iWm) {
+ SurfaceControl out = mPerDisplay.valueAt(i).mWwms.valueAt(iWm)
+ .getSurfaceControlForWindow(rootView);
+ if (out != null) {
+ return out;
+ }
+ }
+ }
+ return null;
+ }
+
+ private class PerDisplay {
+ final int mDisplayId;
+ private final SparseArray<SysUiWindowManager> mWwms = new SparseArray<>();
+
+ PerDisplay(int displayId) {
+ mDisplayId = displayId;
+ }
+
+ public void addView(View view, WindowManager.LayoutParams attrs, int windowType) {
+ SysUiWindowManager wwm = addRoot(windowType);
+ if (wwm == null) {
+ Slog.e(TAG, "Unable to create systemui root");
+ return;
+ }
+ final Display display = mDisplayController.getDisplay(mDisplayId);
+ SurfaceControlViewHost viewRoot =
+ new SurfaceControlViewHost(
+ view.getContext(), display, wwm, true /* useSfChoreographer */);
+ attrs.flags |= FLAG_HARDWARE_ACCELERATED;
+ viewRoot.setView(view, attrs);
+ mViewRoots.put(view, viewRoot);
+
+ try {
+ mWmService.setShellRootAccessibilityWindow(mDisplayId, windowType,
+ viewRoot.getWindowToken());
+ } catch (RemoteException e) {
+ Slog.e(TAG, "Error setting accessibility window for " + mDisplayId + ":"
+ + windowType, e);
+ }
+ }
+
+ SysUiWindowManager addRoot(int windowType) {
+ SysUiWindowManager wwm = mWwms.get(windowType);
+ if (wwm != null) {
+ return wwm;
+ }
+ SurfaceControl rootSurface = null;
+ ContainerWindow win = new ContainerWindow();
+ try {
+ rootSurface = mWmService.addShellRoot(mDisplayId, win, windowType);
+ } catch (RemoteException e) {
+ }
+ if (rootSurface == null) {
+ Slog.e(TAG, "Unable to get root surfacecontrol for systemui");
+ return null;
+ }
+ Context displayContext = mDisplayController.getDisplayContext(mDisplayId);
+ wwm = new SysUiWindowManager(mDisplayId, displayContext, rootSurface, win);
+ mWwms.put(windowType, wwm);
+ return wwm;
+ }
+
+ IWindow getWindow(int windowType) {
+ SysUiWindowManager wwm = mWwms.get(windowType);
+ if (wwm == null) {
+ return null;
+ }
+ return wwm.mContainerWindow;
+ }
+
+ void updateConfiguration(Configuration configuration) {
+ for (int i = 0; i < mWwms.size(); ++i) {
+ mWwms.valueAt(i).updateConfiguration(configuration);
+ }
+ }
+ }
+
+ /**
+ * A subclass of WindowlessWindowManager that provides insets to its viewroots.
+ */
+ public class SysUiWindowManager extends WindowlessWindowManager {
+ final int mDisplayId;
+ ContainerWindow mContainerWindow;
+ public SysUiWindowManager(int displayId, Context ctx, SurfaceControl rootSurface,
+ ContainerWindow container) {
+ super(ctx.getResources().getConfiguration(), rootSurface, null /* hostInputToken */);
+ mContainerWindow = container;
+ mDisplayId = displayId;
+ }
+
+ @Override
+ public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
+ int requestedWidth, int requestedHeight, int viewVisibility, int flags,
+ long frameNumber, ClientWindowFrames outFrames,
+ MergedConfiguration mergedConfiguration,
+ SurfaceControl outSurfaceControl, InsetsState outInsetsState,
+ InsetsSourceControl[] outActiveControls, Point outSurfaceSize,
+ SurfaceControl outBLASTSurfaceControl) {
+ int res = super.relayout(window, seq, attrs, requestedWidth, requestedHeight,
+ viewVisibility, flags, frameNumber, outFrames,
+ mergedConfiguration, outSurfaceControl, outInsetsState,
+ outActiveControls, outSurfaceSize, outBLASTSurfaceControl);
+ if (res != 0) {
+ return res;
+ }
+ DisplayLayout dl = mDisplayController.getDisplayLayout(mDisplayId);
+ outFrames.stableInsets.set(dl.stableInsets());
+ return 0;
+ }
+
+ void updateConfiguration(Configuration configuration) {
+ setConfiguration(configuration);
+ }
+
+ SurfaceControl getSurfaceControlForWindow(View rootView) {
+ return getSurfaceControl(rootView);
+ }
+
+ void setTouchableRegionForWindow(View rootView, Region region) {
+ IBinder token = rootView.getWindowToken();
+ if (token == null) {
+ return;
+ }
+ setTouchRegion(token, region);
+ }
+ }
+
+ static class ContainerWindow extends IWindow.Stub {
+ ContainerWindow() {}
+
+ @Override
+ public void resized(ClientWindowFrames frames, boolean reportDraw,
+ MergedConfiguration newMergedConfiguration, boolean forceLayout,
+ boolean alwaysConsumeSystemBars, int displayId) {}
+
+ @Override
+ public void locationInParentDisplayChanged(Point offset) {}
+
+ @Override
+ public void insetsChanged(InsetsState insetsState) {}
+
+ @Override
+ public void insetsControlChanged(InsetsState insetsState,
+ InsetsSourceControl[] activeControls) {}
+
+ @Override
+ public void showInsets(int types, boolean fromIme) {}
+
+ @Override
+ public void hideInsets(int types, boolean fromIme) {}
+
+ @Override
+ public void moved(int newX, int newY) {}
+
+ @Override
+ public void dispatchAppVisibility(boolean visible) {}
+
+ @Override
+ public void dispatchGetNewSurface() {}
+
+ @Override
+ public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) {}
+
+ @Override
+ public void executeCommand(String command, String parameters, ParcelFileDescriptor out) {}
+
+ @Override
+ public void closeSystemDialogs(String reason) {}
+
+ @Override
+ public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep,
+ float zoom, boolean sync) {}
+
+ @Override
+ public void dispatchWallpaperCommand(String action, int x, int y,
+ int z, Bundle extras, boolean sync) {}
+
+ /* Drag/drop */
+ @Override
+ public void dispatchDragEvent(DragEvent event) {}
+
+ @Override
+ public void updatePointerIcon(float x, float y) {}
+
+ @Override
+ public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility,
+ int localValue, int localChanges) {}
+
+ @Override
+ public void dispatchWindowShown() {}
+
+ @Override
+ public void requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId) {}
+
+ @Override
+ public void dispatchPointerCaptureChanged(boolean hasCapture) {}
+
+ @Override
+ public void requestScrollCapture(IScrollCaptureController controller) {
+ try {
+ controller.onClientUnavailable();
+ } catch (RemoteException ex) {
+ // ignore
+ }
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/TransactionPool.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/TransactionPool.java
new file mode 100644
index 000000000000..4c34566b0d98
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/TransactionPool.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.common;
+
+import android.util.Pools;
+import android.view.SurfaceControl;
+
+/**
+ * Provides a synchronized pool of {@link SurfaceControl.Transaction}s to minimize allocations.
+ */
+public class TransactionPool {
+ private final Pools.SynchronizedPool<SurfaceControl.Transaction> mTransactionPool =
+ new Pools.SynchronizedPool<>(4);
+
+ public TransactionPool() {
+ }
+
+ /** Gets a transaction from the pool. */
+ public SurfaceControl.Transaction acquire() {
+ SurfaceControl.Transaction t = mTransactionPool.acquire();
+ if (t == null) {
+ return new SurfaceControl.Transaction();
+ }
+ return t;
+ }
+
+ /**
+ * Return a transaction to the pool. DO NOT call {@link SurfaceControl.Transaction#close()} if
+ * returning to pool.
+ */
+ public void release(SurfaceControl.Transaction t) {
+ if (!mTransactionPool.release(t)) {
+ t.close();
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java
new file mode 100644
index 000000000000..9c78fc5e57b8
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import androidx.annotation.NonNull;
+
+import com.android.wm.shell.onehanded.OneHandedGestureHandler.OneHandedGestureEventCallback;
+
+import java.io.PrintWriter;
+
+/**
+ * Interface to engage one handed feature.
+ */
+public interface OneHanded {
+ /**
+ * Return whether the device has one handed feature or not.
+ */
+ boolean hasOneHandedFeature();
+
+ /**
+ * Return one handed settings enabled or not.
+ */
+ boolean isOneHandedEnabled();
+
+ /**
+ * Return swipe to notification settings enabled or not.
+ */
+ boolean isSwipeToNotificationEnabled();
+
+ /**
+ * Enters one handed mode.
+ */
+ void startOneHanded();
+
+ /**
+ * Exits one handed mode.
+ */
+ void stopOneHanded();
+
+ /**
+ * Exits one handed mode with {@link OneHandedEvents}.
+ */
+ void stopOneHanded(int event);
+
+ /**
+ * Set navigation 3 button mode enabled or disabled by users.
+ */
+ void setThreeButtonModeEnabled(boolean enabled);
+
+ /**
+ * Register callback to be notified after {@link OneHandedDisplayAreaOrganizer}
+ * transition start or finish
+ */
+ void registerTransitionCallback(OneHandedTransitionCallback callback);
+
+ /**
+ * Register callback for one handed gesture, this gesture callbcak will be activated on
+ * 3 button navigation mode only
+ */
+ void registerGestureCallback(OneHandedGestureEventCallback callback);
+
+ /**
+ * Dump one handed status.
+ */
+ void dump(@NonNull PrintWriter pw);
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedAnimationCallback.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedAnimationCallback.java
new file mode 100644
index 000000000000..6749f7eec968
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedAnimationCallback.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import android.view.SurfaceControl;
+
+/**
+ * Additional callback interface for OneHanded animation
+ */
+public interface OneHandedAnimationCallback {
+ /**
+ * Called when OneHanded animation is started.
+ */
+ default void onOneHandedAnimationStart(
+ OneHandedAnimationController.OneHandedTransitionAnimator animator) {
+ }
+
+ /**
+ * Called when OneHanded animation is ended.
+ */
+ default void onOneHandedAnimationEnd(SurfaceControl.Transaction tx,
+ OneHandedAnimationController.OneHandedTransitionAnimator animator) {
+ }
+
+ /**
+ * Called when OneHanded animation is cancelled.
+ */
+ default void onOneHandedAnimationCancel(
+ OneHandedAnimationController.OneHandedTransitionAnimator animator) {
+ }
+
+ /**
+ * Called when OneHanded animator is updating offset
+ */
+ default void onTutorialAnimationUpdate(int offset) {}
+
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedAnimationController.java
new file mode 100644
index 000000000000..963909621a1b
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedAnimationController.java
@@ -0,0 +1,302 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import android.animation.Animator;
+import android.animation.ValueAnimator;
+import android.annotation.IntDef;
+import android.content.Context;
+import android.graphics.Rect;
+import android.view.SurfaceControl;
+import android.view.animation.Interpolator;
+import android.view.animation.OvershootInterpolator;
+
+import androidx.annotation.VisibleForTesting;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Controller class of OneHanded animations (both from and to OneHanded mode).
+ */
+public class OneHandedAnimationController {
+ private static final float FRACTION_START = 0f;
+ private static final float FRACTION_END = 1f;
+
+ public static final int TRANSITION_DIRECTION_NONE = 0;
+ public static final int TRANSITION_DIRECTION_TRIGGER = 1;
+ public static final int TRANSITION_DIRECTION_EXIT = 2;
+
+ @IntDef(prefix = {"TRANSITION_DIRECTION_"}, value = {
+ TRANSITION_DIRECTION_NONE,
+ TRANSITION_DIRECTION_TRIGGER,
+ TRANSITION_DIRECTION_EXIT,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface TransitionDirection {
+ }
+
+ private final Interpolator mOvershootInterpolator;
+ private final OneHandedSurfaceTransactionHelper mSurfaceTransactionHelper;
+ private final HashMap<SurfaceControl, OneHandedTransitionAnimator> mAnimatorMap =
+ new HashMap<>();
+
+ /**
+ * Constructor of OneHandedAnimationController
+ */
+ public OneHandedAnimationController(Context context) {
+ mSurfaceTransactionHelper = new OneHandedSurfaceTransactionHelper(context);
+ mOvershootInterpolator = new OvershootInterpolator();
+ }
+
+ @SuppressWarnings("unchecked")
+ OneHandedTransitionAnimator getAnimator(SurfaceControl leash, Rect startBounds,
+ Rect endBounds) {
+ final OneHandedTransitionAnimator animator = mAnimatorMap.get(leash);
+ if (animator == null) {
+ mAnimatorMap.put(leash, setupOneHandedTransitionAnimator(
+ OneHandedTransitionAnimator.ofBounds(leash, startBounds, endBounds)));
+ } else if (animator.isRunning()) {
+ animator.updateEndValue(endBounds);
+ } else {
+ animator.cancel();
+ mAnimatorMap.put(leash, setupOneHandedTransitionAnimator(
+ OneHandedTransitionAnimator.ofBounds(leash, startBounds, endBounds)));
+ }
+ return mAnimatorMap.get(leash);
+ }
+
+ HashMap<SurfaceControl, OneHandedTransitionAnimator> getAnimatorMap() {
+ return mAnimatorMap;
+ }
+
+ boolean isAnimatorsConsumed() {
+ return mAnimatorMap.isEmpty();
+ }
+
+ void removeAnimator(SurfaceControl key) {
+ final OneHandedTransitionAnimator animator = mAnimatorMap.remove(key);
+ if (animator != null && animator.isRunning()) {
+ animator.cancel();
+ }
+ }
+
+ OneHandedTransitionAnimator setupOneHandedTransitionAnimator(
+ OneHandedTransitionAnimator animator) {
+ animator.setSurfaceTransactionHelper(mSurfaceTransactionHelper);
+ animator.setInterpolator(mOvershootInterpolator);
+ animator.setFloatValues(FRACTION_START, FRACTION_END);
+ return animator;
+ }
+
+ /**
+ * Animator for OneHanded transition animation which supports both alpha and bounds animation.
+ *
+ * @param <T> Type of property to animate, either offset (float)
+ */
+ public abstract static class OneHandedTransitionAnimator<T> extends ValueAnimator implements
+ ValueAnimator.AnimatorUpdateListener,
+ ValueAnimator.AnimatorListener {
+
+ private final SurfaceControl mLeash;
+ private T mStartValue;
+ private T mEndValue;
+ private T mCurrentValue;
+
+ private final List<OneHandedAnimationCallback> mOneHandedAnimationCallbacks =
+ new ArrayList<>();
+ private OneHandedSurfaceTransactionHelper mSurfaceTransactionHelper;
+ private OneHandedSurfaceTransactionHelper.SurfaceControlTransactionFactory
+ mSurfaceControlTransactionFactory;
+
+ private @TransitionDirection int mTransitionDirection;
+ private int mTransitionOffset;
+
+ private OneHandedTransitionAnimator(SurfaceControl leash, T startValue, T endValue) {
+ mLeash = leash;
+ mStartValue = startValue;
+ mEndValue = endValue;
+ addListener(this);
+ addUpdateListener(this);
+ mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
+ mTransitionDirection = TRANSITION_DIRECTION_NONE;
+ }
+
+ @Override
+ public void onAnimationStart(Animator animation) {
+ mCurrentValue = mStartValue;
+ mOneHandedAnimationCallbacks.forEach(
+ (callback) -> {
+ callback.onOneHandedAnimationStart(this);
+ }
+ );
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mCurrentValue = mEndValue;
+ final SurfaceControl.Transaction tx = newSurfaceControlTransaction();
+ onEndTransaction(mLeash, tx);
+ mOneHandedAnimationCallbacks.forEach(
+ (callback) -> {
+ callback.onOneHandedAnimationEnd(tx, this);
+ }
+ );
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ mCurrentValue = mEndValue;
+ mOneHandedAnimationCallbacks.forEach(
+ (callback) -> {
+ callback.onOneHandedAnimationCancel(this);
+ }
+ );
+ }
+
+ @Override
+ public void onAnimationRepeat(Animator animation) {
+ }
+
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ applySurfaceControlTransaction(mLeash, newSurfaceControlTransaction(),
+ animation.getAnimatedFraction());
+ mOneHandedAnimationCallbacks.forEach(
+ (callback) -> {
+ callback.onTutorialAnimationUpdate(((Rect) mCurrentValue).top);
+ }
+ );
+ }
+
+ void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {
+ }
+
+ void onEndTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {
+ }
+
+ abstract void applySurfaceControlTransaction(SurfaceControl leash,
+ SurfaceControl.Transaction tx, float fraction);
+
+ OneHandedSurfaceTransactionHelper getSurfaceTransactionHelper() {
+ return mSurfaceTransactionHelper;
+ }
+
+ void setSurfaceTransactionHelper(OneHandedSurfaceTransactionHelper helper) {
+ mSurfaceTransactionHelper = helper;
+ }
+
+ OneHandedTransitionAnimator<T> setOneHandedAnimationCallbacks(
+ OneHandedAnimationCallback callback) {
+ mOneHandedAnimationCallbacks.add(callback);
+ return this;
+ }
+
+ SurfaceControl getLeash() {
+ return mLeash;
+ }
+
+ Rect getDestinationBounds() {
+ return (Rect) mEndValue;
+ }
+
+ int getDestinationOffset() {
+ return ((Rect) mEndValue).top - ((Rect) mStartValue).top;
+ }
+
+ @TransitionDirection
+ int getTransitionDirection() {
+ return mTransitionDirection;
+ }
+
+ OneHandedTransitionAnimator<T> setTransitionDirection(int direction) {
+ mTransitionDirection = direction;
+ return this;
+ }
+
+ OneHandedTransitionAnimator<T> setTransitionOffset(int offset) {
+ mTransitionOffset = offset;
+ return this;
+ }
+
+ T getStartValue() {
+ return mStartValue;
+ }
+
+ T getEndValue() {
+ return mEndValue;
+ }
+
+ void setCurrentValue(T value) {
+ mCurrentValue = value;
+ }
+
+ /**
+ * Updates the {@link #mEndValue}.
+ */
+ void updateEndValue(T endValue) {
+ mEndValue = endValue;
+ }
+
+ SurfaceControl.Transaction newSurfaceControlTransaction() {
+ return mSurfaceControlTransactionFactory.getTransaction();
+ }
+
+ @VisibleForTesting
+ static OneHandedTransitionAnimator<Rect> ofBounds(SurfaceControl leash,
+ Rect startValue, Rect endValue) {
+
+ return new OneHandedTransitionAnimator<Rect>(leash, new Rect(startValue),
+ new Rect(endValue)) {
+
+ private final Rect mTmpRect = new Rect();
+
+ private int getCastedFractionValue(float start, float end, float fraction) {
+ return (int) (start * (1 - fraction) + end * fraction + .5f);
+ }
+
+ @Override
+ void applySurfaceControlTransaction(SurfaceControl leash,
+ SurfaceControl.Transaction tx, float fraction) {
+ final Rect start = getStartValue();
+ final Rect end = getEndValue();
+ mTmpRect.set(
+ getCastedFractionValue(start.left, end.left, fraction),
+ getCastedFractionValue(start.top, end.top, fraction),
+ getCastedFractionValue(start.right, end.right, fraction),
+ getCastedFractionValue(start.bottom, end.bottom, fraction));
+ setCurrentValue(mTmpRect);
+ getSurfaceTransactionHelper().crop(tx, leash, mTmpRect)
+ .round(tx, leash);
+ tx.apply();
+ }
+
+ @Override
+ void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {
+ getSurfaceTransactionHelper()
+ .alpha(tx, leash, 1f)
+ .translate(tx, leash, getEndValue().top - getStartValue().top)
+ .round(tx, leash);
+ tx.apply();
+ }
+ };
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java
new file mode 100644
index 000000000000..c84b4781d19d
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java
@@ -0,0 +1,440 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static android.os.UserHandle.USER_CURRENT;
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import android.content.Context;
+import android.content.om.IOverlayManager;
+import android.content.om.OverlayInfo;
+import android.database.ContentObserver;
+import android.graphics.Point;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemProperties;
+import android.provider.Settings;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
+
+import com.android.wm.shell.common.DisplayChangeController;
+import com.android.wm.shell.common.DisplayController;
+import com.android.wm.shell.onehanded.OneHandedGestureHandler.OneHandedGestureEventCallback;
+
+import java.io.PrintWriter;
+
+/**
+ * Manages and manipulates the one handed states, transitions, and gesture for phones.
+ */
+public class OneHandedController implements OneHanded {
+ private static final String TAG = "OneHandedController";
+
+ private static final String ONE_HANDED_MODE_OFFSET_PERCENTAGE =
+ "persist.debug.one_handed_offset_percentage";
+ private static final String ONE_HANDED_MODE_GESTURAL_OVERLAY =
+ "com.android.internal.systemui.onehanded.gestural";
+
+ static final String SUPPORT_ONE_HANDED_MODE = "ro.support_one_handed_mode";
+
+ private final boolean mHasOneHandedFeature;
+ private boolean mIsOneHandedEnabled;
+ private boolean mIsSwipeToNotificationEnabled;
+ private boolean mTaskChangeToExit;
+ private float mOffSetFraction;
+
+ private final Context mContext;
+ private final DisplayController mDisplayController;
+ private final OneHandedGestureHandler mGestureHandler;
+ private final OneHandedTimeoutHandler mTimeoutHandler;
+ private final OneHandedTouchHandler mTouchHandler;
+ private final OneHandedTutorialHandler mTutorialHandler;
+ private final IOverlayManager mOverlayManager;
+ private final Handler mMainHandler = new Handler(Looper.getMainLooper());
+
+ private OneHandedDisplayAreaOrganizer mDisplayAreaOrganizer;
+
+ /**
+ * Handle rotation based on OnDisplayChangingListener callback
+ */
+ private final DisplayChangeController.OnDisplayChangingListener mRotationController =
+ (display, fromRotation, toRotation, wct) -> {
+ if (mDisplayAreaOrganizer != null) {
+ mDisplayAreaOrganizer.onRotateDisplay(fromRotation, toRotation);
+ }
+ };
+
+ private final ContentObserver mEnabledObserver = new ContentObserver(mMainHandler) {
+ @Override
+ public void onChange(boolean selfChange) {
+ final boolean enabled = OneHandedSettingsUtil.getSettingsOneHandedModeEnabled(
+ mContext.getContentResolver());
+ OneHandedEvents.writeEvent(enabled
+ ? OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_ENABLED_ON
+ : OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_ENABLED_OFF);
+
+ setOneHandedEnabled(enabled);
+
+ // Also checks swipe to notification settings since they all need gesture overlay.
+ setEnabledGesturalOverlay(
+ enabled || OneHandedSettingsUtil.getSettingsSwipeToNotificationEnabled(
+ mContext.getContentResolver()));
+ }
+ };
+
+ private final ContentObserver mTimeoutObserver = new ContentObserver(mMainHandler) {
+ @Override
+ public void onChange(boolean selfChange) {
+ final int newTimeout = OneHandedSettingsUtil.getSettingsOneHandedModeTimeout(
+ mContext.getContentResolver());
+ int metricsId = OneHandedEvents.OneHandedSettingsTogglesEvent.INVALID.getId();
+ switch (newTimeout) {
+ case OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_NEVER:
+ metricsId = OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_NEVER;
+ break;
+ case OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_SHORT_IN_SECONDS:
+ metricsId = OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_4;
+ break;
+ case OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS:
+ metricsId = OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_8;
+ break;
+ case OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_LONG_IN_SECONDS:
+ metricsId = OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_12;
+ break;
+ default:
+ // do nothing
+ break;
+ }
+ OneHandedEvents.writeEvent(metricsId);
+
+ if (mTimeoutHandler != null) {
+ mTimeoutHandler.setTimeout(newTimeout);
+ }
+ }
+ };
+
+ private final ContentObserver mTaskChangeExitObserver = new ContentObserver(mMainHandler) {
+ @Override
+ public void onChange(boolean selfChange) {
+ final boolean enabled = OneHandedSettingsUtil.getSettingsTapsAppToExit(
+ mContext.getContentResolver());
+ OneHandedEvents.writeEvent(enabled
+ ? OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_APP_TAPS_EXIT_ON
+ : OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_APP_TAPS_EXIT_OFF);
+
+ setTaskChangeToExit(enabled);
+ }
+ };
+
+ private final ContentObserver mSwipeToNotificationEnabledObserver =
+ new ContentObserver(mMainHandler) {
+ @Override
+ public void onChange(boolean selfChange) {
+ final boolean enabled =
+ OneHandedSettingsUtil.getSettingsSwipeToNotificationEnabled(
+ mContext.getContentResolver());
+ setSwipeToNotificationEnabled(enabled);
+
+ // Also checks one handed mode settings since they all need gesture overlay.
+ setEnabledGesturalOverlay(
+ enabled || OneHandedSettingsUtil.getSettingsOneHandedModeEnabled(
+ mContext.getContentResolver()));
+ }
+ };
+
+ /**
+ * The static constructor method to create OneHnadedController.
+ */
+ public static OneHandedController create(
+ Context context, DisplayController displayController) {
+ OneHandedTutorialHandler tutorialHandler = new OneHandedTutorialHandler(context);
+ OneHandedAnimationController animationController =
+ new OneHandedAnimationController(context);
+ OneHandedTouchHandler touchHandler = new OneHandedTouchHandler();
+ OneHandedGestureHandler gestureHandler = new OneHandedGestureHandler(
+ context, displayController);
+ OneHandedDisplayAreaOrganizer organizer = new OneHandedDisplayAreaOrganizer(
+ context, displayController, animationController, tutorialHandler);
+ return new OneHandedController(context, displayController, organizer, touchHandler,
+ tutorialHandler, gestureHandler);
+ }
+
+ @VisibleForTesting
+ OneHandedController(Context context,
+ DisplayController displayController,
+ OneHandedDisplayAreaOrganizer displayAreaOrganizer,
+ OneHandedTouchHandler touchHandler,
+ OneHandedTutorialHandler tutorialHandler,
+ OneHandedGestureHandler gestureHandler) {
+ mHasOneHandedFeature = SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false);
+ if (!mHasOneHandedFeature) {
+ Log.i(TAG, "Device config SUPPORT_ONE_HANDED_MODE off");
+ mContext = null;
+ mDisplayAreaOrganizer = null;
+ mDisplayController = null;
+ mTouchHandler = null;
+ mTutorialHandler = null;
+ mGestureHandler = null;
+ mTimeoutHandler = null;
+ mOverlayManager = null;
+ return;
+ }
+
+ mContext = context;
+ mDisplayAreaOrganizer = displayAreaOrganizer;
+ mDisplayController = displayController;
+ mTouchHandler = touchHandler;
+ mTutorialHandler = tutorialHandler;
+ mGestureHandler = gestureHandler;
+
+ mOverlayManager = IOverlayManager.Stub.asInterface(
+ ServiceManager.getService(Context.OVERLAY_SERVICE));
+ mOffSetFraction = SystemProperties.getInt(ONE_HANDED_MODE_OFFSET_PERCENTAGE, 50) / 100.0f;
+ mIsOneHandedEnabled = OneHandedSettingsUtil.getSettingsOneHandedModeEnabled(
+ context.getContentResolver());
+ mIsSwipeToNotificationEnabled = OneHandedSettingsUtil.getSettingsSwipeToNotificationEnabled(
+ context.getContentResolver());
+ mTimeoutHandler = OneHandedTimeoutHandler.get();
+
+ mDisplayController.addDisplayChangingController(mRotationController);
+
+ setupCallback();
+ setupSettingObservers();
+ setupTimeoutListener();
+ setupGesturalOverlay();
+ updateSettings();
+ }
+
+ /**
+ * Set one handed enabled or disabled when user update settings
+ */
+ void setOneHandedEnabled(boolean enabled) {
+ mIsOneHandedEnabled = enabled;
+ updateOneHandedEnabled();
+ }
+
+ /**
+ * Set one handed enabled or disabled by when user update settings
+ */
+ void setTaskChangeToExit(boolean enabled) {
+ mTaskChangeToExit = enabled;
+ }
+
+ /**
+ * Sets whether to enable swipe bottom to notification gesture when user update settings.
+ */
+ void setSwipeToNotificationEnabled(boolean enabled) {
+ mIsSwipeToNotificationEnabled = enabled;
+ updateOneHandedEnabled();
+ }
+
+ @Override
+ public boolean hasOneHandedFeature() {
+ return mHasOneHandedFeature;
+ }
+
+ @Override
+ public boolean isOneHandedEnabled() {
+ return mIsOneHandedEnabled;
+ }
+
+ @Override
+ public boolean isSwipeToNotificationEnabled() {
+ return mIsSwipeToNotificationEnabled;
+ }
+
+ @Override
+ public void startOneHanded() {
+ if (!mDisplayAreaOrganizer.isInOneHanded()) {
+ final int yOffSet = Math.round(getDisplaySize().y * mOffSetFraction);
+ mDisplayAreaOrganizer.scheduleOffset(0, yOffSet);
+ mTimeoutHandler.resetTimer();
+
+ OneHandedEvents.writeEvent(OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_GESTURE_IN);
+ }
+ }
+
+ @Override
+ public void stopOneHanded() {
+ if (mDisplayAreaOrganizer.isInOneHanded()) {
+ mDisplayAreaOrganizer.scheduleOffset(0, 0);
+ mTimeoutHandler.removeTimer();
+ }
+ }
+
+ @Override
+ public void stopOneHanded(int event) {
+ if (!mTaskChangeToExit && event == OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_APP_TAPS_OUT) {
+ //Task change exit not enable, do nothing and return here.
+ return;
+ }
+
+ if (mDisplayAreaOrganizer.isInOneHanded()) {
+ OneHandedEvents.writeEvent(event);
+ }
+
+ stopOneHanded();
+ }
+
+ @Override
+ public void setThreeButtonModeEnabled(boolean enabled) {
+ mGestureHandler.onThreeButtonModeEnabled(enabled);
+ }
+
+ @Override
+ public void registerTransitionCallback(OneHandedTransitionCallback callback) {
+ mDisplayAreaOrganizer.registerTransitionCallback(callback);
+ }
+
+ @Override
+ public void registerGestureCallback(OneHandedGestureEventCallback callback) {
+ mGestureHandler.setGestureEventListener(callback);
+ }
+
+ private void setupCallback() {
+ mTouchHandler.registerTouchEventListener(() ->
+ stopOneHanded(OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_OVERSPACE_OUT));
+ mDisplayAreaOrganizer.registerTransitionCallback(mTouchHandler);
+ mDisplayAreaOrganizer.registerTransitionCallback(mGestureHandler);
+ mDisplayAreaOrganizer.registerTransitionCallback(mTutorialHandler);
+ }
+
+ private void setupSettingObservers() {
+ OneHandedSettingsUtil.registerSettingsKeyObserver(Settings.Secure.ONE_HANDED_MODE_ENABLED,
+ mContext.getContentResolver(), mEnabledObserver);
+ OneHandedSettingsUtil.registerSettingsKeyObserver(Settings.Secure.ONE_HANDED_MODE_TIMEOUT,
+ mContext.getContentResolver(), mTimeoutObserver);
+ OneHandedSettingsUtil.registerSettingsKeyObserver(Settings.Secure.TAPS_APP_TO_EXIT,
+ mContext.getContentResolver(), mTaskChangeExitObserver);
+ OneHandedSettingsUtil.registerSettingsKeyObserver(
+ Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED,
+ mContext.getContentResolver(), mSwipeToNotificationEnabledObserver);
+ }
+
+ private void updateSettings() {
+ setOneHandedEnabled(OneHandedSettingsUtil
+ .getSettingsOneHandedModeEnabled(mContext.getContentResolver()));
+ mTimeoutHandler.setTimeout(OneHandedSettingsUtil
+ .getSettingsOneHandedModeTimeout(mContext.getContentResolver()));
+ setTaskChangeToExit(OneHandedSettingsUtil
+ .getSettingsTapsAppToExit(mContext.getContentResolver()));
+ setSwipeToNotificationEnabled(OneHandedSettingsUtil
+ .getSettingsSwipeToNotificationEnabled(mContext.getContentResolver()));
+ }
+
+ private void setupTimeoutListener() {
+ mTimeoutHandler.registerTimeoutListener(timeoutTime -> {
+ stopOneHanded(OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_TIMEOUT_OUT);
+ });
+ }
+
+ /**
+ * Query the current display real size from {@link DisplayController}
+ *
+ * @return {@link DisplayController#getDisplay(int)#getDisplaySize()}
+ */
+ private Point getDisplaySize() {
+ Point displaySize = new Point();
+ if (mDisplayController != null && mDisplayController.getDisplay(DEFAULT_DISPLAY) != null) {
+ mDisplayController.getDisplay(DEFAULT_DISPLAY).getRealSize(displaySize);
+ }
+ return displaySize;
+ }
+
+ private void updateOneHandedEnabled() {
+ if (mDisplayAreaOrganizer.isInOneHanded()) {
+ stopOneHanded();
+ }
+ // TODO Be aware to unregisterOrganizer() after animation finished
+ mDisplayAreaOrganizer.unregisterOrganizer();
+ if (mIsOneHandedEnabled) {
+ mDisplayAreaOrganizer.registerOrganizer(
+ OneHandedDisplayAreaOrganizer.FEATURE_ONE_HANDED);
+ }
+ mTouchHandler.onOneHandedEnabled(mIsOneHandedEnabled);
+ mGestureHandler.onOneHandedEnabled(mIsOneHandedEnabled || mIsSwipeToNotificationEnabled);
+ }
+
+ private void setupGesturalOverlay() {
+ if (!OneHandedSettingsUtil.getSettingsOneHandedModeEnabled(mContext.getContentResolver())) {
+ return;
+ }
+
+ OverlayInfo info = null;
+ try {
+ // TODO(b/157958539) migrate new RRO config file after S+
+ mOverlayManager.setHighestPriority(ONE_HANDED_MODE_GESTURAL_OVERLAY, USER_CURRENT);
+ info = mOverlayManager.getOverlayInfo(ONE_HANDED_MODE_GESTURAL_OVERLAY, USER_CURRENT);
+ } catch (RemoteException e) { /* Do nothing */ }
+
+ if (info != null && !info.isEnabled()) {
+ // Enable the default gestural one handed overlay.
+ setEnabledGesturalOverlay(true);
+ }
+ }
+
+ @VisibleForTesting
+ private void setEnabledGesturalOverlay(boolean enabled) {
+ try {
+ mOverlayManager.setEnabled(ONE_HANDED_MODE_GESTURAL_OVERLAY, enabled, USER_CURRENT);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ @Override
+ public void dump(@NonNull PrintWriter pw) {
+ final String innerPrefix = " ";
+ pw.println(TAG + "states: ");
+ pw.print(innerPrefix + "mOffSetFraction=");
+ pw.println(mOffSetFraction);
+
+ if (mDisplayAreaOrganizer != null) {
+ mDisplayAreaOrganizer.dump(pw);
+ }
+
+ if (mTouchHandler != null) {
+ mTouchHandler.dump(pw);
+ }
+
+ if (mTimeoutHandler != null) {
+ mTimeoutHandler.dump(pw);
+ }
+
+ if (mTutorialHandler != null) {
+ mTutorialHandler.dump(pw);
+ }
+
+ OneHandedSettingsUtil.dump(pw, innerPrefix, mContext.getContentResolver());
+
+ if (mOverlayManager != null) {
+ OverlayInfo info = null;
+ try {
+ info = mOverlayManager.getOverlayInfo(ONE_HANDED_MODE_GESTURAL_OVERLAY,
+ USER_CURRENT);
+ } catch (RemoteException e) { /* Do nothing */ }
+
+ if (info != null && !info.isEnabled()) {
+ pw.print(innerPrefix + "OverlayInfo=");
+ pw.println(info);
+ }
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedDisplayAreaOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedDisplayAreaOrganizer.java
new file mode 100644
index 000000000000..9954618134e8
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedDisplayAreaOrganizer.java
@@ -0,0 +1,368 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import static com.android.wm.shell.onehanded.OneHandedAnimationController.TRANSITION_DIRECTION_EXIT;
+import static com.android.wm.shell.onehanded.OneHandedAnimationController.TRANSITION_DIRECTION_TRIGGER;
+
+import android.content.Context;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.SystemProperties;
+import android.util.Log;
+import android.view.SurfaceControl;
+import android.window.DisplayAreaInfo;
+import android.window.DisplayAreaOrganizer;
+import android.window.WindowContainerTransaction;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
+
+import com.android.internal.os.SomeArgs;
+import com.android.wm.shell.common.DisplayController;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Manages OneHanded display areas such as offset.
+ *
+ * This class listens on {@link DisplayAreaOrganizer} callbacks for windowing mode change
+ * both to and from OneHanded and issues corresponding animation if applicable.
+ * Normally, we apply series of {@link SurfaceControl.Transaction} when the animator is running
+ * and files a final {@link WindowContainerTransaction} at the end of the transition.
+ *
+ * This class is also responsible for translating one handed operations within SysUI component
+ */
+public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
+ private static final String TAG = "OneHandedDisplayAreaOrganizer";
+ private static final String ONE_HANDED_MODE_TRANSLATE_ANIMATION_DURATION =
+ "persist.debug.one_handed_translate_animation_duration";
+
+ @VisibleForTesting
+ static final int MSG_RESET_IMMEDIATE = 1;
+ @VisibleForTesting
+ static final int MSG_OFFSET_ANIMATE = 2;
+ @VisibleForTesting
+ static final int MSG_OFFSET_FINISH = 3;
+
+ private final Rect mLastVisualDisplayBounds = new Rect();
+ private final Rect mDefaultDisplayBounds = new Rect();
+
+ private Handler mUpdateHandler;
+ private boolean mIsInOneHanded;
+ private int mEnterExitAnimationDurationMs;
+
+ @VisibleForTesting
+ HashMap<DisplayAreaInfo, SurfaceControl> mDisplayAreaMap = new HashMap();
+ private DisplayController mDisplayController;
+ private OneHandedAnimationController mAnimationController;
+ private OneHandedSurfaceTransactionHelper.SurfaceControlTransactionFactory
+ mSurfaceControlTransactionFactory;
+ private OneHandedTutorialHandler mTutorialHandler;
+ private List<OneHandedTransitionCallback> mTransitionCallbacks = new ArrayList<>();
+
+ @VisibleForTesting
+ OneHandedAnimationCallback mOneHandedAnimationCallback =
+ new OneHandedAnimationCallback() {
+ @Override
+ public void onOneHandedAnimationStart(
+ OneHandedAnimationController.OneHandedTransitionAnimator animator) {
+ }
+
+ @Override
+ public void onOneHandedAnimationEnd(SurfaceControl.Transaction tx,
+ OneHandedAnimationController.OneHandedTransitionAnimator animator) {
+ mAnimationController.removeAnimator(animator.getLeash());
+ if (mAnimationController.isAnimatorsConsumed()) {
+ mUpdateHandler.sendMessage(mUpdateHandler.obtainMessage(MSG_OFFSET_FINISH,
+ obtainArgsFromAnimator(animator)));
+ }
+ }
+
+ @Override
+ public void onOneHandedAnimationCancel(
+ OneHandedAnimationController.OneHandedTransitionAnimator animator) {
+ mAnimationController.removeAnimator(animator.getLeash());
+ if (mAnimationController.isAnimatorsConsumed()) {
+ mUpdateHandler.sendMessage(mUpdateHandler.obtainMessage(MSG_OFFSET_FINISH,
+ obtainArgsFromAnimator(animator)));
+ }
+ }
+ };
+
+ @SuppressWarnings("unchecked")
+ private Handler.Callback mUpdateCallback = (msg) -> {
+ SomeArgs args = (SomeArgs) msg.obj;
+ final Rect currentBounds = args.arg1 != null ? (Rect) args.arg1 : mDefaultDisplayBounds;
+ final int yOffset = args.argi2;
+ final int direction = args.argi3;
+
+ switch (msg.what) {
+ case MSG_RESET_IMMEDIATE:
+ resetWindowsOffset();
+ mDefaultDisplayBounds.set(currentBounds);
+ mLastVisualDisplayBounds.set(currentBounds);
+ finishOffset(0, TRANSITION_DIRECTION_EXIT);
+ break;
+ case MSG_OFFSET_ANIMATE:
+ final Rect toBounds = new Rect(mDefaultDisplayBounds.left,
+ mDefaultDisplayBounds.top + yOffset,
+ mDefaultDisplayBounds.right,
+ mDefaultDisplayBounds.bottom + yOffset);
+ offsetWindows(currentBounds, toBounds, direction, mEnterExitAnimationDurationMs);
+ break;
+ case MSG_OFFSET_FINISH:
+ finishOffset(yOffset, direction);
+ break;
+ }
+ args.recycle();
+ return true;
+ };
+
+ /**
+ * Constructor of OneHandedDisplayAreaOrganizer
+ */
+ public OneHandedDisplayAreaOrganizer(Context context,
+ DisplayController displayController,
+ OneHandedAnimationController animationController,
+ OneHandedTutorialHandler tutorialHandler) {
+ mUpdateHandler = new Handler(OneHandedThread.get().getLooper(), mUpdateCallback);
+ mAnimationController = animationController;
+ mDisplayController = displayController;
+ mDefaultDisplayBounds.set(getDisplayBounds());
+ mLastVisualDisplayBounds.set(getDisplayBounds());
+ mEnterExitAnimationDurationMs =
+ SystemProperties.getInt(ONE_HANDED_MODE_TRANSLATE_ANIMATION_DURATION, 300);
+ mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
+ mTutorialHandler = tutorialHandler;
+ }
+
+ @Override
+ public void onDisplayAreaAppeared(@NonNull DisplayAreaInfo displayAreaInfo,
+ @NonNull SurfaceControl leash) {
+ Objects.requireNonNull(displayAreaInfo, "displayAreaInfo must not be null");
+ Objects.requireNonNull(leash, "leash must not be null");
+
+ if (displayAreaInfo.featureId != FEATURE_ONE_HANDED) {
+ Log.w(TAG, "Bypass onDisplayAreaAppeared()! displayAreaInfo=" + displayAreaInfo);
+ return;
+ }
+ // mDefaultDisplayBounds may out of date after removeDisplayChangingController()
+ mDefaultDisplayBounds.set(getDisplayBounds());
+ mDisplayAreaMap.put(displayAreaInfo, leash);
+ }
+
+ @Override
+ public void onDisplayAreaVanished(@NonNull DisplayAreaInfo displayAreaInfo) {
+ Objects.requireNonNull(displayAreaInfo,
+ "Requires valid displayArea, and displayArea must not be null");
+
+ if (!mDisplayAreaMap.containsKey(displayAreaInfo)) {
+ Log.w(TAG, "Unrecognized token: " + displayAreaInfo.token);
+ return;
+ }
+ mDisplayAreaMap.remove(displayAreaInfo);
+ }
+
+ @Override
+ public void unregisterOrganizer() {
+ super.unregisterOrganizer();
+ resetWindowsOffset();
+
+ // Ensure all cached instance are cleared after resetWindowsOffset
+ mUpdateHandler.post(() -> {
+ if (mDisplayAreaMap != null && !mDisplayAreaMap.isEmpty()) {
+ mDisplayAreaMap.clear();
+ }
+ });
+ }
+
+ /**
+ * Handler for display rotation changes by below policy which
+ * handles 90 degree display rotation changes {@link Surface.Rotation}
+ *
+ */
+ public void onRotateDisplay(int fromRotation, int toRotation) {
+ // Stop one handed without animation and reset cropped size immediately
+ final Rect newBounds = new Rect(mDefaultDisplayBounds);
+ final boolean isOrientationDiff = Math.abs(fromRotation - toRotation) % 2 == 1;
+
+ if (isOrientationDiff) {
+ newBounds.set(newBounds.left, newBounds.top, newBounds.bottom, newBounds.right);
+ SomeArgs args = SomeArgs.obtain();
+ args.arg1 = newBounds;
+ args.argi1 = 0 /* xOffset */;
+ args.argi2 = 0 /* yOffset */;
+ args.argi3 = TRANSITION_DIRECTION_EXIT;
+ mUpdateHandler.sendMessage(mUpdateHandler.obtainMessage(MSG_RESET_IMMEDIATE, args));
+ }
+ }
+
+ /**
+ * Offset the windows by a given offset on Y-axis, triggered also from screen rotation.
+ * Directly perform manipulation/offset on the leash.
+ */
+ public void scheduleOffset(int xOffset, int yOffset) {
+ SomeArgs args = SomeArgs.obtain();
+ args.arg1 = getLastVisualDisplayBounds();
+ args.argi1 = xOffset;
+ args.argi2 = yOffset;
+ args.argi3 = yOffset > 0 ? TRANSITION_DIRECTION_TRIGGER : TRANSITION_DIRECTION_EXIT;
+ mUpdateHandler.sendMessage(mUpdateHandler.obtainMessage(MSG_OFFSET_ANIMATE, args));
+ }
+
+ private void offsetWindows(Rect fromBounds, Rect toBounds, int direction, int durationMs) {
+ if (Looper.myLooper() != mUpdateHandler.getLooper()) {
+ throw new RuntimeException("Callers should call scheduleOffset() instead of this "
+ + "directly");
+ }
+ mDisplayAreaMap.forEach(
+ (key, leash) -> animateWindows(leash, fromBounds, toBounds, direction,
+ durationMs));
+ }
+
+ private void resetWindowsOffset() {
+ mUpdateHandler.post(() -> {
+ final SurfaceControl.Transaction tx =
+ mSurfaceControlTransactionFactory.getTransaction();
+ mDisplayAreaMap.forEach(
+ (key, leash) -> {
+ final OneHandedAnimationController.OneHandedTransitionAnimator animator =
+ mAnimationController.getAnimatorMap().remove(leash);
+ if (animator != null && animator.isRunning()) {
+ animator.cancel();
+ }
+ tx.setPosition(leash, 0, 0)
+ .setWindowCrop(leash, -1/* reset */, -1/* reset */);
+ });
+ tx.apply();
+ });
+ }
+
+ private void animateWindows(SurfaceControl leash, Rect fromBounds, Rect toBounds,
+ @OneHandedAnimationController.TransitionDirection int direction, int durationMs) {
+ if (Looper.myLooper() != mUpdateHandler.getLooper()) {
+ throw new RuntimeException("Callers should call scheduleOffset() instead of "
+ + "this directly");
+ }
+ mUpdateHandler.post(() -> {
+ final OneHandedAnimationController.OneHandedTransitionAnimator animator =
+ mAnimationController.getAnimator(leash, fromBounds, toBounds);
+ if (animator != null) {
+ animator.setTransitionDirection(direction)
+ .setOneHandedAnimationCallbacks(mOneHandedAnimationCallback)
+ .setOneHandedAnimationCallbacks(mTutorialHandler.getAnimationCallback())
+ .setDuration(durationMs)
+ .start();
+ }
+ });
+ }
+
+ private void finishOffset(int offset,
+ @OneHandedAnimationController.TransitionDirection int direction) {
+ if (Looper.myLooper() != mUpdateHandler.getLooper()) {
+ throw new RuntimeException(
+ "Callers should call scheduleOffset() instead of this directly.");
+ }
+ // Only finishOffset() can update mIsInOneHanded to ensure the state is handle in sequence,
+ // the flag *MUST* be updated before dispatch mTransitionCallbacks
+ mIsInOneHanded = (offset > 0 || direction == TRANSITION_DIRECTION_TRIGGER);
+ mLastVisualDisplayBounds.offsetTo(0,
+ direction == TRANSITION_DIRECTION_TRIGGER ? offset : 0);
+ for (int i = mTransitionCallbacks.size() - 1; i >= 0; i--) {
+ final OneHandedTransitionCallback callback = mTransitionCallbacks.get(i);
+ if (direction == TRANSITION_DIRECTION_TRIGGER) {
+ callback.onStartFinished(getLastVisualDisplayBounds());
+ } else {
+ callback.onStopFinished(getLastVisualDisplayBounds());
+ }
+ }
+ }
+
+ /**
+ * The latest state of one handed mode
+ *
+ * @return true Currently is in one handed mode, otherwise is not in one handed mode
+ */
+ public boolean isInOneHanded() {
+ return mIsInOneHanded;
+ }
+
+ /**
+ * The latest visual bounds of displayArea translated
+ *
+ * @return Rect latest finish_offset
+ */
+ public Rect getLastVisualDisplayBounds() {
+ return mLastVisualDisplayBounds;
+ }
+
+ @Nullable
+ private Rect getDisplayBounds() {
+ Point realSize = new Point(0, 0);
+ if (mDisplayController != null && mDisplayController.getDisplay(DEFAULT_DISPLAY) != null) {
+ mDisplayController.getDisplay(DEFAULT_DISPLAY).getRealSize(realSize);
+ }
+ return new Rect(0, 0, realSize.x, realSize.y);
+ }
+
+ @VisibleForTesting
+ Handler getUpdateHandler() {
+ return mUpdateHandler;
+ }
+
+ /**
+ * Register transition callback
+ */
+ public void registerTransitionCallback(OneHandedTransitionCallback callback) {
+ mTransitionCallbacks.add(callback);
+ }
+
+ private SomeArgs obtainArgsFromAnimator(
+ OneHandedAnimationController.OneHandedTransitionAnimator animator) {
+ SomeArgs args = SomeArgs.obtain();
+ args.arg1 = animator.getDestinationBounds();
+ args.argi1 = 0 /* xOffset */;
+ args.argi2 = animator.getDestinationOffset();
+ args.argi3 = animator.getTransitionDirection();
+ return args;
+ }
+
+ void dump(@NonNull PrintWriter pw) {
+ final String innerPrefix = " ";
+ pw.println(TAG + "states: ");
+ pw.print(innerPrefix + "mIsInOneHanded=");
+ pw.println(mIsInOneHanded);
+ pw.print(innerPrefix + "mDisplayAreaMap=");
+ pw.println(mDisplayAreaMap);
+ pw.print(innerPrefix + "mDefaultDisplayBounds=");
+ pw.println(mDefaultDisplayBounds);
+ pw.print(innerPrefix + "mLastVisualDisplayBounds=");
+ pw.println(mLastVisualDisplayBounds);
+ pw.print(innerPrefix + "getDisplayBounds()=");
+ pw.println(getDisplayBounds());
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedEvents.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedEvents.java
new file mode 100644
index 000000000000..79ddd2b11e72
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedEvents.java
@@ -0,0 +1,276 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.logging.UiEvent;
+import com.android.internal.logging.UiEventLogger;
+import com.android.internal.logging.UiEventLoggerImpl;
+
+/**
+ * Interesting events related to the One-Handed.
+ */
+public class OneHandedEvents {
+ private static final String TAG = "OneHandedEvents";
+
+ public static Callback sCallback;
+ @VisibleForTesting
+ static UiEventLogger sUiEventLogger = new UiEventLoggerImpl();
+
+ /**
+ * One-Handed event types
+ */
+ // Triggers
+ public static final int EVENT_ONE_HANDED_TRIGGER_GESTURE_IN = 0;
+ public static final int EVENT_ONE_HANDED_TRIGGER_GESTURE_OUT = 1;
+ public static final int EVENT_ONE_HANDED_TRIGGER_OVERSPACE_OUT = 2;
+ public static final int EVENT_ONE_HANDED_TRIGGER_POP_IME_OUT = 3;
+ public static final int EVENT_ONE_HANDED_TRIGGER_ROTATION_OUT = 4;
+ public static final int EVENT_ONE_HANDED_TRIGGER_APP_TAPS_OUT = 5;
+ public static final int EVENT_ONE_HANDED_TRIGGER_TIMEOUT_OUT = 6;
+ public static final int EVENT_ONE_HANDED_TRIGGER_SCREEN_OFF_OUT = 7;
+ // Settings toggles
+ public static final int EVENT_ONE_HANDED_SETTINGS_ENABLED_ON = 8;
+ public static final int EVENT_ONE_HANDED_SETTINGS_ENABLED_OFF = 9;
+ public static final int EVENT_ONE_HANDED_SETTINGS_APP_TAPS_EXIT_ON = 10;
+ public static final int EVENT_ONE_HANDED_SETTINGS_APP_TAPS_EXIT_OFF = 11;
+ public static final int EVENT_ONE_HANDED_SETTINGS_TIMEOUT_EXIT_ON = 12;
+ public static final int EVENT_ONE_HANDED_SETTINGS_TIMEOUT_EXIT_OFF = 13;
+ public static final int EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_NEVER = 14;
+ public static final int EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_4 = 15;
+ public static final int EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_8 = 16;
+ public static final int EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_12 = 17;
+
+ private static final String[] EVENT_TAGS = {
+ "one_handed_trigger_gesture_in",
+ "one_handed_trigger_gesture_out",
+ "one_handed_trigger_overspace_out",
+ "one_handed_trigger_pop_ime_out",
+ "one_handed_trigger_rotation_out",
+ "one_handed_trigger_app_taps_out",
+ "one_handed_trigger_timeout_out",
+ "one_handed_trigger_screen_off_out",
+ "one_handed_settings_enabled_on",
+ "one_handed_settings_enabled_off",
+ "one_handed_settings_app_taps_exit_on",
+ "one_handed_settings_app_taps_exit_off",
+ "one_handed_settings_timeout_exit_on",
+ "one_handed_settings_timeout_exit_off",
+ "one_handed_settings_timeout_seconds_never",
+ "one_handed_settings_timeout_seconds_4",
+ "one_handed_settings_timeout_seconds_8",
+ "one_handed_settings_timeout_seconds_12"
+ };
+
+ /**
+ * Events definition that related to One-Handed gestures.
+ */
+ @VisibleForTesting
+ public enum OneHandedTriggerEvent implements UiEventLogger.UiEventEnum {
+ INVALID(0),
+ @UiEvent(doc = "One-Handed trigger in via NavigationBar area")
+ ONE_HANDED_TRIGGER_GESTURE_IN(366),
+
+ @UiEvent(doc = "One-Handed trigger out via NavigationBar area")
+ ONE_HANDED_TRIGGER_GESTURE_OUT(367),
+
+ @UiEvent(doc = "One-Handed trigger out via Overspace area")
+ ONE_HANDED_TRIGGER_OVERSPACE_OUT(368),
+
+ @UiEvent(doc = "One-Handed trigger out while IME pop up")
+ ONE_HANDED_TRIGGER_POP_IME_OUT(369),
+
+ @UiEvent(doc = "One-Handed trigger out while device rotation to landscape")
+ ONE_HANDED_TRIGGER_ROTATION_OUT(370),
+
+ @UiEvent(doc = "One-Handed trigger out when an Activity is launching")
+ ONE_HANDED_TRIGGER_APP_TAPS_OUT(371),
+
+ @UiEvent(doc = "One-Handed trigger out when one-handed mode times up")
+ ONE_HANDED_TRIGGER_TIMEOUT_OUT(372),
+
+ @UiEvent(doc = "One-Handed trigger out when screen off")
+ ONE_HANDED_TRIGGER_SCREEN_OFF_OUT(449);
+
+ private final int mId;
+
+ OneHandedTriggerEvent(int id) {
+ mId = id;
+ }
+
+ public int getId() {
+ return mId;
+ }
+ }
+
+ /**
+ * Events definition that related to Settings toggles.
+ */
+ @VisibleForTesting
+ public enum OneHandedSettingsTogglesEvent implements UiEventLogger.UiEventEnum {
+ INVALID(0),
+ @UiEvent(doc = "One-Handed mode enabled toggle on")
+ ONE_HANDED_SETTINGS_TOGGLES_ENABLED_ON(356),
+
+ @UiEvent(doc = "One-Handed mode enabled toggle off")
+ ONE_HANDED_SETTINGS_TOGGLES_ENABLED_OFF(357),
+
+ @UiEvent(doc = "One-Handed mode app-taps-exit toggle on")
+ ONE_HANDED_SETTINGS_TOGGLES_APP_TAPS_EXIT_ON(358),
+
+ @UiEvent(doc = "One-Handed mode app-taps-exit toggle off")
+ ONE_HANDED_SETTINGS_TOGGLES_APP_TAPS_EXIT_OFF(359),
+
+ @UiEvent(doc = "One-Handed mode timeout-exit toggle on")
+ ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_EXIT_ON(360),
+
+ @UiEvent(doc = "One-Handed mode timeout-exit toggle off")
+ ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_EXIT_OFF(361),
+
+ @UiEvent(doc = "One-Handed mode timeout value changed to never timeout")
+ ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_SECONDS_NEVER(362),
+
+ @UiEvent(doc = "One-Handed mode timeout value changed to 4 seconds")
+ ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_SECONDS_4(363),
+
+ @UiEvent(doc = "One-Handed mode timeout value changed to 8 seconds")
+ ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_SECONDS_8(364),
+
+ @UiEvent(doc = "One-Handed mode timeout value changed to 12 seconds")
+ ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_SECONDS_12(365);
+
+ private final int mId;
+
+ OneHandedSettingsTogglesEvent(int id) {
+ mId = id;
+ }
+
+ public int getId() {
+ return mId;
+ }
+ }
+
+
+ /**
+ * Logs an event to the system log, to sCallback if present, and to the logEvent destinations.
+ * @param tag One of the EVENT_* codes above.
+ */
+ public static void writeEvent(int tag) {
+ final long time = System.currentTimeMillis();
+ logEvent(tag);
+ if (sCallback != null) {
+ sCallback.writeEvent(time, tag);
+ }
+ }
+
+ /**
+ * Logs an event to the UiEvent (statsd) logging.
+ * @param event One of the EVENT_* codes above.
+ * @return String a readable description of the event. Begins "writeEvent <tag_description>"
+ * if the tag is valid.
+ */
+ public static String logEvent(int event) {
+ if (event >= EVENT_TAGS.length) {
+ return "";
+ }
+ final StringBuilder sb = new StringBuilder("writeEvent ").append(EVENT_TAGS[event]);
+ switch (event) {
+ // Triggers
+ case EVENT_ONE_HANDED_TRIGGER_GESTURE_IN:
+ sUiEventLogger.log(OneHandedTriggerEvent.ONE_HANDED_TRIGGER_GESTURE_IN);
+ break;
+ case EVENT_ONE_HANDED_TRIGGER_GESTURE_OUT:
+ sUiEventLogger.log(OneHandedTriggerEvent.ONE_HANDED_TRIGGER_GESTURE_OUT);
+ break;
+ case EVENT_ONE_HANDED_TRIGGER_OVERSPACE_OUT:
+ sUiEventLogger.log(OneHandedTriggerEvent.ONE_HANDED_TRIGGER_OVERSPACE_OUT);
+ break;
+ case EVENT_ONE_HANDED_TRIGGER_POP_IME_OUT:
+ sUiEventLogger.log(OneHandedTriggerEvent.ONE_HANDED_TRIGGER_POP_IME_OUT);
+ break;
+ case EVENT_ONE_HANDED_TRIGGER_ROTATION_OUT:
+ sUiEventLogger.log(OneHandedTriggerEvent.ONE_HANDED_TRIGGER_ROTATION_OUT);
+ break;
+ case EVENT_ONE_HANDED_TRIGGER_APP_TAPS_OUT:
+ sUiEventLogger.log(OneHandedTriggerEvent.ONE_HANDED_TRIGGER_APP_TAPS_OUT);
+ break;
+ case EVENT_ONE_HANDED_TRIGGER_TIMEOUT_OUT:
+ sUiEventLogger.log(OneHandedTriggerEvent.ONE_HANDED_TRIGGER_TIMEOUT_OUT);
+ break;
+ case EVENT_ONE_HANDED_TRIGGER_SCREEN_OFF_OUT:
+ sUiEventLogger.log(OneHandedTriggerEvent.ONE_HANDED_TRIGGER_SCREEN_OFF_OUT);
+ break;
+ // Settings
+ case EVENT_ONE_HANDED_SETTINGS_ENABLED_ON:
+ sUiEventLogger.log(OneHandedSettingsTogglesEvent
+ .ONE_HANDED_SETTINGS_TOGGLES_ENABLED_ON);
+ break;
+ case EVENT_ONE_HANDED_SETTINGS_ENABLED_OFF:
+ sUiEventLogger.log(OneHandedSettingsTogglesEvent
+ .ONE_HANDED_SETTINGS_TOGGLES_ENABLED_OFF);
+ break;
+ case EVENT_ONE_HANDED_SETTINGS_APP_TAPS_EXIT_ON:
+ sUiEventLogger.log(OneHandedSettingsTogglesEvent
+ .ONE_HANDED_SETTINGS_TOGGLES_APP_TAPS_EXIT_ON);
+ break;
+ case EVENT_ONE_HANDED_SETTINGS_APP_TAPS_EXIT_OFF:
+ sUiEventLogger.log(OneHandedSettingsTogglesEvent
+ .ONE_HANDED_SETTINGS_TOGGLES_APP_TAPS_EXIT_OFF);
+ break;
+ case EVENT_ONE_HANDED_SETTINGS_TIMEOUT_EXIT_ON:
+ sUiEventLogger.log(OneHandedSettingsTogglesEvent
+ .ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_EXIT_ON);
+ break;
+ case EVENT_ONE_HANDED_SETTINGS_TIMEOUT_EXIT_OFF:
+ sUiEventLogger.log(OneHandedSettingsTogglesEvent
+ .ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_EXIT_OFF);
+ break;
+ case EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_NEVER:
+ sUiEventLogger.log(OneHandedSettingsTogglesEvent
+ .ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_SECONDS_NEVER);
+ break;
+ case EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_4:
+ sUiEventLogger.log(OneHandedSettingsTogglesEvent
+ .ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_SECONDS_4);
+ break;
+ case EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_8:
+ sUiEventLogger.log(OneHandedSettingsTogglesEvent
+ .ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_SECONDS_8);
+ break;
+ case EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_12:
+ sUiEventLogger.log(OneHandedSettingsTogglesEvent
+ .ONE_HANDED_SETTINGS_TOGGLES_TIMEOUT_SECONDS_12);
+ break;
+ default:
+ // Do nothing
+ break;
+ }
+ return sb.toString();
+ }
+
+ /**
+ * An interface for logging an event to the system log, if Callback present.
+ */
+ public interface Callback {
+ /**
+ *
+ * @param time System current time.
+ * @param tag Event tag.
+ */
+ void writeEvent(long time, int tag);
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedGestureHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedGestureHandler.java
new file mode 100644
index 000000000000..3b1e6cbe5ccd
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedGestureHandler.java
@@ -0,0 +1,269 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.graphics.Point;
+import android.graphics.PointF;
+import android.graphics.Rect;
+import android.hardware.input.InputManager;
+import android.os.Looper;
+import android.util.Log;
+import android.view.Display;
+import android.view.InputChannel;
+import android.view.InputEvent;
+import android.view.InputEventReceiver;
+import android.view.InputMonitor;
+import android.view.MotionEvent;
+import android.view.Surface;
+import android.view.ViewConfiguration;
+import android.window.WindowContainerTransaction;
+
+import androidx.annotation.VisibleForTesting;
+
+import com.android.wm.shell.R;
+import com.android.wm.shell.common.DisplayChangeController;
+import com.android.wm.shell.common.DisplayController;
+
+/**
+ * The class manage swipe up and down gesture for 3-Button mode navigation,
+ * others(e.g, 2-button, full gesture mode) are handled by Launcher quick steps.
+ */
+public class OneHandedGestureHandler implements OneHandedTransitionCallback,
+ DisplayChangeController.OnDisplayChangingListener {
+ private static final String TAG = "OneHandedGestureHandler";
+ private static final boolean DEBUG_GESTURE = false;
+
+ private static final int ANGLE_MAX = 150;
+ private static final int ANGLE_MIN = 30;
+ private final float mDragDistThreshold;
+ private final float mSquaredSlop;
+ private final PointF mDownPos = new PointF();
+ private final PointF mLastPos = new PointF();
+ private final PointF mStartDragPos = new PointF();
+ private boolean mPassedSlop;
+
+ private boolean mAllowGesture;
+ private boolean mIsEnabled;
+ private int mNavGestureHeight;
+ private boolean mIsThreeButtonModeEnabled;
+ private int mRotation = Surface.ROTATION_0;
+
+ @VisibleForTesting
+ InputMonitor mInputMonitor;
+ @VisibleForTesting
+ InputEventReceiver mInputEventReceiver;
+ private DisplayController mDisplayController;
+ @VisibleForTesting
+ @Nullable
+ OneHandedGestureEventCallback mGestureEventCallback;
+ private Rect mGestureRegion = new Rect();
+
+ /**
+ * Constructor of OneHandedGestureHandler, we only handle the gesture of
+ * {@link Display#DEFAULT_DISPLAY}
+ *
+ * @param context {@link Context}
+ * @param displayController {@link DisplayController}
+ */
+ public OneHandedGestureHandler(Context context, DisplayController displayController) {
+ mDisplayController = displayController;
+ displayController.addDisplayChangingController(this);
+ mNavGestureHeight = context.getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.navigation_bar_gesture_height);
+ mDragDistThreshold = context.getResources().getDimensionPixelSize(
+ R.dimen.gestures_onehanded_drag_threshold);
+ final float slop = ViewConfiguration.get(context).getScaledTouchSlop();
+ mSquaredSlop = slop * slop;
+ updateIsEnabled();
+ }
+
+ /**
+ * Notified by {@link OneHandedController}, when user update settings of Enabled or Disabled
+ *
+ * @param isEnabled is one handed settings enabled or not
+ */
+ public void onOneHandedEnabled(boolean isEnabled) {
+ if (DEBUG_GESTURE) {
+ Log.d(TAG, "onOneHandedEnabled, isEnabled = " + isEnabled);
+ }
+ mIsEnabled = isEnabled;
+ updateIsEnabled();
+ }
+
+ void onThreeButtonModeEnabled(boolean isEnabled) {
+ mIsThreeButtonModeEnabled = isEnabled;
+ updateIsEnabled();
+ }
+
+ /**
+ * Register {@link OneHandedGestureEventCallback} to receive onStart(), onStop() callback
+ */
+ public void setGestureEventListener(OneHandedGestureEventCallback callback) {
+ mGestureEventCallback = callback;
+ }
+
+ private void onMotionEvent(MotionEvent ev) {
+ int action = ev.getActionMasked();
+ if (action == MotionEvent.ACTION_DOWN) {
+ mAllowGesture = isWithinTouchRegion(ev.getX(), ev.getY())
+ && mRotation == Surface.ROTATION_0;
+ if (mAllowGesture) {
+ mDownPos.set(ev.getX(), ev.getY());
+ mLastPos.set(mDownPos);
+ }
+ if (DEBUG_GESTURE) {
+ Log.d(TAG, "ACTION_DOWN, mDownPos=" + mDownPos + ", mAllowGesture="
+ + mAllowGesture);
+ }
+ } else if (mAllowGesture) {
+ switch (action) {
+ case MotionEvent.ACTION_MOVE:
+ mLastPos.set(ev.getX(), ev.getY());
+ if (!mPassedSlop) {
+ if (squaredHypot(mLastPos.x - mDownPos.x, mLastPos.y - mDownPos.y)
+ > mSquaredSlop) {
+ mStartDragPos.set(mLastPos.x, mLastPos.y);
+ if (isValidStartAngle(
+ mDownPos.x - mLastPos.x, mDownPos.y - mLastPos.y)
+ || isValidExitAngle(
+ mDownPos.x - mLastPos.x, mDownPos.y - mLastPos.y)) {
+ mPassedSlop = true;
+ mInputMonitor.pilferPointers();
+ }
+ }
+ } else {
+ float distance = (float) Math.hypot(mLastPos.x - mDownPos.x,
+ mLastPos.y - mDownPos.y);
+ if (distance > mDragDistThreshold) {
+ mGestureEventCallback.onStop();
+ }
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ if (mLastPos.y >= mDownPos.y && mPassedSlop) {
+ mGestureEventCallback.onStart();
+ }
+ mPassedSlop = false;
+ mAllowGesture = false;
+ break;
+ case MotionEvent.ACTION_CANCEL:
+ mPassedSlop = false;
+ mAllowGesture = false;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ private void disposeInputChannel() {
+ if (mInputEventReceiver != null) {
+ mInputEventReceiver.dispose();
+ mInputEventReceiver = null;
+ }
+
+ if (mInputMonitor != null) {
+ mInputMonitor.dispose();
+ mInputMonitor = null;
+ }
+ }
+
+ private boolean isWithinTouchRegion(float x, float y) {
+ if (DEBUG_GESTURE) {
+ Log.d(TAG, "isWithinTouchRegion(), mGestureRegion=" + mGestureRegion + ", downX=" + x
+ + ", downY=" + y);
+ }
+ return mGestureRegion.contains(Math.round(x), Math.round(y));
+ }
+
+ private void updateIsEnabled() {
+ disposeInputChannel();
+
+ if (mIsEnabled && mIsThreeButtonModeEnabled) {
+ final Point displaySize = new Point();
+ if (mDisplayController != null) {
+ final Display display = mDisplayController.getDisplay(DEFAULT_DISPLAY);
+ if (display != null) {
+ display.getRealSize(displaySize);
+ }
+ }
+ // Register input event receiver to monitor the touch region of NavBar gesture height
+ mGestureRegion.set(0, displaySize.y - mNavGestureHeight, displaySize.x,
+ displaySize.y);
+ mInputMonitor = InputManager.getInstance().monitorGestureInput(
+ "onehanded-gesture-offset", DEFAULT_DISPLAY);
+ mInputEventReceiver = new EventReceiver(
+ mInputMonitor.getInputChannel(), Looper.getMainLooper());
+ }
+ }
+
+ private void onInputEvent(InputEvent ev) {
+ if (ev instanceof MotionEvent) {
+ onMotionEvent((MotionEvent) ev);
+ }
+ }
+
+ @Override
+ public void onRotateDisplay(int displayId, int fromRotation, int toRotation,
+ WindowContainerTransaction t) {
+ mRotation = toRotation;
+ }
+
+ private class EventReceiver extends InputEventReceiver {
+ EventReceiver(InputChannel channel, Looper looper) {
+ super(channel, looper);
+ }
+
+ public void onInputEvent(InputEvent event) {
+ OneHandedGestureHandler.this.onInputEvent(event);
+ finishInputEvent(event, true);
+ }
+ }
+
+ private boolean isValidStartAngle(float deltaX, float deltaY) {
+ final float angle = (float) Math.toDegrees(Math.atan2(deltaY, deltaX));
+ return angle > -(ANGLE_MAX) && angle < -(ANGLE_MIN);
+ }
+
+ private boolean isValidExitAngle(float deltaX, float deltaY) {
+ final float angle = (float) Math.toDegrees(Math.atan2(deltaY, deltaX));
+ return angle > ANGLE_MIN && angle < ANGLE_MAX;
+ }
+
+ private float squaredHypot(float x, float y) {
+ return x * x + y * y;
+ }
+
+ /**
+ * The touch(gesture) events to notify {@link OneHandedController} start or stop one handed
+ */
+ public interface OneHandedGestureEventCallback {
+ /**
+ * Handles the start gesture.
+ */
+ void onStart();
+
+ /**
+ * Handles the exit gesture.
+ */
+ void onStop();
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedSettingsUtil.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedSettingsUtil.java
new file mode 100644
index 000000000000..4d66f2961a29
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedSettingsUtil.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import android.annotation.IntDef;
+import android.content.ContentResolver;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.provider.Settings;
+
+import java.io.PrintWriter;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * APIs for querying or updating one handed settings .
+ */
+public final class OneHandedSettingsUtil {
+ private static final String TAG = "OneHandedSettingsUtil";
+
+ @IntDef(prefix = {"ONE_HANDED_TIMEOUT_"}, value = {
+ ONE_HANDED_TIMEOUT_NEVER,
+ ONE_HANDED_TIMEOUT_SHORT_IN_SECONDS,
+ ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS,
+ ONE_HANDED_TIMEOUT_LONG_IN_SECONDS,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface OneHandedTimeout {
+ }
+
+ /**
+ * Never stop one handed automatically
+ */
+ public static final int ONE_HANDED_TIMEOUT_NEVER = 0;
+ /**
+ * Auto stop one handed in {@link OneHandedSettingsUtil#ONE_HANDED_TIMEOUT_SHORT_IN_SECONDS}
+ */
+ public static final int ONE_HANDED_TIMEOUT_SHORT_IN_SECONDS = 4;
+ /**
+ * Auto stop one handed in {@link OneHandedSettingsUtil#ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS}
+ */
+ public static final int ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS = 8;
+ /**
+ * Auto stop one handed in {@link OneHandedSettingsUtil#ONE_HANDED_TIMEOUT_LONG_IN_SECONDS}
+ */
+ public static final int ONE_HANDED_TIMEOUT_LONG_IN_SECONDS = 12;
+
+ /**
+ * Register one handed preference settings observer
+ *
+ * @param key Setting key to monitor in observer
+ * @param resolver ContentResolver of context
+ * @param observer Observer from caller
+ * @return uri key for observing
+ */
+ public static Uri registerSettingsKeyObserver(String key, ContentResolver resolver,
+ ContentObserver observer) {
+ Uri uriKey = null;
+ uriKey = Settings.Secure.getUriFor(key);
+ if (resolver != null && uriKey != null) {
+ resolver.registerContentObserver(uriKey, false, observer);
+ }
+ return uriKey;
+ }
+
+ /**
+ * Unregister one handed preference settings observer
+ *
+ * @param resolver ContentResolver of context
+ * @param observer preference key change observer
+ */
+ public static void unregisterSettingsKeyObserver(ContentResolver resolver,
+ ContentObserver observer) {
+ if (resolver != null) {
+ resolver.unregisterContentObserver(observer);
+ }
+ }
+
+ /**
+ * Query one handed enable or disable flag from Settings provider.
+ *
+ * @return enable or disable one handed mode flag.
+ */
+ public static boolean getSettingsOneHandedModeEnabled(ContentResolver resolver) {
+ return Settings.Secure.getInt(resolver,
+ Settings.Secure.ONE_HANDED_MODE_ENABLED, 0 /* Disabled */) == 1;
+ }
+
+ /**
+ * Query taps app to exit config from Settings provider.
+ *
+ * @return enable or disable taps app exit.
+ */
+ public static boolean getSettingsTapsAppToExit(ContentResolver resolver) {
+ return Settings.Secure.getInt(resolver,
+ Settings.Secure.TAPS_APP_TO_EXIT, 0) == 1;
+ }
+
+ /**
+ * Query timeout value from Settings provider.
+ * Default is {@link OneHandedSettingsUtil#ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS}
+ *
+ * @return timeout value in seconds.
+ */
+ public static @OneHandedTimeout int getSettingsOneHandedModeTimeout(ContentResolver resolver) {
+ return Settings.Secure.getInt(resolver,
+ Settings.Secure.ONE_HANDED_MODE_TIMEOUT, ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS);
+ }
+
+ /**
+ * Returns whether swipe bottom to notification gesture enabled or not.
+ */
+ public static boolean getSettingsSwipeToNotificationEnabled(ContentResolver resolver) {
+ return Settings.Secure.getInt(resolver,
+ Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED, 0) == 1;
+ }
+
+ protected static void dump(PrintWriter pw, String prefix, ContentResolver resolver) {
+ final String innerPrefix = prefix + " ";
+ pw.println(prefix + TAG);
+ pw.print(innerPrefix + "isOneHandedModeEnable=");
+ pw.println(getSettingsOneHandedModeEnabled(resolver));
+ pw.print(innerPrefix + "oneHandedTimeOut=");
+ pw.println(getSettingsOneHandedModeTimeout(resolver));
+ pw.print(innerPrefix + "tapsAppToExit=");
+ pw.println(getSettingsTapsAppToExit(resolver));
+ }
+
+ private OneHandedSettingsUtil() {}
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedSurfaceTransactionHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedSurfaceTransactionHelper.java
new file mode 100644
index 000000000000..e7010db97d77
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedSurfaceTransactionHelper.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Rect;
+import android.view.SurfaceControl;
+
+import com.android.wm.shell.R;
+
+/**
+ * Abstracts the common operations on {@link SurfaceControl.Transaction} for OneHanded transition.
+ */
+public class OneHandedSurfaceTransactionHelper {
+ private final boolean mEnableCornerRadius;
+ private final float mCornerRadius;
+
+ public OneHandedSurfaceTransactionHelper(Context context) {
+ final Resources res = context.getResources();
+ mCornerRadius = res.getDimension(com.android.internal.R.dimen.rounded_corner_radius);
+ mEnableCornerRadius = res.getBoolean(R.bool.config_one_handed_enable_round_corner);
+ }
+
+ /**
+ * Operates the translation (setPosition) on a given transaction and leash
+ *
+ * @return same {@link OneHandedSurfaceTransactionHelper} instance for method chaining
+ */
+ OneHandedSurfaceTransactionHelper translate(SurfaceControl.Transaction tx, SurfaceControl leash,
+ float offset) {
+ tx.setPosition(leash, 0, offset);
+ return this;
+ }
+
+ /**
+ * Operates the alpha on a given transaction and leash
+ *
+ * @return same {@link OneHandedSurfaceTransactionHelper} instance for method chaining
+ */
+ OneHandedSurfaceTransactionHelper alpha(SurfaceControl.Transaction tx, SurfaceControl leash,
+ float alpha) {
+ tx.setAlpha(leash, alpha);
+ return this;
+ }
+
+ /**
+ * Operates the crop (setMatrix) on a given transaction and leash
+ *
+ * @return same {@link OneHandedSurfaceTransactionHelper} instance for method chaining
+ */
+ OneHandedSurfaceTransactionHelper crop(SurfaceControl.Transaction tx, SurfaceControl leash,
+ Rect destinationBounds) {
+ tx.setWindowCrop(leash, destinationBounds.width(), destinationBounds.height())
+ .setPosition(leash, destinationBounds.left, destinationBounds.top);
+ return this;
+ }
+
+ /**
+ * Operates the round corner radius on a given transaction and leash
+ *
+ * @return same {@link OneHandedSurfaceTransactionHelper} instance for method chaining
+ */
+ OneHandedSurfaceTransactionHelper round(SurfaceControl.Transaction tx, SurfaceControl leash) {
+ if (mEnableCornerRadius) {
+ tx.setCornerRadius(leash, mCornerRadius);
+ }
+ return this;
+ }
+
+ interface SurfaceControlTransactionFactory {
+ SurfaceControl.Transaction getTransaction();
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedThread.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedThread.java
new file mode 100644
index 000000000000..24d33ede5d63
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedThread.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import android.os.Handler;
+import android.os.HandlerThread;
+
+/**
+ * Similar to {@link com.android.internal.os.BackgroundThread}, this is a shared singleton
+ * foreground thread for each process for updating one handed.
+ */
+public class OneHandedThread extends HandlerThread {
+ private static OneHandedThread sInstance;
+ private static Handler sHandler;
+
+ private OneHandedThread() {
+ super("OneHanded");
+ }
+
+ private static void ensureThreadLocked() {
+ if (sInstance == null) {
+ sInstance = new OneHandedThread();
+ sInstance.start();
+ sHandler = new Handler(sInstance.getLooper());
+ }
+ }
+
+ /**
+ * @return the static update thread instance
+ */
+ public static OneHandedThread get() {
+ synchronized (OneHandedThread.class) {
+ ensureThreadLocked();
+ return sInstance;
+ }
+ }
+
+ /**
+ * @return the static update thread handler instance
+ */
+ public static Handler getHandler() {
+ synchronized (OneHandedThread.class) {
+ ensureThreadLocked();
+ return sHandler;
+ }
+ }
+
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTimeoutHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTimeoutHandler.java
new file mode 100644
index 000000000000..9c97cd7db71f
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTimeoutHandler.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static com.android.wm.shell.onehanded.OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS;
+
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Timeout handler for stop one handed mode operations.
+ */
+public class OneHandedTimeoutHandler {
+ private static final String TAG = "OneHandedTimeoutHandler";
+ private static boolean sIsDragging = false;
+ // Default timeout is ONE_HANDED_TIMEOUT_MEDIUM
+ private static @OneHandedSettingsUtil.OneHandedTimeout int sTimeout =
+ ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS;
+ private static long sTimeoutMs = TimeUnit.SECONDS.toMillis(sTimeout);
+ private static OneHandedTimeoutHandler sInstance;
+ private static List<TimeoutListener> sListeners = new ArrayList<>();
+
+ @VisibleForTesting
+ static final int ONE_HANDED_TIMEOUT_STOP_MSG = 1;
+ @VisibleForTesting
+ static Handler sHandler;
+
+ /**
+ * Get the current config of timeout
+ *
+ * @return timeout of current config
+ */
+ public @OneHandedSettingsUtil.OneHandedTimeout int getTimeout() {
+ return sTimeout;
+ }
+
+ /**
+ * Listens for notify timeout events
+ */
+ public interface TimeoutListener {
+ /**
+ * Called whenever the config time out
+ *
+ * @param timeoutTime The time in seconds to trigger timeout
+ */
+ void onTimeout(int timeoutTime);
+ }
+
+ /**
+ * Set the specific timeout of {@link OneHandedSettingsUtil.OneHandedTimeout}
+ */
+ public static void setTimeout(@OneHandedSettingsUtil.OneHandedTimeout int timeout) {
+ sTimeout = timeout;
+ sTimeoutMs = TimeUnit.SECONDS.toMillis(sTimeout);
+ resetTimer();
+ }
+
+ /**
+ * Reset the timer when one handed trigger or user is operating in some conditions
+ */
+ public static void removeTimer() {
+ sHandler.removeMessages(ONE_HANDED_TIMEOUT_STOP_MSG);
+ }
+
+ /**
+ * Reset the timer when one handed trigger or user is operating in some conditions
+ */
+ public static void resetTimer() {
+ removeTimer();
+ if (sTimeout == OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_NEVER) {
+ return;
+ }
+ if (sTimeout != OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_NEVER) {
+ sHandler.sendEmptyMessageDelayed(ONE_HANDED_TIMEOUT_STOP_MSG, sTimeoutMs);
+ }
+ }
+
+ /**
+ * Register timeout listener to receive time out events
+ *
+ * @param listener the listener be sent events when times up
+ */
+ public static void registerTimeoutListener(TimeoutListener listener) {
+ sListeners.add(listener);
+ }
+
+ /**
+ * Private constructor due to Singleton pattern
+ */
+ private OneHandedTimeoutHandler() {
+ }
+
+ /**
+ * Singleton pattern to get {@link OneHandedTimeoutHandler} instance
+ *
+ * @return the static update thread instance
+ */
+ public static OneHandedTimeoutHandler get() {
+ synchronized (OneHandedTimeoutHandler.class) {
+ if (sInstance == null) {
+ sInstance = new OneHandedTimeoutHandler();
+ }
+ if (sHandler == null) {
+ sHandler = new Handler(Looper.myLooper()) {
+ @Override
+ public void handleMessage(Message msg) {
+ if (msg.what == ONE_HANDED_TIMEOUT_STOP_MSG) {
+ onStop();
+ }
+ }
+ };
+ if (sTimeout != OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_NEVER) {
+ sHandler.sendEmptyMessageDelayed(ONE_HANDED_TIMEOUT_STOP_MSG, sTimeoutMs);
+ }
+ }
+ return sInstance;
+ }
+ }
+
+ private static void onStop() {
+ for (int i = sListeners.size() - 1; i >= 0; i--) {
+ final TimeoutListener listener = sListeners.get(i);
+ listener.onTimeout(sTimeout);
+ }
+ }
+
+ void dump(@NonNull PrintWriter pw) {
+ final String innerPrefix = " ";
+ pw.println(TAG + "states: ");
+ pw.print(innerPrefix + "sTimeout=");
+ pw.println(sTimeout);
+ pw.print(innerPrefix + "sListeners=");
+ pw.println(sListeners);
+ }
+
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTouchHandler.java
new file mode 100644
index 000000000000..721382d52717
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTouchHandler.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import android.graphics.Rect;
+import android.hardware.input.InputManager;
+import android.os.Looper;
+import android.view.InputChannel;
+import android.view.InputEvent;
+import android.view.InputEventReceiver;
+import android.view.InputMonitor;
+import android.view.MotionEvent;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
+
+import java.io.PrintWriter;
+
+/**
+ * Manages all the touch handling for One Handed on the Phone, including user tap outside region
+ * to exit, reset timer when user is in one-handed mode.
+ * Refer {@link OneHandedGestureHandler} to see start and stop one handed gesture
+ */
+public class OneHandedTouchHandler implements OneHandedTransitionCallback {
+ private static final String TAG = "OneHandedTouchHandler";
+ private final Rect mLastUpdatedBounds = new Rect();
+
+ private OneHandedTimeoutHandler mTimeoutHandler;
+
+ @VisibleForTesting
+ InputMonitor mInputMonitor;
+ @VisibleForTesting
+ InputEventReceiver mInputEventReceiver;
+ @VisibleForTesting
+ OneHandedTouchEventCallback mTouchEventCallback;
+
+ private boolean mIsEnabled;
+ private boolean mIsOnStopTransitioning;
+ private boolean mIsInOutsideRegion;
+
+ public OneHandedTouchHandler() {
+ mTimeoutHandler = OneHandedTimeoutHandler.get();
+ updateIsEnabled();
+ }
+
+ /**
+ * Notified by {@link OneHandedController}, when user update settings of Enabled or Disabled
+ *
+ * @param isEnabled is one handed settings enabled or not
+ */
+ public void onOneHandedEnabled(boolean isEnabled) {
+ mIsEnabled = isEnabled;
+ updateIsEnabled();
+ }
+
+ /**
+ * Register {@link OneHandedTouchEventCallback} to receive onEnter(), onExit() callback
+ */
+ public void registerTouchEventListener(OneHandedTouchEventCallback callback) {
+ mTouchEventCallback = callback;
+ }
+
+ private boolean onMotionEvent(MotionEvent ev) {
+ mIsInOutsideRegion = isWithinTouchOutsideRegion(ev.getX(), ev.getY());
+ switch (ev.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ case MotionEvent.ACTION_MOVE: {
+ if (!mIsInOutsideRegion) {
+ mTimeoutHandler.resetTimer();
+ }
+ break;
+ }
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL: {
+ mTimeoutHandler.resetTimer();
+ if (mIsInOutsideRegion && !mIsOnStopTransitioning) {
+ mTouchEventCallback.onStop();
+ mIsOnStopTransitioning = true;
+ }
+ // Reset flag for next operation
+ mIsInOutsideRegion = false;
+ break;
+ }
+ }
+ return true;
+ }
+
+ private void disposeInputChannel() {
+ if (mInputEventReceiver != null) {
+ mInputEventReceiver.dispose();
+ mInputEventReceiver = null;
+ }
+ if (mInputMonitor != null) {
+ mInputMonitor.dispose();
+ mInputMonitor = null;
+ }
+ }
+
+ private boolean isWithinTouchOutsideRegion(float x, float y) {
+ return Math.round(y) < mLastUpdatedBounds.top;
+ }
+
+ private void onInputEvent(InputEvent ev) {
+ if (ev instanceof MotionEvent) {
+ onMotionEvent((MotionEvent) ev);
+ }
+ }
+
+ private void updateIsEnabled() {
+ disposeInputChannel();
+ if (mIsEnabled) {
+ mInputMonitor = InputManager.getInstance().monitorGestureInput(
+ "onehanded-touch", DEFAULT_DISPLAY);
+ mInputEventReceiver = new EventReceiver(
+ mInputMonitor.getInputChannel(), Looper.getMainLooper());
+ }
+ }
+
+ @Override
+ public void onStartFinished(Rect bounds) {
+ mLastUpdatedBounds.set(bounds);
+ }
+
+ @Override
+ public void onStopFinished(Rect bounds) {
+ mLastUpdatedBounds.set(bounds);
+ mIsOnStopTransitioning = false;
+ }
+
+ void dump(@NonNull PrintWriter pw) {
+ final String innerPrefix = " ";
+ pw.println(TAG + "states: ");
+ pw.print(innerPrefix + "mLastUpdatedBounds=");
+ pw.println(mLastUpdatedBounds);
+ }
+
+ private class EventReceiver extends InputEventReceiver {
+ EventReceiver(InputChannel channel, Looper looper) {
+ super(channel, looper);
+ }
+
+ public void onInputEvent(InputEvent event) {
+ OneHandedTouchHandler.this.onInputEvent(event);
+ finishInputEvent(event, true);
+ }
+ }
+
+ /**
+ * The touch(gesture) events to notify {@link OneHandedController} start or stop one handed
+ */
+ public interface OneHandedTouchEventCallback {
+ /**
+ * Handle the exit event.
+ */
+ void onStop();
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTransitionCallback.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTransitionCallback.java
new file mode 100644
index 000000000000..3af7c4b71d0a
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTransitionCallback.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import android.graphics.Rect;
+
+/**
+ * The start or stop one handed transition callback for gesture to get latest timing to handle
+ * touch region.(e.g: one handed activated, user tap out regions of displayArea to stop one handed)
+ */
+public interface OneHandedTransitionCallback {
+ /**
+ * Called when start one handed transition finished
+ */
+ default void onStartFinished(Rect bounds) {
+ }
+
+ /**
+ * Called when stop one handed transition finished
+ */
+ default void onStopFinished(Rect bounds) {
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTutorialHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTutorialHandler.java
new file mode 100644
index 000000000000..b15b5154c2a4
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTutorialHandler.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.graphics.PixelFormat;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.os.SystemProperties;
+import android.provider.Settings;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+
+import com.android.wm.shell.R;
+
+import java.io.PrintWriter;
+
+/**
+ * Manages the user tutorial handling for One Handed operations, including animations synchronized
+ * with one-handed translation.
+ * Refer {@link OneHandedGestureHandler} and {@link OneHandedTouchHandler} to see start and stop
+ * one handed gesture
+ */
+public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
+ private static final String TAG = "OneHandedTutorialHandler";
+ private static final String ONE_HANDED_MODE_OFFSET_PERCENTAGE =
+ "persist.debug.one_handed_offset_percentage";
+ private static final int MAX_TUTORIAL_SHOW_COUNT = 2;
+ private final Rect mLastUpdatedBounds = new Rect();
+ private final WindowManager mWindowManager;
+
+ private View mTutorialView;
+ private Point mDisplaySize = new Point();
+ private Handler mUpdateHandler;
+ private ContentResolver mContentResolver;
+ private boolean mCanShowTutorial;
+
+ /**
+ * Container of the tutorial panel showing at outside region when one handed starting
+ */
+ private ViewGroup mTargetViewContainer;
+ private int mTutorialAreaHeight;
+
+ private final OneHandedAnimationCallback mAnimationCallback = new OneHandedAnimationCallback() {
+ @Override
+ public void onTutorialAnimationUpdate(int offset) {
+ mUpdateHandler.post(() -> onAnimationUpdate(offset));
+ }
+ };
+
+ public OneHandedTutorialHandler(Context context) {
+ context.getDisplay().getRealSize(mDisplaySize);
+ mContentResolver = context.getContentResolver();
+ mUpdateHandler = new Handler();
+ mWindowManager = context.getSystemService(WindowManager.class);
+ mTargetViewContainer = new FrameLayout(context);
+ mTargetViewContainer.setClipChildren(false);
+ mTutorialAreaHeight = Math.round(mDisplaySize.y
+ * (SystemProperties.getInt(ONE_HANDED_MODE_OFFSET_PERCENTAGE, 50) / 100.0f));
+ mTutorialView = LayoutInflater.from(context).inflate(R.layout.one_handed_tutorial, null);
+ mTargetViewContainer.addView(mTutorialView);
+ mCanShowTutorial = (Settings.Secure.getInt(mContentResolver,
+ Settings.Secure.ONE_HANDED_TUTORIAL_SHOW_COUNT, 0) >= MAX_TUTORIAL_SHOW_COUNT)
+ ? false : true;
+ if (mCanShowTutorial) {
+ createOrUpdateTutorialTarget();
+ }
+ }
+
+ @Override
+ public void onStartFinished(Rect bounds) {
+ mUpdateHandler.post(() -> {
+ updateFinished(View.VISIBLE, 0f);
+ updateTutorialCount();
+ });
+ }
+
+ @Override
+ public void onStopFinished(Rect bounds) {
+ mUpdateHandler.post(() -> updateFinished(
+ View.INVISIBLE, -mTargetViewContainer.getHeight()));
+ }
+
+ private void updateFinished(int visible, float finalPosition) {
+ if (!canShowTutorial()) {
+ return;
+ }
+
+ mTargetViewContainer.setVisibility(visible);
+ mTargetViewContainer.setTranslationY(finalPosition);
+ }
+
+ private void updateTutorialCount() {
+ int showCount = Settings.Secure.getInt(mContentResolver,
+ Settings.Secure.ONE_HANDED_TUTORIAL_SHOW_COUNT, 0);
+ showCount = Math.min(MAX_TUTORIAL_SHOW_COUNT, showCount + 1);
+ mCanShowTutorial = showCount < MAX_TUTORIAL_SHOW_COUNT;
+ Settings.Secure.putInt(mContentResolver,
+ Settings.Secure.ONE_HANDED_TUTORIAL_SHOW_COUNT, showCount);
+ }
+
+ /**
+ * Adds the tutorial target view to the WindowManager and update its layout, so it's ready
+ * to be animated in.
+ */
+ private void createOrUpdateTutorialTarget() {
+ mUpdateHandler.post(() -> {
+ if (!mTargetViewContainer.isAttachedToWindow()) {
+ mTargetViewContainer.setVisibility(View.INVISIBLE);
+
+ try {
+ mWindowManager.addView(mTargetViewContainer, getTutorialTargetLayoutParams());
+ } catch (IllegalStateException e) {
+ // This shouldn't happen, but if the target is already added, just update its
+ // layout params.
+ mWindowManager.updateViewLayout(
+ mTargetViewContainer, getTutorialTargetLayoutParams());
+ }
+ } else {
+ mWindowManager.updateViewLayout(mTargetViewContainer,
+ getTutorialTargetLayoutParams());
+ }
+ });
+ }
+
+ OneHandedAnimationCallback getAnimationCallback() {
+ return mAnimationCallback;
+ }
+
+ /**
+ * Returns layout params for the dismiss target, using the latest display metrics.
+ */
+ private WindowManager.LayoutParams getTutorialTargetLayoutParams() {
+ final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
+ mDisplaySize.x, mTutorialAreaHeight, 0, 0,
+ WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
+ WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+ | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
+ | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
+ PixelFormat.TRANSLUCENT);
+ lp.gravity = Gravity.TOP | Gravity.LEFT;
+ lp.privateFlags |= WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS;
+ lp.setFitInsetsTypes(0 /* types */);
+ lp.setTitle("one-handed-tutorial-overlay");
+
+ return lp;
+ }
+
+ void dump(@NonNull PrintWriter pw) {
+ final String innerPrefix = " ";
+ pw.println(TAG + "states: ");
+ pw.print(innerPrefix + "mLastUpdatedBounds=");
+ pw.println(mLastUpdatedBounds);
+ }
+
+ private boolean canShowTutorial() {
+ if (!mCanShowTutorial) {
+ mTargetViewContainer.setVisibility(View.GONE);
+ return false;
+ }
+
+ return true;
+ }
+
+ private void onAnimationUpdate(float value) {
+ if (!canShowTutorial()) {
+ return;
+ }
+ mTargetViewContainer.setVisibility(View.VISIBLE);
+ mTargetViewContainer.setTransitionGroup(true);
+ mTargetViewContainer.setTranslationY(value - mTargetViewContainer.getHeight());
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java b/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java
new file mode 100644
index 000000000000..ae0975467e3f
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogGroup.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.protolog;
+
+import com.android.internal.protolog.common.IProtoLogGroup;
+
+/**
+ * Defines logging groups for ProtoLog.
+ *
+ * This file is used by the ProtoLogTool to generate optimized logging code.
+ */
+public enum ShellProtoLogGroup implements IProtoLogGroup {
+ WM_SHELL_TASK_ORG(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
+ Consts.TAG_WM_SHELL),
+ TEST_GROUP(true, true, false, "WindowManagerShellProtoLogTest");
+
+ private final boolean mEnabled;
+ private volatile boolean mLogToProto;
+ private volatile boolean mLogToLogcat;
+ private final String mTag;
+
+ /**
+ * @param enabled set to false to exclude all log statements for this group from
+ * compilation,
+ * they will not be available in runtime.
+ * @param logToProto enable binary logging for the group
+ * @param logToLogcat enable text logging for the group
+ * @param tag name of the source of the logged message
+ */
+ ShellProtoLogGroup(boolean enabled, boolean logToProto, boolean logToLogcat, String tag) {
+ this.mEnabled = enabled;
+ this.mLogToProto = logToProto;
+ this.mLogToLogcat = logToLogcat;
+ this.mTag = tag;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return mEnabled;
+ }
+
+ @Override
+ public boolean isLogToProto() {
+ return mLogToProto;
+ }
+
+ @Override
+ public boolean isLogToLogcat() {
+ return mLogToLogcat;
+ }
+
+ @Override
+ public boolean isLogToAny() {
+ return mLogToLogcat || mLogToProto;
+ }
+
+ @Override
+ public String getTag() {
+ return mTag;
+ }
+
+ @Override
+ public void setLogToProto(boolean logToProto) {
+ this.mLogToProto = logToProto;
+ }
+
+ @Override
+ public void setLogToLogcat(boolean logToLogcat) {
+ this.mLogToLogcat = logToLogcat;
+ }
+
+ private static class Consts {
+ private static final String TAG_WM_SHELL = "WindowManagerShell";
+
+ private static final boolean ENABLE_DEBUG = true;
+ private static final boolean ENABLE_LOG_TO_PROTO_DEBUG = true;
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java b/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java
new file mode 100644
index 000000000000..6a925e74e847
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/protolog/ShellProtoLogImpl.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.protolog;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.util.Log;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.protolog.BaseProtoLogImpl;
+import com.android.internal.protolog.ProtoLogViewerConfigReader;
+import com.android.internal.protolog.common.IProtoLogGroup;
+import com.android.wm.shell.R;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.json.JSONException;
+
+
+/**
+ * A service for the ProtoLog logging system.
+ */
+public class ShellProtoLogImpl extends BaseProtoLogImpl {
+ private static final String TAG = "ProtoLogImpl";
+ private static final int BUFFER_CAPACITY = 1024 * 1024;
+ // TODO: Get the right path for the proto log file when we initialize the shell components
+ private static final String LOG_FILENAME = new File("wm_shell_log.pb").getAbsolutePath();
+
+ private static ShellProtoLogImpl sServiceInstance = null;
+
+ private final PrintWriter mSystemOutWriter;
+
+ static {
+ addLogGroupEnum(ShellProtoLogGroup.values());
+ }
+
+ /** Used by the ProtoLogTool, do not call directly - use {@code ProtoLog} class instead. */
+ public static void d(IProtoLogGroup group, int messageHash, int paramsMask,
+ @Nullable String messageString,
+ Object... args) {
+ getSingleInstance()
+ .log(LogLevel.DEBUG, group, messageHash, paramsMask, messageString, args);
+ }
+
+ /** Used by the ProtoLogTool, do not call directly - use {@code ProtoLog} class instead. */
+ public static void v(IProtoLogGroup group, int messageHash, int paramsMask,
+ @Nullable String messageString,
+ Object... args) {
+ getSingleInstance().log(LogLevel.VERBOSE, group, messageHash, paramsMask, messageString,
+ args);
+ }
+
+ /** Used by the ProtoLogTool, do not call directly - use {@code ProtoLog} class instead. */
+ public static void i(IProtoLogGroup group, int messageHash, int paramsMask,
+ @Nullable String messageString,
+ Object... args) {
+ getSingleInstance().log(LogLevel.INFO, group, messageHash, paramsMask, messageString, args);
+ }
+
+ /** Used by the ProtoLogTool, do not call directly - use {@code ProtoLog} class instead. */
+ public static void w(IProtoLogGroup group, int messageHash, int paramsMask,
+ @Nullable String messageString,
+ Object... args) {
+ getSingleInstance().log(LogLevel.WARN, group, messageHash, paramsMask, messageString, args);
+ }
+
+ /** Used by the ProtoLogTool, do not call directly - use {@code ProtoLog} class instead. */
+ public static void e(IProtoLogGroup group, int messageHash, int paramsMask,
+ @Nullable String messageString,
+ Object... args) {
+ getSingleInstance()
+ .log(LogLevel.ERROR, group, messageHash, paramsMask, messageString, args);
+ }
+
+ /** Used by the ProtoLogTool, do not call directly - use {@code ProtoLog} class instead. */
+ public static void wtf(IProtoLogGroup group, int messageHash, int paramsMask,
+ @Nullable String messageString,
+ Object... args) {
+ getSingleInstance().log(LogLevel.WTF, group, messageHash, paramsMask, messageString, args);
+ }
+
+ /** Returns true iff logging is enabled for the given {@code IProtoLogGroup}. */
+ public static boolean isEnabled(IProtoLogGroup group) {
+ return group.isLogToLogcat()
+ || (group.isLogToProto() && getSingleInstance().isProtoEnabled());
+ }
+
+ /**
+ * Returns the single instance of the ProtoLogImpl singleton class.
+ */
+ public static synchronized ShellProtoLogImpl getSingleInstance() {
+ if (sServiceInstance == null) {
+ sServiceInstance = new ShellProtoLogImpl();
+ }
+ return sServiceInstance;
+ }
+
+ public void startTextLogging(Context context, String... groups) {
+ try {
+ mViewerConfig.loadViewerConfig(
+ context.getResources().openRawResource(R.raw.wm_shell_protolog));
+ setLogging(true /* setTextLogging */, true, mSystemOutWriter, groups);
+ } catch (IOException e) {
+ Log.i(TAG, "Unable to load log definitions: IOException while reading "
+ + "wm_shell_protolog. " + e);
+ } catch (JSONException e) {
+ Log.i(TAG, "Unable to load log definitions: JSON parsing exception while reading "
+ + "wm_shell_protolog. " + e);
+ }
+ }
+
+ public void stopTextLogging(String... groups) {
+ setLogging(true /* setTextLogging */, false, mSystemOutWriter, groups);
+ }
+
+ private ShellProtoLogImpl() {
+ super(new File(LOG_FILENAME), null, BUFFER_CAPACITY,
+ new ProtoLogViewerConfigReader());
+ mSystemOutWriter = new PrintWriter(System.out, true);
+ }
+}
+
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerHandleView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerHandleView.java
new file mode 100644
index 000000000000..2cb1fff4cde6
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerHandleView.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
+import android.annotation.Nullable;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+import android.util.Property;
+import android.view.View;
+
+import com.android.wm.shell.R;
+import com.android.wm.shell.animation.Interpolators;
+
+/**
+ * View for the handle in the docked stack divider.
+ */
+public class DividerHandleView extends View {
+
+ private static final Property<DividerHandleView, Integer> WIDTH_PROPERTY =
+ new Property<DividerHandleView, Integer>(Integer.class, "width") {
+ @Override
+ public Integer get(DividerHandleView object) {
+ return object.mCurrentWidth;
+ }
+
+ @Override
+ public void set(DividerHandleView object, Integer value) {
+ object.mCurrentWidth = value;
+ object.invalidate();
+ }
+ };
+
+ private static final Property<DividerHandleView, Integer> HEIGHT_PROPERTY =
+ new Property<DividerHandleView, Integer>(Integer.class, "height") {
+ @Override
+ public Integer get(DividerHandleView object) {
+ return object.mCurrentHeight;
+ }
+
+ @Override
+ public void set(DividerHandleView object, Integer value) {
+ object.mCurrentHeight = value;
+ object.invalidate();
+ }
+ };
+
+ private final Paint mPaint = new Paint();
+ private final int mWidth;
+ private final int mHeight;
+ private final int mCircleDiameter;
+ private int mCurrentWidth;
+ private int mCurrentHeight;
+ private AnimatorSet mAnimator;
+ private boolean mTouching;
+
+ public DividerHandleView(Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ mPaint.setColor(getResources().getColor(R.color.docked_divider_handle, null));
+ mPaint.setAntiAlias(true);
+ mWidth = getResources().getDimensionPixelSize(R.dimen.docked_divider_handle_width);
+ mHeight = getResources().getDimensionPixelSize(R.dimen.docked_divider_handle_height);
+ mCurrentWidth = mWidth;
+ mCurrentHeight = mHeight;
+ mCircleDiameter = (mWidth + mHeight) / 3;
+ }
+
+ void setTouching(boolean touching, boolean animate) {
+ if (touching == mTouching) {
+ return;
+ }
+ if (mAnimator != null) {
+ mAnimator.cancel();
+ mAnimator = null;
+ }
+ if (!animate) {
+ if (touching) {
+ mCurrentWidth = mCircleDiameter;
+ mCurrentHeight = mCircleDiameter;
+ } else {
+ mCurrentWidth = mWidth;
+ mCurrentHeight = mHeight;
+ }
+ invalidate();
+ } else {
+ animateToTarget(touching ? mCircleDiameter : mWidth,
+ touching ? mCircleDiameter : mHeight, touching);
+ }
+ mTouching = touching;
+ }
+
+ private void animateToTarget(int targetWidth, int targetHeight, boolean touching) {
+ ObjectAnimator widthAnimator = ObjectAnimator.ofInt(this, WIDTH_PROPERTY,
+ mCurrentWidth, targetWidth);
+ ObjectAnimator heightAnimator = ObjectAnimator.ofInt(this, HEIGHT_PROPERTY,
+ mCurrentHeight, targetHeight);
+ mAnimator = new AnimatorSet();
+ mAnimator.playTogether(widthAnimator, heightAnimator);
+ mAnimator.setDuration(touching
+ ? DividerView.TOUCH_ANIMATION_DURATION
+ : DividerView.TOUCH_RELEASE_ANIMATION_DURATION);
+ mAnimator.setInterpolator(touching
+ ? Interpolators.TOUCH_RESPONSE
+ : Interpolators.FAST_OUT_SLOW_IN);
+ mAnimator.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mAnimator = null;
+ }
+ });
+ mAnimator.start();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ int left = getWidth() / 2 - mCurrentWidth / 2;
+ int top = getHeight() / 2 - mCurrentHeight / 2;
+ int radius = Math.min(mCurrentWidth, mCurrentHeight) / 2;
+ canvas.drawRoundRect(left, top, left + mCurrentWidth, top + mCurrentHeight,
+ radius, radius, mPaint);
+ }
+
+ @Override
+ public boolean hasOverlappingRendering() {
+ return false;
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerImeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerImeController.java
new file mode 100644
index 000000000000..ff617ed466d1
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerImeController.java
@@ -0,0 +1,415 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import static android.content.res.Configuration.SCREEN_HEIGHT_DP_UNDEFINED;
+import static android.content.res.Configuration.SCREEN_WIDTH_DP_UNDEFINED;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ValueAnimator;
+import android.annotation.Nullable;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.util.Slog;
+import android.view.SurfaceControl;
+import android.window.TaskOrganizer;
+import android.window.WindowContainerToken;
+import android.window.WindowContainerTransaction;
+
+import com.android.wm.shell.common.DisplayImeController;
+import com.android.wm.shell.common.TransactionPool;
+
+class DividerImeController implements DisplayImeController.ImePositionProcessor {
+ private static final String TAG = "DividerImeController";
+ private static final boolean DEBUG = SplitScreenController.DEBUG;
+
+ private static final float ADJUSTED_NONFOCUS_DIM = 0.3f;
+
+ private final SplitScreenTaskOrganizer mSplits;
+ private final TransactionPool mTransactionPool;
+ private final Handler mHandler;
+ private final TaskOrganizer mTaskOrganizer;
+
+ /**
+ * These are the y positions of the top of the IME surface when it is hidden and when it is
+ * shown respectively. These are NOT necessarily the top of the visible IME itself.
+ */
+ private int mHiddenTop = 0;
+ private int mShownTop = 0;
+
+ // The following are target states (what we are curretly animating towards).
+ /**
+ * {@code true} if, at the end of the animation, the split task positions should be
+ * adjusted by height of the IME. This happens when the secondary split is the IME target.
+ */
+ private boolean mTargetAdjusted = false;
+ /**
+ * {@code true} if, at the end of the animation, the IME should be shown/visible
+ * regardless of what has focus.
+ */
+ private boolean mTargetShown = false;
+ private float mTargetPrimaryDim = 0.f;
+ private float mTargetSecondaryDim = 0.f;
+
+ // The following are the current (most recent) states set during animation
+ /** {@code true} if the secondary split has IME focus. */
+ private boolean mSecondaryHasFocus = false;
+ /** The dimming currently applied to the primary/secondary splits. */
+ private float mLastPrimaryDim = 0.f;
+ private float mLastSecondaryDim = 0.f;
+ /** The most recent y position of the top of the IME surface */
+ private int mLastAdjustTop = -1;
+
+ // The following are states reached last time an animation fully completed.
+ /** {@code true} if the IME was shown/visible by the last-completed animation. */
+ private boolean mImeWasShown = false;
+ /** {@code true} if the split positions were adjusted by the last-completed animation. */
+ private boolean mAdjusted = false;
+
+ /**
+ * When some aspect of split-screen needs to animate independent from the IME,
+ * this will be non-null and control split animation.
+ */
+ @Nullable
+ private ValueAnimator mAnimation = null;
+
+ private boolean mPaused = true;
+ private boolean mPausedTargetAdjusted = false;
+ private boolean mAdjustedWhileHidden = false;
+
+ DividerImeController(SplitScreenTaskOrganizer splits, TransactionPool pool, Handler handler,
+ TaskOrganizer taskOrganizer) {
+ mSplits = splits;
+ mTransactionPool = pool;
+ mHandler = handler;
+ mTaskOrganizer = taskOrganizer;
+ }
+
+ private DividerView getView() {
+ return mSplits.mSplitScreenController.getDividerView();
+ }
+
+ private SplitDisplayLayout getLayout() {
+ return mSplits.mSplitScreenController.getSplitLayout();
+ }
+
+ private boolean isDividerVisible() {
+ return mSplits.mSplitScreenController.isDividerVisible();
+ }
+
+ private boolean getSecondaryHasFocus(int displayId) {
+ WindowContainerToken imeSplit = mTaskOrganizer.getImeTarget(displayId);
+ return imeSplit != null
+ && (imeSplit.asBinder() == mSplits.mSecondary.token.asBinder());
+ }
+
+ void reset() {
+ mPaused = true;
+ mPausedTargetAdjusted = false;
+ mAdjustedWhileHidden = false;
+ mAnimation = null;
+ mAdjusted = mTargetAdjusted = false;
+ mImeWasShown = mTargetShown = false;
+ mTargetPrimaryDim = mTargetSecondaryDim = mLastPrimaryDim = mLastSecondaryDim = 0.f;
+ mSecondaryHasFocus = false;
+ mLastAdjustTop = -1;
+ }
+
+ private void updateDimTargets() {
+ final boolean splitIsVisible = !getView().isHidden();
+ mTargetPrimaryDim = (mSecondaryHasFocus && mTargetShown && splitIsVisible)
+ ? ADJUSTED_NONFOCUS_DIM : 0.f;
+ mTargetSecondaryDim = (!mSecondaryHasFocus && mTargetShown && splitIsVisible)
+ ? ADJUSTED_NONFOCUS_DIM : 0.f;
+ }
+
+ @Override
+ @ImeAnimationFlags
+ public int onImeStartPositioning(int displayId, int hiddenTop, int shownTop,
+ boolean imeShouldShow, boolean imeIsFloating, SurfaceControl.Transaction t) {
+ mHiddenTop = hiddenTop;
+ mShownTop = shownTop;
+ mTargetShown = imeShouldShow;
+ if (!isDividerVisible()) {
+ return 0;
+ }
+ final boolean splitIsVisible = !getView().isHidden();
+ mSecondaryHasFocus = getSecondaryHasFocus(displayId);
+ final boolean targetAdjusted = splitIsVisible && imeShouldShow && mSecondaryHasFocus
+ && !imeIsFloating && !getLayout().mDisplayLayout.isLandscape()
+ && !mSplits.mSplitScreenController.isMinimized();
+ if (mLastAdjustTop < 0) {
+ mLastAdjustTop = imeShouldShow ? hiddenTop : shownTop;
+ } else if (mLastAdjustTop != (imeShouldShow ? mShownTop : mHiddenTop)) {
+ if (mTargetAdjusted != targetAdjusted && targetAdjusted == mAdjusted) {
+ // Check for an "interruption" of an existing animation. In this case, we
+ // need to fake-flip the last-known state direction so that the animation
+ // completes in the other direction.
+ mAdjusted = mTargetAdjusted;
+ } else if (targetAdjusted && mTargetAdjusted && mAdjusted) {
+ // Already fully adjusted for IME, but IME height has changed; so, force-start
+ // an async animation to the new IME height.
+ mAdjusted = false;
+ }
+ }
+ if (mPaused) {
+ mPausedTargetAdjusted = targetAdjusted;
+ if (DEBUG) Slog.d(TAG, " ime starting but paused " + dumpState());
+ return (targetAdjusted || mAdjusted) ? IME_ANIMATION_NO_ALPHA : 0;
+ }
+ mTargetAdjusted = targetAdjusted;
+ updateDimTargets();
+ if (DEBUG) Slog.d(TAG, " ime starting. vis:" + splitIsVisible + " " + dumpState());
+ if (mAnimation != null || (mImeWasShown && imeShouldShow
+ && mTargetAdjusted != mAdjusted)) {
+ // We need to animate adjustment independently of the IME position, so
+ // start our own animation to drive adjustment. This happens when a
+ // different split's editor has gained focus while the IME is still visible.
+ startAsyncAnimation();
+ }
+ if (splitIsVisible) {
+ // If split is hidden, we don't want to trigger any relayouts that would cause the
+ // divider to show again.
+ updateImeAdjustState();
+ } else {
+ mAdjustedWhileHidden = true;
+ }
+ return (mTargetAdjusted || mAdjusted) ? IME_ANIMATION_NO_ALPHA : 0;
+ }
+
+ private void updateImeAdjustState() {
+ updateImeAdjustState(false /* force */);
+ }
+
+ private void updateImeAdjustState(boolean force) {
+ if (mAdjusted != mTargetAdjusted || force) {
+ // Reposition the server's secondary split position so that it evaluates
+ // insets properly.
+ WindowContainerTransaction wct = new WindowContainerTransaction();
+ final SplitDisplayLayout splitLayout = getLayout();
+ if (mTargetAdjusted) {
+ splitLayout.updateAdjustedBounds(mShownTop, mHiddenTop, mShownTop);
+ wct.setBounds(mSplits.mSecondary.token, splitLayout.mAdjustedSecondary);
+ // "Freeze" the configuration size so that the app doesn't get a config
+ // or relaunch. This is required because normally nav-bar contributes
+ // to configuration bounds (via nondecorframe).
+ Rect adjustAppBounds = new Rect(mSplits.mSecondary.configuration
+ .windowConfiguration.getAppBounds());
+ adjustAppBounds.offset(0, splitLayout.mAdjustedSecondary.top
+ - splitLayout.mSecondary.top);
+ wct.setAppBounds(mSplits.mSecondary.token, adjustAppBounds);
+ wct.setScreenSizeDp(mSplits.mSecondary.token,
+ mSplits.mSecondary.configuration.screenWidthDp,
+ mSplits.mSecondary.configuration.screenHeightDp);
+
+ wct.setBounds(mSplits.mPrimary.token, splitLayout.mAdjustedPrimary);
+ adjustAppBounds = new Rect(mSplits.mPrimary.configuration
+ .windowConfiguration.getAppBounds());
+ adjustAppBounds.offset(0, splitLayout.mAdjustedPrimary.top
+ - splitLayout.mPrimary.top);
+ wct.setAppBounds(mSplits.mPrimary.token, adjustAppBounds);
+ wct.setScreenSizeDp(mSplits.mPrimary.token,
+ mSplits.mPrimary.configuration.screenWidthDp,
+ mSplits.mPrimary.configuration.screenHeightDp);
+ } else {
+ wct.setBounds(mSplits.mSecondary.token, splitLayout.mSecondary);
+ wct.setAppBounds(mSplits.mSecondary.token, null);
+ wct.setScreenSizeDp(mSplits.mSecondary.token,
+ SCREEN_WIDTH_DP_UNDEFINED, SCREEN_HEIGHT_DP_UNDEFINED);
+ wct.setBounds(mSplits.mPrimary.token, splitLayout.mPrimary);
+ wct.setAppBounds(mSplits.mPrimary.token, null);
+ wct.setScreenSizeDp(mSplits.mPrimary.token,
+ SCREEN_WIDTH_DP_UNDEFINED, SCREEN_HEIGHT_DP_UNDEFINED);
+ }
+
+ if (!mSplits.mSplitScreenController.getWmProxy().queueSyncTransactionIfWaiting(wct)) {
+ mTaskOrganizer.applyTransaction(wct);
+ }
+ }
+
+ // Update all the adjusted-for-ime states
+ if (!mPaused) {
+ final DividerView view = getView();
+ if (view != null) {
+ view.setAdjustedForIme(mTargetShown, mTargetShown
+ ? DisplayImeController.ANIMATION_DURATION_SHOW_MS
+ : DisplayImeController.ANIMATION_DURATION_HIDE_MS);
+ }
+ }
+ mSplits.mSplitScreenController.setAdjustedForIme(mTargetShown && !mPaused);
+ }
+
+ public void updateAdjustForIme() {
+ updateImeAdjustState(mAdjustedWhileHidden);
+ mAdjustedWhileHidden = false;
+ }
+
+ @Override
+ public void onImePositionChanged(int displayId, int imeTop,
+ SurfaceControl.Transaction t) {
+ if (mAnimation != null || !isDividerVisible() || mPaused) {
+ // Not synchronized with IME anymore, so return.
+ return;
+ }
+ final float fraction = ((float) imeTop - mHiddenTop) / (mShownTop - mHiddenTop);
+ final float progress = mTargetShown ? fraction : 1.f - fraction;
+ onProgress(progress, t);
+ }
+
+ @Override
+ public void onImeEndPositioning(int displayId, boolean cancelled,
+ SurfaceControl.Transaction t) {
+ if (mAnimation != null || !isDividerVisible() || mPaused) {
+ // Not synchronized with IME anymore, so return.
+ return;
+ }
+ onEnd(cancelled, t);
+ }
+
+ private void onProgress(float progress, SurfaceControl.Transaction t) {
+ final DividerView view = getView();
+ if (mTargetAdjusted != mAdjusted && !mPaused) {
+ final SplitDisplayLayout splitLayout = getLayout();
+ final float fraction = mTargetAdjusted ? progress : 1.f - progress;
+ mLastAdjustTop = (int) (fraction * mShownTop + (1.f - fraction) * mHiddenTop);
+ splitLayout.updateAdjustedBounds(mLastAdjustTop, mHiddenTop, mShownTop);
+ view.resizeSplitSurfaces(t, splitLayout.mAdjustedPrimary,
+ splitLayout.mAdjustedSecondary);
+ }
+ final float invProg = 1.f - progress;
+ view.setResizeDimLayer(t, true /* primary */,
+ mLastPrimaryDim * invProg + progress * mTargetPrimaryDim);
+ view.setResizeDimLayer(t, false /* primary */,
+ mLastSecondaryDim * invProg + progress * mTargetSecondaryDim);
+ }
+
+ void setDimsHidden(SurfaceControl.Transaction t, boolean hidden) {
+ final DividerView view = getView();
+ if (hidden) {
+ view.setResizeDimLayer(t, true /* primary */, 0.f /* alpha */);
+ view.setResizeDimLayer(t, false /* primary */, 0.f /* alpha */);
+ } else {
+ updateDimTargets();
+ view.setResizeDimLayer(t, true /* primary */, mTargetPrimaryDim);
+ view.setResizeDimLayer(t, false /* primary */, mTargetSecondaryDim);
+ }
+ }
+
+ private void onEnd(boolean cancelled, SurfaceControl.Transaction t) {
+ if (!cancelled) {
+ onProgress(1.f, t);
+ mAdjusted = mTargetAdjusted;
+ mImeWasShown = mTargetShown;
+ mLastAdjustTop = mAdjusted ? mShownTop : mHiddenTop;
+ mLastPrimaryDim = mTargetPrimaryDim;
+ mLastSecondaryDim = mTargetSecondaryDim;
+ }
+ }
+
+ private void startAsyncAnimation() {
+ if (mAnimation != null) {
+ mAnimation.cancel();
+ }
+ mAnimation = ValueAnimator.ofFloat(0.f, 1.f);
+ mAnimation.setDuration(DisplayImeController.ANIMATION_DURATION_SHOW_MS);
+ if (mTargetAdjusted != mAdjusted) {
+ final float fraction =
+ ((float) mLastAdjustTop - mHiddenTop) / (mShownTop - mHiddenTop);
+ final float progress = mTargetAdjusted ? fraction : 1.f - fraction;
+ mAnimation.setCurrentFraction(progress);
+ }
+
+ mAnimation.addUpdateListener(animation -> {
+ SurfaceControl.Transaction t = mTransactionPool.acquire();
+ float value = (float) animation.getAnimatedValue();
+ onProgress(value, t);
+ t.apply();
+ mTransactionPool.release(t);
+ });
+ mAnimation.setInterpolator(DisplayImeController.INTERPOLATOR);
+ mAnimation.addListener(new AnimatorListenerAdapter() {
+ private boolean mCancel = false;
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ mCancel = true;
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ SurfaceControl.Transaction t = mTransactionPool.acquire();
+ onEnd(mCancel, t);
+ t.apply();
+ mTransactionPool.release(t);
+ mAnimation = null;
+ }
+ });
+ mAnimation.start();
+ }
+
+ private String dumpState() {
+ return "top:" + mHiddenTop + "->" + mShownTop
+ + " adj:" + mAdjusted + "->" + mTargetAdjusted + "(" + mLastAdjustTop + ")"
+ + " shw:" + mImeWasShown + "->" + mTargetShown
+ + " dims:" + mLastPrimaryDim + "," + mLastSecondaryDim
+ + "->" + mTargetPrimaryDim + "," + mTargetSecondaryDim
+ + " shf:" + mSecondaryHasFocus + " desync:" + (mAnimation != null)
+ + " paus:" + mPaused + "[" + mPausedTargetAdjusted + "]";
+ }
+
+ /** Completely aborts/resets adjustment state */
+ public void pause(int displayId) {
+ if (DEBUG) Slog.d(TAG, "ime pause posting " + dumpState());
+ mHandler.post(() -> {
+ if (DEBUG) Slog.d(TAG, "ime pause run posted " + dumpState());
+ if (mPaused) {
+ return;
+ }
+ mPaused = true;
+ mPausedTargetAdjusted = mTargetAdjusted;
+ mTargetAdjusted = false;
+ mTargetPrimaryDim = mTargetSecondaryDim = 0.f;
+ updateImeAdjustState();
+ startAsyncAnimation();
+ if (mAnimation != null) {
+ mAnimation.end();
+ }
+ });
+ }
+
+ public void resume(int displayId) {
+ if (DEBUG) Slog.d(TAG, "ime resume posting " + dumpState());
+ mHandler.post(() -> {
+ if (DEBUG) Slog.d(TAG, "ime resume run posted " + dumpState());
+ if (!mPaused) {
+ return;
+ }
+ mPaused = false;
+ mTargetAdjusted = mPausedTargetAdjusted;
+ updateDimTargets();
+ final DividerView view = getView();
+ if ((mTargetAdjusted != mAdjusted) && !mSplits.mSplitScreenController.isMinimized()
+ && view != null) {
+ // End unminimize animations since they conflict with adjustment animations.
+ view.finishAnimations();
+ }
+ updateImeAdjustState();
+ startAsyncAnimation();
+ });
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/src/com/android/wm/shell/tests/WindowManagerShellTest.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerState.java
index 376875b143a1..23d86a00d4bf 100644
--- a/libs/WindowManager/Shell/tests/src/com/android/wm/shell/tests/WindowManagerShellTest.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerState.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,27 +14,12 @@
* limitations under the License.
*/
-package com.android.wm.shell.tests;
-
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.filters.SmallTest;
-
-import com.android.wm.shell.WindowManagerShell;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
+package com.android.wm.shell.splitscreen;
/**
- * Tests for the shell.
+ * Class to hold state of divider that needs to persist across configuration changes.
*/
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class WindowManagerShellTest {
-
- WindowManagerShell mShell;
-
- @Test
- public void testNothing() {
- // Do nothing
- }
+final class DividerState {
+ public boolean animateAfterRecentsDrawn;
+ public float mRatioPositionBeforeMinimized;
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerView.java
new file mode 100644
index 000000000000..00146e9447bd
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerView.java
@@ -0,0 +1,1374 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import static android.view.PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW;
+import static android.view.PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW;
+import static android.view.WindowManager.DOCKED_RIGHT;
+
+import android.animation.AnimationHandler;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ValueAnimator;
+import android.annotation.Nullable;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.graphics.Matrix;
+import android.graphics.Rect;
+import android.graphics.Region;
+import android.graphics.Region.Op;
+import android.hardware.display.DisplayManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.RemoteException;
+import android.util.AttributeSet;
+import android.util.Slog;
+import android.view.Display;
+import android.view.MotionEvent;
+import android.view.PointerIcon;
+import android.view.SurfaceControl;
+import android.view.SurfaceControl.Transaction;
+import android.view.VelocityTracker;
+import android.view.View;
+import android.view.View.OnTouchListener;
+import android.view.ViewConfiguration;
+import android.view.ViewRootImpl;
+import android.view.ViewTreeObserver.InternalInsetsInfo;
+import android.view.ViewTreeObserver.OnComputeInternalInsetsListener;
+import android.view.WindowManager;
+import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
+import android.view.animation.Interpolator;
+import android.view.animation.PathInterpolator;
+import android.widget.FrameLayout;
+
+import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
+import com.android.internal.logging.MetricsLogger;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.policy.DividerSnapAlgorithm;
+import com.android.internal.policy.DividerSnapAlgorithm.SnapTarget;
+import com.android.internal.policy.DockedDividerUtils;
+import com.android.wm.shell.R;
+import com.android.wm.shell.animation.FlingAnimationUtils;
+import com.android.wm.shell.animation.Interpolators;
+
+import java.util.function.Consumer;
+
+/**
+ * Docked stack divider.
+ */
+public class DividerView extends FrameLayout implements OnTouchListener,
+ OnComputeInternalInsetsListener {
+ private static final String TAG = "DividerView";
+ private static final boolean DEBUG = SplitScreenController.DEBUG;
+
+ interface DividerCallbacks {
+ void onDraggingStart();
+ void onDraggingEnd();
+ }
+
+ static final long TOUCH_ANIMATION_DURATION = 150;
+ static final long TOUCH_RELEASE_ANIMATION_DURATION = 200;
+
+ public static final int INVALID_RECENTS_GROW_TARGET = -1;
+
+ private static final int LOG_VALUE_RESIZE_50_50 = 0;
+ private static final int LOG_VALUE_RESIZE_DOCKED_SMALLER = 1;
+ private static final int LOG_VALUE_RESIZE_DOCKED_LARGER = 2;
+
+ private static final int LOG_VALUE_UNDOCK_MAX_DOCKED = 0;
+ private static final int LOG_VALUE_UNDOCK_MAX_OTHER = 1;
+
+ private static final int TASK_POSITION_SAME = Integer.MAX_VALUE;
+
+ /**
+ * How much the background gets scaled when we are in the minimized dock state.
+ */
+ private static final float MINIMIZE_DOCK_SCALE = 0f;
+ private static final float ADJUSTED_FOR_IME_SCALE = 0.5f;
+
+ private static final PathInterpolator SLOWDOWN_INTERPOLATOR =
+ new PathInterpolator(0.5f, 1f, 0.5f, 1f);
+ private static final PathInterpolator DIM_INTERPOLATOR =
+ new PathInterpolator(.23f, .87f, .52f, -0.11f);
+ private static final Interpolator IME_ADJUST_INTERPOLATOR =
+ new PathInterpolator(0.2f, 0f, 0.1f, 1f);
+
+ private DividerHandleView mHandle;
+ private View mBackground;
+ private MinimizedDockShadow mMinimizedShadow;
+ private int mStartX;
+ private int mStartY;
+ private int mStartPosition;
+ private int mDockSide;
+ private boolean mMoving;
+ private int mTouchSlop;
+ private boolean mBackgroundLifted;
+ private boolean mIsInMinimizeInteraction;
+ SnapTarget mSnapTargetBeforeMinimized;
+
+ private int mDividerInsets;
+ private final Display mDefaultDisplay;
+
+ private int mDividerSize;
+ private int mTouchElevation;
+ private int mLongPressEntraceAnimDuration;
+
+ private final Rect mDockedRect = new Rect();
+ private final Rect mDockedTaskRect = new Rect();
+ private final Rect mOtherTaskRect = new Rect();
+ private final Rect mOtherRect = new Rect();
+ private final Rect mDockedInsetRect = new Rect();
+ private final Rect mOtherInsetRect = new Rect();
+ private final Rect mLastResizeRect = new Rect();
+ private final Rect mTmpRect = new Rect();
+ private SplitScreenController mSplitScreenController;
+ private WindowManagerProxy mWindowManagerProxy;
+ private DividerWindowManager mWindowManager;
+ private VelocityTracker mVelocityTracker;
+ private FlingAnimationUtils mFlingAnimationUtils;
+ private SplitDisplayLayout mSplitLayout;
+ private DividerImeController mImeController;
+ private DividerCallbacks mCallback;
+ private final AnimationHandler mAnimationHandler = new AnimationHandler();
+
+ private ValueAnimator mCurrentAnimator;
+ private boolean mEntranceAnimationRunning;
+ private boolean mExitAnimationRunning;
+ private int mExitStartPosition;
+ private boolean mDockedStackMinimized;
+ private boolean mHomeStackResizable;
+ private boolean mAdjustedForIme;
+ private DividerState mState;
+
+ private SplitScreenTaskOrganizer mTiles;
+ boolean mFirstLayout = true;
+ int mDividerPositionX;
+ int mDividerPositionY;
+
+ private final Matrix mTmpMatrix = new Matrix();
+ private final float[] mTmpValues = new float[9];
+
+ // The view is removed or in the process of been removed from the system.
+ private boolean mRemoved;
+
+ // Whether the surface for this view has been hidden regardless of actual visibility. This is
+ // used interact with keyguard.
+ private boolean mSurfaceHidden = false;
+
+ private final Handler mHandler = new Handler();
+
+ private final AccessibilityDelegate mHandleDelegate = new AccessibilityDelegate() {
+ @Override
+ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfo(host, info);
+ final DividerSnapAlgorithm snapAlgorithm = getSnapAlgorithm();
+ if (isHorizontalDivision()) {
+ info.addAction(new AccessibilityAction(R.id.action_move_tl_full,
+ mContext.getString(R.string.accessibility_action_divider_top_full)));
+ if (snapAlgorithm.isFirstSplitTargetAvailable()) {
+ info.addAction(new AccessibilityAction(R.id.action_move_tl_70,
+ mContext.getString(R.string.accessibility_action_divider_top_70)));
+ }
+ if (snapAlgorithm.showMiddleSplitTargetForAccessibility()) {
+ // Only show the middle target if there are more than 1 split target
+ info.addAction(new AccessibilityAction(R.id.action_move_tl_50,
+ mContext.getString(R.string.accessibility_action_divider_top_50)));
+ }
+ if (snapAlgorithm.isLastSplitTargetAvailable()) {
+ info.addAction(new AccessibilityAction(R.id.action_move_tl_30,
+ mContext.getString(R.string.accessibility_action_divider_top_30)));
+ }
+ info.addAction(new AccessibilityAction(R.id.action_move_rb_full,
+ mContext.getString(R.string.accessibility_action_divider_bottom_full)));
+ } else {
+ info.addAction(new AccessibilityAction(R.id.action_move_tl_full,
+ mContext.getString(R.string.accessibility_action_divider_left_full)));
+ if (snapAlgorithm.isFirstSplitTargetAvailable()) {
+ info.addAction(new AccessibilityAction(R.id.action_move_tl_70,
+ mContext.getString(R.string.accessibility_action_divider_left_70)));
+ }
+ if (snapAlgorithm.showMiddleSplitTargetForAccessibility()) {
+ // Only show the middle target if there are more than 1 split target
+ info.addAction(new AccessibilityAction(R.id.action_move_tl_50,
+ mContext.getString(R.string.accessibility_action_divider_left_50)));
+ }
+ if (snapAlgorithm.isLastSplitTargetAvailable()) {
+ info.addAction(new AccessibilityAction(R.id.action_move_tl_30,
+ mContext.getString(R.string.accessibility_action_divider_left_30)));
+ }
+ info.addAction(new AccessibilityAction(R.id.action_move_rb_full,
+ mContext.getString(R.string.accessibility_action_divider_right_full)));
+ }
+ }
+
+ @Override
+ public boolean performAccessibilityAction(View host, int action, Bundle args) {
+ int currentPosition = getCurrentPosition();
+ SnapTarget nextTarget = null;
+ DividerSnapAlgorithm snapAlgorithm = mSplitLayout.getSnapAlgorithm();
+ if (action == R.id.action_move_tl_full) {
+ nextTarget = snapAlgorithm.getDismissEndTarget();
+ } else if (action == R.id.action_move_tl_70) {
+ nextTarget = snapAlgorithm.getLastSplitTarget();
+ } else if (action == R.id.action_move_tl_50) {
+ nextTarget = snapAlgorithm.getMiddleTarget();
+ } else if (action == R.id.action_move_tl_30) {
+ nextTarget = snapAlgorithm.getFirstSplitTarget();
+ } else if (action == R.id.action_move_rb_full) {
+ nextTarget = snapAlgorithm.getDismissStartTarget();
+ }
+ if (nextTarget != null) {
+ startDragging(true /* animate */, false /* touching */);
+ stopDragging(currentPosition, nextTarget, 250, Interpolators.FAST_OUT_SLOW_IN);
+ return true;
+ }
+ return super.performAccessibilityAction(host, action, args);
+ }
+ };
+
+ private final Runnable mResetBackgroundRunnable = new Runnable() {
+ @Override
+ public void run() {
+ resetBackground();
+ }
+ };
+
+ private Runnable mUpdateEmbeddedMatrix = () -> {
+ if (getViewRootImpl() == null) {
+ return;
+ }
+ if (isHorizontalDivision()) {
+ mTmpMatrix.setTranslate(0, mDividerPositionY - mDividerInsets);
+ } else {
+ mTmpMatrix.setTranslate(mDividerPositionX - mDividerInsets, 0);
+ }
+ mTmpMatrix.getValues(mTmpValues);
+ try {
+ getViewRootImpl().getAccessibilityEmbeddedConnection().setScreenMatrix(mTmpValues);
+ } catch (RemoteException e) {
+ }
+ };
+
+ public DividerView(Context context) {
+ this(context, null);
+ }
+
+ public DividerView(Context context, @Nullable AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public DividerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public DividerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ final DisplayManager displayManager =
+ (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
+ mDefaultDisplay = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
+ mAnimationHandler.setProvider(new SfVsyncFrameCallbackProvider());
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ mHandle = findViewById(R.id.docked_divider_handle);
+ mBackground = findViewById(R.id.docked_divider_background);
+ mMinimizedShadow = findViewById(R.id.minimized_dock_shadow);
+ mHandle.setOnTouchListener(this);
+ final int dividerWindowWidth = getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.docked_stack_divider_thickness);
+ mDividerInsets = getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.docked_stack_divider_insets);
+ mDividerSize = dividerWindowWidth - 2 * mDividerInsets;
+ mTouchElevation = getResources().getDimensionPixelSize(
+ R.dimen.docked_stack_divider_lift_elevation);
+ mLongPressEntraceAnimDuration = getResources().getInteger(
+ R.integer.long_press_dock_anim_duration);
+ mTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
+ mFlingAnimationUtils = new FlingAnimationUtils(getResources().getDisplayMetrics(), 0.3f);
+ boolean landscape = getResources().getConfiguration().orientation
+ == Configuration.ORIENTATION_LANDSCAPE;
+ mHandle.setPointerIcon(PointerIcon.getSystemIcon(getContext(),
+ landscape ? TYPE_HORIZONTAL_DOUBLE_ARROW : TYPE_VERTICAL_DOUBLE_ARROW));
+ getViewTreeObserver().addOnComputeInternalInsetsListener(this);
+ mHandle.setAccessibilityDelegate(mHandleDelegate);
+ }
+
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+
+ // Save the current target if not minimized once attached to window
+ if (mDockSide != WindowManager.DOCKED_INVALID && !mIsInMinimizeInteraction) {
+ saveSnapTargetBeforeMinimized(mSnapTargetBeforeMinimized);
+ }
+ mFirstLayout = true;
+ }
+
+ void onDividerRemoved() {
+ mRemoved = true;
+ mCallback = null;
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+ if (mFirstLayout) {
+ // Wait for first layout so that the ViewRootImpl surface has been created.
+ initializeSurfaceState();
+ mFirstLayout = false;
+ }
+ int minimizeLeft = 0;
+ int minimizeTop = 0;
+ if (mDockSide == WindowManager.DOCKED_TOP) {
+ minimizeTop = mBackground.getTop();
+ } else if (mDockSide == WindowManager.DOCKED_LEFT) {
+ minimizeLeft = mBackground.getLeft();
+ } else if (mDockSide == WindowManager.DOCKED_RIGHT) {
+ minimizeLeft = mBackground.getRight() - mMinimizedShadow.getWidth();
+ }
+ mMinimizedShadow.layout(minimizeLeft, minimizeTop,
+ minimizeLeft + mMinimizedShadow.getMeasuredWidth(),
+ minimizeTop + mMinimizedShadow.getMeasuredHeight());
+ if (changed) {
+ notifySplitScreenBoundsChanged();
+ }
+ }
+
+ void injectDependencies(SplitScreenController splitScreenController,
+ DividerWindowManager windowManager, DividerState dividerState,
+ DividerCallbacks callback, SplitScreenTaskOrganizer tiles, SplitDisplayLayout sdl,
+ DividerImeController imeController, WindowManagerProxy wmProxy) {
+ mSplitScreenController = splitScreenController;
+ mWindowManager = windowManager;
+ mState = dividerState;
+ mCallback = callback;
+ mTiles = tiles;
+ mSplitLayout = sdl;
+ mImeController = imeController;
+ mWindowManagerProxy = wmProxy;
+
+ if (mState.mRatioPositionBeforeMinimized == 0) {
+ // Set the middle target as the initial state
+ mSnapTargetBeforeMinimized = mSplitLayout.getSnapAlgorithm().getMiddleTarget();
+ } else {
+ repositionSnapTargetBeforeMinimized();
+ }
+ }
+
+ /** Gets non-minimized secondary bounds of split screen. */
+ public Rect getNonMinimizedSplitScreenSecondaryBounds() {
+ mOtherTaskRect.set(mSplitLayout.mSecondary);
+ return mOtherTaskRect;
+ }
+
+ private boolean inSplitMode() {
+ return getVisibility() == VISIBLE;
+ }
+
+ /** Unlike setVisible, this directly hides the surface without changing view visibility. */
+ void setHidden(boolean hidden) {
+ if (mSurfaceHidden == hidden) {
+ return;
+ }
+ mSurfaceHidden = hidden;
+ post(() -> {
+ final SurfaceControl sc = getWindowSurfaceControl();
+ if (sc == null) {
+ return;
+ }
+ Transaction t = mTiles.getTransaction();
+ if (hidden) {
+ t.hide(sc);
+ } else {
+ t.show(sc);
+ }
+ mImeController.setDimsHidden(t, hidden);
+ t.apply();
+ mTiles.releaseTransaction(t);
+ });
+ }
+
+ boolean isHidden() {
+ return mSurfaceHidden;
+ }
+
+ /** Starts dragging the divider bar. */
+ public boolean startDragging(boolean animate, boolean touching) {
+ cancelFlingAnimation();
+ if (touching) {
+ mHandle.setTouching(true, animate);
+ }
+ mDockSide = mSplitLayout.getPrimarySplitSide();
+
+ mWindowManagerProxy.setResizing(true);
+ if (touching) {
+ mWindowManager.setSlippery(false);
+ liftBackground();
+ }
+ if (mCallback != null) {
+ mCallback.onDraggingStart();
+ }
+ return inSplitMode();
+ }
+
+ /** Stops dragging the divider bar. */
+ public void stopDragging(int position, float velocity, boolean avoidDismissStart,
+ boolean logMetrics) {
+ mHandle.setTouching(false, true /* animate */);
+ fling(position, velocity, avoidDismissStart, logMetrics);
+ mWindowManager.setSlippery(true);
+ releaseBackground();
+ }
+
+ private void stopDragging(int position, SnapTarget target, long duration,
+ Interpolator interpolator) {
+ stopDragging(position, target, duration, 0 /* startDelay*/, 0 /* endDelay */, interpolator);
+ }
+
+ private void stopDragging(int position, SnapTarget target, long duration,
+ Interpolator interpolator, long endDelay) {
+ stopDragging(position, target, duration, 0 /* startDelay*/, endDelay, interpolator);
+ }
+
+ private void stopDragging(int position, SnapTarget target, long duration, long startDelay,
+ long endDelay, Interpolator interpolator) {
+ mHandle.setTouching(false, true /* animate */);
+ flingTo(position, target, duration, startDelay, endDelay, interpolator);
+ mWindowManager.setSlippery(true);
+ releaseBackground();
+ }
+
+ private void stopDragging() {
+ mHandle.setTouching(false, true /* animate */);
+ mWindowManager.setSlippery(true);
+ releaseBackground();
+ }
+
+ private void updateDockSide() {
+ mDockSide = mSplitLayout.getPrimarySplitSide();
+ mMinimizedShadow.setDockSide(mDockSide);
+ }
+
+ public DividerSnapAlgorithm getSnapAlgorithm() {
+ return mDockedStackMinimized ? mSplitLayout.getMinimizedSnapAlgorithm(mHomeStackResizable)
+ : mSplitLayout.getSnapAlgorithm();
+ }
+
+ public int getCurrentPosition() {
+ return isHorizontalDivision() ? mDividerPositionY : mDividerPositionX;
+ }
+
+ public boolean isMinimized() {
+ return mDockedStackMinimized;
+ }
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ convertToScreenCoordinates(event);
+ final int action = event.getAction() & MotionEvent.ACTION_MASK;
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ mVelocityTracker = VelocityTracker.obtain();
+ mVelocityTracker.addMovement(event);
+ mStartX = (int) event.getX();
+ mStartY = (int) event.getY();
+ boolean result = startDragging(true /* animate */, true /* touching */);
+ if (!result) {
+
+ // Weren't able to start dragging successfully, so cancel it again.
+ stopDragging();
+ }
+ mStartPosition = getCurrentPosition();
+ mMoving = false;
+ return result;
+ case MotionEvent.ACTION_MOVE:
+ mVelocityTracker.addMovement(event);
+ int x = (int) event.getX();
+ int y = (int) event.getY();
+ boolean exceededTouchSlop =
+ isHorizontalDivision() && Math.abs(y - mStartY) > mTouchSlop
+ || (!isHorizontalDivision() && Math.abs(x - mStartX) > mTouchSlop);
+ if (!mMoving && exceededTouchSlop) {
+ mStartX = x;
+ mStartY = y;
+ mMoving = true;
+ }
+ if (mMoving && mDockSide != WindowManager.DOCKED_INVALID) {
+ SnapTarget snapTarget = getSnapAlgorithm().calculateSnapTarget(
+ mStartPosition, 0 /* velocity */, false /* hardDismiss */);
+ resizeStackSurfaces(calculatePosition(x, y), mStartPosition, snapTarget,
+ null /* transaction */);
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ mVelocityTracker.addMovement(event);
+
+ x = (int) event.getRawX();
+ y = (int) event.getRawY();
+
+ mVelocityTracker.computeCurrentVelocity(1000);
+ int position = calculatePosition(x, y);
+ stopDragging(position, isHorizontalDivision() ? mVelocityTracker.getYVelocity()
+ : mVelocityTracker.getXVelocity(), false /* avoidDismissStart */,
+ true /* log */);
+ mMoving = false;
+ break;
+ }
+ return true;
+ }
+
+ private void logResizeEvent(SnapTarget snapTarget) {
+ if (snapTarget == mSplitLayout.getSnapAlgorithm().getDismissStartTarget()) {
+ MetricsLogger.action(
+ mContext, MetricsEvent.ACTION_WINDOW_UNDOCK_MAX, dockSideTopLeft(mDockSide)
+ ? LOG_VALUE_UNDOCK_MAX_OTHER
+ : LOG_VALUE_UNDOCK_MAX_DOCKED);
+ } else if (snapTarget == mSplitLayout.getSnapAlgorithm().getDismissEndTarget()) {
+ MetricsLogger.action(
+ mContext, MetricsEvent.ACTION_WINDOW_UNDOCK_MAX, dockSideBottomRight(mDockSide)
+ ? LOG_VALUE_UNDOCK_MAX_OTHER
+ : LOG_VALUE_UNDOCK_MAX_DOCKED);
+ } else if (snapTarget == mSplitLayout.getSnapAlgorithm().getMiddleTarget()) {
+ MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_RESIZE,
+ LOG_VALUE_RESIZE_50_50);
+ } else if (snapTarget == mSplitLayout.getSnapAlgorithm().getFirstSplitTarget()) {
+ MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_RESIZE,
+ dockSideTopLeft(mDockSide)
+ ? LOG_VALUE_RESIZE_DOCKED_SMALLER
+ : LOG_VALUE_RESIZE_DOCKED_LARGER);
+ } else if (snapTarget == mSplitLayout.getSnapAlgorithm().getLastSplitTarget()) {
+ MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_RESIZE,
+ dockSideTopLeft(mDockSide)
+ ? LOG_VALUE_RESIZE_DOCKED_LARGER
+ : LOG_VALUE_RESIZE_DOCKED_SMALLER);
+ }
+ }
+
+ private void convertToScreenCoordinates(MotionEvent event) {
+ event.setLocation(event.getRawX(), event.getRawY());
+ }
+
+ private void fling(int position, float velocity, boolean avoidDismissStart,
+ boolean logMetrics) {
+ DividerSnapAlgorithm currentSnapAlgorithm = getSnapAlgorithm();
+ SnapTarget snapTarget = currentSnapAlgorithm.calculateSnapTarget(position, velocity);
+ if (avoidDismissStart && snapTarget == currentSnapAlgorithm.getDismissStartTarget()) {
+ snapTarget = currentSnapAlgorithm.getFirstSplitTarget();
+ }
+ if (logMetrics) {
+ logResizeEvent(snapTarget);
+ }
+ ValueAnimator anim = getFlingAnimator(position, snapTarget, 0 /* endDelay */);
+ mFlingAnimationUtils.apply(anim, position, snapTarget.position, velocity);
+ anim.start();
+ }
+
+ private void flingTo(int position, SnapTarget target, long duration, long startDelay,
+ long endDelay, Interpolator interpolator) {
+ ValueAnimator anim = getFlingAnimator(position, target, endDelay);
+ anim.setDuration(duration);
+ anim.setStartDelay(startDelay);
+ anim.setInterpolator(interpolator);
+ anim.start();
+ }
+
+ private ValueAnimator getFlingAnimator(int position, final SnapTarget snapTarget,
+ final long endDelay) {
+ if (mCurrentAnimator != null) {
+ cancelFlingAnimation();
+ updateDockSide();
+ }
+ if (DEBUG) Slog.d(TAG, "Getting fling " + position + "->" + snapTarget.position);
+ final boolean taskPositionSameAtEnd = snapTarget.flag == SnapTarget.FLAG_NONE;
+ ValueAnimator anim = ValueAnimator.ofInt(position, snapTarget.position);
+ anim.addUpdateListener(animation -> resizeStackSurfaces((int) animation.getAnimatedValue(),
+ taskPositionSameAtEnd && animation.getAnimatedFraction() == 1f
+ ? TASK_POSITION_SAME
+ : snapTarget.taskPosition,
+ snapTarget, null /* transaction */));
+ Consumer<Boolean> endAction = cancelled -> {
+ if (DEBUG) Slog.d(TAG, "End Fling " + cancelled + " min:" + mIsInMinimizeInteraction);
+ final boolean wasMinimizeInteraction = mIsInMinimizeInteraction;
+ // Reset minimized divider position after unminimized state animation finishes.
+ if (!cancelled && !mDockedStackMinimized && mIsInMinimizeInteraction) {
+ mIsInMinimizeInteraction = false;
+ }
+ boolean dismissed = commitSnapFlags(snapTarget);
+ mWindowManagerProxy.setResizing(false);
+ updateDockSide();
+ mCurrentAnimator = null;
+ mEntranceAnimationRunning = false;
+ mExitAnimationRunning = false;
+ if (!dismissed && !wasMinimizeInteraction) {
+ mWindowManagerProxy.applyResizeSplits(snapTarget.position, mSplitLayout);
+ }
+ if (mCallback != null) {
+ mCallback.onDraggingEnd();
+ }
+
+ // Record last snap target the divider moved to
+ if (!mIsInMinimizeInteraction) {
+ // The last snapTarget position can be negative when the last divider position was
+ // offscreen. In that case, save the middle (default) SnapTarget so calculating next
+ // position isn't negative.
+ final SnapTarget saveTarget;
+ if (snapTarget.position < 0) {
+ saveTarget = mSplitLayout.getSnapAlgorithm().getMiddleTarget();
+ } else {
+ saveTarget = snapTarget;
+ }
+ final DividerSnapAlgorithm snapAlgo = mSplitLayout.getSnapAlgorithm();
+ if (saveTarget.position != snapAlgo.getDismissEndTarget().position
+ && saveTarget.position != snapAlgo.getDismissStartTarget().position) {
+ saveSnapTargetBeforeMinimized(saveTarget);
+ }
+ }
+ notifySplitScreenBoundsChanged();
+ };
+ anim.addListener(new AnimatorListenerAdapter() {
+
+ private boolean mCancelled;
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ mCancelled = true;
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ long delay = 0;
+ if (endDelay != 0) {
+ delay = endDelay;
+ } else if (mCancelled) {
+ delay = 0;
+ }
+ if (delay == 0) {
+ endAction.accept(mCancelled);
+ } else {
+ final Boolean cancelled = mCancelled;
+ if (DEBUG) Slog.d(TAG, "Posting endFling " + cancelled + " d:" + delay + "ms");
+ mHandler.postDelayed(() -> endAction.accept(cancelled), delay);
+ }
+ }
+ });
+ anim.setAnimationHandler(mAnimationHandler);
+ mCurrentAnimator = anim;
+ return anim;
+ }
+
+ private void notifySplitScreenBoundsChanged() {
+ if (mSplitLayout.mPrimary == null || mSplitLayout.mSecondary == null) {
+ return;
+ }
+ mOtherTaskRect.set(mSplitLayout.mSecondary);
+
+ mTmpRect.set(mHandle.getLeft(), mHandle.getTop(), mHandle.getRight(), mHandle.getBottom());
+ if (isHorizontalDivision()) {
+ mTmpRect.offsetTo(0, mDividerPositionY);
+ } else {
+ mTmpRect.offsetTo(mDividerPositionX, 0);
+ }
+ mWindowManagerProxy.setTouchRegion(mTmpRect);
+
+ mTmpRect.set(mSplitLayout.mDisplayLayout.stableInsets());
+ switch (mSplitLayout.getPrimarySplitSide()) {
+ case WindowManager.DOCKED_LEFT:
+ mTmpRect.left = 0;
+ break;
+ case WindowManager.DOCKED_RIGHT:
+ mTmpRect.right = 0;
+ break;
+ case WindowManager.DOCKED_TOP:
+ mTmpRect.top = 0;
+ break;
+ }
+ mSplitScreenController.notifyBoundsChanged(mOtherTaskRect, mTmpRect);
+ }
+
+ private void cancelFlingAnimation() {
+ if (mCurrentAnimator != null) {
+ mCurrentAnimator.cancel();
+ }
+ }
+
+ private boolean commitSnapFlags(SnapTarget target) {
+ if (target.flag == SnapTarget.FLAG_NONE) {
+ return false;
+ }
+ final boolean dismissOrMaximize;
+ if (target.flag == SnapTarget.FLAG_DISMISS_START) {
+ dismissOrMaximize = mDockSide == WindowManager.DOCKED_LEFT
+ || mDockSide == WindowManager.DOCKED_TOP;
+ } else {
+ dismissOrMaximize = mDockSide == WindowManager.DOCKED_RIGHT
+ || mDockSide == WindowManager.DOCKED_BOTTOM;
+ }
+ mWindowManagerProxy.dismissOrMaximizeDocked(mTiles, mSplitLayout, dismissOrMaximize);
+ Transaction t = mTiles.getTransaction();
+ setResizeDimLayer(t, true /* primary */, 0f);
+ setResizeDimLayer(t, false /* primary */, 0f);
+ t.apply();
+ mTiles.releaseTransaction(t);
+ return true;
+ }
+
+ private void liftBackground() {
+ if (mBackgroundLifted) {
+ return;
+ }
+ if (isHorizontalDivision()) {
+ mBackground.animate().scaleY(1.4f);
+ } else {
+ mBackground.animate().scaleX(1.4f);
+ }
+ mBackground.animate()
+ .setInterpolator(Interpolators.TOUCH_RESPONSE)
+ .setDuration(TOUCH_ANIMATION_DURATION)
+ .translationZ(mTouchElevation)
+ .start();
+
+ // Lift handle as well so it doesn't get behind the background, even though it doesn't
+ // cast shadow.
+ mHandle.animate()
+ .setInterpolator(Interpolators.TOUCH_RESPONSE)
+ .setDuration(TOUCH_ANIMATION_DURATION)
+ .translationZ(mTouchElevation)
+ .start();
+ mBackgroundLifted = true;
+ }
+
+ private void releaseBackground() {
+ if (!mBackgroundLifted) {
+ return;
+ }
+ mBackground.animate()
+ .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
+ .setDuration(TOUCH_RELEASE_ANIMATION_DURATION)
+ .translationZ(0)
+ .scaleX(1f)
+ .scaleY(1f)
+ .start();
+ mHandle.animate()
+ .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
+ .setDuration(TOUCH_RELEASE_ANIMATION_DURATION)
+ .translationZ(0)
+ .start();
+ mBackgroundLifted = false;
+ }
+
+ private void initializeSurfaceState() {
+ int midPos = mSplitLayout.getSnapAlgorithm().getMiddleTarget().position;
+ // Recalculate the split-layout's internal tile bounds
+ mSplitLayout.resizeSplits(midPos);
+ Transaction t = mTiles.getTransaction();
+ if (mDockedStackMinimized) {
+ int position = mSplitLayout.getMinimizedSnapAlgorithm(mHomeStackResizable)
+ .getMiddleTarget().position;
+ calculateBoundsForPosition(position, mDockSide, mDockedRect);
+ calculateBoundsForPosition(position, DockedDividerUtils.invertDockSide(mDockSide),
+ mOtherRect);
+ mDividerPositionX = mDividerPositionY = position;
+ resizeSplitSurfaces(t, mDockedRect, mSplitLayout.mPrimary,
+ mOtherRect, mSplitLayout.mSecondary);
+ } else {
+ resizeSplitSurfaces(t, mSplitLayout.mPrimary, null,
+ mSplitLayout.mSecondary, null);
+ }
+ setResizeDimLayer(t, true /* primary */, 0.f /* alpha */);
+ setResizeDimLayer(t, false /* secondary */, 0.f /* alpha */);
+ t.apply();
+ mTiles.releaseTransaction(t);
+
+ // Get the actually-visible bar dimensions (relative to full window). This is a thin
+ // bar going through the center.
+ final Rect dividerBar = isHorizontalDivision()
+ ? new Rect(0, mDividerInsets, mSplitLayout.mDisplayLayout.width(),
+ mDividerInsets + mDividerSize)
+ : new Rect(mDividerInsets, 0, mDividerInsets + mDividerSize,
+ mSplitLayout.mDisplayLayout.height());
+ final Region touchRegion = new Region(dividerBar);
+ // Add in the "draggable" portion. While not visible, this is an expanded area that the
+ // user can interact with.
+ touchRegion.union(new Rect(mHandle.getLeft(), mHandle.getTop(),
+ mHandle.getRight(), mHandle.getBottom()));
+ mWindowManager.setTouchRegion(touchRegion);
+ }
+
+ void setMinimizedDockStack(boolean minimized, boolean isHomeStackResizable,
+ Transaction t) {
+ mHomeStackResizable = isHomeStackResizable;
+ updateDockSide();
+ if (!minimized) {
+ resetBackground();
+ }
+ mMinimizedShadow.setAlpha(minimized ? 1f : 0f);
+ if (mDockedStackMinimized != minimized) {
+ mDockedStackMinimized = minimized;
+ if (mSplitLayout.mDisplayLayout.rotation() != mDefaultDisplay.getRotation()) {
+ // Splitscreen to minimize is about to starts after rotating landscape to seascape,
+ // update display info and snap algorithm targets
+ repositionSnapTargetBeforeMinimized();
+ }
+ if (mIsInMinimizeInteraction != minimized || mCurrentAnimator != null) {
+ cancelFlingAnimation();
+ if (minimized) {
+ // Relayout to recalculate the divider shadow when minimizing
+ requestLayout();
+ mIsInMinimizeInteraction = true;
+ resizeStackSurfaces(mSplitLayout.getMinimizedSnapAlgorithm(mHomeStackResizable)
+ .getMiddleTarget(), t);
+ } else {
+ resizeStackSurfaces(mSnapTargetBeforeMinimized, t);
+ mIsInMinimizeInteraction = false;
+ }
+ }
+ }
+ }
+
+ void enterSplitMode(boolean isHomeStackResizable) {
+ post(() -> {
+ final SurfaceControl sc = getWindowSurfaceControl();
+ if (sc == null) {
+ return;
+ }
+ Transaction t = mTiles.getTransaction();
+ t.show(sc).apply();
+ mTiles.releaseTransaction(t);
+ });
+
+ SnapTarget miniMid =
+ mSplitLayout.getMinimizedSnapAlgorithm(isHomeStackResizable).getMiddleTarget();
+ if (mDockedStackMinimized) {
+ mDividerPositionY = mDividerPositionX = miniMid.position;
+ }
+ }
+
+ /**
+ * Tries to grab a surface control from ViewRootImpl. If this isn't available for some reason
+ * (ie. the window isn't ready yet), it will get the surfacecontrol that the WindowlessWM has
+ * assigned to it.
+ */
+ private SurfaceControl getWindowSurfaceControl() {
+ final ViewRootImpl root = getViewRootImpl();
+ if (root == null) {
+ return null;
+ }
+ SurfaceControl out = root.getSurfaceControl();
+ if (out != null && out.isValid()) {
+ return out;
+ }
+ return mWindowManager.mSystemWindows.getViewSurface(this);
+ }
+
+ void exitSplitMode() {
+ // Reset tile bounds
+ final SurfaceControl sc = getWindowSurfaceControl();
+ if (sc == null) {
+ return;
+ }
+ Transaction t = mTiles.getTransaction();
+ t.hide(sc).apply();
+ mTiles.releaseTransaction(t);
+ int midPos = mSplitLayout.getSnapAlgorithm().getMiddleTarget().position;
+ mWindowManagerProxy.applyResizeSplits(midPos, mSplitLayout);
+ }
+
+ void setMinimizedDockStack(boolean minimized, long animDuration,
+ boolean isHomeStackResizable) {
+ if (DEBUG) Slog.d(TAG, "setMinDock: " + mDockedStackMinimized + "->" + minimized);
+ mHomeStackResizable = isHomeStackResizable;
+ updateDockSide();
+ if (mDockedStackMinimized != minimized) {
+ mIsInMinimizeInteraction = true;
+ mDockedStackMinimized = minimized;
+ stopDragging(minimized
+ ? mSnapTargetBeforeMinimized.position
+ : getCurrentPosition(),
+ minimized
+ ? mSplitLayout.getMinimizedSnapAlgorithm(mHomeStackResizable)
+ .getMiddleTarget()
+ : mSnapTargetBeforeMinimized,
+ animDuration, Interpolators.FAST_OUT_SLOW_IN, 0);
+ setAdjustedForIme(false, animDuration);
+ }
+ if (!minimized) {
+ mBackground.animate().withEndAction(mResetBackgroundRunnable);
+ }
+ mBackground.animate()
+ .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
+ .setDuration(animDuration)
+ .start();
+ }
+
+ // Needed to end any currently playing animations when they might compete with other anims
+ // (specifically, IME adjust animation immediately after leaving minimized). Someday maybe
+ // these can be unified, but not today.
+ void finishAnimations() {
+ if (mCurrentAnimator != null) {
+ mCurrentAnimator.end();
+ }
+ }
+
+ void setAdjustedForIme(boolean adjustedForIme, long animDuration) {
+ if (mAdjustedForIme == adjustedForIme) {
+ return;
+ }
+ updateDockSide();
+ mHandle.animate()
+ .setInterpolator(IME_ADJUST_INTERPOLATOR)
+ .setDuration(animDuration)
+ .alpha(adjustedForIme ? 0f : 1f)
+ .start();
+ if (mDockSide == WindowManager.DOCKED_TOP) {
+ mBackground.setPivotY(0);
+ mBackground.animate()
+ .scaleY(adjustedForIme ? ADJUSTED_FOR_IME_SCALE : 1f);
+ }
+ if (!adjustedForIme) {
+ mBackground.animate().withEndAction(mResetBackgroundRunnable);
+ }
+ mBackground.animate()
+ .setInterpolator(IME_ADJUST_INTERPOLATOR)
+ .setDuration(animDuration)
+ .start();
+ mAdjustedForIme = adjustedForIme;
+ }
+
+ private void saveSnapTargetBeforeMinimized(SnapTarget target) {
+ mSnapTargetBeforeMinimized = target;
+ mState.mRatioPositionBeforeMinimized = (float) target.position
+ / (isHorizontalDivision() ? mSplitLayout.mDisplayLayout.height()
+ : mSplitLayout.mDisplayLayout.width());
+ }
+
+ private void resetBackground() {
+ mBackground.setPivotX(mBackground.getWidth() / 2);
+ mBackground.setPivotY(mBackground.getHeight() / 2);
+ mBackground.setScaleX(1f);
+ mBackground.setScaleY(1f);
+ mMinimizedShadow.setAlpha(0f);
+ }
+
+ @Override
+ protected void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ }
+
+ private void repositionSnapTargetBeforeMinimized() {
+ int position = (int) (mState.mRatioPositionBeforeMinimized
+ * (isHorizontalDivision() ? mSplitLayout.mDisplayLayout.height()
+ : mSplitLayout.mDisplayLayout.width()));
+
+ // Set the snap target before minimized but do not save until divider is attached and not
+ // minimized because it does not know its minimized state yet.
+ mSnapTargetBeforeMinimized =
+ mSplitLayout.getSnapAlgorithm().calculateNonDismissingSnapTarget(position);
+ }
+
+ private int calculatePosition(int touchX, int touchY) {
+ return isHorizontalDivision() ? calculateYPosition(touchY) : calculateXPosition(touchX);
+ }
+
+ public boolean isHorizontalDivision() {
+ return getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
+ }
+
+ private int calculateXPosition(int touchX) {
+ return mStartPosition + touchX - mStartX;
+ }
+
+ private int calculateYPosition(int touchY) {
+ return mStartPosition + touchY - mStartY;
+ }
+
+ private void alignTopLeft(Rect containingRect, Rect rect) {
+ int width = rect.width();
+ int height = rect.height();
+ rect.set(containingRect.left, containingRect.top,
+ containingRect.left + width, containingRect.top + height);
+ }
+
+ private void alignBottomRight(Rect containingRect, Rect rect) {
+ int width = rect.width();
+ int height = rect.height();
+ rect.set(containingRect.right - width, containingRect.bottom - height,
+ containingRect.right, containingRect.bottom);
+ }
+
+ private void calculateBoundsForPosition(int position, int dockSide, Rect outRect) {
+ DockedDividerUtils.calculateBoundsForPosition(position, dockSide, outRect,
+ mSplitLayout.mDisplayLayout.width(), mSplitLayout.mDisplayLayout.height(),
+ mDividerSize);
+ }
+
+ private void resizeStackSurfaces(SnapTarget taskSnapTarget, Transaction t) {
+ resizeStackSurfaces(taskSnapTarget.position, taskSnapTarget.position, taskSnapTarget, t);
+ }
+
+ void resizeSplitSurfaces(Transaction t, Rect dockedRect, Rect otherRect) {
+ resizeSplitSurfaces(t, dockedRect, null, otherRect, null);
+ }
+
+ private void resizeSplitSurfaces(Transaction t, Rect dockedRect, Rect dockedTaskRect,
+ Rect otherRect, Rect otherTaskRect) {
+ dockedTaskRect = dockedTaskRect == null ? dockedRect : dockedTaskRect;
+ otherTaskRect = otherTaskRect == null ? otherRect : otherTaskRect;
+
+ mDividerPositionX = mSplitLayout.getPrimarySplitSide() == DOCKED_RIGHT
+ ? otherRect.right : dockedRect.right;
+ mDividerPositionY = dockedRect.bottom;
+
+ if (DEBUG) {
+ Slog.d(TAG, "Resizing split surfaces: " + dockedRect + " " + dockedTaskRect
+ + " " + otherRect + " " + otherTaskRect);
+ }
+
+ t.setPosition(mTiles.mPrimarySurface, dockedTaskRect.left, dockedTaskRect.top);
+ Rect crop = new Rect(dockedRect);
+ crop.offsetTo(-Math.min(dockedTaskRect.left - dockedRect.left, 0),
+ -Math.min(dockedTaskRect.top - dockedRect.top, 0));
+ t.setWindowCrop(mTiles.mPrimarySurface, crop);
+ t.setPosition(mTiles.mSecondarySurface, otherTaskRect.left, otherTaskRect.top);
+ crop.set(otherRect);
+ crop.offsetTo(-(otherTaskRect.left - otherRect.left),
+ -(otherTaskRect.top - otherRect.top));
+ t.setWindowCrop(mTiles.mSecondarySurface, crop);
+ final SurfaceControl dividerCtrl = getWindowSurfaceControl();
+ if (dividerCtrl != null) {
+ if (isHorizontalDivision()) {
+ t.setPosition(dividerCtrl, 0, mDividerPositionY - mDividerInsets);
+ } else {
+ t.setPosition(dividerCtrl, mDividerPositionX - mDividerInsets, 0);
+ }
+ }
+ if (getViewRootImpl() != null) {
+ mHandler.removeCallbacks(mUpdateEmbeddedMatrix);
+ mHandler.post(mUpdateEmbeddedMatrix);
+ }
+ }
+
+ void setResizeDimLayer(Transaction t, boolean primary, float alpha) {
+ SurfaceControl dim = primary ? mTiles.mPrimaryDim : mTiles.mSecondaryDim;
+ if (alpha <= 0.001f) {
+ t.hide(dim);
+ } else {
+ t.setAlpha(dim, alpha);
+ t.show(dim);
+ }
+ }
+
+ void resizeStackSurfaces(int position, int taskPosition, SnapTarget taskSnapTarget,
+ Transaction transaction) {
+ if (mRemoved) {
+ // This divider view has been removed so shouldn't have any additional influence.
+ return;
+ }
+ calculateBoundsForPosition(position, mDockSide, mDockedRect);
+ calculateBoundsForPosition(position, DockedDividerUtils.invertDockSide(mDockSide),
+ mOtherRect);
+
+ if (mDockedRect.equals(mLastResizeRect) && !mEntranceAnimationRunning) {
+ return;
+ }
+
+ // Make sure shadows are updated
+ if (mBackground.getZ() > 0f) {
+ mBackground.invalidate();
+ }
+
+ final boolean ownTransaction = transaction == null;
+ final Transaction t = ownTransaction ? mTiles.getTransaction() : transaction;
+ mLastResizeRect.set(mDockedRect);
+ if (mIsInMinimizeInteraction) {
+ calculateBoundsForPosition(mSnapTargetBeforeMinimized.position, mDockSide,
+ mDockedTaskRect);
+ calculateBoundsForPosition(mSnapTargetBeforeMinimized.position,
+ DockedDividerUtils.invertDockSide(mDockSide), mOtherTaskRect);
+
+ // Move a right-docked-app to line up with the divider while dragging it
+ if (mDockSide == DOCKED_RIGHT) {
+ mDockedTaskRect.offset(Math.max(position, -mDividerSize)
+ - mDockedTaskRect.left + mDividerSize, 0);
+ }
+ resizeSplitSurfaces(t, mDockedRect, mDockedTaskRect, mOtherRect, mOtherTaskRect);
+ if (ownTransaction) {
+ t.apply();
+ mTiles.releaseTransaction(t);
+ }
+ return;
+ }
+
+ if (mEntranceAnimationRunning && taskPosition != TASK_POSITION_SAME) {
+ calculateBoundsForPosition(taskPosition, mDockSide, mDockedTaskRect);
+
+ // Move a docked app if from the right in position with the divider up to insets
+ if (mDockSide == DOCKED_RIGHT) {
+ mDockedTaskRect.offset(Math.max(position, -mDividerSize)
+ - mDockedTaskRect.left + mDividerSize, 0);
+ }
+ calculateBoundsForPosition(taskPosition, DockedDividerUtils.invertDockSide(mDockSide),
+ mOtherTaskRect);
+ resizeSplitSurfaces(t, mDockedRect, mDockedTaskRect, mOtherRect, mOtherTaskRect);
+ } else if (mExitAnimationRunning && taskPosition != TASK_POSITION_SAME) {
+ calculateBoundsForPosition(taskPosition, mDockSide, mDockedTaskRect);
+ mDockedInsetRect.set(mDockedTaskRect);
+ calculateBoundsForPosition(mExitStartPosition,
+ DockedDividerUtils.invertDockSide(mDockSide), mOtherTaskRect);
+ mOtherInsetRect.set(mOtherTaskRect);
+ applyExitAnimationParallax(mOtherTaskRect, position);
+
+ // Move a right-docked-app to line up with the divider while dragging it
+ if (mDockSide == DOCKED_RIGHT) {
+ mDockedTaskRect.offset(position + mDividerSize, 0);
+ }
+ resizeSplitSurfaces(t, mDockedRect, mDockedTaskRect, mOtherRect, mOtherTaskRect);
+ } else if (taskPosition != TASK_POSITION_SAME) {
+ calculateBoundsForPosition(position, DockedDividerUtils.invertDockSide(mDockSide),
+ mOtherRect);
+ int dockSideInverted = DockedDividerUtils.invertDockSide(mDockSide);
+ int taskPositionDocked =
+ restrictDismissingTaskPosition(taskPosition, mDockSide, taskSnapTarget);
+ int taskPositionOther =
+ restrictDismissingTaskPosition(taskPosition, dockSideInverted, taskSnapTarget);
+ calculateBoundsForPosition(taskPositionDocked, mDockSide, mDockedTaskRect);
+ calculateBoundsForPosition(taskPositionOther, dockSideInverted, mOtherTaskRect);
+ mTmpRect.set(0, 0, mSplitLayout.mDisplayLayout.width(),
+ mSplitLayout.mDisplayLayout.height());
+ alignTopLeft(mDockedRect, mDockedTaskRect);
+ alignTopLeft(mOtherRect, mOtherTaskRect);
+ mDockedInsetRect.set(mDockedTaskRect);
+ mOtherInsetRect.set(mOtherTaskRect);
+ if (dockSideTopLeft(mDockSide)) {
+ alignTopLeft(mTmpRect, mDockedInsetRect);
+ alignBottomRight(mTmpRect, mOtherInsetRect);
+ } else {
+ alignBottomRight(mTmpRect, mDockedInsetRect);
+ alignTopLeft(mTmpRect, mOtherInsetRect);
+ }
+ applyDismissingParallax(mDockedTaskRect, mDockSide, taskSnapTarget, position,
+ taskPositionDocked);
+ applyDismissingParallax(mOtherTaskRect, dockSideInverted, taskSnapTarget, position,
+ taskPositionOther);
+ resizeSplitSurfaces(t, mDockedRect, mDockedTaskRect, mOtherRect, mOtherTaskRect);
+ } else {
+ resizeSplitSurfaces(t, mDockedRect, null, mOtherRect, null);
+ }
+ SnapTarget closestDismissTarget = getSnapAlgorithm().getClosestDismissTarget(position);
+ float dimFraction = getDimFraction(position, closestDismissTarget);
+ setResizeDimLayer(t, isDismissTargetPrimary(closestDismissTarget), dimFraction);
+ if (ownTransaction) {
+ t.apply();
+ mTiles.releaseTransaction(t);
+ }
+ }
+
+ private void applyExitAnimationParallax(Rect taskRect, int position) {
+ if (mDockSide == WindowManager.DOCKED_TOP) {
+ taskRect.offset(0, (int) ((position - mExitStartPosition) * 0.25f));
+ } else if (mDockSide == WindowManager.DOCKED_LEFT) {
+ taskRect.offset((int) ((position - mExitStartPosition) * 0.25f), 0);
+ } else if (mDockSide == WindowManager.DOCKED_RIGHT) {
+ taskRect.offset((int) ((mExitStartPosition - position) * 0.25f), 0);
+ }
+ }
+
+ private float getDimFraction(int position, SnapTarget dismissTarget) {
+ if (mEntranceAnimationRunning) {
+ return 0f;
+ }
+ float fraction = getSnapAlgorithm().calculateDismissingFraction(position);
+ fraction = Math.max(0, Math.min(fraction, 1f));
+ fraction = DIM_INTERPOLATOR.getInterpolation(fraction);
+ return fraction;
+ }
+
+ /**
+ * When the snap target is dismissing one side, make sure that the dismissing side doesn't get
+ * 0 size.
+ */
+ private int restrictDismissingTaskPosition(int taskPosition, int dockSide,
+ SnapTarget snapTarget) {
+ if (snapTarget.flag == SnapTarget.FLAG_DISMISS_START && dockSideTopLeft(dockSide)) {
+ return Math.max(mSplitLayout.getSnapAlgorithm().getFirstSplitTarget().position,
+ mStartPosition);
+ } else if (snapTarget.flag == SnapTarget.FLAG_DISMISS_END
+ && dockSideBottomRight(dockSide)) {
+ return Math.min(mSplitLayout.getSnapAlgorithm().getLastSplitTarget().position,
+ mStartPosition);
+ } else {
+ return taskPosition;
+ }
+ }
+
+ /**
+ * Applies a parallax to the task when dismissing.
+ */
+ private void applyDismissingParallax(Rect taskRect, int dockSide, SnapTarget snapTarget,
+ int position, int taskPosition) {
+ float fraction = Math.min(1, Math.max(0,
+ mSplitLayout.getSnapAlgorithm().calculateDismissingFraction(position)));
+ SnapTarget dismissTarget = null;
+ SnapTarget splitTarget = null;
+ int start = 0;
+ if (position <= mSplitLayout.getSnapAlgorithm().getLastSplitTarget().position
+ && dockSideTopLeft(dockSide)) {
+ dismissTarget = mSplitLayout.getSnapAlgorithm().getDismissStartTarget();
+ splitTarget = mSplitLayout.getSnapAlgorithm().getFirstSplitTarget();
+ start = taskPosition;
+ } else if (position >= mSplitLayout.getSnapAlgorithm().getLastSplitTarget().position
+ && dockSideBottomRight(dockSide)) {
+ dismissTarget = mSplitLayout.getSnapAlgorithm().getDismissEndTarget();
+ splitTarget = mSplitLayout.getSnapAlgorithm().getLastSplitTarget();
+ start = splitTarget.position;
+ }
+ if (dismissTarget != null && fraction > 0f
+ && isDismissing(splitTarget, position, dockSide)) {
+ fraction = calculateParallaxDismissingFraction(fraction, dockSide);
+ int offsetPosition = (int) (start + fraction
+ * (dismissTarget.position - splitTarget.position));
+ int width = taskRect.width();
+ int height = taskRect.height();
+ switch (dockSide) {
+ case WindowManager.DOCKED_LEFT:
+ taskRect.left = offsetPosition - width;
+ taskRect.right = offsetPosition;
+ break;
+ case WindowManager.DOCKED_RIGHT:
+ taskRect.left = offsetPosition + mDividerSize;
+ taskRect.right = offsetPosition + width + mDividerSize;
+ break;
+ case WindowManager.DOCKED_TOP:
+ taskRect.top = offsetPosition - height;
+ taskRect.bottom = offsetPosition;
+ break;
+ case WindowManager.DOCKED_BOTTOM:
+ taskRect.top = offsetPosition + mDividerSize;
+ taskRect.bottom = offsetPosition + height + mDividerSize;
+ break;
+ }
+ }
+ }
+
+ /**
+ * @return for a specified {@code fraction}, this returns an adjusted value that simulates a
+ * slowing down parallax effect
+ */
+ private static float calculateParallaxDismissingFraction(float fraction, int dockSide) {
+ float result = SLOWDOWN_INTERPOLATOR.getInterpolation(fraction) / 3.5f;
+
+ // Less parallax at the top, just because.
+ if (dockSide == WindowManager.DOCKED_TOP) {
+ result /= 2f;
+ }
+ return result;
+ }
+
+ private static boolean isDismissing(SnapTarget snapTarget, int position, int dockSide) {
+ if (dockSide == WindowManager.DOCKED_TOP || dockSide == WindowManager.DOCKED_LEFT) {
+ return position < snapTarget.position;
+ } else {
+ return position > snapTarget.position;
+ }
+ }
+
+ private boolean isDismissTargetPrimary(SnapTarget dismissTarget) {
+ return (dismissTarget.flag == SnapTarget.FLAG_DISMISS_START && dockSideTopLeft(mDockSide))
+ || (dismissTarget.flag == SnapTarget.FLAG_DISMISS_END
+ && dockSideBottomRight(mDockSide));
+ }
+
+ /**
+ * @return true if and only if {@code dockSide} is top or left
+ */
+ private static boolean dockSideTopLeft(int dockSide) {
+ return dockSide == WindowManager.DOCKED_TOP || dockSide == WindowManager.DOCKED_LEFT;
+ }
+
+ /**
+ * @return true if and only if {@code dockSide} is bottom or right
+ */
+ private static boolean dockSideBottomRight(int dockSide) {
+ return dockSide == WindowManager.DOCKED_BOTTOM || dockSide == WindowManager.DOCKED_RIGHT;
+ }
+
+ @Override
+ public void onComputeInternalInsets(InternalInsetsInfo inoutInfo) {
+ inoutInfo.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
+ inoutInfo.touchableRegion.set(mHandle.getLeft(), mHandle.getTop(), mHandle.getRight(),
+ mHandle.getBottom());
+ inoutInfo.touchableRegion.op(mBackground.getLeft(), mBackground.getTop(),
+ mBackground.getRight(), mBackground.getBottom(), Op.UNION);
+ }
+
+ void onDockedFirstAnimationFrame() {
+ saveSnapTargetBeforeMinimized(mSplitLayout.getSnapAlgorithm().getMiddleTarget());
+ }
+
+ void onDockedTopTask() {
+ mState.animateAfterRecentsDrawn = true;
+ startDragging(false /* animate */, false /* touching */);
+ updateDockSide();
+ mEntranceAnimationRunning = true;
+
+ resizeStackSurfaces(calculatePositionForInsetBounds(),
+ mSplitLayout.getSnapAlgorithm().getMiddleTarget().position,
+ mSplitLayout.getSnapAlgorithm().getMiddleTarget(),
+ null /* transaction */);
+ }
+
+ void onRecentsDrawn() {
+ updateDockSide();
+ final int position = calculatePositionForInsetBounds();
+ if (mState.animateAfterRecentsDrawn) {
+ mState.animateAfterRecentsDrawn = false;
+
+ mHandler.post(() -> {
+ // Delay switching resizing mode because this might cause jank in recents animation
+ // that's longer than this animation.
+ stopDragging(position, getSnapAlgorithm().getMiddleTarget(),
+ mLongPressEntraceAnimDuration, Interpolators.FAST_OUT_SLOW_IN,
+ 200 /* endDelay */);
+ });
+ }
+ }
+
+ void onUndockingTask() {
+ int dockSide = mSplitLayout.getPrimarySplitSide();
+ if (inSplitMode()) {
+ startDragging(false /* animate */, false /* touching */);
+ SnapTarget target = dockSideTopLeft(dockSide)
+ ? mSplitLayout.getSnapAlgorithm().getDismissEndTarget()
+ : mSplitLayout.getSnapAlgorithm().getDismissStartTarget();
+
+ // Don't start immediately - give a little bit time to settle the drag resize change.
+ mExitAnimationRunning = true;
+ mExitStartPosition = getCurrentPosition();
+ stopDragging(mExitStartPosition, target, 336 /* duration */, 100 /* startDelay */,
+ 0 /* endDelay */, Interpolators.FAST_OUT_SLOW_IN);
+ }
+ }
+
+ private int calculatePositionForInsetBounds() {
+ mSplitLayout.mDisplayLayout.getStableBounds(mTmpRect);
+ return DockedDividerUtils.calculatePositionForBounds(mTmpRect, mDockSide, mDividerSize);
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerWindowManager.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerWindowManager.java
new file mode 100644
index 000000000000..0b4e17c27398
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/DividerWindowManager.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
+import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
+import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
+import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY;
+import static android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
+import static android.view.WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
+import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
+import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
+
+import android.graphics.PixelFormat;
+import android.graphics.Region;
+import android.os.Binder;
+import android.view.View;
+import android.view.WindowManager;
+
+import com.android.wm.shell.common.SystemWindows;
+
+/**
+ * Manages the window parameters of the docked stack divider.
+ */
+final class DividerWindowManager {
+
+ private static final String WINDOW_TITLE = "DockedStackDivider";
+
+ final SystemWindows mSystemWindows;
+ private WindowManager.LayoutParams mLp;
+ private View mView;
+
+ DividerWindowManager(SystemWindows systemWindows) {
+ mSystemWindows = systemWindows;
+ }
+
+ /** Add a divider view */
+ void add(View view, int width, int height, int displayId) {
+ mLp = new WindowManager.LayoutParams(
+ width, height, TYPE_DOCK_DIVIDER,
+ FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL
+ | FLAG_WATCH_OUTSIDE_TOUCH | FLAG_SPLIT_TOUCH | FLAG_SLIPPERY,
+ PixelFormat.TRANSLUCENT);
+ mLp.token = new Binder();
+ mLp.setTitle(WINDOW_TITLE);
+ mLp.privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION;
+ mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
+ view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
+ mSystemWindows.addView(view, mLp, displayId, TYPE_DOCK_DIVIDER);
+ mView = view;
+ }
+
+ void remove() {
+ if (mView != null) {
+ mSystemWindows.removeView(mView);
+ }
+ mView = null;
+ }
+
+ void setSlippery(boolean slippery) {
+ boolean changed = false;
+ if (slippery && (mLp.flags & FLAG_SLIPPERY) == 0) {
+ mLp.flags |= FLAG_SLIPPERY;
+ changed = true;
+ } else if (!slippery && (mLp.flags & FLAG_SLIPPERY) != 0) {
+ mLp.flags &= ~FLAG_SLIPPERY;
+ changed = true;
+ }
+ if (changed) {
+ mSystemWindows.updateViewLayout(mView, mLp);
+ }
+ }
+
+ void setTouchable(boolean touchable) {
+ if (mView == null) {
+ return;
+ }
+ boolean changed = false;
+ if (!touchable && (mLp.flags & FLAG_NOT_TOUCHABLE) == 0) {
+ mLp.flags |= FLAG_NOT_TOUCHABLE;
+ changed = true;
+ } else if (touchable && (mLp.flags & FLAG_NOT_TOUCHABLE) != 0) {
+ mLp.flags &= ~FLAG_NOT_TOUCHABLE;
+ changed = true;
+ }
+ if (changed) {
+ mSystemWindows.updateViewLayout(mView, mLp);
+ }
+ }
+
+ /** Sets the touch region to `touchRegion`. Use null to unset.*/
+ void setTouchRegion(Region touchRegion) {
+ if (mView == null) {
+ return;
+ }
+ mSystemWindows.setTouchableRegion(mView, touchRegion);
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ForcedResizableInfoActivity.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ForcedResizableInfoActivity.java
new file mode 100644
index 000000000000..7a1633530148
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ForcedResizableInfoActivity.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY;
+import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN;
+
+import android.annotation.Nullable;
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.os.Bundle;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.OnTouchListener;
+import android.widget.TextView;
+
+import com.android.wm.shell.R;
+
+/**
+ * Translucent activity that gets started on top of a task in multi-window to inform the user that
+ * we forced the activity below to be resizable.
+ */
+public class ForcedResizableInfoActivity extends Activity implements OnTouchListener {
+
+ public static final String EXTRA_FORCED_RESIZEABLE_REASON = "extra_forced_resizeable_reason";
+
+ private static final long DISMISS_DELAY = 2500;
+
+ private final Runnable mFinishRunnable = new Runnable() {
+ @Override
+ public void run() {
+ finish();
+ }
+ };
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.forced_resizable_activity);
+ TextView tv = findViewById(com.android.internal.R.id.message);
+ int reason = getIntent().getIntExtra(EXTRA_FORCED_RESIZEABLE_REASON, -1);
+ String text;
+ switch (reason) {
+ case FORCED_RESIZEABLE_REASON_SPLIT_SCREEN:
+ text = getString(R.string.dock_forced_resizable);
+ break;
+ case FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY:
+ text = getString(R.string.forced_resizable_secondary_display);
+ break;
+ default:
+ throw new IllegalArgumentException("Unexpected forced resizeable reason: "
+ + reason);
+ }
+ tv.setText(text);
+ getWindow().setTitle(text);
+ getWindow().getDecorView().setOnTouchListener(this);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ getWindow().getDecorView().postDelayed(mFinishRunnable, DISMISS_DELAY);
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ finish();
+ }
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ finish();
+ return true;
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ finish();
+ return true;
+ }
+
+ @Override
+ public void finish() {
+ super.finish();
+ overridePendingTransition(0, R.anim.forced_resizable_exit);
+ }
+
+ @Override
+ public void setTaskDescription(ActivityManager.TaskDescription taskDescription) {
+ // Do nothing
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ForcedResizableInfoActivityController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ForcedResizableInfoActivityController.java
new file mode 100644
index 000000000000..1ef142dacb9e
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ForcedResizableInfoActivityController.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+
+import static com.android.wm.shell.splitscreen.ForcedResizableInfoActivity.EXTRA_FORCED_RESIZEABLE_REASON;
+
+import android.app.ActivityOptions;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Handler;
+import android.os.UserHandle;
+import android.util.ArraySet;
+import android.widget.Toast;
+
+import com.android.wm.shell.R;
+
+import java.util.function.Consumer;
+
+/**
+ * Controller that decides when to show the {@link ForcedResizableInfoActivity}.
+ */
+final class ForcedResizableInfoActivityController implements DividerView.DividerCallbacks {
+
+ private static final String SELF_PACKAGE_NAME = "com.android.systemui";
+
+ private static final int TIMEOUT = 1000;
+ private final Context mContext;
+ private final Handler mHandler = new Handler();
+ private final ArraySet<PendingTaskRecord> mPendingTasks = new ArraySet<>();
+ private final ArraySet<String> mPackagesShownInSession = new ArraySet<>();
+ private boolean mDividerDragging;
+
+ private final Runnable mTimeoutRunnable = this::showPending;
+
+ private final Consumer<Boolean> mDockedStackExistsListener = exists -> {
+ if (!exists) {
+ mPackagesShownInSession.clear();
+ }
+ };
+
+ /** Record of force resized task that's pending to be handled. */
+ private class PendingTaskRecord {
+ int mTaskId;
+ /**
+ * {@link android.app.ITaskStackListener#FORCED_RESIZEABLE_REASON_SPLIT_SCREEN} or
+ * {@link android.app.ITaskStackListener#FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY}
+ */
+ int mReason;
+
+ PendingTaskRecord(int taskId, int reason) {
+ this.mTaskId = taskId;
+ this.mReason = reason;
+ }
+ }
+
+ ForcedResizableInfoActivityController(Context context,
+ SplitScreenController splitScreenController) {
+ mContext = context;
+ splitScreenController.registerInSplitScreenListener(mDockedStackExistsListener);
+ }
+
+ @Override
+ public void onDraggingStart() {
+ mDividerDragging = true;
+ mHandler.removeCallbacks(mTimeoutRunnable);
+ }
+
+ @Override
+ public void onDraggingEnd() {
+ mDividerDragging = false;
+ showPending();
+ }
+
+ void onAppTransitionFinished() {
+ if (!mDividerDragging) {
+ showPending();
+ }
+ }
+
+ void activityForcedResizable(String packageName, int taskId, int reason) {
+ if (debounce(packageName)) {
+ return;
+ }
+ mPendingTasks.add(new PendingTaskRecord(taskId, reason));
+ postTimeout();
+ }
+
+ void activityDismissingSplitScreen() {
+ Toast.makeText(mContext, R.string.dock_non_resizeble_failed_to_dock_text,
+ Toast.LENGTH_SHORT).show();
+ }
+
+ void activityLaunchOnSecondaryDisplayFailed() {
+ Toast.makeText(mContext, R.string.activity_launch_on_secondary_display_failed_text,
+ Toast.LENGTH_SHORT).show();
+ }
+
+ private void showPending() {
+ mHandler.removeCallbacks(mTimeoutRunnable);
+ for (int i = mPendingTasks.size() - 1; i >= 0; i--) {
+ PendingTaskRecord pendingRecord = mPendingTasks.valueAt(i);
+ Intent intent = new Intent(mContext, ForcedResizableInfoActivity.class);
+ ActivityOptions options = ActivityOptions.makeBasic();
+ options.setLaunchTaskId(pendingRecord.mTaskId);
+ // Set as task overlay and allow to resume, so that when an app enters split-screen and
+ // becomes paused, the overlay will still be shown.
+ options.setTaskOverlay(true, true /* canResume */);
+ intent.putExtra(EXTRA_FORCED_RESIZEABLE_REASON, pendingRecord.mReason);
+ mContext.startActivityAsUser(intent, options.toBundle(), UserHandle.CURRENT);
+ }
+ mPendingTasks.clear();
+ }
+
+ private void postTimeout() {
+ mHandler.removeCallbacks(mTimeoutRunnable);
+ mHandler.postDelayed(mTimeoutRunnable, TIMEOUT);
+ }
+
+ private boolean debounce(String packageName) {
+ if (packageName == null) {
+ return false;
+ }
+
+ // We launch ForcedResizableInfoActivity into a task that was forced resizable, so that
+ // triggers another notification. So ignore our own activity.
+ if (SELF_PACKAGE_NAME.equals(packageName)) {
+ return true;
+ }
+ boolean debounce = mPackagesShownInSession.contains(packageName);
+ mPackagesShownInSession.add(packageName);
+ return debounce;
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/MinimizedDockShadow.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/MinimizedDockShadow.java
new file mode 100644
index 000000000000..06f4ef109193
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/MinimizedDockShadow.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.LinearGradient;
+import android.graphics.Paint;
+import android.graphics.Shader;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.WindowManager;
+
+import com.android.wm.shell.R;
+
+/**
+ * Shadow for the minimized dock state on homescreen.
+ */
+public class MinimizedDockShadow extends View {
+
+ private final Paint mShadowPaint = new Paint();
+
+ private int mDockSide = WindowManager.DOCKED_INVALID;
+
+ public MinimizedDockShadow(Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ void setDockSide(int dockSide) {
+ if (dockSide != mDockSide) {
+ mDockSide = dockSide;
+ updatePaint(getLeft(), getTop(), getRight(), getBottom());
+ invalidate();
+ }
+ }
+
+ private void updatePaint(int left, int top, int right, int bottom) {
+ int startColor = mContext.getResources().getColor(
+ R.color.minimize_dock_shadow_start, null);
+ int endColor = mContext.getResources().getColor(
+ R.color.minimize_dock_shadow_end, null);
+ final int middleColor = Color.argb(
+ (Color.alpha(startColor) + Color.alpha(endColor)) / 2, 0, 0, 0);
+ final int quarter = Color.argb(
+ (int) (Color.alpha(startColor) * 0.25f + Color.alpha(endColor) * 0.75f),
+ 0, 0, 0);
+ if (mDockSide == WindowManager.DOCKED_TOP) {
+ mShadowPaint.setShader(new LinearGradient(
+ 0, 0, 0, bottom - top,
+ new int[] { startColor, middleColor, quarter, endColor },
+ new float[] { 0f, 0.35f, 0.6f, 1f }, Shader.TileMode.CLAMP));
+ } else if (mDockSide == WindowManager.DOCKED_LEFT) {
+ mShadowPaint.setShader(new LinearGradient(
+ 0, 0, right - left, 0,
+ new int[] { startColor, middleColor, quarter, endColor },
+ new float[] { 0f, 0.35f, 0.6f, 1f }, Shader.TileMode.CLAMP));
+ } else if (mDockSide == WindowManager.DOCKED_RIGHT) {
+ mShadowPaint.setShader(new LinearGradient(
+ right - left, 0, 0, 0,
+ new int[] { startColor, middleColor, quarter, endColor },
+ new float[] { 0f, 0.35f, 0.6f, 1f }, Shader.TileMode.CLAMP));
+ }
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+ if (changed) {
+ updatePaint(left, top, right, bottom);
+ invalidate();
+ }
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ canvas.drawRect(0, 0, getWidth(), getHeight(), mShadowPaint);
+ }
+
+ @Override
+ public boolean hasOverlappingRendering() {
+ return false;
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitDisplayLayout.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitDisplayLayout.java
new file mode 100644
index 000000000000..3c0f93906795
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitDisplayLayout.java
@@ -0,0 +1,313 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
+import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
+import static android.view.WindowManager.DOCKED_BOTTOM;
+import static android.view.WindowManager.DOCKED_INVALID;
+import static android.view.WindowManager.DOCKED_LEFT;
+import static android.view.WindowManager.DOCKED_RIGHT;
+import static android.view.WindowManager.DOCKED_TOP;
+
+import android.annotation.NonNull;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.graphics.Rect;
+import android.util.TypedValue;
+import android.window.WindowContainerTransaction;
+
+import com.android.internal.policy.DividerSnapAlgorithm;
+import com.android.internal.policy.DockedDividerUtils;
+import com.android.wm.shell.common.DisplayLayout;
+
+/**
+ * Handles split-screen related internal display layout. In general, this represents the
+ * WM-facing understanding of the splits.
+ */
+public class SplitDisplayLayout {
+ /** Minimum size of an adjusted stack bounds relative to original stack bounds. Used to
+ * restrict IME adjustment so that a min portion of top stack remains visible.*/
+ private static final float ADJUSTED_STACK_FRACTION_MIN = 0.3f;
+
+ private static final int DIVIDER_WIDTH_INACTIVE_DP = 4;
+
+ SplitScreenTaskOrganizer mTiles;
+ DisplayLayout mDisplayLayout;
+ Context mContext;
+
+ // Lazy stuff
+ boolean mResourcesValid = false;
+ int mDividerSize;
+ int mDividerSizeInactive;
+ private DividerSnapAlgorithm mSnapAlgorithm = null;
+ private DividerSnapAlgorithm mMinimizedSnapAlgorithm = null;
+ Rect mPrimary = null;
+ Rect mSecondary = null;
+ Rect mAdjustedPrimary = null;
+ Rect mAdjustedSecondary = null;
+
+ public SplitDisplayLayout(Context ctx, DisplayLayout dl, SplitScreenTaskOrganizer taskTiles) {
+ mTiles = taskTiles;
+ mDisplayLayout = dl;
+ mContext = ctx;
+ }
+
+ void rotateTo(int newRotation) {
+ mDisplayLayout.rotateTo(mContext.getResources(), newRotation);
+ final Configuration config = new Configuration();
+ config.unset();
+ config.orientation = mDisplayLayout.getOrientation();
+ Rect tmpRect = new Rect(0, 0, mDisplayLayout.width(), mDisplayLayout.height());
+ tmpRect.inset(mDisplayLayout.nonDecorInsets());
+ config.windowConfiguration.setAppBounds(tmpRect);
+ tmpRect.set(0, 0, mDisplayLayout.width(), mDisplayLayout.height());
+ tmpRect.inset(mDisplayLayout.stableInsets());
+ config.screenWidthDp = (int) (tmpRect.width() / mDisplayLayout.density());
+ config.screenHeightDp = (int) (tmpRect.height() / mDisplayLayout.density());
+ mContext = mContext.createConfigurationContext(config);
+ mSnapAlgorithm = null;
+ mMinimizedSnapAlgorithm = null;
+ mResourcesValid = false;
+ }
+
+ private void updateResources() {
+ if (mResourcesValid) {
+ return;
+ }
+ mResourcesValid = true;
+ Resources res = mContext.getResources();
+ mDividerSize = DockedDividerUtils.getDividerSize(res,
+ DockedDividerUtils.getDividerInsets(res));
+ mDividerSizeInactive = (int) TypedValue.applyDimension(
+ TypedValue.COMPLEX_UNIT_DIP, DIVIDER_WIDTH_INACTIVE_DP, res.getDisplayMetrics());
+ }
+
+ int getPrimarySplitSide() {
+ switch (mDisplayLayout.getNavigationBarPosition(mContext.getResources())) {
+ case DisplayLayout.NAV_BAR_BOTTOM:
+ return mDisplayLayout.isLandscape() ? DOCKED_LEFT : DOCKED_TOP;
+ case DisplayLayout.NAV_BAR_LEFT:
+ return DOCKED_RIGHT;
+ case DisplayLayout.NAV_BAR_RIGHT:
+ return DOCKED_LEFT;
+ default:
+ return DOCKED_INVALID;
+ }
+ }
+
+ DividerSnapAlgorithm getSnapAlgorithm() {
+ if (mSnapAlgorithm == null) {
+ updateResources();
+ boolean isHorizontalDivision = !mDisplayLayout.isLandscape();
+ mSnapAlgorithm = new DividerSnapAlgorithm(mContext.getResources(),
+ mDisplayLayout.width(), mDisplayLayout.height(), mDividerSize,
+ isHorizontalDivision, mDisplayLayout.stableInsets(), getPrimarySplitSide());
+ }
+ return mSnapAlgorithm;
+ }
+
+ DividerSnapAlgorithm getMinimizedSnapAlgorithm(boolean homeStackResizable) {
+ if (mMinimizedSnapAlgorithm == null) {
+ updateResources();
+ boolean isHorizontalDivision = !mDisplayLayout.isLandscape();
+ mMinimizedSnapAlgorithm = new DividerSnapAlgorithm(mContext.getResources(),
+ mDisplayLayout.width(), mDisplayLayout.height(), mDividerSize,
+ isHorizontalDivision, mDisplayLayout.stableInsets(), getPrimarySplitSide(),
+ true /* isMinimized */, homeStackResizable);
+ }
+ return mMinimizedSnapAlgorithm;
+ }
+
+ void resizeSplits(int position) {
+ mPrimary = mPrimary == null ? new Rect() : mPrimary;
+ mSecondary = mSecondary == null ? new Rect() : mSecondary;
+ calcSplitBounds(position, mPrimary, mSecondary);
+ }
+
+ void resizeSplits(int position, WindowContainerTransaction t) {
+ resizeSplits(position);
+ t.setBounds(mTiles.mPrimary.token, mPrimary);
+ t.setBounds(mTiles.mSecondary.token, mSecondary);
+
+ t.setSmallestScreenWidthDp(mTiles.mPrimary.token,
+ getSmallestWidthDpForBounds(mContext, mDisplayLayout, mPrimary));
+ t.setSmallestScreenWidthDp(mTiles.mSecondary.token,
+ getSmallestWidthDpForBounds(mContext, mDisplayLayout, mSecondary));
+ }
+
+ void calcSplitBounds(int position, @NonNull Rect outPrimary, @NonNull Rect outSecondary) {
+ int dockSide = getPrimarySplitSide();
+ DockedDividerUtils.calculateBoundsForPosition(position, dockSide, outPrimary,
+ mDisplayLayout.width(), mDisplayLayout.height(), mDividerSize);
+
+ DockedDividerUtils.calculateBoundsForPosition(position,
+ DockedDividerUtils.invertDockSide(dockSide), outSecondary, mDisplayLayout.width(),
+ mDisplayLayout.height(), mDividerSize);
+ }
+
+ Rect calcResizableMinimizedHomeStackBounds() {
+ DividerSnapAlgorithm.SnapTarget miniMid =
+ getMinimizedSnapAlgorithm(true /* resizable */).getMiddleTarget();
+ Rect homeBounds = new Rect();
+ DockedDividerUtils.calculateBoundsForPosition(miniMid.position,
+ DockedDividerUtils.invertDockSide(getPrimarySplitSide()), homeBounds,
+ mDisplayLayout.width(), mDisplayLayout.height(), mDividerSize);
+ return homeBounds;
+ }
+
+ /**
+ * Updates the adjustment depending on it's current state.
+ */
+ void updateAdjustedBounds(int currImeTop, int hiddenTop, int shownTop) {
+ adjustForIME(mDisplayLayout, currImeTop, hiddenTop, shownTop, mDividerSize,
+ mDividerSizeInactive, mPrimary, mSecondary);
+ }
+
+ /** Assumes top/bottom split. Splits are not adjusted for left/right splits. */
+ private void adjustForIME(DisplayLayout dl, int currImeTop, int hiddenTop, int shownTop,
+ int dividerWidth, int dividerWidthInactive, Rect primaryBounds, Rect secondaryBounds) {
+ if (mAdjustedPrimary == null) {
+ mAdjustedPrimary = new Rect();
+ mAdjustedSecondary = new Rect();
+ }
+
+ final Rect displayStableRect = new Rect();
+ dl.getStableBounds(displayStableRect);
+
+ final float shownFraction = ((float) (currImeTop - hiddenTop)) / (shownTop - hiddenTop);
+ final int currDividerWidth =
+ (int) (dividerWidthInactive * shownFraction + dividerWidth * (1.f - shownFraction));
+
+ // Calculate the highest we can move the bottom of the top stack to keep 30% visible.
+ final int minTopStackBottom = displayStableRect.top
+ + (int) ((mPrimary.bottom - displayStableRect.top) * ADJUSTED_STACK_FRACTION_MIN);
+ // Based on that, calculate the maximum amount we'll allow the ime to shift things.
+ final int maxOffset = mPrimary.bottom - minTopStackBottom;
+ // Calculate how much we would shift things without limits (basically the height of ime).
+ final int desiredOffset = hiddenTop - shownTop;
+ // Calculate an "adjustedTop" which is the currImeTop but restricted by our constraints.
+ // We want an effect where the adjustment only occurs during the "highest" portion of the
+ // ime animation. This is done by shifting the adjustment values by the difference in
+ // offsets (effectively playing the whole adjustment animation some fixed amount of pixels
+ // below the ime top).
+ final int topCorrection = Math.max(0, desiredOffset - maxOffset);
+ final int adjustedTop = currImeTop + topCorrection;
+ // The actual yOffset is the distance between adjustedTop and the bottom of the display.
+ // Since our adjustedTop values are playing "below" the ime, we clamp at 0 so we only
+ // see adjustment upward.
+ final int yOffset = Math.max(0, dl.height() - adjustedTop);
+
+ // TOP
+ // Reduce the offset by an additional small amount to squish the divider bar.
+ mAdjustedPrimary.set(primaryBounds);
+ mAdjustedPrimary.offset(0, -yOffset + (dividerWidth - currDividerWidth));
+
+ // BOTTOM
+ mAdjustedSecondary.set(secondaryBounds);
+ mAdjustedSecondary.offset(0, -yOffset);
+ }
+
+ static int getSmallestWidthDpForBounds(@NonNull Context context, DisplayLayout dl,
+ Rect bounds) {
+ int dividerSize = DockedDividerUtils.getDividerSize(context.getResources(),
+ DockedDividerUtils.getDividerInsets(context.getResources()));
+
+ int minWidth = Integer.MAX_VALUE;
+
+ // Go through all screen orientations and find the orientation in which the task has the
+ // smallest width.
+ Rect tmpRect = new Rect();
+ Rect rotatedDisplayRect = new Rect();
+ Rect displayRect = new Rect(0, 0, dl.width(), dl.height());
+
+ DisplayLayout tmpDL = new DisplayLayout();
+ for (int rotation = 0; rotation < 4; rotation++) {
+ tmpDL.set(dl);
+ tmpDL.rotateTo(context.getResources(), rotation);
+ DividerSnapAlgorithm snap = initSnapAlgorithmForRotation(context, tmpDL, dividerSize);
+
+ tmpRect.set(bounds);
+ DisplayLayout.rotateBounds(tmpRect, displayRect, rotation - dl.rotation());
+ rotatedDisplayRect.set(0, 0, tmpDL.width(), tmpDL.height());
+ final int dockSide = getPrimarySplitSide(tmpRect, rotatedDisplayRect,
+ tmpDL.getOrientation());
+ final int position = DockedDividerUtils.calculatePositionForBounds(tmpRect, dockSide,
+ dividerSize);
+
+ final int snappedPosition =
+ snap.calculateNonDismissingSnapTarget(position).position;
+ DockedDividerUtils.calculateBoundsForPosition(snappedPosition, dockSide, tmpRect,
+ tmpDL.width(), tmpDL.height(), dividerSize);
+ Rect insettedDisplay = new Rect(rotatedDisplayRect);
+ insettedDisplay.inset(tmpDL.stableInsets());
+ tmpRect.intersect(insettedDisplay);
+ minWidth = Math.min(tmpRect.width(), minWidth);
+ }
+ return (int) (minWidth / dl.density());
+ }
+
+ static DividerSnapAlgorithm initSnapAlgorithmForRotation(Context context, DisplayLayout dl,
+ int dividerSize) {
+ final Configuration config = new Configuration();
+ config.unset();
+ config.orientation = dl.getOrientation();
+ Rect tmpRect = new Rect(0, 0, dl.width(), dl.height());
+ tmpRect.inset(dl.nonDecorInsets());
+ config.windowConfiguration.setAppBounds(tmpRect);
+ tmpRect.set(0, 0, dl.width(), dl.height());
+ tmpRect.inset(dl.stableInsets());
+ config.screenWidthDp = (int) (tmpRect.width() / dl.density());
+ config.screenHeightDp = (int) (tmpRect.height() / dl.density());
+ final Context rotationContext = context.createConfigurationContext(config);
+ return new DividerSnapAlgorithm(
+ rotationContext.getResources(), dl.width(), dl.height(), dividerSize,
+ config.orientation == ORIENTATION_PORTRAIT, dl.stableInsets());
+ }
+
+ /**
+ * Get the current primary-split side. Determined by its location of {@param bounds} within
+ * {@param displayRect} but if both are the same, it will try to dock to each side and determine
+ * if allowed in its respected {@param orientation}.
+ *
+ * @param bounds bounds of the primary split task to get which side is docked
+ * @param displayRect bounds of the display that contains the primary split task
+ * @param orientation the origination of device
+ * @return current primary-split side
+ */
+ static int getPrimarySplitSide(Rect bounds, Rect displayRect, int orientation) {
+ if (orientation == ORIENTATION_PORTRAIT) {
+ // Portrait mode, docked either at the top or the bottom.
+ final int diff = (displayRect.bottom - bounds.bottom) - (bounds.top - displayRect.top);
+ if (diff < 0) {
+ return DOCKED_BOTTOM;
+ } else {
+ // Top is default
+ return DOCKED_TOP;
+ }
+ } else if (orientation == ORIENTATION_LANDSCAPE) {
+ // Landscape mode, docked either on the left or on the right.
+ final int diff = (displayRect.right - bounds.right) - (bounds.left - displayRect.left);
+ if (diff < 0) {
+ return DOCKED_RIGHT;
+ }
+ return DOCKED_LEFT;
+ }
+ return DOCKED_INVALID;
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreen.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreen.java
new file mode 100644
index 000000000000..184342f14d4f
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreen.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import android.graphics.Rect;
+import android.window.WindowContainerToken;
+
+import java.io.PrintWriter;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+/**
+ * Interface to engage split screen feature.
+ */
+public interface SplitScreen {
+ /** Returns {@code true} if split screen is supported on the device. */
+ boolean isSplitScreenSupported();
+
+ /** Called when keyguard showing state changed. */
+ void onKeyguardVisibilityChanged(boolean isShowing);
+
+ /** Returns {@link DividerView}. */
+ DividerView getDividerView();
+
+ /** Returns {@code true} if one of the split screen is in minimized mode. */
+ boolean isMinimized();
+
+ /** Returns {@code true} if the home stack is resizable. */
+ boolean isHomeStackResizable();
+
+ /** Returns {@code true} if the divider is visible. */
+ boolean isDividerVisible();
+
+ /** Switch to minimized state if appropriate. */
+ void setMinimized(boolean minimized);
+
+ /**
+ * Workaround for b/62528361, at the time recents has drawn, it may happen before a
+ * configuration change to the Divider, and internally, the event will be posted to the
+ * subscriber, or DividerView, which has been removed and prevented from resizing. Instead,
+ * register the event handler here and proxy the event to the current DividerView.
+ */
+ void onRecentsDrawn();
+
+ /** Called when there's an activity forced resizable. */
+ void onActivityForcedResizable(String packageName, int taskId, int reason);
+
+ /** Called when there's an activity dismissing split screen. */
+ void onActivityDismissingSplitScreen();
+
+ /** Called when there's an activity launch on secondary display failed. */
+ void onActivityLaunchOnSecondaryDisplayFailed();
+
+ /** Called when there's a task undocking. */
+ void onUndockingTask();
+
+ /** Called when the first docked animation frame rendered. */
+ void onDockedFirstAnimationFrame();
+
+ /** Called when top task docked. */
+ void onDockedTopTask();
+
+ /** Called when app transition finished. */
+ void onAppTransitionFinished();
+
+ /** Dumps current status of Split Screen. */
+ void dump(PrintWriter pw);
+
+ /** Registers listener that gets called whenever the existence of the divider changes. */
+ void registerInSplitScreenListener(Consumer<Boolean> listener);
+
+ /** Registers listener that gets called whenever the split screen bounds changes. */
+ void registerBoundsChangeListener(BiConsumer<Rect, Rect> listener);
+
+ /** @return the container token for the secondary split root task. */
+ WindowContainerToken getSecondaryRoot();
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java
new file mode 100644
index 000000000000..eed5092ea96b
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java
@@ -0,0 +1,546 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
+import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import android.app.ActivityTaskManager;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.provider.Settings;
+import android.util.Slog;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.window.TaskOrganizer;
+import android.window.WindowContainerToken;
+import android.window.WindowContainerTransaction;
+
+import com.android.internal.policy.DividerSnapAlgorithm;
+import com.android.wm.shell.R;
+import com.android.wm.shell.ShellTaskOrganizer;
+import com.android.wm.shell.common.DisplayChangeController;
+import com.android.wm.shell.common.DisplayController;
+import com.android.wm.shell.common.DisplayImeController;
+import com.android.wm.shell.common.DisplayLayout;
+import com.android.wm.shell.common.SystemWindows;
+import com.android.wm.shell.common.TransactionPool;
+
+import java.io.PrintWriter;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+/**
+ * Controls split screen feature.
+ */
+public class SplitScreenController implements SplitScreen,
+ DisplayController.OnDisplaysChangedListener {
+ static final boolean DEBUG = false;
+
+ private static final String TAG = "Divider";
+ private static final int DEFAULT_APP_TRANSITION_DURATION = 336;
+
+ private final Context mContext;
+ private final DisplayChangeController.OnDisplayChangingListener mRotationController;
+ private final DisplayController mDisplayController;
+ private final DisplayImeController mImeController;
+ private final DividerImeController mImePositionProcessor;
+ private final DividerState mDividerState = new DividerState();
+ private final ForcedResizableInfoActivityController mForcedResizableController;
+ private final Handler mHandler;
+ private final SplitScreenTaskOrganizer mSplits;
+ private final SystemWindows mSystemWindows;
+ final TransactionPool mTransactionPool;
+ private final WindowManagerProxy mWindowManagerProxy;
+ private final TaskOrganizer mTaskOrganizer;
+
+ private final ArrayList<WeakReference<Consumer<Boolean>>> mDockedStackExistsListeners =
+ new ArrayList<>();
+ private final ArrayList<WeakReference<BiConsumer<Rect, Rect>>> mBoundsChangedListeners =
+ new ArrayList<>();
+
+
+ private DividerWindowManager mWindowManager;
+ private DividerView mView;
+
+ // Keeps track of real-time split geometry including snap positions and ime adjustments
+ private SplitDisplayLayout mSplitLayout;
+
+ // Transient: this contains the layout calculated for a new rotation requested by WM. This is
+ // kept around so that we can wait for a matching configuration change and then use the exact
+ // layout that we sent back to WM.
+ private SplitDisplayLayout mRotateSplitLayout;
+
+ private boolean mIsKeyguardShowing;
+ private boolean mVisible = false;
+ private boolean mMinimized = false;
+ private boolean mAdjustedForIme = false;
+ private boolean mHomeStackResizable = false;
+
+ public SplitScreenController(Context context,
+ DisplayController displayController, SystemWindows systemWindows,
+ DisplayImeController imeController, Handler handler, TransactionPool transactionPool,
+ ShellTaskOrganizer shellTaskOrganizer) {
+ mContext = context;
+ mDisplayController = displayController;
+ mSystemWindows = systemWindows;
+ mImeController = imeController;
+ mHandler = handler;
+ mForcedResizableController = new ForcedResizableInfoActivityController(context, this);
+ mTransactionPool = transactionPool;
+ mWindowManagerProxy = new WindowManagerProxy(mTransactionPool, mHandler,
+ shellTaskOrganizer);
+ mTaskOrganizer = shellTaskOrganizer;
+ mSplits = new SplitScreenTaskOrganizer(this, shellTaskOrganizer);
+ mImePositionProcessor = new DividerImeController(mSplits, mTransactionPool, mHandler,
+ shellTaskOrganizer);
+ mRotationController =
+ (display, fromRotation, toRotation, wct) -> {
+ if (!mSplits.isSplitScreenSupported() || mWindowManagerProxy == null) {
+ return;
+ }
+ WindowContainerTransaction t = new WindowContainerTransaction();
+ DisplayLayout displayLayout =
+ new DisplayLayout(mDisplayController.getDisplayLayout(display));
+ SplitDisplayLayout sdl =
+ new SplitDisplayLayout(mContext, displayLayout, mSplits);
+ sdl.rotateTo(toRotation);
+ mRotateSplitLayout = sdl;
+ final int position = isDividerVisible()
+ ? (mMinimized ? mView.mSnapTargetBeforeMinimized.position
+ : mView.getCurrentPosition())
+ // snap resets to middle target when not in split-mode
+ : sdl.getSnapAlgorithm().getMiddleTarget().position;
+ DividerSnapAlgorithm snap = sdl.getSnapAlgorithm();
+ final DividerSnapAlgorithm.SnapTarget target =
+ snap.calculateNonDismissingSnapTarget(position);
+ sdl.resizeSplits(target.position, t);
+
+ if (isSplitActive() && mHomeStackResizable) {
+ mWindowManagerProxy
+ .applyHomeTasksMinimized(sdl, mSplits.mSecondary.token, t);
+ }
+ if (mWindowManagerProxy.queueSyncTransactionIfWaiting(t)) {
+ // Because sync transactions are serialized, its possible for an "older"
+ // bounds-change to get applied after a screen rotation. In that case, we
+ // want to actually defer on that rather than apply immediately. Of course,
+ // this means that the bounds may not change until after the rotation so
+ // the user might see some artifacts. This should be rare.
+ Slog.w(TAG, "Screen rotated while other operations were pending, this may"
+ + " result in some graphical artifacts.");
+ } else {
+ wct.merge(t, true /* transfer */);
+ }
+ };
+
+ mWindowManager = new DividerWindowManager(mSystemWindows);
+ mDisplayController.addDisplayWindowListener(this);
+ // Don't initialize the divider or anything until we get the default display.
+ }
+
+ /** Returns {@code true} if split screen is supported on the device. */
+ public boolean isSplitScreenSupported() {
+ return mSplits.isSplitScreenSupported();
+ }
+
+ /** Called when keyguard showing state changed. */
+ public void onKeyguardVisibilityChanged(boolean showing) {
+ if (!isSplitActive() || mView == null) {
+ return;
+ }
+ mView.setHidden(showing);
+ if (!showing) {
+ mImePositionProcessor.updateAdjustForIme();
+ }
+ mIsKeyguardShowing = showing;
+ }
+
+ @Override
+ public void onDisplayAdded(int displayId) {
+ if (displayId != DEFAULT_DISPLAY) {
+ return;
+ }
+ mSplitLayout = new SplitDisplayLayout(mDisplayController.getDisplayContext(displayId),
+ mDisplayController.getDisplayLayout(displayId), mSplits);
+ mImeController.addPositionProcessor(mImePositionProcessor);
+ mDisplayController.addDisplayChangingController(mRotationController);
+ if (!ActivityTaskManager.supportsSplitScreenMultiWindow(mContext)) {
+ removeDivider();
+ return;
+ }
+ try {
+ mSplits.init();
+ // Set starting tile bounds based on middle target
+ final WindowContainerTransaction tct = new WindowContainerTransaction();
+ int midPos = mSplitLayout.getSnapAlgorithm().getMiddleTarget().position;
+ mSplitLayout.resizeSplits(midPos, tct);
+ mTaskOrganizer.applyTransaction(tct);
+ } catch (Exception e) {
+ Slog.e(TAG, "Failed to register docked stack listener", e);
+ removeDivider();
+ return;
+ }
+ }
+
+ @Override
+ public void onDisplayConfigurationChanged(int displayId, Configuration newConfig) {
+ if (displayId != DEFAULT_DISPLAY || !mSplits.isSplitScreenSupported()) {
+ return;
+ }
+ mSplitLayout = new SplitDisplayLayout(mDisplayController.getDisplayContext(displayId),
+ mDisplayController.getDisplayLayout(displayId), mSplits);
+ if (mRotateSplitLayout == null) {
+ int midPos = mSplitLayout.getSnapAlgorithm().getMiddleTarget().position;
+ final WindowContainerTransaction tct = new WindowContainerTransaction();
+ mSplitLayout.resizeSplits(midPos, tct);
+ mTaskOrganizer.applyTransaction(tct);
+ } else if (mSplitLayout.mDisplayLayout.rotation()
+ == mRotateSplitLayout.mDisplayLayout.rotation()) {
+ mSplitLayout.mPrimary = new Rect(mRotateSplitLayout.mPrimary);
+ mSplitLayout.mSecondary = new Rect(mRotateSplitLayout.mSecondary);
+ mRotateSplitLayout = null;
+ }
+ if (isSplitActive()) {
+ update(newConfig);
+ }
+ }
+
+ /** Posts task to handler dealing with divider. */
+ void post(Runnable task) {
+ mHandler.post(task);
+ }
+
+ /** Returns {@link DividerView}. */
+ public DividerView getDividerView() {
+ return mView;
+ }
+
+ /** Returns {@code true} if one of the split screen is in minimized mode. */
+ public boolean isMinimized() {
+ return mMinimized;
+ }
+
+ public boolean isHomeStackResizable() {
+ return mHomeStackResizable;
+ }
+
+ /** Returns {@code true} if the divider is visible. */
+ public boolean isDividerVisible() {
+ return mView != null && mView.getVisibility() == View.VISIBLE;
+ }
+
+ /**
+ * This indicates that at-least one of the splits has content. This differs from
+ * isDividerVisible because the divider is only visible once *everything* is in split mode
+ * while this only cares if some things are (eg. while entering/exiting as well).
+ */
+ private boolean isSplitActive() {
+ return mSplits.mPrimary != null && mSplits.mSecondary != null
+ && (mSplits.mPrimary.topActivityType != ACTIVITY_TYPE_UNDEFINED
+ || mSplits.mSecondary.topActivityType != ACTIVITY_TYPE_UNDEFINED);
+ }
+
+ private void addDivider(Configuration configuration) {
+ Context dctx = mDisplayController.getDisplayContext(mContext.getDisplayId());
+ mView = (DividerView)
+ LayoutInflater.from(dctx).inflate(R.layout.docked_stack_divider, null);
+ DisplayLayout displayLayout = mDisplayController.getDisplayLayout(mContext.getDisplayId());
+ mView.injectDependencies(this, mWindowManager, mDividerState, mForcedResizableController,
+ mSplits, mSplitLayout, mImePositionProcessor, mWindowManagerProxy);
+ mView.setVisibility(mVisible ? View.VISIBLE : View.INVISIBLE);
+ mView.setMinimizedDockStack(mMinimized, mHomeStackResizable, null /* transaction */);
+ final int size = dctx.getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.docked_stack_divider_thickness);
+ final boolean landscape = configuration.orientation == ORIENTATION_LANDSCAPE;
+ final int width = landscape ? size : displayLayout.width();
+ final int height = landscape ? displayLayout.height() : size;
+ mWindowManager.add(mView, width, height, mContext.getDisplayId());
+ }
+
+ private void removeDivider() {
+ if (mView != null) {
+ mView.onDividerRemoved();
+ }
+ mWindowManager.remove();
+ }
+
+ private void update(Configuration configuration) {
+ final boolean isDividerHidden = mView != null && mIsKeyguardShowing;
+
+ removeDivider();
+ addDivider(configuration);
+
+ if (mMinimized) {
+ mView.setMinimizedDockStack(true, mHomeStackResizable, null /* transaction */);
+ updateTouchable();
+ }
+ mView.setHidden(isDividerHidden);
+ }
+
+ void onTaskVanished() {
+ mHandler.post(this::removeDivider);
+ }
+
+ private void updateVisibility(final boolean visible) {
+ if (DEBUG) Slog.d(TAG, "Updating visibility " + mVisible + "->" + visible);
+ if (mVisible != visible) {
+ mVisible = visible;
+ mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
+
+ if (visible) {
+ mView.enterSplitMode(mHomeStackResizable);
+ // Update state because animations won't finish.
+ mWindowManagerProxy.runInSync(
+ t -> mView.setMinimizedDockStack(mMinimized, mHomeStackResizable, t));
+
+ } else {
+ mView.exitSplitMode();
+ mWindowManagerProxy.runInSync(
+ t -> mView.setMinimizedDockStack(false, mHomeStackResizable, t));
+ }
+ // Notify existence listeners
+ synchronized (mDockedStackExistsListeners) {
+ mDockedStackExistsListeners.removeIf(wf -> {
+ Consumer<Boolean> l = wf.get();
+ if (l != null) l.accept(visible);
+ return l == null;
+ });
+ }
+ }
+ }
+
+ /** Switch to minimized state if appropriate. */
+ public void setMinimized(final boolean minimized) {
+ if (DEBUG) Slog.d(TAG, "posting ext setMinimized " + minimized + " vis:" + mVisible);
+ mHandler.post(() -> {
+ if (DEBUG) Slog.d(TAG, "run posted ext setMinimized " + minimized + " vis:" + mVisible);
+ if (!mVisible) {
+ return;
+ }
+ setHomeMinimized(minimized);
+ });
+ }
+
+ private void setHomeMinimized(final boolean minimized) {
+ if (DEBUG) {
+ Slog.d(TAG, "setHomeMinimized min:" + mMinimized + "->" + minimized + " hrsz:"
+ + mHomeStackResizable + " split:" + isDividerVisible());
+ }
+ WindowContainerTransaction wct = new WindowContainerTransaction();
+ final boolean minimizedChanged = mMinimized != minimized;
+ // Update minimized state
+ if (minimizedChanged) {
+ mMinimized = minimized;
+ }
+ // Always set this because we could be entering split when mMinimized is already true
+ wct.setFocusable(mSplits.mPrimary.token, !mMinimized);
+
+ // Sync state to DividerView if it exists.
+ if (mView != null) {
+ final int displayId = mView.getDisplay() != null
+ ? mView.getDisplay().getDisplayId() : DEFAULT_DISPLAY;
+ // pause ime here (before updateMinimizedDockedStack)
+ if (mMinimized) {
+ mImePositionProcessor.pause(displayId);
+ }
+ if (minimizedChanged) {
+ // This conflicts with IME adjustment, so only call it when things change.
+ mView.setMinimizedDockStack(minimized, getAnimDuration(), mHomeStackResizable);
+ }
+ if (!mMinimized) {
+ // afterwards so it can end any animations started in view
+ mImePositionProcessor.resume(displayId);
+ }
+ }
+ updateTouchable();
+
+ // If we are only setting focusability, a sync transaction isn't necessary (in fact it
+ // can interrupt other animations), so see if it can be submitted on pending instead.
+ if (!mWindowManagerProxy.queueSyncTransactionIfWaiting(wct)) {
+ mTaskOrganizer.applyTransaction(wct);
+ }
+ }
+
+ void setAdjustedForIme(boolean adjustedForIme) {
+ if (mAdjustedForIme == adjustedForIme) {
+ return;
+ }
+ mAdjustedForIme = adjustedForIme;
+ updateTouchable();
+ }
+
+ private void updateTouchable() {
+ mWindowManager.setTouchable(!mAdjustedForIme);
+ }
+
+ /**
+ * Workaround for b/62528361, at the time recents has drawn, it may happen before a
+ * configuration change to the Divider, and internally, the event will be posted to the
+ * subscriber, or DividerView, which has been removed and prevented from resizing. Instead,
+ * register the event handler here and proxy the event to the current DividerView.
+ */
+ public void onRecentsDrawn() {
+ if (mView != null) {
+ mView.onRecentsDrawn();
+ }
+ }
+
+ /** Called when there's an activity forced resizable. */
+ public void onActivityForcedResizable(String packageName, int taskId, int reason) {
+ mForcedResizableController.activityForcedResizable(packageName, taskId, reason);
+ }
+
+ /** Called when there's an activity dismissing split screen. */
+ public void onActivityDismissingSplitScreen() {
+ mForcedResizableController.activityDismissingSplitScreen();
+ }
+
+ /** Called when there's an activity launch on secondary display failed. */
+ public void onActivityLaunchOnSecondaryDisplayFailed() {
+ mForcedResizableController.activityLaunchOnSecondaryDisplayFailed();
+ }
+
+ /** Called when there's a task undocking. */
+ public void onUndockingTask() {
+ if (mView != null) {
+ mView.onUndockingTask();
+ }
+ }
+
+ /** Called when the first docked animation frame rendered. */
+ public void onDockedFirstAnimationFrame() {
+ if (mView != null) {
+ mView.onDockedFirstAnimationFrame();
+ }
+ }
+
+ /** Called when top task docked. */
+ public void onDockedTopTask() {
+ if (mView != null) {
+ mView.onDockedTopTask();
+ }
+ }
+
+ /** Called when app transition finished. */
+ public void onAppTransitionFinished() {
+ if (mView == null) {
+ return;
+ }
+ mForcedResizableController.onAppTransitionFinished();
+ }
+
+ /** Dumps current status of Split Screen. */
+ public void dump(PrintWriter pw) {
+ pw.print(" mVisible="); pw.println(mVisible);
+ pw.print(" mMinimized="); pw.println(mMinimized);
+ pw.print(" mAdjustedForIme="); pw.println(mAdjustedForIme);
+ }
+
+ long getAnimDuration() {
+ float transitionScale = Settings.Global.getFloat(mContext.getContentResolver(),
+ Settings.Global.TRANSITION_ANIMATION_SCALE,
+ mContext.getResources().getFloat(
+ com.android.internal.R.dimen
+ .config_appTransitionAnimationDurationScaleDefault));
+ final long transitionDuration = DEFAULT_APP_TRANSITION_DURATION;
+ return (long) (transitionDuration * transitionScale);
+ }
+
+ /** Registers listener that gets called whenever the existence of the divider changes. */
+ public void registerInSplitScreenListener(Consumer<Boolean> listener) {
+ listener.accept(isDividerVisible());
+ synchronized (mDockedStackExistsListeners) {
+ mDockedStackExistsListeners.add(new WeakReference<>(listener));
+ }
+ }
+
+ @Override
+ public void registerBoundsChangeListener(BiConsumer<Rect, Rect> listener) {
+ synchronized (mBoundsChangedListeners) {
+ mBoundsChangedListeners.add(new WeakReference<>(listener));
+ }
+ }
+
+ /** Notifies the bounds of split screen changed. */
+ void notifyBoundsChanged(Rect secondaryWindowBounds, Rect secondaryWindowInsets) {
+ synchronized (mBoundsChangedListeners) {
+ mBoundsChangedListeners.removeIf(wf -> {
+ BiConsumer<Rect, Rect> l = wf.get();
+ if (l != null) l.accept(secondaryWindowBounds, secondaryWindowInsets);
+ return l == null;
+ });
+ }
+ }
+
+ void startEnterSplit() {
+ update(mDisplayController.getDisplayContext(
+ mContext.getDisplayId()).getResources().getConfiguration());
+ // Set resizable directly here because applyEnterSplit already resizes home stack.
+ mHomeStackResizable = mWindowManagerProxy.applyEnterSplit(mSplits, mSplitLayout);
+ }
+
+ void startDismissSplit() {
+ mWindowManagerProxy.applyDismissSplit(mSplits, mSplitLayout, true /* dismissOrMaximize */);
+ updateVisibility(false /* visible */);
+ mMinimized = false;
+ removeDivider();
+ mImePositionProcessor.reset();
+ }
+
+ void ensureMinimizedSplit() {
+ setHomeMinimized(true /* minimized */);
+ if (mView != null && !isDividerVisible()) {
+ // Wasn't in split-mode yet, so enter now.
+ if (DEBUG) {
+ Slog.d(TAG, " entering split mode with minimized=true");
+ }
+ updateVisibility(true /* visible */);
+ }
+ }
+
+ void ensureNormalSplit() {
+ setHomeMinimized(false /* minimized */);
+ if (mView != null && !isDividerVisible()) {
+ // Wasn't in split-mode, so enter now.
+ if (DEBUG) {
+ Slog.d(TAG, " enter split mode unminimized ");
+ }
+ updateVisibility(true /* visible */);
+ }
+ }
+
+ SplitDisplayLayout getSplitLayout() {
+ return mSplitLayout;
+ }
+
+ WindowManagerProxy getWmProxy() {
+ return mWindowManagerProxy;
+ }
+
+ /** @return the container token for the secondary split root task. */
+ public WindowContainerToken getSecondaryRoot() {
+ if (mSplits == null || mSplits.mSecondary == null) {
+ return null;
+ }
+ return mSplits.mSecondary.token;
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenTaskOrganizer.java
new file mode 100644
index 000000000000..30bc43b0292f
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenTaskOrganizer.java
@@ -0,0 +1,232 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
+import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
+import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY;
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import android.app.ActivityManager.RunningTaskInfo;
+import android.app.WindowConfiguration;
+import android.graphics.Rect;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.Display;
+import android.view.SurfaceControl;
+import android.view.SurfaceSession;
+
+import com.android.wm.shell.ShellTaskOrganizer;
+
+class SplitScreenTaskOrganizer implements ShellTaskOrganizer.TaskListener {
+ private static final String TAG = "SplitScreenTaskOrg";
+ private static final boolean DEBUG = SplitScreenController.DEBUG;
+
+ private final ShellTaskOrganizer mTaskOrganizer;
+
+ RunningTaskInfo mPrimary;
+ RunningTaskInfo mSecondary;
+ SurfaceControl mPrimarySurface;
+ SurfaceControl mSecondarySurface;
+ SurfaceControl mPrimaryDim;
+ SurfaceControl mSecondaryDim;
+ Rect mHomeBounds = new Rect();
+ final SplitScreenController mSplitScreenController;
+ private boolean mSplitScreenSupported = false;
+
+ final SurfaceSession mSurfaceSession = new SurfaceSession();
+
+ SplitScreenTaskOrganizer(SplitScreenController splitScreenController,
+ ShellTaskOrganizer shellTaskOrganizer) {
+ mSplitScreenController = splitScreenController;
+ mTaskOrganizer = shellTaskOrganizer;
+ mTaskOrganizer.addListener(this, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY,
+ WINDOWING_MODE_SPLIT_SCREEN_SECONDARY);
+ }
+
+ void init() throws RemoteException {
+ synchronized (this) {
+ try {
+ mPrimary = mTaskOrganizer.createRootTask(Display.DEFAULT_DISPLAY,
+ WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
+ mSecondary = mTaskOrganizer.createRootTask(Display.DEFAULT_DISPLAY,
+ WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY);
+ } catch (Exception e) {
+ // teardown to prevent callbacks
+ mTaskOrganizer.removeListener(this);
+ throw e;
+ }
+ }
+ }
+
+ boolean isSplitScreenSupported() {
+ return mSplitScreenSupported;
+ }
+
+ SurfaceControl.Transaction getTransaction() {
+ return mSplitScreenController.mTransactionPool.acquire();
+ }
+
+ void releaseTransaction(SurfaceControl.Transaction t) {
+ mSplitScreenController.mTransactionPool.release(t);
+ }
+
+ @Override
+ public void onTaskAppeared(RunningTaskInfo taskInfo, SurfaceControl leash) {
+ synchronized (this) {
+ if (mPrimary == null || mSecondary == null) {
+ Log.w(TAG, "Received onTaskAppeared before creating root tasks " + taskInfo);
+ return;
+ }
+
+ if (taskInfo.token.equals(mPrimary.token)) {
+ mPrimarySurface = leash;
+ } else if (taskInfo.token.equals(mSecondary.token)) {
+ mSecondarySurface = leash;
+ }
+
+ if (!mSplitScreenSupported && mPrimarySurface != null && mSecondarySurface != null) {
+ mSplitScreenSupported = true;
+
+ // Initialize dim surfaces:
+ mPrimaryDim = new SurfaceControl.Builder(mSurfaceSession)
+ .setParent(mPrimarySurface).setColorLayer()
+ .setName("Primary Divider Dim")
+ .setCallsite("SplitScreenTaskOrganizer.onTaskAppeared")
+ .build();
+ mSecondaryDim = new SurfaceControl.Builder(mSurfaceSession)
+ .setParent(mSecondarySurface).setColorLayer()
+ .setName("Secondary Divider Dim")
+ .setCallsite("SplitScreenTaskOrganizer.onTaskAppeared")
+ .build();
+ SurfaceControl.Transaction t = getTransaction();
+ t.setLayer(mPrimaryDim, Integer.MAX_VALUE);
+ t.setColor(mPrimaryDim, new float[]{0f, 0f, 0f});
+ t.setLayer(mSecondaryDim, Integer.MAX_VALUE);
+ t.setColor(mSecondaryDim, new float[]{0f, 0f, 0f});
+ t.apply();
+ releaseTransaction(t);
+ }
+ }
+ }
+
+ @Override
+ public void onTaskVanished(RunningTaskInfo taskInfo) {
+ synchronized (this) {
+ final boolean isPrimaryTask = mPrimary != null
+ && taskInfo.token.equals(mPrimary.token);
+ final boolean isSecondaryTask = mSecondary != null
+ && taskInfo.token.equals(mSecondary.token);
+
+ if (mSplitScreenSupported && (isPrimaryTask || isSecondaryTask)) {
+ mSplitScreenSupported = false;
+
+ SurfaceControl.Transaction t = getTransaction();
+ t.remove(mPrimaryDim);
+ t.remove(mSecondaryDim);
+ t.remove(mPrimarySurface);
+ t.remove(mSecondarySurface);
+ t.apply();
+ releaseTransaction(t);
+
+ mSplitScreenController.onTaskVanished();
+ }
+ }
+ }
+
+ @Override
+ public void onTaskInfoChanged(RunningTaskInfo taskInfo) {
+ if (taskInfo.displayId != DEFAULT_DISPLAY) {
+ return;
+ }
+ mSplitScreenController.post(() -> handleTaskInfoChanged(taskInfo));
+ }
+
+ /**
+ * This is effectively a finite state machine which moves between the various split-screen
+ * presentations based on the contents of the split regions.
+ */
+ private void handleTaskInfoChanged(RunningTaskInfo info) {
+ if (!mSplitScreenSupported) {
+ // This shouldn't happen; but apparently there is a chance that SysUI crashes without
+ // system server receiving binder-death (or maybe it receives binder-death too late?).
+ // In this situation, when sys-ui restarts, the split root-tasks will still exist so
+ // there is a small window of time during init() where WM might send messages here
+ // before init() fails. So, avoid a cycle of crashes by returning early.
+ Log.e(TAG, "Got handleTaskInfoChanged when not initialized: " + info);
+ return;
+ }
+ final boolean secondaryImpliedMinimize = mSecondary.topActivityType == ACTIVITY_TYPE_HOME
+ || (mSecondary.topActivityType == ACTIVITY_TYPE_RECENTS
+ && mSplitScreenController.isHomeStackResizable());
+ final boolean primaryWasEmpty = mPrimary.topActivityType == ACTIVITY_TYPE_UNDEFINED;
+ final boolean secondaryWasEmpty = mSecondary.topActivityType == ACTIVITY_TYPE_UNDEFINED;
+ if (info.token.asBinder() == mPrimary.token.asBinder()) {
+ mPrimary = info;
+ } else if (info.token.asBinder() == mSecondary.token.asBinder()) {
+ mSecondary = info;
+ }
+ final boolean primaryIsEmpty = mPrimary.topActivityType == ACTIVITY_TYPE_UNDEFINED;
+ final boolean secondaryIsEmpty = mSecondary.topActivityType == ACTIVITY_TYPE_UNDEFINED;
+ final boolean secondaryImpliesMinimize = mSecondary.topActivityType == ACTIVITY_TYPE_HOME
+ || (mSecondary.topActivityType == ACTIVITY_TYPE_RECENTS
+ && mSplitScreenController.isHomeStackResizable());
+ if (DEBUG) {
+ Log.d(TAG, "onTaskInfoChanged " + mPrimary + " " + mSecondary);
+ }
+ if (primaryIsEmpty == primaryWasEmpty && secondaryWasEmpty == secondaryIsEmpty
+ && secondaryImpliedMinimize == secondaryImpliesMinimize) {
+ // No relevant changes
+ return;
+ }
+ if (primaryIsEmpty || secondaryIsEmpty) {
+ // At-least one of the splits is empty which means we are currently transitioning
+ // into or out-of split-screen mode.
+ if (DEBUG) {
+ Log.d(TAG, " at-least one split empty " + mPrimary.topActivityType
+ + " " + mSecondary.topActivityType);
+ }
+ if (mSplitScreenController.isDividerVisible()) {
+ // Was in split-mode, which means we are leaving split, so continue that.
+ // This happens when the stack in the primary-split is dismissed.
+ if (DEBUG) {
+ Log.d(TAG, " was in split, so this means leave it "
+ + mPrimary.topActivityType + " " + mSecondary.topActivityType);
+ }
+ mSplitScreenController.startDismissSplit();
+ } else if (!primaryIsEmpty && primaryWasEmpty && secondaryWasEmpty) {
+ // Wasn't in split-mode (both were empty), but now that the primary split is
+ // populated, we should fully enter split by moving everything else into secondary.
+ // This just tells window-manager to reparent things, the UI will respond
+ // when it gets new task info for the secondary split.
+ if (DEBUG) {
+ Log.d(TAG, " was not in split, but primary is populated, so enter it");
+ }
+ mSplitScreenController.startEnterSplit();
+ }
+ } else if (secondaryImpliesMinimize) {
+ // Both splits are populated but the secondary split has a home/recents stack on top,
+ // so enter minimized mode.
+ mSplitScreenController.ensureMinimizedSplit();
+ } else {
+ // Both splits are populated by normal activities, so make sure we aren't minimized.
+ mSplitScreenController.ensureNormalSplit();
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/WindowManagerProxy.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/WindowManagerProxy.java
new file mode 100644
index 000000000000..25827cdb9e24
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/WindowManagerProxy.java
@@ -0,0 +1,369 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.splitscreen;
+
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
+import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
+import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
+import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
+import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import android.annotation.NonNull;
+import android.app.ActivityManager;
+import android.app.ActivityTaskManager;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.Display;
+import android.view.SurfaceControl;
+import android.view.WindowManagerGlobal;
+import android.window.TaskOrganizer;
+import android.window.WindowContainerToken;
+import android.window.WindowContainerTransaction;
+import android.window.WindowOrganizer;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.wm.shell.common.SyncTransactionQueue;
+import com.android.wm.shell.common.TransactionPool;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * Proxy to simplify calls into window manager/activity manager
+ */
+class WindowManagerProxy {
+
+ private static final String TAG = "WindowManagerProxy";
+ private static final int[] HOME_AND_RECENTS = {ACTIVITY_TYPE_HOME, ACTIVITY_TYPE_RECENTS};
+
+ @GuardedBy("mDockedRect")
+ private final Rect mDockedRect = new Rect();
+
+ private final Rect mTmpRect1 = new Rect();
+
+ @GuardedBy("mDockedRect")
+ private final Rect mTouchableRegion = new Rect();
+
+ private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
+
+ private final SyncTransactionQueue mSyncTransactionQueue;
+
+ private final Runnable mSetTouchableRegionRunnable = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ synchronized (mDockedRect) {
+ mTmpRect1.set(mTouchableRegion);
+ }
+ WindowManagerGlobal.getWindowManagerService().setDockedStackDividerTouchRegion(
+ mTmpRect1);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to set touchable region: " + e);
+ }
+ }
+ };
+
+ private final TaskOrganizer mTaskOrganizer;
+
+ WindowManagerProxy(TransactionPool transactionPool, Handler handler,
+ TaskOrganizer taskOrganizer) {
+ mSyncTransactionQueue = new SyncTransactionQueue(transactionPool, handler);
+ mTaskOrganizer = taskOrganizer;
+ }
+
+ void dismissOrMaximizeDocked(final SplitScreenTaskOrganizer tiles, SplitDisplayLayout layout,
+ final boolean dismissOrMaximize) {
+ mExecutor.execute(() -> applyDismissSplit(tiles, layout, dismissOrMaximize));
+ }
+
+ public void setResizing(final boolean resizing) {
+ mExecutor.execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ ActivityTaskManager.getService().setSplitScreenResizing(resizing);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error calling setDockedStackResizing: " + e);
+ }
+ }
+ });
+ }
+
+ /** Sets a touch region */
+ public void setTouchRegion(Rect region) {
+ synchronized (mDockedRect) {
+ mTouchableRegion.set(region);
+ }
+ mExecutor.execute(mSetTouchableRegionRunnable);
+ }
+
+ void applyResizeSplits(int position, SplitDisplayLayout splitLayout) {
+ WindowContainerTransaction t = new WindowContainerTransaction();
+ splitLayout.resizeSplits(position, t);
+ new WindowOrganizer().applyTransaction(t);
+ }
+
+ private boolean getHomeAndRecentsTasks(List<ActivityManager.RunningTaskInfo> out,
+ WindowContainerToken parent) {
+ boolean resizable = false;
+ List<ActivityManager.RunningTaskInfo> rootTasks = parent == null
+ ? mTaskOrganizer.getRootTasks(Display.DEFAULT_DISPLAY, HOME_AND_RECENTS)
+ : mTaskOrganizer.getChildTasks(parent, HOME_AND_RECENTS);
+ for (int i = 0, n = rootTasks.size(); i < n; ++i) {
+ final ActivityManager.RunningTaskInfo ti = rootTasks.get(i);
+ out.add(ti);
+ if (ti.topActivityType == ACTIVITY_TYPE_HOME) {
+ resizable = ti.isResizeable;
+ }
+ }
+ return resizable;
+ }
+
+ /**
+ * Assign a fixed override-bounds to home tasks that reflect their geometry while the primary
+ * split is minimized. This actually "sticks out" of the secondary split area, but when in
+ * minimized mode, the secondary split gets a 'negative' crop to expose it.
+ */
+ boolean applyHomeTasksMinimized(SplitDisplayLayout layout, WindowContainerToken parent,
+ @NonNull WindowContainerTransaction wct) {
+ // Resize the home/recents stacks to the larger minimized-state size
+ final Rect homeBounds;
+ final ArrayList<ActivityManager.RunningTaskInfo> homeStacks = new ArrayList<>();
+ boolean isHomeResizable = getHomeAndRecentsTasks(homeStacks, parent);
+ if (isHomeResizable) {
+ homeBounds = layout.calcResizableMinimizedHomeStackBounds();
+ } else {
+ // home is not resizable, so lock it to its inherent orientation size.
+ homeBounds = new Rect(0, 0, 0, 0);
+ for (int i = homeStacks.size() - 1; i >= 0; --i) {
+ if (homeStacks.get(i).topActivityType == ACTIVITY_TYPE_HOME) {
+ final int orient = homeStacks.get(i).configuration.orientation;
+ final boolean displayLandscape = layout.mDisplayLayout.isLandscape();
+ final boolean isLandscape = orient == ORIENTATION_LANDSCAPE
+ || (orient == ORIENTATION_UNDEFINED && displayLandscape);
+ homeBounds.right = isLandscape == displayLandscape
+ ? layout.mDisplayLayout.width() : layout.mDisplayLayout.height();
+ homeBounds.bottom = isLandscape == displayLandscape
+ ? layout.mDisplayLayout.height() : layout.mDisplayLayout.width();
+ break;
+ }
+ }
+ }
+ for (int i = homeStacks.size() - 1; i >= 0; --i) {
+ // For non-resizable homes, the minimized size is actually the fullscreen-size. As a
+ // result, we don't minimize for recents since it only shows half-size screenshots.
+ if (!isHomeResizable) {
+ if (homeStacks.get(i).topActivityType == ACTIVITY_TYPE_RECENTS) {
+ continue;
+ }
+ wct.setWindowingMode(homeStacks.get(i).token, WINDOWING_MODE_FULLSCREEN);
+ }
+ wct.setBounds(homeStacks.get(i).token, homeBounds);
+ }
+ layout.mTiles.mHomeBounds.set(homeBounds);
+ return isHomeResizable;
+ }
+
+ /**
+ * Finishes entering split-screen by reparenting all FULLSCREEN tasks into the secondary split.
+ * This assumes there is already something in the primary split since that is usually what
+ * triggers a call to this. In the same transaction, this overrides the home task bounds via
+ * {@link #applyHomeTasksMinimized}.
+ *
+ * @return whether the home stack is resizable
+ */
+ boolean applyEnterSplit(SplitScreenTaskOrganizer tiles, SplitDisplayLayout layout) {
+ // Set launchtile first so that any stack created after
+ // getAllRootTaskInfos and before reparent (even if unlikely) are placed
+ // correctly.
+ mTaskOrganizer.setLaunchRoot(DEFAULT_DISPLAY, tiles.mSecondary.token);
+ List<ActivityManager.RunningTaskInfo> rootTasks =
+ mTaskOrganizer.getRootTasks(DEFAULT_DISPLAY, null /* activityTypes */);
+ WindowContainerTransaction wct = new WindowContainerTransaction();
+ if (rootTasks.isEmpty()) {
+ return false;
+ }
+ ActivityManager.RunningTaskInfo topHomeTask = null;
+ for (int i = rootTasks.size() - 1; i >= 0; --i) {
+ final ActivityManager.RunningTaskInfo rootTask = rootTasks.get(i);
+ // Only move resizeable task to split secondary. However, we have an exception
+ // for non-resizable home because we will minimize to show it.
+ if (!rootTask.isResizeable && rootTask.topActivityType != ACTIVITY_TYPE_HOME) {
+ continue;
+ }
+ // Only move fullscreen tasks to split secondary.
+ if (rootTask.configuration.windowConfiguration.getWindowingMode()
+ != WINDOWING_MODE_FULLSCREEN) {
+ continue;
+ }
+ // Since this iterates from bottom to top, update topHomeTask for every fullscreen task
+ // so it will be left with the status of the top one.
+ topHomeTask = isHomeOrRecentTask(rootTask) ? rootTask : null;
+ wct.reparent(rootTask.token, tiles.mSecondary.token, true /* onTop */);
+ }
+ // Move the secondary split-forward.
+ wct.reorder(tiles.mSecondary.token, true /* onTop */);
+ boolean isHomeResizable = applyHomeTasksMinimized(layout, null /* parent */, wct);
+ if (topHomeTask != null) {
+ // Translate/update-crop of secondary out-of-band with sync transaction -- Until BALST
+ // is enabled, this temporarily syncs the home surface position with offset until
+ // sync transaction finishes.
+ wct.setBoundsChangeTransaction(topHomeTask.token, tiles.mHomeBounds);
+ }
+ applySyncTransaction(wct);
+ return isHomeResizable;
+ }
+
+ boolean isHomeOrRecentTask(ActivityManager.RunningTaskInfo ti) {
+ final int atype = ti.configuration.windowConfiguration.getActivityType();
+ return atype == ACTIVITY_TYPE_HOME || atype == ACTIVITY_TYPE_RECENTS;
+ }
+
+ /**
+ * Reparents all tile members back to their display and resets home task override bounds.
+ * @param dismissOrMaximize When {@code true} this resolves the split by closing the primary
+ * split (thus resulting in the top of the secondary split becoming
+ * fullscreen. {@code false} resolves the other way.
+ */
+ void applyDismissSplit(SplitScreenTaskOrganizer tiles, SplitDisplayLayout layout,
+ boolean dismissOrMaximize) {
+ // Set launch root first so that any task created after getChildContainers and
+ // before reparent (pretty unlikely) are put into fullscreen.
+ mTaskOrganizer.setLaunchRoot(Display.DEFAULT_DISPLAY, null);
+ // TODO(task-org): Once task-org is more complete, consider using Appeared/Vanished
+ // plus specific APIs to clean this up.
+ List<ActivityManager.RunningTaskInfo> primaryChildren =
+ mTaskOrganizer.getChildTasks(tiles.mPrimary.token, null /* activityTypes */);
+ List<ActivityManager.RunningTaskInfo> secondaryChildren =
+ mTaskOrganizer.getChildTasks(tiles.mSecondary.token, null /* activityTypes */);
+ // In some cases (eg. non-resizable is launched), system-server will leave split-screen.
+ // as a result, the above will not capture any tasks; yet, we need to clean-up the
+ // home task bounds.
+ List<ActivityManager.RunningTaskInfo> freeHomeAndRecents =
+ mTaskOrganizer.getRootTasks(DEFAULT_DISPLAY, HOME_AND_RECENTS);
+ // Filter out the root split tasks
+ freeHomeAndRecents.removeIf(p -> p.token.equals(tiles.mSecondary.token)
+ || p.token.equals(tiles.mPrimary.token));
+
+ if (primaryChildren.isEmpty() && secondaryChildren.isEmpty()
+ && freeHomeAndRecents.isEmpty()) {
+ return;
+ }
+ WindowContainerTransaction wct = new WindowContainerTransaction();
+ if (dismissOrMaximize) {
+ // Dismissing, so move all primary split tasks first
+ for (int i = primaryChildren.size() - 1; i >= 0; --i) {
+ wct.reparent(primaryChildren.get(i).token, null /* parent */,
+ true /* onTop */);
+ }
+ boolean homeOnTop = false;
+ // Don't need to worry about home tasks because they are already in the "proper"
+ // order within the secondary split.
+ for (int i = secondaryChildren.size() - 1; i >= 0; --i) {
+ final ActivityManager.RunningTaskInfo ti = secondaryChildren.get(i);
+ wct.reparent(ti.token, null /* parent */, true /* onTop */);
+ if (isHomeOrRecentTask(ti)) {
+ wct.setBounds(ti.token, null);
+ wct.setWindowingMode(ti.token, WINDOWING_MODE_UNDEFINED);
+ if (i == 0) {
+ homeOnTop = true;
+ }
+ }
+ }
+ if (homeOnTop) {
+ // Translate/update-crop of secondary out-of-band with sync transaction -- instead
+ // play this in sync with new home-app frame because until BALST is enabled this
+ // shows up on screen before the syncTransaction returns.
+ // We only have access to the secondary root surface, though, so in order to
+ // position things properly, we have to take into account the existing negative
+ // offset/crop of the minimized-home task.
+ final boolean landscape = layout.mDisplayLayout.isLandscape();
+ final int posX = landscape ? layout.mSecondary.left - tiles.mHomeBounds.left
+ : layout.mSecondary.left;
+ final int posY = landscape ? layout.mSecondary.top
+ : layout.mSecondary.top - tiles.mHomeBounds.top;
+ final SurfaceControl.Transaction sft = new SurfaceControl.Transaction();
+ sft.setPosition(tiles.mSecondarySurface, posX, posY);
+ final Rect crop = new Rect(0, 0, layout.mDisplayLayout.width(),
+ layout.mDisplayLayout.height());
+ crop.offset(-posX, -posY);
+ sft.setWindowCrop(tiles.mSecondarySurface, crop);
+ wct.setBoundsChangeTransaction(tiles.mSecondary.token, sft);
+ }
+ } else {
+ // Maximize, so move non-home secondary split first
+ for (int i = secondaryChildren.size() - 1; i >= 0; --i) {
+ if (isHomeOrRecentTask(secondaryChildren.get(i))) {
+ continue;
+ }
+ wct.reparent(secondaryChildren.get(i).token, null /* parent */,
+ true /* onTop */);
+ }
+ // Find and place home tasks in-between. This simulates the fact that there was
+ // nothing behind the primary split's tasks.
+ for (int i = secondaryChildren.size() - 1; i >= 0; --i) {
+ final ActivityManager.RunningTaskInfo ti = secondaryChildren.get(i);
+ if (isHomeOrRecentTask(ti)) {
+ wct.reparent(ti.token, null /* parent */, true /* onTop */);
+ // reset bounds and mode too
+ wct.setBounds(ti.token, null);
+ wct.setWindowingMode(ti.token, WINDOWING_MODE_UNDEFINED);
+ }
+ }
+ for (int i = primaryChildren.size() - 1; i >= 0; --i) {
+ wct.reparent(primaryChildren.get(i).token, null /* parent */,
+ true /* onTop */);
+ }
+ }
+ for (int i = freeHomeAndRecents.size() - 1; i >= 0; --i) {
+ wct.setBounds(freeHomeAndRecents.get(i).token, null);
+ wct.setWindowingMode(freeHomeAndRecents.get(i).token, WINDOWING_MODE_UNDEFINED);
+ }
+ // Reset focusable to true
+ wct.setFocusable(tiles.mPrimary.token, true /* focusable */);
+ applySyncTransaction(wct);
+ }
+
+ /**
+ * Utility to apply a sync transaction serially with other sync transactions.
+ *
+ * @see SyncTransactionQueue#queue
+ */
+ void applySyncTransaction(WindowContainerTransaction wct) {
+ mSyncTransactionQueue.queue(wct);
+ }
+
+ /**
+ * @see SyncTransactionQueue#queueIfWaiting
+ */
+ boolean queueSyncTransactionIfWaiting(WindowContainerTransaction wct) {
+ return mSyncTransactionQueue.queueIfWaiting(wct);
+ }
+
+ /**
+ * @see SyncTransactionQueue#runInSync
+ */
+ void runInSync(SyncTransactionQueue.TransactionRunnable runnable) {
+ mSyncTransactionQueue.runInSync(runnable);
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/README.md b/libs/WindowManager/Shell/tests/README.md
new file mode 100644
index 000000000000..c19db76a358c
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/README.md
@@ -0,0 +1,15 @@
+# WM Shell Test
+
+This contains all tests written for WM (WindowManager) Shell and it's currently
+divided into 3 categories
+
+- unittest, tests against individual functions, usually @SmallTest and do not
+ require UI automation nor real device to run
+- integration, this maybe a mix of functional and integration tests. Contains
+ tests verify the WM Shell as a whole, like talking to WM core. This usually
+ involves mocking the window manager service or even talking to the real one.
+ Due to this nature, test cases in this package is normally annotated as
+ @LargeTest and runs with UI automation on real device
+- flicker, similar to functional tests with its sole focus on flickerness. See
+ [WM Shell Flicker Test Package](http://cs/android/framework/base/libs/WindowManager/Shell/tests/flicker/)
+ for more details
diff --git a/libs/WindowManager/Shell/tests/flicker/Android.bp b/libs/WindowManager/Shell/tests/flicker/Android.bp
new file mode 100644
index 000000000000..587902221826
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/Android.bp
@@ -0,0 +1,34 @@
+//
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+android_test {
+ name: "WMShellFlickerTests",
+ srcs: ["src/**/*.java", "src/**/*.kt"],
+ manifest: "AndroidManifest.xml",
+ test_config: "AndroidTest.xml",
+ platform_apis: true,
+ certificate: "platform",
+ test_suites: ["device-tests"],
+ libs: ["android.test.runner"],
+ static_libs: [
+ "androidx.test.ext.junit",
+ "flickerlib",
+ "truth-prebuilt",
+ "app-helpers-core",
+ "launcher-helper-lib",
+ "launcher-aosp-tapl"
+ ],
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/AndroidManifest.xml b/libs/WindowManager/Shell/tests/flicker/AndroidManifest.xml
new file mode 100644
index 000000000000..8b2f6681554a
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/AndroidManifest.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.wm.shell.flicker">
+
+ <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="29"/>
+ <!-- Read and write traces from external storage -->
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+ <!-- Write secure settings -->
+ <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
+ <!-- Capture screen contents -->
+ <uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" />
+ <!-- Enable / Disable tracing !-->
+ <uses-permission android:name="android.permission.DUMP" />
+ <!-- Run layers trace -->
+ <uses-permission android:name="android.permission.HARDWARE_TEST"/>
+ <!-- Workaround grant runtime permission exception from b/152733071 -->
+ <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/>
+ <uses-permission android:name="android.permission.READ_LOGS"/>
+ <application>
+ <uses-library android:name="android.test.runner"/>
+ </application>
+
+ <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.wm.shell.flicker"
+ android:label="WindowManager Shell Flicker Tests">
+ </instrumentation>
+</manifest>
diff --git a/libs/WindowManager/Shell/tests/flicker/AndroidTest.xml b/libs/WindowManager/Shell/tests/flicker/AndroidTest.xml
new file mode 100644
index 000000000000..526fc502c0fb
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/AndroidTest.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright 2020 Google Inc. All Rights Reserved.
+ -->
+<configuration description="Runs WindowManager Shell Flicker Tests">
+ <option name="test-tag" value="FlickerTests" />
+ <target_preparer class="com.android.tradefed.targetprep.DeviceSetup">
+ <!-- keeps the screen on during tests -->
+ <option name="screen-always-on" value="on" />
+ <!-- prevents the phone from restarting -->
+ <option name="force-skip-system-props" value="true" />
+ <!-- set WM tracing verbose level to all -->
+ <option name="run-command" value="cmd window tracing level all" />
+ <!-- inform WM to log all transactions -->
+ <option name="run-command" value="cmd window tracing transaction" />
+ <!-- restart launcher to activate TAPL -->
+ <option name="run-command" value="setprop ro.test_harness 1 ; am force-stop com.google.android.apps.nexuslauncher" />
+ </target_preparer>
+ <target_preparer class="com.android.tradefed.targetprep.DeviceCleaner">
+ <!-- reboot the device to teardown any crashed tests -->
+ <option name="cleanup-action" value="REBOOT" />
+ </target_preparer>
+ <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true"/>
+ <option name="test-file-name" value="WMShellFlickerTests.apk"/>
+ <option name="test-file-name" value="WMShellFlickerTestApp.apk" />
+ </target_preparer>
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest">
+ <option name="package" value="com.android.wm.shell.flicker"/>
+ <option name="exclude-annotation" value="androidx.test.filters.FlakyTest" />
+ <option name="shell-timeout" value="6600s" />
+ <option name="test-timeout" value="6000s" />
+ <option name="hidden-api-checks" value="false" />
+ </test>
+ <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
+ <option name="directory-keys" value="/storage/emulated/0/Android/data/com.android.wm.shell.flicker/files" />
+ <option name="collect-on-run-ended-only" value="true" />
+ <option name="clean-up" value="true" />
+ </metrics_collector>
+</configuration>
diff --git a/libs/WindowManager/Shell/tests/flicker/README.md b/libs/WindowManager/Shell/tests/flicker/README.md
new file mode 100644
index 000000000000..4502d498a65b
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/README.md
@@ -0,0 +1,10 @@
+# WM Shell Flicker Test Package
+
+Please reference the following links
+
+- [Introduction to Flicker Test Library](http://cs/android/platform_testing/libraries/flicker/)
+- [Flicker Test in frameworks/base](http://cs/android/frameworks/base/tests/FlickerTests/)
+
+on what is Flicker Test and how to write a Flicker Test
+
+To run the Flicker Tests for WM Shell, simply run `atest WMShellFlickerTests`
diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/CommonAssertions.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/CommonAssertions.kt
new file mode 100644
index 000000000000..4ff2bfca3a4a
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/CommonAssertions.kt
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.flicker
+
+import com.android.server.wm.flicker.dsl.EventLogAssertion
+import com.android.server.wm.flicker.dsl.LayersAssertion
+import com.android.server.wm.flicker.dsl.WmAssertion
+import com.android.server.wm.flicker.helpers.WindowUtils
+
+@JvmOverloads
+fun WmAssertion.statusBarWindowIsAlwaysVisible(
+ bugId: Int = 0,
+ enabled: Boolean = bugId == 0
+) {
+ all("statusBarWindowIsAlwaysVisible", enabled, bugId) {
+ this.showsAboveAppWindow(FlickerTestBase.STATUS_BAR_WINDOW_TITLE)
+ }
+}
+
+@JvmOverloads
+fun WmAssertion.navBarWindowIsAlwaysVisible(
+ bugId: Int = 0,
+ enabled: Boolean = bugId == 0
+) {
+ all("navBarWindowIsAlwaysVisible", enabled, bugId) {
+ this.showsAboveAppWindow(FlickerTestBase.NAVIGATION_BAR_WINDOW_TITLE)
+ }
+}
+
+@JvmOverloads
+fun LayersAssertion.noUncoveredRegions(
+ beginRotation: Int,
+ endRotation: Int = beginRotation,
+ allStates: Boolean = true,
+ bugId: Int = 0,
+ enabled: Boolean = bugId == 0
+) {
+ val startingBounds = WindowUtils.getDisplayBounds(beginRotation)
+ val endingBounds = WindowUtils.getDisplayBounds(endRotation)
+ if (allStates) {
+ all("noUncoveredRegions", enabled, bugId) {
+ if (startingBounds == endingBounds) {
+ this.coversAtLeastRegion(startingBounds)
+ } else {
+ this.coversAtLeastRegion(startingBounds)
+ .then()
+ .coversAtLeastRegion(endingBounds)
+ }
+ }
+ } else {
+ start("noUncoveredRegions_StartingPos") {
+ this.coversAtLeastRegion(startingBounds)
+ }
+ end("noUncoveredRegions_EndingPos") {
+ this.coversAtLeastRegion(endingBounds)
+ }
+ }
+}
+
+@JvmOverloads
+fun LayersAssertion.navBarLayerIsAlwaysVisible(
+ bugId: Int = 0,
+ enabled: Boolean = bugId == 0
+) {
+ all("navBarLayerIsAlwaysVisible", enabled, bugId) {
+ this.showsLayer(FlickerTestBase.NAVIGATION_BAR_WINDOW_TITLE)
+ }
+}
+
+@JvmOverloads
+fun LayersAssertion.statusBarLayerIsAlwaysVisible(
+ bugId: Int = 0,
+ enabled: Boolean = bugId == 0
+) {
+ all("statusBarLayerIsAlwaysVisible", enabled, bugId) {
+ this.showsLayer(FlickerTestBase.STATUS_BAR_WINDOW_TITLE)
+ }
+}
+
+@JvmOverloads
+fun LayersAssertion.navBarLayerRotatesAndScales(
+ beginRotation: Int,
+ endRotation: Int = beginRotation,
+ bugId: Int = 0,
+ enabled: Boolean = bugId == 0
+) {
+ val startingPos = WindowUtils.getNavigationBarPosition(beginRotation)
+ val endingPos = WindowUtils.getNavigationBarPosition(endRotation)
+
+ start("navBarLayerRotatesAndScales_StartingPos", enabled, bugId) {
+ this.hasVisibleRegion(FlickerTestBase.NAVIGATION_BAR_WINDOW_TITLE, startingPos)
+ }
+ end("navBarLayerRotatesAndScales_EndingPost", enabled, bugId) {
+ this.hasVisibleRegion(FlickerTestBase.NAVIGATION_BAR_WINDOW_TITLE, endingPos)
+ }
+
+ if (startingPos == endingPos) {
+ all("navBarLayerRotatesAndScales", enabled, bugId) {
+ this.hasVisibleRegion(FlickerTestBase.NAVIGATION_BAR_WINDOW_TITLE, startingPos)
+ }
+ }
+}
+
+@JvmOverloads
+fun LayersAssertion.statusBarLayerRotatesScales(
+ beginRotation: Int,
+ endRotation: Int = beginRotation,
+ bugId: Int = 0,
+ enabled: Boolean = bugId == 0
+) {
+ val startingPos = WindowUtils.getStatusBarPosition(beginRotation)
+ val endingPos = WindowUtils.getStatusBarPosition(endRotation)
+
+ start("statusBarLayerRotatesScales_StartingPos", enabled, bugId) {
+ this.hasVisibleRegion(FlickerTestBase.STATUS_BAR_WINDOW_TITLE, startingPos)
+ }
+ end("statusBarLayerRotatesScales_EndingPos", enabled, bugId) {
+ this.hasVisibleRegion(FlickerTestBase.STATUS_BAR_WINDOW_TITLE, endingPos)
+ }
+}
+
+fun EventLogAssertion.focusChanges(
+ vararg windows: String,
+ bugId: Int = 0,
+ enabled: Boolean = bugId == 0
+) {
+ all(enabled = enabled, bugId = bugId) {
+ this.focusChanges(windows)
+ }
+}
+
+fun EventLogAssertion.focusDoesNotChange(
+ bugId: Int = 0,
+ enabled: Boolean = bugId == 0
+) {
+ all(enabled = enabled, bugId = bugId) {
+ this.focusDoesNotChange()
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/FlickerTestBase.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/FlickerTestBase.kt
new file mode 100644
index 000000000000..99f824bb8341
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/FlickerTestBase.kt
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.flicker
+
+import android.os.RemoteException
+import android.os.SystemClock
+import android.platform.helpers.IAppHelper
+import android.view.Surface
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.uiautomator.UiDevice
+import com.android.server.wm.flicker.Flicker
+
+/**
+ * Base class of all Flicker test that performs common functions for all flicker tests:
+ *
+ *
+ * - Caches transitions so that a transition is run once and the transition results are used by
+ * tests multiple times. This is needed for parameterized tests which call the BeforeClass methods
+ * multiple times.
+ * - Keeps track of all test artifacts and deletes ones which do not need to be reviewed.
+ * - Fails tests if results are not available for any test due to jank.
+ */
+abstract class FlickerTestBase {
+ val instrumentation by lazy {
+ InstrumentationRegistry.getInstrumentation()
+ }
+ val uiDevice by lazy {
+ UiDevice.getInstance(instrumentation)
+ }
+
+ /**
+ * Build a test tag for the test
+ * @param testName Name of the transition(s) being tested
+ * @param app App being launcher
+ * @param rotation Initial screen rotation
+ *
+ * @return test tag with pattern <NAME>__<APP>__<ROTATION>
+ </ROTATION></APP></NAME> */
+ protected fun buildTestTag(testName: String, app: IAppHelper, rotation: Int): String {
+ return buildTestTag(
+ testName, app, rotation, rotation, app2 = null, extraInfo = "")
+ }
+
+ /**
+ * Build a test tag for the test
+ * @param testName Name of the transition(s) being tested
+ * @param app App being launcher
+ * @param beginRotation Initial screen rotation
+ * @param endRotation End screen rotation (if any, otherwise use same as initial)
+ *
+ * @return test tag with pattern <NAME>__<APP>__<BEGIN_ROTATION>-<END_ROTATION>
+ </END_ROTATION></BEGIN_ROTATION></APP></NAME> */
+ protected fun buildTestTag(
+ testName: String,
+ app: IAppHelper,
+ beginRotation: Int,
+ endRotation: Int
+ ): String {
+ return buildTestTag(
+ testName, app, beginRotation, endRotation, app2 = null, extraInfo = "")
+ }
+
+ /**
+ * Build a test tag for the test
+ * @param testName Name of the transition(s) being tested
+ * @param app App being launcher
+ * @param app2 Second app being launched (if any)
+ * @param beginRotation Initial screen rotation
+ * @param endRotation End screen rotation (if any, otherwise use same as initial)
+ * @param extraInfo Additional information to append to the tag
+ *
+ * @return test tag with pattern <NAME>__<APP></APP>(S)>__<ROTATION></ROTATION>(S)>[__<EXTRA>]
+ </EXTRA></NAME> */
+ protected fun buildTestTag(
+ testName: String,
+ app: IAppHelper,
+ beginRotation: Int,
+ endRotation: Int,
+ app2: IAppHelper?,
+ extraInfo: String
+ ): String {
+ var testTag = "${testName}__${app.launcherName}"
+ if (app2 != null) {
+ testTag += "-${app2.launcherName}"
+ }
+ testTag += "__${Surface.rotationToString(beginRotation)}"
+ if (endRotation != beginRotation) {
+ testTag += "-${Surface.rotationToString(endRotation)}"
+ }
+ if (extraInfo.isNotEmpty()) {
+ testTag += "__$extraInfo"
+ }
+ return testTag
+ }
+
+ protected fun Flicker.setRotation(rotation: Int) {
+ try {
+ when (rotation) {
+ Surface.ROTATION_270 -> device.setOrientationLeft()
+ Surface.ROTATION_90 -> device.setOrientationRight()
+ Surface.ROTATION_0 -> device.setOrientationNatural()
+ else -> device.setOrientationNatural()
+ }
+ // Wait for animation to complete
+ SystemClock.sleep(1000)
+ } catch (e: RemoteException) {
+ throw RuntimeException(e)
+ }
+ }
+
+ companion object {
+ const val NAVIGATION_BAR_WINDOW_TITLE = "NavigationBar"
+ const val STATUS_BAR_WINDOW_TITLE = "StatusBar"
+ const val DOCKED_STACK_DIVIDER = "DockedStackDivider"
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/NonRotationTestBase.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/NonRotationTestBase.kt
new file mode 100644
index 000000000000..90334ae91e9d
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/NonRotationTestBase.kt
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.flicker
+
+import android.view.Surface
+import org.junit.runners.Parameterized
+
+abstract class NonRotationTestBase(
+ protected val rotationName: String,
+ protected val rotation: Int
+) : FlickerTestBase() {
+ companion object {
+ const val SCREENSHOT_LAYER = "RotationLayer"
+
+ @Parameterized.Parameters(name = "{0}")
+ @JvmStatic
+ fun getParams(): Collection<Array<Any>> {
+ val supportedRotations = intArrayOf(Surface.ROTATION_0, Surface.ROTATION_90)
+ return supportedRotations.map { arrayOf(Surface.rotationToString(it), it) }
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/helpers/FlickerAppHelper.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/helpers/FlickerAppHelper.kt
new file mode 100644
index 000000000000..308a36efef87
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/helpers/FlickerAppHelper.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.flicker.helpers
+
+import android.app.Instrumentation
+import android.support.test.launcherhelper.ILauncherStrategy
+import com.android.server.wm.flicker.StandardAppHelper
+
+abstract class FlickerAppHelper(
+ instr: Instrumentation,
+ launcherName: String,
+ launcherStrategy: ILauncherStrategy
+) : StandardAppHelper(instr, sFlickerPackage, launcherName, launcherStrategy) {
+ companion object {
+ var sFlickerPackage = "com.android.wm.shell.flicker.testapp"
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/helpers/PipAppHelper.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/helpers/PipAppHelper.kt
new file mode 100644
index 000000000000..539170202b8a
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/helpers/PipAppHelper.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.flicker.helpers
+
+import android.app.Instrumentation
+import android.support.test.launcherhelper.ILauncherStrategy
+import android.support.test.launcherhelper.LauncherStrategyFactory
+import androidx.test.uiautomator.By
+import androidx.test.uiautomator.UiDevice
+import com.android.server.wm.flicker.helpers.hasPipWindow
+import com.android.server.wm.flicker.helpers.closePipWindow
+import org.junit.Assert
+
+class PipAppHelper(
+ instr: Instrumentation,
+ launcherStrategy: ILauncherStrategy = LauncherStrategyFactory
+ .getInstance(instr)
+ .launcherStrategy
+) : FlickerAppHelper(instr, "PipApp", launcherStrategy) {
+ fun clickEnterPipButton(device: UiDevice) {
+ val enterPipButton = device.findObject(By.res(getPackage(), "enter_pip"))
+ Assert.assertNotNull("Pip button not found, this usually happens when the device " +
+ "was left in an unknown state (e.g. in split screen)", enterPipButton)
+ enterPipButton.click()
+ device.hasPipWindow()
+ }
+
+ fun closePipWindow(device: UiDevice) {
+ device.closePipWindow()
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/EnterPipTest.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/EnterPipTest.kt
new file mode 100644
index 000000000000..4b04449bdbc2
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/EnterPipTest.kt
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.flicker.pip
+
+import android.view.Surface
+import androidx.test.filters.FlakyTest
+import androidx.test.filters.LargeTest
+import com.android.server.wm.flicker.dsl.flicker
+import com.android.server.wm.flicker.helpers.closePipWindow
+import com.android.server.wm.flicker.helpers.expandPipWindow
+import com.android.server.wm.flicker.helpers.hasPipWindow
+import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
+import com.android.wm.shell.flicker.navBarLayerIsAlwaysVisible
+import com.android.wm.shell.flicker.navBarLayerRotatesAndScales
+import com.android.wm.shell.flicker.navBarWindowIsAlwaysVisible
+import com.android.wm.shell.flicker.noUncoveredRegions
+import com.android.wm.shell.flicker.statusBarLayerIsAlwaysVisible
+import com.android.wm.shell.flicker.statusBarLayerRotatesScales
+import com.android.wm.shell.flicker.statusBarWindowIsAlwaysVisible
+import org.junit.FixMethodOrder
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.MethodSorters
+import org.junit.runners.Parameterized
+
+/**
+ * Test Pip launch.
+ * To run this test: `atest FlickerTests:PipToAppTest`
+ */
+@LargeTest
+@RunWith(Parameterized::class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@FlakyTest(bugId = 152738416)
+class EnterPipTest(
+ rotationName: String,
+ rotation: Int
+) : PipTestBase(rotationName, rotation) {
+ @Test
+ fun test() {
+ flicker(instrumentation) {
+ withTag { buildTestTag("enterPip", testApp, rotation) }
+ repeat { 1 }
+ setup {
+ test {
+ device.wakeUpAndGoToHomeScreen()
+ }
+ eachRun {
+ device.pressHome()
+ testApp.open()
+ this.setRotation(rotation)
+ }
+ }
+ teardown {
+ eachRun {
+ if (device.hasPipWindow()) {
+ device.closePipWindow()
+ }
+ testApp.exit()
+ this.setRotation(Surface.ROTATION_0)
+ }
+ test {
+ if (device.hasPipWindow()) {
+ device.closePipWindow()
+ }
+ }
+ }
+ transitions {
+ testApp.clickEnterPipButton(device)
+ device.expandPipWindow()
+ }
+ assertions {
+ windowManagerTrace {
+ navBarWindowIsAlwaysVisible()
+ statusBarWindowIsAlwaysVisible()
+ all("pipWindowBecomesVisible") {
+ this.showsAppWindow(testApp.`package`)
+ .then()
+ .showsAppWindow(sPipWindowTitle)
+ }
+ }
+
+ layersTrace {
+ navBarLayerIsAlwaysVisible()
+ statusBarLayerIsAlwaysVisible()
+ noUncoveredRegions(rotation, Surface.ROTATION_0, allStates = false)
+ navBarLayerRotatesAndScales(rotation, Surface.ROTATION_0)
+ statusBarLayerRotatesScales(rotation, Surface.ROTATION_0)
+
+ all("pipLayerBecomesVisible") {
+ this.showsLayer(testApp.launcherName)
+ .then()
+ .showsLayer(sPipWindowTitle)
+ }
+ }
+ }
+ }
+ }
+
+ companion object {
+ @Parameterized.Parameters(name = "{0}")
+ @JvmStatic
+ fun getParams(): Collection<Array<Any>> {
+ val supportedRotations = intArrayOf(Surface.ROTATION_0)
+ return supportedRotations.map { arrayOf(Surface.rotationToString(it), it) }
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/PipTestBase.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/PipTestBase.kt
new file mode 100644
index 000000000000..3822d69a65f5
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/PipTestBase.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.flicker.pip
+
+import com.android.wm.shell.flicker.NonRotationTestBase
+import com.android.wm.shell.flicker.helpers.PipAppHelper
+
+abstract class PipTestBase(
+ rotationName: String,
+ rotation: Int
+) : NonRotationTestBase(rotationName, rotation) {
+ protected val testApp = PipAppHelper(instrumentation)
+
+ companion object {
+ const val sPipWindowTitle = "PipMenuActivity"
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/test-apps/Android.bp b/libs/WindowManager/Shell/tests/flicker/test-apps/Android.bp
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/test-apps/Android.bp
diff --git a/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/Android.bp b/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/Android.bp
new file mode 100644
index 000000000000..d12b49245277
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/Android.bp
@@ -0,0 +1,20 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+android_test {
+ name: "WMShellFlickerTestApp",
+ srcs: ["**/*.java"],
+ sdk_version: "current",
+ test_suites: ["device-tests"],
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/AndroidManifest.xml b/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/AndroidManifest.xml
new file mode 100644
index 000000000000..95dc1d48eee8
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/AndroidManifest.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.wm.shell.flicker.testapp">
+
+ <uses-sdk android:minSdkVersion="29"
+ android:targetSdkVersion="29"/>
+ <application android:allowBackup="false"
+ android:supportsRtl="true">
+ <activity android:name=".PipActivity"
+ android:resizeableActivity="true"
+ android:supportsPictureInPicture="true"
+ android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
+ android:taskAffinity="com.android.wm.shell.flicker.testapp.PipActivity"
+ android:label="PipApp"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/res/layout/activity_pip.xml b/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/res/layout/activity_pip.xml
new file mode 100644
index 000000000000..e1870d9c523d
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/res/layout/activity_pip.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@android:color/holo_blue_bright">
+ <Button android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/enter_pip"
+ android:text="Enter PIP"/>
+</LinearLayout>
diff --git a/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/src/com/android/wm/shell/flicker/testapp/PipActivity.java b/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/src/com/android/wm/shell/flicker/testapp/PipActivity.java
new file mode 100644
index 000000000000..305281691e11
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/test-apps/flickerapp/src/com/android/wm/shell/flicker/testapp/PipActivity.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.flicker.testapp;
+
+import android.app.Activity;
+import android.app.PictureInPictureParams;
+import android.graphics.Rect;
+import android.os.Bundle;
+import android.util.Rational;
+import android.view.WindowManager;
+import android.widget.Button;
+
+public class PipActivity extends Activity {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ WindowManager.LayoutParams p = getWindow().getAttributes();
+ p.layoutInDisplayCutoutMode = WindowManager.LayoutParams
+ .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
+ getWindow().setAttributes(p);
+ setContentView(R.layout.activity_pip);
+ Button enterPip = (Button) findViewById(R.id.enter_pip);
+
+ PictureInPictureParams params = new PictureInPictureParams.Builder()
+ .setAspectRatio(new Rational(1, 1))
+ .setSourceRectHint(new Rect(0, 0, 100, 100))
+ .build();
+
+ enterPip.setOnClickListener((v) -> enterPictureInPictureMode(params));
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/Android.bp b/libs/WindowManager/Shell/tests/unittest/Android.bp
index 78fa45ebdf94..937b00b3a0fd 100644
--- a/libs/WindowManager/Shell/tests/Android.bp
+++ b/libs/WindowManager/Shell/tests/unittest/Android.bp
@@ -13,7 +13,7 @@
// limitations under the License.
android_test {
- name: "WindowManagerShellTests",
+ name: "WMShellUnitTests",
srcs: ["**/*.java"],
@@ -25,6 +25,7 @@ android_test {
"androidx.test.ext.junit",
"mockito-target-extended-minus-junit4",
"truth-prebuilt",
+ "testables",
],
libs: [
"android.test.mock",
@@ -36,9 +37,6 @@ android_test {
"libstaticjvmtiagent",
],
- sdk_version: "current",
- platform_apis: true,
-
optimize: {
enabled: false,
},
diff --git a/libs/WindowManager/Shell/tests/AndroidManifest.xml b/libs/WindowManager/Shell/tests/unittest/AndroidManifest.xml
index a8f795ec8a8d..a8f795ec8a8d 100644
--- a/libs/WindowManager/Shell/tests/AndroidManifest.xml
+++ b/libs/WindowManager/Shell/tests/unittest/AndroidManifest.xml
diff --git a/libs/WindowManager/Shell/tests/AndroidTest.xml b/libs/WindowManager/Shell/tests/unittest/AndroidTest.xml
index 4dce4db360e4..21ed2c075dff 100644
--- a/libs/WindowManager/Shell/tests/AndroidTest.xml
+++ b/libs/WindowManager/Shell/tests/unittest/AndroidTest.xml
@@ -17,12 +17,12 @@
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
<option name="install-arg" value="-t" />
- <option name="test-file-name" value="WindowManagerShellTests.apk" />
+ <option name="test-file-name" value="WMShellUnitTests.apk" />
</target_preparer>
<option name="test-suite-tag" value="apct" />
<option name="test-suite-tag" value="framework-base-presubmit" />
- <option name="test-tag" value="WindowManagerShellTests" />
+ <option name="test-tag" value="WMShellUnitTests" />
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="com.android.wm.shell.tests" />
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
diff --git a/libs/WindowManager/Shell/tests/res/values/config.xml b/libs/WindowManager/Shell/tests/unittest/res/values/config.xml
index c894eb0133b5..c894eb0133b5 100644
--- a/libs/WindowManager/Shell/tests/res/values/config.xml
+++ b/libs/WindowManager/Shell/tests/unittest/res/values/config.xml
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/ShellTaskOrganizerTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/ShellTaskOrganizerTests.java
new file mode 100644
index 000000000000..497b6b714281
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/ShellTaskOrganizerTests.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell;
+
+import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
+import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+
+import android.app.ActivityManager.RunningTaskInfo;
+import android.os.RemoteException;
+import android.view.SurfaceControl;
+import android.window.ITaskOrganizer;
+import android.window.ITaskOrganizerController;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.ArrayList;
+
+/**
+ * Tests for the shell task organizer.
+ */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class ShellTaskOrganizerTests {
+
+ @Mock
+ private ITaskOrganizerController mTaskOrganizerController;
+
+ ShellTaskOrganizer mOrganizer;
+
+ private class TrackingTaskListener implements ShellTaskOrganizer.TaskListener {
+ final ArrayList<RunningTaskInfo> appeared = new ArrayList<>();
+ final ArrayList<RunningTaskInfo> vanished = new ArrayList<>();
+ final ArrayList<RunningTaskInfo> infoChanged = new ArrayList<>();
+
+ @Override
+ public void onTaskAppeared(RunningTaskInfo taskInfo, SurfaceControl leash) {
+ appeared.add(taskInfo);
+ }
+
+ @Override
+ public void onTaskInfoChanged(RunningTaskInfo taskInfo) {
+ infoChanged.add(taskInfo);
+ }
+
+ @Override
+ public void onTaskVanished(RunningTaskInfo taskInfo) {
+ vanished.add(taskInfo);
+ }
+
+ @Override
+ public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) {
+ // Not currently used
+ }
+ }
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mOrganizer = new ShellTaskOrganizer(mTaskOrganizerController);
+ }
+
+ @Test
+ public void registerOrganizer_sendRegisterTaskOrganizer() throws RemoteException {
+ mOrganizer.registerOrganizer();
+
+ verify(mTaskOrganizerController).registerTaskOrganizer(any(ITaskOrganizer.class));
+ }
+
+ @Test
+ public void testAppearedVanished() {
+ RunningTaskInfo taskInfo = createTaskInfo(WINDOWING_MODE_MULTI_WINDOW);
+ TrackingTaskListener listener = new TrackingTaskListener();
+ mOrganizer.addListener(listener, WINDOWING_MODE_MULTI_WINDOW);
+ mOrganizer.onTaskAppeared(taskInfo, null);
+ assertTrue(listener.appeared.contains(taskInfo));
+
+ mOrganizer.onTaskVanished(taskInfo);
+ assertTrue(listener.vanished.contains(taskInfo));
+ }
+
+ @Test
+ public void testAddListenerExistingTasks() {
+ RunningTaskInfo taskInfo = createTaskInfo(WINDOWING_MODE_MULTI_WINDOW);
+ mOrganizer.onTaskAppeared(taskInfo, null);
+
+ TrackingTaskListener listener = new TrackingTaskListener();
+ mOrganizer.addListener(listener, WINDOWING_MODE_MULTI_WINDOW);
+ assertTrue(listener.appeared.contains(taskInfo));
+ }
+
+ @Test
+ public void testWindowingModeChange() {
+ RunningTaskInfo taskInfo = createTaskInfo(WINDOWING_MODE_MULTI_WINDOW);
+ TrackingTaskListener mwListener = new TrackingTaskListener();
+ TrackingTaskListener pipListener = new TrackingTaskListener();
+ mOrganizer.addListener(mwListener, WINDOWING_MODE_MULTI_WINDOW);
+ mOrganizer.addListener(pipListener, WINDOWING_MODE_PINNED);
+ mOrganizer.onTaskAppeared(taskInfo, null);
+ assertTrue(mwListener.appeared.contains(taskInfo));
+ assertTrue(pipListener.appeared.isEmpty());
+
+ taskInfo = createTaskInfo(WINDOWING_MODE_PINNED);
+ mOrganizer.onTaskInfoChanged(taskInfo);
+ assertTrue(mwListener.vanished.contains(taskInfo));
+ assertTrue(pipListener.appeared.contains(taskInfo));
+ }
+
+ private RunningTaskInfo createTaskInfo(int windowingMode) {
+ RunningTaskInfo taskInfo = new RunningTaskInfo();
+ taskInfo.configuration.windowConfiguration.setWindowingMode(windowingMode);
+ return taskInfo;
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayLayoutTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayLayoutTest.java
new file mode 100644
index 000000000000..2b5b77e49e3a
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayLayoutTest.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.common;
+
+import static android.content.res.Configuration.UI_MODE_TYPE_NORMAL;
+import static android.view.Surface.ROTATION_0;
+import static android.view.Surface.ROTATION_270;
+import static android.view.Surface.ROTATION_90;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.graphics.Insets;
+import android.graphics.Rect;
+import android.view.DisplayCutout;
+import android.view.DisplayInfo;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.internal.R;
+
+import org.junit.Test;
+
+@SmallTest
+public class DisplayLayoutTest {
+
+ @Test
+ public void testInsets() {
+ Resources res = createResources(40, 50, false, 30, 40);
+ // Test empty display, no bars or anything
+ DisplayInfo info = createDisplayInfo(1000, 1500, 0, ROTATION_0);
+ DisplayLayout dl = new DisplayLayout(info, res, false, false);
+ assertEquals(new Rect(0, 0, 0, 0), dl.stableInsets());
+ assertEquals(new Rect(0, 0, 0, 0), dl.nonDecorInsets());
+
+ // Test with bars
+ dl = new DisplayLayout(info, res, true, true);
+ assertEquals(new Rect(0, 40, 0, 50), dl.stableInsets());
+ assertEquals(new Rect(0, 0, 0, 50), dl.nonDecorInsets());
+
+ // Test just cutout
+ info = createDisplayInfo(1000, 1500, 60, ROTATION_0);
+ dl = new DisplayLayout(info, res, false, false);
+ assertEquals(new Rect(0, 60, 0, 0), dl.stableInsets());
+ assertEquals(new Rect(0, 60, 0, 0), dl.nonDecorInsets());
+
+ // Test with bars and cutout
+ dl = new DisplayLayout(info, res, true, true);
+ assertEquals(new Rect(0, 60, 0, 50), dl.stableInsets());
+ assertEquals(new Rect(0, 60, 0, 50), dl.nonDecorInsets());
+ }
+
+ @Test
+ public void testRotate() {
+ // Basic rotate utility
+ Rect testParent = new Rect(0, 0, 1000, 600);
+ Rect testInner = new Rect(40, 20, 120, 80);
+ Rect testResult = new Rect(testInner);
+ DisplayLayout.rotateBounds(testResult, testParent, 1);
+ assertEquals(new Rect(20, 880, 80, 960), testResult);
+ testResult.set(testInner);
+ DisplayLayout.rotateBounds(testResult, testParent, 2);
+ assertEquals(new Rect(880, 20, 960, 80), testResult);
+ testResult.set(testInner);
+ DisplayLayout.rotateBounds(testResult, testParent, 3);
+ assertEquals(new Rect(520, 40, 580, 120), testResult);
+
+ Resources res = createResources(40, 50, false, 30, 40);
+ DisplayInfo info = createDisplayInfo(1000, 1500, 60, ROTATION_0);
+ DisplayLayout dl = new DisplayLayout(info, res, true, true);
+ assertEquals(new Rect(0, 60, 0, 50), dl.stableInsets());
+ assertEquals(new Rect(0, 60, 0, 50), dl.nonDecorInsets());
+
+ // Rotate to 90
+ dl.rotateTo(res, ROTATION_90);
+ assertEquals(new Rect(60, 30, 0, 40), dl.stableInsets());
+ assertEquals(new Rect(60, 0, 0, 40), dl.nonDecorInsets());
+
+ // Rotate with moving navbar
+ res = createResources(40, 50, true, 30, 40);
+ dl = new DisplayLayout(info, res, true, true);
+ dl.rotateTo(res, ROTATION_270);
+ assertEquals(new Rect(40, 30, 60, 0), dl.stableInsets());
+ assertEquals(new Rect(40, 0, 60, 0), dl.nonDecorInsets());
+ }
+
+ private Resources createResources(
+ int navLand, int navPort, boolean navMoves, int statusLand, int statusPort) {
+ Configuration cfg = new Configuration();
+ cfg.uiMode = UI_MODE_TYPE_NORMAL;
+ Resources res = mock(Resources.class);
+ doReturn(navLand).when(res).getDimensionPixelSize(
+ R.dimen.navigation_bar_height_landscape_car_mode);
+ doReturn(navPort).when(res).getDimensionPixelSize(R.dimen.navigation_bar_height_car_mode);
+ doReturn(navLand).when(res).getDimensionPixelSize(R.dimen.navigation_bar_width_car_mode);
+ doReturn(navLand).when(res).getDimensionPixelSize(R.dimen.navigation_bar_height_landscape);
+ doReturn(navPort).when(res).getDimensionPixelSize(R.dimen.navigation_bar_height);
+ doReturn(navLand).when(res).getDimensionPixelSize(R.dimen.navigation_bar_width);
+ doReturn(navMoves).when(res).getBoolean(R.bool.config_navBarCanMove);
+ doReturn(statusLand).when(res).getDimensionPixelSize(R.dimen.status_bar_height_landscape);
+ doReturn(statusPort).when(res).getDimensionPixelSize(R.dimen.status_bar_height_portrait);
+ doReturn(cfg).when(res).getConfiguration();
+ return res;
+ }
+
+ private DisplayInfo createDisplayInfo(int width, int height, int cutoutHeight, int rotation) {
+ DisplayInfo info = new DisplayInfo();
+ info.logicalWidth = width;
+ info.logicalHeight = height;
+ info.rotation = rotation;
+ if (cutoutHeight > 0) {
+ info.displayCutout = new DisplayCutout(
+ Insets.of(0, cutoutHeight, 0, 0) /* safeInsets */, null /* boundLeft */,
+ new Rect(width / 2 - cutoutHeight, 0, width / 2 + cutoutHeight,
+ cutoutHeight) /* boundTop */, null /* boundRight */,
+ null /* boundBottom */);
+ } else {
+ info.displayCutout = DisplayCutout.NO_CUTOUT;
+ }
+ info.logicalDensityDpi = 300;
+ return info;
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedAnimationControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedAnimationControllerTest.java
new file mode 100644
index 000000000000..a8a3a9fd7da2
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedAnimationControllerTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static org.junit.Assert.assertNotNull;
+
+import android.graphics.Rect;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.view.SurfaceControl;
+
+import androidx.test.filters.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Unit tests against {@link OneHandedAnimationController} to ensure that it sends the right
+ * callbacks
+ * depending on the various interactions.
+ */
+@RunWith(AndroidTestingRunner.class)
+@SmallTest
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
+public class OneHandedAnimationControllerTest extends OneHandedTestCase {
+ private static final int TEST_BOUNDS_WIDTH = 1000;
+ private static final int TEST_BOUNDS_HEIGHT = 1000;
+
+ OneHandedAnimationController mOneHandedAnimationController;
+ OneHandedTutorialHandler mTutorialHandler;
+
+ @Mock
+ private SurfaceControl mMockLeash;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ mTutorialHandler = new OneHandedTutorialHandler(mContext);
+ mOneHandedAnimationController = new OneHandedAnimationController(mContext);
+ }
+
+ @Test
+ public void testGetAnimator_withSameBounds_returnAnimator() {
+ final Rect originalBounds = new Rect(0, 0, TEST_BOUNDS_WIDTH, TEST_BOUNDS_HEIGHT);
+ final Rect destinationBounds = originalBounds;
+ destinationBounds.offset(0, 300);
+ final OneHandedAnimationController.OneHandedTransitionAnimator animator =
+ mOneHandedAnimationController
+ .getAnimator(mMockLeash, originalBounds, destinationBounds);
+
+ assertNotNull(animator);
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedControllerTest.java
new file mode 100644
index 000000000000..1ce8b5445b37
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedControllerTest.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.provider.Settings;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.view.Display;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.wm.shell.common.DisplayController;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class OneHandedControllerTest extends OneHandedTestCase {
+ Display mDisplay;
+ OneHandedController mOneHandedController;
+ OneHandedTimeoutHandler mTimeoutHandler;
+
+ @Mock
+ DisplayController mMockDisplayController;
+ @Mock
+ OneHandedDisplayAreaOrganizer mMockDisplayAreaOrganizer;
+ @Mock
+ OneHandedTouchHandler mMockTouchHandler;
+ @Mock
+ OneHandedTutorialHandler mMockTutorialHandler;
+ @Mock
+ OneHandedGestureHandler mMockGestureHandler;
+ @Mock
+ OneHandedTimeoutHandler mMockTimeoutHandler;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mDisplay = mContext.getDisplay();
+ OneHandedController oneHandedController = new OneHandedController(
+ mContext,
+ mMockDisplayController,
+ mMockDisplayAreaOrganizer,
+ mMockTouchHandler,
+ mMockTutorialHandler,
+ mMockGestureHandler);
+ mOneHandedController = Mockito.spy(oneHandedController);
+ mTimeoutHandler = Mockito.spy(OneHandedTimeoutHandler.get());
+
+ when(mMockDisplayController.getDisplay(anyInt())).thenReturn(mDisplay);
+ when(mMockDisplayAreaOrganizer.isInOneHanded()).thenReturn(false);
+ }
+
+ @Test
+ public void testDefaultShouldNotInOneHanded() {
+ final OneHandedAnimationController animationController = new OneHandedAnimationController(
+ mContext);
+ OneHandedDisplayAreaOrganizer displayAreaOrganizer = new OneHandedDisplayAreaOrganizer(
+ mContext, mMockDisplayController, animationController, mMockTutorialHandler);
+
+ assertThat(displayAreaOrganizer.isInOneHanded()).isFalse();
+ }
+
+ @Test
+ public void testRegisterOrganizer() {
+ verify(mMockDisplayAreaOrganizer, atLeastOnce()).registerOrganizer(anyInt());
+ }
+
+ @Test
+ public void testStartOneHanded() {
+ mOneHandedController.startOneHanded();
+
+ verify(mMockDisplayAreaOrganizer).scheduleOffset(anyInt(), anyInt());
+ }
+
+ @Test
+ public void testStopOneHanded() {
+ when(mMockDisplayAreaOrganizer.isInOneHanded()).thenReturn(false);
+ mOneHandedController.stopOneHanded();
+
+ verify(mMockDisplayAreaOrganizer, never()).scheduleOffset(anyInt(), anyInt());
+ }
+
+ @Test
+ public void testRegisterTransitionCallbackAfterInit() {
+ verify(mMockDisplayAreaOrganizer).registerTransitionCallback(mMockTouchHandler);
+ verify(mMockDisplayAreaOrganizer).registerTransitionCallback(mMockGestureHandler);
+ verify(mMockDisplayAreaOrganizer).registerTransitionCallback(mMockTutorialHandler);
+ }
+
+ @Test
+ public void testRegisterTransitionCallback() {
+ OneHandedTransitionCallback callback = new OneHandedTransitionCallback() {};
+ mOneHandedController.registerTransitionCallback(callback);
+
+ verify(mMockDisplayAreaOrganizer).registerTransitionCallback(callback);
+ }
+
+
+ @Test
+ public void testStopOneHanded_shouldRemoveTimer() {
+ mOneHandedController.stopOneHanded();
+
+ verify(mTimeoutHandler).removeTimer();
+ }
+
+ @Test
+ public void testUpdateIsEnabled() {
+ final boolean enabled = true;
+ mOneHandedController.setOneHandedEnabled(enabled);
+
+ verify(mMockTouchHandler, atLeastOnce()).onOneHandedEnabled(enabled);
+ }
+
+ @Test
+ public void testUpdateSwipeToNotificationIsEnabled() {
+ final boolean enabled = true;
+ mOneHandedController.setSwipeToNotificationEnabled(enabled);
+
+ verify(mMockTouchHandler, atLeastOnce()).onOneHandedEnabled(enabled);
+ }
+
+ @Ignore("b/167943723, refactor it and fix it")
+ @Test
+ public void tesSettingsObserver_updateTapAppToExit() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.TAPS_APP_TO_EXIT, 1);
+
+ verify(mOneHandedController).setTaskChangeToExit(true);
+ }
+
+ @Ignore("b/167943723, refactor it and fix it")
+ @Test
+ public void tesSettingsObserver_updateEnabled() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ONE_HANDED_MODE_ENABLED, 1);
+
+ verify(mOneHandedController).setOneHandedEnabled(true);
+ }
+
+ @Ignore("b/167943723, refactor it and fix it")
+ @Test
+ public void tesSettingsObserver_updateTimeout() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ONE_HANDED_MODE_TIMEOUT,
+ OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS);
+
+ verify(mMockTimeoutHandler).setTimeout(
+ OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS);
+ }
+
+ @Ignore("b/167943723, refactor it and fix it")
+ @Test
+ public void tesSettingsObserver_updateSwipeToNotification() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED, 1);
+
+ verify(mOneHandedController).setSwipeToNotificationEnabled(true);
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedDisplayAreaOrganizerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedDisplayAreaOrganizerTest.java
new file mode 100644
index 000000000000..5ff94b6308ef
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedDisplayAreaOrganizerTest.java
@@ -0,0 +1,286 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static android.view.Display.DEFAULT_DISPLAY;
+import static android.window.DisplayAreaOrganizer.FEATURE_ONE_HANDED;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyFloat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.res.Configuration;
+import android.os.Handler;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.view.Display;
+import android.view.Surface;
+import android.view.SurfaceControl;
+import android.window.DisplayAreaInfo;
+import android.window.IWindowContainerToken;
+import android.window.WindowContainerToken;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.wm.shell.common.DisplayController;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
+ static final int DISPLAY_WIDTH = 1000;
+ static final int DISPLAY_HEIGHT = 1000;
+
+ DisplayAreaInfo mDisplayAreaInfo;
+ Display mDisplay;
+ OneHandedDisplayAreaOrganizer mDisplayAreaOrganizer;
+ OneHandedTutorialHandler mTutorialHandler;
+ OneHandedAnimationController.OneHandedTransitionAnimator mFakeAnimator;
+ WindowContainerToken mToken;
+ SurfaceControl mLeash;
+ @Mock
+ IWindowContainerToken mMockRealToken;
+ @Mock
+ OneHandedAnimationController mMockAnimationController;
+ @Mock
+ OneHandedAnimationController.OneHandedTransitionAnimator mMockAnimator;
+ @Mock
+ OneHandedSurfaceTransactionHelper mMockSurfaceTransactionHelper;
+ @Mock
+ DisplayController mMockDisplayController;
+ @Mock
+ SurfaceControl mMockLeash;
+ @Spy
+ Handler mUpdateHandler;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mToken = new WindowContainerToken(mMockRealToken);
+ mLeash = new SurfaceControl();
+ mDisplay = mContext.getDisplay();
+ mDisplayAreaInfo = new DisplayAreaInfo(mToken, DEFAULT_DISPLAY, FEATURE_ONE_HANDED);
+ mDisplayAreaInfo.configuration.orientation = Configuration.ORIENTATION_PORTRAIT;
+ when(mMockAnimationController.getAnimator(any(), any(), any())).thenReturn(null);
+ when(mMockDisplayController.getDisplay(anyInt())).thenReturn(mDisplay);
+ when(mMockSurfaceTransactionHelper.translate(any(), any(), anyFloat())).thenReturn(
+ mMockSurfaceTransactionHelper);
+ when(mMockSurfaceTransactionHelper.crop(any(), any(), any())).thenReturn(
+ mMockSurfaceTransactionHelper);
+ when(mMockSurfaceTransactionHelper.round(any(), any())).thenReturn(
+ mMockSurfaceTransactionHelper);
+ when(mMockAnimator.isRunning()).thenReturn(true);
+ when(mMockAnimator.setDuration(anyInt())).thenReturn(mFakeAnimator);
+ when(mMockAnimator.setOneHandedAnimationCallbacks(any())).thenReturn(mFakeAnimator);
+ when(mMockAnimator.setTransitionDirection(anyInt())).thenReturn(mFakeAnimator);
+ when(mMockLeash.getWidth()).thenReturn(DISPLAY_WIDTH);
+ when(mMockLeash.getHeight()).thenReturn(DISPLAY_HEIGHT);
+
+ mDisplayAreaOrganizer = new OneHandedDisplayAreaOrganizer(mContext,
+ mMockDisplayController,
+ mMockAnimationController,
+ mTutorialHandler);
+ mUpdateHandler = mDisplayAreaOrganizer.getUpdateHandler();
+ }
+
+ @Test
+ public void testGetDisplayAreaUpdateHandler_isNotNull() {
+ assertThat(mUpdateHandler).isNotNull();
+ }
+
+ @Test
+ public void testOnDisplayAreaAppeared() {
+ mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mLeash);
+
+ verify(mMockAnimationController, never()).getAnimator(any(), any(), any());
+ }
+
+ @Test
+ public void testOnDisplayAreaVanished() {
+ mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mLeash);
+ mDisplayAreaOrganizer.onDisplayAreaVanished(mDisplayAreaInfo);
+ }
+
+ @Test
+ public void testOnDisplayAreaInfoChanged_updateDisplayAreaInfo() {
+ final DisplayAreaInfo newDisplayAreaInfo = new DisplayAreaInfo(mToken, DEFAULT_DISPLAY,
+ FEATURE_ONE_HANDED);
+ mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mLeash);
+ mDisplayAreaOrganizer.onDisplayAreaInfoChanged(newDisplayAreaInfo);
+
+ assertThat(mDisplayAreaOrganizer.mDisplayAreaMap.containsKey(mDisplayAreaInfo)).isTrue();
+ }
+
+ @Ignore("b/160848002")
+ @Test
+ public void testScheduleOffset() {
+ final int xOffSet = 0;
+ final int yOffSet = 100;
+
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onDisplayAreaAppeared(mDisplayAreaInfo, mLeash);
+ mDisplayAreaOrganizer.scheduleOffset(xOffSet, yOffSet);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_OFFSET_ANIMATE)).isEqualTo(true);
+ }
+
+ @Ignore("b/160848002")
+ @Test
+ public void testRotation_portraitToLandscape() {
+ when(mMockLeash.isValid()).thenReturn(false);
+ // Rotate 0 -> 90
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_0, Surface.ROTATION_90);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
+
+ // Rotate 0 -> 270
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_0, Surface.ROTATION_270);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
+
+ // Rotate 180 -> 90
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_180, Surface.ROTATION_90);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
+
+ // Rotate 180 -> 270
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_180, Surface.ROTATION_270);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
+ }
+
+ @Ignore("b/160848002")
+ @Test
+ public void testRotation_landscapeToPortrait() {
+ when(mMockLeash.isValid()).thenReturn(false);
+ // Rotate 90 -> 0
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_90, Surface.ROTATION_0);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
+
+ // Rotate 90 -> 180
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_90, Surface.ROTATION_180);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
+
+ // Rotate 270 -> 0
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_270, Surface.ROTATION_0);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
+
+ // Rotate 270 -> 180
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_270, Surface.ROTATION_180);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
+ }
+
+ @Ignore("b/160848002")
+ @Test
+ public void testRotation_portraitToPortrait() {
+ when(mMockLeash.isValid()).thenReturn(false);
+ // Rotate 0 -> 0
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_0, Surface.ROTATION_0);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
+
+ // Rotate 0 -> 180
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_0, Surface.ROTATION_180);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
+
+ // Rotate 180 -> 180
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_180, Surface.ROTATION_180);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
+
+ // Rotate 180 -> 180
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_180, Surface.ROTATION_0);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
+ }
+
+ @Ignore("b/160848002")
+ @Test
+ public void testRotation_landscapeToLandscape() {
+ when(mMockLeash.isValid()).thenReturn(false);
+ // Rotate 90 -> 90
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_90, Surface.ROTATION_90);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
+
+ // Rotate 90 -> 270
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_90, Surface.ROTATION_270);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
+
+ // Rotate 270 -> 270
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_270, Surface.ROTATION_270);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
+
+ // Rotate 270 -> 90
+ TestableLooper.get(this).processAllMessages();
+ mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_270, Surface.ROTATION_90);
+
+ assertThat(mUpdateHandler.hasMessages(
+ OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedEventsTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedEventsTest.java
new file mode 100644
index 000000000000..492c34e10ed5
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedEventsTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static org.junit.Assert.assertEquals;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.internal.logging.UiEventLogger;
+import com.android.internal.logging.testing.UiEventLoggerFake;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+@RunWith(Parameterized.class)
+@SmallTest
+public class OneHandedEventsTest extends OneHandedTestCase {
+
+ private UiEventLoggerFake mUiEventLogger;
+
+ @Parameterized.Parameter
+ public int mTag;
+
+ @Parameterized.Parameter(1)
+ public String mExpectedMessage;
+
+ public UiEventLogger.UiEventEnum mUiEvent;
+
+ @Before
+ public void setFakeLoggers() {
+ mUiEventLogger = new UiEventLoggerFake();
+ OneHandedEvents.sUiEventLogger = mUiEventLogger;
+ }
+
+ @Test
+ public void testLogEvent() {
+ if (mUiEvent != null) {
+ assertEquals(1, mUiEventLogger.numLogs());
+ assertEquals(mUiEvent.getId(), mUiEventLogger.eventId(0));
+ }
+ }
+
+ @Parameterized.Parameters(name = "{index}: {2}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][]{
+ // Triggers
+ {OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_GESTURE_IN,
+ "writeEvent one_handed_trigger_gesture_in"},
+ {OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_GESTURE_OUT,
+ "writeEvent one_handed_trigger_gesture_out"},
+ {OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_OVERSPACE_OUT,
+ "writeEvent one_handed_trigger_overspace_out"},
+ {OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_POP_IME_OUT,
+ "writeEvent one_handed_trigger_pop_ime_out"},
+ {OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_ROTATION_OUT,
+ "writeEvent one_handed_trigger_rotation_out"},
+ {OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_APP_TAPS_OUT,
+ "writeEvent one_handed_trigger_app_taps_out"},
+ {OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_TIMEOUT_OUT,
+ "writeEvent one_handed_trigger_timeout_out"},
+ {OneHandedEvents.EVENT_ONE_HANDED_TRIGGER_SCREEN_OFF_OUT,
+ "writeEvent one_handed_trigger_screen_off_out"},
+ // Settings toggles
+ {OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_ENABLED_ON,
+ "writeEvent one_handed_settings_enabled_on"},
+ {OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_ENABLED_OFF,
+ "writeEvent one_handed_settings_enabled_off"},
+ {OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_APP_TAPS_EXIT_ON,
+ "writeEvent one_handed_settings_app_taps_exit_on"},
+ {OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_APP_TAPS_EXIT_OFF,
+ "writeEvent one_handed_settings_app_taps_exit_off"},
+ {OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_TIMEOUT_EXIT_ON,
+ "writeEvent one_handed_settings_timeout_exit_on"},
+ {OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_TIMEOUT_EXIT_OFF,
+ "writeEvent one_handed_settings_timeout_exit_off"},
+ {OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_NEVER,
+ "writeEvent one_handed_settings_timeout_seconds_never"},
+ {OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_4,
+ "writeEvent one_handed_settings_timeout_seconds_4"},
+ {OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_8,
+ "writeEvent one_handed_settings_timeout_seconds_8"},
+ {OneHandedEvents.EVENT_ONE_HANDED_SETTINGS_TIMEOUT_SECONDS_12,
+ "writeEvent one_handed_settings_timeout_seconds_12"}
+ });
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedGestureHandlerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedGestureHandlerTest.java
new file mode 100644
index 000000000000..fb417c8ca5e8
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedGestureHandlerTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.wm.shell.common.DisplayController;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class OneHandedGestureHandlerTest extends OneHandedTestCase {
+ OneHandedTutorialHandler mTutorialHandler;
+ OneHandedGestureHandler mGestureHandler;
+ @Mock
+ DisplayController mMockDisplayController;
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mTutorialHandler = new OneHandedTutorialHandler(mContext);
+ mGestureHandler = new OneHandedGestureHandler(mContext, mMockDisplayController);
+ }
+
+ @Test
+ public void testSetGestureEventListener() {
+ OneHandedGestureHandler.OneHandedGestureEventCallback callback =
+ new OneHandedGestureHandler.OneHandedGestureEventCallback() {
+ @Override
+ public void onStart() {}
+
+ @Override
+ public void onStop() {}
+ };
+
+ mGestureHandler.setGestureEventListener(callback);
+ assertThat(mGestureHandler.mGestureEventCallback).isEqualTo(callback);
+ }
+
+ @Ignore("b/167943723, refactor it and fix it")
+ @Test
+ public void testReceiveNewConfig_whenThreeButtonModeEnabled() {
+ mGestureHandler.onOneHandedEnabled(true);
+ mGestureHandler.onThreeButtonModeEnabled(true);
+
+ assertThat(mGestureHandler.mInputMonitor).isNotNull();
+ assertThat(mGestureHandler.mInputEventReceiver).isNotNull();
+ }
+
+ @Test
+ public void testOneHandedDisabled_shouldDisposeInputChannel() {
+ mGestureHandler.onOneHandedEnabled(false);
+
+ assertThat(mGestureHandler.mInputMonitor).isNull();
+ assertThat(mGestureHandler.mInputEventReceiver).isNull();
+ }
+
+ @Test
+ public void testChangeNavBarToNon3Button_shouldDisposeInputChannel() {
+ mGestureHandler.onOneHandedEnabled(true);
+ mGestureHandler.onThreeButtonModeEnabled(false);
+
+ assertThat(mGestureHandler.mInputMonitor).isNull();
+ assertThat(mGestureHandler.mInputEventReceiver).isNull();
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedSettingsUtilTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedSettingsUtilTest.java
new file mode 100644
index 000000000000..7c11138a47aa
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedSettingsUtilTest.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static com.android.wm.shell.onehanded.OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_LONG_IN_SECONDS;
+import static com.android.wm.shell.onehanded.OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS;
+import static com.android.wm.shell.onehanded.OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_NEVER;
+import static com.android.wm.shell.onehanded.OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_SHORT_IN_SECONDS;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ContentResolver;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.provider.Settings;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+
+import androidx.test.filters.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class OneHandedSettingsUtilTest extends OneHandedTestCase {
+ ContentResolver mContentResolver;
+ ContentObserver mContentObserver;
+ boolean mOnChanged;
+
+ @Before
+ public void setUp() {
+ mContentResolver = mContext.getContentResolver();
+ mContentObserver = new ContentObserver(mContext.getMainThreadHandler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ mOnChanged = true;
+ }
+ };
+ }
+
+ @Test
+ public void testRegisterSecureKeyObserver() {
+ final Uri result = OneHandedSettingsUtil.registerSettingsKeyObserver(
+ Settings.Secure.TAPS_APP_TO_EXIT, mContentResolver, mContentObserver);
+
+ assertThat(result).isNotNull();
+
+ OneHandedSettingsUtil.registerSettingsKeyObserver(
+ Settings.Secure.TAPS_APP_TO_EXIT, mContentResolver, mContentObserver);
+ }
+
+ @Test
+ public void testUnregisterSecureKeyObserver() {
+ OneHandedSettingsUtil.registerSettingsKeyObserver(
+ Settings.Secure.TAPS_APP_TO_EXIT, mContentResolver, mContentObserver);
+ OneHandedSettingsUtil.unregisterSettingsKeyObserver(mContentResolver, mContentObserver);
+
+ assertThat(mOnChanged).isFalse();
+
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.TAPS_APP_TO_EXIT, 0);
+
+ assertThat(mOnChanged).isFalse();
+ }
+
+ @Test
+ public void testGetSettingsIsOneHandedModeEnabled() {
+ assertThat(OneHandedSettingsUtil.getSettingsOneHandedModeEnabled(
+ mContentResolver)).isAnyOf(true, false);
+ }
+
+ @Test
+ public void testGetSettingsTapsAppToExit() {
+ assertThat(OneHandedSettingsUtil.getSettingsTapsAppToExit(
+ mContentResolver)).isAnyOf(true, false);
+ }
+
+ @Test
+ public void testGetSettingsOneHandedModeTimeout() {
+ assertThat(OneHandedSettingsUtil.getSettingsOneHandedModeTimeout(
+ mContentResolver)).isAnyOf(
+ ONE_HANDED_TIMEOUT_NEVER,
+ ONE_HANDED_TIMEOUT_SHORT_IN_SECONDS,
+ ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS,
+ ONE_HANDED_TIMEOUT_LONG_IN_SECONDS);
+ }
+
+ @Test
+ public void testGetSettingsSwipeToNotificationEnabled() {
+ assertThat(OneHandedSettingsUtil.getSettingsSwipeToNotificationEnabled(
+ mContentResolver)).isAnyOf(true, false);
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTestCase.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTestCase.java
new file mode 100644
index 000000000000..c7ae2a09ad67
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTestCase.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import static com.android.wm.shell.onehanded.OneHandedController.SUPPORT_ONE_HANDED_MODE;
+import static com.android.wm.shell.onehanded.OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS;
+
+import static org.junit.Assume.assumeTrue;
+
+import android.content.Context;
+import android.hardware.display.DisplayManager;
+import android.os.SystemProperties;
+import android.provider.Settings;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * Base class that does One Handed specific setup.
+ */
+public abstract class OneHandedTestCase {
+ static boolean sOrigEnabled;
+ static boolean sOrigTapsAppToExitEnabled;
+ static int sOrigTimeout;
+ static boolean sOrigSwipeToNotification;
+
+ protected Context mContext;
+
+ @Before
+ public void setupSettings() {
+ final Context testContext =
+ InstrumentationRegistry.getInstrumentation().getTargetContext();
+ final DisplayManager dm = testContext.getSystemService(DisplayManager.class);
+ mContext = testContext.createDisplayContext(dm.getDisplay(DEFAULT_DISPLAY));
+
+ InstrumentationRegistry
+ .getInstrumentation()
+ .getUiAutomation()
+ .adoptShellPermissionIdentity();
+
+ sOrigEnabled = OneHandedSettingsUtil.getSettingsOneHandedModeEnabled(
+ getContext().getContentResolver());
+ sOrigTimeout = OneHandedSettingsUtil.getSettingsOneHandedModeTimeout(
+ getContext().getContentResolver());
+ sOrigTapsAppToExitEnabled = OneHandedSettingsUtil.getSettingsTapsAppToExit(
+ getContext().getContentResolver());
+ sOrigSwipeToNotification = OneHandedSettingsUtil.getSettingsSwipeToNotificationEnabled(
+ getContext().getContentResolver());
+ Settings.Secure.putInt(getContext().getContentResolver(),
+ Settings.Secure.ONE_HANDED_MODE_ENABLED, 1);
+ Settings.Secure.putInt(getContext().getContentResolver(),
+ Settings.Secure.ONE_HANDED_MODE_TIMEOUT, ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS);
+ Settings.Secure.putInt(getContext().getContentResolver(),
+ Settings.Secure.TAPS_APP_TO_EXIT, 1);
+ Settings.Secure.putInt(getContext().getContentResolver(),
+ Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED, 1);
+ }
+
+ @Before
+ public void assumeOneHandedModeSupported() {
+ assumeTrue(SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false));
+ }
+
+ @After
+ public void restoreSettings() {
+ Settings.Secure.putInt(getContext().getContentResolver(),
+ Settings.Secure.ONE_HANDED_MODE_ENABLED, sOrigEnabled ? 1 : 0);
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ONE_HANDED_MODE_TIMEOUT, sOrigTimeout);
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.TAPS_APP_TO_EXIT, sOrigTapsAppToExitEnabled ? 1 : 0);
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED,
+ sOrigSwipeToNotification ? 1 : 0);
+
+ InstrumentationRegistry
+ .getInstrumentation()
+ .getUiAutomation()
+ .dropShellPermissionIdentity();
+ }
+
+ protected Context getContext() {
+ return mContext;
+ }
+}
+
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTimeoutHandlerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTimeoutHandlerTest.java
new file mode 100644
index 000000000000..e2b70c3bcc70
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTimeoutHandlerTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static com.android.wm.shell.onehanded.OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_LONG_IN_SECONDS;
+import static com.android.wm.shell.onehanded.OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS;
+import static com.android.wm.shell.onehanded.OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_NEVER;
+import static com.android.wm.shell.onehanded.OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_SHORT_IN_SECONDS;
+import static com.android.wm.shell.onehanded.OneHandedTimeoutHandler.ONE_HANDED_TIMEOUT_STOP_MSG;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+
+import androidx.test.filters.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class OneHandedTimeoutHandlerTest extends OneHandedTestCase {
+ OneHandedTimeoutHandler mTimeoutHandler;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mTimeoutHandler = Mockito.spy(OneHandedTimeoutHandler.get());
+ }
+
+ @Test
+ public void testTimeoutHandler_isNotNull() {
+ assertThat(OneHandedTimeoutHandler.get()).isNotNull();
+ }
+
+ @Test
+ public void testTimeoutHandler_getTimeout_defaultMedium() {
+ assertThat(OneHandedTimeoutHandler.get().getTimeout()).isEqualTo(
+ ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS);
+ }
+
+ @Test
+ public void testTimeoutHandler_setNewTime_resetTimer() {
+ mTimeoutHandler.setTimeout(ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS);
+ verify(mTimeoutHandler).resetTimer();
+ assertThat(mTimeoutHandler.sHandler.hasMessages(ONE_HANDED_TIMEOUT_STOP_MSG)).isNotNull();
+ }
+
+ @Test
+ public void testSetTimeoutNever_neverResetTimer() {
+ mTimeoutHandler.setTimeout(ONE_HANDED_TIMEOUT_NEVER);
+ assertThat(!mTimeoutHandler.sHandler.hasMessages(ONE_HANDED_TIMEOUT_STOP_MSG)).isNotNull();
+ }
+
+ @Test
+ public void testSetTimeoutShort() {
+ mTimeoutHandler.setTimeout(ONE_HANDED_TIMEOUT_SHORT_IN_SECONDS);
+ verify(mTimeoutHandler).resetTimer();
+ assertThat(mTimeoutHandler.sHandler.hasMessages(ONE_HANDED_TIMEOUT_STOP_MSG)).isNotNull();
+ }
+
+ @Test
+ public void testSetTimeoutMedium() {
+ mTimeoutHandler.setTimeout(ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS);
+ verify(mTimeoutHandler).resetTimer();
+ assertThat(mTimeoutHandler.sHandler.hasMessages(
+ ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS)).isNotNull();
+ }
+
+ @Test
+ public void testSetTimeoutLong() {
+ mTimeoutHandler.setTimeout(ONE_HANDED_TIMEOUT_LONG_IN_SECONDS);
+ assertThat(mTimeoutHandler.getTimeout()).isEqualTo(ONE_HANDED_TIMEOUT_LONG_IN_SECONDS);
+ }
+
+ @Test
+ public void testDragging_shouldRemoveAndSendEmptyMessageDelay() {
+ final boolean isDragging = true;
+ mTimeoutHandler.setTimeout(ONE_HANDED_TIMEOUT_LONG_IN_SECONDS);
+ mTimeoutHandler.resetTimer();
+ TestableLooper.get(this).processAllMessages();
+ assertThat(mTimeoutHandler.sHandler.hasMessages(ONE_HANDED_TIMEOUT_STOP_MSG)).isNotNull();
+ }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTouchHandlerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTouchHandlerTest.java
new file mode 100644
index 000000000000..c69e385b2602
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTouchHandlerTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+
+import androidx.test.filters.SmallTest;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class OneHandedTouchHandlerTest extends OneHandedTestCase {
+ OneHandedTouchHandler mTouchHandler;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mTouchHandler = new OneHandedTouchHandler();
+ }
+
+ @Test
+ public void testRegisterTouchEventListener() {
+ OneHandedTouchHandler.OneHandedTouchEventCallback callback = () -> {
+ };
+ mTouchHandler.registerTouchEventListener(callback);
+
+ assertThat(mTouchHandler.mTouchEventCallback).isEqualTo(callback);
+ }
+
+ @Test
+ public void testOneHandedDisabled_shouldDisposeInputChannel() {
+ mTouchHandler.onOneHandedEnabled(false);
+
+ assertThat(mTouchHandler.mInputMonitor).isNull();
+ assertThat(mTouchHandler.mInputEventReceiver).isNull();
+ }
+
+ @Ignore("b/167943723, refactor it and fix it")
+ @Test
+ public void testOneHandedEnabled_monitorInputChannel() {
+ mTouchHandler.onOneHandedEnabled(true);
+
+ assertThat(mTouchHandler.mInputMonitor).isNotNull();
+ assertThat(mTouchHandler.mInputEventReceiver).isNotNull();
+ }
+} \ No newline at end of file
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTutorialHandlerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTutorialHandlerTest.java
new file mode 100644
index 000000000000..4a133d39291a
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedTutorialHandlerTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.onehanded;
+
+import static org.mockito.Mockito.verify;
+
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.wm.shell.common.DisplayController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class OneHandedTutorialHandlerTest extends OneHandedTestCase {
+ @Mock
+ OneHandedTouchHandler mTouchHandler;
+ OneHandedTutorialHandler mTutorialHandler;
+ OneHandedGestureHandler mGestureHandler;
+ OneHandedController mOneHandedController;
+ @Mock
+ DisplayController mMockDisplayController;
+ @Mock
+ OneHandedDisplayAreaOrganizer mMockDisplayAreaOrganizer;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mTutorialHandler = new OneHandedTutorialHandler(mContext);
+ mGestureHandler = new OneHandedGestureHandler(mContext, mMockDisplayController);
+ mOneHandedController = new OneHandedController(
+ getContext(),
+ mMockDisplayController,
+ mMockDisplayAreaOrganizer,
+ mTouchHandler,
+ mTutorialHandler,
+ mGestureHandler);
+ }
+
+ @Test
+ public void testOneHandedManager_registerForDisplayAreaOrganizer() {
+ verify(mMockDisplayAreaOrganizer).registerTransitionCallback(mTutorialHandler);
+ }
+}
diff --git a/libs/androidfw/Android.bp b/libs/androidfw/Android.bp
index aa34edf487fe..8ab7da5257ab 100644
--- a/libs/androidfw/Android.bp
+++ b/libs/androidfw/Android.bp
@@ -155,6 +155,7 @@ cc_test {
android: {
srcs: [
"tests/BackupData_test.cpp",
+ "tests/BackupHelpers_test.cpp",
"tests/ObbFile_test.cpp",
"tests/PosixUtils_test.cpp",
],
diff --git a/libs/androidfw/BackupHelpers.cpp b/libs/androidfw/BackupHelpers.cpp
index 8bfe2b6a259a..e80e9486c8b2 100644
--- a/libs/androidfw/BackupHelpers.cpp
+++ b/libs/androidfw/BackupHelpers.cpp
@@ -479,7 +479,7 @@ void send_tarfile_chunk(BackupDataWriter* writer, const char* buffer, size_t siz
}
int write_tarfile(const String8& packageName, const String8& domain,
- const String8& rootpath, const String8& filepath, off_t* outSize,
+ const String8& rootpath, const String8& filepath, off64_t* outSize,
BackupDataWriter* writer)
{
// In the output stream everything is stored relative to the root
diff --git a/libs/androidfw/include/androidfw/BackupHelpers.h b/libs/androidfw/include/androidfw/BackupHelpers.h
index 2da247b77c0a..a0fa13662cb9 100644
--- a/libs/androidfw/include/androidfw/BackupHelpers.h
+++ b/libs/androidfw/include/androidfw/BackupHelpers.h
@@ -137,7 +137,7 @@ int back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapsh
char const* const* files, char const* const *keys, int fileCount);
int write_tarfile(const String8& packageName, const String8& domain,
- const String8& rootPath, const String8& filePath, off_t* outSize,
+ const String8& rootPath, const String8& filePath, off64_t* outSize,
BackupDataWriter* outputStream);
class RestoreHelperBase
diff --git a/libs/androidfw/include/androidfw/ResourceTypes.h b/libs/androidfw/include/androidfw/ResourceTypes.h
index e351a46d633a..e10a7f3f5c61 100644
--- a/libs/androidfw/include/androidfw/ResourceTypes.h
+++ b/libs/androidfw/include/androidfw/ResourceTypes.h
@@ -1717,6 +1717,10 @@ struct ResTable_overlayable_policy_header
// The overlay must be signed with the same signature as the actor declared for the target
// resource
ACTOR_SIGNATURE = 0x00000080,
+
+ // The overlay must be signed with the same signature as the reference package declared
+ // in the SystemConfig
+ CONFIG_SIGNATURE = 0x00000100,
};
using PolicyBitmask = uint32_t;
diff --git a/libs/androidfw/tests/BackupHelpers_test.cpp b/libs/androidfw/tests/BackupHelpers_test.cpp
new file mode 100644
index 000000000000..86b7fb361228
--- /dev/null
+++ b/libs/androidfw/tests/BackupHelpers_test.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "BackupHelpers_test"
+#include <androidfw/BackupHelpers.h>
+
+#include <gtest/gtest.h>
+
+#include <fcntl.h>
+#include <utils/String8.h>
+#include <android-base/file.h>
+
+namespace android {
+
+class BackupHelpersTest : public testing::Test {
+protected:
+
+ virtual void SetUp() {
+ }
+ virtual void TearDown() {
+ }
+};
+
+TEST_F(BackupHelpersTest, WriteTarFileWithSizeLessThan2GB) {
+ TemporaryFile tf;
+ // Allocate a 1 KB file.
+ off64_t fileSize = 1024;
+ ASSERT_EQ(0, posix_fallocate64(tf.fd, 0, fileSize));
+ off64_t tarSize = 0;
+ int err = write_tarfile(/* packageName */ String8("test-pkg"), /* domain */ String8(""), /* rootpath */ String8(""), /* filePath */ String8(tf.path), /* outSize */ &tarSize, /* writer */ NULL);
+ ASSERT_EQ(err, 0);
+ // Returned tarSize includes 512 B for the header.
+ off64_t expectedTarSize = fileSize + 512;
+ ASSERT_EQ(tarSize, expectedTarSize);
+}
+
+TEST_F(BackupHelpersTest, WriteTarFileWithSizeGreaterThan2GB) {
+ TemporaryFile tf;
+ // Allocate a 2 GB file.
+ off64_t fileSize = 2ll * 1024ll * 1024ll * 1024ll + 512ll;
+ ASSERT_EQ(0, posix_fallocate64(tf.fd, 0, fileSize));
+ off64_t tarSize = 0;
+ int err = write_tarfile(/* packageName */ String8("test-pkg"), /* domain */ String8(""), /* rootpath */ String8(""), /* filePath */ String8(tf.path), /* outSize */ &tarSize, /* writer */ NULL);
+ ASSERT_EQ(err, 0);
+ // Returned tarSize includes 512 B for the header.
+ off64_t expectedTarSize = fileSize + 512;
+ ASSERT_EQ(tarSize, expectedTarSize);
+}
+}
+
diff --git a/libs/hostgraphics/Android.bp b/libs/hostgraphics/Android.bp
index e713b98b867e..9d83e491fdc1 100644
--- a/libs/hostgraphics/Android.bp
+++ b/libs/hostgraphics/Android.bp
@@ -5,6 +5,10 @@ cc_library_host_static {
"-Wno-unused-parameter",
],
+ static_libs: [
+ "libbase",
+ ],
+
srcs: [
":libui_host_common",
"Fence.cpp",
@@ -28,4 +32,4 @@ cc_library_host_static {
enabled: true,
}
},
-} \ No newline at end of file
+}
diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp
index aa842ff6a7b7..90d2537d97a8 100644
--- a/libs/hwui/Android.bp
+++ b/libs/hwui/Android.bp
@@ -53,8 +53,6 @@ cc_defaults {
host: {
include_dirs: [
"external/vulkan-headers/include",
- "frameworks/native/libs/math/include",
- "frameworks/native/libs/ui/include",
],
cflags: [
"-Wno-unused-variable",
@@ -71,6 +69,10 @@ cc_defaults {
"libminikin",
],
+ static_libs: [
+ "libui-types",
+ ],
+
target: {
android: {
shared_libs: [
@@ -83,7 +85,6 @@ cc_defaults {
"libGLESv2",
"libGLESv3",
"libvulkan",
- "libui",
"libnativedisplay",
"libnativewindow",
"libprotobuf-cpp-lite",
@@ -152,6 +153,45 @@ cc_defaults {
}
// ------------------------
+// framework-graphics jar
+// ------------------------
+
+java_sdk_library {
+ name: "framework-graphics",
+ defaults: ["framework-module-defaults"],
+ visibility: [
+ "//frameworks/base", // Framework
+ ],
+
+ srcs: [
+ ":framework-graphics-srcs",
+ ],
+
+ permitted_packages: [
+ "android.graphics",
+ ],
+
+ // TODO: once framework-graphics is officially part of the
+ // UI-rendering module this line would no longer be
+ // needed.
+ installable: true,
+
+ // Disable api_lint that the defaults enable
+ // TODO: enable this
+ api_lint: {
+ enabled: false,
+ },
+}
+
+filegroup {
+ name: "framework-graphics-srcs",
+ srcs: [
+ "apex/java/**/*.java",
+ ],
+ path: "apex/java"
+}
+
+// ------------------------
// APEX
// ------------------------
@@ -346,6 +386,7 @@ cc_defaults {
"libstatspull",
"libstatssocket",
"libpdfium",
+ "libbinder_ndk",
],
static_libs: [
"libgif",
@@ -421,6 +462,14 @@ cc_defaults {
"RenderNode.cpp",
"RenderProperties.cpp",
"RootRenderNode.cpp",
+ "shader/Shader.cpp",
+ "shader/BitmapShader.cpp",
+ "shader/BlurShader.cpp",
+ "shader/ComposeShader.cpp",
+ "shader/LinearGradientShader.cpp",
+ "shader/RadialGradientShader.cpp",
+ "shader/RuntimeShader.cpp",
+ "shader/SweepGradientShader.cpp",
"SkiaCanvas.cpp",
"VectorDrawable.cpp",
],
@@ -457,6 +506,7 @@ cc_defaults {
"service/GraphicsStatsService.cpp",
"thread/CommonPool.cpp",
"utils/GLUtils.cpp",
+ "utils/NdkUtils.cpp",
"utils/StringUtils.cpp",
"AutoBackendTextureRelease.cpp",
"DeferredLayerUpdater.cpp",
@@ -499,6 +549,11 @@ cc_library {
"android_graphics_jni",
],
export_header_lib_headers: ["android_graphics_apex_headers"],
+ target: {
+ android: {
+ version_script: "libhwui.map.txt",
+ }
+ },
}
cc_library_static {
@@ -516,6 +571,7 @@ cc_defaults {
android: {
shared_libs: [
"libgui",
+ "libui",
],
}
},
diff --git a/libs/hwui/AnimationContext.h b/libs/hwui/AnimationContext.h
index 74d5e79c0b77..f8a2072ffbdb 100644
--- a/libs/hwui/AnimationContext.h
+++ b/libs/hwui/AnimationContext.h
@@ -77,8 +77,8 @@ class AnimationContext {
PREVENT_COPY_AND_ASSIGN(AnimationContext);
public:
- ANDROID_API explicit AnimationContext(renderthread::TimeLord& clock);
- ANDROID_API virtual ~AnimationContext();
+ explicit AnimationContext(renderthread::TimeLord& clock);
+ virtual ~AnimationContext();
nsecs_t frameTimeMs() { return mFrameTimeMs; }
bool hasAnimations() {
@@ -87,22 +87,22 @@ public:
// Will always add to the next frame list, which is swapped when
// startFrame() is called
- ANDROID_API void addAnimatingRenderNode(RenderNode& node);
+ void addAnimatingRenderNode(RenderNode& node);
// Marks the start of a frame, which will update the frame time and move all
// next frame animations into the current frame
- ANDROID_API virtual void startFrame(TreeInfo::TraversalMode mode);
+ virtual void startFrame(TreeInfo::TraversalMode mode);
// Runs any animations still left in mCurrentFrameAnimations that were not run
// as part of the standard RenderNode:prepareTree pass.
- ANDROID_API virtual void runRemainingAnimations(TreeInfo& info);
+ virtual void runRemainingAnimations(TreeInfo& info);
- ANDROID_API virtual void callOnFinished(BaseRenderNodeAnimator* animator,
+ virtual void callOnFinished(BaseRenderNodeAnimator* animator,
AnimationListener* listener);
- ANDROID_API virtual void destroy();
+ virtual void destroy();
- ANDROID_API virtual void pauseAnimators() {}
+ virtual void pauseAnimators() {}
private:
friend class AnimationHandle;
diff --git a/libs/hwui/Animator.h b/libs/hwui/Animator.h
index ed7b6eb1cf4a..3c9f1ea1b6e3 100644
--- a/libs/hwui/Animator.h
+++ b/libs/hwui/Animator.h
@@ -39,10 +39,10 @@ class RenderProperties;
class AnimationListener : public VirtualLightRefBase {
public:
- ANDROID_API virtual void onAnimationFinished(BaseRenderNodeAnimator*) = 0;
+ virtual void onAnimationFinished(BaseRenderNodeAnimator*) = 0;
protected:
- ANDROID_API virtual ~AnimationListener() {}
+ virtual ~AnimationListener() {}
};
enum class RepeatMode {
@@ -55,34 +55,34 @@ class BaseRenderNodeAnimator : public VirtualLightRefBase {
PREVENT_COPY_AND_ASSIGN(BaseRenderNodeAnimator);
public:
- ANDROID_API void setStartValue(float value);
- ANDROID_API void setInterpolator(Interpolator* interpolator);
- ANDROID_API void setDuration(nsecs_t durationInMs);
- ANDROID_API nsecs_t duration() { return mDuration; }
- ANDROID_API void setStartDelay(nsecs_t startDelayInMs);
- ANDROID_API nsecs_t startDelay() { return mStartDelay; }
- ANDROID_API void setListener(AnimationListener* listener) { mListener = listener; }
+ void setStartValue(float value);
+ void setInterpolator(Interpolator* interpolator);
+ void setDuration(nsecs_t durationInMs);
+ nsecs_t duration() { return mDuration; }
+ void setStartDelay(nsecs_t startDelayInMs);
+ nsecs_t startDelay() { return mStartDelay; }
+ void setListener(AnimationListener* listener) { mListener = listener; }
AnimationListener* listener() { return mListener.get(); }
- ANDROID_API void setAllowRunningAsync(bool mayRunAsync) { mMayRunAsync = mayRunAsync; }
+ void setAllowRunningAsync(bool mayRunAsync) { mMayRunAsync = mayRunAsync; }
bool mayRunAsync() { return mMayRunAsync; }
- ANDROID_API void start();
- ANDROID_API virtual void reset();
- ANDROID_API void reverse();
+ void start();
+ virtual void reset();
+ void reverse();
// Terminates the animation at its current progress.
- ANDROID_API void cancel();
+ void cancel();
// Terminates the animation and skip to the end of the animation.
- ANDROID_API virtual void end();
+ virtual void end();
void attach(RenderNode* target);
virtual void onAttached() {}
void detach() { mTarget = nullptr; }
- ANDROID_API void pushStaging(AnimationContext& context);
- ANDROID_API bool animate(AnimationContext& context);
+ void pushStaging(AnimationContext& context);
+ bool animate(AnimationContext& context);
// Returns the remaining time in ms for the animation. Note this should only be called during
// an animation on RenderThread.
- ANDROID_API nsecs_t getRemainingPlayTime();
+ nsecs_t getRemainingPlayTime();
bool isRunning() {
return mPlayState == PlayState::Running || mPlayState == PlayState::Reversing;
@@ -90,7 +90,7 @@ public:
bool isFinished() { return mPlayState == PlayState::Finished; }
float finalValue() { return mFinalValue; }
- ANDROID_API virtual uint32_t dirtyMask() = 0;
+ virtual uint32_t dirtyMask() = 0;
void forceEndNow(AnimationContext& context);
RenderNode* target() { return mTarget; }
@@ -196,9 +196,9 @@ public:
ALPHA,
};
- ANDROID_API RenderPropertyAnimator(RenderProperty property, float finalValue);
+ RenderPropertyAnimator(RenderProperty property, float finalValue);
- ANDROID_API virtual uint32_t dirtyMask();
+ virtual uint32_t dirtyMask();
protected:
virtual float getValue(RenderNode* target) const override;
@@ -221,10 +221,10 @@ private:
class CanvasPropertyPrimitiveAnimator : public BaseRenderNodeAnimator {
public:
- ANDROID_API CanvasPropertyPrimitiveAnimator(CanvasPropertyPrimitive* property,
+ CanvasPropertyPrimitiveAnimator(CanvasPropertyPrimitive* property,
float finalValue);
- ANDROID_API virtual uint32_t dirtyMask();
+ virtual uint32_t dirtyMask();
protected:
virtual float getValue(RenderNode* target) const override;
@@ -241,10 +241,10 @@ public:
ALPHA,
};
- ANDROID_API CanvasPropertyPaintAnimator(CanvasPropertyPaint* property, PaintField field,
+ CanvasPropertyPaintAnimator(CanvasPropertyPaint* property, PaintField field,
float finalValue);
- ANDROID_API virtual uint32_t dirtyMask();
+ virtual uint32_t dirtyMask();
protected:
virtual float getValue(RenderNode* target) const override;
@@ -257,9 +257,9 @@ private:
class RevealAnimator : public BaseRenderNodeAnimator {
public:
- ANDROID_API RevealAnimator(int centerX, int centerY, float startValue, float finalValue);
+ RevealAnimator(int centerX, int centerY, float startValue, float finalValue);
- ANDROID_API virtual uint32_t dirtyMask();
+ virtual uint32_t dirtyMask();
protected:
virtual float getValue(RenderNode* target) const override;
diff --git a/libs/hwui/AnimatorManager.h b/libs/hwui/AnimatorManager.h
index 9575391a8b3f..a0df01d5962c 100644
--- a/libs/hwui/AnimatorManager.h
+++ b/libs/hwui/AnimatorManager.h
@@ -54,7 +54,7 @@ public:
void animateNoDamage(TreeInfo& info);
// Hard-ends all animators. May only be called on the UI thread.
- ANDROID_API void endAllStagingAnimators();
+ void endAllStagingAnimators();
// Hard-ends all animators that have been pushed. Used for cleanup if
// the ActivityContext is being destroyed
diff --git a/libs/hwui/AutoBackendTextureRelease.cpp b/libs/hwui/AutoBackendTextureRelease.cpp
index 72747e8fa543..33264d5d5c86 100644
--- a/libs/hwui/AutoBackendTextureRelease.cpp
+++ b/libs/hwui/AutoBackendTextureRelease.cpp
@@ -25,7 +25,8 @@ using namespace android::uirenderer::renderthread;
namespace android {
namespace uirenderer {
-AutoBackendTextureRelease::AutoBackendTextureRelease(GrContext* context, AHardwareBuffer* buffer) {
+AutoBackendTextureRelease::AutoBackendTextureRelease(GrDirectContext* context,
+ AHardwareBuffer* buffer) {
AHardwareBuffer_Desc desc;
AHardwareBuffer_describe(buffer, &desc);
bool createProtectedImage = 0 != (desc.usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT);
@@ -67,8 +68,9 @@ static void releaseProc(SkImage::ReleaseContext releaseContext) {
textureRelease->unref(false);
}
-void AutoBackendTextureRelease::makeImage(AHardwareBuffer* buffer, android_dataspace dataspace,
- GrContext* context) {
+void AutoBackendTextureRelease::makeImage(AHardwareBuffer* buffer,
+ android_dataspace dataspace,
+ GrDirectContext* context) {
AHardwareBuffer_Desc desc;
AHardwareBuffer_describe(buffer, &desc);
SkColorType colorType = GrAHardwareBufferUtils::GetSkColorTypeFromBufferFormat(desc.format);
@@ -81,7 +83,7 @@ void AutoBackendTextureRelease::makeImage(AHardwareBuffer* buffer, android_datas
}
}
-void AutoBackendTextureRelease::newBufferContent(GrContext* context) {
+void AutoBackendTextureRelease::newBufferContent(GrDirectContext* context) {
if (mBackendTexture.isValid()) {
mUpdateProc(mImageCtx, context);
}
diff --git a/libs/hwui/AutoBackendTextureRelease.h b/libs/hwui/AutoBackendTextureRelease.h
index acdd63cb7921..06f51fcd1105 100644
--- a/libs/hwui/AutoBackendTextureRelease.h
+++ b/libs/hwui/AutoBackendTextureRelease.h
@@ -31,7 +31,8 @@ namespace uirenderer {
*/
class AutoBackendTextureRelease final {
public:
- AutoBackendTextureRelease(GrContext* context, AHardwareBuffer* buffer);
+ AutoBackendTextureRelease(GrDirectContext* context,
+ AHardwareBuffer* buffer);
const GrBackendTexture& getTexture() const { return mBackendTexture; }
@@ -42,9 +43,11 @@ public:
inline sk_sp<SkImage> getImage() const { return mImage; }
- void makeImage(AHardwareBuffer* buffer, android_dataspace dataspace, GrContext* context);
+ void makeImage(AHardwareBuffer* buffer,
+ android_dataspace dataspace,
+ GrDirectContext* context);
- void newBufferContent(GrContext* context);
+ void newBufferContent(GrDirectContext* context);
private:
// The only way to invoke dtor is with unref, when mUsageCount is 0.
diff --git a/libs/hwui/CanvasTransform.cpp b/libs/hwui/CanvasTransform.cpp
index 8c37d73366c2..9d03ce5252a3 100644
--- a/libs/hwui/CanvasTransform.cpp
+++ b/libs/hwui/CanvasTransform.cpp
@@ -22,7 +22,6 @@
#include <SkGradientShader.h>
#include <SkPaint.h>
#include <SkShader.h>
-#include <ui/ColorSpace.h>
#include <algorithm>
#include <cmath>
diff --git a/libs/hwui/ColorMode.h b/libs/hwui/ColorMode.h
new file mode 100644
index 000000000000..6d387f9ef43d
--- /dev/null
+++ b/libs/hwui/ColorMode.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+namespace android::uirenderer {
+
+// Must match the constants in ActivityInfo.java
+enum class ColorMode {
+ // SRGB means HWUI will produce buffer in SRGB color space.
+ Default = 0,
+ // WideColorGamut selects the most optimal colorspace & format for the device's display
+ // Most commonly DisplayP3 + RGBA_8888 currently.
+ WideColorGamut = 1,
+ // HDR Rec2020 + F16
+ Hdr = 2,
+ // HDR Rec2020 + 1010102
+ Hdr10 = 3,
+};
+
+} // namespace android::uirenderer
diff --git a/libs/hwui/DamageAccumulator.h b/libs/hwui/DamageAccumulator.h
index 030a20f31c42..2faa9d012d66 100644
--- a/libs/hwui/DamageAccumulator.h
+++ b/libs/hwui/DamageAccumulator.h
@@ -58,7 +58,7 @@ public:
// Returns the current dirty area, *NOT* transformed by pushed transforms
void peekAtDirty(SkRect* dest) const;
- ANDROID_API void computeCurrentTransform(Matrix4* outMatrix) const;
+ void computeCurrentTransform(Matrix4* outMatrix) const;
void finish(SkRect* totalDirty);
diff --git a/libs/hwui/DeferredLayerUpdater.cpp b/libs/hwui/DeferredLayerUpdater.cpp
index 67d8c07e61de..6589dbd50cf7 100644
--- a/libs/hwui/DeferredLayerUpdater.cpp
+++ b/libs/hwui/DeferredLayerUpdater.cpp
@@ -189,7 +189,7 @@ void DeferredLayerUpdater::detachSurfaceTexture() {
sk_sp<SkImage> DeferredLayerUpdater::ImageSlot::createIfNeeded(AHardwareBuffer* buffer,
android_dataspace dataspace,
bool forceCreate,
- GrContext* context) {
+ GrDirectContext* context) {
if (!mTextureRelease || !mTextureRelease->getImage().get() || dataspace != mDataspace ||
forceCreate || mBuffer != buffer) {
if (buffer != mBuffer) {
diff --git a/libs/hwui/DeferredLayerUpdater.h b/libs/hwui/DeferredLayerUpdater.h
index c44c0d537fa7..6731e9c428d6 100644
--- a/libs/hwui/DeferredLayerUpdater.h
+++ b/libs/hwui/DeferredLayerUpdater.h
@@ -44,11 +44,11 @@ class DeferredLayerUpdater : public VirtualLightRefBase, public IGpuContextCallb
public:
// Note that DeferredLayerUpdater assumes it is taking ownership of the layer
// and will not call incrementRef on it as a result.
- ANDROID_API explicit DeferredLayerUpdater(RenderState& renderState);
+ explicit DeferredLayerUpdater(RenderState& renderState);
- ANDROID_API ~DeferredLayerUpdater();
+ ~DeferredLayerUpdater();
- ANDROID_API bool setSize(int width, int height) {
+ bool setSize(int width, int height) {
if (mWidth != width || mHeight != height) {
mWidth = width;
mHeight = height;
@@ -60,7 +60,7 @@ public:
int getWidth() { return mWidth; }
int getHeight() { return mHeight; }
- ANDROID_API bool setBlend(bool blend) {
+ bool setBlend(bool blend) {
if (blend != mBlend) {
mBlend = blend;
return true;
@@ -68,18 +68,18 @@ public:
return false;
}
- ANDROID_API void setSurfaceTexture(AutoTextureRelease&& consumer);
+ void setSurfaceTexture(AutoTextureRelease&& consumer);
- ANDROID_API void updateTexImage() { mUpdateTexImage = true; }
+ void updateTexImage() { mUpdateTexImage = true; }
- ANDROID_API void setTransform(const SkMatrix* matrix) {
+ void setTransform(const SkMatrix* matrix) {
delete mTransform;
mTransform = matrix ? new SkMatrix(*matrix) : nullptr;
}
SkMatrix* getTransform() { return mTransform; }
- ANDROID_API void setPaint(const SkPaint* paint);
+ void setPaint(const SkPaint* paint);
void apply();
@@ -106,7 +106,7 @@ private:
~ImageSlot() { clear(); }
sk_sp<SkImage> createIfNeeded(AHardwareBuffer* buffer, android_dataspace dataspace,
- bool forceCreate, GrContext* context);
+ bool forceCreate, GrDirectContext* context);
private:
void clear();
diff --git a/libs/hwui/DeviceInfo.cpp b/libs/hwui/DeviceInfo.cpp
index c24224cbbd67..07594715a84c 100644
--- a/libs/hwui/DeviceInfo.cpp
+++ b/libs/hwui/DeviceInfo.cpp
@@ -15,6 +15,8 @@
*/
#include <DeviceInfo.h>
+#include <android/hardware_buffer.h>
+#include <apex/display.h>
#include <log/log.h>
#include <utils/Errors.h>
@@ -30,14 +32,47 @@ DeviceInfo* DeviceInfo::get() {
DeviceInfo::DeviceInfo() {
#if HWUI_NULL_GPU
- mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE;
+ mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE;
#else
- mMaxTextureSize = -1;
+ mMaxTextureSize = -1;
#endif
- updateDisplayInfo();
}
-DeviceInfo::~DeviceInfo() {
- ADisplay_release(mDisplays);
+
+void DeviceInfo::updateDisplayInfo() {
+ if (Properties::isolatedProcess) {
+ return;
+ }
+
+ ADisplay** displays;
+ int size = ADisplay_acquirePhysicalDisplays(&displays);
+
+ if (size <= 0) {
+ LOG_ALWAYS_FATAL("Failed to acquire physical displays for WCG support!");
+ }
+
+ for (int i = 0; i < size; ++i) {
+ // Pick the first internal display for querying the display type
+ // In practice this is controlled by a sysprop so it doesn't really
+ // matter which display we use.
+ if (ADisplay_getDisplayType(displays[i]) == DISPLAY_TYPE_INTERNAL) {
+ // We get the dataspace from DisplayManager already. Allocate space
+ // for the result here but we don't actually care about using it.
+ ADataSpace dataspace;
+ AHardwareBuffer_Format pixelFormat;
+ ADisplay_getPreferredWideColorFormat(displays[i], &dataspace, &pixelFormat);
+
+ if (pixelFormat == AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM) {
+ mWideColorType = SkColorType::kN32_SkColorType;
+ } else if (pixelFormat == AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT) {
+ mWideColorType = SkColorType::kRGBA_F16_SkColorType;
+ } else {
+ LOG_ALWAYS_FATAL("Unreachable: unsupported pixel format: %d", pixelFormat);
+ }
+ ADisplay_release(displays);
+ return;
+ }
+ }
+ LOG_ALWAYS_FATAL("Failed to find a valid physical display for WCG support!");
}
int DeviceInfo::maxTextureSize() const {
@@ -49,75 +84,29 @@ void DeviceInfo::setMaxTextureSize(int maxTextureSize) {
DeviceInfo::get()->mMaxTextureSize = maxTextureSize;
}
+void DeviceInfo::setWideColorDataspace(ADataSpace dataspace) {
+ switch (dataspace) {
+ case ADATASPACE_DISPLAY_P3:
+ get()->mWideColorSpace =
+ SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3);
+ break;
+ case ADATASPACE_SCRGB:
+ get()->mWideColorSpace = SkColorSpace::MakeSRGB();
+ break;
+ case ADATASPACE_SRGB:
+ // when sRGB is returned, it means wide color gamut is not supported.
+ get()->mWideColorSpace = SkColorSpace::MakeSRGB();
+ break;
+ default:
+ LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space.");
+ }
+}
+
void DeviceInfo::onRefreshRateChanged(int64_t vsyncPeriod) {
mVsyncPeriod = vsyncPeriod;
}
-void DeviceInfo::updateDisplayInfo() {
- if (Properties::isolatedProcess) {
- return;
- }
-
- if (mCurrentConfig == nullptr) {
- mDisplaysSize = ADisplay_acquirePhysicalDisplays(&mDisplays);
- LOG_ALWAYS_FATAL_IF(mDisplays == nullptr || mDisplaysSize <= 0,
- "Failed to get physical displays: no connected display: %d!", mDisplaysSize);
- for (size_t i = 0; i < mDisplaysSize; i++) {
- ADisplayType type = ADisplay_getDisplayType(mDisplays[i]);
- if (type == ADisplayType::DISPLAY_TYPE_INTERNAL) {
- mPhysicalDisplayIndex = i;
- break;
- }
- }
- LOG_ALWAYS_FATAL_IF(mPhysicalDisplayIndex < 0, "Failed to find a connected physical display!");
-
-
- // Since we now just got the primary display for the first time, then
- // store the primary display metadata here.
- ADisplay* primaryDisplay = mDisplays[mPhysicalDisplayIndex];
- mMaxRefreshRate = ADisplay_getMaxSupportedFps(primaryDisplay);
- ADataSpace dataspace;
- AHardwareBuffer_Format format;
- ADisplay_getPreferredWideColorFormat(primaryDisplay, &dataspace, &format);
- switch (dataspace) {
- case ADATASPACE_DISPLAY_P3:
- mWideColorSpace =
- SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
- break;
- case ADATASPACE_SCRGB:
- mWideColorSpace = SkColorSpace::MakeSRGB();
- break;
- case ADATASPACE_SRGB:
- // when sRGB is returned, it means wide color gamut is not supported.
- mWideColorSpace = SkColorSpace::MakeSRGB();
- break;
- default:
- LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space.");
- }
- switch (format) {
- case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
- mWideColorType = SkColorType::kN32_SkColorType;
- break;
- case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
- mWideColorType = SkColorType::kRGBA_F16_SkColorType;
- break;
- default:
- LOG_ALWAYS_FATAL("Unreachable: unsupported pixel format.");
- }
- }
- // This method may have been called when the display config changed, so
- // sync with the current configuration.
- ADisplay* primaryDisplay = mDisplays[mPhysicalDisplayIndex];
- status_t status = ADisplay_getCurrentConfig(primaryDisplay, &mCurrentConfig);
- LOG_ALWAYS_FATAL_IF(status, "Failed to get display config, error %d", status);
-
- mWidth = ADisplayConfig_getWidth(mCurrentConfig);
- mHeight = ADisplayConfig_getHeight(mCurrentConfig);
- mDensity = ADisplayConfig_getDensity(mCurrentConfig);
- mVsyncPeriod = static_cast<int64_t>(1000000000 / ADisplayConfig_getFps(mCurrentConfig));
- mCompositorOffset = ADisplayConfig_getCompositorOffsetNanos(mCurrentConfig);
- mAppOffset = ADisplayConfig_getAppVsyncOffsetNanos(mCurrentConfig);
-}
+std::atomic<float> DeviceInfo::sDensity = 2.0;
} /* namespace uirenderer */
} /* namespace android */
diff --git a/libs/hwui/DeviceInfo.h b/libs/hwui/DeviceInfo.h
index 16a22f4706f5..27be62269959 100644
--- a/libs/hwui/DeviceInfo.h
+++ b/libs/hwui/DeviceInfo.h
@@ -16,8 +16,10 @@
#ifndef DEVICEINFO_H
#define DEVICEINFO_H
-#include <apex/display.h>
#include <SkImageInfo.h>
+#include <android/data_space.h>
+
+#include <mutex>
#include "utils/Macros.h"
@@ -36,16 +38,37 @@ public:
static float getMaxRefreshRate() { return get()->mMaxRefreshRate; }
static int32_t getWidth() { return get()->mWidth; }
static int32_t getHeight() { return get()->mHeight; }
- static float getDensity() { return get()->mDensity; }
+ // Gets the density in density-independent pixels
+ static float getDensity() { return sDensity.load(); }
static int64_t getVsyncPeriod() { return get()->mVsyncPeriod; }
- static int64_t getCompositorOffset() { return get()->mCompositorOffset; }
- static int64_t getAppOffset() { return get()->mAppOffset; }
+ static int64_t getCompositorOffset() { return get()->getCompositorOffsetInternal(); }
+ static int64_t getAppOffset() { return get()->mAppVsyncOffsetNanos; }
+ // Sets the density in density-independent pixels
+ static void setDensity(float density) { sDensity.store(density); }
+ static void setMaxRefreshRate(float refreshRate) { get()->mMaxRefreshRate = refreshRate; }
+ static void setWidth(int32_t width) { get()->mWidth = width; }
+ static void setHeight(int32_t height) { get()->mHeight = height; }
+ static void setRefreshRate(float refreshRate) {
+ get()->mVsyncPeriod = static_cast<int64_t>(1000000000 / refreshRate);
+ }
+ static void setPresentationDeadlineNanos(int64_t deadlineNanos) {
+ get()->mPresentationDeadlineNanos = deadlineNanos;
+ }
+ static void setAppVsyncOffsetNanos(int64_t offsetNanos) {
+ get()->mAppVsyncOffsetNanos = offsetNanos;
+ }
+ static void setWideColorDataspace(ADataSpace dataspace);
// this value is only valid after the GPU has been initialized and there is a valid graphics
// context or if you are using the HWUI_NULL_GPU
int maxTextureSize() const;
sk_sp<SkColorSpace> getWideColorSpace() const { return mWideColorSpace; }
- SkColorType getWideColorType() const { return mWideColorType; }
+ SkColorType getWideColorType() {
+ static std::once_flag kFlag;
+ // lazily update display info from SF here, so that the call is performed by RenderThread.
+ std::call_once(kFlag, [&, this]() { updateDisplayInfo(); });
+ return mWideColorType;
+ }
// This method should be called whenever the display refresh rate changes.
void onRefreshRateChanged(int64_t vsyncPeriod);
@@ -54,24 +77,32 @@ private:
friend class renderthread::RenderThread;
static void setMaxTextureSize(int maxTextureSize);
void updateDisplayInfo();
+ int64_t getCompositorOffsetInternal() const {
+ // Assume that SF takes around a millisecond to latch buffers after
+ // waking up
+ return mVsyncPeriod - (mPresentationDeadlineNanos - 1000000);
+ }
DeviceInfo();
- ~DeviceInfo();
+ ~DeviceInfo() = default;
int mMaxTextureSize;
sk_sp<SkColorSpace> mWideColorSpace = SkColorSpace::MakeSRGB();
SkColorType mWideColorType = SkColorType::kN32_SkColorType;
- ADisplayConfig* mCurrentConfig = nullptr;
- ADisplay** mDisplays = nullptr;
int mDisplaysSize = 0;
int mPhysicalDisplayIndex = -1;
float mMaxRefreshRate = 60.0;
int32_t mWidth = 1080;
int32_t mHeight = 1920;
- float mDensity = 2.0;
int64_t mVsyncPeriod = 16666666;
- int64_t mCompositorOffset = 0;
- int64_t mAppOffset = 0;
+ // Magically corresponds with an sf offset of 0 for a sane default.
+ int64_t mPresentationDeadlineNanos = 17666666;
+ int64_t mAppVsyncOffsetNanos = 0;
+
+ // Density is not retrieved from the ADisplay apis, so this may potentially
+ // be called on multiple threads.
+ // Unit is density-independent pixels
+ static std::atomic<float> sDensity;
};
} /* namespace uirenderer */
diff --git a/libs/hwui/FrameInfo.h b/libs/hwui/FrameInfo.h
index 51674fbd557e..dc30617009e7 100644
--- a/libs/hwui/FrameInfo.h
+++ b/libs/hwui/FrameInfo.h
@@ -69,7 +69,7 @@ enum {
};
};
-class ANDROID_API UiFrameInfoBuilder {
+class UiFrameInfoBuilder {
public:
explicit UiFrameInfoBuilder(int64_t* buffer) : mBuffer(buffer) {
memset(mBuffer, 0, UI_THREAD_FRAME_INFO_SIZE * sizeof(int64_t));
diff --git a/libs/hwui/HardwareBitmapUploader.cpp b/libs/hwui/HardwareBitmapUploader.cpp
index a3d552faeb0a..ab9b8b55a4cb 100644
--- a/libs/hwui/HardwareBitmapUploader.cpp
+++ b/libs/hwui/HardwareBitmapUploader.cpp
@@ -16,24 +16,27 @@
#include "HardwareBitmapUploader.h"
-#include "hwui/Bitmap.h"
-#include "renderthread/EglManager.h"
-#include "renderthread/VulkanManager.h"
-#include "thread/ThreadBase.h"
-#include "utils/TimeUtils.h"
-
+#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl3.h>
-#include <GrContext.h>
+#include <GrDirectContext.h>
#include <SkCanvas.h>
#include <SkImage.h>
#include <utils/GLUtils.h>
+#include <utils/NdkUtils.h>
#include <utils/Trace.h>
#include <utils/TraceUtils.h>
+
#include <thread>
+#include "hwui/Bitmap.h"
+#include "renderthread/EglManager.h"
+#include "renderthread/VulkanManager.h"
+#include "thread/ThreadBase.h"
+#include "utils/TimeUtils.h"
+
namespace android::uirenderer {
class AHBUploader;
@@ -42,7 +45,7 @@ class AHBUploader;
static sp<AHBUploader> sUploader = nullptr;
struct FormatInfo {
- PixelFormat pixelFormat;
+ AHardwareBuffer_Format bufferFormat;
GLint format, type;
VkFormat vkFormat;
bool isSupported = false;
@@ -53,12 +56,6 @@ class AHBUploader : public RefBase {
public:
virtual ~AHBUploader() {}
- // Called to start creation of the Vulkan and EGL contexts on another thread before we actually
- // need to do an upload.
- void initialize() {
- onInitialize();
- }
-
void destroy() {
std::lock_guard _lock{mLock};
LOG_ALWAYS_FATAL_IF(mPendingUploads, "terminate called while uploads in progress");
@@ -71,10 +68,10 @@ public:
}
bool uploadHardwareBitmap(const SkBitmap& bitmap, const FormatInfo& format,
- sp<GraphicBuffer> graphicBuffer) {
+ AHardwareBuffer* ahb) {
ATRACE_CALL();
beginUpload();
- bool result = onUploadHardwareBitmap(bitmap, format, graphicBuffer);
+ bool result = onUploadHardwareBitmap(bitmap, format, ahb);
endUpload();
return result;
}
@@ -88,12 +85,11 @@ protected:
sp<ThreadBase> mUploadThread = nullptr;
private:
- virtual void onInitialize() = 0;
virtual void onIdle() = 0;
virtual void onDestroy() = 0;
virtual bool onUploadHardwareBitmap(const SkBitmap& bitmap, const FormatInfo& format,
- sp<GraphicBuffer> graphicBuffer) = 0;
+ AHardwareBuffer* ahb) = 0;
virtual void onBeginUpload() = 0;
bool shouldTimeOutLocked() {
@@ -138,7 +134,6 @@ private:
class EGLUploader : public AHBUploader {
private:
- void onInitialize() override {}
void onDestroy() override {
mEglManager.destroy();
}
@@ -165,16 +160,16 @@ private:
}
bool onUploadHardwareBitmap(const SkBitmap& bitmap, const FormatInfo& format,
- sp<GraphicBuffer> graphicBuffer) override {
+ AHardwareBuffer* ahb) override {
ATRACE_CALL();
EGLDisplay display = getUploadEglDisplay();
LOG_ALWAYS_FATAL_IF(display == EGL_NO_DISPLAY, "Failed to get EGL_DEFAULT_DISPLAY! err=%s",
uirenderer::renderthread::EglManager::eglErrorString());
- // We use an EGLImage to access the content of the GraphicBuffer
+ // We use an EGLImage to access the content of the buffer
// The EGL image is later bound to a 2D texture
- EGLClientBuffer clientBuffer = (EGLClientBuffer)graphicBuffer->getNativeBuffer();
+ const EGLClientBuffer clientBuffer = eglGetNativeClientBufferANDROID(ahb);
AutoEglImage autoImage(display, clientBuffer);
if (autoImage.image == EGL_NO_IMAGE_KHR) {
ALOGW("Could not create EGL image, err =%s",
@@ -228,62 +223,67 @@ private:
class VkUploader : public AHBUploader {
private:
- void onInitialize() override {
- std::lock_guard _lock{mLock};
- if (!mUploadThread) {
- mUploadThread = new ThreadBase{};
- }
- if (!mUploadThread->isRunning()) {
- mUploadThread->start("GrallocUploadThread");
- }
-
- mUploadThread->queue().post([this]() {
- std::lock_guard _lock{mVkLock};
- if (!mVulkanManager.hasVkContext()) {
- mVulkanManager.initialize();
- }
- });
- }
void onDestroy() override {
+ std::lock_guard _lock{mVkLock};
mGrContext.reset();
- mVulkanManager.destroy();
+ mVulkanManagerStrong.clear();
}
void onIdle() override {
- mGrContext.reset();
+ onDestroy();
}
- void onBeginUpload() override {
- {
- std::lock_guard _lock{mVkLock};
- if (!mVulkanManager.hasVkContext()) {
- LOG_ALWAYS_FATAL_IF(mGrContext,
- "GrContext exists with no VulkanManager for vulkan uploads");
- mUploadThread->queue().runSync([this]() {
- mVulkanManager.initialize();
- });
- }
- }
- if (!mGrContext) {
- GrContextOptions options;
- mGrContext = mVulkanManager.createContext(options);
- LOG_ALWAYS_FATAL_IF(!mGrContext, "failed to create GrContext for vulkan uploads");
- this->postIdleTimeoutCheck();
- }
- }
+ void onBeginUpload() override {}
bool onUploadHardwareBitmap(const SkBitmap& bitmap, const FormatInfo& format,
- sp<GraphicBuffer> graphicBuffer) override {
- ATRACE_CALL();
+ AHardwareBuffer* ahb) override {
+ bool uploadSucceeded = false;
+ mUploadThread->queue().runSync([this, &uploadSucceeded, bitmap, ahb]() {
+ ATRACE_CALL();
+ std::lock_guard _lock{mVkLock};
+
+ renderthread::VulkanManager* vkManager = getVulkanManager();
+ if (!vkManager->hasVkContext()) {
+ LOG_ALWAYS_FATAL_IF(mGrContext,
+ "GrContext exists with no VulkanManager for vulkan uploads");
+ vkManager->initialize();
+ }
+
+ if (!mGrContext) {
+ GrContextOptions options;
+ mGrContext = vkManager->createContext(options,
+ renderthread::VulkanManager::ContextType::kUploadThread);
+ LOG_ALWAYS_FATAL_IF(!mGrContext, "failed to create GrContext for vulkan uploads");
+ this->postIdleTimeoutCheck();
+ }
+
+ sk_sp<SkImage> image =
+ SkImage::MakeFromAHardwareBufferWithData(mGrContext.get(), bitmap.pixmap(), ahb);
+ mGrContext->submit(true);
+
+ uploadSucceeded = (image.get() != nullptr);
+ });
+ return uploadSucceeded;
+ }
- std::lock_guard _lock{mLock};
+ /* must be called on the upload thread after the vkLock has been acquired */
+ renderthread::VulkanManager* getVulkanManager() {
+ if (!mVulkanManagerStrong) {
+ mVulkanManagerStrong = mVulkanManagerWeak.promote();
- sk_sp<SkImage> image = SkImage::MakeFromAHardwareBufferWithData(mGrContext.get(),
- bitmap.pixmap(), reinterpret_cast<AHardwareBuffer*>(graphicBuffer.get()));
- return (image.get() != nullptr);
+ // create a new manager if we couldn't promote the weak ref
+ if (!mVulkanManagerStrong) {
+ mVulkanManagerStrong = renderthread::VulkanManager::getInstance();
+ mGrContext.reset();
+ mVulkanManagerWeak = mVulkanManagerStrong;
+ }
+ }
+
+ return mVulkanManagerStrong.get();
}
- sk_sp<GrContext> mGrContext;
- renderthread::VulkanManager mVulkanManager;
+ sk_sp<GrDirectContext> mGrContext;
+ sp<renderthread::VulkanManager> mVulkanManagerStrong;
+ wp<renderthread::VulkanManager> mVulkanManagerWeak;
std::mutex mVkLock;
};
@@ -294,13 +294,17 @@ bool HardwareBitmapUploader::hasFP16Support() {
// Gralloc shouldn't let us create a USAGE_HW_TEXTURE if GLES is unable to consume it, so
// we don't need to double-check the GLES version/extension.
std::call_once(sOnce, []() {
- sp<GraphicBuffer> buffer = new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBA_FP16,
- GraphicBuffer::USAGE_HW_TEXTURE |
- GraphicBuffer::USAGE_SW_WRITE_NEVER |
- GraphicBuffer::USAGE_SW_READ_NEVER,
- "tempFp16Buffer");
- status_t error = buffer->initCheck();
- hasFP16Support = !error;
+ AHardwareBuffer_Desc desc = {
+ .width = 1,
+ .height = 1,
+ .layers = 1,
+ .format = AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT,
+ .usage = AHARDWAREBUFFER_USAGE_CPU_READ_NEVER |
+ AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER |
+ AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE,
+ };
+ UniqueAHardwareBuffer buffer = allocateAHardwareBuffer(desc);
+ hasFP16Support = buffer != nullptr;
});
return hasFP16Support;
@@ -314,7 +318,7 @@ static FormatInfo determineFormat(const SkBitmap& skBitmap, bool usingGL) {
[[fallthrough]];
// ARGB_4444 is upconverted to RGBA_8888
case kARGB_4444_SkColorType:
- formatInfo.pixelFormat = PIXEL_FORMAT_RGBA_8888;
+ formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
formatInfo.format = GL_RGBA;
formatInfo.type = GL_UNSIGNED_BYTE;
formatInfo.vkFormat = VK_FORMAT_R8G8B8A8_UNORM;
@@ -323,25 +327,25 @@ static FormatInfo determineFormat(const SkBitmap& skBitmap, bool usingGL) {
formatInfo.isSupported = HardwareBitmapUploader::hasFP16Support();
if (formatInfo.isSupported) {
formatInfo.type = GL_HALF_FLOAT;
- formatInfo.pixelFormat = PIXEL_FORMAT_RGBA_FP16;
+ formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT;
formatInfo.vkFormat = VK_FORMAT_R16G16B16A16_SFLOAT;
} else {
formatInfo.type = GL_UNSIGNED_BYTE;
- formatInfo.pixelFormat = PIXEL_FORMAT_RGBA_8888;
+ formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
formatInfo.vkFormat = VK_FORMAT_R8G8B8A8_UNORM;
}
formatInfo.format = GL_RGBA;
break;
case kRGB_565_SkColorType:
formatInfo.isSupported = true;
- formatInfo.pixelFormat = PIXEL_FORMAT_RGB_565;
+ formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;
formatInfo.format = GL_RGB;
formatInfo.type = GL_UNSIGNED_SHORT_5_6_5;
formatInfo.vkFormat = VK_FORMAT_R5G6B5_UNORM_PACK16;
break;
case kGray_8_SkColorType:
formatInfo.isSupported = usingGL;
- formatInfo.pixelFormat = PIXEL_FORMAT_RGBA_8888;
+ formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
formatInfo.format = GL_LUMINANCE;
formatInfo.type = GL_UNSIGNED_BYTE;
formatInfo.vkFormat = VK_FORMAT_R8G8B8A8_UNORM;
@@ -394,35 +398,33 @@ sk_sp<Bitmap> HardwareBitmapUploader::allocateHardwareBitmap(const SkBitmap& sou
}
SkBitmap bitmap = makeHwCompatible(format, sourceBitmap);
- sp<GraphicBuffer> buffer = new GraphicBuffer(
- static_cast<uint32_t>(bitmap.width()), static_cast<uint32_t>(bitmap.height()),
- format.pixelFormat,
- GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_NEVER |
- GraphicBuffer::USAGE_SW_READ_NEVER,
- std::string("Bitmap::allocateHardwareBitmap pid [") + std::to_string(getpid()) +
- "]");
-
- status_t error = buffer->initCheck();
- if (error < 0) {
- ALOGW("createGraphicBuffer() failed in GraphicBuffer.create()");
+ AHardwareBuffer_Desc desc = {
+ .width = static_cast<uint32_t>(bitmap.width()),
+ .height = static_cast<uint32_t>(bitmap.height()),
+ .layers = 1,
+ .format = format.bufferFormat,
+ .usage = AHARDWAREBUFFER_USAGE_CPU_READ_NEVER | AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER |
+ AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE,
+ };
+ UniqueAHardwareBuffer ahb = allocateAHardwareBuffer(desc);
+ if (!ahb) {
+ ALOGW("allocateHardwareBitmap() failed in AHardwareBuffer_allocate()");
return nullptr;
- }
+ };
createUploader(usingGL);
- if (!sUploader->uploadHardwareBitmap(bitmap, format, buffer)) {
+ if (!sUploader->uploadHardwareBitmap(bitmap, format, ahb.get())) {
return nullptr;
}
- return Bitmap::createFrom(buffer->toAHardwareBuffer(), bitmap.colorType(),
- bitmap.refColorSpace(), bitmap.alphaType(),
- Bitmap::computePalette(bitmap));
+ return Bitmap::createFrom(ahb.get(), bitmap.colorType(), bitmap.refColorSpace(),
+ bitmap.alphaType(), Bitmap::computePalette(bitmap));
}
void HardwareBitmapUploader::initialize() {
bool usingGL = uirenderer::Properties::getRenderPipelineType() ==
uirenderer::RenderPipelineType::SkiaGL;
createUploader(usingGL);
- sUploader->initialize();
}
void HardwareBitmapUploader::terminate() {
diff --git a/libs/hwui/HardwareBitmapUploader.h b/libs/hwui/HardwareBitmapUploader.h
index 72243d23dd35..ad7a95a4fa03 100644
--- a/libs/hwui/HardwareBitmapUploader.h
+++ b/libs/hwui/HardwareBitmapUploader.h
@@ -20,7 +20,7 @@
namespace android::uirenderer {
-class ANDROID_API HardwareBitmapUploader {
+class HardwareBitmapUploader {
public:
static void initialize();
static void terminate();
diff --git a/libs/hwui/Interpolator.h b/libs/hwui/Interpolator.h
index 452988fc8711..131cc3935f10 100644
--- a/libs/hwui/Interpolator.h
+++ b/libs/hwui/Interpolator.h
@@ -37,12 +37,12 @@ protected:
Interpolator() {}
};
-class ANDROID_API AccelerateDecelerateInterpolator : public Interpolator {
+class AccelerateDecelerateInterpolator : public Interpolator {
public:
virtual float interpolate(float input) override;
};
-class ANDROID_API AccelerateInterpolator : public Interpolator {
+class AccelerateInterpolator : public Interpolator {
public:
explicit AccelerateInterpolator(float factor) : mFactor(factor), mDoubleFactor(factor * 2) {}
virtual float interpolate(float input) override;
@@ -52,7 +52,7 @@ private:
const float mDoubleFactor;
};
-class ANDROID_API AnticipateInterpolator : public Interpolator {
+class AnticipateInterpolator : public Interpolator {
public:
explicit AnticipateInterpolator(float tension) : mTension(tension) {}
virtual float interpolate(float input) override;
@@ -61,7 +61,7 @@ private:
const float mTension;
};
-class ANDROID_API AnticipateOvershootInterpolator : public Interpolator {
+class AnticipateOvershootInterpolator : public Interpolator {
public:
explicit AnticipateOvershootInterpolator(float tension) : mTension(tension) {}
virtual float interpolate(float input) override;
@@ -70,12 +70,12 @@ private:
const float mTension;
};
-class ANDROID_API BounceInterpolator : public Interpolator {
+class BounceInterpolator : public Interpolator {
public:
virtual float interpolate(float input) override;
};
-class ANDROID_API CycleInterpolator : public Interpolator {
+class CycleInterpolator : public Interpolator {
public:
explicit CycleInterpolator(float cycles) : mCycles(cycles) {}
virtual float interpolate(float input) override;
@@ -84,7 +84,7 @@ private:
const float mCycles;
};
-class ANDROID_API DecelerateInterpolator : public Interpolator {
+class DecelerateInterpolator : public Interpolator {
public:
explicit DecelerateInterpolator(float factor) : mFactor(factor) {}
virtual float interpolate(float input) override;
@@ -93,12 +93,12 @@ private:
const float mFactor;
};
-class ANDROID_API LinearInterpolator : public Interpolator {
+class LinearInterpolator : public Interpolator {
public:
virtual float interpolate(float input) override { return input; }
};
-class ANDROID_API OvershootInterpolator : public Interpolator {
+class OvershootInterpolator : public Interpolator {
public:
explicit OvershootInterpolator(float tension) : mTension(tension) {}
virtual float interpolate(float input) override;
@@ -107,7 +107,7 @@ private:
const float mTension;
};
-class ANDROID_API PathInterpolator : public Interpolator {
+class PathInterpolator : public Interpolator {
public:
explicit PathInterpolator(std::vector<float>&& x, std::vector<float>&& y) : mX(x), mY(y) {}
virtual float interpolate(float input) override;
@@ -117,7 +117,7 @@ private:
std::vector<float> mY;
};
-class ANDROID_API LUTInterpolator : public Interpolator {
+class LUTInterpolator : public Interpolator {
public:
LUTInterpolator(float* values, size_t size);
~LUTInterpolator();
diff --git a/libs/hwui/Matrix.h b/libs/hwui/Matrix.h
index 0c515a41689d..4c6e1a0a6eee 100644
--- a/libs/hwui/Matrix.h
+++ b/libs/hwui/Matrix.h
@@ -44,7 +44,7 @@ namespace uirenderer {
// Classes
///////////////////////////////////////////////////////////////////////////////
-class ANDROID_API Matrix4 {
+class Matrix4 {
public:
float data[16];
diff --git a/libs/hwui/PathParser.h b/libs/hwui/PathParser.h
index 878bb7c0f137..859697eb3e9b 100644
--- a/libs/hwui/PathParser.h
+++ b/libs/hwui/PathParser.h
@@ -30,17 +30,17 @@ namespace uirenderer {
class PathParser {
public:
- struct ANDROID_API ParseResult {
+ struct ParseResult {
bool failureOccurred = false;
std::string failureMessage;
};
/**
* Parse the string literal and create a Skia Path. Return true on success.
*/
- ANDROID_API static void parseAsciiStringForSkPath(SkPath* outPath, ParseResult* result,
- const char* pathStr, size_t strLength);
- ANDROID_API static void getPathDataFromAsciiString(PathData* outData, ParseResult* result,
- const char* pathStr, size_t strLength);
+ static void parseAsciiStringForSkPath(SkPath* outPath, ParseResult* result,
+ const char* pathStr, size_t strLength);
+ static void getPathDataFromAsciiString(PathData* outData, ParseResult* result,
+ const char* pathStr, size_t strLength);
static void dump(const PathData& data);
static void validateVerbAndPoints(char verb, size_t points, ParseResult* result);
};
diff --git a/libs/hwui/Properties.cpp b/libs/hwui/Properties.cpp
index 446e81e65bb8..ba44d056dda3 100644
--- a/libs/hwui/Properties.cpp
+++ b/libs/hwui/Properties.cpp
@@ -78,6 +78,7 @@ bool Properties::isolatedProcess = false;
int Properties::contextPriority = 0;
int Properties::defaultRenderAhead = -1;
+float Properties::defaultSdrWhitePoint = 200.f;
bool Properties::load() {
bool prevDebugLayersUpdates = debugLayersUpdates;
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index d3ecb54d94f6..85a0f4aa7809 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -213,10 +213,10 @@ public:
static int overrideSpotShadowStrength;
static ProfileType getProfileType();
- ANDROID_API static RenderPipelineType peekRenderPipelineType();
- ANDROID_API static RenderPipelineType getRenderPipelineType();
+ static RenderPipelineType peekRenderPipelineType();
+ static RenderPipelineType getRenderPipelineType();
- ANDROID_API static bool enableHighContrastText;
+ static bool enableHighContrastText;
// Should be used only by test apps
static bool waitForGpuCompletion;
@@ -235,20 +235,22 @@ public:
static bool skpCaptureEnabled;
// For experimentation b/68769804
- ANDROID_API static bool enableRTAnimations;
+ static bool enableRTAnimations;
// Used for testing only to change the render pipeline.
static void overrideRenderPipelineType(RenderPipelineType);
static bool runningInEmulator;
- ANDROID_API static bool debuggingEnabled;
- ANDROID_API static bool isolatedProcess;
+ static bool debuggingEnabled;
+ static bool isolatedProcess;
- ANDROID_API static int contextPriority;
+ static int contextPriority;
static int defaultRenderAhead;
+ static float defaultSdrWhitePoint;
+
private:
static ProfileType sProfileType;
static bool sDisableProfileBars;
diff --git a/libs/hwui/PropertyValuesAnimatorSet.h b/libs/hwui/PropertyValuesAnimatorSet.h
index e4214b22d1cc..c04a0b9b0fe7 100644
--- a/libs/hwui/PropertyValuesAnimatorSet.h
+++ b/libs/hwui/PropertyValuesAnimatorSet.h
@@ -44,7 +44,7 @@ private:
};
// TODO: This class should really be named VectorDrawableAnimator
-class ANDROID_API PropertyValuesAnimatorSet : public BaseRenderNodeAnimator {
+class PropertyValuesAnimatorSet : public BaseRenderNodeAnimator {
public:
friend class PropertyAnimatorSetListener;
PropertyValuesAnimatorSet();
diff --git a/libs/hwui/PropertyValuesHolder.h b/libs/hwui/PropertyValuesHolder.h
index 0a799d3c0b5c..bb26cbe7bc9b 100644
--- a/libs/hwui/PropertyValuesHolder.h
+++ b/libs/hwui/PropertyValuesHolder.h
@@ -28,7 +28,7 @@ namespace uirenderer {
* When a fraction in [0f, 1f] is provided, the holder will calculate an interpolated value based
* on its start and end value, and set the new value on the VectorDrawble's corresponding property.
*/
-class ANDROID_API PropertyValuesHolder {
+class PropertyValuesHolder {
public:
virtual void setFraction(float fraction) = 0;
virtual ~PropertyValuesHolder() {}
@@ -49,19 +49,19 @@ public:
}
};
-class ANDROID_API ColorEvaluator : public Evaluator<SkColor> {
+class ColorEvaluator : public Evaluator<SkColor> {
public:
virtual void evaluate(SkColor* outColor, const SkColor& from, const SkColor& to,
float fraction) const override;
};
-class ANDROID_API PathEvaluator : public Evaluator<PathData> {
+class PathEvaluator : public Evaluator<PathData> {
virtual void evaluate(PathData* out, const PathData& from, const PathData& to,
float fraction) const override;
};
template <typename T>
-class ANDROID_API PropertyValuesHolderImpl : public PropertyValuesHolder {
+class PropertyValuesHolderImpl : public PropertyValuesHolder {
public:
PropertyValuesHolderImpl(const T& startValue, const T& endValue)
: mStartValue(startValue), mEndValue(endValue) {}
@@ -85,7 +85,7 @@ protected:
T mEndValue;
};
-class ANDROID_API GroupPropertyValuesHolder : public PropertyValuesHolderImpl<float> {
+class GroupPropertyValuesHolder : public PropertyValuesHolderImpl<float> {
public:
GroupPropertyValuesHolder(VectorDrawable::Group* ptr, int propertyId, float startValue,
float endValue)
@@ -99,7 +99,7 @@ private:
int mPropertyId;
};
-class ANDROID_API FullPathColorPropertyValuesHolder : public PropertyValuesHolderImpl<SkColor> {
+class FullPathColorPropertyValuesHolder : public PropertyValuesHolderImpl<SkColor> {
public:
FullPathColorPropertyValuesHolder(VectorDrawable::FullPath* ptr, int propertyId,
SkColor startValue, SkColor endValue)
@@ -116,7 +116,7 @@ private:
int mPropertyId;
};
-class ANDROID_API FullPathPropertyValuesHolder : public PropertyValuesHolderImpl<float> {
+class FullPathPropertyValuesHolder : public PropertyValuesHolderImpl<float> {
public:
FullPathPropertyValuesHolder(VectorDrawable::FullPath* ptr, int propertyId, float startValue,
float endValue)
@@ -132,7 +132,7 @@ private:
int mPropertyId;
};
-class ANDROID_API PathDataPropertyValuesHolder : public PropertyValuesHolderImpl<PathData> {
+class PathDataPropertyValuesHolder : public PropertyValuesHolderImpl<PathData> {
public:
PathDataPropertyValuesHolder(VectorDrawable::Path* ptr, PathData* startValue,
PathData* endValue)
@@ -146,7 +146,7 @@ private:
PathData mPathData;
};
-class ANDROID_API RootAlphaPropertyValuesHolder : public PropertyValuesHolderImpl<float> {
+class RootAlphaPropertyValuesHolder : public PropertyValuesHolderImpl<float> {
public:
RootAlphaPropertyValuesHolder(VectorDrawable::Tree* tree, float startValue, float endValue)
: PropertyValuesHolderImpl(startValue, endValue), mTree(tree) {
diff --git a/libs/hwui/Readback.cpp b/libs/hwui/Readback.cpp
index 39900e65cb8a..b71bb07dbc86 100644
--- a/libs/hwui/Readback.cpp
+++ b/libs/hwui/Readback.cpp
@@ -18,7 +18,6 @@
#include <sync/sync.h>
#include <system/window.h>
-#include <ui/GraphicBuffer.h>
#include "DeferredLayerUpdater.h"
#include "Properties.h"
@@ -28,6 +27,7 @@
#include "renderthread/VulkanManager.h"
#include "utils/Color.h"
#include "utils/MathUtils.h"
+#include "utils/NdkUtils.h"
#include "utils/TraceUtils.h"
using namespace android::uirenderer::renderthread;
@@ -54,8 +54,7 @@ CopyResult Readback::copySurfaceInto(ANativeWindow* window, const Rect& srcRect,
return CopyResult::SourceEmpty;
}
- std::unique_ptr<AHardwareBuffer, decltype(&AHardwareBuffer_release)> sourceBuffer(
- rawSourceBuffer, AHardwareBuffer_release);
+ UniqueAHardwareBuffer sourceBuffer{rawSourceBuffer};
AHardwareBuffer_Desc description;
AHardwareBuffer_describe(sourceBuffer.get(), &description);
if (description.usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT) {
@@ -119,7 +118,7 @@ CopyResult Readback::copyImageInto(const sk_sp<SkImage>& image, Matrix4& texTran
}
int imgWidth = image->width();
int imgHeight = image->height();
- sk_sp<GrContext> grContext = sk_ref_sp(mRenderThread.getGrContext());
+ sk_sp<GrDirectContext> grContext = sk_ref_sp(mRenderThread.getGrContext());
if (bitmap->colorType() == kRGBA_F16_SkColorType &&
!grContext->colorTypeSupportedAsSurface(bitmap->colorType())) {
diff --git a/libs/hwui/RecordingCanvas.cpp b/libs/hwui/RecordingCanvas.cpp
index dc467c41baed..473dc53dc4bf 100644
--- a/libs/hwui/RecordingCanvas.cpp
+++ b/libs/hwui/RecordingCanvas.cpp
@@ -96,7 +96,7 @@ struct Restore final : Op {
struct SaveLayer final : Op {
static const auto kType = Type::SaveLayer;
SaveLayer(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
- const SkImage* clipMask, const SkMatrix* clipMatrix, SkCanvas::SaveLayerFlags flags) {
+ SkCanvas::SaveLayerFlags flags) {
if (bounds) {
this->bounds = *bounds;
}
@@ -104,19 +104,14 @@ struct SaveLayer final : Op {
this->paint = *paint;
}
this->backdrop = sk_ref_sp(backdrop);
- this->clipMask = sk_ref_sp(clipMask);
- this->clipMatrix = clipMatrix ? *clipMatrix : SkMatrix::I();
this->flags = flags;
}
SkRect bounds = kUnset;
SkPaint paint;
sk_sp<const SkImageFilter> backdrop;
- sk_sp<const SkImage> clipMask;
- SkMatrix clipMatrix;
SkCanvas::SaveLayerFlags flags;
void draw(SkCanvas* c, const SkMatrix&) const {
- c->saveLayer({maybe_unset(bounds), &paint, backdrop.get(), clipMask.get(),
- clipMatrix.isIdentity() ? nullptr : &clipMatrix, flags});
+ c->saveLayer({maybe_unset(bounds), &paint, backdrop.get(), flags});
}
};
struct SaveBehind final : Op {
@@ -132,9 +127,9 @@ struct SaveBehind final : Op {
struct Concat44 final : Op {
static const auto kType = Type::Concat44;
- Concat44(const SkScalar m[16]) { memcpy(colMajor, m, sizeof(colMajor)); }
- SkScalar colMajor[16];
- void draw(SkCanvas* c, const SkMatrix&) const { c->experimental_concat44(colMajor); }
+ Concat44(const SkM44& m) : matrix(m) {}
+ SkM44 matrix;
+ void draw(SkCanvas* c, const SkMatrix&) const { c->concat(matrix); }
};
struct Concat final : Op {
static const auto kType = Type::Concat;
@@ -448,14 +443,13 @@ struct DrawPoints final : Op {
};
struct DrawVertices final : Op {
static const auto kType = Type::DrawVertices;
- DrawVertices(const SkVertices* v, int bc, SkBlendMode m, const SkPaint& p)
- : vertices(sk_ref_sp(const_cast<SkVertices*>(v))), boneCount(bc), mode(m), paint(p) {}
+ DrawVertices(const SkVertices* v, SkBlendMode m, const SkPaint& p)
+ : vertices(sk_ref_sp(const_cast<SkVertices*>(v))), mode(m), paint(p) {}
sk_sp<SkVertices> vertices;
- int boneCount;
SkBlendMode mode;
SkPaint paint;
void draw(SkCanvas* c, const SkMatrix&) const {
- c->drawVertices(vertices, pod<SkVertices::Bone>(this), boneCount, mode, paint);
+ c->drawVertices(vertices, mode, paint);
}
};
struct DrawAtlas final : Op {
@@ -530,6 +524,7 @@ void* DisplayListData::push(size_t pod, Args&&... args) {
// Next greater multiple of SKLITEDL_PAGE.
fReserved = (fUsed + skip + SKLITEDL_PAGE) & ~(SKLITEDL_PAGE - 1);
fBytes.realloc(fReserved);
+ LOG_ALWAYS_FATAL_IF(fBytes.get() == nullptr, "realloc(%zd) failed", fReserved);
}
SkASSERT(fUsed + skip <= fReserved);
auto op = (T*)(fBytes.get() + fUsed);
@@ -565,17 +560,16 @@ void DisplayListData::restore() {
this->push<Restore>(0);
}
void DisplayListData::saveLayer(const SkRect* bounds, const SkPaint* paint,
- const SkImageFilter* backdrop, const SkImage* clipMask,
- const SkMatrix* clipMatrix, SkCanvas::SaveLayerFlags flags) {
- this->push<SaveLayer>(0, bounds, paint, backdrop, clipMask, clipMatrix, flags);
+ const SkImageFilter* backdrop, SkCanvas::SaveLayerFlags flags) {
+ this->push<SaveLayer>(0, bounds, paint, backdrop, flags);
}
void DisplayListData::saveBehind(const SkRect* subset) {
this->push<SaveBehind>(0, subset);
}
-void DisplayListData::concat44(const SkScalar colMajor[16]) {
- this->push<Concat44>(0, colMajor);
+void DisplayListData::concat(const SkM44& m) {
+ this->push<Concat44>(0, m);
}
void DisplayListData::concat(const SkMatrix& matrix) {
this->push<Concat>(0, matrix);
@@ -686,11 +680,8 @@ void DisplayListData::drawPoints(SkCanvas::PointMode mode, size_t count, const S
void* pod = this->push<DrawPoints>(count * sizeof(SkPoint), mode, count, paint);
copy_v(pod, points, count);
}
-void DisplayListData::drawVertices(const SkVertices* vertices, const SkVertices::Bone bones[],
- int boneCount, SkBlendMode mode, const SkPaint& paint) {
- void* pod = this->push<DrawVertices>(boneCount * sizeof(SkVertices::Bone), vertices, boneCount,
- mode, paint);
- copy_v(pod, bones, boneCount);
+void DisplayListData::drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) {
+ this->push<DrawVertices>(0, vertices, mode, paint);
}
void DisplayListData::drawAtlas(const SkImage* atlas, const SkRSXform xforms[], const SkRect texs[],
const SkColor colors[], int count, SkBlendMode xfermode,
@@ -823,8 +814,7 @@ void RecordingCanvas::willSave() {
fDL->save();
}
SkCanvas::SaveLayerStrategy RecordingCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
- fDL->saveLayer(rec.fBounds, rec.fPaint, rec.fBackdrop, rec.fClipMask, rec.fClipMatrix,
- rec.fSaveLayerFlags);
+ fDL->saveLayer(rec.fBounds, rec.fPaint, rec.fBackdrop, rec.fSaveLayerFlags);
return SkCanvas::kNoLayer_SaveLayerStrategy;
}
void RecordingCanvas::willRestore() {
@@ -841,8 +831,8 @@ bool RecordingCanvas::onDoSaveBehind(const SkRect* subset) {
return false;
}
-void RecordingCanvas::didConcat44(const SkScalar colMajor[16]) {
- fDL->concat44(colMajor);
+void RecordingCanvas::didConcat44(const SkM44& m) {
+ fDL->concat(m);
}
void RecordingCanvas::didConcat(const SkMatrix& matrix) {
fDL->concat(matrix);
@@ -929,24 +919,6 @@ void RecordingCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScala
fDL->drawTextBlob(blob, x, y, paint);
}
-void RecordingCanvas::onDrawBitmap(const SkBitmap& bm, SkScalar x, SkScalar y,
- const SkPaint* paint) {
- fDL->drawImage(SkImage::MakeFromBitmap(bm), x, y, paint, BitmapPalette::Unknown);
-}
-void RecordingCanvas::onDrawBitmapNine(const SkBitmap& bm, const SkIRect& center, const SkRect& dst,
- const SkPaint* paint) {
- fDL->drawImageNine(SkImage::MakeFromBitmap(bm), center, dst, paint);
-}
-void RecordingCanvas::onDrawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRect& dst,
- const SkPaint* paint, SrcRectConstraint constraint) {
- fDL->drawImageRect(SkImage::MakeFromBitmap(bm), src, dst, paint, constraint,
- BitmapPalette::Unknown);
-}
-void RecordingCanvas::onDrawBitmapLattice(const SkBitmap& bm, const SkCanvas::Lattice& lattice,
- const SkRect& dst, const SkPaint* paint) {
- fDL->drawImageLattice(SkImage::MakeFromBitmap(bm), lattice, dst, paint, BitmapPalette::Unknown);
-}
-
void RecordingCanvas::drawImage(const sk_sp<SkImage>& image, SkScalar x, SkScalar y,
const SkPaint* paint, BitmapPalette palette) {
fDL->drawImage(image, x, y, paint, palette);
@@ -1007,9 +979,8 @@ void RecordingCanvas::onDrawPoints(SkCanvas::PointMode mode, size_t count, const
fDL->drawPoints(mode, count, pts, paint);
}
void RecordingCanvas::onDrawVerticesObject(const SkVertices* vertices,
- const SkVertices::Bone bones[], int boneCount,
SkBlendMode mode, const SkPaint& paint) {
- fDL->drawVertices(vertices, bones, boneCount, mode, paint);
+ fDL->drawVertices(vertices, mode, paint);
}
void RecordingCanvas::onDrawAtlas(const SkImage* atlas, const SkRSXform xforms[],
const SkRect texs[], const SkColor colors[], int count,
diff --git a/libs/hwui/RecordingCanvas.h b/libs/hwui/RecordingCanvas.h
index 7eb1ce3eb18a..63d120c4ca19 100644
--- a/libs/hwui/RecordingCanvas.h
+++ b/libs/hwui/RecordingCanvas.h
@@ -77,12 +77,11 @@ private:
void flush();
void save();
- void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, const SkImage*,
- const SkMatrix*, SkCanvas::SaveLayerFlags);
+ void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, SkCanvas::SaveLayerFlags);
void saveBehind(const SkRect*);
void restore();
- void concat44(const SkScalar colMajor[16]);
+ void concat(const SkM44&);
void concat(const SkMatrix&);
void setMatrix(const SkMatrix&);
void scale(SkScalar, SkScalar);
@@ -120,8 +119,7 @@ private:
void drawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode,
const SkPaint&);
void drawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint&);
- void drawVertices(const SkVertices*, const SkVertices::Bone bones[], int boneCount, SkBlendMode,
- const SkPaint&);
+ void drawVertices(const SkVertices*, SkBlendMode, const SkPaint&);
void drawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
SkBlendMode, const SkRect*, const SkPaint*);
void drawShadowRec(const SkPath&, const SkDrawShadowRec&);
@@ -155,7 +153,7 @@ public:
void onFlush() override;
- void didConcat44(const SkScalar[16]) override;
+ void didConcat44(const SkM44&) override;
void didConcat(const SkMatrix&) override;
void didSetMatrix(const SkMatrix&) override;
void didScale(SkScalar, SkScalar) override;
@@ -182,13 +180,6 @@ public:
void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint&) override;
- void onDrawBitmap(const SkBitmap&, SkScalar, SkScalar, const SkPaint*) override;
- void onDrawBitmapLattice(const SkBitmap&, const Lattice&, const SkRect&,
- const SkPaint*) override;
- void onDrawBitmapNine(const SkBitmap&, const SkIRect&, const SkRect&, const SkPaint*) override;
- void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
- SrcRectConstraint) override;
-
void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top, const SkPaint* paint,
BitmapPalette pallete);
@@ -206,8 +197,7 @@ public:
void onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode,
const SkPaint&) override;
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
- void onDrawVerticesObject(const SkVertices*, const SkVertices::Bone bones[], int boneCount,
- SkBlendMode, const SkPaint&) override;
+ void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
SkBlendMode, const SkRect*, const SkPaint*) override;
void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
diff --git a/libs/hwui/RenderNode.h b/libs/hwui/RenderNode.h
index c0ec2174bb35..6d5e62e955bb 100644
--- a/libs/hwui/RenderNode.h
+++ b/libs/hwui/RenderNode.h
@@ -94,17 +94,17 @@ public:
DISPLAY_LIST = 1 << 14,
};
- ANDROID_API RenderNode();
- ANDROID_API virtual ~RenderNode();
+ RenderNode();
+ virtual ~RenderNode();
// See flags defined in DisplayList.java
enum ReplayFlag { kReplayFlag_ClipChildren = 0x1 };
- ANDROID_API void setStagingDisplayList(DisplayList* newData);
+ void setStagingDisplayList(DisplayList* newData);
- ANDROID_API void output();
- ANDROID_API int getUsageSize();
- ANDROID_API int getAllocatedSize();
+ void output();
+ int getUsageSize();
+ int getAllocatedSize();
bool isRenderable() const { return mDisplayList && !mDisplayList->isEmpty(); }
@@ -149,12 +149,12 @@ public:
int getHeight() const { return properties().getHeight(); }
- ANDROID_API virtual void prepareTree(TreeInfo& info);
+ virtual void prepareTree(TreeInfo& info);
void destroyHardwareResources(TreeInfo* info = nullptr);
void destroyLayers();
// UI thread only!
- ANDROID_API void addAnimator(const sp<BaseRenderNodeAnimator>& animator);
+ void addAnimator(const sp<BaseRenderNodeAnimator>& animator);
void removeAnimator(const sp<BaseRenderNodeAnimator>& animator);
// This can only happen during pushStaging()
@@ -179,7 +179,7 @@ public:
// the frameNumber to appropriately batch/synchronize these transactions.
// There is no other filtering/batching to ensure that only the "final"
// state called once per frame.
- class ANDROID_API PositionListener : public VirtualLightRefBase {
+ class PositionListener : public VirtualLightRefBase {
public:
virtual ~PositionListener() {}
// Called when the RenderNode's position changes
@@ -190,14 +190,14 @@ public:
virtual void onPositionLost(RenderNode& node, const TreeInfo* info) = 0;
};
- ANDROID_API void setPositionListener(PositionListener* listener) {
+ void setPositionListener(PositionListener* listener) {
mStagingPositionListener = listener;
mPositionListenerDirty = true;
}
// This is only modified in MODE_FULL, so it can be safely accessed
// on the UI thread.
- ANDROID_API bool hasParents() { return mParentCount; }
+ bool hasParents() { return mParentCount; }
void onRemovedFromTree(TreeInfo* info);
diff --git a/libs/hwui/RenderProperties.h b/libs/hwui/RenderProperties.h
index 24f6035b6708..ef4cd1f1eb62 100644
--- a/libs/hwui/RenderProperties.h
+++ b/libs/hwui/RenderProperties.h
@@ -69,7 +69,7 @@ enum ClippingFlags {
CLIP_TO_CLIP_BOUNDS = 0x1 << 1,
};
-class ANDROID_API LayerProperties {
+class LayerProperties {
public:
bool setType(LayerType type) {
if (RP_SET(mType, type)) {
@@ -123,7 +123,7 @@ private:
/*
* Data structure that holds the properties for a RenderNode
*/
-class ANDROID_API RenderProperties {
+class RenderProperties {
public:
RenderProperties();
virtual ~RenderProperties();
diff --git a/libs/hwui/RootRenderNode.h b/libs/hwui/RootRenderNode.h
index 12de4ecac94b..1d3f5a8a51e0 100644
--- a/libs/hwui/RootRenderNode.h
+++ b/libs/hwui/RootRenderNode.h
@@ -27,16 +27,16 @@
namespace android::uirenderer {
-class ANDROID_API RootRenderNode : public RenderNode {
+class RootRenderNode : public RenderNode {
public:
- ANDROID_API explicit RootRenderNode(std::unique_ptr<ErrorHandler> errorHandler)
+ explicit RootRenderNode(std::unique_ptr<ErrorHandler> errorHandler)
: RenderNode(), mErrorHandler(std::move(errorHandler)) {}
- ANDROID_API virtual ~RootRenderNode() {}
+ virtual ~RootRenderNode() {}
virtual void prepareTree(TreeInfo& info) override;
- ANDROID_API void attachAnimatingNode(RenderNode* animatingNode);
+ void attachAnimatingNode(RenderNode* animatingNode);
void attachPendingVectorDrawableAnimators();
@@ -53,9 +53,9 @@ public:
void pushStagingVectorDrawableAnimators(AnimationContext* context);
- ANDROID_API void destroy();
+ void destroy();
- ANDROID_API void addVectorDrawableAnimator(PropertyValuesAnimatorSet* anim);
+ void addVectorDrawableAnimator(PropertyValuesAnimatorSet* anim);
private:
const std::unique_ptr<ErrorHandler> mErrorHandler;
@@ -75,12 +75,11 @@ private:
};
#ifdef __ANDROID__ // Layoutlib does not support Animations
-class ANDROID_API ContextFactoryImpl : public IContextFactory {
+class ContextFactoryImpl : public IContextFactory {
public:
- ANDROID_API explicit ContextFactoryImpl(RootRenderNode* rootNode) : mRootNode(rootNode) {}
+ explicit ContextFactoryImpl(RootRenderNode* rootNode) : mRootNode(rootNode) {}
- ANDROID_API virtual AnimationContext* createAnimationContext(
- renderthread::TimeLord& clock) override;
+ virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) override;
private:
RootRenderNode* mRootNode;
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp
index 941437998838..cfba5d4f6aa2 100644
--- a/libs/hwui/SkiaCanvas.cpp
+++ b/libs/hwui/SkiaCanvas.cpp
@@ -40,6 +40,9 @@
#include <SkShader.h>
#include <SkTemplates.h>
#include <SkTextBlob.h>
+#include <SkVertices.h>
+
+#include <shader/BitmapShader.h>
#include <memory>
#include <optional>
@@ -48,6 +51,7 @@
namespace android {
using uirenderer::PaintUtils;
+using uirenderer::BitmapShader;
Canvas* Canvas::create_canvas(const SkBitmap& bitmap) {
return new SkiaCanvas(bitmap);
@@ -680,7 +684,9 @@ void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight,
if (paint) {
pnt = *paint;
}
- pnt.setShader(bitmap.makeImage()->makeShader());
+
+ pnt.setShader(sk_ref_sp(new BitmapShader(
+ bitmap.makeImage(), SkTileMode::kClamp, SkTileMode::kClamp, nullptr)));
auto v = builder.detach();
apply_looper(&pnt, [&](const SkPaint& p) {
mCanvas->drawVertices(v, SkBlendMode::kModulate, p);
@@ -842,9 +848,4 @@ void SkiaCanvas::drawRenderNode(uirenderer::RenderNode* renderNode) {
LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw RenderNodes");
}
-void SkiaCanvas::callDrawGLFunction(Functor* functor,
- uirenderer::GlFunctorLifecycleListener* listener) {
- LOG_ALWAYS_FATAL("SkiaCanvas can't directly draw GL Content");
-}
-
} // namespace android
diff --git a/libs/hwui/SkiaCanvas.h b/libs/hwui/SkiaCanvas.h
index 1eb089d8764c..1df2b2671659 100644
--- a/libs/hwui/SkiaCanvas.h
+++ b/libs/hwui/SkiaCanvas.h
@@ -57,8 +57,8 @@ public:
LOG_ALWAYS_FATAL("SkiaCanvas does not produce a DisplayList");
return nullptr;
}
- virtual void insertReorderBarrier(bool enableReorder) override {
- LOG_ALWAYS_FATAL("SkiaCanvas does not support reordering barriers");
+ virtual void enableZ(bool enableZ) override {
+ LOG_ALWAYS_FATAL("SkiaCanvas does not support enableZ");
}
virtual void setBitmap(const SkBitmap& bitmap) override;
@@ -152,8 +152,6 @@ public:
virtual void drawLayer(uirenderer::DeferredLayerUpdater* layerHandle) override;
virtual void drawRenderNode(uirenderer::RenderNode* renderNode) override;
- virtual void callDrawGLFunction(Functor* functor,
- uirenderer::GlFunctorLifecycleListener* listener) override;
virtual void drawPicture(const SkPicture& picture) override;
protected:
diff --git a/libs/hwui/VectorDrawable.cpp b/libs/hwui/VectorDrawable.cpp
index cd908354aea5..0f566e4b494a 100644
--- a/libs/hwui/VectorDrawable.cpp
+++ b/libs/hwui/VectorDrawable.cpp
@@ -23,7 +23,6 @@
#include "PathParser.h"
#include "SkColorFilter.h"
#include "SkImageInfo.h"
-#include "SkShader.h"
#include "hwui/Paint.h"
#ifdef __ANDROID__
@@ -159,10 +158,10 @@ void FullPath::draw(SkCanvas* outCanvas, bool useStagingData) {
// Draw path's fill, if fill color or gradient is valid
bool needsFill = false;
- SkPaint paint;
+ Paint paint;
if (properties.getFillGradient() != nullptr) {
paint.setColor(applyAlpha(SK_ColorBLACK, properties.getFillAlpha()));
- paint.setShader(sk_sp<SkShader>(SkSafeRef(properties.getFillGradient())));
+ paint.setShader(sk_sp<Shader>(SkSafeRef(properties.getFillGradient())));
needsFill = true;
} else if (properties.getFillColor() != SK_ColorTRANSPARENT) {
paint.setColor(applyAlpha(properties.getFillColor(), properties.getFillAlpha()));
@@ -179,7 +178,7 @@ void FullPath::draw(SkCanvas* outCanvas, bool useStagingData) {
bool needsStroke = false;
if (properties.getStrokeGradient() != nullptr) {
paint.setColor(applyAlpha(SK_ColorBLACK, properties.getStrokeAlpha()));
- paint.setShader(sk_sp<SkShader>(SkSafeRef(properties.getStrokeGradient())));
+ paint.setShader(sk_sp<Shader>(SkSafeRef(properties.getStrokeGradient())));
needsStroke = true;
} else if (properties.getStrokeColor() != SK_ColorTRANSPARENT) {
paint.setColor(applyAlpha(properties.getStrokeColor(), properties.getStrokeAlpha()));
diff --git a/libs/hwui/VectorDrawable.h b/libs/hwui/VectorDrawable.h
index e1b6f2adde74..d4086f1aa622 100644
--- a/libs/hwui/VectorDrawable.h
+++ b/libs/hwui/VectorDrawable.h
@@ -31,8 +31,8 @@
#include <SkPath.h>
#include <SkPathMeasure.h>
#include <SkRect.h>
-#include <SkShader.h>
#include <SkSurface.h>
+#include <shader/Shader.h>
#include <cutils/compiler.h>
#include <stddef.h>
@@ -97,7 +97,7 @@ private:
bool* mStagingDirty;
};
-class ANDROID_API Node {
+class Node {
public:
class Properties {
public:
@@ -127,9 +127,9 @@ protected:
PropertyChangedListener* mPropertyChangedListener = nullptr;
};
-class ANDROID_API Path : public Node {
+class Path : public Node {
public:
- struct ANDROID_API Data {
+ struct Data {
std::vector<char> verbs;
std::vector<size_t> verbSizes;
std::vector<float> points;
@@ -200,7 +200,7 @@ private:
bool mStagingPropertiesDirty = true;
};
-class ANDROID_API FullPath : public Path {
+class FullPath : public Path {
public:
class FullPathProperties : public Properties {
public:
@@ -227,20 +227,20 @@ public:
strokeGradient = prop.strokeGradient;
onPropertyChanged();
}
- void setFillGradient(SkShader* gradient) {
+ void setFillGradient(Shader* gradient) {
if (fillGradient.get() != gradient) {
fillGradient = sk_ref_sp(gradient);
onPropertyChanged();
}
}
- void setStrokeGradient(SkShader* gradient) {
+ void setStrokeGradient(Shader* gradient) {
if (strokeGradient.get() != gradient) {
strokeGradient = sk_ref_sp(gradient);
onPropertyChanged();
}
}
- SkShader* getFillGradient() const { return fillGradient.get(); }
- SkShader* getStrokeGradient() const { return strokeGradient.get(); }
+ Shader* getFillGradient() const { return fillGradient.get(); }
+ Shader* getStrokeGradient() const { return strokeGradient.get(); }
float getStrokeWidth() const { return mPrimitiveFields.strokeWidth; }
void setStrokeWidth(float strokeWidth) {
VD_SET_PRIMITIVE_FIELD_AND_NOTIFY(strokeWidth, strokeWidth);
@@ -320,8 +320,8 @@ public:
count,
};
PrimitiveFields mPrimitiveFields;
- sk_sp<SkShader> fillGradient;
- sk_sp<SkShader> strokeGradient;
+ sk_sp<Shader> fillGradient;
+ sk_sp<Shader> strokeGradient;
};
// Called from UI thread
@@ -369,7 +369,7 @@ private:
bool mAntiAlias = true;
};
-class ANDROID_API ClipPath : public Path {
+class ClipPath : public Path {
public:
ClipPath(const ClipPath& path) : Path(path) {}
ClipPath(const char* path, size_t strLength) : Path(path, strLength) {}
@@ -378,7 +378,7 @@ public:
virtual void setAntiAlias(bool aa) {}
};
-class ANDROID_API Group : public Node {
+class Group : public Node {
public:
class GroupProperties : public Properties {
public:
@@ -498,7 +498,7 @@ private:
std::vector<std::unique_ptr<Node> > mChildren;
};
-class ANDROID_API Tree : public VirtualLightRefBase {
+class Tree : public VirtualLightRefBase {
public:
explicit Tree(Group* rootNode) : mRootNode(rootNode) {
mRootNode->setPropertyChangedListener(&mPropertyChangedListener);
diff --git a/libs/hwui/apex/java/android/graphics/ColorMatrix.java b/libs/hwui/apex/java/android/graphics/ColorMatrix.java
new file mode 100644
index 000000000000..6299b2c47ea1
--- /dev/null
+++ b/libs/hwui/apex/java/android/graphics/ColorMatrix.java
@@ -0,0 +1,288 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.graphics;
+
+import java.util.Arrays;
+
+/**
+ * 4x5 matrix for transforming the color and alpha components of a Bitmap.
+ * The matrix can be passed as single array, and is treated as follows:
+ *
+ * <pre>
+ * [ a, b, c, d, e,
+ * f, g, h, i, j,
+ * k, l, m, n, o,
+ * p, q, r, s, t ]</pre>
+ *
+ * <p>
+ * When applied to a color <code>[R, G, B, A]</code>, the resulting color
+ * is computed as:
+ * </p>
+ *
+ * <pre>
+ * R&rsquo; = a*R + b*G + c*B + d*A + e;
+ * G&rsquo; = f*R + g*G + h*B + i*A + j;
+ * B&rsquo; = k*R + l*G + m*B + n*A + o;
+ * A&rsquo; = p*R + q*G + r*B + s*A + t;</pre>
+ *
+ * <p>
+ * That resulting color <code>[R&rsquo;, G&rsquo;, B&rsquo;, A&rsquo;]</code>
+ * then has each channel clamped to the <code>0</code> to <code>255</code>
+ * range.
+ * </p>
+ *
+ * <p>
+ * The sample ColorMatrix below inverts incoming colors by scaling each
+ * channel by <code>-1</code>, and then shifting the result up by
+ * <code>255</code> to remain in the standard color space.
+ * </p>
+ *
+ * <pre>
+ * [ -1, 0, 0, 0, 255,
+ * 0, -1, 0, 0, 255,
+ * 0, 0, -1, 0, 255,
+ * 0, 0, 0, 1, 0 ]</pre>
+ */
+@SuppressWarnings({ "MismatchedReadAndWriteOfArray", "PointlessArithmeticExpression" })
+public class ColorMatrix {
+ private final float[] mArray = new float[20];
+
+ /**
+ * Create a new colormatrix initialized to identity (as if reset() had
+ * been called).
+ */
+ public ColorMatrix() {
+ reset();
+ }
+
+ /**
+ * Create a new colormatrix initialized with the specified array of values.
+ */
+ public ColorMatrix(float[] src) {
+ System.arraycopy(src, 0, mArray, 0, 20);
+ }
+
+ /**
+ * Create a new colormatrix initialized with the specified colormatrix.
+ */
+ public ColorMatrix(ColorMatrix src) {
+ System.arraycopy(src.mArray, 0, mArray, 0, 20);
+ }
+
+ /**
+ * Return the array of floats representing this colormatrix.
+ */
+ public final float[] getArray() { return mArray; }
+
+ /**
+ * Set this colormatrix to identity:
+ * <pre>
+ * [ 1 0 0 0 0 - red vector
+ * 0 1 0 0 0 - green vector
+ * 0 0 1 0 0 - blue vector
+ * 0 0 0 1 0 ] - alpha vector
+ * </pre>
+ */
+ public void reset() {
+ final float[] a = mArray;
+ Arrays.fill(a, 0);
+ a[0] = a[6] = a[12] = a[18] = 1;
+ }
+
+ /**
+ * Assign the src colormatrix into this matrix, copying all of its values.
+ */
+ public void set(ColorMatrix src) {
+ System.arraycopy(src.mArray, 0, mArray, 0, 20);
+ }
+
+ /**
+ * Assign the array of floats into this matrix, copying all of its values.
+ */
+ public void set(float[] src) {
+ System.arraycopy(src, 0, mArray, 0, 20);
+ }
+
+ /**
+ * Set this colormatrix to scale by the specified values.
+ */
+ public void setScale(float rScale, float gScale, float bScale,
+ float aScale) {
+ final float[] a = mArray;
+
+ for (int i = 19; i > 0; --i) {
+ a[i] = 0;
+ }
+ a[0] = rScale;
+ a[6] = gScale;
+ a[12] = bScale;
+ a[18] = aScale;
+ }
+
+ /**
+ * Set the rotation on a color axis by the specified values.
+ * <p>
+ * <code>axis=0</code> correspond to a rotation around the RED color
+ * <code>axis=1</code> correspond to a rotation around the GREEN color
+ * <code>axis=2</code> correspond to a rotation around the BLUE color
+ * </p>
+ */
+ public void setRotate(int axis, float degrees) {
+ reset();
+ double radians = degrees * Math.PI / 180d;
+ float cosine = (float) Math.cos(radians);
+ float sine = (float) Math.sin(radians);
+ switch (axis) {
+ // Rotation around the red color
+ case 0:
+ mArray[6] = mArray[12] = cosine;
+ mArray[7] = sine;
+ mArray[11] = -sine;
+ break;
+ // Rotation around the green color
+ case 1:
+ mArray[0] = mArray[12] = cosine;
+ mArray[2] = -sine;
+ mArray[10] = sine;
+ break;
+ // Rotation around the blue color
+ case 2:
+ mArray[0] = mArray[6] = cosine;
+ mArray[1] = sine;
+ mArray[5] = -sine;
+ break;
+ default:
+ throw new RuntimeException();
+ }
+ }
+
+ /**
+ * Set this colormatrix to the concatenation of the two specified
+ * colormatrices, such that the resulting colormatrix has the same effect
+ * as applying matB and then applying matA.
+ * <p>
+ * It is legal for either matA or matB to be the same colormatrix as this.
+ * </p>
+ */
+ public void setConcat(ColorMatrix matA, ColorMatrix matB) {
+ float[] tmp;
+ if (matA == this || matB == this) {
+ tmp = new float[20];
+ } else {
+ tmp = mArray;
+ }
+
+ final float[] a = matA.mArray;
+ final float[] b = matB.mArray;
+ int index = 0;
+ for (int j = 0; j < 20; j += 5) {
+ for (int i = 0; i < 4; i++) {
+ tmp[index++] = a[j + 0] * b[i + 0] + a[j + 1] * b[i + 5] +
+ a[j + 2] * b[i + 10] + a[j + 3] * b[i + 15];
+ }
+ tmp[index++] = a[j + 0] * b[4] + a[j + 1] * b[9] +
+ a[j + 2] * b[14] + a[j + 3] * b[19] +
+ a[j + 4];
+ }
+
+ if (tmp != mArray) {
+ System.arraycopy(tmp, 0, mArray, 0, 20);
+ }
+ }
+
+ /**
+ * Concat this colormatrix with the specified prematrix.
+ * <p>
+ * This is logically the same as calling setConcat(this, prematrix);
+ * </p>
+ */
+ public void preConcat(ColorMatrix prematrix) {
+ setConcat(this, prematrix);
+ }
+
+ /**
+ * Concat this colormatrix with the specified postmatrix.
+ * <p>
+ * This is logically the same as calling setConcat(postmatrix, this);
+ * </p>
+ */
+ public void postConcat(ColorMatrix postmatrix) {
+ setConcat(postmatrix, this);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Set the matrix to affect the saturation of colors.
+ *
+ * @param sat A value of 0 maps the color to gray-scale. 1 is identity.
+ */
+ public void setSaturation(float sat) {
+ reset();
+ float[] m = mArray;
+
+ final float invSat = 1 - sat;
+ final float R = 0.213f * invSat;
+ final float G = 0.715f * invSat;
+ final float B = 0.072f * invSat;
+
+ m[0] = R + sat; m[1] = G; m[2] = B;
+ m[5] = R; m[6] = G + sat; m[7] = B;
+ m[10] = R; m[11] = G; m[12] = B + sat;
+ }
+
+ /**
+ * Set the matrix to convert RGB to YUV
+ */
+ public void setRGB2YUV() {
+ reset();
+ float[] m = mArray;
+ // these coefficients match those in libjpeg
+ m[0] = 0.299f; m[1] = 0.587f; m[2] = 0.114f;
+ m[5] = -0.16874f; m[6] = -0.33126f; m[7] = 0.5f;
+ m[10] = 0.5f; m[11] = -0.41869f; m[12] = -0.08131f;
+ }
+
+ /**
+ * Set the matrix to convert from YUV to RGB
+ */
+ public void setYUV2RGB() {
+ reset();
+ float[] m = mArray;
+ // these coefficients match those in libjpeg
+ m[2] = 1.402f;
+ m[5] = 1; m[6] = -0.34414f; m[7] = -0.71414f;
+ m[10] = 1; m[11] = 1.772f; m[12] = 0;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ // if (obj == this) return true; -- NaN value would mean matrix != itself
+ if (!(obj instanceof ColorMatrix)) {
+ return false;
+ }
+
+ // we don't use Arrays.equals(), since that considers NaN == NaN
+ final float[] other = ((ColorMatrix) obj).mArray;
+ for (int i = 0; i < 20; i++) {
+ if (other[i] != mArray[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/libs/hwui/apex/jni_runtime.cpp b/libs/hwui/apex/jni_runtime.cpp
index a114e2f42157..12e2e8135278 100644
--- a/libs/hwui/apex/jni_runtime.cpp
+++ b/libs/hwui/apex/jni_runtime.cpp
@@ -16,14 +16,14 @@
#include "android/graphics/jni_runtime.h"
-#include <android/log.h>
-#include <nativehelper/JNIHelp.h>
-#include <sys/cdefs.h>
-
#include <EGL/egl.h>
#include <GraphicsJNI.h>
#include <Properties.h>
#include <SkGraphics.h>
+#include <android/log.h>
+#include <nativehelper/JNIHelp.h>
+#include <sys/cdefs.h>
+#include <vulkan/vulkan.h>
#undef LOG_TAG
#define LOG_TAG "AndroidGraphicsJNI"
@@ -61,6 +61,7 @@ extern int register_android_graphics_Path(JNIEnv* env);
extern int register_android_graphics_PathMeasure(JNIEnv* env);
extern int register_android_graphics_Picture(JNIEnv*);
extern int register_android_graphics_Region(JNIEnv* env);
+extern int register_android_graphics_TextureLayer(JNIEnv* env);
extern int register_android_graphics_animation_NativeInterpolatorFactory(JNIEnv* env);
extern int register_android_graphics_animation_RenderNodeAnimator(JNIEnv* env);
extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
@@ -76,7 +77,6 @@ extern int register_android_graphics_text_LineBreaker(JNIEnv *env);
extern int register_android_util_PathParser(JNIEnv* env);
extern int register_android_view_DisplayListCanvas(JNIEnv* env);
extern int register_android_view_RenderNode(JNIEnv* env);
-extern int register_android_view_TextureLayer(JNIEnv* env);
extern int register_android_view_ThreadedRenderer(JNIEnv* env);
#ifdef NDEBUG
@@ -123,6 +123,7 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_graphics_Picture),
REG_JNI(register_android_graphics_Region),
REG_JNI(register_android_graphics_Shader),
+ REG_JNI(register_android_graphics_TextureLayer),
REG_JNI(register_android_graphics_Typeface),
REG_JNI(register_android_graphics_YuvImage),
REG_JNI(register_android_graphics_animation_NativeInterpolatorFactory),
@@ -140,7 +141,6 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_util_PathParser),
REG_JNI(register_android_view_RenderNode),
REG_JNI(register_android_view_DisplayListCanvas),
- REG_JNI(register_android_view_TextureLayer),
REG_JNI(register_android_view_ThreadedRenderer),
};
@@ -172,6 +172,11 @@ using android::uirenderer::RenderPipelineType;
void zygote_preload_graphics() {
if (Properties::peekRenderPipelineType() == RenderPipelineType::SkiaGL) {
+ // Preload GL driver if HWUI renders with GL backend.
eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ } else {
+ // Preload Vulkan driver if HWUI renders with Vulkan backend.
+ uint32_t apiVersion;
+ vkEnumerateInstanceVersion(&apiVersion);
}
-} \ No newline at end of file
+}
diff --git a/libs/hwui/api/current.txt b/libs/hwui/api/current.txt
new file mode 100644
index 000000000000..c396a2032eed
--- /dev/null
+++ b/libs/hwui/api/current.txt
@@ -0,0 +1,23 @@
+// Signature format: 2.0
+package android.graphics {
+
+ public class ColorMatrix {
+ ctor public ColorMatrix();
+ ctor public ColorMatrix(float[]);
+ ctor public ColorMatrix(android.graphics.ColorMatrix);
+ method public final float[] getArray();
+ method public void postConcat(android.graphics.ColorMatrix);
+ method public void preConcat(android.graphics.ColorMatrix);
+ method public void reset();
+ method public void set(android.graphics.ColorMatrix);
+ method public void set(float[]);
+ method public void setConcat(android.graphics.ColorMatrix, android.graphics.ColorMatrix);
+ method public void setRGB2YUV();
+ method public void setRotate(int, float);
+ method public void setSaturation(float);
+ method public void setScale(float, float, float, float);
+ method public void setYUV2RGB();
+ }
+
+}
+
diff --git a/libs/hwui/api/module-lib-current.txt b/libs/hwui/api/module-lib-current.txt
new file mode 100644
index 000000000000..d802177e249b
--- /dev/null
+++ b/libs/hwui/api/module-lib-current.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/libs/hwui/api/module-lib-removed.txt b/libs/hwui/api/module-lib-removed.txt
new file mode 100644
index 000000000000..d802177e249b
--- /dev/null
+++ b/libs/hwui/api/module-lib-removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/libs/hwui/api/removed.txt b/libs/hwui/api/removed.txt
new file mode 100644
index 000000000000..d802177e249b
--- /dev/null
+++ b/libs/hwui/api/removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/libs/hwui/api/system-current.txt b/libs/hwui/api/system-current.txt
new file mode 100644
index 000000000000..d802177e249b
--- /dev/null
+++ b/libs/hwui/api/system-current.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/libs/hwui/api/system-removed.txt b/libs/hwui/api/system-removed.txt
new file mode 100644
index 000000000000..d802177e249b
--- /dev/null
+++ b/libs/hwui/api/system-removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/libs/hwui/hwui/AnimatedImageDrawable.h b/libs/hwui/hwui/AnimatedImageDrawable.h
index f0aa35acf71b..f81a5a40b44e 100644
--- a/libs/hwui/hwui/AnimatedImageDrawable.h
+++ b/libs/hwui/hwui/AnimatedImageDrawable.h
@@ -44,7 +44,7 @@ public:
* This class can be drawn into Canvas.h and maintains the state needed to drive
* the animation from the RenderThread.
*/
-class ANDROID_API AnimatedImageDrawable : public SkDrawable {
+class AnimatedImageDrawable : public SkDrawable {
public:
// bytesUsed includes the approximate sizes of the SkAnimatedImage and the SkPictures in the
// Snapshots.
diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp
index 60ef4371d38d..1a89cfd5d0ad 100644
--- a/libs/hwui/hwui/Bitmap.cpp
+++ b/libs/hwui/hwui/Bitmap.cpp
@@ -33,7 +33,6 @@
#ifndef _WIN32
#include <binder/IServiceManager.h>
#endif
-#include <ui/PixelFormat.h>
#include <SkCanvas.h>
#include <SkImagePriv.h>
@@ -132,15 +131,8 @@ sk_sp<Bitmap> Bitmap::allocateHeapBitmap(size_t size, const SkImageInfo& info, s
return sk_sp<Bitmap>(new Bitmap(addr, size, info, rowBytes));
}
-void FreePixelRef(void* addr, void* context) {
- auto pixelRef = (SkPixelRef*)context;
- pixelRef->unref();
-}
-
sk_sp<Bitmap> Bitmap::createFrom(const SkImageInfo& info, SkPixelRef& pixelRef) {
- pixelRef.ref();
- return sk_sp<Bitmap>(new Bitmap((void*)pixelRef.pixels(), (void*)&pixelRef, FreePixelRef, info,
- pixelRef.rowBytes()));
+ return sk_sp<Bitmap>(new Bitmap(pixelRef, info));
}
@@ -230,14 +222,12 @@ Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBy
mPixelStorage.heap.size = size;
}
-Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc, const SkImageInfo& info,
- size_t rowBytes)
- : SkPixelRef(info.width(), info.height(), address, rowBytes)
+Bitmap::Bitmap(SkPixelRef& pixelRef, const SkImageInfo& info)
+ : SkPixelRef(info.width(), info.height(), pixelRef.pixels(), pixelRef.rowBytes())
, mInfo(validateAlpha(info))
- , mPixelStorageType(PixelStorageType::External) {
- mPixelStorage.external.address = address;
- mPixelStorage.external.context = context;
- mPixelStorage.external.freeFunc = freeFunc;
+ , mPixelStorageType(PixelStorageType::WrappedPixelRef) {
+ pixelRef.ref();
+ mPixelStorage.wrapped.pixelRef = &pixelRef;
}
Bitmap::Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info, size_t rowBytes)
@@ -266,9 +256,8 @@ Bitmap::Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes
Bitmap::~Bitmap() {
switch (mPixelStorageType) {
- case PixelStorageType::External:
- mPixelStorage.external.freeFunc(mPixelStorage.external.address,
- mPixelStorage.external.context);
+ case PixelStorageType::WrappedPixelRef:
+ mPixelStorage.wrapped.pixelRef->unref();
break;
case PixelStorageType::Ashmem:
#ifndef _WIN32 // ashmem not implemented on Windows
@@ -300,19 +289,6 @@ void Bitmap::setHasHardwareMipMap(bool hasMipMap) {
mHasHardwareMipMap = hasMipMap;
}
-void* Bitmap::getStorage() const {
- switch (mPixelStorageType) {
- case PixelStorageType::External:
- return mPixelStorage.external.address;
- case PixelStorageType::Ashmem:
- return mPixelStorage.ashmem.address;
- case PixelStorageType::Heap:
- return mPixelStorage.heap.address;
- case PixelStorageType::Hardware:
- return nullptr;
- }
-}
-
int Bitmap::getAshmemFd() const {
switch (mPixelStorageType) {
case PixelStorageType::Ashmem:
diff --git a/libs/hwui/hwui/Bitmap.h b/libs/hwui/hwui/Bitmap.h
index b8b59947a57b..6ece7ef9f329 100644
--- a/libs/hwui/hwui/Bitmap.h
+++ b/libs/hwui/hwui/Bitmap.h
@@ -32,7 +32,7 @@ class SkWStream;
namespace android {
enum class PixelStorageType {
- External,
+ WrappedPixelRef,
Heap,
Ashmem,
Hardware,
@@ -56,7 +56,7 @@ class PixelStorage;
typedef void (*FreeFunc)(void* addr, void* context);
-class ANDROID_API Bitmap : public SkPixelRef {
+class Bitmap : public SkPixelRef {
public:
/* The allocate factories not only construct the Bitmap object but also allocate the
* backing store whose type is determined by the specific method that is called.
@@ -71,6 +71,7 @@ public:
static sk_sp<Bitmap> allocateHardwareBitmap(const SkBitmap& bitmap);
static sk_sp<Bitmap> allocateHeapBitmap(SkBitmap* bitmap);
static sk_sp<Bitmap> allocateHeapBitmap(const SkImageInfo& info);
+ static sk_sp<Bitmap> allocateHeapBitmap(size_t size, const SkImageInfo& i, size_t rowBytes);
/* The createFrom factories construct a new Bitmap object by wrapping the already allocated
* memory that is provided as an input param.
@@ -160,11 +161,9 @@ public:
int32_t quality, SkWStream* stream);
private:
static sk_sp<Bitmap> allocateAshmemBitmap(size_t size, const SkImageInfo& i, size_t rowBytes);
- static sk_sp<Bitmap> allocateHeapBitmap(size_t size, const SkImageInfo& i, size_t rowBytes);
Bitmap(void* address, size_t allocSize, const SkImageInfo& info, size_t rowBytes);
- Bitmap(void* address, void* context, FreeFunc freeFunc, const SkImageInfo& info,
- size_t rowBytes);
+ Bitmap(SkPixelRef& pixelRef, const SkImageInfo& info);
Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info, size_t rowBytes);
#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes,
@@ -178,7 +177,6 @@ private:
#endif
virtual ~Bitmap();
- void* getStorage() const;
SkImageInfo mInfo;
@@ -191,10 +189,8 @@ private:
union {
struct {
- void* address;
- void* context;
- FreeFunc freeFunc;
- } external;
+ SkPixelRef* pixelRef;
+ } wrapped;
struct {
void* address;
int fd;
diff --git a/libs/hwui/hwui/Canvas.cpp b/libs/hwui/hwui/Canvas.cpp
index c138a32eacc2..2a377bbb83f2 100644
--- a/libs/hwui/hwui/Canvas.cpp
+++ b/libs/hwui/hwui/Canvas.cpp
@@ -73,7 +73,7 @@ void Canvas::drawTextDecorations(float x, float y, float length, const Paint& pa
static void simplifyPaint(int color, Paint* paint) {
paint->setColor(color);
- paint->setShader(nullptr);
+ paint->setShader((sk_sp<uirenderer::Shader>)nullptr);
paint->setColorFilter(nullptr);
paint->setLooper(nullptr);
paint->setStrokeWidth(4 + 0.04 * paint->getSkFont().getSize());
diff --git a/libs/hwui/hwui/Canvas.h b/libs/hwui/hwui/Canvas.h
index 27dfed305a94..333567b0cf91 100644
--- a/libs/hwui/hwui/Canvas.h
+++ b/libs/hwui/hwui/Canvas.h
@@ -20,7 +20,6 @@
#include <utils/Functor.h>
#include <androidfw/ResourceTypes.h>
-#include "GlFunctorLifecycleListener.h"
#include "Properties.h"
#include "utils/Macros.h"
@@ -144,7 +143,7 @@ public:
virtual void resetRecording(int width, int height,
uirenderer::RenderNode* renderNode = nullptr) = 0;
virtual uirenderer::DisplayList* finishRecording() = 0;
- virtual void insertReorderBarrier(bool enableReorder) = 0;
+ virtual void enableZ(bool enableZ) = 0;
bool isHighContrastText() const { return uirenderer::Properties::enableHighContrastText; }
@@ -162,8 +161,7 @@ public:
virtual void drawLayer(uirenderer::DeferredLayerUpdater* layerHandle) = 0;
virtual void drawRenderNode(uirenderer::RenderNode* renderNode) = 0;
- virtual void callDrawGLFunction(Functor* functor,
- uirenderer::GlFunctorLifecycleListener* listener) = 0;
+
virtual void drawWebViewFunctor(int /*functor*/) {
LOG_ALWAYS_FATAL("Not supported");
}
diff --git a/libs/hwui/hwui/MinikinSkia.cpp b/libs/hwui/hwui/MinikinSkia.cpp
index 6a12a203b9f8..a6137b073d5a 100644
--- a/libs/hwui/hwui/MinikinSkia.cpp
+++ b/libs/hwui/hwui/MinikinSkia.cpp
@@ -125,22 +125,22 @@ const std::vector<minikin::FontVariation>& MinikinFontSkia::GetAxes() const {
std::shared_ptr<minikin::MinikinFont> MinikinFontSkia::createFontWithVariation(
const std::vector<minikin::FontVariation>& variations) const {
- SkFontArguments params;
+ SkFontArguments args;
int ttcIndex;
std::unique_ptr<SkStreamAsset> stream(mTypeface->openStream(&ttcIndex));
LOG_ALWAYS_FATAL_IF(stream == nullptr, "openStream failed");
- params.setCollectionIndex(ttcIndex);
- std::vector<SkFontArguments::Axis> skAxes;
- skAxes.resize(variations.size());
+ args.setCollectionIndex(ttcIndex);
+ std::vector<SkFontArguments::VariationPosition::Coordinate> skVariation;
+ skVariation.resize(variations.size());
for (size_t i = 0; i < variations.size(); i++) {
- skAxes[i].fTag = variations[i].axisTag;
- skAxes[i].fStyleValue = SkFloatToScalar(variations[i].value);
+ skVariation[i].axis = variations[i].axisTag;
+ skVariation[i].value = SkFloatToScalar(variations[i].value);
}
- params.setAxes(skAxes.data(), skAxes.size());
+ args.setVariationDesignPosition({skVariation.data(), static_cast<int>(skVariation.size())});
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
- sk_sp<SkTypeface> face(fm->makeFromStream(std::move(stream), params));
+ sk_sp<SkTypeface> face(fm->makeFromStream(std::move(stream), args));
return std::make_shared<MinikinFontSkia>(std::move(face), mFontData, mFontSize, mFilePath,
ttcIndex, variations);
diff --git a/libs/hwui/hwui/MinikinUtils.h b/libs/hwui/hwui/MinikinUtils.h
index cbf409504675..0eacde9a467e 100644
--- a/libs/hwui/hwui/MinikinUtils.h
+++ b/libs/hwui/hwui/MinikinUtils.h
@@ -39,30 +39,30 @@ namespace android {
class MinikinUtils {
public:
- ANDROID_API static minikin::MinikinPaint prepareMinikinPaint(const Paint* paint,
+ static minikin::MinikinPaint prepareMinikinPaint(const Paint* paint,
const Typeface* typeface);
- ANDROID_API static minikin::Layout doLayout(const Paint* paint, minikin::Bidi bidiFlags,
+ static minikin::Layout doLayout(const Paint* paint, minikin::Bidi bidiFlags,
const Typeface* typeface, const uint16_t* buf,
size_t bufSize, size_t start, size_t count,
size_t contextStart, size_t contextCount,
minikin::MeasuredText* mt);
- ANDROID_API static float measureText(const Paint* paint, minikin::Bidi bidiFlags,
+ static float measureText(const Paint* paint, minikin::Bidi bidiFlags,
const Typeface* typeface, const uint16_t* buf,
size_t start, size_t count, size_t bufSize,
float* advances);
- ANDROID_API static bool hasVariationSelector(const Typeface* typeface, uint32_t codepoint,
+ static bool hasVariationSelector(const Typeface* typeface, uint32_t codepoint,
uint32_t vs);
- ANDROID_API static float xOffsetForTextAlign(Paint* paint, const minikin::Layout& layout);
+ static float xOffsetForTextAlign(Paint* paint, const minikin::Layout& layout);
- ANDROID_API static float hOffsetForTextAlign(Paint* paint, const minikin::Layout& layout,
+ static float hOffsetForTextAlign(Paint* paint, const minikin::Layout& layout,
const SkPath& path);
// f is a functor of type void f(size_t start, size_t end);
template <typename F>
- ANDROID_API static void forFontRun(const minikin::Layout& layout, Paint* paint, F& f) {
+ static void forFontRun(const minikin::Layout& layout, Paint* paint, F& f) {
float saveSkewX = paint->getSkFont().getSkewX();
bool savefakeBold = paint->getSkFont().isEmbolden();
const minikin::MinikinFont* curFont = nullptr;
diff --git a/libs/hwui/hwui/Paint.h b/libs/hwui/hwui/Paint.h
index 281ecd27d780..0bb689c19079 100644
--- a/libs/hwui/hwui/Paint.h
+++ b/libs/hwui/hwui/Paint.h
@@ -30,9 +30,11 @@
#include <minikin/FamilyVariant.h>
#include <minikin/Hyphenator.h>
+#include <shader/Shader.h>
+
namespace android {
-class ANDROID_API Paint : public SkPaint {
+class Paint : public SkPaint {
public:
// Default values for underlined and strikethrough text,
// as defined by Skia in SkTextFormatParams.h.
@@ -149,8 +151,14 @@ public:
// The only respected flags are : [ antialias, dither, filterBitmap ]
static uint32_t GetSkPaintJavaFlags(const SkPaint&);
static void SetSkPaintJavaFlags(SkPaint*, uint32_t flags);
+
+ void setShader(sk_sp<uirenderer::Shader> shader);
private:
+
+ using SkPaint::setShader;
+ using SkPaint::setImageFilter;
+
SkFont mFont;
sk_sp<SkDrawLooper> mLooper;
@@ -169,6 +177,7 @@ private:
bool mStrikeThru = false;
bool mUnderline = false;
bool mDevKern = false;
+ sk_sp<uirenderer::Shader> mShader;
};
} // namespace android
diff --git a/libs/hwui/hwui/PaintImpl.cpp b/libs/hwui/hwui/PaintImpl.cpp
index fa2674fc2f5e..21f60fd7b671 100644
--- a/libs/hwui/hwui/PaintImpl.cpp
+++ b/libs/hwui/hwui/PaintImpl.cpp
@@ -24,7 +24,8 @@ Paint::Paint()
, mWordSpacing(0)
, mFontFeatureSettings()
, mMinikinLocaleListId(0)
- , mFamilyVariant(minikin::FamilyVariant::DEFAULT) {
+ , mFamilyVariant(minikin::FamilyVariant::DEFAULT)
+ , mShader(nullptr) {
// SkPaint::antialiasing defaults to false, but
// SkFont::edging defaults to kAntiAlias. To keep them
// insync, we manually set the font to kAilas.
@@ -45,7 +46,8 @@ Paint::Paint(const Paint& paint)
, mAlign(paint.mAlign)
, mStrikeThru(paint.mStrikeThru)
, mUnderline(paint.mUnderline)
- , mDevKern(paint.mDevKern) {}
+ , mDevKern(paint.mDevKern)
+ , mShader(paint.mShader){}
Paint::~Paint() {}
@@ -65,9 +67,30 @@ Paint& Paint::operator=(const Paint& other) {
mStrikeThru = other.mStrikeThru;
mUnderline = other.mUnderline;
mDevKern = other.mDevKern;
+ mShader = other.mShader;
return *this;
}
+void Paint::setShader(sk_sp<uirenderer::Shader> shader) {
+ if (shader) {
+ // If there is an SkShader compatible shader, apply it
+ sk_sp<SkShader> skShader = shader->asSkShader();
+ if (skShader.get()) {
+ SkPaint::setShader(skShader);
+ SkPaint::setImageFilter(nullptr);
+ } else {
+ // ... otherwise the specified shader can only be represented as an ImageFilter
+ SkPaint::setShader(nullptr);
+ SkPaint::setImageFilter(shader->asSkImageFilter());
+ }
+ } else {
+ // No shader is provided at all, clear out both the SkShader and SkImageFilter slots
+ SkPaint::setShader(nullptr);
+ SkPaint::setImageFilter(nullptr);
+ }
+ mShader = shader;
+}
+
bool operator==(const Paint& a, const Paint& b) {
return static_cast<const SkPaint&>(a) == static_cast<const SkPaint&>(b) &&
a.mFont == b.mFont &&
diff --git a/libs/hwui/jni/Bitmap.cpp b/libs/hwui/jni/Bitmap.cpp
index c0663a9bc699..eb9885a4436a 100755
--- a/libs/hwui/jni/Bitmap.cpp
+++ b/libs/hwui/jni/Bitmap.cpp
@@ -19,12 +19,19 @@
#include <utils/Color.h>
#ifdef __ANDROID__ // Layoutlib does not support graphic buffer, parcel or render thread
+#include <android-base/unique_fd.h>
+#include <android/binder_parcel.h>
+#include <android/binder_parcel_jni.h>
+#include <android/binder_parcel_platform.h>
+#include <android/binder_parcel_utils.h>
#include <private/android/AHardwareBufferHelpers.h>
-#include <binder/Parcel.h>
+#include <cutils/ashmem.h>
#include <dlfcn.h>
#include <renderthread/RenderProxy.h>
+#include <sys/mman.h>
#endif
+#include <inttypes.h>
#include <string.h>
#include <memory>
#include <string>
@@ -567,152 +574,296 @@ static void Bitmap_setHasMipMap(JNIEnv* env, jobject, jlong bitmapHandle,
///////////////////////////////////////////////////////////////////////////////
+// TODO: Move somewhere else
#ifdef __ANDROID__ // Layoutlib does not support parcel
-static struct parcel_offsets_t
-{
- jclass clazz;
- jfieldID mNativePtr;
-} gParcelOffsets;
-
-static Parcel* parcelForJavaObject(JNIEnv* env, jobject obj) {
- if (obj) {
- Parcel* p = (Parcel*)env->GetLongField(obj, gParcelOffsets.mNativePtr);
- if (p != NULL) {
- return p;
+
+class ScopedParcel {
+public:
+ explicit ScopedParcel(JNIEnv* env, jobject parcel) {
+ mParcel = AParcel_fromJavaParcel(env, parcel);
+ }
+
+ ~ScopedParcel() { AParcel_delete(mParcel); }
+
+ int32_t readInt32() {
+ int32_t temp = 0;
+ // TODO: This behavior-matches what android::Parcel does
+ // but this should probably be better
+ if (AParcel_readInt32(mParcel, &temp) != STATUS_OK) {
+ temp = 0;
}
- jniThrowException(env, "java/lang/IllegalStateException", "Parcel has been finalized!");
+ return temp;
+ }
+
+ uint32_t readUint32() {
+ uint32_t temp = 0;
+ // TODO: This behavior-matches what android::Parcel does
+ // but this should probably be better
+ if (AParcel_readUint32(mParcel, &temp) != STATUS_OK) {
+ temp = 0;
+ }
+ return temp;
+ }
+
+ void writeInt32(int32_t value) { AParcel_writeInt32(mParcel, value); }
+
+ void writeUint32(uint32_t value) { AParcel_writeUint32(mParcel, value); }
+
+ bool allowFds() const { return AParcel_getAllowFds(mParcel); }
+
+ std::optional<sk_sp<SkData>> readData() {
+ struct Data {
+ void* ptr = nullptr;
+ size_t size = 0;
+ } data;
+ auto error = AParcel_readByteArray(mParcel, &data,
+ [](void* arrayData, int32_t length,
+ int8_t** outBuffer) -> bool {
+ Data* data = reinterpret_cast<Data*>(arrayData);
+ if (length > 0) {
+ data->ptr = sk_malloc_canfail(length);
+ if (!data->ptr) {
+ return false;
+ }
+ *outBuffer =
+ reinterpret_cast<int8_t*>(data->ptr);
+ data->size = length;
+ }
+ return true;
+ });
+ if (error != STATUS_OK || data.size <= 0) {
+ sk_free(data.ptr);
+ return std::nullopt;
+ } else {
+ return SkData::MakeFromMalloc(data.ptr, data.size);
+ }
+ }
+
+ void writeData(const std::optional<sk_sp<SkData>>& optData) {
+ if (optData) {
+ const auto& data = *optData;
+ AParcel_writeByteArray(mParcel, reinterpret_cast<const int8_t*>(data->data()),
+ data->size());
+ } else {
+ AParcel_writeByteArray(mParcel, nullptr, -1);
+ }
+ }
+
+ AParcel* get() { return mParcel; }
+
+private:
+ AParcel* mParcel;
+};
+
+enum class BlobType : int32_t {
+ IN_PLACE,
+ ASHMEM,
+};
+
+#define ON_ERROR_RETURN(X) \
+ if ((error = (X)) != STATUS_OK) return error
+
+template <typename T, typename U>
+static binder_status_t readBlob(AParcel* parcel, T inPlaceCallback, U ashmemCallback) {
+ binder_status_t error = STATUS_OK;
+ BlobType type;
+ static_assert(sizeof(BlobType) == sizeof(int32_t));
+ ON_ERROR_RETURN(AParcel_readInt32(parcel, (int32_t*)&type));
+ if (type == BlobType::IN_PLACE) {
+ struct Data {
+ std::unique_ptr<int8_t[]> ptr = nullptr;
+ int32_t size = 0;
+ } data;
+ ON_ERROR_RETURN(
+ AParcel_readByteArray(parcel, &data,
+ [](void* arrayData, int32_t length, int8_t** outBuffer) {
+ Data* data = reinterpret_cast<Data*>(arrayData);
+ if (length > 0) {
+ data->ptr = std::make_unique<int8_t[]>(length);
+ data->size = length;
+ *outBuffer = data->ptr.get();
+ }
+ return data->ptr != nullptr;
+ }));
+ inPlaceCallback(std::move(data.ptr), data.size);
+ return STATUS_OK;
+ } else if (type == BlobType::ASHMEM) {
+ int rawFd = -1;
+ int32_t size = 0;
+ ON_ERROR_RETURN(AParcel_readInt32(parcel, &size));
+ ON_ERROR_RETURN(AParcel_readParcelFileDescriptor(parcel, &rawFd));
+ android::base::unique_fd fd(rawFd);
+ ashmemCallback(std::move(fd), size);
+ return STATUS_OK;
+ } else {
+ // Although the above if/else was "exhaustive" guard against unknown types
+ return STATUS_UNKNOWN_ERROR;
}
- return NULL;
}
-#endif
+
+static constexpr size_t BLOB_INPLACE_LIMIT = 12 * 1024;
+// Fail fast if we can't use ashmem and the size exceeds this limit - the binder transaction
+// wouldn't go through, anyway
+// TODO: Can we get this from somewhere?
+static constexpr size_t BLOB_MAX_INPLACE_LIMIT = 1 * 1024 * 1024;
+static constexpr bool shouldUseAshmem(AParcel* parcel, int32_t size) {
+ return size > BLOB_INPLACE_LIMIT && AParcel_getAllowFds(parcel);
+}
+
+static binder_status_t writeBlobFromFd(AParcel* parcel, int32_t size, int fd) {
+ binder_status_t error = STATUS_OK;
+ ON_ERROR_RETURN(AParcel_writeInt32(parcel, static_cast<int32_t>(BlobType::ASHMEM)));
+ ON_ERROR_RETURN(AParcel_writeInt32(parcel, size));
+ ON_ERROR_RETURN(AParcel_writeParcelFileDescriptor(parcel, fd));
+ return STATUS_OK;
+}
+
+static binder_status_t writeBlob(AParcel* parcel, const int32_t size, const void* data, bool immutable) {
+ if (size <= 0 || data == nullptr) {
+ return STATUS_NOT_ENOUGH_DATA;
+ }
+ binder_status_t error = STATUS_OK;
+ if (shouldUseAshmem(parcel, size)) {
+ // Create new ashmem region with read/write priv
+ base::unique_fd fd(ashmem_create_region("bitmap", size));
+ if (fd.get() < 0) {
+ return STATUS_NO_MEMORY;
+ }
+
+ {
+ void* dest = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd.get(), 0);
+ if (dest == MAP_FAILED) {
+ return STATUS_NO_MEMORY;
+ }
+ memcpy(dest, data, size);
+ munmap(dest, size);
+ }
+
+ if (immutable && ashmem_set_prot_region(fd.get(), PROT_READ) < 0) {
+ return STATUS_UNKNOWN_ERROR;
+ }
+ // Workaround b/149851140 in AParcel_writeParcelFileDescriptor
+ int rawFd = fd.release();
+ error = writeBlobFromFd(parcel, size, rawFd);
+ close(rawFd);
+ return error;
+ } else {
+ if (size > BLOB_MAX_INPLACE_LIMIT) {
+ return STATUS_FAILED_TRANSACTION;
+ }
+ ON_ERROR_RETURN(AParcel_writeInt32(parcel, static_cast<int32_t>(BlobType::IN_PLACE)));
+ ON_ERROR_RETURN(AParcel_writeByteArray(parcel, static_cast<const int8_t*>(data), size));
+ return STATUS_OK;
+ }
+}
+
+#undef ON_ERROR_RETURN
+
+#endif // __ANDROID__ // Layoutlib does not support parcel
// This is the maximum possible size because the SkColorSpace must be
// representable (and therefore serializable) using a matrix and numerical
// transfer function. If we allow more color space representations in the
// framework, we may need to update this maximum size.
-static constexpr uint32_t kMaxColorSpaceSerializedBytes = 80;
+static constexpr size_t kMaxColorSpaceSerializedBytes = 80;
+
+static constexpr auto RuntimeException = "java/lang/RuntimeException";
+
+static bool validateImageInfo(const SkImageInfo& info, int32_t rowBytes) {
+ // TODO: Can we avoid making a SkBitmap for this?
+ return SkBitmap().setInfo(info, rowBytes);
+}
static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
#ifdef __ANDROID__ // Layoutlib does not support parcel
if (parcel == NULL) {
- SkDebugf("-------- unparcel parcel is NULL\n");
+ jniThrowNullPointerException(env, "parcel cannot be null");
return NULL;
}
- android::Parcel* p = parcelForJavaObject(env, parcel);
+ ScopedParcel p(env, parcel);
- const bool isMutable = p->readInt32() != 0;
- const SkColorType colorType = (SkColorType)p->readInt32();
- const SkAlphaType alphaType = (SkAlphaType)p->readInt32();
- const uint32_t colorSpaceSize = p->readUint32();
+ const bool isMutable = p.readInt32();
+ const SkColorType colorType = static_cast<SkColorType>(p.readInt32());
+ const SkAlphaType alphaType = static_cast<SkAlphaType>(p.readInt32());
sk_sp<SkColorSpace> colorSpace;
- if (colorSpaceSize > 0) {
- if (colorSpaceSize > kMaxColorSpaceSerializedBytes) {
+ const auto optColorSpaceData = p.readData();
+ if (optColorSpaceData) {
+ const auto& colorSpaceData = *optColorSpaceData;
+ if (colorSpaceData->size() > kMaxColorSpaceSerializedBytes) {
ALOGD("Bitmap_createFromParcel: Serialized SkColorSpace is larger than expected: "
- "%d bytes\n", colorSpaceSize);
+ "%zu bytes (max: %zu)\n",
+ colorSpaceData->size(), kMaxColorSpaceSerializedBytes);
}
- const void* data = p->readInplace(colorSpaceSize);
- if (data) {
- colorSpace = SkColorSpace::Deserialize(data, colorSpaceSize);
- } else {
- ALOGD("Bitmap_createFromParcel: Unable to read serialized SkColorSpace data\n");
- }
+ colorSpace = SkColorSpace::Deserialize(colorSpaceData->data(), colorSpaceData->size());
}
- const int width = p->readInt32();
- const int height = p->readInt32();
- const int rowBytes = p->readInt32();
- const int density = p->readInt32();
+ const int32_t width = p.readInt32();
+ const int32_t height = p.readInt32();
+ const int32_t rowBytes = p.readInt32();
+ const int32_t density = p.readInt32();
if (kN32_SkColorType != colorType &&
kRGBA_F16_SkColorType != colorType &&
kRGB_565_SkColorType != colorType &&
kARGB_4444_SkColorType != colorType &&
kAlpha_8_SkColorType != colorType) {
- SkDebugf("Bitmap_createFromParcel unknown colortype: %d\n", colorType);
+ jniThrowExceptionFmt(env, RuntimeException,
+ "Bitmap_createFromParcel unknown colortype: %d\n", colorType);
return NULL;
}
- std::unique_ptr<SkBitmap> bitmap(new SkBitmap);
- if (!bitmap->setInfo(SkImageInfo::Make(width, height, colorType, alphaType, colorSpace),
- rowBytes)) {
+ auto imageInfo = SkImageInfo::Make(width, height, colorType, alphaType, colorSpace);
+ size_t allocationSize = 0;
+ if (!validateImageInfo(imageInfo, rowBytes)) {
+ jniThrowRuntimeException(env, "Received bad SkImageInfo");
return NULL;
}
-
- // Read the bitmap blob.
- size_t size = bitmap->computeByteSize();
- android::Parcel::ReadableBlob blob;
- android::status_t status = p->readBlob(size, &blob);
- if (status) {
- doThrowRE(env, "Could not read bitmap blob.");
+ if (!Bitmap::computeAllocationSize(rowBytes, height, &allocationSize)) {
+ jniThrowExceptionFmt(env, RuntimeException,
+ "Received bad bitmap size: width=%d, height=%d, rowBytes=%d", width,
+ height, rowBytes);
return NULL;
}
-
- // Map the bitmap in place from the ashmem region if possible otherwise copy.
sk_sp<Bitmap> nativeBitmap;
- // If the blob is mutable we have ownership of the region and can always use it
- // If the blob is immutable _and_ we're immutable, we can then still use it
- if (blob.fd() >= 0 && (blob.isMutable() || !isMutable)) {
-#if DEBUG_PARCEL
- ALOGD("Bitmap.createFromParcel: mapped contents of bitmap from %s blob "
- "(fds %s)",
- blob.isMutable() ? "mutable" : "immutable",
- p->allowFds() ? "allowed" : "forbidden");
-#endif
- // Dup the file descriptor so we can keep a reference to it after the Parcel
- // is disposed.
- int dupFd = fcntl(blob.fd(), F_DUPFD_CLOEXEC, 0);
- if (dupFd < 0) {
- ALOGE("Error allocating dup fd. Error:%d", errno);
- blob.release();
- doThrowRE(env, "Could not allocate dup blob fd.");
- return NULL;
- }
-
- // Map the pixels in place and take ownership of the ashmem region. We must also respect the
- // rowBytes value already set on the bitmap instead of attempting to compute our own.
- nativeBitmap = Bitmap::createFrom(bitmap->info(), bitmap->rowBytes(), dupFd,
- const_cast<void*>(blob.data()), size, !isMutable);
- if (!nativeBitmap) {
- close(dupFd);
- blob.release();
- doThrowRE(env, "Could not allocate ashmem pixel ref.");
- return NULL;
- }
-
- // Clear the blob handle, don't release it.
- blob.clear();
- } else {
-#if DEBUG_PARCEL
- if (blob.fd() >= 0) {
- ALOGD("Bitmap.createFromParcel: copied contents of mutable bitmap "
- "from immutable blob (fds %s)",
- p->allowFds() ? "allowed" : "forbidden");
- } else {
- ALOGD("Bitmap.createFromParcel: copied contents from %s blob "
- "(fds %s)",
- blob.isMutable() ? "mutable" : "immutable",
- p->allowFds() ? "allowed" : "forbidden");
- }
-#endif
-
- // Copy the pixels into a new buffer.
- nativeBitmap = Bitmap::allocateHeapBitmap(bitmap.get());
- if (!nativeBitmap) {
- blob.release();
- doThrowRE(env, "Could not allocate java pixel ref.");
- return NULL;
- }
- memcpy(bitmap->getPixels(), blob.data(), size);
-
- // Release the blob handle.
- blob.release();
+ binder_status_t error = readBlob(
+ p.get(),
+ // In place callback
+ [&](std::unique_ptr<int8_t[]> buffer, int32_t size) {
+ nativeBitmap = Bitmap::allocateHeapBitmap(allocationSize, imageInfo, rowBytes);
+ if (nativeBitmap) {
+ memcpy(nativeBitmap->pixels(), buffer.get(), size);
+ }
+ },
+ // Ashmem callback
+ [&](android::base::unique_fd fd, int32_t size) {
+ int flags = PROT_READ;
+ if (isMutable) {
+ flags |= PROT_WRITE;
+ }
+ void* addr = mmap(nullptr, size, flags, MAP_SHARED, fd.get(), 0);
+ if (addr == MAP_FAILED) {
+ const int err = errno;
+ ALOGW("mmap failed, error %d (%s)", err, strerror(err));
+ return;
+ }
+ nativeBitmap =
+ Bitmap::createFrom(imageInfo, rowBytes, fd.release(), addr, size, !isMutable);
+ });
+ if (error != STATUS_OK) {
+ // TODO: Stringify the error, see signalExceptionForError in android_util_Binder.cpp
+ jniThrowExceptionFmt(env, RuntimeException, "Failed to read from Parcel, error=%d", error);
+ return nullptr;
+ }
+ if (!nativeBitmap) {
+ jniThrowRuntimeException(env, "Could not allocate java pixel ref.");
+ return nullptr;
}
- return createBitmap(env, nativeBitmap.release(),
- getPremulBitmapCreateFlags(isMutable), NULL, NULL, density);
+ return createBitmap(env, nativeBitmap.release(), getPremulBitmapCreateFlags(isMutable), nullptr,
+ nullptr, density);
#else
- doThrowRE(env, "Cannot use parcels outside of Android");
+ jniThrowRuntimeException(env, "Cannot use parcels outside of Android");
return NULL;
#endif
}
@@ -725,48 +876,38 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,
return JNI_FALSE;
}
- android::Parcel* p = parcelForJavaObject(env, parcel);
+ ScopedParcel p(env, parcel);
SkBitmap bitmap;
auto bitmapWrapper = reinterpret_cast<BitmapWrapper*>(bitmapHandle);
bitmapWrapper->getSkBitmap(&bitmap);
- p->writeInt32(!bitmap.isImmutable());
- p->writeInt32(bitmap.colorType());
- p->writeInt32(bitmap.alphaType());
+ p.writeInt32(!bitmap.isImmutable());
+ p.writeInt32(bitmap.colorType());
+ p.writeInt32(bitmap.alphaType());
SkColorSpace* colorSpace = bitmap.colorSpace();
if (colorSpace != nullptr) {
- sk_sp<SkData> data = colorSpace->serialize();
- size_t size = data->size();
- p->writeUint32(size);
- if (size > 0) {
- if (size > kMaxColorSpaceSerializedBytes) {
- ALOGD("Bitmap_writeToParcel: Serialized SkColorSpace is larger than expected: "
- "%zu bytes\n", size);
- }
-
- p->write(data->data(), size);
- }
+ p.writeData(colorSpace->serialize());
} else {
- p->writeUint32(0);
+ p.writeData(std::nullopt);
}
- p->writeInt32(bitmap.width());
- p->writeInt32(bitmap.height());
- p->writeInt32(bitmap.rowBytes());
- p->writeInt32(density);
+ p.writeInt32(bitmap.width());
+ p.writeInt32(bitmap.height());
+ p.writeInt32(bitmap.rowBytes());
+ p.writeInt32(density);
// Transfer the underlying ashmem region if we have one and it's immutable.
- android::status_t status;
+ binder_status_t status;
int fd = bitmapWrapper->bitmap().getAshmemFd();
- if (fd >= 0 && bitmap.isImmutable() && p->allowFds()) {
+ if (fd >= 0 && p.allowFds() && bitmap.isImmutable()) {
#if DEBUG_PARCEL
ALOGD("Bitmap.writeToParcel: transferring immutable bitmap's ashmem fd as "
- "immutable blob (fds %s)",
- p->allowFds() ? "allowed" : "forbidden");
+ "immutable blob (fds %s)",
+ p.allowFds() ? "allowed" : "forbidden");
#endif
- status = p->writeDupImmutableBlobFileDescriptor(fd);
- if (status) {
+ status = writeBlobFromFd(p.get(), bitmapWrapper->bitmap().getAllocationByteCount(), fd);
+ if (status != STATUS_OK) {
doThrowRE(env, "Could not write bitmap blob file descriptor.");
return JNI_FALSE;
}
@@ -776,26 +917,15 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,
// Copy the bitmap to a new blob.
#if DEBUG_PARCEL
ALOGD("Bitmap.writeToParcel: copying bitmap into new blob (fds %s)",
- p->allowFds() ? "allowed" : "forbidden");
+ p.allowFds() ? "allowed" : "forbidden");
#endif
- const bool mutableCopy = !bitmap.isImmutable();
size_t size = bitmap.computeByteSize();
- android::Parcel::WritableBlob blob;
- status = p->writeBlob(size, mutableCopy, &blob);
+ status = writeBlob(p.get(), size, bitmap.getPixels(), bitmap.isImmutable());
if (status) {
doThrowRE(env, "Could not copy bitmap to parcel blob.");
return JNI_FALSE;
}
-
- const void* pSrc = bitmap.getPixels();
- if (pSrc == NULL) {
- memset(blob.data(), 0, size);
- } else {
- memcpy(blob.data(), pSrc, size);
- }
-
- blob.release();
return JNI_TRUE;
#else
doThrowRE(env, "Cannot use parcels outside of Android");
@@ -1074,13 +1204,16 @@ static jobject Bitmap_wrapHardwareBufferBitmap(JNIEnv* env, jobject, jobject har
static jobject Bitmap_getHardwareBuffer(JNIEnv* env, jobject, jlong bitmapPtr) {
#ifdef __ANDROID__ // Layoutlib does not support graphic buffer
LocalScopedBitmap bitmapHandle(bitmapPtr);
- LOG_ALWAYS_FATAL_IF(!bitmapHandle->isHardware(),
+ if (!bitmapHandle->isHardware()) {
+ jniThrowException(env, "java/lang/IllegalStateException",
"Hardware config is only supported config in Bitmap_getHardwareBuffer");
+ return nullptr;
+ }
Bitmap& bitmap = bitmapHandle->bitmap();
return AHardwareBuffer_toHardwareBuffer(env, bitmap.hardwareBuffer());
#else
- return NULL;
+ return nullptr;
#endif
}
@@ -1091,6 +1224,14 @@ static jboolean Bitmap_isImmutable(CRITICAL_JNI_PARAMS_COMMA jlong bitmapHandle)
return bitmapHolder->bitmap().isImmutable() ? JNI_TRUE : JNI_FALSE;
}
+static jboolean Bitmap_isBackedByAshmem(CRITICAL_JNI_PARAMS_COMMA jlong bitmapHandle) {
+ LocalScopedBitmap bitmapHolder(bitmapHandle);
+ if (!bitmapHolder.valid()) return JNI_FALSE;
+
+ return bitmapHolder->bitmap().pixelStorageType() == PixelStorageType::Ashmem ? JNI_TRUE
+ : JNI_FALSE;
+}
+
static void Bitmap_setImmutable(JNIEnv* env, jobject, jlong bitmapHandle) {
LocalScopedBitmap bitmapHolder(bitmapHandle);
if (!bitmapHolder.valid()) return;
@@ -1157,12 +1298,11 @@ static const JNINativeMethod gBitmapMethods[] = {
{ "nativeSetImmutable", "(J)V", (void*)Bitmap_setImmutable},
// ------------ @CriticalNative ----------------
- { "nativeIsImmutable", "(J)Z", (void*)Bitmap_isImmutable}
+ { "nativeIsImmutable", "(J)Z", (void*)Bitmap_isImmutable},
+ { "nativeIsBackedByAshmem", "(J)Z", (void*)Bitmap_isBackedByAshmem}
};
-const char* const kParcelPathName = "android/os/Parcel";
-
int register_android_graphics_Bitmap(JNIEnv* env)
{
gBitmap_class = MakeGlobalRefOrDie(env, FindClassOrDie(env, "android/graphics/Bitmap"));
@@ -1180,9 +1320,6 @@ int register_android_graphics_Bitmap(JNIEnv* env)
AHardwareBuffer_toHardwareBuffer = (AHB_to_HB)dlsym(handle_, "AHardwareBuffer_toHardwareBuffer");
LOG_ALWAYS_FATAL_IF(AHardwareBuffer_toHardwareBuffer == nullptr,
" Failed to find required symbol AHardwareBuffer_toHardwareBuffer!");
-
- gParcelOffsets.clazz = MakeGlobalRefOrDie(env, FindClassOrDie(env, kParcelPathName));
- gParcelOffsets.mNativePtr = GetFieldIDOrDie(env, gParcelOffsets.clazz, "mNativePtr", "J");
#endif
return android::RegisterMethodsOrDie(env, "android/graphics/Bitmap", gBitmapMethods,
NELEM(gBitmapMethods));
diff --git a/libs/hwui/jni/BitmapFactory.cpp b/libs/hwui/jni/BitmapFactory.cpp
index e8e89d81bdb7..7d2583a2ac01 100644
--- a/libs/hwui/jni/BitmapFactory.cpp
+++ b/libs/hwui/jni/BitmapFactory.cpp
@@ -3,12 +3,11 @@
#include "BitmapFactory.h"
#include "CreateJavaOutputStreamAdaptor.h"
+#include "FrontBufferedStream.h"
#include "GraphicsJNI.h"
#include "MimeType.h"
#include "NinePatchPeeker.h"
#include "SkAndroidCodec.h"
-#include "SkBRDAllocator.h"
-#include "SkFrontBufferedStream.h"
#include "SkMath.h"
#include "SkPixelRef.h"
#include "SkStream.h"
@@ -510,8 +509,8 @@ static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, jbyteA
std::unique_ptr<SkStream> stream(CreateJavaInputStreamAdaptor(env, is, storage));
if (stream.get()) {
- std::unique_ptr<SkStreamRewindable> bufferedStream(
- SkFrontBufferedStream::Make(std::move(stream), SkCodec::MinBufferedBytesNeeded()));
+ std::unique_ptr<SkStreamRewindable> bufferedStream(skia::FrontBufferedStream::Make(
+ std::move(stream), SkCodec::MinBufferedBytesNeeded()));
SkASSERT(bufferedStream.get() != NULL);
bitmap = doDecode(env, std::move(bufferedStream), padding, options, inBitmapHandle,
colorSpaceHandle);
@@ -565,8 +564,8 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi
// Use a buffered stream. Although an SkFILEStream can be rewound, this
// ensures that SkImageDecoder::Factory never rewinds beyond the
// current position of the file descriptor.
- std::unique_ptr<SkStreamRewindable> stream(SkFrontBufferedStream::Make(std::move(fileStream),
- SkCodec::MinBufferedBytesNeeded()));
+ std::unique_ptr<SkStreamRewindable> stream(skia::FrontBufferedStream::Make(
+ std::move(fileStream), SkCodec::MinBufferedBytesNeeded()));
return doDecode(env, std::move(stream), padding, bitmapFactoryOptions, inBitmapHandle,
colorSpaceHandle);
diff --git a/libs/hwui/jni/BitmapRegionDecoder.cpp b/libs/hwui/jni/BitmapRegionDecoder.cpp
index 712351382d97..4cc05ef6f13b 100644
--- a/libs/hwui/jni/BitmapRegionDecoder.cpp
+++ b/libs/hwui/jni/BitmapRegionDecoder.cpp
@@ -22,8 +22,8 @@
#include "GraphicsJNI.h"
#include "Utils.h"
+#include "BitmapRegionDecoder.h"
#include "SkBitmap.h"
-#include "SkBitmapRegionDecoder.h"
#include "SkCodec.h"
#include "SkData.h"
#include "SkStream.h"
@@ -36,10 +36,8 @@
using namespace android;
-static jobject createBitmapRegionDecoder(JNIEnv* env, std::unique_ptr<SkStreamRewindable> stream) {
- std::unique_ptr<SkBitmapRegionDecoder> brd(
- SkBitmapRegionDecoder::Create(stream.release(),
- SkBitmapRegionDecoder::kAndroidCodec_Strategy));
+static jobject createBitmapRegionDecoder(JNIEnv* env, sk_sp<SkData> data) {
+ auto brd = skia::BitmapRegionDecoder::Make(std::move(data));
if (!brd) {
doThrowIOE(env, "Image format not supported");
return nullObjectReturn("CreateBitmapRegionDecoder returned null");
@@ -49,21 +47,13 @@ static jobject createBitmapRegionDecoder(JNIEnv* env, std::unique_ptr<SkStreamRe
}
static jobject nativeNewInstanceFromByteArray(JNIEnv* env, jobject, jbyteArray byteArray,
- jint offset, jint length, jboolean isShareable) {
- /* If isShareable we could decide to just wrap the java array and
- share it, but that means adding a globalref to the java array object
- For now we just always copy the array's data if isShareable.
- */
+ jint offset, jint length) {
AutoJavaByteArray ar(env, byteArray);
- std::unique_ptr<SkMemoryStream> stream(new SkMemoryStream(ar.ptr() + offset, length, true));
-
- // the decoder owns the stream.
- jobject brd = createBitmapRegionDecoder(env, std::move(stream));
- return brd;
+ return createBitmapRegionDecoder(env, SkData::MakeWithCopy(ar.ptr() + offset, length));
}
static jobject nativeNewInstanceFromFileDescriptor(JNIEnv* env, jobject clazz,
- jobject fileDescriptor, jboolean isShareable) {
+ jobject fileDescriptor) {
NPE_CHECK_RETURN_ZERO(env, fileDescriptor);
jint descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);
@@ -74,41 +64,28 @@ static jobject nativeNewInstanceFromFileDescriptor(JNIEnv* env, jobject clazz,
return nullObjectReturn("fstat return -1");
}
- sk_sp<SkData> data(SkData::MakeFromFD(descriptor));
- std::unique_ptr<SkMemoryStream> stream(new SkMemoryStream(std::move(data)));
-
- // the decoder owns the stream.
- jobject brd = createBitmapRegionDecoder(env, std::move(stream));
- return brd;
+ return createBitmapRegionDecoder(env, SkData::MakeFromFD(descriptor));
}
-static jobject nativeNewInstanceFromStream(JNIEnv* env, jobject clazz,
- jobject is, // InputStream
- jbyteArray storage, // byte[]
- jboolean isShareable) {
- jobject brd = NULL;
- // for now we don't allow shareable with java inputstreams
- std::unique_ptr<SkStreamRewindable> stream(CopyJavaInputStream(env, is, storage));
-
- if (stream) {
- // the decoder owns the stream.
- brd = createBitmapRegionDecoder(env, std::move(stream));
+static jobject nativeNewInstanceFromStream(JNIEnv* env, jobject clazz, jobject is, // InputStream
+ jbyteArray storage) { // byte[]
+ jobject brd = nullptr;
+ sk_sp<SkData> data = CopyJavaInputStream(env, is, storage);
+
+ if (data) {
+ brd = createBitmapRegionDecoder(env, std::move(data));
}
return brd;
}
-static jobject nativeNewInstanceFromAsset(JNIEnv* env, jobject clazz,
- jlong native_asset, // Asset
- jboolean isShareable) {
+static jobject nativeNewInstanceFromAsset(JNIEnv* env, jobject clazz, jlong native_asset) {
Asset* asset = reinterpret_cast<Asset*>(native_asset);
- std::unique_ptr<SkMemoryStream> stream(CopyAssetToStream(asset));
- if (NULL == stream) {
- return NULL;
+ sk_sp<SkData> data = CopyAssetToData(asset);
+ if (!data) {
+ return nullptr;
}
- // the decoder owns the stream.
- jobject brd = createBitmapRegionDecoder(env, std::move(stream));
- return brd;
+ return createBitmapRegionDecoder(env, data);
}
/*
@@ -158,7 +135,7 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in
recycledBytes = recycledBitmap->getAllocationByteCount();
}
- SkBitmapRegionDecoder* brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
+ auto* brd = reinterpret_cast<skia::BitmapRegionDecoder*>(brdHandle);
SkColorType decodeColorType = brd->computeOutputColorType(colorType);
if (decodeColorType == kRGBA_F16_SkColorType && isHardware &&
!uirenderer::HardwareBitmapUploader::hasFP16Support()) {
@@ -166,7 +143,7 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in
}
// Set up the pixel allocator
- SkBRDAllocator* allocator = nullptr;
+ skia::BRDAllocator* allocator = nullptr;
RecyclingClippingPixelAllocator recycleAlloc(recycledBitmap, recycledBytes);
HeapAllocator heapAlloc;
if (javaBitmap) {
@@ -230,20 +207,17 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in
}
static jint nativeGetHeight(JNIEnv* env, jobject, jlong brdHandle) {
- SkBitmapRegionDecoder* brd =
- reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
+ auto* brd = reinterpret_cast<skia::BitmapRegionDecoder*>(brdHandle);
return static_cast<jint>(brd->height());
}
static jint nativeGetWidth(JNIEnv* env, jobject, jlong brdHandle) {
- SkBitmapRegionDecoder* brd =
- reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
+ auto* brd = reinterpret_cast<skia::BitmapRegionDecoder*>(brdHandle);
return static_cast<jint>(brd->width());
}
static void nativeClean(JNIEnv* env, jobject, jlong brdHandle) {
- SkBitmapRegionDecoder* brd =
- reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
+ auto* brd = reinterpret_cast<skia::BitmapRegionDecoder*>(brdHandle);
delete brd;
}
@@ -261,22 +235,22 @@ static const JNINativeMethod gBitmapRegionDecoderMethods[] = {
{ "nativeClean", "(J)V", (void*)nativeClean},
{ "nativeNewInstance",
- "([BIIZ)Landroid/graphics/BitmapRegionDecoder;",
+ "([BII)Landroid/graphics/BitmapRegionDecoder;",
(void*)nativeNewInstanceFromByteArray
},
{ "nativeNewInstance",
- "(Ljava/io/InputStream;[BZ)Landroid/graphics/BitmapRegionDecoder;",
+ "(Ljava/io/InputStream;[B)Landroid/graphics/BitmapRegionDecoder;",
(void*)nativeNewInstanceFromStream
},
{ "nativeNewInstance",
- "(Ljava/io/FileDescriptor;Z)Landroid/graphics/BitmapRegionDecoder;",
+ "(Ljava/io/FileDescriptor;)Landroid/graphics/BitmapRegionDecoder;",
(void*)nativeNewInstanceFromFileDescriptor
},
{ "nativeNewInstance",
- "(JZ)Landroid/graphics/BitmapRegionDecoder;",
+ "(J)Landroid/graphics/BitmapRegionDecoder;",
(void*)nativeNewInstanceFromAsset
},
};
diff --git a/libs/hwui/jni/CreateJavaOutputStreamAdaptor.cpp b/libs/hwui/jni/CreateJavaOutputStreamAdaptor.cpp
index f1c6b29204b2..785a5dc995ab 100644
--- a/libs/hwui/jni/CreateJavaOutputStreamAdaptor.cpp
+++ b/libs/hwui/jni/CreateJavaOutputStreamAdaptor.cpp
@@ -177,8 +177,12 @@ SkStream* CreateJavaInputStreamAdaptor(JNIEnv* env, jobject stream, jbyteArray s
return JavaInputStreamAdaptor::Create(env, stream, storage, swallowExceptions);
}
-static SkMemoryStream* adaptor_to_mem_stream(SkStream* stream) {
- SkASSERT(stream != NULL);
+sk_sp<SkData> CopyJavaInputStream(JNIEnv* env, jobject inputStream, jbyteArray storage) {
+ std::unique_ptr<SkStream> stream(CreateJavaInputStreamAdaptor(env, inputStream, storage));
+ if (!stream) {
+ return nullptr;
+ }
+
size_t bufferSize = 4096;
size_t streamLen = 0;
size_t len;
@@ -194,18 +198,7 @@ static SkMemoryStream* adaptor_to_mem_stream(SkStream* stream) {
}
data = (char*)sk_realloc_throw(data, streamLen);
- SkMemoryStream* streamMem = new SkMemoryStream();
- streamMem->setMemoryOwned(data, streamLen);
- return streamMem;
-}
-
-SkStreamRewindable* CopyJavaInputStream(JNIEnv* env, jobject stream,
- jbyteArray storage) {
- std::unique_ptr<SkStream> adaptor(CreateJavaInputStreamAdaptor(env, stream, storage));
- if (NULL == adaptor.get()) {
- return NULL;
- }
- return adaptor_to_mem_stream(adaptor.get());
+ return SkData::MakeFromMalloc(data, streamLen);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/libs/hwui/jni/CreateJavaOutputStreamAdaptor.h b/libs/hwui/jni/CreateJavaOutputStreamAdaptor.h
index 849418da01a1..bae40f1e8d2f 100644
--- a/libs/hwui/jni/CreateJavaOutputStreamAdaptor.h
+++ b/libs/hwui/jni/CreateJavaOutputStreamAdaptor.h
@@ -2,6 +2,7 @@
#define _ANDROID_GRAPHICS_CREATE_JAVA_OUTPUT_STREAM_ADAPTOR_H_
#include "jni.h"
+#include "SkData.h"
class SkMemoryStream;
class SkStream;
@@ -27,15 +28,14 @@ SkStream* CreateJavaInputStreamAdaptor(JNIEnv* env, jobject stream, jbyteArray s
bool swallowExceptions = true);
/**
- * Copy a Java InputStream. The result will be rewindable.
+ * Copy a Java InputStream to an SkData.
* @param env JNIEnv object.
* @param stream Pointer to Java InputStream.
* @param storage Java byte array for retrieving data from the
* Java InputStream.
- * @return SkStreamRewindable The data in stream will be copied
- * to a new SkStreamRewindable.
+ * @return SkData containing the stream's data.
*/
-SkStreamRewindable* CopyJavaInputStream(JNIEnv* env, jobject stream, jbyteArray storage);
+sk_sp<SkData> CopyJavaInputStream(JNIEnv* env, jobject stream, jbyteArray storage);
SkWStream* CreateJavaOutputStreamAdaptor(JNIEnv* env, jobject stream, jbyteArray storage);
diff --git a/libs/hwui/jni/FontFamily.cpp b/libs/hwui/jni/FontFamily.cpp
index a2fef1e19328..68eaa0a3ca54 100644
--- a/libs/hwui/jni/FontFamily.cpp
+++ b/libs/hwui/jni/FontFamily.cpp
@@ -104,21 +104,21 @@ static jlong FontFamily_getFamilyReleaseFunc(CRITICAL_JNI_PARAMS) {
static bool addSkTypeface(NativeFamilyBuilder* builder, sk_sp<SkData>&& data, int ttcIndex,
jint weight, jint italic) {
- FatVector<SkFontArguments::Axis, 2> skiaAxes;
+ FatVector<SkFontArguments::VariationPosition::Coordinate, 2> skVariation;
for (const auto& axis : builder->axes) {
- skiaAxes.emplace_back(SkFontArguments::Axis{axis.axisTag, axis.value});
+ skVariation.push_back({axis.axisTag, axis.value});
}
const size_t fontSize = data->size();
const void* fontPtr = data->data();
std::unique_ptr<SkStreamAsset> fontData(new SkMemoryStream(std::move(data)));
- SkFontArguments params;
- params.setCollectionIndex(ttcIndex);
- params.setAxes(skiaAxes.data(), skiaAxes.size());
+ SkFontArguments args;
+ args.setCollectionIndex(ttcIndex);
+ args.setVariationDesignPosition({skVariation.data(), static_cast<int>(skVariation.size())});
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
- sk_sp<SkTypeface> face(fm->makeFromStream(std::move(fontData), params));
+ sk_sp<SkTypeface> face(fm->makeFromStream(std::move(fontData), args));
if (face == NULL) {
ALOGE("addFont failed to create font, invalid request");
builder->axes.clear();
diff --git a/libs/hwui/jni/Graphics.cpp b/libs/hwui/jni/Graphics.cpp
index f76ecb4c9c8a..ecbb55ec878d 100644
--- a/libs/hwui/jni/Graphics.cpp
+++ b/libs/hwui/jni/Graphics.cpp
@@ -470,7 +470,7 @@ SkRegion* GraphicsJNI::getNativeRegion(JNIEnv* env, jobject region)
///////////////////////////////////////////////////////////////////////////////////////////
-jobject GraphicsJNI::createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap)
+jobject GraphicsJNI::createBitmapRegionDecoder(JNIEnv* env, skia::BitmapRegionDecoder* bitmap)
{
ALOG_ASSERT(bitmap != NULL);
diff --git a/libs/hwui/jni/GraphicsJNI.h b/libs/hwui/jni/GraphicsJNI.h
index b58a740a4c27..79ab617411e3 100644
--- a/libs/hwui/jni/GraphicsJNI.h
+++ b/libs/hwui/jni/GraphicsJNI.h
@@ -4,8 +4,8 @@
#include <cutils/compiler.h>
#include "Bitmap.h"
+#include "BRDAllocator.h"
#include "SkBitmap.h"
-#include "SkBRDAllocator.h"
#include "SkCodec.h"
#include "SkPixelRef.h"
#include "SkMallocPixelRef.h"
@@ -17,10 +17,12 @@
#include "graphics_jni_helpers.h"
-class SkBitmapRegionDecoder;
class SkCanvas;
namespace android {
+namespace skia {
+ class BitmapRegionDecoder;
+}
class Paint;
struct Typeface;
}
@@ -103,7 +105,8 @@ public:
static jobject createRegion(JNIEnv* env, SkRegion* region);
- static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap);
+ static jobject createBitmapRegionDecoder(JNIEnv* env,
+ android::skia::BitmapRegionDecoder* bitmap);
/**
* Given a bitmap we natively allocate a memory block to store the contents
@@ -154,7 +157,7 @@ private:
static JavaVM* mJavaVM;
};
-class HeapAllocator : public SkBRDAllocator {
+class HeapAllocator : public android::skia::BRDAllocator {
public:
HeapAllocator() { };
~HeapAllocator() { };
@@ -181,7 +184,7 @@ private:
* the decoded output to fit in the recycled bitmap if necessary.
* This allocator implements that behavior.
*
- * Skia's SkBitmapRegionDecoder expects the memory that
+ * Skia's BitmapRegionDecoder expects the memory that
* is allocated to be large enough to decode the entire region
* that is requested. It will decode directly into the memory
* that is provided.
@@ -200,7 +203,7 @@ private:
* reuse it again, given that it still may be in use from our
* first allocation.
*/
-class RecyclingClippingPixelAllocator : public SkBRDAllocator {
+class RecyclingClippingPixelAllocator : public android::skia::BRDAllocator {
public:
RecyclingClippingPixelAllocator(android::Bitmap* recycledBitmap,
diff --git a/libs/hwui/jni/ImageDecoder.cpp b/libs/hwui/jni/ImageDecoder.cpp
index 41d939bd6373..1f4fd230e55e 100644
--- a/libs/hwui/jni/ImageDecoder.cpp
+++ b/libs/hwui/jni/ImageDecoder.cpp
@@ -27,9 +27,9 @@
#include <hwui/ImageDecoder.h>
#include <HardwareBitmapUploader.h>
+#include <FrontBufferedStream.h>
#include <SkAndroidCodec.h>
#include <SkEncodedImageFormat.h>
-#include <SkFrontBufferedStream.h>
#include <SkStream.h>
#include <androidfw/Asset.h>
@@ -187,8 +187,7 @@ static jobject ImageDecoder_nCreateInputStream(JNIEnv* env, jobject /*clazz*/,
}
std::unique_ptr<SkStream> bufferedStream(
- SkFrontBufferedStream::Make(std::move(stream),
- SkCodec::MinBufferedBytesNeeded()));
+ skia::FrontBufferedStream::Make(std::move(stream), SkCodec::MinBufferedBytesNeeded()));
return native_create(env, std::move(bufferedStream), source, preferAnimation);
}
diff --git a/libs/hwui/jni/Movie.cpp b/libs/hwui/jni/Movie.cpp
index ede0ca8cda5b..bb8c99a73edf 100644
--- a/libs/hwui/jni/Movie.cpp
+++ b/libs/hwui/jni/Movie.cpp
@@ -1,7 +1,7 @@
#include "CreateJavaOutputStreamAdaptor.h"
+#include "FrontBufferedStream.h"
#include "GraphicsJNI.h"
#include <nativehelper/ScopedLocalRef.h>
-#include "SkFrontBufferedStream.h"
#include "Movie.h"
#include "SkStream.h"
#include "SkUtils.h"
@@ -100,10 +100,8 @@ static jobject movie_decodeStream(JNIEnv* env, jobject clazz, jobject istream) {
// Need to buffer enough input to be able to rewind as much as might be read by a decoder
// trying to determine the stream's format. The only decoder for movies is GIF, which
// will only read 6.
- // FIXME: Get this number from SkImageDecoder
- // bufferedStream takes ownership of strm
- std::unique_ptr<SkStreamRewindable> bufferedStream(SkFrontBufferedStream::Make(
- std::unique_ptr<SkStream>(strm), 6));
+ std::unique_ptr<SkStreamRewindable> bufferedStream(
+ android::skia::FrontBufferedStream::Make(std::unique_ptr<SkStream>(strm), 6));
SkASSERT(bufferedStream.get() != NULL);
Movie* moov = Movie::DecodeStream(bufferedStream.get());
diff --git a/libs/hwui/jni/Paint.cpp b/libs/hwui/jni/Paint.cpp
index df8635a8fe5a..554674a331cd 100644
--- a/libs/hwui/jni/Paint.cpp
+++ b/libs/hwui/jni/Paint.cpp
@@ -47,6 +47,7 @@
#include <minikin/LocaleList.h>
#include <minikin/Measurement.h>
#include <minikin/MinikinPaint.h>
+#include <shader/Shader.h>
#include <unicode/utf16.h>
#include <cassert>
@@ -54,6 +55,8 @@
#include <memory>
#include <vector>
+using namespace android::uirenderer;
+
namespace android {
struct JMetricsID {
@@ -782,11 +785,10 @@ namespace PaintGlue {
return obj->getFillPath(*src, dst) ? JNI_TRUE : JNI_FALSE;
}
- static jlong setShader(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong shaderHandle) {
- Paint* obj = reinterpret_cast<Paint*>(objHandle);
- SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
- obj->setShader(sk_ref_sp(shader));
- return reinterpret_cast<jlong>(obj->getShader());
+ static void setShader(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong shaderHandle) {
+ auto* paint = reinterpret_cast<Paint*>(objHandle);
+ auto* shader = reinterpret_cast<Shader*>(shaderHandle);
+ paint->setShader(sk_ref_sp(shader));
}
static jlong setColorFilter(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong filterHandle) {
@@ -1097,7 +1099,7 @@ static const JNINativeMethod methods[] = {
{"nGetStrokeJoin","(J)I", (void*) PaintGlue::getStrokeJoin},
{"nSetStrokeJoin","(JI)V", (void*) PaintGlue::setStrokeJoin},
{"nGetFillPath","(JJJ)Z", (void*) PaintGlue::getFillPath},
- {"nSetShader","(JJ)J", (void*) PaintGlue::setShader},
+ {"nSetShader","(JJ)V", (void*) PaintGlue::setShader},
{"nSetColorFilter","(JJ)J", (void*) PaintGlue::setColorFilter},
{"nSetXfermode","(JI)V", (void*) PaintGlue::setXfermode},
{"nSetPathEffect","(JJ)J", (void*) PaintGlue::setPathEffect},
diff --git a/libs/hwui/jni/Picture.cpp b/libs/hwui/jni/Picture.cpp
index d1b952130e88..8e4203c0b115 100644
--- a/libs/hwui/jni/Picture.cpp
+++ b/libs/hwui/jni/Picture.cpp
@@ -111,7 +111,7 @@ sk_sp<SkPicture> Picture::makePartialCopy() const {
SkPictureRecorder reRecorder;
- SkCanvas* canvas = reRecorder.beginRecording(mWidth, mHeight, NULL, 0);
+ SkCanvas* canvas = reRecorder.beginRecording(mWidth, mHeight);
mRecorder->partialReplay(canvas);
return reRecorder.finishRecordingAsPicture();
}
diff --git a/libs/hwui/jni/Shader.cpp b/libs/hwui/jni/Shader.cpp
index 0f6837640524..7cb77233846f 100644
--- a/libs/hwui/jni/Shader.cpp
+++ b/libs/hwui/jni/Shader.cpp
@@ -5,6 +5,14 @@
#include "SkShader.h"
#include "SkBlendMode.h"
#include "include/effects/SkRuntimeEffect.h"
+#include "shader/Shader.h"
+#include "shader/BitmapShader.h"
+#include "shader/BlurShader.h"
+#include "shader/ComposeShader.h"
+#include "shader/LinearGradientShader.h"
+#include "shader/RadialGradientShader.h"
+#include "shader/RuntimeShader.h"
+#include "shader/SweepGradientShader.h"
#include <vector>
@@ -50,7 +58,7 @@ static jint Color_HSVToColor(JNIEnv* env, jobject, jint alpha, jfloatArray hsvAr
///////////////////////////////////////////////////////////////////////////////////////////////
-static void Shader_safeUnref(SkShader* shader) {
+static void Shader_safeUnref(Shader* shader) {
SkSafeUnref(shader);
}
@@ -74,15 +82,15 @@ static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jlong matrixPtr, j
SkBitmap bitmap;
image = SkMakeImageFromRasterBitmap(bitmap, kNever_SkCopyPixelsMode);
}
- sk_sp<SkShader> shader = image->makeShader(
- (SkTileMode)tileModeX, (SkTileMode)tileModeY);
- ThrowIAE_IfNull(env, shader.get());
- if (matrix) {
- shader = shader->makeWithLocalMatrix(*matrix);
- }
+ auto* shader = new BitmapShader(
+ image,
+ static_cast<SkTileMode>(tileModeX),
+ static_cast<SkTileMode>(tileModeY),
+ matrix
+ );
- return reinterpret_cast<jlong>(shader.release());
+ return reinterpret_cast<jlong>(shader);
}
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -118,17 +126,18 @@ static jlong LinearGradient_create(JNIEnv* env, jobject, jlong matrixPtr,
#error Need to convert float array to SkScalar array before calling the following function.
#endif
- sk_sp<SkShader> shader(SkGradientShader::MakeLinear(pts, &colors[0],
- GraphicsJNI::getNativeColorSpace(colorSpaceHandle), pos, colors.size(),
- static_cast<SkTileMode>(tileMode), sGradientShaderFlags, nullptr));
- ThrowIAE_IfNull(env, shader);
-
- const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- if (matrix) {
- shader = shader->makeWithLocalMatrix(*matrix);
- }
+ auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
+ auto* shader = new LinearGradientShader(
+ pts,
+ colors,
+ GraphicsJNI::getNativeColorSpace(colorSpaceHandle),
+ pos,
+ static_cast<SkTileMode>(tileMode),
+ sGradientShaderFlags,
+ matrix
+ );
- return reinterpret_cast<jlong>(shader.release());
+ return reinterpret_cast<jlong>(shader);
}
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -148,17 +157,20 @@ static jlong RadialGradient_create(JNIEnv* env, jobject, jlong matrixPtr, jfloat
#error Need to convert float array to SkScalar array before calling the following function.
#endif
- sk_sp<SkShader> shader = SkGradientShader::MakeRadial(center, radius, &colors[0],
- GraphicsJNI::getNativeColorSpace(colorSpaceHandle), pos, colors.size(),
- static_cast<SkTileMode>(tileMode), sGradientShaderFlags, nullptr);
- ThrowIAE_IfNull(env, shader);
+ auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- if (matrix) {
- shader = shader->makeWithLocalMatrix(*matrix);
- }
+ auto* shader = new RadialGradientShader(
+ center,
+ radius,
+ colors,
+ GraphicsJNI::getNativeColorSpace(colorSpaceHandle),
+ pos,
+ static_cast<SkTileMode>(tileMode),
+ sGradientShaderFlags,
+ matrix
+ );
- return reinterpret_cast<jlong>(shader.release());
+ return reinterpret_cast<jlong>(shader);
}
///////////////////////////////////////////////////////////////////////////////
@@ -174,74 +186,93 @@ static jlong SweepGradient_create(JNIEnv* env, jobject, jlong matrixPtr, jfloat
#error Need to convert float array to SkScalar array before calling the following function.
#endif
- sk_sp<SkShader> shader = SkGradientShader::MakeSweep(x, y, &colors[0],
- GraphicsJNI::getNativeColorSpace(colorSpaceHandle), pos, colors.size(),
- sGradientShaderFlags, nullptr);
- ThrowIAE_IfNull(env, shader);
+ auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- if (matrix) {
- shader = shader->makeWithLocalMatrix(*matrix);
- }
+ auto* shader = new SweepGradientShader(
+ x,
+ y,
+ colors,
+ GraphicsJNI::getNativeColorSpace(colorSpaceHandle),
+ pos,
+ sGradientShaderFlags,
+ matrix
+ );
- return reinterpret_cast<jlong>(shader.release());
+ return reinterpret_cast<jlong>(shader);
}
///////////////////////////////////////////////////////////////////////////////////////////////
static jlong ComposeShader_create(JNIEnv* env, jobject o, jlong matrixPtr,
jlong shaderAHandle, jlong shaderBHandle, jint xfermodeHandle) {
- const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- SkShader* shaderA = reinterpret_cast<SkShader *>(shaderAHandle);
- SkShader* shaderB = reinterpret_cast<SkShader *>(shaderBHandle);
- SkBlendMode mode = static_cast<SkBlendMode>(xfermodeHandle);
- sk_sp<SkShader> baseShader(SkShaders::Blend(mode,
- sk_ref_sp(shaderA), sk_ref_sp(shaderB)));
-
- SkShader* shader;
-
- if (matrix) {
- shader = baseShader->makeWithLocalMatrix(*matrix).release();
- } else {
- shader = baseShader.release();
- }
- return reinterpret_cast<jlong>(shader);
+ auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
+ auto* shaderA = reinterpret_cast<Shader*>(shaderAHandle);
+ auto* shaderB = reinterpret_cast<Shader*>(shaderBHandle);
+
+ auto mode = static_cast<SkBlendMode>(xfermodeHandle);
+
+ auto* composeShader = new ComposeShader(
+ *shaderA,
+ *shaderB,
+ mode,
+ matrix
+ );
+
+ return reinterpret_cast<jlong>(composeShader);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////
+
+static jlong BlurShader_create(JNIEnv* env , jobject o, jlong matrixPtr, jfloat sigmaX,
+ jfloat sigmaY, jlong shaderHandle) {
+ auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
+ auto* inputShader = reinterpret_cast<Shader*>(shaderHandle);
+
+ auto* blurShader = new BlurShader(
+ sigmaX,
+ sigmaY,
+ inputShader,
+ matrix
+ );
+ return reinterpret_cast<jlong>(blurShader);
}
///////////////////////////////////////////////////////////////////////////////////////////////
static jlong RuntimeShader_create(JNIEnv* env, jobject, jlong shaderFactory, jlong matrixPtr,
jbyteArray inputs, jlong colorSpaceHandle, jboolean isOpaque) {
- SkRuntimeEffect* effect = reinterpret_cast<SkRuntimeEffect*>(shaderFactory);
+ auto* effect = reinterpret_cast<SkRuntimeEffect*>(shaderFactory);
AutoJavaByteArray arInputs(env, inputs);
- sk_sp<SkData> fData;
- fData = SkData::MakeWithCopy(arInputs.ptr(), arInputs.length());
- const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- sk_sp<SkShader> shader = effect->makeShader(fData, nullptr, 0, matrix, isOpaque == JNI_TRUE);
- ThrowIAE_IfNull(env, shader);
+ auto data = SkData::MakeWithCopy(arInputs.ptr(), arInputs.length());
+ auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
- return reinterpret_cast<jlong>(shader.release());
+ auto* shader = new RuntimeShader(
+ *effect,
+ std::move(data),
+ isOpaque == JNI_TRUE,
+ matrix
+ );
+ return reinterpret_cast<jlong>(shader);
}
///////////////////////////////////////////////////////////////////////////////////////////////
static jlong RuntimeShader_createShaderFactory(JNIEnv* env, jobject, jstring sksl) {
ScopedUtfChars strSksl(env, sksl);
- sk_sp<SkRuntimeEffect> effect = std::get<0>(SkRuntimeEffect::Make(SkString(strSksl.c_str())));
- ThrowIAE_IfNull(env, effect);
-
+ auto result = SkRuntimeEffect::Make(SkString(strSksl.c_str()));
+ sk_sp<SkRuntimeEffect> effect = std::get<0>(result);
+ if (!effect) {
+ const auto& err = std::get<1>(result);
+ doThrowIAE(env, err.c_str());
+ }
return reinterpret_cast<jlong>(effect.release());
}
///////////////////////////////////////////////////////////////////////////////////////////////
-static void Effect_safeUnref(SkRuntimeEffect* effect) {
- SkSafeUnref(effect);
-}
-
static jlong RuntimeShader_getNativeFinalizer(JNIEnv*, jobject) {
- return static_cast<jlong>(reinterpret_cast<uintptr_t>(&Effect_safeUnref));
+ return static_cast<jlong>(reinterpret_cast<uintptr_t>(&Shader_safeUnref));
}
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -259,6 +290,10 @@ static const JNINativeMethod gBitmapShaderMethods[] = {
{ "nativeCreate", "(JJII)J", (void*)BitmapShader_constructor },
};
+static const JNINativeMethod gBlurShaderMethods[] = {
+ { "nativeCreate", "(JFFJ)J", (void*)BlurShader_create }
+};
+
static const JNINativeMethod gLinearGradientMethods[] = {
{ "nativeCreate", "(JFFFF[J[FIJ)J", (void*)LinearGradient_create },
};
@@ -290,6 +325,8 @@ int register_android_graphics_Shader(JNIEnv* env)
NELEM(gShaderMethods));
android::RegisterMethodsOrDie(env, "android/graphics/BitmapShader", gBitmapShaderMethods,
NELEM(gBitmapShaderMethods));
+ android::RegisterMethodsOrDie(env, "android/graphics/BlurShader", gBlurShaderMethods,
+ NELEM(gBlurShaderMethods));
android::RegisterMethodsOrDie(env, "android/graphics/LinearGradient", gLinearGradientMethods,
NELEM(gLinearGradientMethods));
android::RegisterMethodsOrDie(env, "android/graphics/RadialGradient", gRadialGradientMethods,
diff --git a/libs/hwui/jni/Utils.cpp b/libs/hwui/jni/Utils.cpp
index 34fd6687d52c..ac2f5b77d23a 100644
--- a/libs/hwui/jni/Utils.cpp
+++ b/libs/hwui/jni/Utils.cpp
@@ -114,7 +114,7 @@ size_t AssetStreamAdaptor::read(void* buffer, size_t size) {
return amount;
}
-SkMemoryStream* android::CopyAssetToStream(Asset* asset) {
+sk_sp<SkData> android::CopyAssetToData(Asset* asset) {
if (NULL == asset) {
return NULL;
}
@@ -138,7 +138,7 @@ SkMemoryStream* android::CopyAssetToStream(Asset* asset) {
return NULL;
}
- return new SkMemoryStream(std::move(data));
+ return data;
}
jobject android::nullObjectReturn(const char msg[]) {
diff --git a/libs/hwui/jni/Utils.h b/libs/hwui/jni/Utils.h
index f628cc3c85ed..6cdf44d85a5a 100644
--- a/libs/hwui/jni/Utils.h
+++ b/libs/hwui/jni/Utils.h
@@ -46,12 +46,11 @@ private:
};
/**
- * Make a deep copy of the asset, and return it as a stream, or NULL if there
+ * Make a deep copy of the asset, and return it as an SkData, or NULL if there
* was an error.
- * FIXME: If we could "ref/reopen" the asset, we may not need to copy it here.
*/
-SkMemoryStream* CopyAssetToStream(Asset*);
+sk_sp<SkData> CopyAssetToData(Asset*);
/** Restore the file descriptor's offset in our destructor
*/
diff --git a/libs/hwui/jni/android_graphics_DisplayListCanvas.cpp b/libs/hwui/jni/android_graphics_DisplayListCanvas.cpp
index 54822f1f07e2..7c1422de0984 100644
--- a/libs/hwui/jni/android_graphics_DisplayListCanvas.cpp
+++ b/libs/hwui/jni/android_graphics_DisplayListCanvas.cpp
@@ -67,39 +67,7 @@ private:
JavaVM* mVm;
jobject mRunnable;
};
-
-class GlFunctorReleasedCallbackBridge : public GlFunctorLifecycleListener {
-public:
- GlFunctorReleasedCallbackBridge(JNIEnv* env, jobject javaCallback) {
- mLooper = Looper::getForThread();
- mMessage = new InvokeRunnableMessage(env, javaCallback);
- }
-
- virtual void onGlFunctorReleased(Functor* functor) override {
- mLooper->sendMessage(mMessage, 0);
- }
-
-private:
- sp<Looper> mLooper;
- sp<InvokeRunnableMessage> mMessage;
-};
-#endif
-
-// ---------------- @FastNative -----------------------------
-
-static void android_view_DisplayListCanvas_callDrawGLFunction(JNIEnv* env, jobject clazz,
- jlong canvasPtr, jlong functorPtr, jobject releasedCallback) {
-#ifdef __ANDROID__ // Layoutlib does not support GL
- Canvas* canvas = reinterpret_cast<Canvas*>(canvasPtr);
- Functor* functor = reinterpret_cast<Functor*>(functorPtr);
- sp<GlFunctorReleasedCallbackBridge> bridge;
- if (releasedCallback) {
- bridge = new GlFunctorReleasedCallbackBridge(env, releasedCallback);
- }
- canvas->callDrawGLFunction(functor, bridge.get());
#endif
-}
-
// ---------------- @CriticalNative -------------------------
@@ -124,10 +92,10 @@ static jint android_view_DisplayListCanvas_getMaxTextureSize(CRITICAL_JNI_PARAMS
#endif
}
-static void android_view_DisplayListCanvas_insertReorderBarrier(CRITICAL_JNI_PARAMS_COMMA jlong canvasPtr,
+static void android_view_DisplayListCanvas_enableZ(CRITICAL_JNI_PARAMS_COMMA jlong canvasPtr,
jboolean reorderEnable) {
Canvas* canvas = reinterpret_cast<Canvas*>(canvasPtr);
- canvas->insertReorderBarrier(reorderEnable);
+ canvas->enableZ(reorderEnable);
}
static jlong android_view_DisplayListCanvas_finishRecording(CRITICAL_JNI_PARAMS_COMMA jlong canvasPtr) {
@@ -183,18 +151,12 @@ static void android_view_DisplayListCanvas_drawWebViewFunctor(CRITICAL_JNI_PARAM
const char* const kClassPathName = "android/graphics/RecordingCanvas";
static JNINativeMethod gMethods[] = {
-
- // ------------ @FastNative ------------------
-
- { "nCallDrawGLFunction", "(JJLjava/lang/Runnable;)V",
- (void*) android_view_DisplayListCanvas_callDrawGLFunction },
-
// ------------ @CriticalNative --------------
{ "nCreateDisplayListCanvas", "(JII)J", (void*) android_view_DisplayListCanvas_createDisplayListCanvas },
{ "nResetDisplayListCanvas", "(JJII)V", (void*) android_view_DisplayListCanvas_resetDisplayListCanvas },
{ "nGetMaximumTextureWidth", "()I", (void*) android_view_DisplayListCanvas_getMaxTextureSize },
{ "nGetMaximumTextureHeight", "()I", (void*) android_view_DisplayListCanvas_getMaxTextureSize },
- { "nInsertReorderBarrier", "(JZ)V", (void*) android_view_DisplayListCanvas_insertReorderBarrier },
+ { "nEnableZ", "(JZ)V", (void*) android_view_DisplayListCanvas_enableZ },
{ "nFinishRecording", "(J)J", (void*) android_view_DisplayListCanvas_finishRecording },
{ "nDrawRenderNode", "(JJ)V", (void*) android_view_DisplayListCanvas_drawRenderNode },
{ "nDrawTextureLayer", "(JJ)V", (void*) android_view_DisplayListCanvas_drawTextureLayer },
diff --git a/libs/hwui/jni/android_graphics_HardwareRenderer.cpp b/libs/hwui/jni/android_graphics_HardwareRenderer.cpp
index 9815e85db880..e817ca744c58 100644
--- a/libs/hwui/jni/android_graphics_HardwareRenderer.cpp
+++ b/libs/hwui/jni/android_graphics_HardwareRenderer.cpp
@@ -143,11 +143,10 @@ static jlong android_view_ThreadedRenderer_createRootRenderNode(JNIEnv* env, job
}
static jlong android_view_ThreadedRenderer_createProxy(JNIEnv* env, jobject clazz,
- jboolean translucent, jboolean isWideGamut, jlong rootRenderNodePtr) {
+ jboolean translucent, jlong rootRenderNodePtr) {
RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootRenderNodePtr);
ContextFactoryImpl factory(rootRenderNode);
RenderProxy* proxy = new RenderProxy(translucent, rootRenderNode, &factory);
- proxy->setWideGamut(isWideGamut);
return (jlong) proxy;
}
@@ -185,7 +184,9 @@ static void android_view_ThreadedRenderer_setSurface(JNIEnv* env, jobject clazz,
proxy->setSwapBehavior(SwapBehavior::kSwap_discardBuffer);
}
proxy->setSurface(window, enableTimeout);
- ANativeWindow_release(window);
+ if (window) {
+ ANativeWindow_release(window);
+ }
}
static jboolean android_view_ThreadedRenderer_pause(JNIEnv* env, jobject clazz,
@@ -218,10 +219,15 @@ static void android_view_ThreadedRenderer_setOpaque(JNIEnv* env, jobject clazz,
proxy->setOpaque(opaque);
}
-static void android_view_ThreadedRenderer_setWideGamut(JNIEnv* env, jobject clazz,
- jlong proxyPtr, jboolean wideGamut) {
+static void android_view_ThreadedRenderer_setColorMode(JNIEnv* env, jobject clazz,
+ jlong proxyPtr, jint colorMode) {
RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
- proxy->setWideGamut(wideGamut);
+ proxy->setColorMode(static_cast<ColorMode>(colorMode));
+}
+
+static void android_view_ThreadedRenderer_setSdrWhitePoint(JNIEnv* env, jobject clazz,
+ jlong proxyPtr, jfloat sdrWhitePoint) {
+ Properties::defaultSdrWhitePoint = sdrWhitePoint;
}
static int android_view_ThreadedRenderer_syncAndDrawFrame(JNIEnv* env, jobject clazz,
@@ -256,12 +262,6 @@ static void android_view_ThreadedRenderer_registerVectorDrawableAnimator(JNIEnv*
rootRenderNode->addVectorDrawableAnimator(animator);
}
-static void android_view_ThreadedRenderer_invokeFunctor(JNIEnv* env, jobject clazz,
- jlong functorPtr, jboolean waitForCompletion) {
- Functor* functor = reinterpret_cast<Functor*>(functorPtr);
- RenderProxy::invokeFunctor(functor, waitForCompletion);
-}
-
static jlong android_view_ThreadedRenderer_createTextureLayer(JNIEnv* env, jobject clazz,
jlong proxyPtr) {
RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
@@ -593,6 +593,28 @@ static void android_view_ThreadedRenderer_preload(JNIEnv*, jclass) {
RenderProxy::preload();
}
+// Plumbs the display density down to DeviceInfo.
+static void android_view_ThreadedRenderer_setDisplayDensityDpi(JNIEnv*, jclass, jint densityDpi) {
+ // Convert from dpi to density-independent pixels.
+ const float density = densityDpi / 160.0;
+ DeviceInfo::setDensity(density);
+}
+
+static void android_view_ThreadedRenderer_initDisplayInfo(JNIEnv*, jclass, jint physicalWidth,
+ jint physicalHeight, jfloat refreshRate,
+ jfloat maxRefreshRate,
+ jint wideColorDataspace,
+ jlong appVsyncOffsetNanos,
+ jlong presentationDeadlineNanos) {
+ DeviceInfo::setWidth(physicalWidth);
+ DeviceInfo::setHeight(physicalHeight);
+ DeviceInfo::setRefreshRate(refreshRate);
+ DeviceInfo::setMaxRefreshRate(maxRefreshRate);
+ DeviceInfo::setWideColorDataspace(static_cast<ADataSpace>(wideColorDataspace));
+ DeviceInfo::setAppVsyncOffsetNanos(appVsyncOffsetNanos);
+ DeviceInfo::setPresentationDeadlineNanos(presentationDeadlineNanos);
+}
+
// ----------------------------------------------------------------------------
// HardwareRendererObserver
// ----------------------------------------------------------------------------
@@ -637,67 +659,83 @@ static void android_view_ThreadedRenderer_setupShadersDiskCache(JNIEnv* env, job
const char* const kClassPathName = "android/graphics/HardwareRenderer";
static const JNINativeMethod gMethods[] = {
- { "nRotateProcessStatsBuffer", "()V", (void*) android_view_ThreadedRenderer_rotateProcessStatsBuffer },
- { "nSetProcessStatsBuffer", "(I)V", (void*) android_view_ThreadedRenderer_setProcessStatsBuffer },
- { "nGetRenderThreadTid", "(J)I", (void*) android_view_ThreadedRenderer_getRenderThreadTid },
- { "nCreateRootRenderNode", "()J", (void*) android_view_ThreadedRenderer_createRootRenderNode },
- { "nCreateProxy", "(ZZJ)J", (void*) android_view_ThreadedRenderer_createProxy },
- { "nDeleteProxy", "(J)V", (void*) android_view_ThreadedRenderer_deleteProxy },
- { "nLoadSystemProperties", "(J)Z", (void*) android_view_ThreadedRenderer_loadSystemProperties },
- { "nSetName", "(JLjava/lang/String;)V", (void*) android_view_ThreadedRenderer_setName },
- { "nSetSurface", "(JLandroid/view/Surface;Z)V", (void*) android_view_ThreadedRenderer_setSurface },
- { "nPause", "(J)Z", (void*) android_view_ThreadedRenderer_pause },
- { "nSetStopped", "(JZ)V", (void*) android_view_ThreadedRenderer_setStopped },
- { "nSetLightAlpha", "(JFF)V", (void*) android_view_ThreadedRenderer_setLightAlpha },
- { "nSetLightGeometry", "(JFFFF)V", (void*) android_view_ThreadedRenderer_setLightGeometry },
- { "nSetOpaque", "(JZ)V", (void*) android_view_ThreadedRenderer_setOpaque },
- { "nSetWideGamut", "(JZ)V", (void*) android_view_ThreadedRenderer_setWideGamut },
- { "nSyncAndDrawFrame", "(J[JI)I", (void*) android_view_ThreadedRenderer_syncAndDrawFrame },
- { "nDestroy", "(JJ)V", (void*) android_view_ThreadedRenderer_destroy },
- { "nRegisterAnimatingRenderNode", "(JJ)V", (void*) android_view_ThreadedRenderer_registerAnimatingRenderNode },
- { "nRegisterVectorDrawableAnimator", "(JJ)V", (void*) android_view_ThreadedRenderer_registerVectorDrawableAnimator },
- { "nInvokeFunctor", "(JZ)V", (void*) android_view_ThreadedRenderer_invokeFunctor },
- { "nCreateTextureLayer", "(J)J", (void*) android_view_ThreadedRenderer_createTextureLayer },
- { "nBuildLayer", "(JJ)V", (void*) android_view_ThreadedRenderer_buildLayer },
- { "nCopyLayerInto", "(JJJ)Z", (void*) android_view_ThreadedRenderer_copyLayerInto },
- { "nPushLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_pushLayerUpdate },
- { "nCancelLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_cancelLayerUpdate },
- { "nDetachSurfaceTexture", "(JJ)V", (void*) android_view_ThreadedRenderer_detachSurfaceTexture },
- { "nDestroyHardwareResources", "(J)V", (void*) android_view_ThreadedRenderer_destroyHardwareResources },
- { "nTrimMemory", "(I)V", (void*) android_view_ThreadedRenderer_trimMemory },
- { "nOverrideProperty", "(Ljava/lang/String;Ljava/lang/String;)V", (void*) android_view_ThreadedRenderer_overrideProperty },
- { "nFence", "(J)V", (void*) android_view_ThreadedRenderer_fence },
- { "nStopDrawing", "(J)V", (void*) android_view_ThreadedRenderer_stopDrawing },
- { "nNotifyFramePending", "(J)V", (void*) android_view_ThreadedRenderer_notifyFramePending },
- { "nDumpProfileInfo", "(JLjava/io/FileDescriptor;I)V", (void*) android_view_ThreadedRenderer_dumpProfileInfo },
- { "setupShadersDiskCache", "(Ljava/lang/String;Ljava/lang/String;)V",
- (void*) android_view_ThreadedRenderer_setupShadersDiskCache },
- { "nAddRenderNode", "(JJZ)V", (void*) android_view_ThreadedRenderer_addRenderNode},
- { "nRemoveRenderNode", "(JJ)V", (void*) android_view_ThreadedRenderer_removeRenderNode},
- { "nDrawRenderNode", "(JJ)V", (void*) android_view_ThreadedRendererd_drawRenderNode},
- { "nSetContentDrawBounds", "(JIIII)V", (void*)android_view_ThreadedRenderer_setContentDrawBounds},
- { "nSetPictureCaptureCallback", "(JLandroid/graphics/HardwareRenderer$PictureCapturedCallback;)V",
- (void*) android_view_ThreadedRenderer_setPictureCapturedCallbackJNI },
- { "nSetFrameCallback", "(JLandroid/graphics/HardwareRenderer$FrameDrawingCallback;)V",
- (void*)android_view_ThreadedRenderer_setFrameCallback},
- { "nSetFrameCompleteCallback", "(JLandroid/graphics/HardwareRenderer$FrameCompleteCallback;)V",
- (void*)android_view_ThreadedRenderer_setFrameCompleteCallback },
- { "nAddObserver", "(JJ)V", (void*)android_view_ThreadedRenderer_addObserver },
- { "nRemoveObserver", "(JJ)V", (void*)android_view_ThreadedRenderer_removeObserver },
- { "nCopySurfaceInto", "(Landroid/view/Surface;IIIIJ)I",
- (void*)android_view_ThreadedRenderer_copySurfaceInto },
- { "nCreateHardwareBitmap", "(JII)Landroid/graphics/Bitmap;",
- (void*)android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode },
- { "disableVsync", "()V", (void*)android_view_ThreadedRenderer_disableVsync },
- { "nSetHighContrastText", "(Z)V", (void*)android_view_ThreadedRenderer_setHighContrastText },
- { "nHackySetRTAnimationsEnabled", "(Z)V",
- (void*)android_view_ThreadedRenderer_hackySetRTAnimationsEnabled },
- { "nSetDebuggingEnabled", "(Z)V", (void*)android_view_ThreadedRenderer_setDebuggingEnabled },
- { "nSetIsolatedProcess", "(Z)V", (void*)android_view_ThreadedRenderer_setIsolatedProcess },
- { "nSetContextPriority", "(I)V", (void*)android_view_ThreadedRenderer_setContextPriority },
- { "nAllocateBuffers", "(J)V", (void*)android_view_ThreadedRenderer_allocateBuffers },
- { "nSetForceDark", "(JZ)V", (void*)android_view_ThreadedRenderer_setForceDark },
- { "preload", "()V", (void*)android_view_ThreadedRenderer_preload },
+ {"nRotateProcessStatsBuffer", "()V",
+ (void*)android_view_ThreadedRenderer_rotateProcessStatsBuffer},
+ {"nSetProcessStatsBuffer", "(I)V",
+ (void*)android_view_ThreadedRenderer_setProcessStatsBuffer},
+ {"nGetRenderThreadTid", "(J)I", (void*)android_view_ThreadedRenderer_getRenderThreadTid},
+ {"nCreateRootRenderNode", "()J", (void*)android_view_ThreadedRenderer_createRootRenderNode},
+ {"nCreateProxy", "(ZJ)J", (void*)android_view_ThreadedRenderer_createProxy},
+ {"nDeleteProxy", "(J)V", (void*)android_view_ThreadedRenderer_deleteProxy},
+ {"nLoadSystemProperties", "(J)Z",
+ (void*)android_view_ThreadedRenderer_loadSystemProperties},
+ {"nSetName", "(JLjava/lang/String;)V", (void*)android_view_ThreadedRenderer_setName},
+ {"nSetSurface", "(JLandroid/view/Surface;Z)V",
+ (void*)android_view_ThreadedRenderer_setSurface},
+ {"nPause", "(J)Z", (void*)android_view_ThreadedRenderer_pause},
+ {"nSetStopped", "(JZ)V", (void*)android_view_ThreadedRenderer_setStopped},
+ {"nSetLightAlpha", "(JFF)V", (void*)android_view_ThreadedRenderer_setLightAlpha},
+ {"nSetLightGeometry", "(JFFFF)V", (void*)android_view_ThreadedRenderer_setLightGeometry},
+ {"nSetOpaque", "(JZ)V", (void*)android_view_ThreadedRenderer_setOpaque},
+ {"nSetColorMode", "(JI)V", (void*)android_view_ThreadedRenderer_setColorMode},
+ {"nSetSdrWhitePoint", "(JF)V", (void*)android_view_ThreadedRenderer_setSdrWhitePoint},
+ {"nSyncAndDrawFrame", "(J[JI)I", (void*)android_view_ThreadedRenderer_syncAndDrawFrame},
+ {"nDestroy", "(JJ)V", (void*)android_view_ThreadedRenderer_destroy},
+ {"nRegisterAnimatingRenderNode", "(JJ)V",
+ (void*)android_view_ThreadedRenderer_registerAnimatingRenderNode},
+ {"nRegisterVectorDrawableAnimator", "(JJ)V",
+ (void*)android_view_ThreadedRenderer_registerVectorDrawableAnimator},
+ {"nCreateTextureLayer", "(J)J", (void*)android_view_ThreadedRenderer_createTextureLayer},
+ {"nBuildLayer", "(JJ)V", (void*)android_view_ThreadedRenderer_buildLayer},
+ {"nCopyLayerInto", "(JJJ)Z", (void*)android_view_ThreadedRenderer_copyLayerInto},
+ {"nPushLayerUpdate", "(JJ)V", (void*)android_view_ThreadedRenderer_pushLayerUpdate},
+ {"nCancelLayerUpdate", "(JJ)V", (void*)android_view_ThreadedRenderer_cancelLayerUpdate},
+ {"nDetachSurfaceTexture", "(JJ)V",
+ (void*)android_view_ThreadedRenderer_detachSurfaceTexture},
+ {"nDestroyHardwareResources", "(J)V",
+ (void*)android_view_ThreadedRenderer_destroyHardwareResources},
+ {"nTrimMemory", "(I)V", (void*)android_view_ThreadedRenderer_trimMemory},
+ {"nOverrideProperty", "(Ljava/lang/String;Ljava/lang/String;)V",
+ (void*)android_view_ThreadedRenderer_overrideProperty},
+ {"nFence", "(J)V", (void*)android_view_ThreadedRenderer_fence},
+ {"nStopDrawing", "(J)V", (void*)android_view_ThreadedRenderer_stopDrawing},
+ {"nNotifyFramePending", "(J)V", (void*)android_view_ThreadedRenderer_notifyFramePending},
+ {"nDumpProfileInfo", "(JLjava/io/FileDescriptor;I)V",
+ (void*)android_view_ThreadedRenderer_dumpProfileInfo},
+ {"setupShadersDiskCache", "(Ljava/lang/String;Ljava/lang/String;)V",
+ (void*)android_view_ThreadedRenderer_setupShadersDiskCache},
+ {"nAddRenderNode", "(JJZ)V", (void*)android_view_ThreadedRenderer_addRenderNode},
+ {"nRemoveRenderNode", "(JJ)V", (void*)android_view_ThreadedRenderer_removeRenderNode},
+ {"nDrawRenderNode", "(JJ)V", (void*)android_view_ThreadedRendererd_drawRenderNode},
+ {"nSetContentDrawBounds", "(JIIII)V",
+ (void*)android_view_ThreadedRenderer_setContentDrawBounds},
+ {"nSetPictureCaptureCallback",
+ "(JLandroid/graphics/HardwareRenderer$PictureCapturedCallback;)V",
+ (void*)android_view_ThreadedRenderer_setPictureCapturedCallbackJNI},
+ {"nSetFrameCallback", "(JLandroid/graphics/HardwareRenderer$FrameDrawingCallback;)V",
+ (void*)android_view_ThreadedRenderer_setFrameCallback},
+ {"nSetFrameCompleteCallback",
+ "(JLandroid/graphics/HardwareRenderer$FrameCompleteCallback;)V",
+ (void*)android_view_ThreadedRenderer_setFrameCompleteCallback},
+ {"nAddObserver", "(JJ)V", (void*)android_view_ThreadedRenderer_addObserver},
+ {"nRemoveObserver", "(JJ)V", (void*)android_view_ThreadedRenderer_removeObserver},
+ {"nCopySurfaceInto", "(Landroid/view/Surface;IIIIJ)I",
+ (void*)android_view_ThreadedRenderer_copySurfaceInto},
+ {"nCreateHardwareBitmap", "(JII)Landroid/graphics/Bitmap;",
+ (void*)android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode},
+ {"disableVsync", "()V", (void*)android_view_ThreadedRenderer_disableVsync},
+ {"nSetHighContrastText", "(Z)V", (void*)android_view_ThreadedRenderer_setHighContrastText},
+ {"nHackySetRTAnimationsEnabled", "(Z)V",
+ (void*)android_view_ThreadedRenderer_hackySetRTAnimationsEnabled},
+ {"nSetDebuggingEnabled", "(Z)V", (void*)android_view_ThreadedRenderer_setDebuggingEnabled},
+ {"nSetIsolatedProcess", "(Z)V", (void*)android_view_ThreadedRenderer_setIsolatedProcess},
+ {"nSetContextPriority", "(I)V", (void*)android_view_ThreadedRenderer_setContextPriority},
+ {"nAllocateBuffers", "(J)V", (void*)android_view_ThreadedRenderer_allocateBuffers},
+ {"nSetForceDark", "(JZ)V", (void*)android_view_ThreadedRenderer_setForceDark},
+ {"nSetDisplayDensityDpi", "(I)V",
+ (void*)android_view_ThreadedRenderer_setDisplayDensityDpi},
+ {"nInitDisplayInfo", "(IIFFIJJ)V", (void*)android_view_ThreadedRenderer_initDisplayInfo},
+ {"preload", "()V", (void*)android_view_ThreadedRenderer_preload},
};
static JavaVM* mJvm = nullptr;
diff --git a/libs/hwui/jni/android_graphics_TextureLayer.cpp b/libs/hwui/jni/android_graphics_TextureLayer.cpp
index bd20269d3751..4dbb24ce4347 100644
--- a/libs/hwui/jni/android_graphics_TextureLayer.cpp
+++ b/libs/hwui/jni/android_graphics_TextureLayer.cpp
@@ -67,7 +67,7 @@ static void TextureLayer_updateSurfaceTexture(JNIEnv* env, jobject clazz,
// JNI Glue
// ----------------------------------------------------------------------------
-const char* const kClassPathName = "android/view/TextureLayer";
+const char* const kClassPathName = "android/graphics/TextureLayer";
static const JNINativeMethod gMethods[] = {
{ "nPrepare", "(JIIZ)Z", (void*) TextureLayer_prepare },
@@ -78,7 +78,7 @@ static const JNINativeMethod gMethods[] = {
{ "nUpdateSurfaceTexture", "(J)V", (void*) TextureLayer_updateSurfaceTexture },
};
-int register_android_view_TextureLayer(JNIEnv* env) {
+int register_android_graphics_TextureLayer(JNIEnv* env) {
return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
}
diff --git a/libs/hwui/jni/android_graphics_drawable_VectorDrawable.cpp b/libs/hwui/jni/android_graphics_drawable_VectorDrawable.cpp
index 9cffceb308c8..a1adcb30e80d 100644
--- a/libs/hwui/jni/android_graphics_drawable_VectorDrawable.cpp
+++ b/libs/hwui/jni/android_graphics_drawable_VectorDrawable.cpp
@@ -143,13 +143,13 @@ static void updateFullPathPropertiesAndStrokeStyles(JNIEnv*, jobject, jlong full
static void updateFullPathFillGradient(JNIEnv*, jobject, jlong pathPtr, jlong fillGradientPtr) {
VectorDrawable::FullPath* path = reinterpret_cast<VectorDrawable::FullPath*>(pathPtr);
- SkShader* fillShader = reinterpret_cast<SkShader*>(fillGradientPtr);
+ auto* fillShader = reinterpret_cast<Shader*>(fillGradientPtr);
path->mutateStagingProperties()->setFillGradient(fillShader);
}
static void updateFullPathStrokeGradient(JNIEnv*, jobject, jlong pathPtr, jlong strokeGradientPtr) {
VectorDrawable::FullPath* path = reinterpret_cast<VectorDrawable::FullPath*>(pathPtr);
- SkShader* strokeShader = reinterpret_cast<SkShader*>(strokeGradientPtr);
+ auto* strokeShader = reinterpret_cast<Shader*>(strokeGradientPtr);
path->mutateStagingProperties()->setStrokeGradient(strokeShader);
}
diff --git a/libs/hwui/jni/fonts/Font.cpp b/libs/hwui/jni/fonts/Font.cpp
index 5714cd1d0390..996cdceed8a7 100644
--- a/libs/hwui/jni/fonts/Font.cpp
+++ b/libs/hwui/jni/fonts/Font.cpp
@@ -93,19 +93,19 @@ static jlong Font_Builder_build(JNIEnv* env, jobject clazz, jlong builderPtr, jo
sk_sp<SkData> data(SkData::MakeWithProc(fontPtr, fontSize,
release_global_ref, reinterpret_cast<void*>(fontRef)));
- FatVector<SkFontArguments::Axis, 2> skiaAxes;
+ FatVector<SkFontArguments::VariationPosition::Coordinate, 2> skVariation;
for (const auto& axis : builder->axes) {
- skiaAxes.emplace_back(SkFontArguments::Axis{axis.axisTag, axis.value});
+ skVariation.push_back({axis.axisTag, axis.value});
}
std::unique_ptr<SkStreamAsset> fontData(new SkMemoryStream(std::move(data)));
- SkFontArguments params;
- params.setCollectionIndex(ttcIndex);
- params.setAxes(skiaAxes.data(), skiaAxes.size());
+ SkFontArguments args;
+ args.setCollectionIndex(ttcIndex);
+ args.setVariationDesignPosition({skVariation.data(), static_cast<int>(skVariation.size())});
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
- sk_sp<SkTypeface> face(fm->makeFromStream(std::move(fontData), params));
+ sk_sp<SkTypeface> face(fm->makeFromStream(std::move(fontData), args));
if (face == nullptr) {
jniThrowException(env, "java/lang/IllegalArgumentException",
"Failed to create internal object. maybe invalid font data.");
diff --git a/libs/hwui/libhwui.map.txt b/libs/hwui/libhwui.map.txt
new file mode 100644
index 000000000000..73de0d12a60b
--- /dev/null
+++ b/libs/hwui/libhwui.map.txt
@@ -0,0 +1,70 @@
+LIBHWUI {
+ global:
+ /* listing of all C APIs to be exposed by libhwui to consumers outside of the module */
+ ABitmap_getInfoFromJava;
+ ABitmap_acquireBitmapFromJava;
+ ABitmap_copy;
+ ABitmap_acquireRef;
+ ABitmap_releaseRef;
+ ABitmap_getInfo;
+ ABitmap_getDataSpace;
+ ABitmap_getPixels;
+ ABitmap_notifyPixelsChanged;
+ ABitmapConfig_getFormatFromConfig;
+ ABitmapConfig_getConfigFromFormat;
+ ABitmap_compress;
+ ABitmap_getHardwareBuffer;
+ ACanvas_isSupportedPixelFormat;
+ ACanvas_getNativeHandleFromJava;
+ ACanvas_createCanvas;
+ ACanvas_destroyCanvas;
+ ACanvas_setBuffer;
+ ACanvas_clipRect;
+ ACanvas_clipOutRect;
+ ACanvas_drawRect;
+ ACanvas_drawBitmap;
+ init_android_graphics;
+ register_android_graphics_classes;
+ register_android_graphics_GraphicsStatsService;
+ zygote_preload_graphics;
+ AMatrix_getContents;
+ APaint_createPaint;
+ APaint_destroyPaint;
+ APaint_setBlendMode;
+ ARegionIterator_acquireIterator;
+ ARegionIterator_releaseIterator;
+ ARegionIterator_isComplex;
+ ARegionIterator_isDone;
+ ARegionIterator_next;
+ ARegionIterator_getRect;
+ ARegionIterator_getTotalBounds;
+ ARenderThread_dumpGraphicsMemory;
+ local:
+ *;
+};
+
+LIBHWUI_PLATFORM {
+ global:
+ extern "C++" {
+ /* required by libwebviewchromium_plat_support */
+ android::uirenderer::ColorSpaceToADataSpace*;
+ android::uirenderer::WebViewFunctor_*;
+ GraphicsJNI::getNativeCanvas*;
+ SkCanvasStateUtils::ReleaseCanvasState*;
+ SkColorSpace::toXYZD50*;
+ SkColorSpace::transferFn*;
+ /* required by libjnigraphics */
+ android::ImageDecoder::*;
+ android::uirenderer::DataSpaceToColorSpace*;
+ android::uirenderer::ColorSpaceToADataSpace*;
+ getMimeType*;
+ SkAndroidCodec::*;
+ SkCodec::MakeFromStream*;
+ SkColorInfo::*;
+ SkFILEStream::SkFILEStream*;
+ SkImageInfo::*;
+ SkMemoryStream::SkMemoryStream*;
+ };
+ local:
+ *;
+};
diff --git a/libs/hwui/pipeline/skia/FunctorDrawable.h b/libs/hwui/pipeline/skia/FunctorDrawable.h
index cf2f93b95e71..988a896b6267 100644
--- a/libs/hwui/pipeline/skia/FunctorDrawable.h
+++ b/libs/hwui/pipeline/skia/FunctorDrawable.h
@@ -16,8 +16,6 @@
#pragma once
-#include "GlFunctorLifecycleListener.h"
-
#include <SkCanvas.h>
#include <SkDrawable.h>
@@ -36,44 +34,21 @@ namespace skiapipeline {
*/
class FunctorDrawable : public SkDrawable {
public:
- FunctorDrawable(Functor* functor, GlFunctorLifecycleListener* listener, SkCanvas* canvas)
- : mBounds(canvas->getLocalClipBounds())
- , mAnyFunctor(std::in_place_type<LegacyFunctor>, functor, listener) {}
-
FunctorDrawable(int functor, SkCanvas* canvas)
: mBounds(canvas->getLocalClipBounds())
- , mAnyFunctor(std::in_place_type<NewFunctor>, functor) {}
+ , mWebViewHandle(WebViewFunctorManager::instance().handleFor(functor)) {}
virtual ~FunctorDrawable() {}
virtual void syncFunctor(const WebViewSyncData& data) const {
- if (mAnyFunctor.index() == 0) {
- std::get<0>(mAnyFunctor).handle->sync(data);
- } else {
- (*(std::get<1>(mAnyFunctor).functor))(DrawGlInfo::kModeSync, nullptr);
- }
+ mWebViewHandle->sync(data);
}
protected:
virtual SkRect onGetBounds() override { return mBounds; }
const SkRect mBounds;
-
- struct LegacyFunctor {
- explicit LegacyFunctor(Functor* functor, GlFunctorLifecycleListener* listener)
- : functor(functor), listener(listener) {}
- Functor* functor;
- sp<GlFunctorLifecycleListener> listener;
- };
-
- struct NewFunctor {
- explicit NewFunctor(int functor) {
- handle = WebViewFunctorManager::instance().handleFor(functor);
- }
- sp<WebViewFunctor::Handle> handle;
- };
-
- std::variant<NewFunctor, LegacyFunctor> mAnyFunctor;
+ sp<WebViewFunctor::Handle> mWebViewHandle;
};
} // namespace skiapipeline
diff --git a/libs/hwui/pipeline/skia/GLFunctorDrawable.cpp b/libs/hwui/pipeline/skia/GLFunctorDrawable.cpp
index 8f67f97fb4bc..dd0fc695c246 100644
--- a/libs/hwui/pipeline/skia/GLFunctorDrawable.cpp
+++ b/libs/hwui/pipeline/skia/GLFunctorDrawable.cpp
@@ -15,10 +15,9 @@
*/
#include "GLFunctorDrawable.h"
-#include <GrContext.h>
+#include <GrDirectContext.h>
#include <private/hwui/DrawGlInfo.h>
#include "FunctorDrawable.h"
-#include "GlFunctorLifecycleListener.h"
#include "GrBackendSurface.h"
#include "GrRenderTarget.h"
#include "GrRenderTargetContext.h"
@@ -26,20 +25,12 @@
#include "SkAndroidFrameworkUtils.h"
#include "SkClipStack.h"
#include "SkRect.h"
-#include "include/private/SkM44.h"
+#include "SkM44.h"
namespace android {
namespace uirenderer {
namespace skiapipeline {
-GLFunctorDrawable::~GLFunctorDrawable() {
- if (auto lp = std::get_if<LegacyFunctor>(&mAnyFunctor)) {
- if (lp->listener) {
- lp->listener->onGlFunctorReleased(lp->functor);
- }
- }
-}
-
static void setScissor(int viewportHeight, const SkIRect& clip) {
SkASSERT(!clip.isEmpty());
// transform to Y-flipped GL space, and prevent negatives
@@ -85,7 +76,7 @@ void GLFunctorDrawable::onDraw(SkCanvas* canvas) {
SkIRect surfaceBounds = canvas->internal_private_getTopLayerBounds();
SkIRect clipBounds = canvas->getDeviceClipBounds();
- SkM44 mat4(canvas->experimental_getLocalToDevice());
+ SkM44 mat4(canvas->getLocalToDevice());
SkRegion clipRegion;
canvas->temporary_internal_getRgnClip(&clipRegion);
@@ -186,11 +177,7 @@ void GLFunctorDrawable::onDraw(SkCanvas* canvas) {
setScissor(info.height, clipRegion.getBounds());
}
- if (mAnyFunctor.index() == 0) {
- std::get<0>(mAnyFunctor).handle->drawGl(info);
- } else {
- (*(std::get<1>(mAnyFunctor).functor))(DrawGlInfo::kModeDraw, &info);
- }
+ mWebViewHandle->drawGl(info);
if (clearStencilAfterFunctor) {
// clear stencil buffer as it may be used by Skia
diff --git a/libs/hwui/pipeline/skia/GLFunctorDrawable.h b/libs/hwui/pipeline/skia/GLFunctorDrawable.h
index 2ea4f67428bc..4092e8dfa3a5 100644
--- a/libs/hwui/pipeline/skia/GLFunctorDrawable.h
+++ b/libs/hwui/pipeline/skia/GLFunctorDrawable.h
@@ -33,7 +33,7 @@ class GLFunctorDrawable : public FunctorDrawable {
public:
using FunctorDrawable::FunctorDrawable;
- virtual ~GLFunctorDrawable();
+ virtual ~GLFunctorDrawable() {}
protected:
void onDraw(SkCanvas* canvas) override;
diff --git a/libs/hwui/pipeline/skia/LayerDrawable.cpp b/libs/hwui/pipeline/skia/LayerDrawable.cpp
index f839213e9007..f95f347cffaf 100644
--- a/libs/hwui/pipeline/skia/LayerDrawable.cpp
+++ b/libs/hwui/pipeline/skia/LayerDrawable.cpp
@@ -29,7 +29,7 @@ namespace skiapipeline {
void LayerDrawable::onDraw(SkCanvas* canvas) {
Layer* layer = mLayerUpdater->backingLayer();
if (layer) {
- DrawLayer(canvas->getGrContext(), canvas, layer, nullptr, nullptr, true);
+ DrawLayer(canvas->recordingContext(), canvas, layer, nullptr, nullptr, true);
}
}
@@ -67,8 +67,12 @@ static bool shouldFilterRect(const SkMatrix& matrix, const SkRect& srcRect, cons
isIntegerAligned(dstDevRect.y()));
}
-bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer,
- const SkRect* srcRect, const SkRect* dstRect,
+// TODO: Context arg probably doesn't belong here – do debug check at callsite instead.
+bool LayerDrawable::DrawLayer(GrRecordingContext* context,
+ SkCanvas* canvas,
+ Layer* layer,
+ const SkRect* srcRect,
+ const SkRect* dstRect,
bool useLayerTransform) {
if (context == nullptr) {
SkDEBUGF(("Attempting to draw LayerDrawable into an unsupported surface"));
diff --git a/libs/hwui/pipeline/skia/LayerDrawable.h b/libs/hwui/pipeline/skia/LayerDrawable.h
index 7cd515ae9fcb..ffbb480023ac 100644
--- a/libs/hwui/pipeline/skia/LayerDrawable.h
+++ b/libs/hwui/pipeline/skia/LayerDrawable.h
@@ -32,8 +32,12 @@ class LayerDrawable : public SkDrawable {
public:
explicit LayerDrawable(DeferredLayerUpdater* layerUpdater) : mLayerUpdater(layerUpdater) {}
- static bool DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer, const SkRect* srcRect,
- const SkRect* dstRect, bool useLayerTransform);
+ static bool DrawLayer(GrRecordingContext* context,
+ SkCanvas* canvas,
+ Layer* layer,
+ const SkRect* srcRect,
+ const SkRect* dstRect,
+ bool useLayerTransform);
protected:
virtual SkRect onGetBounds() override {
diff --git a/libs/hwui/pipeline/skia/ShaderCache.h b/libs/hwui/pipeline/skia/ShaderCache.h
index 0898017d52a1..5b8e668a56f4 100644
--- a/libs/hwui/pipeline/skia/ShaderCache.h
+++ b/libs/hwui/pipeline/skia/ShaderCache.h
@@ -37,7 +37,7 @@ public:
* "get" returns a pointer to the singleton ShaderCache object. This
* singleton object will never be destroyed.
*/
- ANDROID_API static ShaderCache& get();
+ static ShaderCache& get();
/**
* initShaderDiskCache" loads the serialized cache contents from disk,
diff --git a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
index 24a6228242a5..389fe7eed7c7 100644
--- a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
+++ b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
@@ -87,6 +87,8 @@ bool SkiaOpenGLPipeline::draw(const Frame& frame, const SkRect& screenDirty, con
// Note: The default preference of pixel format is RGBA_8888, when other
// pixel format is available, we should branch out and do more check.
fboInfo.fFormat = GL_RGBA8;
+ } else if (colorType == kRGBA_1010102_SkColorType) {
+ fboInfo.fFormat = GL_RGB10_A2;
} else {
LOG_ALWAYS_FATAL("Unsupported color type.");
}
diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.cpp b/libs/hwui/pipeline/skia/SkiaPipeline.cpp
index 5088494d6a07..6dd36981e8aa 100644
--- a/libs/hwui/pipeline/skia/SkiaPipeline.cpp
+++ b/libs/hwui/pipeline/skia/SkiaPipeline.cpp
@@ -35,6 +35,7 @@
#include "VectorDrawable.h"
#include "thread/CommonPool.h"
#include "tools/SkSharingProc.h"
+#include "utils/Color.h"
#include "utils/String8.h"
#include "utils/TraceUtils.h"
@@ -145,7 +146,7 @@ void SkiaPipeline::renderLayersImpl(const LayerUpdateQueue& layers, bool opaque)
if (cachedContext.get() != currentContext) {
if (cachedContext.get()) {
ATRACE_NAME("flush layers (context changed)");
- cachedContext->flush();
+ cachedContext->flushAndSubmit();
}
cachedContext.reset(SkSafeRef(currentContext));
}
@@ -153,7 +154,7 @@ void SkiaPipeline::renderLayersImpl(const LayerUpdateQueue& layers, bool opaque)
if (cachedContext.get()) {
ATRACE_NAME("flush layers");
- cachedContext->flush();
+ cachedContext->flushAndSubmit();
}
}
@@ -450,7 +451,7 @@ void SkiaPipeline::renderFrame(const LayerUpdateQueue& layers, const SkRect& cli
}
ATRACE_NAME("flush commands");
- surface->getCanvas()->flush();
+ surface->flushAndSubmit();
Properties::skpCaptureEnabled = previousSkpEnabled;
}
@@ -587,14 +588,23 @@ void SkiaPipeline::dumpResourceCacheUsage() const {
void SkiaPipeline::setSurfaceColorProperties(ColorMode colorMode) {
mColorMode = colorMode;
- if (colorMode == ColorMode::SRGB) {
- mSurfaceColorType = SkColorType::kN32_SkColorType;
- mSurfaceColorSpace = SkColorSpace::MakeSRGB();
- } else if (colorMode == ColorMode::WideColorGamut) {
- mSurfaceColorType = DeviceInfo::get()->getWideColorType();
- mSurfaceColorSpace = DeviceInfo::get()->getWideColorSpace();
- } else {
- LOG_ALWAYS_FATAL("Unreachable: unsupported color mode.");
+ switch (colorMode) {
+ case ColorMode::Default:
+ mSurfaceColorType = SkColorType::kN32_SkColorType;
+ mSurfaceColorSpace = SkColorSpace::MakeSRGB();
+ break;
+ case ColorMode::WideColorGamut:
+ mSurfaceColorType = DeviceInfo::get()->getWideColorType();
+ mSurfaceColorSpace = DeviceInfo::get()->getWideColorSpace();
+ break;
+ case ColorMode::Hdr:
+ mSurfaceColorType = SkColorType::kRGBA_F16_SkColorType;
+ mSurfaceColorSpace = SkColorSpace::MakeRGB(GetPQSkTransferFunction(), SkNamedGamut::kRec2020);
+ break;
+ case ColorMode::Hdr10:
+ mSurfaceColorType = SkColorType::kRGBA_1010102_SkColorType;
+ mSurfaceColorSpace = SkColorSpace::MakeRGB(GetPQSkTransferFunction(), SkNamedGamut::kRec2020);
+ break;
}
}
diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.h b/libs/hwui/pipeline/skia/SkiaPipeline.h
index 8341164edc19..100bfb6b159a 100644
--- a/libs/hwui/pipeline/skia/SkiaPipeline.h
+++ b/libs/hwui/pipeline/skia/SkiaPipeline.h
@@ -50,7 +50,7 @@ public:
bool createOrUpdateLayer(RenderNode* node, const DamageAccumulator& damageAccumulator,
ErrorHandler* errorHandler) override;
- void setSurfaceColorProperties(renderthread::ColorMode colorMode) override;
+ void setSurfaceColorProperties(ColorMode colorMode) override;
SkColorType getSurfaceColorType() const override { return mSurfaceColorType; }
sk_sp<SkColorSpace> getSurfaceColorSpace() override { return mSurfaceColorSpace; }
@@ -76,7 +76,7 @@ protected:
renderthread::RenderThread& mRenderThread;
- renderthread::ColorMode mColorMode = renderthread::ColorMode::SRGB;
+ ColorMode mColorMode = ColorMode::Default;
SkColorType mSurfaceColorType;
sk_sp<SkColorSpace> mSurfaceColorSpace;
diff --git a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
index d67cf8c9c73f..e292cbdd101f 100644
--- a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
+++ b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
@@ -57,7 +57,7 @@ void SkiaRecordingCanvas::initDisplayList(uirenderer::RenderNode* renderNode, in
uirenderer::DisplayList* SkiaRecordingCanvas::finishRecording() {
// close any existing chunks if necessary
- insertReorderBarrier(false);
+ enableZ(false);
mRecorder.restoreToCount(1);
return mDisplayList.release();
}
@@ -85,8 +85,8 @@ void SkiaRecordingCanvas::drawCircle(uirenderer::CanvasPropertyPrimitive* x,
drawDrawable(mDisplayList->allocateDrawable<AnimatedCircle>(x, y, radius, paint));
}
-void SkiaRecordingCanvas::insertReorderBarrier(bool enableReorder) {
- if (mCurrentBarrier && enableReorder) {
+void SkiaRecordingCanvas::enableZ(bool enableZ) {
+ if (mCurrentBarrier && enableZ) {
// Already in a re-order section, nothing to do
return;
}
@@ -98,7 +98,7 @@ void SkiaRecordingCanvas::insertReorderBarrier(bool enableReorder) {
mCurrentBarrier = nullptr;
drawDrawable(drawable);
}
- if (enableReorder) {
+ if (enableZ) {
mCurrentBarrier =
mDisplayList->allocateDrawable<StartReorderBarrierDrawable>(mDisplayList.get());
drawDrawable(mCurrentBarrier);
@@ -132,23 +132,6 @@ void SkiaRecordingCanvas::drawRenderNode(uirenderer::RenderNode* renderNode) {
}
}
-
-void SkiaRecordingCanvas::callDrawGLFunction(Functor* functor,
- uirenderer::GlFunctorLifecycleListener* listener) {
-#ifdef __ANDROID__ // Layoutlib does not support GL, Vulcan etc.
- FunctorDrawable* functorDrawable;
- if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaVulkan) {
- functorDrawable = mDisplayList->allocateDrawable<VkInteropFunctorDrawable>(
- functor, listener, asSkCanvas());
- } else {
- functorDrawable =
- mDisplayList->allocateDrawable<GLFunctorDrawable>(functor, listener, asSkCanvas());
- }
- mDisplayList->mChildFunctors.push_back(functorDrawable);
- drawDrawable(functorDrawable);
-#endif
-}
-
void SkiaRecordingCanvas::drawWebViewFunctor(int functor) {
#ifdef __ANDROID__ // Layoutlib does not support GL, Vulcan etc.
FunctorDrawable* functorDrawable;
diff --git a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.h b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.h
index bd5274c94e75..83e934974afd 100644
--- a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.h
+++ b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.h
@@ -69,11 +69,10 @@ public:
virtual void drawVectorDrawable(VectorDrawableRoot* vectorDrawable) override;
- virtual void insertReorderBarrier(bool enableReorder) override;
+ virtual void enableZ(bool enableZ) override;
virtual void drawLayer(uirenderer::DeferredLayerUpdater* layerHandle) override;
virtual void drawRenderNode(uirenderer::RenderNode* renderNode) override;
- virtual void callDrawGLFunction(Functor* functor,
- uirenderer::GlFunctorLifecycleListener* listener) override;
+
void drawWebViewFunctor(int functor) override;
private:
diff --git a/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp b/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp
index 68f111752a4c..50b45e6eb7ec 100644
--- a/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp
+++ b/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp
@@ -20,7 +20,7 @@
#include <GrBackendDrawableInfo.h>
#include <SkAndroidFrameworkUtils.h>
#include <SkImage.h>
-#include "include/private/SkM44.h"
+#include <SkM44.h>
#include <utils/Color.h>
#include <utils/Trace.h>
#include <utils/TraceUtils.h>
@@ -121,12 +121,7 @@ std::unique_ptr<FunctorDrawable::GpuDrawHandler> VkFunctorDrawable::onSnapGpuDra
return nullptr;
}
std::unique_ptr<VkFunctorDrawHandler> draw;
- if (mAnyFunctor.index() == 0) {
- return std::make_unique<VkFunctorDrawHandler>(std::get<0>(mAnyFunctor).handle, matrix, clip,
- image_info);
- } else {
- LOG_ALWAYS_FATAL("Not implemented");
- }
+ return std::make_unique<VkFunctorDrawHandler>(mWebViewHandle, matrix, clip, image_info);
}
} // namespace skiapipeline
diff --git a/libs/hwui/pipeline/skia/VkFunctorDrawable.h b/libs/hwui/pipeline/skia/VkFunctorDrawable.h
index d3f97773b91d..fbfc6e76595e 100644
--- a/libs/hwui/pipeline/skia/VkFunctorDrawable.h
+++ b/libs/hwui/pipeline/skia/VkFunctorDrawable.h
@@ -19,7 +19,6 @@
#include "FunctorDrawable.h"
#include <SkImageInfo.h>
-#include <ui/GraphicBuffer.h>
#include <utils/RefBase.h>
namespace android {
diff --git a/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp b/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp
index 241d3708def5..403d9075dbd1 100644
--- a/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp
+++ b/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp
@@ -15,23 +15,24 @@
*/
#include "VkInteropFunctorDrawable.h"
-#include <private/hwui/DrawGlInfo.h>
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <GLES3/gl3.h>
+#include <private/hwui/DrawGlInfo.h>
#include <utils/Color.h>
+#include <utils/GLUtils.h>
#include <utils/Trace.h>
#include <utils/TraceUtils.h>
+
#include <thread>
+
#include "renderthread/EglManager.h"
#include "thread/ThreadBase.h"
#include "utils/TimeUtils.h"
-#include <EGL/eglext.h>
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-#include <GLES3/gl3.h>
-
-#include <utils/GLUtils.h>
-
namespace android {
namespace uirenderer {
namespace skiapipeline {
@@ -75,20 +76,23 @@ void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) {
SkImageInfo surfaceInfo = canvas->imageInfo();
- if (!mFrameBuffer.get() || mFBInfo != surfaceInfo) {
+ if (mFrameBuffer == nullptr || mFBInfo != surfaceInfo) {
// Buffer will be used as an OpenGL ES render target.
- mFrameBuffer = new GraphicBuffer(
- // TODO: try to reduce the size of the buffer: possibly by using clip bounds.
- static_cast<uint32_t>(surfaceInfo.width()),
- static_cast<uint32_t>(surfaceInfo.height()),
- ColorTypeToPixelFormat(surfaceInfo.colorType()),
- GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_NEVER |
- GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_HW_RENDER,
- std::string("VkInteropFunctorDrawable::onDraw pid [") + std::to_string(getpid()) +
- "]");
- status_t error = mFrameBuffer->initCheck();
- if (error < 0) {
- ALOGW("VkInteropFunctorDrawable::onDraw() failed in GraphicBuffer.create()");
+ AHardwareBuffer_Desc desc = {
+ .width = static_cast<uint32_t>(surfaceInfo.width()),
+ .height = static_cast<uint32_t>(surfaceInfo.height()),
+ .layers = 1,
+ .format = ColorTypeToBufferFormat(surfaceInfo.colorType()),
+ .usage = AHARDWAREBUFFER_USAGE_CPU_READ_NEVER |
+ AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER |
+ AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
+ AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER,
+ };
+
+ mFrameBuffer = allocateAHardwareBuffer(desc);
+
+ if (!mFrameBuffer) {
+ ALOGW("VkInteropFunctorDrawable::onDraw() failed in AHardwareBuffer_allocate()");
return;
}
@@ -106,7 +110,7 @@ void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) {
uirenderer::renderthread::EglManager::eglErrorString());
// We use an EGLImage to access the content of the GraphicBuffer
// The EGL image is later bound to a 2D texture
- EGLClientBuffer clientBuffer = (EGLClientBuffer)mFrameBuffer->getNativeBuffer();
+ const EGLClientBuffer clientBuffer = eglGetNativeClientBufferANDROID(mFrameBuffer.get());
AutoEglImage autoImage(display, clientBuffer);
if (autoImage.image == EGL_NO_IMAGE_KHR) {
ALOGW("Could not create EGL image, err =%s",
@@ -121,7 +125,7 @@ void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) {
glBindTexture(GL_TEXTURE_2D, 0);
DrawGlInfo info;
- SkM44 mat4(canvas->experimental_getLocalToDevice());
+ SkM44 mat4(canvas->getLocalToDevice());
SkIRect clipBounds = canvas->getDeviceClipBounds();
info.clipLeft = clipBounds.fLeft;
@@ -151,11 +155,7 @@ void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
- if (mAnyFunctor.index() == 0) {
- std::get<0>(mAnyFunctor).handle->drawGl(info);
- } else {
- (*(std::get<1>(mAnyFunctor).functor))(DrawGlInfo::kModeDraw, &info);
- }
+ mWebViewHandle->drawGl(info);
EGLSyncKHR glDrawFinishedFence =
eglCreateSyncKHR(eglGetCurrentDisplay(), EGL_SYNC_FENCE_KHR, NULL);
@@ -179,22 +179,13 @@ void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) {
// drawing into the offscreen surface, so we need to reset it here.
canvas->resetMatrix();
- auto functorImage = SkImage::MakeFromAHardwareBuffer(
- reinterpret_cast<AHardwareBuffer*>(mFrameBuffer.get()), kPremul_SkAlphaType,
- canvas->imageInfo().refColorSpace(), kBottomLeft_GrSurfaceOrigin);
+ auto functorImage = SkImage::MakeFromAHardwareBuffer(mFrameBuffer.get(), kPremul_SkAlphaType,
+ canvas->imageInfo().refColorSpace(),
+ kBottomLeft_GrSurfaceOrigin);
canvas->drawImage(functorImage, 0, 0, &paint);
canvas->restore();
}
-VkInteropFunctorDrawable::~VkInteropFunctorDrawable() {
- if (auto lp = std::get_if<LegacyFunctor>(&mAnyFunctor)) {
- if (lp->listener) {
- ScopedDrawRequest _drawRequest{};
- lp->listener->onGlFunctorReleased(lp->functor);
- }
- }
-}
-
void VkInteropFunctorDrawable::syncFunctor(const WebViewSyncData& data) const {
ScopedDrawRequest _drawRequest{};
FunctorDrawable::syncFunctor(data);
diff --git a/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.h b/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.h
index c47ee114263f..e6ea175929c0 100644
--- a/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.h
+++ b/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.h
@@ -16,11 +16,12 @@
#pragma once
-#include "FunctorDrawable.h"
-
-#include <ui/GraphicBuffer.h>
+#include <android/hardware_buffer.h>
+#include <utils/NdkUtils.h>
#include <utils/RefBase.h>
+#include "FunctorDrawable.h"
+
namespace android {
namespace uirenderer {
@@ -34,7 +35,7 @@ class VkInteropFunctorDrawable : public FunctorDrawable {
public:
using FunctorDrawable::FunctorDrawable;
- virtual ~VkInteropFunctorDrawable();
+ virtual ~VkInteropFunctorDrawable() {}
static void vkInvokeFunctor(Functor* functor);
@@ -45,7 +46,7 @@ protected:
private:
// Variables below describe/store temporary offscreen buffer used for Vulkan pipeline.
- sp<GraphicBuffer> mFrameBuffer;
+ UniqueAHardwareBuffer mFrameBuffer;
SkImageInfo mFBInfo;
};
diff --git a/libs/hwui/renderthread/CacheManager.cpp b/libs/hwui/renderthread/CacheManager.cpp
index 1e5877356e8d..b57dee4897ac 100644
--- a/libs/hwui/renderthread/CacheManager.cpp
+++ b/libs/hwui/renderthread/CacheManager.cpp
@@ -101,7 +101,7 @@ void CacheManager::trimMemory(TrimMemoryMode mode) {
return;
}
- mGrContext->flush();
+ mGrContext->flushAndSubmit();
switch (mode) {
case TrimMemoryMode::Complete:
@@ -122,14 +122,15 @@ void CacheManager::trimMemory(TrimMemoryMode mode) {
// We must sync the cpu to make sure deletions of resources still queued up on the GPU actually
// happen.
- mGrContext->flush(kSyncCpu_GrFlushFlag, 0, nullptr);
+ mGrContext->flush({});
+ mGrContext->submit(true);
}
void CacheManager::trimStaleResources() {
if (!mGrContext) {
return;
}
- mGrContext->flush();
+ mGrContext->flushAndSubmit();
mGrContext->purgeResourcesNotUsedInMs(std::chrono::seconds(30));
}
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index a362bd220936..13d544c68e95 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -174,7 +174,10 @@ void CanvasContext::setSurface(ANativeWindow* window, bool enableTimeout) {
} else {
mNativeSurface = nullptr;
}
+ setupPipelineSurface();
+}
+void CanvasContext::setupPipelineSurface() {
bool hasSurface = mRenderPipeline->setSurface(
mNativeSurface ? mNativeSurface->getNativeWindow() : nullptr, mSwapBehavior);
@@ -184,7 +187,7 @@ void CanvasContext::setSurface(ANativeWindow* window, bool enableTimeout) {
mFrameNumber = -1;
- if (window != nullptr && hasSurface) {
+ if (mNativeSurface != nullptr && hasSurface) {
mHaveNewSurface = true;
mSwapHistory.clear();
// Enable frame stats after the surface has been bound to the appropriate graphics API.
@@ -239,9 +242,9 @@ void CanvasContext::setOpaque(bool opaque) {
mOpaque = opaque;
}
-void CanvasContext::setWideGamut(bool wideGamut) {
- ColorMode colorMode = wideGamut ? ColorMode::WideColorGamut : ColorMode::SRGB;
- mRenderPipeline->setSurfaceColorProperties(colorMode);
+void CanvasContext::setColorMode(ColorMode mode) {
+ mRenderPipeline->setSurfaceColorProperties(mode);
+ setupPipelineSurface();
}
bool CanvasContext::makeCurrent() {
diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h
index 0f1b8aebf56c..cba710f01063 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -30,6 +30,7 @@
#include "renderthread/RenderTask.h"
#include "renderthread/RenderThread.h"
#include "utils/RingBuffer.h"
+#include "ColorMode.h"
#include <SkBitmap.h>
#include <SkRect.h>
@@ -119,7 +120,7 @@ public:
void setLightAlpha(uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
void setLightGeometry(const Vector3& lightCenter, float lightRadius);
void setOpaque(bool opaque);
- void setWideGamut(bool wideGamut);
+ void setColorMode(ColorMode mode);
bool makeCurrent();
void prepareTree(TreeInfo& info, int64_t* uiFrameInfo, int64_t syncQueued, RenderNode* target);
void draw();
@@ -170,9 +171,9 @@ public:
}
// Used to queue up work that needs to be completed before this frame completes
- ANDROID_API void enqueueFrameWork(std::function<void()>&& func);
+ void enqueueFrameWork(std::function<void()>&& func);
- ANDROID_API int64_t getFrameNumber();
+ int64_t getFrameNumber();
void waitOnFences();
@@ -211,6 +212,7 @@ private:
bool isSwapChainStuffed();
bool surfaceRequiresRedraw();
void setPresentTime();
+ void setupPipelineSurface();
SkRect computeDirtyRect(const Frame& frame, SkRect* dirty);
diff --git a/libs/hwui/renderthread/EglManager.cpp b/libs/hwui/renderthread/EglManager.cpp
index 7982ab664c1b..a11678189bad 100644
--- a/libs/hwui/renderthread/EglManager.cpp
+++ b/libs/hwui/renderthread/EglManager.cpp
@@ -76,6 +76,7 @@ static struct {
bool glColorSpace = false;
bool scRGB = false;
bool displayP3 = false;
+ bool hdr = false;
bool contextPriority = false;
bool surfacelessContext = false;
bool nativeFenceSync = false;
@@ -86,7 +87,8 @@ static struct {
EglManager::EglManager()
: mEglDisplay(EGL_NO_DISPLAY)
, mEglConfig(nullptr)
- , mEglConfigWideGamut(nullptr)
+ , mEglConfigF16(nullptr)
+ , mEglConfig1010102(nullptr)
, mEglContext(EGL_NO_CONTEXT)
, mPBufferSurface(EGL_NO_SURFACE)
, mCurrentSurface(EGL_NO_SURFACE)
@@ -136,15 +138,14 @@ void EglManager::initialize() {
LOG_ALWAYS_FATAL_IF(!DeviceInfo::get()->getWideColorSpace()->toXYZD50(&wideColorGamut),
"Could not get gamut matrix from wideColorSpace");
bool hasWideColorSpaceExtension = false;
- if (memcmp(&wideColorGamut, &SkNamedGamut::kDCIP3, sizeof(wideColorGamut)) == 0) {
+ if (memcmp(&wideColorGamut, &SkNamedGamut::kDisplayP3, sizeof(wideColorGamut)) == 0) {
hasWideColorSpaceExtension = EglExtensions.displayP3;
} else if (memcmp(&wideColorGamut, &SkNamedGamut::kSRGB, sizeof(wideColorGamut)) == 0) {
hasWideColorSpaceExtension = EglExtensions.scRGB;
} else {
LOG_ALWAYS_FATAL("Unsupported wide color space.");
}
- mHasWideColorGamutSupport = EglExtensions.glColorSpace && hasWideColorSpaceExtension &&
- mEglConfigWideGamut != EGL_NO_CONFIG_KHR;
+ mHasWideColorGamutSupport = EglExtensions.glColorSpace && hasWideColorSpaceExtension;
}
EGLConfig EglManager::load8BitsConfig(EGLDisplay display, EglManager::SwapBehavior swapBehavior) {
@@ -177,6 +178,35 @@ EGLConfig EglManager::load8BitsConfig(EGLDisplay display, EglManager::SwapBehavi
return config;
}
+EGLConfig EglManager::load1010102Config(EGLDisplay display, SwapBehavior swapBehavior) {
+ EGLint eglSwapBehavior =
+ (swapBehavior == SwapBehavior::Preserved) ? EGL_SWAP_BEHAVIOR_PRESERVED_BIT : 0;
+ // If we reached this point, we have a valid swap behavior
+ EGLint attribs[] = {EGL_RENDERABLE_TYPE,
+ EGL_OPENGL_ES2_BIT,
+ EGL_RED_SIZE,
+ 10,
+ EGL_GREEN_SIZE,
+ 10,
+ EGL_BLUE_SIZE,
+ 10,
+ EGL_ALPHA_SIZE,
+ 2,
+ EGL_DEPTH_SIZE,
+ 0,
+ EGL_STENCIL_SIZE,
+ STENCIL_BUFFER_SIZE,
+ EGL_SURFACE_TYPE,
+ EGL_WINDOW_BIT | eglSwapBehavior,
+ EGL_NONE};
+ EGLConfig config = EGL_NO_CONFIG_KHR;
+ EGLint numConfigs = 1;
+ if (!eglChooseConfig(display, attribs, &config, numConfigs, &numConfigs) || numConfigs != 1) {
+ return EGL_NO_CONFIG_KHR;
+ }
+ return config;
+}
+
EGLConfig EglManager::loadFP16Config(EGLDisplay display, SwapBehavior swapBehavior) {
EGLint eglSwapBehavior =
(swapBehavior == SwapBehavior::Preserved) ? EGL_SWAP_BEHAVIOR_PRESERVED_BIT : 0;
@@ -208,12 +238,8 @@ EGLConfig EglManager::loadFP16Config(EGLDisplay display, SwapBehavior swapBehavi
return config;
}
-extern "C" EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name);
-
void EglManager::initExtensions() {
auto extensions = StringUtils::split(eglQueryString(mEglDisplay, EGL_EXTENSIONS));
- auto extensionsAndroid =
- StringUtils::split(eglQueryStringImplementationANDROID(mEglDisplay, EGL_EXTENSIONS));
// For our purposes we don't care if EGL_BUFFER_AGE is a result of
// EGL_EXT_buffer_age or EGL_KHR_partial_update as our usage is covered
@@ -230,14 +256,12 @@ void EglManager::initExtensions() {
EglExtensions.pixelFormatFloat = extensions.has("EGL_EXT_pixel_format_float");
EglExtensions.scRGB = extensions.has("EGL_EXT_gl_colorspace_scrgb");
EglExtensions.displayP3 = extensions.has("EGL_EXT_gl_colorspace_display_p3_passthrough");
+ EglExtensions.hdr = extensions.has("EGL_EXT_gl_colorspace_bt2020_pq");
EglExtensions.contextPriority = extensions.has("EGL_IMG_context_priority");
EglExtensions.surfacelessContext = extensions.has("EGL_KHR_surfaceless_context");
EglExtensions.fenceSync = extensions.has("EGL_KHR_fence_sync");
EglExtensions.waitSync = extensions.has("EGL_KHR_wait_sync");
-
- // EGL_ANDROID_native_fence_sync is not exposed to applications, so access
- // this through the private Android-specific query instead.
- EglExtensions.nativeFenceSync = extensionsAndroid.has("EGL_ANDROID_native_fence_sync");
+ EglExtensions.nativeFenceSync = extensions.has("EGL_ANDROID_native_fence_sync");
}
bool EglManager::hasEglContext() {
@@ -260,18 +284,20 @@ void EglManager::loadConfigs() {
LOG_ALWAYS_FATAL("Failed to choose config, error = %s", eglErrorString());
}
}
- SkColorType wideColorType = DeviceInfo::get()->getWideColorType();
// When we reach this point, we have a valid swap behavior
- if (wideColorType == SkColorType::kRGBA_F16_SkColorType && EglExtensions.pixelFormatFloat) {
- mEglConfigWideGamut = loadFP16Config(mEglDisplay, mSwapBehavior);
- if (mEglConfigWideGamut == EGL_NO_CONFIG_KHR) {
+ if (EglExtensions.pixelFormatFloat) {
+ mEglConfigF16 = loadFP16Config(mEglDisplay, mSwapBehavior);
+ if (mEglConfigF16 == EGL_NO_CONFIG_KHR) {
ALOGE("Device claims wide gamut support, cannot find matching config, error = %s",
eglErrorString());
EglExtensions.pixelFormatFloat = false;
}
- } else if (wideColorType == SkColorType::kN32_SkColorType) {
- mEglConfigWideGamut = load8BitsConfig(mEglDisplay, mSwapBehavior);
+ }
+ mEglConfig1010102 = load1010102Config(mEglDisplay, mSwapBehavior);
+ if (mEglConfig1010102 == EGL_NO_CONFIG_KHR) {
+ ALOGW("Failed to initialize 101010-2 format, error = %s",
+ eglErrorString());
}
}
@@ -311,8 +337,9 @@ Result<EGLSurface, EGLint> EglManager::createSurface(EGLNativeWindowType window,
sk_sp<SkColorSpace> colorSpace) {
LOG_ALWAYS_FATAL_IF(!hasEglContext(), "Not initialized");
- bool wideColorGamut = colorMode == ColorMode::WideColorGamut && mHasWideColorGamutSupport &&
- EglExtensions.noConfigContext;
+ if (!mHasWideColorGamutSupport || !EglExtensions.noConfigContext) {
+ colorMode = ColorMode::Default;
+ }
// The color space we want to use depends on whether linear blending is turned
// on and whether the app has requested wide color gamut rendering. When wide
@@ -338,26 +365,47 @@ Result<EGLSurface, EGLint> EglManager::createSurface(EGLNativeWindowType window,
// list is considered empty if the first entry is EGL_NONE
EGLint attribs[] = {EGL_NONE, EGL_NONE, EGL_NONE};
+ EGLConfig config = mEglConfig;
+ if (DeviceInfo::get()->getWideColorType() == kRGBA_F16_SkColorType) {
+ if (mEglConfigF16 == EGL_NO_CONFIG_KHR) {
+ colorMode = ColorMode::Default;
+ } else {
+ config = mEglConfigF16;
+ }
+ }
if (EglExtensions.glColorSpace) {
attribs[0] = EGL_GL_COLORSPACE_KHR;
- if (wideColorGamut) {
- skcms_Matrix3x3 colorGamut;
- LOG_ALWAYS_FATAL_IF(!colorSpace->toXYZD50(&colorGamut),
- "Could not get gamut matrix from color space");
- if (memcmp(&colorGamut, &SkNamedGamut::kDCIP3, sizeof(colorGamut)) == 0) {
- attribs[1] = EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT;
- } else if (memcmp(&colorGamut, &SkNamedGamut::kSRGB, sizeof(colorGamut)) == 0) {
- attribs[1] = EGL_GL_COLORSPACE_SCRGB_EXT;
- } else {
- LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space.");
+ switch (colorMode) {
+ case ColorMode::Default:
+ attribs[1] = EGL_GL_COLORSPACE_LINEAR_KHR;
+ break;
+ case ColorMode::WideColorGamut: {
+ skcms_Matrix3x3 colorGamut;
+ LOG_ALWAYS_FATAL_IF(!colorSpace->toXYZD50(&colorGamut),
+ "Could not get gamut matrix from color space");
+ if (memcmp(&colorGamut, &SkNamedGamut::kDisplayP3, sizeof(colorGamut)) == 0) {
+ attribs[1] = EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT;
+ } else if (memcmp(&colorGamut, &SkNamedGamut::kSRGB, sizeof(colorGamut)) == 0) {
+ attribs[1] = EGL_GL_COLORSPACE_SCRGB_EXT;
+ } else if (memcmp(&colorGamut, &SkNamedGamut::kRec2020, sizeof(colorGamut)) == 0) {
+ attribs[1] = EGL_GL_COLORSPACE_BT2020_PQ_EXT;
+ } else {
+ LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space.");
+ }
+ break;
}
- } else {
- attribs[1] = EGL_GL_COLORSPACE_LINEAR_KHR;
+ case ColorMode::Hdr:
+ config = mEglConfigF16;
+ attribs[1] = EGL_GL_COLORSPACE_BT2020_PQ_EXT;
+ break;
+ case ColorMode::Hdr10:
+ config = mEglConfig1010102;
+ attribs[1] = EGL_GL_COLORSPACE_BT2020_PQ_EXT;
+ break;
}
}
- EGLSurface surface = eglCreateWindowSurface(
- mEglDisplay, wideColorGamut ? mEglConfigWideGamut : mEglConfig, window, attribs);
+ EGLSurface surface = eglCreateWindowSurface(mEglDisplay, config, window, attribs);
if (surface == EGL_NO_SURFACE) {
return Error<EGLint>{eglGetError()};
}
diff --git a/libs/hwui/renderthread/EglManager.h b/libs/hwui/renderthread/EglManager.h
index a893e245b214..69f3ed014c53 100644
--- a/libs/hwui/renderthread/EglManager.h
+++ b/libs/hwui/renderthread/EglManager.h
@@ -21,7 +21,6 @@
#include <SkImageInfo.h>
#include <SkRect.h>
#include <cutils/compiler.h>
-#include <ui/GraphicBuffer.h>
#include <utils/StrongPointer.h>
#include "IRenderPipeline.h"
@@ -89,6 +88,7 @@ private:
static EGLConfig load8BitsConfig(EGLDisplay display, SwapBehavior swapBehavior);
static EGLConfig loadFP16Config(EGLDisplay display, SwapBehavior swapBehavior);
+ static EGLConfig load1010102Config(EGLDisplay display, SwapBehavior swapBehavior);
void initExtensions();
void createPBufferSurface();
@@ -98,7 +98,8 @@ private:
EGLDisplay mEglDisplay;
EGLConfig mEglConfig;
- EGLConfig mEglConfigWideGamut;
+ EGLConfig mEglConfigF16;
+ EGLConfig mEglConfig1010102;
EGLContext mEglContext;
EGLSurface mPBufferSurface;
EGLSurface mCurrentSurface;
diff --git a/libs/hwui/renderthread/IRenderPipeline.h b/libs/hwui/renderthread/IRenderPipeline.h
index c3c22869a42f..a04738d6a6f0 100644
--- a/libs/hwui/renderthread/IRenderPipeline.h
+++ b/libs/hwui/renderthread/IRenderPipeline.h
@@ -22,6 +22,7 @@
#include "Lighting.h"
#include "SwapBehavior.h"
#include "hwui/Bitmap.h"
+#include "ColorMode.h"
#include <SkRect.h>
#include <utils/RefBase.h>
@@ -42,16 +43,6 @@ namespace renderthread {
enum class MakeCurrentResult { AlreadyCurrent, Failed, Succeeded };
-enum class ColorMode {
- // SRGB means HWUI will produce buffer in SRGB color space.
- SRGB,
- // WideColorGamut means HWUI would support rendering scRGB non-linear into
- // a signed buffer with enough range to support the wide color gamut of the
- // display.
- WideColorGamut,
- // Hdr
-};
-
class Frame;
class IRenderPipeline {
diff --git a/libs/hwui/renderthread/ReliableSurface.cpp b/libs/hwui/renderthread/ReliableSurface.cpp
index dcf1fc189588..c29cc11fa7ea 100644
--- a/libs/hwui/renderthread/ReliableSurface.cpp
+++ b/libs/hwui/renderthread/ReliableSurface.cpp
@@ -149,21 +149,25 @@ ANativeWindowBuffer* ReliableSurface::acquireFallbackBuffer(int error) {
return AHardwareBuffer_to_ANativeWindowBuffer(mScratchBuffer.get());
}
- AHardwareBuffer_Desc desc;
- desc.usage = mUsage;
- desc.format = mFormat;
- desc.width = 1;
- desc.height = 1;
- desc.layers = 1;
- desc.rfu0 = 0;
- desc.rfu1 = 0;
- AHardwareBuffer* newBuffer = nullptr;
- int err = AHardwareBuffer_allocate(&desc, &newBuffer);
- if (err) {
+ AHardwareBuffer_Desc desc = AHardwareBuffer_Desc{
+ .usage = mUsage,
+ .format = mFormat,
+ .width = 1,
+ .height = 1,
+ .layers = 1,
+ .rfu0 = 0,
+ .rfu1 = 0,
+ };
+
+ AHardwareBuffer* newBuffer;
+ int result = AHardwareBuffer_allocate(&desc, &newBuffer);
+
+ if (result != NO_ERROR) {
// Allocate failed, that sucks
- ALOGW("Failed to allocate scratch buffer, error=%d", err);
+ ALOGW("Failed to allocate scratch buffer, error=%d", result);
return nullptr;
}
+
mScratchBuffer.reset(newBuffer);
return AHardwareBuffer_to_ANativeWindowBuffer(newBuffer);
}
diff --git a/libs/hwui/renderthread/ReliableSurface.h b/libs/hwui/renderthread/ReliableSurface.h
index f699eb1fe6b3..41969e776fc8 100644
--- a/libs/hwui/renderthread/ReliableSurface.h
+++ b/libs/hwui/renderthread/ReliableSurface.h
@@ -21,6 +21,7 @@
#include <apex/window.h>
#include <utils/Errors.h>
#include <utils/Macros.h>
+#include <utils/NdkUtils.h>
#include <utils/StrongPointer.h>
#include <memory>
@@ -67,8 +68,7 @@ private:
uint64_t mUsage = AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER;
AHardwareBuffer_Format mFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
- std::unique_ptr<AHardwareBuffer, void (*)(AHardwareBuffer*)> mScratchBuffer{
- nullptr, AHardwareBuffer_release};
+ UniqueAHardwareBuffer mScratchBuffer;
ANativeWindowBuffer* mReservedBuffer = nullptr;
base::unique_fd mReservedFenceFd;
bool mHasDequeuedBuffer = false;
diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index b66a13d1efda..b51f6dcfc66f 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -77,10 +77,10 @@ void RenderProxy::setName(const char* name) {
}
void RenderProxy::setSurface(ANativeWindow* window, bool enableTimeout) {
- ANativeWindow_acquire(window);
+ if (window) { ANativeWindow_acquire(window); }
mRenderThread.queue().post([this, win = window, enableTimeout]() mutable {
mContext->setSurface(win, enableTimeout);
- ANativeWindow_release(win);
+ if (win) { ANativeWindow_release(win); }
});
}
@@ -109,8 +109,8 @@ void RenderProxy::setOpaque(bool opaque) {
mRenderThread.queue().post([=]() { mContext->setOpaque(opaque); });
}
-void RenderProxy::setWideGamut(bool wideGamut) {
- mRenderThread.queue().post([=]() { mContext->setWideGamut(wideGamut); });
+void RenderProxy::setColorMode(ColorMode mode) {
+ mRenderThread.queue().post([=]() { mContext->setColorMode(mode); });
}
int64_t* RenderProxy::frameInfo() {
@@ -128,20 +128,6 @@ void RenderProxy::destroy() {
mRenderThread.queue().runSync([=]() { mContext->destroy(); });
}
-void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
- ATRACE_CALL();
- RenderThread& thread = RenderThread::getInstance();
- auto invoke = [&thread, functor]() { CanvasContext::invokeFunctor(thread, functor); };
- if (waitForCompletion) {
- // waitForCompletion = true is expected to be fairly rare and only
- // happen in destruction. Thus it should be fine to temporarily
- // create a Mutex
- thread.queue().runSync(std::move(invoke));
- } else {
- thread.queue().post(std::move(invoke));
- }
-}
-
void RenderProxy::destroyFunctor(int functor) {
ATRACE_CALL();
RenderThread& thread = RenderThread::getInstance();
diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h
index 3baeb2f7a476..33dabc9895b1 100644
--- a/libs/hwui/renderthread/RenderProxy.h
+++ b/libs/hwui/renderthread/RenderProxy.h
@@ -24,6 +24,7 @@
#include "../FrameMetricsObserver.h"
#include "../IContextFactory.h"
+#include "ColorMode.h"
#include "DrawFrameTask.h"
#include "SwapBehavior.h"
#include "hwui/Bitmap.h"
@@ -60,69 +61,67 @@ enum {
* references RenderProxy fields. This is safe as RenderProxy cannot
* be deleted if it is blocked inside a call.
*/
-class ANDROID_API RenderProxy {
+class RenderProxy {
public:
- ANDROID_API RenderProxy(bool opaque, RenderNode* rootNode, IContextFactory* contextFactory);
- ANDROID_API virtual ~RenderProxy();
+ RenderProxy(bool opaque, RenderNode* rootNode, IContextFactory* contextFactory);
+ virtual ~RenderProxy();
// Won't take effect until next EGLSurface creation
- ANDROID_API void setSwapBehavior(SwapBehavior swapBehavior);
- ANDROID_API bool loadSystemProperties();
- ANDROID_API void setName(const char* name);
-
- ANDROID_API void setSurface(ANativeWindow* window, bool enableTimeout = true);
- ANDROID_API void allocateBuffers();
- ANDROID_API bool pause();
- ANDROID_API void setStopped(bool stopped);
- ANDROID_API void setLightAlpha(uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
- ANDROID_API void setLightGeometry(const Vector3& lightCenter, float lightRadius);
- ANDROID_API void setOpaque(bool opaque);
- ANDROID_API void setWideGamut(bool wideGamut);
- ANDROID_API int64_t* frameInfo();
- ANDROID_API int syncAndDrawFrame();
- ANDROID_API void destroy();
-
- ANDROID_API static void invokeFunctor(Functor* functor, bool waitForCompletion);
+ void setSwapBehavior(SwapBehavior swapBehavior);
+ bool loadSystemProperties();
+ void setName(const char* name);
+
+ void setSurface(ANativeWindow* window, bool enableTimeout = true);
+ void allocateBuffers();
+ bool pause();
+ void setStopped(bool stopped);
+ void setLightAlpha(uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
+ void setLightGeometry(const Vector3& lightCenter, float lightRadius);
+ void setOpaque(bool opaque);
+ void setColorMode(ColorMode mode);
+ int64_t* frameInfo();
+ int syncAndDrawFrame();
+ void destroy();
+
static void destroyFunctor(int functor);
- ANDROID_API DeferredLayerUpdater* createTextureLayer();
- ANDROID_API void buildLayer(RenderNode* node);
- ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
- ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer);
- ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer);
- ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer);
+ DeferredLayerUpdater* createTextureLayer();
+ void buildLayer(RenderNode* node);
+ bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
+ void pushLayerUpdate(DeferredLayerUpdater* layer);
+ void cancelLayerUpdate(DeferredLayerUpdater* layer);
+ void detachSurfaceTexture(DeferredLayerUpdater* layer);
- ANDROID_API void destroyHardwareResources();
- ANDROID_API static void trimMemory(int level);
- ANDROID_API static void overrideProperty(const char* name, const char* value);
+ void destroyHardwareResources();
+ static void trimMemory(int level);
+ static void overrideProperty(const char* name, const char* value);
- ANDROID_API void fence();
- ANDROID_API static int maxTextureSize();
- ANDROID_API void stopDrawing();
- ANDROID_API void notifyFramePending();
+ void fence();
+ static int maxTextureSize();
+ void stopDrawing();
+ void notifyFramePending();
- ANDROID_API void dumpProfileInfo(int fd, int dumpFlags);
+ void dumpProfileInfo(int fd, int dumpFlags);
// Not exported, only used for testing
void resetProfileInfo();
uint32_t frameTimePercentile(int p);
- ANDROID_API static void dumpGraphicsMemory(int fd);
+ static void dumpGraphicsMemory(int fd);
- ANDROID_API static void rotateProcessStatsBuffer();
- ANDROID_API static void setProcessStatsBuffer(int fd);
- ANDROID_API int getRenderThreadTid();
+ static void rotateProcessStatsBuffer();
+ static void setProcessStatsBuffer(int fd);
+ int getRenderThreadTid();
- ANDROID_API void addRenderNode(RenderNode* node, bool placeFront);
- ANDROID_API void removeRenderNode(RenderNode* node);
- ANDROID_API void drawRenderNode(RenderNode* node);
- ANDROID_API void setContentDrawBounds(int left, int top, int right, int bottom);
- ANDROID_API void setPictureCapturedCallback(
- const std::function<void(sk_sp<SkPicture>&&)>& callback);
- ANDROID_API void setFrameCallback(std::function<void(int64_t)>&& callback);
- ANDROID_API void setFrameCompleteCallback(std::function<void(int64_t)>&& callback);
+ void addRenderNode(RenderNode* node, bool placeFront);
+ void removeRenderNode(RenderNode* node);
+ void drawRenderNode(RenderNode* node);
+ void setContentDrawBounds(int left, int top, int right, int bottom);
+ void setPictureCapturedCallback(const std::function<void(sk_sp<SkPicture>&&)>& callback);
+ void setFrameCallback(std::function<void(int64_t)>&& callback);
+ void setFrameCompleteCallback(std::function<void(int64_t)>&& callback);
- ANDROID_API void addFrameMetricsObserver(FrameMetricsObserver* observer);
- ANDROID_API void removeFrameMetricsObserver(FrameMetricsObserver* observer);
- ANDROID_API void setForceDark(bool enable);
+ void addFrameMetricsObserver(FrameMetricsObserver* observer);
+ void removeFrameMetricsObserver(FrameMetricsObserver* observer);
+ void setForceDark(bool enable);
/**
* Sets a render-ahead depth on the backing renderer. This will increase latency by
@@ -139,17 +138,17 @@ public:
*
* @param renderAhead How far to render ahead, must be in the range [0..2]
*/
- ANDROID_API void setRenderAheadDepth(int renderAhead);
+ void setRenderAheadDepth(int renderAhead);
- ANDROID_API static int copySurfaceInto(ANativeWindow* window, int left, int top, int right,
+ static int copySurfaceInto(ANativeWindow* window, int left, int top, int right,
int bottom, SkBitmap* bitmap);
- ANDROID_API static void prepareToDraw(Bitmap& bitmap);
+ static void prepareToDraw(Bitmap& bitmap);
static int copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap);
- ANDROID_API static void disableVsync();
+ static void disableVsync();
- ANDROID_API static void preload();
+ static void preload();
private:
RenderThread& mRenderThread;
diff --git a/libs/hwui/renderthread/RenderTask.h b/libs/hwui/renderthread/RenderTask.h
index c56a3578ad58..3e3a381d65fe 100644
--- a/libs/hwui/renderthread/RenderTask.h
+++ b/libs/hwui/renderthread/RenderTask.h
@@ -45,12 +45,12 @@ namespace renderthread {
* malloc/free churn of small objects?
*/
-class ANDROID_API RenderTask {
+class RenderTask {
public:
- ANDROID_API RenderTask() : mNext(nullptr), mRunAt(0) {}
- ANDROID_API virtual ~RenderTask() {}
+ RenderTask() : mNext(nullptr), mRunAt(0) {}
+ virtual ~RenderTask() {}
- ANDROID_API virtual void run() = 0;
+ virtual void run() = 0;
RenderTask* mNext;
nsecs_t mRunAt; // nano-seconds on the SYSTEM_TIME_MONOTONIC clock
diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp
index 206b58f62ea7..4dcbc4458e97 100644
--- a/libs/hwui/renderthread/RenderThread.cpp
+++ b/libs/hwui/renderthread/RenderThread.cpp
@@ -131,8 +131,7 @@ RenderThread::RenderThread()
, mFrameCallbackTaskPending(false)
, mRenderState(nullptr)
, mEglManager(nullptr)
- , mFunctorManager(WebViewFunctorManager::instance())
- , mVkManager(nullptr) {
+ , mFunctorManager(WebViewFunctorManager::instance()) {
Properties::load();
start("RenderThread");
}
@@ -166,7 +165,7 @@ void RenderThread::initThreadLocals() {
initializeChoreographer();
mEglManager = new EglManager();
mRenderState = new RenderState(*this);
- mVkManager = new VulkanManager();
+ mVkManager = VulkanManager::getInstance();
mCacheManager = new CacheManager();
}
@@ -190,13 +189,14 @@ void RenderThread::requireGlContext() {
auto glesVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));
auto size = glesVersion ? strlen(glesVersion) : -1;
cacheManager().configureContext(&options, glesVersion, size);
- sk_sp<GrContext> grContext(GrContext::MakeGL(std::move(glInterface), options));
+ sk_sp<GrDirectContext> grContext(GrDirectContext::MakeGL(std::move(glInterface), options));
LOG_ALWAYS_FATAL_IF(!grContext.get());
setGrContext(grContext);
}
void RenderThread::requireVkContext() {
- if (mVkManager->hasVkContext()) {
+ // the getter creates the context in the event it had been destroyed by destroyRenderingContext
+ if (vulkanManager().hasVkContext()) {
return;
}
mVkManager->initialize();
@@ -204,7 +204,7 @@ void RenderThread::requireVkContext() {
initGrContextOptions(options);
auto vkDriverVersion = mVkManager->getDriverVersion();
cacheManager().configureContext(&options, &vkDriverVersion, sizeof(vkDriverVersion));
- sk_sp<GrContext> grContext = mVkManager->createContext(options);
+ sk_sp<GrDirectContext> grContext = mVkManager->createContext(options);
LOG_ALWAYS_FATAL_IF(!grContext.get());
setGrContext(grContext);
}
@@ -222,11 +222,16 @@ void RenderThread::destroyRenderingContext() {
mEglManager->destroy();
}
} else {
- if (vulkanManager().hasVkContext()) {
- setGrContext(nullptr);
- vulkanManager().destroy();
- }
+ setGrContext(nullptr);
+ mVkManager.clear();
+ }
+}
+
+VulkanManager& RenderThread::vulkanManager() {
+ if (!mVkManager.get()) {
+ mVkManager = VulkanManager::getInstance();
}
+ return *mVkManager.get();
}
void RenderThread::dumpGraphicsMemory(int fd) {
@@ -263,7 +268,7 @@ Readback& RenderThread::readback() {
return *mReadback;
}
-void RenderThread::setGrContext(sk_sp<GrContext> context) {
+void RenderThread::setGrContext(sk_sp<GrDirectContext> context) {
mCacheManager->reset(context);
if (mGrContext) {
mRenderState->onContextDestroyed();
diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h
index 8be46a6d16e1..d7dc00b8a5c1 100644
--- a/libs/hwui/renderthread/RenderThread.h
+++ b/libs/hwui/renderthread/RenderThread.h
@@ -17,7 +17,7 @@
#ifndef RENDERTHREAD_H_
#define RENDERTHREAD_H_
-#include <GrContext.h>
+#include <GrDirectContext.h>
#include <SkBitmap.h>
#include <apex/choreographer.h>
#include <cutils/compiler.h>
@@ -88,7 +88,7 @@ class RenderThread : private ThreadBase {
public:
// Sets a callback that fires before any RenderThread setup has occurred.
- ANDROID_API static void setOnStartHook(JVMAttachHook onStartHook);
+ static void setOnStartHook(JVMAttachHook onStartHook);
static JVMAttachHook getOnStartHook();
WorkQueue& queue() { return ThreadBase::queue(); }
@@ -106,11 +106,11 @@ public:
ProfileDataContainer& globalProfileData() { return mGlobalProfileData; }
Readback& readback();
- GrContext* getGrContext() const { return mGrContext.get(); }
- void setGrContext(sk_sp<GrContext> cxt);
+ GrDirectContext* getGrContext() const { return mGrContext.get(); }
+ void setGrContext(sk_sp<GrDirectContext> cxt);
CacheManager& cacheManager() { return *mCacheManager; }
- VulkanManager& vulkanManager() { return *mVkManager; }
+ VulkanManager& vulkanManager();
sk_sp<Bitmap> allocateHardwareBitmap(SkBitmap& skBitmap);
void dumpGraphicsMemory(int fd);
@@ -186,9 +186,9 @@ private:
ProfileDataContainer mGlobalProfileData;
Readback* mReadback = nullptr;
- sk_sp<GrContext> mGrContext;
+ sk_sp<GrDirectContext> mGrContext;
CacheManager* mCacheManager;
- VulkanManager* mVkManager;
+ sp<VulkanManager> mVkManager;
};
} /* namespace renderthread */
diff --git a/libs/hwui/renderthread/VulkanManager.cpp b/libs/hwui/renderthread/VulkanManager.cpp
index ba70afc8b8d2..4dbce92ed01c 100644
--- a/libs/hwui/renderthread/VulkanManager.cpp
+++ b/libs/hwui/renderthread/VulkanManager.cpp
@@ -20,7 +20,7 @@
#include <EGL/eglext.h>
#include <GrBackendSemaphore.h>
#include <GrBackendSurface.h>
-#include <GrContext.h>
+#include <GrDirectContext.h>
#include <GrTypes.h>
#include <android/sync.h>
#include <ui/FatVector.h>
@@ -57,12 +57,22 @@ static void free_features_extensions_structs(const VkPhysicalDeviceFeatures2& fe
#define GET_INST_PROC(F) m##F = (PFN_vk##F)vkGetInstanceProcAddr(mInstance, "vk" #F)
#define GET_DEV_PROC(F) m##F = (PFN_vk##F)vkGetDeviceProcAddr(mDevice, "vk" #F)
-void VulkanManager::destroy() {
- if (VK_NULL_HANDLE != mCommandPool) {
- mDestroyCommandPool(mDevice, mCommandPool, nullptr);
- mCommandPool = VK_NULL_HANDLE;
+sp<VulkanManager> VulkanManager::getInstance() {
+ // cache a weakptr to the context to enable a second thread to share the same vulkan state
+ static wp<VulkanManager> sWeakInstance = nullptr;
+ static std::mutex sLock;
+
+ std::lock_guard _lock{sLock};
+ sp<VulkanManager> vulkanManager = sWeakInstance.promote();
+ if (!vulkanManager.get()) {
+ vulkanManager = new VulkanManager();
+ sWeakInstance = vulkanManager;
}
+ return vulkanManager;
+}
+
+VulkanManager::~VulkanManager() {
if (mDevice != VK_NULL_HANDLE) {
mDeviceWaitIdle(mDevice);
mDestroyDevice(mDevice, nullptr);
@@ -73,7 +83,7 @@ void VulkanManager::destroy() {
}
mGraphicsQueue = VK_NULL_HANDLE;
- mPresentQueue = VK_NULL_HANDLE;
+ mAHBUploadQueue = VK_NULL_HANDLE;
mDevice = VK_NULL_HANDLE;
mPhysicalDevice = VK_NULL_HANDLE;
mInstance = VK_NULL_HANDLE;
@@ -175,15 +185,12 @@ void VulkanManager::setupDevice(GrVkExtensions& grExtensions, VkPhysicalDeviceFe
for (uint32_t i = 0; i < queueCount; i++) {
if (queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
mGraphicsQueueIndex = i;
+ LOG_ALWAYS_FATAL_IF(queueProps[i].queueCount < 2);
break;
}
}
LOG_ALWAYS_FATAL_IF(mGraphicsQueueIndex == queueCount);
- // All physical devices and queue families on Android must be capable of
- // presentation with any native window. So just use the first one.
- mPresentQueueIndex = 0;
-
{
uint32_t extensionCount = 0;
err = mEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, &extensionCount,
@@ -277,31 +284,21 @@ void VulkanManager::setupDevice(GrVkExtensions& grExtensions, VkPhysicalDeviceFe
queueNextPtr = &queuePriorityCreateInfo;
}
- const VkDeviceQueueCreateInfo queueInfo[2] = {
- {
- VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
- queueNextPtr, // pNext
- 0, // VkDeviceQueueCreateFlags
- mGraphicsQueueIndex, // queueFamilyIndex
- 1, // queueCount
- queuePriorities, // pQueuePriorities
- },
- {
- VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
- queueNextPtr, // pNext
- 0, // VkDeviceQueueCreateFlags
- mPresentQueueIndex, // queueFamilyIndex
- 1, // queueCount
- queuePriorities, // pQueuePriorities
- }};
- uint32_t queueInfoCount = (mPresentQueueIndex != mGraphicsQueueIndex) ? 2 : 1;
+ const VkDeviceQueueCreateInfo queueInfo = {
+ VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
+ queueNextPtr, // pNext
+ 0, // VkDeviceQueueCreateFlags
+ mGraphicsQueueIndex, // queueFamilyIndex
+ 2, // queueCount
+ queuePriorities, // pQueuePriorities
+ };
const VkDeviceCreateInfo deviceInfo = {
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType
&features, // pNext
0, // VkDeviceCreateFlags
- queueInfoCount, // queueCreateInfoCount
- queueInfo, // pQueueCreateInfos
+ 1, // queueCreateInfoCount
+ &queueInfo, // pQueueCreateInfos
0, // layerCount
nullptr, // ppEnabledLayerNames
(uint32_t)mDeviceExtensions.size(), // extensionCount
@@ -347,29 +344,15 @@ void VulkanManager::initialize() {
this->setupDevice(mExtensions, mPhysicalDeviceFeatures2);
mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 0, &mGraphicsQueue);
-
- // create the command pool for the command buffers
- if (VK_NULL_HANDLE == mCommandPool) {
- VkCommandPoolCreateInfo commandPoolInfo;
- memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo));
- commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
- // this needs to be on the render queue
- commandPoolInfo.queueFamilyIndex = mGraphicsQueueIndex;
- commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
- SkDEBUGCODE(VkResult res =)
- mCreateCommandPool(mDevice, &commandPoolInfo, nullptr, &mCommandPool);
- SkASSERT(VK_SUCCESS == res);
- }
- LOG_ALWAYS_FATAL_IF(mCommandPool == VK_NULL_HANDLE);
-
- mGetDeviceQueue(mDevice, mPresentQueueIndex, 0, &mPresentQueue);
+ mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 1, &mAHBUploadQueue);
if (Properties::enablePartialUpdates && Properties::useBufferAge) {
mSwapBehavior = SwapBehavior::BufferAge;
}
}
-sk_sp<GrContext> VulkanManager::createContext(const GrContextOptions& options) {
+sk_sp<GrDirectContext> VulkanManager::createContext(const GrContextOptions& options,
+ ContextType contextType) {
auto getProc = [](const char* proc_name, VkInstance instance, VkDevice device) {
if (device != VK_NULL_HANDLE) {
return vkGetDeviceProcAddr(device, proc_name);
@@ -381,14 +364,15 @@ sk_sp<GrContext> VulkanManager::createContext(const GrContextOptions& options) {
backendContext.fInstance = mInstance;
backendContext.fPhysicalDevice = mPhysicalDevice;
backendContext.fDevice = mDevice;
- backendContext.fQueue = mGraphicsQueue;
+ backendContext.fQueue = (contextType == ContextType::kRenderThread) ? mGraphicsQueue
+ : mAHBUploadQueue;
backendContext.fGraphicsQueueIndex = mGraphicsQueueIndex;
backendContext.fMaxAPIVersion = mAPIVersion;
backendContext.fVkExtensions = &mExtensions;
backendContext.fDeviceFeatures2 = &mPhysicalDeviceFeatures2;
backendContext.fGetProc = std::move(getProc);
- return GrContext::MakeVulkan(backendContext, options);
+ return GrDirectContext::MakeVulkan(backendContext, options);
}
VkFunctorInitParams VulkanManager::getVkFunctorInitParams() const {
@@ -459,7 +443,7 @@ Frame VulkanManager::dequeueNextBuffer(VulkanSurface* surface) {
// The following flush blocks the GPU immediately instead of waiting for other
// drawing ops. It seems dequeue_fence is not respected otherwise.
// TODO: remove the flush after finding why backendSemaphore is not working.
- bufferInfo->skSurface->flush();
+ bufferInfo->skSurface->flushAndSubmit();
}
}
}
@@ -525,9 +509,15 @@ void VulkanManager::swapBuffers(VulkanSurface* surface, const SkRect& dirtyRect)
int fenceFd = -1;
DestroySemaphoreInfo* destroyInfo =
new DestroySemaphoreInfo(mDestroySemaphore, mDevice, semaphore);
+ GrFlushInfo flushInfo;
+ flushInfo.fNumSemaphores = 1;
+ flushInfo.fSignalSemaphores = &backendSemaphore;
+ flushInfo.fFinishedProc = destroy_semaphore;
+ flushInfo.fFinishedContext = destroyInfo;
GrSemaphoresSubmitted submitted = bufferInfo->skSurface->flush(
- SkSurface::BackendSurfaceAccess::kPresent, kNone_GrFlushFlags, 1, &backendSemaphore,
- destroy_semaphore, destroyInfo);
+ SkSurface::BackendSurfaceAccess::kPresent, flushInfo);
+ ALOGE_IF(!bufferInfo->skSurface->getContext(), "Surface is not backed by gpu");
+ bufferInfo->skSurface->getContext()->submit();
if (submitted == GrSemaphoresSubmitted::kYes) {
VkSemaphoreGetFdInfoKHR getFdInfo;
getFdInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR;
@@ -548,17 +538,19 @@ void VulkanManager::swapBuffers(VulkanSurface* surface, const SkRect& dirtyRect)
void VulkanManager::destroySurface(VulkanSurface* surface) {
// Make sure all submit commands have finished before starting to destroy objects.
- if (VK_NULL_HANDLE != mPresentQueue) {
- mQueueWaitIdle(mPresentQueue);
+ if (VK_NULL_HANDLE != mGraphicsQueue) {
+ mQueueWaitIdle(mGraphicsQueue);
}
mDeviceWaitIdle(mDevice);
delete surface;
}
-VulkanSurface* VulkanManager::createSurface(ANativeWindow* window, ColorMode colorMode,
+VulkanSurface* VulkanManager::createSurface(ANativeWindow* window,
+ ColorMode colorMode,
sk_sp<SkColorSpace> surfaceColorSpace,
- SkColorType surfaceColorType, GrContext* grContext,
+ SkColorType surfaceColorType,
+ GrDirectContext* grContext,
uint32_t extraBuffers) {
LOG_ALWAYS_FATAL_IF(!hasVkContext(), "Not initialized");
if (!window) {
@@ -569,7 +561,7 @@ VulkanSurface* VulkanManager::createSurface(ANativeWindow* window, ColorMode col
*this, extraBuffers);
}
-status_t VulkanManager::fenceWait(int fence, GrContext* grContext) {
+status_t VulkanManager::fenceWait(int fence, GrDirectContext* grContext) {
if (!hasVkContext()) {
ALOGE("VulkanManager::fenceWait: VkDevice not initialized");
return INVALID_OPERATION;
@@ -612,12 +604,12 @@ status_t VulkanManager::fenceWait(int fence, GrContext* grContext) {
// Skia takes ownership of the semaphore and will delete it once the wait has finished.
grContext->wait(1, &beSemaphore);
- grContext->flush();
+ grContext->flushAndSubmit();
return OK;
}
-status_t VulkanManager::createReleaseFence(int* nativeFence, GrContext* grContext) {
+status_t VulkanManager::createReleaseFence(int* nativeFence, GrDirectContext* grContext) {
*nativeFence = -1;
if (!hasVkContext()) {
ALOGE("VulkanManager::createReleaseFence: VkDevice not initialized");
@@ -648,8 +640,13 @@ status_t VulkanManager::createReleaseFence(int* nativeFence, GrContext* grContex
// Even if Skia fails to submit the semaphore, it will still call the destroy_semaphore callback
// which will remove its ref to the semaphore. The VulkanManager must still release its ref,
// when it is done with the semaphore.
- GrSemaphoresSubmitted submitted = grContext->flush(kNone_GrFlushFlags, 1, &backendSemaphore,
- destroy_semaphore, destroyInfo);
+ GrFlushInfo flushInfo;
+ flushInfo.fNumSemaphores = 1;
+ flushInfo.fSignalSemaphores = &backendSemaphore;
+ flushInfo.fFinishedProc = destroy_semaphore;
+ flushInfo.fFinishedContext = destroyInfo;
+ GrSemaphoresSubmitted submitted = grContext->flush(flushInfo);
+ grContext->submit();
if (submitted == GrSemaphoresSubmitted::kNo) {
ALOGE("VulkanManager::createReleaseFence: Failed to submit semaphore");
diff --git a/libs/hwui/renderthread/VulkanManager.h b/libs/hwui/renderthread/VulkanManager.h
index 8b19f13fdfb9..7a77466303cd 100644
--- a/libs/hwui/renderthread/VulkanManager.h
+++ b/libs/hwui/renderthread/VulkanManager.h
@@ -43,10 +43,9 @@ class RenderThread;
// This class contains the shared global Vulkan objects, such as VkInstance, VkDevice and VkQueue,
// which are re-used by CanvasContext. This class is created once and should be used by all vulkan
// windowing contexts. The VulkanManager must be initialized before use.
-class VulkanManager {
+class VulkanManager final : public RefBase {
public:
- explicit VulkanManager() {}
- ~VulkanManager() { destroy(); }
+ static sp<VulkanManager> getInstance();
// Sets up the vulkan context that is shared amonst all clients of the VulkanManager. This must
// be call once before use of the VulkanManager. Multiple calls after the first will simiply
@@ -57,36 +56,47 @@ public:
bool hasVkContext() { return mDevice != VK_NULL_HANDLE; }
// Create and destroy functions for wrapping an ANativeWindow in a VulkanSurface
- VulkanSurface* createSurface(ANativeWindow* window, ColorMode colorMode,
+ VulkanSurface* createSurface(ANativeWindow* window,
+ ColorMode colorMode,
sk_sp<SkColorSpace> surfaceColorSpace,
- SkColorType surfaceColorType, GrContext* grContext,
+ SkColorType surfaceColorType,
+ GrDirectContext* grContext,
uint32_t extraBuffers);
void destroySurface(VulkanSurface* surface);
Frame dequeueNextBuffer(VulkanSurface* surface);
void swapBuffers(VulkanSurface* surface, const SkRect& dirtyRect);
- // Cleans up all the global state in the VulkanManger.
- void destroy();
-
// Inserts a wait on fence command into the Vulkan command buffer.
- status_t fenceWait(int fence, GrContext* grContext);
+ status_t fenceWait(int fence, GrDirectContext* grContext);
// Creates a fence that is signaled when all the pending Vulkan commands are finished on the
// GPU.
- status_t createReleaseFence(int* nativeFence, GrContext* grContext);
+ status_t createReleaseFence(int* nativeFence, GrDirectContext* grContext);
// Returned pointers are owned by VulkanManager.
// An instance of VkFunctorInitParams returned from getVkFunctorInitParams refers to
// the internal state of VulkanManager: VulkanManager must be alive to use the returned value.
VkFunctorInitParams getVkFunctorInitParams() const;
- sk_sp<GrContext> createContext(const GrContextOptions& options);
+
+ enum class ContextType {
+ kRenderThread,
+ kUploadThread
+ };
+
+ // returns a Skia graphic context used to draw content on the specified thread
+ sk_sp<GrDirectContext> createContext(const GrContextOptions& options,
+ ContextType contextType = ContextType::kRenderThread);
uint32_t getDriverVersion() const { return mDriverVersion; }
private:
friend class VulkanSurface;
+
+ explicit VulkanManager() {}
+ ~VulkanManager();
+
// Sets up the VkInstance and VkDevice objects. Also fills out the passed in
// VkPhysicalDeviceFeatures struct.
void setupDevice(GrVkExtensions&, VkPhysicalDeviceFeatures2&);
@@ -152,9 +162,7 @@ private:
uint32_t mGraphicsQueueIndex;
VkQueue mGraphicsQueue = VK_NULL_HANDLE;
- uint32_t mPresentQueueIndex;
- VkQueue mPresentQueue = VK_NULL_HANDLE;
- VkCommandPool mCommandPool = VK_NULL_HANDLE;
+ VkQueue mAHBUploadQueue = VK_NULL_HANDLE;
// Variables saved to populate VkFunctorInitParams.
static const uint32_t mAPIVersion = VK_MAKE_VERSION(1, 1, 0);
diff --git a/libs/hwui/renderthread/VulkanSurface.cpp b/libs/hwui/renderthread/VulkanSurface.cpp
index a7ea21d8c4de..1da09b454da7 100644
--- a/libs/hwui/renderthread/VulkanSurface.cpp
+++ b/libs/hwui/renderthread/VulkanSurface.cpp
@@ -200,16 +200,16 @@ bool VulkanSurface::InitializeWindowInfoStruct(ANativeWindow* window, ColorMode
"Could not get gamut matrix from color space");
if (memcmp(&surfaceGamut, &SkNamedGamut::kSRGB, sizeof(surfaceGamut)) == 0) {
outWindowInfo->dataspace = HAL_DATASPACE_V0_SCRGB;
- } else if (memcmp(&surfaceGamut, &SkNamedGamut::kDCIP3, sizeof(surfaceGamut)) == 0) {
+ } else if (memcmp(&surfaceGamut, &SkNamedGamut::kDisplayP3, sizeof(surfaceGamut)) == 0) {
outWindowInfo->dataspace = HAL_DATASPACE_DISPLAY_P3;
} else {
LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space.");
}
}
- outWindowInfo->pixelFormat = ColorTypeToPixelFormat(colorType);
+ outWindowInfo->bufferFormat = ColorTypeToBufferFormat(colorType);
VkFormat vkPixelFormat = VK_FORMAT_R8G8B8A8_UNORM;
- if (outWindowInfo->pixelFormat == PIXEL_FORMAT_RGBA_FP16) {
+ if (outWindowInfo->bufferFormat == AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT) {
vkPixelFormat = VK_FORMAT_R16G16B16A16_SFLOAT;
}
@@ -263,10 +263,10 @@ bool VulkanSurface::InitializeWindowInfoStruct(ANativeWindow* window, ColorMode
bool VulkanSurface::UpdateWindow(ANativeWindow* window, const WindowInfo& windowInfo) {
ATRACE_CALL();
- int err = native_window_set_buffers_format(window, windowInfo.pixelFormat);
+ int err = native_window_set_buffers_format(window, windowInfo.bufferFormat);
if (err != 0) {
ALOGE("VulkanSurface::UpdateWindow() native_window_set_buffers_format(%d) failed: %s (%d)",
- windowInfo.pixelFormat, strerror(-err), err);
+ windowInfo.bufferFormat, strerror(-err), err);
return false;
}
diff --git a/libs/hwui/renderthread/VulkanSurface.h b/libs/hwui/renderthread/VulkanSurface.h
index bd2362612a13..40a44b11c0bc 100644
--- a/libs/hwui/renderthread/VulkanSurface.h
+++ b/libs/hwui/renderthread/VulkanSurface.h
@@ -17,8 +17,6 @@
#include <system/graphics.h>
#include <system/window.h>
-#include <ui/BufferQueueDefs.h>
-#include <ui/PixelFormat.h>
#include <vulkan/vulkan.h>
#include <SkRefCnt.h>
@@ -91,7 +89,7 @@ private:
struct WindowInfo {
SkISize size;
- PixelFormat pixelFormat;
+ uint32_t bufferFormat;
android_dataspace dataspace;
int transform;
size_t bufferCount;
@@ -111,8 +109,13 @@ private:
static bool UpdateWindow(ANativeWindow* window, const WindowInfo& windowInfo);
void releaseBuffers();
+ // TODO: This number comes from ui/BufferQueueDefs. We're not pulling the
+ // header in so that we don't need to depend on libui, but we should share
+ // this constant somewhere. But right now it's okay to keep here because we
+ // can't safely change the slot count anyways.
+ static constexpr size_t kNumBufferSlots = 64;
// TODO: Just use a vector?
- NativeBufferInfo mNativeBuffers[android::BufferQueueDefs::NUM_BUFFER_SLOTS];
+ NativeBufferInfo mNativeBuffers[kNumBufferSlots];
sp<ANativeWindow> mNativeWindow;
WindowInfo mWindowInfo;
diff --git a/libs/hwui/service/GraphicsStatsService.h b/libs/hwui/service/GraphicsStatsService.h
index 59e21d039c9d..4063f749f808 100644
--- a/libs/hwui/service/GraphicsStatsService.h
+++ b/libs/hwui/service/GraphicsStatsService.h
@@ -44,18 +44,16 @@ public:
ProtobufStatsd,
};
- ANDROID_API static void saveBuffer(const std::string& path, const std::string& package,
- int64_t versionCode, int64_t startTime, int64_t endTime,
- const ProfileData* data);
-
- ANDROID_API static Dump* createDump(int outFd, DumpType type);
- ANDROID_API static void addToDump(Dump* dump, const std::string& path,
- const std::string& package, int64_t versionCode,
- int64_t startTime, int64_t endTime, const ProfileData* data);
- ANDROID_API static void addToDump(Dump* dump, const std::string& path);
- ANDROID_API static void finishDump(Dump* dump);
- ANDROID_API static void finishDumpInMemory(Dump* dump, AStatsEventList* data,
- bool lastFullDay);
+ static void saveBuffer(const std::string& path, const std::string& package, int64_t versionCode,
+ int64_t startTime, int64_t endTime, const ProfileData* data);
+
+ static Dump* createDump(int outFd, DumpType type);
+ static void addToDump(Dump* dump, const std::string& path, const std::string& package,
+ int64_t versionCode, int64_t startTime, int64_t endTime,
+ const ProfileData* data);
+ static void addToDump(Dump* dump, const std::string& path);
+ static void finishDump(Dump* dump);
+ static void finishDumpInMemory(Dump* dump, AStatsEventList* data, bool lastFullDay);
// Visible for testing
static bool parseFromFile(const std::string& path, protos::GraphicsStatsProto* output);
diff --git a/libs/hwui/shader/BitmapShader.cpp b/libs/hwui/shader/BitmapShader.cpp
new file mode 100644
index 000000000000..fe653e85a021
--- /dev/null
+++ b/libs/hwui/shader/BitmapShader.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "BitmapShader.h"
+
+#include "SkImagePriv.h"
+
+namespace android::uirenderer {
+BitmapShader::BitmapShader(const sk_sp<SkImage>& image, const SkTileMode tileModeX,
+ const SkTileMode tileModeY, const SkMatrix* matrix)
+ : Shader(matrix), skShader(image->makeShader(tileModeX, tileModeY)) {}
+
+sk_sp<SkShader> BitmapShader::makeSkShader() {
+ return skShader;
+}
+
+BitmapShader::~BitmapShader() {}
+} // namespace android::uirenderer \ No newline at end of file
diff --git a/libs/hwui/shader/BitmapShader.h b/libs/hwui/shader/BitmapShader.h
new file mode 100644
index 000000000000..ed6a6e6802d1
--- /dev/null
+++ b/libs/hwui/shader/BitmapShader.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "Shader.h"
+#include "SkShader.h"
+
+namespace android::uirenderer {
+
+/**
+ * Shader implementation that renders a Bitmap as either a SkShader or SkImageFilter
+ */
+class BitmapShader : public Shader {
+public:
+ BitmapShader(const sk_sp<SkImage>& image, const SkTileMode tileModeX,
+ const SkTileMode tileModeY, const SkMatrix* matrix);
+ ~BitmapShader() override;
+
+protected:
+ sk_sp<SkShader> makeSkShader() override;
+
+private:
+ sk_sp<SkShader> skShader;
+};
+} // namespace android::uirenderer \ No newline at end of file
diff --git a/libs/hwui/shader/BlurShader.cpp b/libs/hwui/shader/BlurShader.cpp
new file mode 100644
index 000000000000..fa10be100bca
--- /dev/null
+++ b/libs/hwui/shader/BlurShader.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "BlurShader.h"
+#include "SkImageFilters.h"
+#include "SkRefCnt.h"
+#include "utils/Blur.h"
+
+namespace android::uirenderer {
+BlurShader::BlurShader(float radiusX, float radiusY, Shader* inputShader, const SkMatrix* matrix)
+ : Shader(matrix)
+ , skImageFilter(
+ SkImageFilters::Blur(
+ Blur::convertRadiusToSigma(radiusX),
+ Blur::convertRadiusToSigma(radiusY),
+ SkTileMode::kClamp,
+ inputShader ? inputShader->asSkImageFilter() : nullptr,
+ nullptr)
+ ) { }
+
+sk_sp<SkImageFilter> BlurShader::makeSkImageFilter() {
+ return skImageFilter;
+}
+
+BlurShader::~BlurShader() {}
+
+} // namespace android::uirenderer \ No newline at end of file
diff --git a/libs/hwui/shader/BlurShader.h b/libs/hwui/shader/BlurShader.h
new file mode 100644
index 000000000000..9eb22bd11f4a
--- /dev/null
+++ b/libs/hwui/shader/BlurShader.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#include "Shader.h"
+
+namespace android::uirenderer {
+
+/**
+ * Shader implementation that blurs another Shader instance or the source bitmap
+ */
+class BlurShader : public Shader {
+public:
+ /**
+ * Creates a BlurShader instance with the provided radius values to blur along the x and y
+ * axis accordingly.
+ *
+ * This will blur the contents of the provided input shader if it is non-null, otherwise
+ * the source bitmap will be blurred instead.
+ */
+ BlurShader(float radiusX, float radiusY, Shader* inputShader, const SkMatrix* matrix);
+ ~BlurShader() override;
+protected:
+ sk_sp<SkImageFilter> makeSkImageFilter() override;
+private:
+ sk_sp<SkImageFilter> skImageFilter;
+};
+
+} // namespace android::uirenderer \ No newline at end of file
diff --git a/libs/hwui/shader/ComposeShader.cpp b/libs/hwui/shader/ComposeShader.cpp
new file mode 100644
index 000000000000..3765489e7431
--- /dev/null
+++ b/libs/hwui/shader/ComposeShader.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ComposeShader.h"
+
+#include "SkImageFilters.h"
+#include "SkShader.h"
+
+namespace android::uirenderer {
+
+ComposeShader::ComposeShader(Shader& shaderA, Shader& shaderB, const SkBlendMode blendMode,
+ const SkMatrix* matrix)
+ : Shader(matrix) {
+ // If both Shaders can be represented as SkShaders then use those, if not
+ // create an SkImageFilter from both Shaders and create the equivalent SkImageFilter
+ sk_sp<SkShader> skShaderA = shaderA.asSkShader();
+ sk_sp<SkShader> skShaderB = shaderB.asSkShader();
+ if (skShaderA.get() && skShaderB.get()) {
+ skShader = SkShaders::Blend(blendMode, skShaderA, skShaderB);
+ skImageFilter = nullptr;
+ } else {
+ sk_sp<SkImageFilter> skImageFilterA = shaderA.asSkImageFilter();
+ sk_sp<SkImageFilter> skImageFilterB = shaderB.asSkImageFilter();
+ skShader = nullptr;
+ skImageFilter = SkImageFilters::Xfermode(blendMode, skImageFilterA, skImageFilterB);
+ }
+}
+
+sk_sp<SkShader> ComposeShader::makeSkShader() {
+ return skShader;
+}
+
+sk_sp<SkImageFilter> ComposeShader::makeSkImageFilter() {
+ return skImageFilter;
+}
+
+ComposeShader::~ComposeShader() {}
+} // namespace android::uirenderer
diff --git a/libs/hwui/shader/ComposeShader.h b/libs/hwui/shader/ComposeShader.h
new file mode 100644
index 000000000000..a246b520d46a
--- /dev/null
+++ b/libs/hwui/shader/ComposeShader.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "Shader.h"
+#include "SkShader.h"
+
+namespace android::uirenderer {
+
+/**
+ * Shader implementation that can composite 2 Shaders together with the specified blend mode.
+ * This implementation can appropriately convert the composed result to either an SkShader or
+ * SkImageFilter depending on the inputs
+ */
+class ComposeShader : public Shader {
+public:
+ ComposeShader(Shader& shaderA, Shader& shaderB, const SkBlendMode blendMode,
+ const SkMatrix* matrix);
+ ~ComposeShader() override;
+
+protected:
+ sk_sp<SkShader> makeSkShader() override;
+ sk_sp<SkImageFilter> makeSkImageFilter() override;
+
+private:
+ sk_sp<SkShader> skShader;
+ sk_sp<SkImageFilter> skImageFilter;
+};
+} // namespace android::uirenderer
diff --git a/libs/hwui/shader/LinearGradientShader.cpp b/libs/hwui/shader/LinearGradientShader.cpp
new file mode 100644
index 000000000000..868fa44fb4b7
--- /dev/null
+++ b/libs/hwui/shader/LinearGradientShader.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "LinearGradientShader.h"
+
+#include <vector>
+
+#include "SkGradientShader.h"
+
+namespace android::uirenderer {
+
+LinearGradientShader::LinearGradientShader(const SkPoint pts[2],
+ const std::vector<SkColor4f>& colors,
+ sk_sp<SkColorSpace> colorspace, const SkScalar pos[],
+ const SkTileMode tileMode, const uint32_t shaderFlags,
+ const SkMatrix* matrix)
+ : Shader(matrix)
+ , skShader(SkGradientShader::MakeLinear(pts, colors.data(), colorspace, pos, colors.size(),
+ tileMode, shaderFlags, nullptr)) {}
+
+sk_sp<SkShader> LinearGradientShader::makeSkShader() {
+ return skShader;
+}
+
+LinearGradientShader::~LinearGradientShader() {}
+} // namespace android::uirenderer \ No newline at end of file
diff --git a/libs/hwui/shader/LinearGradientShader.h b/libs/hwui/shader/LinearGradientShader.h
new file mode 100644
index 000000000000..596f4e009448
--- /dev/null
+++ b/libs/hwui/shader/LinearGradientShader.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "Shader.h"
+#include "SkShader.h"
+
+namespace android::uirenderer {
+
+/**
+ * Shader implementation that renders a color ramp of colors to either as either SkShader or
+ * SkImageFilter
+ */
+class LinearGradientShader : public Shader {
+public:
+ LinearGradientShader(const SkPoint pts[2], const std::vector<SkColor4f>& colors,
+ sk_sp<SkColorSpace> colorspace, const SkScalar pos[],
+ const SkTileMode tileMode, const uint32_t shaderFlags,
+ const SkMatrix* matrix);
+ ~LinearGradientShader() override;
+
+protected:
+ sk_sp<SkShader> makeSkShader() override;
+
+private:
+ sk_sp<SkShader> skShader;
+};
+} // namespace android::uirenderer
diff --git a/libs/hwui/shader/RadialGradientShader.cpp b/libs/hwui/shader/RadialGradientShader.cpp
new file mode 100644
index 000000000000..21ff56fee2f8
--- /dev/null
+++ b/libs/hwui/shader/RadialGradientShader.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "RadialGradientShader.h"
+
+#include <vector>
+
+#include "SkGradientShader.h"
+
+namespace android::uirenderer {
+
+RadialGradientShader::RadialGradientShader(const SkPoint& center, const float radius,
+ const std::vector<SkColor4f>& colors,
+ sk_sp<SkColorSpace> colorspace, const SkScalar pos[],
+ const SkTileMode tileMode, const uint32_t shaderFlags,
+ const SkMatrix* matrix)
+ : Shader(matrix)
+ , skShader(SkGradientShader::MakeRadial(center, radius, colors.data(), colorspace, pos,
+ colors.size(), tileMode, shaderFlags, nullptr)) {}
+
+sk_sp<SkShader> RadialGradientShader::makeSkShader() {
+ return skShader;
+}
+
+RadialGradientShader::~RadialGradientShader() {}
+} // namespace android::uirenderer \ No newline at end of file
diff --git a/libs/hwui/shader/RadialGradientShader.h b/libs/hwui/shader/RadialGradientShader.h
new file mode 100644
index 000000000000..9a2ff139aedb
--- /dev/null
+++ b/libs/hwui/shader/RadialGradientShader.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "Shader.h"
+#include "SkShader.h"
+
+namespace android::uirenderer {
+
+/**
+ * Shader implementation that renders a color ramp from the center outward to either as either
+ * a SkShader or SkImageFilter
+ */
+class RadialGradientShader : public Shader {
+public:
+ RadialGradientShader(const SkPoint& center, const float radius,
+ const std::vector<SkColor4f>& colors, sk_sp<SkColorSpace> colorSpace,
+ const SkScalar pos[], const SkTileMode tileMode, const uint32_t shaderFlags,
+ const SkMatrix* matrix);
+ ~RadialGradientShader() override;
+
+protected:
+ sk_sp<SkShader> makeSkShader() override;
+
+private:
+ sk_sp<SkShader> skShader;
+};
+} // namespace android::uirenderer \ No newline at end of file
diff --git a/libs/hwui/shader/RuntimeShader.cpp b/libs/hwui/shader/RuntimeShader.cpp
new file mode 100644
index 000000000000..dd0b6980841a
--- /dev/null
+++ b/libs/hwui/shader/RuntimeShader.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RuntimeShader.h"
+
+#include "SkShader.h"
+#include "include/effects/SkRuntimeEffect.h"
+
+namespace android::uirenderer {
+
+RuntimeShader::RuntimeShader(SkRuntimeEffect& effect, sk_sp<SkData> data, bool isOpaque,
+ const SkMatrix* matrix)
+ : Shader(nullptr)
+ , // Explicitly passing null as RuntimeShader is created with the
+ // matrix directly
+ skShader(effect.makeShader(std::move(data), nullptr, 0, matrix, isOpaque)) {}
+
+sk_sp<SkShader> RuntimeShader::makeSkShader() {
+ return skShader;
+}
+
+RuntimeShader::~RuntimeShader() {}
+} // namespace android::uirenderer \ No newline at end of file
diff --git a/libs/hwui/shader/RuntimeShader.h b/libs/hwui/shader/RuntimeShader.h
new file mode 100644
index 000000000000..7fe0b0206467
--- /dev/null
+++ b/libs/hwui/shader/RuntimeShader.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "Shader.h"
+#include "SkShader.h"
+#include "include/effects/SkRuntimeEffect.h"
+
+namespace android::uirenderer {
+
+/**
+ * RuntimeShader implementation that can map to either a SkShader or SkImageFilter
+ */
+class RuntimeShader : public Shader {
+public:
+ RuntimeShader(SkRuntimeEffect& effect, sk_sp<SkData> data, bool isOpaque,
+ const SkMatrix* matrix);
+ ~RuntimeShader() override;
+
+protected:
+ sk_sp<SkShader> makeSkShader() override;
+
+private:
+ sk_sp<SkShader> skShader;
+};
+} // namespace android::uirenderer
diff --git a/libs/hwui/shader/Shader.cpp b/libs/hwui/shader/Shader.cpp
new file mode 100644
index 000000000000..45123dd55002
--- /dev/null
+++ b/libs/hwui/shader/Shader.cpp
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Shader.h"
+
+#include "SkImageFilters.h"
+#include "SkPaint.h"
+#include "SkRefCnt.h"
+
+namespace android::uirenderer {
+
+Shader::Shader(const SkMatrix* matrix)
+ : localMatrix(matrix ? *matrix : SkMatrix::I())
+ , skShader(nullptr)
+ , skImageFilter(nullptr) {}
+
+Shader::~Shader() {}
+
+sk_sp<SkShader> Shader::asSkShader() {
+ // If we already have created a shader with these parameters just return the existing
+ // shader we have already created
+ if (!this->skShader.get()) {
+ this->skShader = makeSkShader();
+ if (this->skShader.get()) {
+ if (!localMatrix.isIdentity()) {
+ this->skShader = this->skShader->makeWithLocalMatrix(localMatrix);
+ }
+ }
+ }
+ return this->skShader;
+}
+
+/**
+ * By default return null as we cannot convert all visual effects to SkShader instances
+ */
+sk_sp<SkShader> Shader::makeSkShader() {
+ return nullptr;
+}
+
+sk_sp<SkImageFilter> Shader::asSkImageFilter() {
+ // If we already have created an ImageFilter with these parameters just return the existing
+ // ImageFilter we have already created
+ if (!this->skImageFilter.get()) {
+ // Attempt to create an SkImageFilter from the current Shader implementation
+ this->skImageFilter = makeSkImageFilter();
+ if (this->skImageFilter) {
+ if (!localMatrix.isIdentity()) {
+ // If we have created an SkImageFilter and we have a transformation, wrap
+ // the created SkImageFilter to apply the given matrix
+ this->skImageFilter = SkImageFilters::MatrixTransform(
+ localMatrix, kMedium_SkFilterQuality, this->skImageFilter);
+ }
+ } else {
+ // Otherwise if no SkImageFilter implementation is provided, create one from
+ // the result of asSkShader. Note the matrix is already applied to the shader in
+ // this case so just convert it to an SkImageFilter using SkImageFilters::Paint
+ SkPaint paint;
+ paint.setShader(asSkShader());
+ sk_sp<SkImageFilter> paintFilter = SkImageFilters::Paint(paint);
+ this->skImageFilter = SkImageFilters::Xfermode(SkBlendMode::kDstIn,
+ std::move(paintFilter));
+ }
+ }
+ return this->skImageFilter;
+}
+
+/**
+ * By default return null for subclasses to implement. If there is not a direct SkImageFilter
+ * conversion
+ */
+sk_sp<SkImageFilter> Shader::makeSkImageFilter() {
+ return nullptr;
+}
+} // namespace android::uirenderer \ No newline at end of file
diff --git a/libs/hwui/shader/Shader.h b/libs/hwui/shader/Shader.h
new file mode 100644
index 000000000000..6403e1147ded
--- /dev/null
+++ b/libs/hwui/shader/Shader.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "SkImageFilter.h"
+#include "SkShader.h"
+#include "SkPaint.h"
+#include "SkRefCnt.h"
+
+class SkMatrix;
+
+namespace android::uirenderer {
+
+/**
+ * Shader class that can optionally wrap an SkShader or SkImageFilter depending
+ * on the implementation
+ */
+class Shader: public SkRefCnt {
+public:
+ /**
+ * Creates a Shader instance with an optional transformation matrix. The transformation matrix
+ * is copied internally and ownership is unchanged. It is the responsibility of the caller to
+ * deallocate it appropriately.
+ * @param matrix Optional matrix to transform the underlying SkShader or SkImageFilter
+ */
+ Shader(const SkMatrix* matrix);
+ virtual ~Shader();
+
+ /**
+ * Create an SkShader from the current Shader instance or return a previously
+ * created instance. This can be null if no SkShader could be created from this
+ * Shader instance.
+ */
+ sk_sp<SkShader> asSkShader();
+
+ /**
+ * Create an SkImageFilter from the current Shader instance or return a previously
+ * created instance. Unlike asSkShader, this method cannot return null.
+ */
+ sk_sp<SkImageFilter> asSkImageFilter();
+
+protected:
+ /**
+ * Create a new SkShader instance based on this Shader instance
+ */
+ virtual sk_sp<SkShader> makeSkShader();
+
+ /**
+ * Create a new SkImageFilter instance based on this Shader instance. If no SkImageFilter
+ * can be created then return nullptr
+ */
+ virtual sk_sp<SkImageFilter> makeSkImageFilter();
+
+private:
+ /**
+ * Optional matrix transform
+ */
+ const SkMatrix localMatrix;
+
+ /**
+ * Cached SkShader instance to be returned on subsequent queries
+ */
+ sk_sp<SkShader> skShader;
+
+ /**
+ * Cached SkImageFilter instance to be returned on subsequent queries
+ */
+ sk_sp<SkImageFilter> skImageFilter;
+};
+} // namespace android::uirenderer
diff --git a/libs/hwui/shader/SweepGradientShader.cpp b/libs/hwui/shader/SweepGradientShader.cpp
new file mode 100644
index 000000000000..3b1f37f8b051
--- /dev/null
+++ b/libs/hwui/shader/SweepGradientShader.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SweepGradientShader.h"
+
+#include <vector>
+
+#include "SkGradientShader.h"
+#include "SkImageFilters.h"
+
+namespace android::uirenderer {
+
+SweepGradientShader::SweepGradientShader(float x, float y, const std::vector<SkColor4f>& colors,
+ const sk_sp<SkColorSpace>& colorspace, const SkScalar pos[],
+ const uint32_t shaderFlags, const SkMatrix* matrix)
+ : Shader(matrix)
+ , skShader(SkGradientShader::MakeSweep(x, y, colors.data(), colorspace, pos, colors.size(),
+ shaderFlags, nullptr)) {}
+
+sk_sp<SkShader> SweepGradientShader::makeSkShader() {
+ return skShader;
+}
+
+SweepGradientShader::~SweepGradientShader() {}
+} // namespace android::uirenderer \ No newline at end of file
diff --git a/libs/hwui/shader/SweepGradientShader.h b/libs/hwui/shader/SweepGradientShader.h
new file mode 100644
index 000000000000..dad3ef0ffad4
--- /dev/null
+++ b/libs/hwui/shader/SweepGradientShader.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "Shader.h"
+#include "SkShader.h"
+
+namespace android::uirenderer {
+
+/**
+ * Shader implementation that renders a color ramp clockwise such that the start and end colors
+ * are visible at 3 o'clock. This handles converting to either an SkShader or SkImageFilter
+ */
+class SweepGradientShader : public Shader {
+public:
+ SweepGradientShader(float x, float y, const std::vector<SkColor4f>& colors,
+ const sk_sp<SkColorSpace>& colorspace, const SkScalar pos[],
+ const uint32_t shaderFlags, const SkMatrix* matrix);
+ virtual ~SweepGradientShader() override;
+
+protected:
+ virtual sk_sp<SkShader> makeSkShader() override;
+
+private:
+ sk_sp<SkShader> skShader;
+};
+} // namespace android::uirenderer
diff --git a/libs/hwui/tests/common/TestUtils.h b/libs/hwui/tests/common/TestUtils.h
index 91a808df3657..36c5a8c1b3de 100644
--- a/libs/hwui/tests/common/TestUtils.h
+++ b/libs/hwui/tests/common/TestUtils.h
@@ -287,18 +287,6 @@ public:
static std::unique_ptr<uint16_t[]> asciiToUtf16(const char* str);
- class MockFunctor : public Functor {
- public:
- virtual status_t operator()(int what, void* data) {
- mLastMode = what;
- return DrawGlInfo::kStatusDone;
- }
- int getLastMode() const { return mLastMode; }
-
- private:
- int mLastMode = -1;
- };
-
static SkColor getColor(const sk_sp<SkSurface>& surface, int x, int y);
static SkRect getClipBounds(const SkCanvas* canvas);
@@ -311,30 +299,32 @@ public:
int glesDraw = 0;
};
- static void expectOnRenderThread() { EXPECT_EQ(gettid(), TestUtils::getRenderThreadTid()); }
+ static void expectOnRenderThread(const std::string_view& function = "unknown") {
+ EXPECT_EQ(gettid(), TestUtils::getRenderThreadTid()) << "Called on wrong thread: " << function;
+ }
static WebViewFunctorCallbacks createMockFunctor(RenderMode mode) {
auto callbacks = WebViewFunctorCallbacks{
.onSync =
[](int functor, void* client_data, const WebViewSyncData& data) {
- expectOnRenderThread();
+ expectOnRenderThread("onSync");
sMockFunctorCounts[functor].sync++;
},
.onContextDestroyed =
[](int functor, void* client_data) {
- expectOnRenderThread();
+ expectOnRenderThread("onContextDestroyed");
sMockFunctorCounts[functor].contextDestroyed++;
},
.onDestroyed =
[](int functor, void* client_data) {
- expectOnRenderThread();
+ expectOnRenderThread("onDestroyed");
sMockFunctorCounts[functor].destroyed++;
},
};
switch (mode) {
case RenderMode::OpenGL_ES:
callbacks.gles.draw = [](int functor, void* client_data, const DrawGlInfo& params) {
- expectOnRenderThread();
+ expectOnRenderThread("draw");
sMockFunctorCounts[functor].glesDraw++;
};
break;
diff --git a/libs/hwui/tests/common/scenes/BitmapShaders.cpp b/libs/hwui/tests/common/scenes/BitmapShaders.cpp
index c4067af388e3..e2c1651d823a 100644
--- a/libs/hwui/tests/common/scenes/BitmapShaders.cpp
+++ b/libs/hwui/tests/common/scenes/BitmapShaders.cpp
@@ -18,6 +18,7 @@
#include "hwui/Paint.h"
#include "TestSceneBase.h"
#include "tests/common/BitmapAllocationTestUtils.h"
+#include <shader/BitmapShader.h>
#include "utils/Color.h"
class BitmapShaders;
@@ -45,15 +46,24 @@ public:
});
Paint paint;
+ sk_sp<BitmapShader> bitmapShader = sk_make_sp<BitmapShader>(
+ hwuiBitmap->makeImage(),
+ SkTileMode::kRepeat,
+ SkTileMode::kRepeat,
+ nullptr
+ );
+
sk_sp<SkImage> image = hwuiBitmap->makeImage();
- sk_sp<SkShader> repeatShader =
- image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
- paint.setShader(std::move(repeatShader));
+ paint.setShader(std::move(bitmapShader));
canvas.drawRoundRect(0, 0, 500, 500, 50.0f, 50.0f, paint);
- sk_sp<SkShader> mirrorShader =
- image->makeShader(SkTileMode::kMirror, SkTileMode::kMirror);
- paint.setShader(std::move(mirrorShader));
+ sk_sp<BitmapShader> mirrorBitmapShader = sk_make_sp<BitmapShader>(
+ image,
+ SkTileMode::kMirror,
+ SkTileMode::kMirror,
+ nullptr
+ );
+ paint.setShader(std::move(mirrorBitmapShader));
canvas.drawRoundRect(0, 600, 500, 1100, 50.0f, 50.0f, paint);
}
diff --git a/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp b/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp
index 5886ea39acce..d37bc3c7d37c 100644
--- a/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp
+++ b/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp
@@ -20,6 +20,10 @@
#include <SkGradientShader.h>
#include <SkImagePriv.h>
#include <ui/PixelFormat.h>
+#include <shader/BitmapShader.h>
+#include <shader/LinearGradientShader.h>
+#include <shader/RadialGradientShader.h>
+#include <shader/ComposeShader.h>
class HwBitmapInCompositeShader;
@@ -50,20 +54,41 @@ public:
pixels[4000 + 4 * i + 3] = 255;
}
buffer->unlock();
- sk_sp<Bitmap> hardwareBitmap(Bitmap::createFrom(buffer->toAHardwareBuffer(),
- SkColorSpace::MakeSRGB()));
- sk_sp<SkShader> hardwareShader(createBitmapShader(*hardwareBitmap));
+
+ sk_sp<BitmapShader> bitmapShader = sk_make_sp<BitmapShader>(
+ Bitmap::createFrom(
+ buffer->toAHardwareBuffer(),
+ SkColorSpace::MakeSRGB()
+ )->makeImage(),
+ SkTileMode::kClamp,
+ SkTileMode::kClamp,
+ nullptr
+ );
SkPoint center;
center.set(50, 50);
- SkColor colors[2];
- colors[0] = Color::Black;
- colors[1] = Color::White;
- sk_sp<SkShader> gradientShader = SkGradientShader::MakeRadial(
- center, 50, colors, nullptr, 2, SkTileMode::kRepeat);
-
- sk_sp<SkShader> compositeShader(
- SkShaders::Blend(SkBlendMode::kDstATop, hardwareShader, gradientShader));
+
+ std::vector<SkColor4f> vColors(2);
+ vColors[0] = SkColors::kBlack;
+ vColors[1] = SkColors::kWhite;
+
+ sk_sp<RadialGradientShader> radialShader = sk_make_sp<RadialGradientShader>(
+ center,
+ 50,
+ vColors,
+ SkColorSpace::MakeSRGB(),
+ nullptr,
+ SkTileMode::kRepeat,
+ 0,
+ nullptr
+ );
+
+ sk_sp<ComposeShader> compositeShader = sk_make_sp<ComposeShader>(
+ *bitmapShader.get(),
+ *radialShader.get(),
+ SkBlendMode::kDstATop,
+ nullptr
+ );
Paint paint;
paint.setShader(std::move(compositeShader));
diff --git a/libs/hwui/tests/common/scenes/ListOfFadedTextAnimation.cpp b/libs/hwui/tests/common/scenes/ListOfFadedTextAnimation.cpp
index a9449b62a1f8..76e39deedd9a 100644
--- a/libs/hwui/tests/common/scenes/ListOfFadedTextAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/ListOfFadedTextAnimation.cpp
@@ -17,7 +17,8 @@
#include "TestSceneBase.h"
#include "tests/common/TestListViewSceneBase.h"
#include "hwui/Paint.h"
-#include <SkGradientShader.h>
+#include "SkColor.h"
+#include <shader/LinearGradientShader.h>
class ListOfFadedTextAnimation;
@@ -42,15 +43,26 @@ class ListOfFadedTextAnimation : public TestListViewSceneBase {
pts[0].set(0, 0);
pts[1].set(0, 1);
- SkColor colors[2] = {Color::Black, Color::Transparent};
- sk_sp<SkShader> s(
- SkGradientShader::MakeLinear(pts, colors, NULL, 2, SkTileMode::kClamp));
-
SkMatrix matrix;
matrix.setScale(1, length);
matrix.postRotate(-90);
+
+ std::vector<SkColor4f> vColors(2);
+ vColors[0] = SkColors::kBlack;
+ vColors[1] = SkColors::kTransparent;
+
+ sk_sp<LinearGradientShader> linearGradientShader = sk_make_sp<LinearGradientShader>(
+ pts,
+ vColors,
+ SkColorSpace::MakeSRGB(),
+ nullptr,
+ SkTileMode::kClamp,
+ 0,
+ &matrix
+ );
+
Paint fadingPaint;
- fadingPaint.setShader(s->makeWithLocalMatrix(matrix));
+ fadingPaint.setShader(linearGradientShader);
fadingPaint.setBlendMode(SkBlendMode::kDstOut);
canvas.drawRect(0, 0, length, itemHeight, fadingPaint);
canvas.restore();
diff --git a/libs/hwui/tests/common/scenes/MagnifierAnimation.cpp b/libs/hwui/tests/common/scenes/MagnifierAnimation.cpp
index f4fce277454d..edadf78db051 100644
--- a/libs/hwui/tests/common/scenes/MagnifierAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/MagnifierAnimation.cpp
@@ -56,9 +56,9 @@ public:
(float)magnifier->height(), 0, 0, (float)props.getWidth(),
(float)props.getHeight(), nullptr);
});
- canvas.insertReorderBarrier(true);
+ canvas.enableZ(true);
canvas.drawRenderNode(zoomImageView.get());
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(false);
}
void doFrame(int frameNr) override {
diff --git a/libs/hwui/tests/common/scenes/RecentsAnimation.cpp b/libs/hwui/tests/common/scenes/RecentsAnimation.cpp
index 3480a0f18407..1c2507867f6e 100644
--- a/libs/hwui/tests/common/scenes/RecentsAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/RecentsAnimation.cpp
@@ -36,7 +36,7 @@ public:
int cardsize = std::min(width, height) - dp(64);
renderer.drawColor(Color::White, SkBlendMode::kSrcOver);
- renderer.insertReorderBarrier(true);
+ renderer.enableZ(true);
int x = dp(32);
for (int i = 0; i < 4; i++) {
@@ -52,7 +52,7 @@ public:
mCards.push_back(card);
}
- renderer.insertReorderBarrier(false);
+ renderer.enableZ(false);
}
void doFrame(int frameNr) override {
diff --git a/libs/hwui/tests/common/scenes/RectGridAnimation.cpp b/libs/hwui/tests/common/scenes/RectGridAnimation.cpp
index 80b5cc191089..f37bcbc3ee1b 100644
--- a/libs/hwui/tests/common/scenes/RectGridAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/RectGridAnimation.cpp
@@ -29,7 +29,7 @@ public:
sp<RenderNode> card;
void createContent(int width, int height, Canvas& canvas) override {
canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver);
- canvas.insertReorderBarrier(true);
+ canvas.enableZ(true);
card = TestUtils::createNode(50, 50, 250, 250, [](RenderProperties& props, Canvas& canvas) {
canvas.drawColor(0xFFFF00FF, SkBlendMode::kSrcOver);
@@ -47,7 +47,7 @@ public:
});
canvas.drawRenderNode(card.get());
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(false);
}
void doFrame(int frameNr) override {
int curFrame = frameNr % 150;
diff --git a/libs/hwui/tests/common/scenes/RoundRectClippingAnimation.cpp b/libs/hwui/tests/common/scenes/RoundRectClippingAnimation.cpp
index 314e922e9f38..163745b04ed2 100644
--- a/libs/hwui/tests/common/scenes/RoundRectClippingAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/RoundRectClippingAnimation.cpp
@@ -27,7 +27,7 @@ public:
std::vector<sp<RenderNode> > cards;
void createContent(int width, int height, Canvas& canvas) override {
canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver);
- canvas.insertReorderBarrier(true);
+ canvas.enableZ(true);
int ci = 0;
for (int x = 0; x < width; x += mSpacing) {
@@ -45,7 +45,7 @@ public:
}
}
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(false);
}
void doFrame(int frameNr) override {
int curFrame = frameNr % 50;
diff --git a/libs/hwui/tests/common/scenes/ShadowGrid2Animation.cpp b/libs/hwui/tests/common/scenes/ShadowGrid2Animation.cpp
index bdc991ba1890..c13e80e8c204 100644
--- a/libs/hwui/tests/common/scenes/ShadowGrid2Animation.cpp
+++ b/libs/hwui/tests/common/scenes/ShadowGrid2Animation.cpp
@@ -29,7 +29,7 @@ public:
std::vector<sp<RenderNode> > cards;
void createContent(int width, int height, Canvas& canvas) override {
canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver);
- canvas.insertReorderBarrier(true);
+ canvas.enableZ(true);
for (int x = dp(8); x < (width - dp(58)); x += dp(58)) {
for (int y = dp(8); y < (height - dp(58)); y += dp(58)) {
@@ -39,7 +39,7 @@ public:
}
}
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(false);
}
void doFrame(int frameNr) override {
int curFrame = frameNr % 150;
diff --git a/libs/hwui/tests/common/scenes/ShadowGridAnimation.cpp b/libs/hwui/tests/common/scenes/ShadowGridAnimation.cpp
index a12fd4d69280..772b98e32220 100644
--- a/libs/hwui/tests/common/scenes/ShadowGridAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/ShadowGridAnimation.cpp
@@ -29,7 +29,7 @@ public:
std::vector<sp<RenderNode> > cards;
void createContent(int width, int height, Canvas& canvas) override {
canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver);
- canvas.insertReorderBarrier(true);
+ canvas.enableZ(true);
for (int x = dp(16); x < (width - dp(116)); x += dp(116)) {
for (int y = dp(16); y < (height - dp(116)); y += dp(116)) {
@@ -39,7 +39,7 @@ public:
}
}
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(false);
}
void doFrame(int frameNr) override {
int curFrame = frameNr % 150;
diff --git a/libs/hwui/tests/common/scenes/ShadowShaderAnimation.cpp b/libs/hwui/tests/common/scenes/ShadowShaderAnimation.cpp
index 9f599100200e..0019da5fd80b 100644
--- a/libs/hwui/tests/common/scenes/ShadowShaderAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/ShadowShaderAnimation.cpp
@@ -29,7 +29,7 @@ public:
std::vector<sp<RenderNode> > cards;
void createContent(int width, int height, Canvas& canvas) override {
canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver);
- canvas.insertReorderBarrier(true);
+ canvas.enableZ(true);
int outset = 50;
for (int i = 0; i < 10; i++) {
@@ -39,7 +39,7 @@ public:
cards.push_back(card);
}
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(false);
}
void doFrame(int frameNr) override {
int curFrame = frameNr % 10;
diff --git a/libs/hwui/tests/common/scenes/SimpleColorMatrixAnimation.cpp b/libs/hwui/tests/common/scenes/SimpleColorMatrixAnimation.cpp
index a0bc5aa245d5..bdc157f85264 100644
--- a/libs/hwui/tests/common/scenes/SimpleColorMatrixAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/SimpleColorMatrixAnimation.cpp
@@ -17,7 +17,7 @@
#include "TestSceneBase.h"
#include <SkColorMatrixFilter.h>
-#include <SkGradientShader.h>
+#include <shader/LinearGradientShader.h>
class SimpleColorMatrixAnimation;
@@ -65,9 +65,12 @@ private:
// enough renderer might apply it directly to the paint color)
float pos[] = {0, 1};
SkPoint pts[] = {SkPoint::Make(0, 0), SkPoint::Make(width, height)};
- SkColor colors[2] = {Color::DeepPurple_500, Color::DeepOrange_500};
- paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2,
- SkTileMode::kClamp));
+ std::vector<SkColor4f> colors(2);
+ colors[0] = SkColor4f::FromColor(Color::DeepPurple_500);
+ colors[1] = SkColor4f::FromColor(Color::DeepOrange_500);
+ paint.setShader(sk_make_sp<LinearGradientShader>(
+ pts, colors, SkColorSpace::MakeSRGB(), pos, SkTileMode::kClamp,
+ 0, nullptr));
// overdraw several times to emphasize shader cost
for (int i = 0; i < 10; i++) {
diff --git a/libs/hwui/tests/common/scenes/SimpleGradientAnimation.cpp b/libs/hwui/tests/common/scenes/SimpleGradientAnimation.cpp
index 57a260c8d234..9a15c9d370a4 100644
--- a/libs/hwui/tests/common/scenes/SimpleGradientAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/SimpleGradientAnimation.cpp
@@ -17,6 +17,7 @@
#include "TestSceneBase.h"
#include <SkGradientShader.h>
+#include <shader/LinearGradientShader.h>
class SimpleGradientAnimation;
@@ -55,9 +56,24 @@ private:
// overdraw several times to emphasize shader cost
for (int i = 0; i < 10; i++) {
// use i%2 start position to pick 2 color combo with black in it
- SkColor colors[3] = {Color::Transparent, Color::Black, Color::Cyan_500};
- paint.setShader(SkGradientShader::MakeLinear(pts, colors + (i % 2), pos, 2,
- SkTileMode::kClamp));
+ std::vector<SkColor4f> vColors(2);
+ vColors[0] = ((i % 2) == 0) ?
+ SkColor4f::FromColor(Color::Transparent) :
+ SkColor4f::FromColor(Color::Black);
+ vColors[1] = (((i + 1) % 2) == 0) ?
+ SkColor4f::FromColor(Color::Black) :
+ SkColor4f::FromColor(Color::Cyan_500);
+
+ sk_sp<LinearGradientShader> gradient = sk_make_sp<LinearGradientShader>(
+ pts,
+ vColors,
+ SkColorSpace::MakeSRGB(),
+ pos,
+ SkTileMode::kClamp,
+ 0,
+ nullptr
+ );
+ paint.setShader(gradient);
canvas.drawRect(i, i, width, height, paint);
}
});
diff --git a/libs/hwui/tests/common/scenes/TvApp.cpp b/libs/hwui/tests/common/scenes/TvApp.cpp
index bac887053d2f..1b0a07a98b3f 100644
--- a/libs/hwui/tests/common/scenes/TvApp.cpp
+++ b/libs/hwui/tests/common/scenes/TvApp.cpp
@@ -67,7 +67,7 @@ public:
mBg = createBitmapNode(canvas, 0xFF9C27B0, 0, 0, width, height);
canvas.drawRenderNode(mBg.get());
- canvas.insertReorderBarrier(true);
+ canvas.enableZ(true);
mSingleBitmap = mAllocator(dp(160), dp(120), kRGBA_8888_SkColorType,
[](SkBitmap& skBitmap) { skBitmap.eraseColor(0xFF0000FF); });
@@ -80,7 +80,7 @@ public:
mCards.push_back(card);
}
}
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(false);
}
void doFrame(int frameNr) override {
diff --git a/libs/hwui/tests/microbench/DisplayListCanvasBench.cpp b/libs/hwui/tests/microbench/DisplayListCanvasBench.cpp
index 4ce6c32470ea..d393c693c774 100644
--- a/libs/hwui/tests/microbench/DisplayListCanvasBench.cpp
+++ b/libs/hwui/tests/microbench/DisplayListCanvasBench.cpp
@@ -133,14 +133,14 @@ void BM_DisplayListCanvas_basicViewGroupDraw(benchmark::State& benchState) {
int clipRestoreCount = canvas->save(SaveFlags::MatrixClip);
canvas->clipRect(1, 1, 199, 199, SkClipOp::kIntersect);
- canvas->insertReorderBarrier(true);
+ canvas->enableZ(true);
// Draw child loop
for (int i = 0; i < benchState.range(0); i++) {
canvas->drawRenderNode(child.get());
}
- canvas->insertReorderBarrier(false);
+ canvas->enableZ(false);
canvas->restoreToCount(clipRestoreCount);
delete canvas->finishRecording();
diff --git a/libs/hwui/tests/scripts/prep_generic.sh b/libs/hwui/tests/scripts/prep_generic.sh
index 223bf373c65a..89826ff69463 100755
--- a/libs/hwui/tests/scripts/prep_generic.sh
+++ b/libs/hwui/tests/scripts/prep_generic.sh
@@ -28,11 +28,17 @@
# performance between different device models.
# Fun notes for maintaining this file:
-# `expr` can deal with ints > INT32_MAX, but if compares cannot. This is why we use MHz.
-# `expr` can sometimes evaluate right-to-left. This is why we use parens.
+# $((arithmetic expressions)) can deal with ints > INT32_MAX, but if compares cannot. This is
+# why we use MHz.
+# $((arithmetic expressions)) can sometimes evaluate right-to-left. This is why we use parens.
# Everything below the initial host-check isn't bash - Android uses mksh
# mksh allows `\n` in an echo, bash doesn't
# can't use `awk`
+# can't use `sed`
+# can't use `cut` on < L
+# can't use `expr` on < L
+
+ARG_CORES=${1:-big}
CPU_TARGET_FREQ_PERCENT=50
GPU_TARGET_FREQ_PERCENT=50
@@ -43,7 +49,7 @@ if [ "`command -v getprop`" == "" ]; then
echo "Pushing $0 and running it on device..."
dest=/data/local/tmp/`basename $0`
adb push $0 ${dest}
- adb shell ${dest}
+ adb shell ${dest} $@
adb shell rm ${dest}
exit
else
@@ -56,7 +62,7 @@ if [ "`command -v getprop`" == "" ]; then
fi
# require root
-if [ "`id -u`" -ne "0" ]; then
+if [[ `id` != "uid=0"* ]]; then
echo "Not running as root, cannot lock clocks, aborting"
exit -1
fi
@@ -64,74 +70,175 @@ fi
DEVICE=`getprop ro.product.device`
MODEL=`getprop ro.product.model`
-# Find CPU max frequency, and lock big cores to an available frequency
-# that's >= $CPU_TARGET_FREQ_PERCENT% of max. Disable other cores.
+if [ "$ARG_CORES" == "big" ]; then
+ CPU_IDEAL_START_FREQ_KHZ=0
+elif [ "$ARG_CORES" == "little" ]; then
+ CPU_IDEAL_START_FREQ_KHZ=100000000 ## finding min of max freqs, so start at 100M KHz (100 GHz)
+else
+ echo "Invalid argument \$1 for ARG_CORES, should be 'big' or 'little', but was $ARG_CORES"
+ exit -1
+fi
+
+function_core_check() {
+ if [ "$ARG_CORES" == "big" ]; then
+ [ $1 -gt $2 ]
+ elif [ "$ARG_CORES" == "little" ]; then
+ [ $1 -lt $2 ]
+ else
+ echo "Invalid argument \$1 for ARG_CORES, should be 'big' or 'little', but was $ARG_CORES"
+ exit -1
+ fi
+}
+
+function_setup_go() {
+ if [ -f /d/fpsgo/common/force_onoff ]; then
+ # Disable fpsgo
+ echo 0 > /d/fpsgo/common/force_onoff
+ fpsgoState=`cat /d/fpsgo/common/force_onoff`
+ if [ "$fpsgoState" != "0" ] && [ "$fpsgoState" != "force off" ]; then
+ echo "Failed to disable fpsgo"
+ exit -1
+ fi
+ fi
+}
+
+# Find the min or max (little vs big) of CPU max frequency, and lock cores of the selected type to
+# an available frequency that's >= $CPU_TARGET_FREQ_PERCENT% of max. Disable other cores.
function_lock_cpu() {
CPU_BASE=/sys/devices/system/cpu
GOV=cpufreq/scaling_governor
+ # Options to make clock locking on go devices more sticky.
+ function_setup_go
+
# Find max CPU freq, and associated list of available freqs
- cpuMaxFreq=0
+ cpuIdealFreq=$CPU_IDEAL_START_FREQ_KHZ
cpuAvailFreqCmpr=0
cpuAvailFreq=0
enableIndices=''
disableIndices=''
cpu=0
- while [ -f ${CPU_BASE}/cpu${cpu}/online ]; do
- # enable core, so we can find its frequencies
- echo 1 > ${CPU_BASE}/cpu${cpu}/online
+ while [ -d ${CPU_BASE}/cpu${cpu}/cpufreq ]; do
+ # Try to enable core, so we can find its frequencies.
+ # Note: In cases where the online file is inaccessible, it represents a
+ # core which cannot be turned off, so we simply assume it is enabled if
+ # this command fails.
+ if [ -f "$CPU_BASE/cpu$cpu/online" ]; then
+ echo 1 > ${CPU_BASE}/cpu${cpu}/online || true
+ fi
+
+ # set userspace governor on all CPUs to ensure freq scaling is disabled
+ echo userspace > ${CPU_BASE}/cpu${cpu}/${GOV}
maxFreq=`cat ${CPU_BASE}/cpu$cpu/cpufreq/cpuinfo_max_freq`
availFreq=`cat ${CPU_BASE}/cpu$cpu/cpufreq/scaling_available_frequencies`
availFreqCmpr=${availFreq// /-}
- if [ ${maxFreq} -gt ${cpuMaxFreq} ]; then
- # new highest max freq, look for cpus with same max freq and same avail freq list
- cpuMaxFreq=${maxFreq}
+ if (function_core_check $maxFreq $cpuIdealFreq); then
+ # new min/max of max freq, look for cpus with same max freq and same avail freq list
+ cpuIdealFreq=${maxFreq}
cpuAvailFreq=${availFreq}
cpuAvailFreqCmpr=${availFreqCmpr}
- if [ -z ${disableIndices} ]; then
+ if [ -z "$disableIndices" ]; then
disableIndices="$enableIndices"
else
disableIndices="$disableIndices $enableIndices"
fi
enableIndices=${cpu}
- elif [ ${maxFreq} == ${cpuMaxFreq} ] && [ ${availFreqCmpr} == ${cpuAvailFreqCmpr} ]; then
+ elif [ ${maxFreq} == ${cpuIdealFreq} ] && [ ${availFreqCmpr} == ${cpuAvailFreqCmpr} ]; then
enableIndices="$enableIndices $cpu"
else
- disableIndices="$disableIndices $cpu"
+ if [ -z "$disableIndices" ]; then
+ disableIndices="$cpu"
+ else
+ disableIndices="$disableIndices $cpu"
+ fi
fi
+
cpu=$(($cpu + 1))
done
+ # check that some CPUs will be enabled
+ if [ -z "$enableIndices" ]; then
+ echo "Failed to find any $ARG_CORES cores to enable, aborting."
+ exit -1
+ fi
+
# Chose a frequency to lock to that's >= $CPU_TARGET_FREQ_PERCENT% of max
# (below, 100M = 1K for KHz->MHz * 100 for %)
- TARGET_FREQ_MHZ=`expr \( ${cpuMaxFreq} \* ${CPU_TARGET_FREQ_PERCENT} \) \/ 100000`
+ TARGET_FREQ_MHZ=$(( ($cpuIdealFreq * $CPU_TARGET_FREQ_PERCENT) / 100000 ))
chosenFreq=0
+ chosenFreqDiff=100000000
for freq in ${cpuAvailFreq}; do
- freqMhz=`expr ${freq} \/ 1000`
+ freqMhz=$(( ${freq} / 1000 ))
if [ ${freqMhz} -ge ${TARGET_FREQ_MHZ} ]; then
- chosenFreq=${freq}
- break
+ newChosenFreqDiff=$(( $freq - $TARGET_FREQ_MHZ ))
+ if [ $newChosenFreqDiff -lt $chosenFreqDiff ]; then
+ chosenFreq=${freq}
+ chosenFreqDiff=$(( $chosenFreq - $TARGET_FREQ_MHZ ))
+ fi
fi
done
+ # Lock wembley clocks using high-priority op code method.
+ # This block depends on the shell utility awk, which is only available on API 27+
+ if [ "$DEVICE" == "wembley" ]; then
+ # Get list of available frequencies to lock to by parsing the op-code list.
+ AVAIL_OP_FREQS=`cat /proc/cpufreq/MT_CPU_DVFS_LL/cpufreq_oppidx \
+ | awk '{print $2}' \
+ | tail -n +3 \
+ | while read line; do
+ echo "${line:1:${#line}-2}"
+ done`
+
+ # Compute the closest available frequency to the desired frequency, $chosenFreq.
+ # This assumes the op codes listen in /proc/cpufreq/MT_CPU_DVFS_LL/cpufreq_oppidx are listed
+ # in order and 0-indexed.
+ opCode=-1
+ opFreq=0
+ currOpCode=-1
+ for currOpFreq in $AVAIL_OP_FREQS; do
+ currOpCode=$((currOpCode + 1))
+
+ prevDiff=$((chosenFreq-opFreq))
+ prevDiff=`function_abs $prevDiff`
+ currDiff=$((chosenFreq-currOpFreq))
+ currDiff=`function_abs $currDiff`
+ if [ $currDiff -lt $prevDiff ]; then
+ opCode="$currOpCode"
+ opFreq="$currOpFreq"
+ fi
+ done
+
+ echo "$opCode" > /proc/ppm/policy/ut_fix_freq_idx
+ fi
+
# enable 'big' CPUs
for cpu in ${enableIndices}; do
freq=${CPU_BASE}/cpu$cpu/cpufreq
- echo 1 > ${CPU_BASE}/cpu${cpu}/online
- echo userspace > ${CPU_BASE}/cpu${cpu}/${GOV}
+ # Try to enable core, so we can find its frequencies.
+ # Note: In cases where the online file is inaccessible, it represents a
+ # core which cannot be turned off, so we simply assume it is enabled if
+ # this command fails.
+ if [ -f "$CPU_BASE/cpu$cpu/online" ]; then
+ echo 1 > ${CPU_BASE}/cpu${cpu}/online || true
+ fi
+
+ # scaling_max_freq must be set before scaling_min_freq
echo ${chosenFreq} > ${freq}/scaling_max_freq
echo ${chosenFreq} > ${freq}/scaling_min_freq
echo ${chosenFreq} > ${freq}/scaling_setspeed
+ # Give system a bit of time to propagate the change to scaling_setspeed.
+ sleep 0.1
+
# validate setting the freq worked
obsCur=`cat ${freq}/scaling_cur_freq`
obsMin=`cat ${freq}/scaling_min_freq`
obsMax=`cat ${freq}/scaling_max_freq`
- if [ obsCur -ne ${chosenFreq} ] || [ obsMin -ne ${chosenFreq} ] || [ obsMax -ne ${chosenFreq} ]; then
+ if [ "$obsCur" -ne "$chosenFreq" ] || [ "$obsMin" -ne "$chosenFreq" ] || [ "$obsMax" -ne "$chosenFreq" ]; then
echo "Failed to set CPU$cpu to $chosenFreq Hz! Aborting..."
echo "scaling_cur_freq = $obsCur"
echo "scaling_min_freq = $obsMin"
@@ -145,8 +252,20 @@ function_lock_cpu() {
echo 0 > ${CPU_BASE}/cpu${cpu}/online
done
- echo "\nLocked CPUs ${enableIndices// /,} to $chosenFreq / $maxFreq KHz"
+ echo "=================================="
+ echo "Locked CPUs ${enableIndices// /,} to $chosenFreq / $cpuIdealFreq KHz"
echo "Disabled CPUs ${disableIndices// /,}"
+ echo "=================================="
+}
+
+# Returns the absolute value of the first arg passed to this helper.
+function_abs() {
+ n=$1
+ if [ $n -lt 0 ]; then
+ echo "$((n * -1 ))"
+ else
+ echo "$n"
+ fi
}
# If we have a Qualcomm GPU, find its max frequency, and lock to
@@ -154,12 +273,12 @@ function_lock_cpu() {
function_lock_gpu_kgsl() {
if [ ! -d /sys/class/kgsl/kgsl-3d0/ ]; then
# not kgsl, abort
- echo "\nCurrently don't support locking GPU clocks of $MODEL ($DEVICE)"
+ echo "Currently don't support locking GPU clocks of $MODEL ($DEVICE)"
return -1
fi
if [ ${DEVICE} == "walleye" ] || [ ${DEVICE} == "taimen" ]; then
# Workaround crash
- echo "\nUnable to lock GPU clocks of $MODEL ($DEVICE)"
+ echo "Unable to lock GPU clocks of $MODEL ($DEVICE)"
return -1
fi
@@ -174,13 +293,13 @@ function_lock_gpu_kgsl() {
done
# (below, 100M = 1M for MHz * 100 for %)
- TARGET_FREQ_MHZ=`expr \( ${gpuMaxFreq} \* ${GPU_TARGET_FREQ_PERCENT} \) \/ 100000000`
+ TARGET_FREQ_MHZ=$(( (${gpuMaxFreq} * ${GPU_TARGET_FREQ_PERCENT}) / 100000000 ))
chosenFreq=${gpuMaxFreq}
index=0
chosenIndex=0
for freq in ${gpuAvailFreq}; do
- freqMhz=`expr ${freq} \/ 1000000`
+ freqMhz=$(( ${freq} / 1000000 ))
if [ ${freqMhz} -ge ${TARGET_FREQ_MHZ} ] && [ ${chosenFreq} -ge ${freq} ]; then
# note avail freq are generally in reverse order, so we don't break out of this loop
chosenFreq=${freq}
@@ -190,7 +309,7 @@ function_lock_gpu_kgsl() {
done
lastIndex=$(($index - 1))
- firstFreq=`echo $gpuAvailFreq | cut -d" " -f1`
+ firstFreq=`function_cut_first_from_space_seperated_list $gpuAvailFreq`
if [ ${gpuMaxFreq} != ${firstFreq} ]; then
# pwrlevel is index of desired freq among available frequencies, from highest to lowest.
@@ -226,24 +345,40 @@ function_lock_gpu_kgsl() {
echo "index = $chosenIndex"
exit -1
fi
- echo "\nLocked GPU to $chosenFreq / $gpuMaxFreq Hz"
+ echo "Locked GPU to $chosenFreq / $gpuMaxFreq Hz"
+}
+
+# cut is not available on some devices (Nexus 5 running LRX22C).
+function_cut_first_from_space_seperated_list() {
+ list=$1
+
+ for freq in $list; do
+ echo $freq
+ break
+ done
}
# kill processes that manage thermals / scaling
-stop thermal-engine
-stop perfd
-stop vendor.thermal-engine
-stop vendor.perfd
+stop thermal-engine || true
+stop perfd || true
+stop vendor.thermal-engine || true
+stop vendor.perfd || true
+setprop vendor.powerhal.init 0 || true
+setprop ctl.interface_restart android.hardware.power@1.0::IPower/default || true
function_lock_cpu
-function_lock_gpu_kgsl
+if [ "$DEVICE" -ne "wembley" ]; then
+ function_lock_gpu_kgsl
+else
+ echo "Unable to lock gpu clocks of $MODEL ($DEVICE)."
+fi
# Memory bus - hardcoded per-device for now
if [ ${DEVICE} == "marlin" ] || [ ${DEVICE} == "sailfish" ]; then
echo 13763 > /sys/class/devfreq/soc:qcom,gpubw/max_freq
else
- echo "\nUnable to lock memory bus of $MODEL ($DEVICE)."
+ echo "Unable to lock memory bus of $MODEL ($DEVICE)."
fi
-echo "\n$DEVICE clocks have been locked - to reset, reboot the device\n" \ No newline at end of file
+echo "$DEVICE clocks have been locked - to reset, reboot the device"
diff --git a/libs/hwui/tests/unit/CacheManagerTests.cpp b/libs/hwui/tests/unit/CacheManagerTests.cpp
index c83a3c88cbdd..edd3e4e4f4d4 100644
--- a/libs/hwui/tests/unit/CacheManagerTests.cpp
+++ b/libs/hwui/tests/unit/CacheManagerTests.cpp
@@ -26,7 +26,7 @@ using namespace android;
using namespace android::uirenderer;
using namespace android::uirenderer::renderthread;
-static size_t getCacheUsage(GrContext* grContext) {
+static size_t getCacheUsage(GrDirectContext* grContext) {
size_t cacheUsage;
grContext->getResourceCacheUsage(nullptr, &cacheUsage);
return cacheUsage;
@@ -35,7 +35,7 @@ static size_t getCacheUsage(GrContext* grContext) {
RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, trimMemory) {
int32_t width = DeviceInfo::get()->getWidth();
int32_t height = DeviceInfo::get()->getHeight();
- GrContext* grContext = renderThread.getGrContext();
+ GrDirectContext* grContext = renderThread.getGrContext();
ASSERT_TRUE(grContext != nullptr);
// create pairs of offscreen render targets and images until we exceed the
@@ -47,7 +47,7 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, trimMemory) {
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(grContext, SkBudgeted::kYes, info);
surface->getCanvas()->drawColor(SK_AlphaTRANSPARENT);
- grContext->flush();
+ grContext->flushAndSubmit();
surfaces.push_back(surface);
}
diff --git a/libs/hwui/tests/unit/CanvasContextTests.cpp b/libs/hwui/tests/unit/CanvasContextTests.cpp
index 28cff5b9b154..1771c3590e10 100644
--- a/libs/hwui/tests/unit/CanvasContextTests.cpp
+++ b/libs/hwui/tests/unit/CanvasContextTests.cpp
@@ -42,14 +42,3 @@ RENDERTHREAD_TEST(CanvasContext, create) {
canvasContext->destroy();
}
-
-RENDERTHREAD_TEST(CanvasContext, invokeFunctor) {
- TestUtils::MockFunctor functor;
- CanvasContext::invokeFunctor(renderThread, &functor);
- if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaVulkan) {
- // we currently don't support OpenGL WebViews on the Vulkan backend
- ASSERT_EQ(functor.getLastMode(), DrawGlInfo::kModeProcessNoContext);
- } else {
- ASSERT_EQ(functor.getLastMode(), DrawGlInfo::kModeProcess);
- }
-}
diff --git a/libs/hwui/tests/unit/FatalTestCanvas.h b/libs/hwui/tests/unit/FatalTestCanvas.h
index 1723c2eb4948..76ae0853b477 100644
--- a/libs/hwui/tests/unit/FatalTestCanvas.h
+++ b/libs/hwui/tests/unit/FatalTestCanvas.h
@@ -81,21 +81,6 @@ public:
const SkPaint*) {
ADD_FAILURE() << "onDrawImageLattice not expected in this test";
}
- void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*) {
- ADD_FAILURE() << "onDrawBitmap not expected in this test";
- }
- void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
- SrcRectConstraint) {
- ADD_FAILURE() << "onDrawBitmapRect not expected in this test";
- }
- void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
- const SkPaint*) {
- ADD_FAILURE() << "onDrawBitmapNine not expected in this test";
- }
- void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst,
- const SkPaint*) {
- ADD_FAILURE() << "onDrawBitmapLattice not expected in this test";
- }
void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) {
ADD_FAILURE() << "onClipRRect not expected in this test";
}
diff --git a/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp b/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp
index 3632be06c45f..7aa6be8722cf 100644
--- a/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp
+++ b/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp
@@ -108,27 +108,27 @@ protected:
TEST(RenderNodeDrawable, zReorder) {
auto parent = TestUtils::createSkiaNode(0, 0, 100, 100, [](RenderProperties& props,
SkiaRecordingCanvas& canvas) {
- canvas.insertReorderBarrier(true);
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(true);
+ canvas.enableZ(false);
drawOrderedNode(&canvas, 0, 10.0f); // in reorder=false at this point, so played inorder
drawOrderedRect(&canvas, 1);
- canvas.insertReorderBarrier(true);
+ canvas.enableZ(true);
drawOrderedNode(&canvas, 6, 2.0f);
drawOrderedRect(&canvas, 3);
drawOrderedNode(&canvas, 4, 0.0f);
drawOrderedRect(&canvas, 5);
drawOrderedNode(&canvas, 2, -2.0f);
drawOrderedNode(&canvas, 7, 2.0f);
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(false);
drawOrderedRect(&canvas, 8);
drawOrderedNode(&canvas, 9, -10.0f); // in reorder=false at this point, so played inorder
- canvas.insertReorderBarrier(true); // reorder a node ahead of drawrect op
+ canvas.enableZ(true); // reorder a node ahead of drawrect op
drawOrderedRect(&canvas, 11);
drawOrderedNode(&canvas, 10, -1.0f);
- canvas.insertReorderBarrier(false);
- canvas.insertReorderBarrier(true); // test with two empty reorder sections
- canvas.insertReorderBarrier(true);
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(false);
+ canvas.enableZ(true); // test with two empty reorder sections
+ canvas.enableZ(true);
+ canvas.enableZ(false);
drawOrderedRect(&canvas, 12);
});
@@ -1142,7 +1142,7 @@ TEST(ReorderBarrierDrawable, testShadowMatrix) {
0, 0, CANVAS_WIDTH, CANVAS_HEIGHT,
[](RenderProperties& props, SkiaRecordingCanvas& canvas) {
canvas.translate(TRANSLATE_X, TRANSLATE_Y);
- canvas.insertReorderBarrier(true);
+ canvas.enableZ(true);
auto node = TestUtils::createSkiaNode(
CASTER_X, CASTER_Y, CASTER_X + CASTER_WIDTH, CASTER_Y + CASTER_HEIGHT,
@@ -1152,7 +1152,7 @@ TEST(ReorderBarrierDrawable, testShadowMatrix) {
props.mutableOutline().setShouldClip(true);
});
canvas.drawRenderNode(node.get());
- canvas.insertReorderBarrier(false);
+ canvas.enableZ(false);
});
// create a canvas not backed by any device/pixels, but with dimensions to avoid quick rejection
@@ -1169,7 +1169,7 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(SkiaRecordingCanvas, drawVectorDrawable) {
class VectorDrawableTestCanvas : public TestCanvasBase {
public:
VectorDrawableTestCanvas() : TestCanvasBase(CANVAS_WIDTH, CANVAS_HEIGHT) {}
- void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
+ void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint) override {
const int index = mDrawCounter++;
switch (index) {
diff --git a/libs/hwui/tests/unit/RenderNodeTests.cpp b/libs/hwui/tests/unit/RenderNodeTests.cpp
index 1cd9bd8ee9d9..c19e1ed6ce75 100644
--- a/libs/hwui/tests/unit/RenderNodeTests.cpp
+++ b/libs/hwui/tests/unit/RenderNodeTests.cpp
@@ -231,39 +231,41 @@ TEST(RenderNode, multiTreeValidity) {
}
TEST(RenderNode, releasedCallback) {
- class DecRefOnReleased : public GlFunctorLifecycleListener {
- public:
- explicit DecRefOnReleased(int* refcnt) : mRefCnt(refcnt) {}
- void onGlFunctorReleased(Functor* functor) override { *mRefCnt -= 1; }
-
- private:
- int* mRefCnt;
- };
-
- int refcnt = 0;
- sp<DecRefOnReleased> listener(new DecRefOnReleased(&refcnt));
- Functor noopFunctor;
+ int functor = WebViewFunctor_create(
+ nullptr, TestUtils::createMockFunctor(RenderMode::OpenGL_ES), RenderMode::OpenGL_ES);
auto node = TestUtils::createNode(0, 0, 200, 400, [&](RenderProperties& props, Canvas& canvas) {
- refcnt++;
- canvas.callDrawGLFunction(&noopFunctor, listener.get());
+ canvas.drawWebViewFunctor(functor);
+ });
+ TestUtils::runOnRenderThreadUnmanaged([&] (RenderThread&) {
+ TestUtils::syncHierarchyPropertiesAndDisplayList(node);
});
- TestUtils::syncHierarchyPropertiesAndDisplayList(node);
- EXPECT_EQ(1, refcnt);
+ auto& counts = TestUtils::countsForFunctor(functor);
+ EXPECT_EQ(1, counts.sync);
+ EXPECT_EQ(0, counts.destroyed);
TestUtils::recordNode(*node, [&](Canvas& canvas) {
- refcnt++;
- canvas.callDrawGLFunction(&noopFunctor, listener.get());
+ canvas.drawWebViewFunctor(functor);
});
- EXPECT_EQ(2, refcnt);
+ EXPECT_EQ(1, counts.sync);
+ EXPECT_EQ(0, counts.destroyed);
- TestUtils::syncHierarchyPropertiesAndDisplayList(node);
- EXPECT_EQ(1, refcnt);
+ TestUtils::runOnRenderThreadUnmanaged([&] (RenderThread&) {
+ TestUtils::syncHierarchyPropertiesAndDisplayList(node);
+ });
+ EXPECT_EQ(2, counts.sync);
+ EXPECT_EQ(0, counts.destroyed);
+
+ WebViewFunctor_release(functor);
+ EXPECT_EQ(2, counts.sync);
+ EXPECT_EQ(0, counts.destroyed);
TestUtils::recordNode(*node, [](Canvas& canvas) {});
- EXPECT_EQ(1, refcnt);
- TestUtils::syncHierarchyPropertiesAndDisplayList(node);
- EXPECT_EQ(0, refcnt);
+ TestUtils::runOnRenderThreadUnmanaged([&] (RenderThread&) {
+ TestUtils::syncHierarchyPropertiesAndDisplayList(node);
+ });
+ EXPECT_EQ(2, counts.sync);
+ EXPECT_EQ(1, counts.destroyed);
}
RENDERTHREAD_TEST(RenderNode, prepareTree_nullableDisplayList) {
diff --git a/libs/hwui/tests/unit/SkiaCanvasTests.cpp b/libs/hwui/tests/unit/SkiaCanvasTests.cpp
index fcc64fdd0be6..f77ca2a8c06c 100644
--- a/libs/hwui/tests/unit/SkiaCanvasTests.cpp
+++ b/libs/hwui/tests/unit/SkiaCanvasTests.cpp
@@ -73,7 +73,7 @@ TEST(SkiaCanvas, colorSpaceXform) {
// Test picture recording.
SkPictureRecorder recorder;
- SkCanvas* skPicCanvas = recorder.beginRecording(1, 1, NULL, 0);
+ SkCanvas* skPicCanvas = recorder.beginRecording(1, 1);
SkiaCanvas picCanvas(skPicCanvas);
picCanvas.drawBitmap(*adobeBitmap, 0, 0, nullptr);
sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
@@ -104,7 +104,7 @@ TEST(SkiaCanvas, captureCanvasState) {
// Create a picture canvas.
SkPictureRecorder recorder;
- SkCanvas* skPicCanvas = recorder.beginRecording(1, 1, NULL, 0);
+ SkCanvas* skPicCanvas = recorder.beginRecording(1, 1);
SkiaCanvas picCanvas(skPicCanvas);
state = picCanvas.captureCanvasState();
diff --git a/libs/hwui/tests/unit/SkiaDisplayListTests.cpp b/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
index d08aea668b2a..74a565439f85 100644
--- a/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
+++ b/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
@@ -48,7 +48,10 @@ TEST(SkiaDisplayList, reset) {
SkCanvas dummyCanvas;
RenderNodeDrawable drawable(nullptr, &dummyCanvas);
skiaDL->mChildNodes.emplace_back(nullptr, &dummyCanvas);
- GLFunctorDrawable functorDrawable(nullptr, nullptr, &dummyCanvas);
+ int functor1 = WebViewFunctor_create(
+ nullptr, TestUtils::createMockFunctor(RenderMode::OpenGL_ES), RenderMode::OpenGL_ES);
+ GLFunctorDrawable functorDrawable{functor1, &dummyCanvas};
+ WebViewFunctor_release(functor1);
skiaDL->mChildFunctors.push_back(&functorDrawable);
skiaDL->mMutableImages.push_back(nullptr);
skiaDL->appendVD(nullptr);
@@ -97,16 +100,13 @@ TEST(SkiaDisplayList, syncContexts) {
SkiaDisplayList skiaDL;
SkCanvas dummyCanvas;
- TestUtils::MockFunctor functor;
- GLFunctorDrawable functorDrawable(&functor, nullptr, &dummyCanvas);
- skiaDL.mChildFunctors.push_back(&functorDrawable);
- int functor2 = WebViewFunctor_create(
+ int functor1 = WebViewFunctor_create(
nullptr, TestUtils::createMockFunctor(RenderMode::OpenGL_ES), RenderMode::OpenGL_ES);
- auto& counts = TestUtils::countsForFunctor(functor2);
+ auto& counts = TestUtils::countsForFunctor(functor1);
skiaDL.mChildFunctors.push_back(
- skiaDL.allocateDrawable<GLFunctorDrawable>(functor2, &dummyCanvas));
- WebViewFunctor_release(functor2);
+ skiaDL.allocateDrawable<GLFunctorDrawable>(functor1, &dummyCanvas));
+ WebViewFunctor_release(functor1);
SkRect bounds = SkRect::MakeWH(200, 200);
VectorDrawableRoot vectorDrawable(new VectorDrawable::Group());
@@ -120,7 +120,6 @@ TEST(SkiaDisplayList, syncContexts) {
});
});
- EXPECT_EQ(functor.getLastMode(), DrawGlInfo::kModeSync);
EXPECT_EQ(counts.sync, 1);
EXPECT_EQ(counts.destroyed, 0);
EXPECT_EQ(vectorDrawable.mutateProperties()->getBounds(), bounds);
diff --git a/libs/hwui/tests/unit/VectorDrawableTests.cpp b/libs/hwui/tests/unit/VectorDrawableTests.cpp
index 6d4c57413f00..5e56b26f46f0 100644
--- a/libs/hwui/tests/unit/VectorDrawableTests.cpp
+++ b/libs/hwui/tests/unit/VectorDrawableTests.cpp
@@ -17,9 +17,14 @@
#include <gtest/gtest.h>
#include "PathParser.h"
+#include "GraphicsJNI.h"
+#include "SkGradientShader.h"
+#include "SkShader.h"
#include "VectorDrawable.h"
#include "utils/MathUtils.h"
#include "utils/VectorDrawableUtils.h"
+#include <shader/Shader.h>
+#include <shader/LinearGradientShader.h>
#include <functional>
@@ -395,7 +400,21 @@ TEST(VectorDrawable, drawPathWithoutIncrementingShaderRefCount) {
bitmap.allocN32Pixels(5, 5, false);
SkCanvas canvas(bitmap);
- sk_sp<SkShader> shader = SkShaders::Color(SK_ColorBLACK);
+ SkPoint pts[2];
+ pts[0].set(0, 0);
+ pts[1].set(0, 0);
+
+ std::vector<SkColor4f> colors(2);
+ colors[0] = SkColors::kBlack;
+ colors[1] = SkColors::kBlack;
+
+ sk_sp<LinearGradientShader> shader = sk_sp(new LinearGradientShader(pts,
+ colors,
+ SkColorSpace::MakeSRGB(),
+ nullptr,
+ SkTileMode::kClamp,
+ SkGradientShader::kInterpolateColorsInPremul_Flag,
+ nullptr));
// Initial ref count is 1
EXPECT_TRUE(shader->unique());
diff --git a/libs/hwui/utils/Blur.h b/libs/hwui/utils/Blur.h
index d6b41b83def8..6b822f01e25c 100644
--- a/libs/hwui/utils/Blur.h
+++ b/libs/hwui/utils/Blur.h
@@ -26,9 +26,9 @@ namespace uirenderer {
class Blur {
public:
// If radius > 0, return the corresponding sigma, else return 0
- ANDROID_API static float convertRadiusToSigma(float radius);
+ static float convertRadiusToSigma(float radius);
// If sigma > 0.5, return the corresponding radius, else return 0
- ANDROID_API static float convertSigmaToRadius(float sigma);
+ static float convertSigmaToRadius(float sigma);
// If the original radius was on an integer boundary then after the sigma to
// radius conversion a small rounding error may be introduced. This function
// accounts for that error and snaps to the appropriate integer boundary.
diff --git a/libs/hwui/utils/Color.cpp b/libs/hwui/utils/Color.cpp
index 71a27ced2e09..87512f0354c8 100644
--- a/libs/hwui/utils/Color.cpp
+++ b/libs/hwui/utils/Color.cpp
@@ -16,8 +16,8 @@
#include "Color.h"
-#include <utils/Log.h>
#include <ui/ColorSpace.h>
+#include <utils/Log.h>
#ifdef __ANDROID__ // Layoutlib does not support hardware buffers or native windows
#include <android/hardware_buffer.h>
@@ -26,6 +26,7 @@
#include <algorithm>
#include <cmath>
+#include <Properties.h>
namespace android {
namespace uirenderer {
@@ -72,46 +73,34 @@ SkImageInfo BufferDescriptionToImageInfo(const AHardwareBuffer_Desc& bufferDesc,
sk_sp<SkColorSpace> colorSpace) {
return createImageInfo(bufferDesc.width, bufferDesc.height, bufferDesc.format, colorSpace);
}
-#endif
-android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType) {
+uint32_t ColorTypeToBufferFormat(SkColorType colorType) {
switch (colorType) {
case kRGBA_8888_SkColorType:
- return PIXEL_FORMAT_RGBA_8888;
+ return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
case kRGBA_F16_SkColorType:
- return PIXEL_FORMAT_RGBA_FP16;
+ return AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT;
case kRGB_565_SkColorType:
- return PIXEL_FORMAT_RGB_565;
+ return AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;
case kRGB_888x_SkColorType:
- return PIXEL_FORMAT_RGBX_8888;
+ return AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM;
case kRGBA_1010102_SkColorType:
- return PIXEL_FORMAT_RGBA_1010102;
+ return AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM;
case kARGB_4444_SkColorType:
- return PIXEL_FORMAT_RGBA_4444;
+ // Hardcoding the value from android::PixelFormat
+ static constexpr uint64_t kRGBA4444 = 7;
+ return kRGBA4444;
default:
ALOGV("Unsupported colorType: %d, return RGBA_8888 by default", (int)colorType);
- return PIXEL_FORMAT_RGBA_8888;
- }
-}
-
-SkColorType PixelFormatToColorType(android::PixelFormat format) {
- switch (format) {
- case PIXEL_FORMAT_RGBX_8888: return kRGB_888x_SkColorType;
- case PIXEL_FORMAT_RGBA_8888: return kRGBA_8888_SkColorType;
- case PIXEL_FORMAT_RGBA_FP16: return kRGBA_F16_SkColorType;
- case PIXEL_FORMAT_RGB_565: return kRGB_565_SkColorType;
- case PIXEL_FORMAT_RGBA_1010102: return kRGBA_1010102_SkColorType;
- case PIXEL_FORMAT_RGBA_4444: return kARGB_4444_SkColorType;
- default:
- ALOGV("Unsupported PixelFormat: %d, return kUnknown_SkColorType by default", format);
- return kUnknown_SkColorType;
+ return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
}
}
+#endif
namespace {
static constexpr skcms_TransferFunction k2Dot6 = {2.6f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
-// Skia's SkNamedGamut::kDCIP3 is based on a white point of D65. This gamut
+// Skia's SkNamedGamut::kDisplayP3 is based on a white point of D65. This gamut
// matches the white point used by ColorSpace.Named.DCIP3.
static constexpr skcms_Matrix3x3 kDCIP3 = {{
{0.486143, 0.323835, 0.154234},
@@ -180,7 +169,7 @@ android_dataspace ColorSpaceToADataSpace(SkColorSpace* colorSpace, SkColorType c
}
}
- if (nearlyEqual(fn, SkNamedTransferFn::kSRGB) && nearlyEqual(gamut, SkNamedGamut::kDCIP3)) {
+ if (nearlyEqual(fn, SkNamedTransferFn::kSRGB) && nearlyEqual(gamut, SkNamedGamut::kDisplayP3)) {
return HAL_DATASPACE_DISPLAY_P3;
}
@@ -221,7 +210,7 @@ sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace) {
gamut = SkNamedGamut::kRec2020;
break;
case HAL_DATASPACE_STANDARD_DCI_P3:
- gamut = SkNamedGamut::kDCIP3;
+ gamut = SkNamedGamut::kDisplayP3;
break;
case HAL_DATASPACE_STANDARD_ADOBE_RGB:
gamut = SkNamedGamut::kAdobeRGB;
@@ -356,5 +345,23 @@ SkColor LabToSRGB(const Lab& lab, SkAlpha alpha) {
static_cast<uint8_t>(rgb.b * 255));
}
+skcms_TransferFunction GetPQSkTransferFunction(float sdr_white_level) {
+ if (sdr_white_level <= 0.f) {
+ sdr_white_level = Properties::defaultSdrWhitePoint;
+ }
+ // The generic PQ transfer function produces normalized luminance values i.e.
+ // the range 0-1 represents 0-10000 nits for the reference display, but we
+ // want to map 1.0 to |sdr_white_level| nits so we need to scale accordingly.
+ const double w = 10000. / sdr_white_level;
+ // Distribute scaling factor W by scaling A and B with X ^ (1/F):
+ // ((A + Bx^C) / (D + Ex^C))^F * W = ((A + Bx^C) / (D + Ex^C) * W^(1/F))^F
+ // See https://crbug.com/1058580#c32 for discussion.
+ skcms_TransferFunction fn = SkNamedTransferFn::kPQ;
+ const double ws = pow(w, 1. / fn.f);
+ fn.a = ws * fn.a;
+ fn.b = ws * fn.b;
+ return fn;
+}
+
} // namespace uirenderer
} // namespace android
diff --git a/libs/hwui/utils/Color.h b/libs/hwui/utils/Color.h
index a76f7e499c37..1654072fd264 100644
--- a/libs/hwui/utils/Color.h
+++ b/libs/hwui/utils/Color.h
@@ -16,14 +16,12 @@
#ifndef COLOR_H
#define COLOR_H
-#include <math.h>
-#include <cutils/compiler.h>
-#include <system/graphics.h>
-#include <ui/PixelFormat.h>
-
#include <SkColor.h>
#include <SkColorSpace.h>
#include <SkImageInfo.h>
+#include <cutils/compiler.h>
+#include <math.h>
+#include <system/graphics.h>
struct ANativeWindow_Buffer;
struct AHardwareBuffer_Desc;
@@ -93,15 +91,14 @@ static constexpr float EOCF_sRGB(float srgb) {
}
#ifdef __ANDROID__ // Layoutlib does not support hardware buffers or native windows
-ANDROID_API SkImageInfo ANativeWindowToImageInfo(const ANativeWindow_Buffer& buffer,
+SkImageInfo ANativeWindowToImageInfo(const ANativeWindow_Buffer& buffer,
sk_sp<SkColorSpace> colorSpace);
SkImageInfo BufferDescriptionToImageInfo(const AHardwareBuffer_Desc& bufferDesc,
sk_sp<SkColorSpace> colorSpace);
-#endif
-android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType);
-ANDROID_API SkColorType PixelFormatToColorType(android::PixelFormat format);
+uint32_t ColorTypeToBufferFormat(SkColorType colorType);
+#endif
ANDROID_API sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace);
@@ -129,6 +126,7 @@ struct Lab {
Lab sRGBToLab(SkColor color);
SkColor LabToSRGB(const Lab& lab, SkAlpha alpha);
+skcms_TransferFunction GetPQSkTransferFunction(float sdr_white_level = 0.f);
} /* namespace uirenderer */
} /* namespace android */
diff --git a/libs/hwui/utils/MathUtils.h b/libs/hwui/utils/MathUtils.h
index cc8d83f10d43..62bf39ca8a7a 100644
--- a/libs/hwui/utils/MathUtils.h
+++ b/libs/hwui/utils/MathUtils.h
@@ -31,7 +31,9 @@ public:
* Check for floats that are close enough to zero.
*/
inline static bool isZero(float value) {
- return (value >= -NON_ZERO_EPSILON) && (value <= NON_ZERO_EPSILON);
+ // Using fabsf is more performant as ARM computes
+ // fabsf in a single instruction.
+ return fabsf(value) <= NON_ZERO_EPSILON;
}
inline static bool isOne(float value) {
diff --git a/libs/hwui/GlFunctorLifecycleListener.h b/libs/hwui/utils/NdkUtils.cpp
index 5adc46961c8b..de6274ee5bcc 100644
--- a/libs/hwui/GlFunctorLifecycleListener.h
+++ b/libs/hwui/utils/NdkUtils.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,19 +14,19 @@
* limitations under the License.
*/
-#pragma once
-
-#include <utils/Functor.h>
-#include <utils/RefBase.h>
+#include <utils/NdkUtils.h>
namespace android {
namespace uirenderer {
-class GlFunctorLifecycleListener : public VirtualLightRefBase {
-public:
- virtual ~GlFunctorLifecycleListener() {}
- virtual void onGlFunctorReleased(Functor* functor) = 0;
-};
+UniqueAHardwareBuffer allocateAHardwareBuffer(const AHardwareBuffer_Desc& desc) {
+ AHardwareBuffer* buffer;
+ if (AHardwareBuffer_allocate(&desc, &buffer) != 0) {
+ return nullptr;
+ } else {
+ return UniqueAHardwareBuffer{buffer};
+ }
+}
} // namespace uirenderer
} // namespace android
diff --git a/libs/hwui/utils/NdkUtils.h b/libs/hwui/utils/NdkUtils.h
new file mode 100644
index 000000000000..f218eb2ff404
--- /dev/null
+++ b/libs/hwui/utils/NdkUtils.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <android/hardware_buffer.h>
+
+#include <memory>
+
+namespace android {
+namespace uirenderer {
+
+// Deleter for an AHardwareBuffer, to be passed to an std::unique_ptr.
+struct AHardwareBuffer_deleter {
+ void operator()(AHardwareBuffer* ahb) const { AHardwareBuffer_release(ahb); }
+};
+
+using UniqueAHardwareBuffer = std::unique_ptr<AHardwareBuffer, AHardwareBuffer_deleter>;
+
+// Allocates a UniqueAHardwareBuffer with the provided buffer description.
+// Returns nullptr if allocation did not succeed.
+UniqueAHardwareBuffer allocateAHardwareBuffer(const AHardwareBuffer_Desc& desc);
+
+} // namespace uirenderer
+} // namespace android
diff --git a/libs/hwui/utils/VectorDrawableUtils.h b/libs/hwui/utils/VectorDrawableUtils.h
index 4be48fb942fc..4f63959165db 100644
--- a/libs/hwui/utils/VectorDrawableUtils.h
+++ b/libs/hwui/utils/VectorDrawableUtils.h
@@ -28,10 +28,10 @@ namespace uirenderer {
class VectorDrawableUtils {
public:
- ANDROID_API static bool canMorph(const PathData& morphFrom, const PathData& morphTo);
- ANDROID_API static bool interpolatePathData(PathData* outData, const PathData& morphFrom,
+ static bool canMorph(const PathData& morphFrom, const PathData& morphTo);
+ static bool interpolatePathData(PathData* outData, const PathData& morphFrom,
const PathData& morphTo, float fraction);
- ANDROID_API static void verbsToPath(SkPath* outPath, const PathData& data);
+ static void verbsToPath(SkPath* outPath, const PathData& data);
static void interpolatePaths(PathData* outPathData, const PathData& from, const PathData& to,
float fraction);
};
diff --git a/libs/usb/tests/AccessoryChat/AndroidManifest.xml b/libs/usb/tests/AccessoryChat/AndroidManifest.xml
index 6667ebaa4d49..b93eeab11324 100644
--- a/libs/usb/tests/AccessoryChat/AndroidManifest.xml
+++ b/libs/usb/tests/AccessoryChat/AndroidManifest.xml
@@ -15,26 +15,28 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.accessorychat">
+ package="com.android.accessorychat">
- <uses-feature android:name="android.hardware.usb.accessory" />
+ <uses-feature android:name="android.hardware.usb.accessory"/>
<application android:label="Accessory Chat">
- <activity android:name="AccessoryChat" android:label="Accessory Chat">
+ <activity android:name="AccessoryChat"
+ android:label="Accessory Chat"
+ android:exported="true">
<intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="android.intent.category.LAUNCHER" />
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
- <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
+ <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"/>
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
- android:resource="@xml/accessory_filter" />
+ android:resource="@xml/accessory_filter"/>
</activity>
</application>
- <uses-sdk android:minSdkVersion="12" />
+ <uses-sdk android:minSdkVersion="12"/>
</manifest>