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

Commit a6107c16 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "De-couple RenderNode from View package"

parents d0938d02 6b164402
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1022,6 +1022,7 @@ android.graphics.-$$Lambda$ColorSpace$Rgb$b9VGKuNnse0bbguR9jbOM_wK2Ac
android.graphics.-$$Lambda$ColorSpace$Rgb$bWzafC8vMHNuVmRuTUPEFUMlfuY
android.graphics.-$$Lambda$ColorSpace$Rgb$bWzafC8vMHNuVmRuTUPEFUMlfuY
android.graphics.-$$Lambda$ColorSpace$S2rlqJvkXGTpUF6mZhvkElds8JE
android.graphics.-$$Lambda$ColorSpace$S2rlqJvkXGTpUF6mZhvkElds8JE
android.graphics.BaseCanvas
android.graphics.BaseCanvas
android.graphics.BaseRecordingCanvas
android.graphics.Bitmap
android.graphics.Bitmap
android.graphics.Bitmap$1
android.graphics.Bitmap$1
android.graphics.Bitmap$2
android.graphics.Bitmap$2
@@ -3303,7 +3304,6 @@ android.view.OrientationEventListener
android.view.OrientationEventListener$SensorEventListenerImpl
android.view.OrientationEventListener$SensorEventListenerImpl
android.view.PointerIcon
android.view.PointerIcon
android.view.PointerIcon$1
android.view.PointerIcon$1
android.view.RecordingCanvas
android.view.RenderNode
android.view.RenderNode
android.view.RenderNode$NoImagePreloadHolder
android.view.RenderNode$NoImagePreloadHolder
android.view.RenderNodeAnimator
android.view.RenderNodeAnimator
+2 −1
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package android.view;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.UnsupportedAppUsage;
import android.annotation.UnsupportedAppUsage;
import android.graphics.BaseRecordingCanvas;
import android.graphics.Bitmap;
import android.graphics.Bitmap;
import android.graphics.CanvasProperty;
import android.graphics.CanvasProperty;
import android.graphics.Paint;
import android.graphics.Paint;
@@ -35,7 +36,7 @@ import dalvik.annotation.optimization.FastNative;
 *
 *
 * @hide
 * @hide
 */
 */
public final class DisplayListCanvas extends RecordingCanvas {
public final class DisplayListCanvas extends BaseRecordingCanvas {
    // The recording canvas pool should be large enough to handle a deeply nested
    // The recording canvas pool should be large enough to handle a deeply nested
    // view hierarchy because display lists are generated recursively.
    // view hierarchy because display lists are generated recursively.
    private static final int POOL_LIMIT = 25;
    private static final int POOL_LIMIT = 25;
+29 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 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;

/**
 * Exists just to allow for android.graphics & android.view package separation
 *
 * TODO: Get off of this coupling more cleanly somehow
 *
 * @hide
 */
public interface NativeVectorDrawableAnimator {
    /** @hide */
    long getAnimatorNativePtr();
}
+60 −17
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.graphics.Matrix;
import android.graphics.Outline;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.drawable.AnimatedVectorDrawable;


import dalvik.annotation.optimization.CriticalNative;
import dalvik.annotation.optimization.CriticalNative;
import dalvik.annotation.optimization.FastNative;
import dalvik.annotation.optimization.FastNative;
@@ -148,12 +147,12 @@ public class RenderNode {
     * @hide
     * @hide
     */
     */
    final long mNativeRenderNode;
    final long mNativeRenderNode;
    private final View mOwningView;
    private final AnimationHost mAnimationHost;


    private RenderNode(String name, View owningView) {
    private RenderNode(String name, AnimationHost animationHost) {
        mNativeRenderNode = nCreate(name);
        mNativeRenderNode = nCreate(name);
        NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativeRenderNode);
        NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativeRenderNode);
        mOwningView = owningView;
        mAnimationHost = animationHost;
    }
    }


    /**
    /**
@@ -162,7 +161,7 @@ public class RenderNode {
    private RenderNode(long nativePtr) {
    private RenderNode(long nativePtr) {
        mNativeRenderNode = nativePtr;
        mNativeRenderNode = nativePtr;
        NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativeRenderNode);
        NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativeRenderNode);
        mOwningView = null;
        mAnimationHost = null;
    }
    }


    /**
    /**
@@ -174,8 +173,8 @@ public class RenderNode {
     * @return A new RenderNode.
     * @return A new RenderNode.
     */
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public static RenderNode create(String name, @Nullable View owningView) {
    public static RenderNode create(String name, @Nullable AnimationHost animationHost) {
        return new RenderNode(name, owningView);
        return new RenderNode(name, animationHost);
    }
    }


    /**
    /**
@@ -188,11 +187,38 @@ public class RenderNode {
        return new RenderNode(nativePtr);
        return new RenderNode(nativePtr);
    }
    }


    /**
     * Listens for RenderNode position updates for synchronous window movement.
     *
     * This is not suitable for generic position listening, it is only designed & intended
     * for use by things which require external position events like SurfaceView, PopupWindow, etc..
     *
     * @hide
     */
    interface PositionUpdateListener {

        /**
         * Called by native by a Rendering Worker thread to update window position
         *
         * @hide
         */
        void positionChanged(long frameNumber, int left, int top, int right, int bottom);

        /**
         * Called by native on RenderThread to notify that the view is no longer in the
         * draw tree. UI thread is blocked at this point.
         *
         * @hide
         */
        void positionLost(long frameNumber);

    }

    /**
    /**
     * Enable callbacks for position changes.
     * Enable callbacks for position changes.
     */
     */
    public void requestPositionUpdates(SurfaceView view) {
    public void requestPositionUpdates(PositionUpdateListener listener) {
        nRequestPositionUpdates(mNativeRenderNode, view);
        nRequestPositionUpdates(mNativeRenderNode, listener);
    }
    }




@@ -873,26 +899,42 @@ public class RenderNode {
    // Animations
    // Animations
    ///////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////


    /**
     * TODO: Figure out if this can be eliminated/refactored away
     *
     * For now this interface exists to de-couple RenderNode from anything View-specific in a
     * bit of a kludge.
     *
     * @hide */
    interface AnimationHost {
        void registerAnimatingRenderNode(RenderNode animator);
        void registerVectorDrawableAnimator(NativeVectorDrawableAnimator animator);
        boolean isAttached();
    }

    /** @hide */
    public void addAnimator(RenderNodeAnimator animator) {
    public void addAnimator(RenderNodeAnimator animator) {
        if (mOwningView == null || mOwningView.mAttachInfo == null) {
        if (!isAttached()) {
            throw new IllegalStateException("Cannot start this animator on a detached view!");
            throw new IllegalStateException("Cannot start this animator on a detached view!");
        }
        }
        nAddAnimator(mNativeRenderNode, animator.getNativeAnimator());
        nAddAnimator(mNativeRenderNode, animator.getNativeAnimator());
        mOwningView.mAttachInfo.mViewRootImpl.registerAnimatingRenderNode(this);
        mAnimationHost.registerAnimatingRenderNode(this);
    }
    }


    /** @hide */
    public boolean isAttached() {
    public boolean isAttached() {
        return mOwningView != null && mOwningView.mAttachInfo != null;
        return mAnimationHost != null && mAnimationHost.isAttached();
    }
    }


    public void registerVectorDrawableAnimator(
    /** @hide */
            AnimatedVectorDrawable.VectorDrawableAnimatorRT animatorSet) {
    public void registerVectorDrawableAnimator(NativeVectorDrawableAnimator animatorSet) {
        if (mOwningView == null || mOwningView.mAttachInfo == null) {
        if (!isAttached()) {
            throw new IllegalStateException("Cannot start this animator on a detached view!");
            throw new IllegalStateException("Cannot start this animator on a detached view!");
        }
        }
        mOwningView.mAttachInfo.mViewRootImpl.registerVectorDrawableAnimator(animatorSet);
        mAnimationHost.registerVectorDrawableAnimator(animatorSet);
    }
    }


    /** @hide */
    public void endAllAnimators() {
    public void endAllAnimators() {
        nEndAllAnimators(mNativeRenderNode);
        nEndAllAnimators(mNativeRenderNode);
    }
    }
@@ -906,7 +948,8 @@ public class RenderNode {
    private static native long nGetNativeFinalizer();
    private static native long nGetNativeFinalizer();
    private static native void nOutput(long renderNode);
    private static native void nOutput(long renderNode);
    private static native int nGetDebugSize(long renderNode);
    private static native int nGetDebugSize(long renderNode);
    private static native void nRequestPositionUpdates(long renderNode, SurfaceView callback);
    private static native void nRequestPositionUpdates(long renderNode,
            PositionUpdateListener callback);


    // Animations
    // Animations


+67 −68
Original line number Original line Diff line number Diff line
@@ -209,7 +209,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb


    public SurfaceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    public SurfaceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        super(context, attrs, defStyleAttr, defStyleRes);
        mRenderNode.requestPositionUpdates(this);
        mRenderNode.requestPositionUpdates(mPositionListener);


        setWillNotDraw(true);
        setWillNotDraw(true);
    }
    }
@@ -826,13 +826,11 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb


    private Rect mRTLastReportedPosition = new Rect();
    private Rect mRTLastReportedPosition = new Rect();


    /**
    private RenderNode.PositionUpdateListener mPositionListener =
     * Called by native by a Rendering Worker thread to update the window position
            new RenderNode.PositionUpdateListener() {
     * @hide

     */
        @Override
    @UnsupportedAppUsage
        public void positionChanged(long frameNumber, int left, int top, int right, int bottom) {
    public final void updateSurfacePosition_renderWorker(long frameNumber,
            int left, int top, int right, int bottom) {
            if (mSurfaceControl == null) {
            if (mSurfaceControl == null) {
                return;
                return;
            }
            }
@@ -854,9 +852,11 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
            }
            }
            try {
            try {
                if (DEBUG) {
                if (DEBUG) {
                Log.d(TAG, String.format("%d updateSurfacePosition RenderWorker, frameNr = %d, " +
                    Log.d(TAG, String.format(
                        "postion = [%d, %d, %d, %d]", System.identityHashCode(this),
                            "%d updateSurfacePosition RenderWorker, frameNr = %d, "
                        frameNumber, left, top, right, bottom));
                                    + "postion = [%d, %d, %d, %d]",
                            System.identityHashCode(this), frameNumber,
                            left, top, right, bottom));
                }
                }
                mRTLastReportedPosition.set(left, top, right, bottom);
                mRTLastReportedPosition.set(left, top, right, bottom);
                setParentSpaceRectangle(mRTLastReportedPosition, frameNumber);
                setParentSpaceRectangle(mRTLastReportedPosition, frameNumber);
@@ -866,13 +866,8 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
            }
            }
        }
        }


    /**
        @Override
     * Called by native on RenderThread to notify that the view is no longer in the
        public void positionLost(long frameNumber) {
     * draw tree. UI thread is blocked at this point.
     * @hide
     */
    @UnsupportedAppUsage
    public final void surfacePositionLost_uiRtSync(long frameNumber) {
            if (DEBUG) {
            if (DEBUG) {
                Log.d(TAG, String.format("%d windowPositionLost, frameNr = %d",
                Log.d(TAG, String.format("%d windowPositionLost, frameNr = %d",
                        System.identityHashCode(this), frameNumber));
                        System.identityHashCode(this), frameNumber));
@@ -890,10 +885,13 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
                // updates.
                // updates.
                if (!mScreenRect.isEmpty() && !mScreenRect.equals(mRTLastReportedPosition)) {
                if (!mScreenRect.isEmpty() && !mScreenRect.equals(mRTLastReportedPosition)) {
                    try {
                    try {
                    if (DEBUG) Log.d(TAG, String.format("%d updateSurfacePosition, " +
                        if (DEBUG) {
                            "postion = [%d, %d, %d, %d]", System.identityHashCode(this),
                            Log.d(TAG, String.format("%d updateSurfacePosition, "
                                            + "postion = [%d, %d, %d, %d]",
                                    System.identityHashCode(this),
                                    mScreenRect.left, mScreenRect.top,
                                    mScreenRect.left, mScreenRect.top,
                                    mScreenRect.right, mScreenRect.bottom));
                                    mScreenRect.right, mScreenRect.bottom));
                        }
                        setParentSpaceRectangle(mScreenRect, frameNumber);
                        setParentSpaceRectangle(mScreenRect, frameNumber);
                    } catch (Exception ex) {
                    } catch (Exception ex) {
                        Log.e(TAG, "Exception configuring surface", ex);
                        Log.e(TAG, "Exception configuring surface", ex);
@@ -901,6 +899,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
                }
                }
            }
            }
        }
        }
    };


    private SurfaceHolder.Callback[] getSurfaceCallbacks() {
    private SurfaceHolder.Callback[] getSurfaceCallbacks() {
        SurfaceHolder.Callback callbacks[];
        SurfaceHolder.Callback callbacks[];
Loading