• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.wm.shell.common.split;
18 
19 import static android.view.WindowManager.DOCKED_BOTTOM;
20 import static android.view.WindowManager.DOCKED_INVALID;
21 import static android.view.WindowManager.DOCKED_LEFT;
22 import static android.view.WindowManager.DOCKED_RIGHT;
23 import static android.view.WindowManager.DOCKED_TOP;
24 
25 import static com.android.wm.shell.shared.animation.Interpolators.DIM_INTERPOLATOR;
26 
27 import android.graphics.Point;
28 import android.graphics.Rect;
29 
30 /**
31  * Default interface for a set of calculation classes, used for calculating various parallax and
32  * dimming effects in split screen.
33  */
34 public interface ParallaxSpec {
35     /** Returns an int indicating which side of the screen is being dimmed (if any). */
getDimmingSide(int position, DividerSnapAlgorithm snapAlgorithm, boolean isLeftRightSplit)36     default int getDimmingSide(int position, DividerSnapAlgorithm snapAlgorithm,
37             boolean isLeftRightSplit) {
38         if (position < snapAlgorithm.getFirstSplitTarget().getPosition()) {
39             return isLeftRightSplit ? DOCKED_LEFT : DOCKED_TOP;
40         } else if (position > snapAlgorithm.getLastSplitTarget().getPosition()) {
41             return isLeftRightSplit ? DOCKED_RIGHT : DOCKED_BOTTOM;
42         }
43         return DOCKED_INVALID;
44     }
45 
46     /** Returns the dim amount that we'll apply to the app surface. 0f = no dim, 1f = full black */
getDimValue(int position, DividerSnapAlgorithm snapAlgorithm)47     default float getDimValue(int position, DividerSnapAlgorithm snapAlgorithm) {
48         float progressTowardScreenEdge =
49                 Math.max(0, Math.min(snapAlgorithm.calculateDismissingFraction(position), 1f));
50         return DIM_INTERPOLATOR.getInterpolation(progressTowardScreenEdge);
51     }
52 
53     /**
54      * Calculates the amount to offset app surfaces to create nice parallax effects. Writes to
55      * {@link ResizingEffectPolicy#mRetreatingSideParallax} and
56      * {@link ResizingEffectPolicy#mAdvancingSideParallax}.
57      */
getParallax(Point retreatingOut, Point advancingOut, int position, DividerSnapAlgorithm snapAlgorithm, boolean isLeftRightSplit, Rect displayBounds, Rect retreatingSurface, Rect retreatingContent, Rect advancingSurface, Rect advancingContent, int dimmingSide, boolean topLeftShrink)58     void getParallax(Point retreatingOut, Point advancingOut, int position,
59             DividerSnapAlgorithm snapAlgorithm, boolean isLeftRightSplit, Rect displayBounds,
60             Rect retreatingSurface, Rect retreatingContent, Rect advancingSurface,
61             Rect advancingContent, int dimmingSide, boolean topLeftShrink);
62 }
63