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

Commit d27cf02d authored by Rob Carr's avatar Rob Carr Committed by Android (Google) Code Review
Browse files

Merge "Set SCALING_MODE_NO_SCALE_CROP for SurfaceView."

parents 1b3b8b74 cd9a18c7
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public class Surface implements Parcelable {
    private static native int nativeGetHeight(long nativeObject);

    private static native long nativeGetNextFrameNumber(long nativeObject);
    private static native int nativeSetScalingMode(long nativeObject, int scalingMode);

    public static final Parcelable.Creator<Surface> CREATOR =
            new Parcelable.Creator<Surface>() {
@@ -94,6 +95,21 @@ public class Surface implements Parcelable {

    private HwuiContext mHwuiContext;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({SCALING_MODE_FREEZE, SCALING_MODE_SCALE_TO_WINDOW,
                    SCALING_MODE_SCALE_CROP, SCALING_MODE_NO_SCALE_CROP})
    public @interface ScalingMode {}
    // From system/window.h
    /** @hide */
    static final int SCALING_MODE_FREEZE = 0;
    /** @hide */
    static final int SCALING_MODE_SCALE_TO_WINDOW = 1;
    /** @hide */
    static final int SCALING_MODE_SCALE_CROP = 2;
    /** @hide */
    static final int SCALING_MODE_NO_SCALE_CROP = 3;

    /** @hide */
    @IntDef({ROTATION_0, ROTATION_90, ROTATION_180, ROTATION_270})
    @Retention(RetentionPolicy.SOURCE)
@@ -499,6 +515,20 @@ public class Surface implements Parcelable {
        }
    }

    /**
     * Set the scaling mode to be used for this surfaces buffers
     * @hide
     */
    void setScalingMode(@ScalingMode int scalingMode) {
        synchronized (mLock) {
            checkNotReleasedLocked();
            int err = nativeSetScalingMode(mNativeObject, scalingMode);
            if (err != 0) {
                throw new IllegalArgumentException("Invalid scaling mode: " + scalingMode);
            }
        }
    }

    /**
     * Exception thrown when a Canvas couldn't be locked with {@link Surface#lockCanvas}, or
     * when a SurfaceTexture could not successfully be allocated.
+12 −1
Original line number Diff line number Diff line
@@ -578,8 +578,19 @@ public class SurfaceView extends View {
                    }

                    mSurface.transferFrom(mNewSurface);

                    if (visible && mSurface.isValid()) {
                        // We set SCALING_MODE_NO_SCALE_CROP to allow the WindowManager
                        // to update our Surface crop without requiring a new buffer from
                        // us. In the default mode of SCALING_MODE_FREEZE, surface geometry
                        // state (which includes crop) is only applied when a buffer
                        // with appropriate geometry is available. During drag resize
                        // it is quite frequent that a matching buffer will not be available
                        // (because we are constantly being resized and have fallen behind).
                        // However in such situations the WindowManager still needs to be able
                        // to update our crop to ensure we stay within the bounds of the containing
                        // window.
                        mSurface.setScalingMode(Surface.SCALING_MODE_NO_SCALE_CROP);

                        if (!mSurfaceCreated && (surfaceChanged || visibleChanged)) {
                            mSurfaceCreated = true;
                            mIsCreating = true;
+7 −0
Original line number Diff line number Diff line
@@ -465,11 +465,17 @@ static jint nativeGetHeight(JNIEnv* env, jclass clazz, jlong nativeObject) {
    anw->query(anw, NATIVE_WINDOW_HEIGHT, &value);
    return value;
}

static jlong nativeGetNextFrameNumber(JNIEnv *env, jclass clazz, jlong nativeObject) {
    Surface* surface = reinterpret_cast<Surface*>(nativeObject);
    return surface->getNextFrameNumber();
}

static jint nativeSetScalingMode(JNIEnv *env, jclass clazz, jlong nativeObject, jint scalingMode) {
    Surface* surface = reinterpret_cast<Surface*>(nativeObject);
    return surface->setScalingMode(scalingMode);
}

namespace uirenderer {

using namespace android::uirenderer::renderthread;
@@ -546,6 +552,7 @@ static const JNINativeMethod gSurfaceMethods[] = {
    {"nativeGetWidth", "(J)I", (void*)nativeGetWidth },
    {"nativeGetHeight", "(J)I", (void*)nativeGetHeight },
    {"nativeGetNextFrameNumber", "(J)J", (void*)nativeGetNextFrameNumber },
    {"nativeSetScalingMode", "(JI)I", (void*)nativeSetScalingMode },

    // HWUI context
    {"nHwuiCreate", "(JJ)J", (void*) hwui::create },