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

Commit 72409f2e authored by Haofan Wang's avatar Haofan Wang Committed by Android (Google) Code Review
Browse files

Merge changes from topic "cherrypicker-not_set-L96200030017286449:N23400030260323266" into main

* changes:
  Handle apply default picture profile for Tv Input[2/2]
  Handle apply default picture profile for Tv Input[1/2]
parents 36af3442 c86b564b
Loading
Loading
Loading
Loading
+41 −3
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.RenderNode;
import android.hardware.input.InputManager;
import android.media.quality.PictureProfileHandle;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
@@ -210,6 +211,8 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
    private float mRequestedHdrHeadroom = 0.f;
    private float mHdrHeadroom = 0.f;

    private PictureProfileHandle mRequestedPictureProfileHandle = null;

    /**
     * We use this lock to protect access to mSurfaceControl. Both are accessed on the UI
     * thread and the render thread via RenderNode.PositionUpdateListener#positionLost.
@@ -1014,6 +1017,29 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        invalidate();
    }

    /**
     * Sends the picture profile handle to the Composer HAL for application on the surface.
     * <p>
     * This method allows a system application to specify a picture profile handle.
     * The provided {@link PictureProfileHandle} will be propagated to the Composer HAL,
     * which is then responsible for applying the corresponding display adjustments.
     * <p>
     *
     * <p><b>Example Usage:</b></p>
     * This is used by TvView to apply a picture profile handle obtained for the current TV input.
     *
     * @param handle The non-null {@link PictureProfileHandle} to send to the layer.
     * @throws IllegalArgumentException if the provided handle is null.
     * @hide
     */
    public void sendPictureProfileHandle(PictureProfileHandle handle) {
        if (handle == null) {
            throw new IllegalArgumentException("PictureProfileHandle is null");
        }
        mRequestedPictureProfileHandle = handle;
        updateSurface();
    }

    private void updateOpaqueFlag() {
        if (!PixelFormat.formatHasAlpha(mRequestedFormat)) {
            mSurfaceFlags |= SurfaceControl.OPAQUE;
@@ -1094,7 +1120,8 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall

    private boolean performSurfaceTransaction(ViewRootImpl viewRoot, Translator translator,
            boolean creating, boolean sizeChanged, boolean hintChanged, boolean relativeZChanged,
            boolean hdrHeadroomChanged, Transaction surfaceUpdateTransaction) {
            boolean hdrHeadroomChanged, PictureProfileHandle pictureProfileHandle,
            Transaction surfaceUpdateTransaction) {
        boolean realSizeChanged = false;

        mSurfaceLock.lock();
@@ -1133,6 +1160,10 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                surfaceUpdateTransaction.setDesiredHdrHeadroom(
                        mBlastSurfaceControl, mHdrHeadroom);
            }
            if (pictureProfileHandle != null) {
                surfaceUpdateTransaction.setPictureProfileHandle(
                        mBlastSurfaceControl, pictureProfileHandle);
            }
            if (isAboveParent()) {
                float alpha = getAlpha();
                surfaceUpdateTransaction.setAlpha(mSurfaceControl, alpha);
@@ -1278,11 +1309,12 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        final boolean surfaceLifecycleStrategyChanged =
                mSurfaceLifecycleStrategy != mRequestedSurfaceLifecycleStrategy;
        final boolean hdrHeadroomChanged = mHdrHeadroom != mRequestedHdrHeadroom;
        final boolean pictureProfileChanged = mRequestedPictureProfileHandle != null;

        if (creating || formatChanged || sizeChanged || visibleChanged
                || alphaChanged || windowVisibleChanged || positionChanged
                || layoutSizeChanged || hintChanged || relativeZChanged || !mAttachedToWindow
                || surfaceLifecycleStrategyChanged || hdrHeadroomChanged) {
                || surfaceLifecycleStrategyChanged || hdrHeadroomChanged || pictureProfileChanged) {

            if (DEBUG) Log.i(TAG, System.identityHashCode(this) + " "
                    + "Changes: creating=" + creating
@@ -1321,6 +1353,12 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                mSurfaceLifecycleStrategy = mRequestedSurfaceLifecycleStrategy;
                mHdrHeadroom = mRequestedHdrHeadroom;

                // Picture profiles operate a bit differently. Since the picture profiles can also
                // be changed when queueing buffers, SurfaceView can't be the single source
                // of truth for the picture profile.
                PictureProfileHandle pictureProfileHandle = mRequestedPictureProfileHandle;
                mRequestedPictureProfileHandle = null;

                mScreenRect.left = mWindowSpaceLeft;
                mScreenRect.top = mWindowSpaceTop;
                mScreenRect.right = mWindowSpaceLeft + getWidth();
@@ -1357,7 +1395,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall

                final boolean realSizeChanged = performSurfaceTransaction(viewRoot, translator,
                        creating, sizeChanged, hintChanged, relativeZChanged, hdrHeadroomChanged,
                        surfaceUpdateTransaction);
                        pictureProfileHandle, surfaceUpdateTransaction);

                try {
                    SurfaceHolder.Callback[] callbacks = null;
+20 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ import android.graphics.RectF;
import android.graphics.Region;
import android.media.AudioPresentation;
import android.media.PlaybackParams;
import android.media.quality.MediaQualityManager;
import android.media.quality.PictureProfileHandle;
import android.media.tv.TvInputManager.Session;
import android.media.tv.TvInputManager.Session.FinishedInputEventCallback;
import android.media.tv.TvInputManager.SessionCallback;
@@ -98,6 +100,7 @@ public class TvView extends ViewGroup {
    private boolean mOverlayViewCreated;
    private Rect mOverlayViewFrame;
    private final TvInputManager mTvInputManager;
    private final MediaQualityManager mMediaQualityManager;
    private MySessionCallback mSessionCallback;
    private TvInputCallback mCallback;
    private OnUnhandledInputEventListener mOnUnhandledInputEventListener;
@@ -194,6 +197,8 @@ public class TvView extends ViewGroup {
        mDefStyleAttr = defStyleAttr;
        resetSurfaceView();
        mTvInputManager = (TvInputManager) getContext().getSystemService(Context.TV_INPUT_SERVICE);
        mMediaQualityManager = (MediaQualityManager) getContext().getSystemService(
                Context.MEDIA_QUALITY_SERVICE);
        mTvAppAttributionSource = getContext().getAttributionSource();
    }

@@ -391,6 +396,21 @@ public class TvView extends ViewGroup {
            // MySessionCallback.this is different from mSessionCallback, we know that this callback
            // is obsolete and should ignore it.
            mSessionCallback = new MySessionCallback(inputId, channelUri, params);
            if (mSurfaceView != null && mMediaQualityManager != null) {
                String idForProfile = inputId;
                TvInputInfo tvInputInfo = mTvInputManager.getTvInputInfo(inputId);
                if (tvInputInfo != null && tvInputInfo.getParentId() != null) {
                    idForProfile = tvInputInfo.getParentId();
                    if (DEBUG) {
                        Log.d(TAG, "the parent of inputId received is " + idForProfile);
                    }
                }
                long handle = mMediaQualityManager.getPictureProfileForTvInput(idForProfile);
                if (handle > 0) {
                    PictureProfileHandle pph = new PictureProfileHandle(handle);
                    mSurfaceView.sendPictureProfileHandle(pph);
                }
            }
            if (mTvInputManager != null) {
                mTvInputManager.createSession(
                        inputId, mTvAppAttributionSource, mSessionCallback, mHandler);