Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f89042c authored by Rob Carr's avatar Rob Carr Committed by Automerger Merge Worker
Browse files

Merge "Expose API for using SurfaceControl with ViewRootImpl" into sc-dev am: 2b434b28

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13842193

Change-Id: I991c351464b0b4fa27a68ee065b3057bd6ec3a01
parents d55ceb35 2b434b28
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -48711,6 +48711,7 @@ package android.view {
    method @Nullable public android.graphics.drawable.Drawable getVerticalScrollbarThumbDrawable();
    method @Nullable public android.graphics.drawable.Drawable getVerticalScrollbarTrackDrawable();
    method public int getVerticalScrollbarWidth();
    method @Nullable public android.view.ViewRoot getViewRoot();
    method @Nullable public android.view.translation.ViewTranslationCallback getViewTranslationCallback();
    method public android.view.ViewTreeObserver getViewTreeObserver();
    method public int getVisibility();
@@ -49787,6 +49788,11 @@ package android.view {
    method public android.view.ViewPropertyAnimator zBy(float);
  }
  @UiThread public interface ViewRoot {
    method public boolean applyTransactionOnDraw(@NonNull android.view.SurfaceControl.Transaction);
    method @Nullable public android.view.SurfaceControl.Transaction buildReparentTransaction(@NonNull android.view.SurfaceControl);
  }
  public abstract class ViewStructure {
    ctor public ViewStructure();
    method public abstract int addChildCount(int);
@@ -49982,6 +49988,7 @@ package android.view {
    method @NonNull public java.util.List<android.graphics.Rect> getSystemGestureExclusionRects();
    method public long getTransitionBackgroundFadeDuration();
    method public android.transition.TransitionManager getTransitionManager();
    method @Nullable public android.view.ViewRoot getViewRoot();
    method public abstract int getVolumeControlStream();
    method public android.view.WindowManager getWindowManager();
    method public final android.content.res.TypedArray getWindowStyle();
+20 −0
Original line number Diff line number Diff line
@@ -29543,6 +29543,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            return mScrollCaptureInternal;
        }
        ViewRoot getViewRoot() {
            return mViewRootImpl;
        }
        public void dump(String prefix, PrintWriter writer) {
            String innerPrefix = prefix + "  ";
            writer.println(prefix + "AttachInfo:");
@@ -30930,4 +30934,20 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            callback.onDisplayHashError(DISPLAY_HASH_ERROR_UNKNOWN);
        }
    }
    /**
     * @return The {@link android.view.ViewRoot} interface for this View. This will only
     * return a non-null value when called between {@link #onAttachedToWindow} and
     * {@link #onDetachedFromWindow}.
     *
     * The ViewRoot itself is not a View, it is just the interface to the windowing-system
     * object that contains the entire view hierarchy. For the root View of a given hierarchy
     * see {@link #getRootView}.
     */
    public @Nullable ViewRoot getViewRoot() {
        if (mAttachInfo != null) {
            return mAttachInfo.getViewRoot();
        }
        return null;
    }
}
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.view;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UiThread;

/**
 * Provides an interface to the root-Surface of a View Hierarchy or Window. This
 * is used in combination with the {@link android.view.SurfaceControl} API to enable
 * attaching app created SurfaceControl to the ViewRoot's surface hierarchy, and enable
 * SurfaceTransactions to be performed in sync with the ViewRoot drawing. This object
 * is obtained from {@link android.view.View#getViewRoot} and
 * {@link android.view.Window#getViewRoot}. It must be used from the UI thread of
 * the object it was obtained from.
 */
@UiThread
public interface ViewRoot {
    /**
     * Create a transaction which will reparent {@param child} to the ViewRoot. See
     * {@link SurfaceControl.Transaction#reparent}. This transacton must be applied
     * or merged in to another transaction by the caller, otherwise it will have
     * no effect.
     *
     * @param child The SurfaceControl to reparent.
     * @return A new transaction which performs the reparent operation when applied.
     */
    @Nullable SurfaceControl.Transaction buildReparentTransaction(@NonNull SurfaceControl child);

    /**
     * Consume the passed in transaction, and request the ViewRoot to apply it with the
     * next draw. This transaction will be merged with the buffer transaction from the ViewRoot
     * and they will show up on-screen atomically synced.
     *
     * This will not cause a draw to be scheduled, and if there are no other changes
     * to the View hierarchy you may need to call {@link android.view.View#invalidate}
     */
    boolean applyTransactionOnDraw(@NonNull SurfaceControl.Transaction t);
}
+18 −1
Original line number Diff line number Diff line
@@ -224,7 +224,7 @@ import java.util.concurrent.CountDownLatch;
 */
@SuppressWarnings({"EmptyCatchBlock", "PointlessBooleanExpression"})
public final class ViewRootImpl implements ViewParent,
        View.AttachInfo.Callbacks, ThreadedRenderer.DrawCallbacks {
        View.AttachInfo.Callbacks, ThreadedRenderer.DrawCallbacks, ViewRoot {
    private static final String TAG = "ViewRootImpl";
    private static final boolean DBG = false;
    private static final boolean LOCAL_LOGV = false;
@@ -10249,4 +10249,21 @@ public final class ViewRootImpl implements ViewParent,
            t.apply();
        }
    }

    @Override
    @Nullable public SurfaceControl.Transaction buildReparentTransaction(
        @NonNull SurfaceControl child) {
        if (mSurfaceControl.isValid()) {
            return new SurfaceControl.Transaction().reparent(child, mSurfaceControl);
        }
        return null;
    }

    @Override
    public boolean applyTransactionOnDraw(@NonNull SurfaceControl.Transaction t) {
        registerRtFrameCallback(frame -> {
            mergeWithNextTransaction(t, frame);
        });
        return true;
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -2717,4 +2717,14 @@ public abstract class Window {
    public @Nullable WindowInsetsController getInsetsController() {
        return null;
    }

    /**
     * This will be null before a content view is added, e.g. via
     * {@link #setContentView} or {@link #addContentView}.
     *
     * @return The {@link android.view.ViewRoot} interface for this Window
     */
    public @Nullable ViewRoot getViewRoot() {
        return null;
    }
}
Loading