Search in sources :

Example 61 with DisplayInfo

use of android.view.DisplayInfo in project android_frameworks_base by DirtyUnicorns.

the class WindowManagerService method updateRotationUncheckedLocked.

// TODO(multidisplay): Rotate any display?
/**
     * Updates the current rotation.
     *
     * Returns true if the rotation has been changed.  In this case YOU
     * MUST CALL sendNewConfiguration() TO UNFREEZE THE SCREEN.
     */
public boolean updateRotationUncheckedLocked(boolean inTransaction) {
    if (mDeferredRotationPauseCount > 0) {
        // updates have been resumed.
        if (DEBUG_ORIENTATION)
            Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
        return false;
    }
    ScreenRotationAnimation screenRotationAnimation = mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
    if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
        // again after the animation is finished and the display is unfrozen.
        if (DEBUG_ORIENTATION)
            Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
        return false;
    }
    if (mDisplayFrozen) {
        // the display. We also need to abort rotation here.
        if (DEBUG_ORIENTATION)
            Slog.v(TAG_WM, "Deferring rotation, still finishing previous rotation");
        return false;
    }
    if (!mDisplayEnabled) {
        // No point choosing a rotation if the display is not enabled.
        if (DEBUG_ORIENTATION)
            Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
        return false;
    }
    final DisplayContent displayContent = getDefaultDisplayContentLocked();
    final WindowList windows = displayContent.getWindowList();
    final int oldRotation = mRotation;
    int rotation = mPolicy.rotationForOrientationLw(mLastOrientation, mRotation);
    boolean rotateSeamlessly = mPolicy.shouldRotateSeamlessly(oldRotation, rotation);
    if (rotateSeamlessly) {
        for (int i = windows.size() - 1; i >= 0; i--) {
            WindowState w = windows.get(i);
            // w.mSeamlessRotationCount but that could be incorrect in the case of window-removal.
            if (w.mSeamlesslyRotated) {
                return false;
            }
            // having the camera work is our primary goal.
            if (w.isChildWindow() & w.isVisibleNow() && !w.mWinAnimator.mSurfaceController.getTransformToDisplayInverse()) {
                rotateSeamlessly = false;
            }
        }
    }
    // TODO: Implement forced rotation changes.
    //       Set mAltOrientation to indicate that the application is receiving
    //       an orientation that has different metrics than it expected.
    //       eg. Portrait instead of Landscape.
    boolean altOrientation = !mPolicy.rotationHasCompatibleMetricsLw(mLastOrientation, rotation);
    if (DEBUG_ORIENTATION) {
        Slog.v(TAG_WM, "Selected orientation " + mLastOrientation + ", got rotation " + rotation + " which has " + (altOrientation ? "incompatible" : "compatible") + " metrics");
    }
    if (mRotation == rotation && mAltOrientation == altOrientation) {
        // No change.
        return false;
    }
    if (DEBUG_ORIENTATION) {
        Slog.v(TAG_WM, "Rotation changed to " + rotation + (altOrientation ? " (alt)" : "") + " from " + mRotation + (mAltOrientation ? " (alt)" : "") + ", lastOrientation=" + mLastOrientation);
    }
    mRotation = rotation;
    mAltOrientation = altOrientation;
    mPolicy.setRotationLw(mRotation);
    mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
    mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
    mH.sendEmptyMessageDelayed(H.WINDOW_FREEZE_TIMEOUT, WINDOW_FREEZE_TIMEOUT_DURATION);
    mWaitingForConfig = true;
    displayContent.layoutNeeded = true;
    final int[] anim = new int[2];
    if (displayContent.isDimming()) {
        anim[0] = anim[1] = 0;
    } else {
        mPolicy.selectRotationAnimationLw(anim);
    }
    if (!rotateSeamlessly) {
        startFreezingDisplayLocked(inTransaction, anim[0], anim[1]);
        // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
        screenRotationAnimation = mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
    } else {
        // The screen rotation animation uses a screenshot to freeze the screen
        // while windows resize underneath.
        // When we are rotating seamlessly, we allow the elements to transition
        // to their rotated state independently and without a freeze required.
        screenRotationAnimation = null;
        // We have to reset this in case a window was removed before it
        // finished seamless rotation.
        mSeamlessRotationCount = 0;
    }
    // We need to update our screen size information to match the new rotation. If the rotation
    // has actually changed then this method will return true and, according to the comment at
    // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
    // By updating the Display info here it will be available to
    // computeScreenConfigurationLocked later.
    updateDisplayAndOrientationLocked(mCurConfiguration.uiMode);
    final DisplayInfo displayInfo = displayContent.getDisplayInfo();
    if (!inTransaction) {
        if (SHOW_TRANSACTIONS) {
            Slog.i(TAG_WM, ">>> OPEN TRANSACTION setRotationUnchecked");
        }
        SurfaceControl.openTransaction();
    }
    try {
        //       it doesn't support hardware OpenGL emulation yet.
        if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null && screenRotationAnimation.hasScreenshot()) {
            if (screenRotationAnimation.setRotationInTransaction(rotation, mFxSession, MAX_ANIMATION_DURATION, getTransitionAnimationScaleLocked(), displayInfo.logicalWidth, displayInfo.logicalHeight)) {
                scheduleAnimationLocked();
            }
        }
        if (rotateSeamlessly) {
            for (int i = windows.size() - 1; i >= 0; i--) {
                WindowState w = windows.get(i);
                w.mWinAnimator.seamlesslyRotateWindow(oldRotation, mRotation);
            }
        }
        mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
    } finally {
        if (!inTransaction) {
            SurfaceControl.closeTransaction();
            if (SHOW_LIGHT_TRANSACTIONS) {
                Slog.i(TAG_WM, "<<< CLOSE TRANSACTION setRotationUnchecked");
            }
        }
    }
    for (int i = windows.size() - 1; i >= 0; i--) {
        WindowState w = windows.get(i);
        // Discard surface after orientation change, these can't be reused.
        if (w.mAppToken != null) {
            w.mAppToken.destroySavedSurfaces();
        }
        if (w.mHasSurface && !rotateSeamlessly) {
            if (DEBUG_ORIENTATION)
                Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
            w.mOrientationChanging = true;
            mWindowPlacerLocked.mOrientationChangeComplete = false;
            w.mLastFreezeDuration = 0;
        }
    }
    if (rotateSeamlessly) {
        mH.removeMessages(H.SEAMLESS_ROTATION_TIMEOUT);
        mH.sendEmptyMessageDelayed(H.SEAMLESS_ROTATION_TIMEOUT, SEAMLESS_ROTATION_TIMEOUT_DURATION);
    }
    for (int i = mRotationWatchers.size() - 1; i >= 0; i--) {
        try {
            mRotationWatchers.get(i).watcher.onRotationChanged(rotation);
        } catch (RemoteException e) {
        }
    }
    // windows in final state. Otherwise, we make this call at the rotation end.
    if (screenRotationAnimation == null && mAccessibilityController != null && displayContent.getDisplayId() == Display.DEFAULT_DISPLAY) {
        mAccessibilityController.onRotationChangedLocked(getDefaultDisplayContentLocked(), rotation);
    }
    return true;
}
Also used : DisplayInfo(android.view.DisplayInfo) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 62 with DisplayInfo

use of android.view.DisplayInfo in project android_frameworks_base by DirtyUnicorns.

the class WindowManagerService method computeScreenConfigurationLocked.

/** Do not call if mDisplayReady == false */
void computeScreenConfigurationLocked(Configuration config) {
    final DisplayInfo displayInfo = updateDisplayAndOrientationLocked(config.uiMode);
    final int dw = displayInfo.logicalWidth;
    final int dh = displayInfo.logicalHeight;
    config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
    config.screenWidthDp = (int) (mPolicy.getConfigDisplayWidth(dw, dh, mRotation, config.uiMode) / mDisplayMetrics.density);
    config.screenHeightDp = (int) (mPolicy.getConfigDisplayHeight(dw, dh, mRotation, config.uiMode) / mDisplayMetrics.density);
    final boolean rotated = (mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270);
    computeSizeRangesAndScreenLayout(displayInfo, rotated, config.uiMode, dw, dh, mDisplayMetrics.density, config);
    config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK) | ((displayInfo.flags & Display.FLAG_ROUND) != 0 ? Configuration.SCREENLAYOUT_ROUND_YES : Configuration.SCREENLAYOUT_ROUND_NO);
    config.compatScreenWidthDp = (int) (config.screenWidthDp / mCompatibleScreenScale);
    config.compatScreenHeightDp = (int) (config.screenHeightDp / mCompatibleScreenScale);
    config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, mDisplayMetrics, dw, dh);
    config.densityDpi = displayInfo.logicalDensityDpi;
    // Update the configuration based on available input devices, lid switch,
    // and platform configuration.
    config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
    config.keyboard = Configuration.KEYBOARD_NOKEYS;
    config.navigation = Configuration.NAVIGATION_NONAV;
    int keyboardPresence = 0;
    int navigationPresence = 0;
    final InputDevice[] devices = mInputManager.getInputDevices();
    final int len = devices.length;
    for (int i = 0; i < len; i++) {
        InputDevice device = devices[i];
        if (!device.isVirtual()) {
            final int sources = device.getSources();
            final int presenceFlag = device.isExternal() ? WindowManagerPolicy.PRESENCE_EXTERNAL : WindowManagerPolicy.PRESENCE_INTERNAL;
            if (mIsTouchDevice) {
                if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) {
                    config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
                }
            } else {
                config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
            }
            if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
                config.navigation = Configuration.NAVIGATION_TRACKBALL;
                navigationPresence |= presenceFlag;
            } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD && config.navigation == Configuration.NAVIGATION_NONAV) {
                config.navigation = Configuration.NAVIGATION_DPAD;
                navigationPresence |= presenceFlag;
            }
            if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
                config.keyboard = Configuration.KEYBOARD_QWERTY;
                keyboardPresence |= presenceFlag;
            }
        }
    }
    if (config.navigation == Configuration.NAVIGATION_NONAV && mHasPermanentDpad) {
        config.navigation = Configuration.NAVIGATION_DPAD;
        navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
    }
    // Determine whether a hard keyboard is available and enabled.
    boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
    if (hardKeyboardAvailable != mHardKeyboardAvailable) {
        mHardKeyboardAvailable = hardKeyboardAvailable;
        mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
        mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
    }
    // Let the policy update hidden states.
    config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
    config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
    config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
    mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
}
Also used : InputDevice(android.view.InputDevice) DisplayInfo(android.view.DisplayInfo) Point(android.graphics.Point)

Example 63 with DisplayInfo

use of android.view.DisplayInfo in project android_frameworks_base by DirtyUnicorns.

the class LogicalDisplay method getDisplayInfoLocked.

/**
     * Gets information about the logical display.
     *
     * @return The device info, which should be treated as immutable by the caller.
     * The logical display should allocate a new display info object whenever
     * the data changes.
     */
public DisplayInfo getDisplayInfoLocked() {
    if (mInfo == null) {
        mInfo = new DisplayInfo();
        mInfo.copyFrom(mBaseDisplayInfo);
        if (mOverrideDisplayInfo != null) {
            mInfo.appWidth = mOverrideDisplayInfo.appWidth;
            mInfo.appHeight = mOverrideDisplayInfo.appHeight;
            mInfo.smallestNominalAppWidth = mOverrideDisplayInfo.smallestNominalAppWidth;
            mInfo.smallestNominalAppHeight = mOverrideDisplayInfo.smallestNominalAppHeight;
            mInfo.largestNominalAppWidth = mOverrideDisplayInfo.largestNominalAppWidth;
            mInfo.largestNominalAppHeight = mOverrideDisplayInfo.largestNominalAppHeight;
            mInfo.logicalWidth = mOverrideDisplayInfo.logicalWidth;
            mInfo.logicalHeight = mOverrideDisplayInfo.logicalHeight;
            mInfo.overscanLeft = mOverrideDisplayInfo.overscanLeft;
            mInfo.overscanTop = mOverrideDisplayInfo.overscanTop;
            mInfo.overscanRight = mOverrideDisplayInfo.overscanRight;
            mInfo.overscanBottom = mOverrideDisplayInfo.overscanBottom;
            mInfo.rotation = mOverrideDisplayInfo.rotation;
            mInfo.logicalDensityDpi = mOverrideDisplayInfo.logicalDensityDpi;
            mInfo.physicalXDpi = mOverrideDisplayInfo.physicalXDpi;
            mInfo.physicalYDpi = mOverrideDisplayInfo.physicalYDpi;
        }
    }
    return mInfo;
}
Also used : DisplayInfo(android.view.DisplayInfo)

Example 64 with DisplayInfo

use of android.view.DisplayInfo in project android_frameworks_base by DirtyUnicorns.

the class LogicalDisplay method setDisplayInfoOverrideFromWindowManagerLocked.

/**
     * Sets overridden logical display information from the window manager.
     * This method can be used to adjust application insets, rotation, and other
     * properties that the window manager takes care of.
     *
     * @param info The logical display information, may be null.
     */
public boolean setDisplayInfoOverrideFromWindowManagerLocked(DisplayInfo info) {
    if (info != null) {
        if (mOverrideDisplayInfo == null) {
            mOverrideDisplayInfo = new DisplayInfo(info);
            mInfo = null;
            return true;
        }
        if (!mOverrideDisplayInfo.equals(info)) {
            mOverrideDisplayInfo.copyFrom(info);
            mInfo = null;
            return true;
        }
    } else if (mOverrideDisplayInfo != null) {
        mOverrideDisplayInfo = null;
        mInfo = null;
        return true;
    }
    return false;
}
Also used : DisplayInfo(android.view.DisplayInfo)

Example 65 with DisplayInfo

use of android.view.DisplayInfo in project android_frameworks_base by AOSPA.

the class ColorFade method prepare.

/**
     * Warms up the color fade in preparation for turning on or off.
     * This method prepares a GL context, and captures a screen shot.
     *
     * @param mode The desired mode for the upcoming animation.
     * @return True if the color fade is ready, false if it is uncontrollable.
     */
public boolean prepare(Context context, int mode) {
    if (DEBUG) {
        Slog.d(TAG, "prepare: mode=" + mode);
    }
    mMode = mode;
    // Get the display size and layer stack.
    // This is not expected to change while the color fade surface is showing.
    DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(mDisplayId);
    mDisplayLayerStack = displayInfo.layerStack;
    mDisplayWidth = displayInfo.getNaturalWidth();
    mDisplayHeight = displayInfo.getNaturalHeight();
    // Prepare the surface for drawing.
    if (!(createSurface() && createEglContext() && createEglSurface() && captureScreenshotTextureAndSetViewport())) {
        dismiss();
        return false;
    }
    // Init GL
    if (!attachEglContext()) {
        return false;
    }
    try {
        if (!initGLShaders(context) || !initGLBuffers() || checkGlErrors("prepare")) {
            detachEglContext();
            dismiss();
            return false;
        }
    } finally {
        detachEglContext();
    }
    // Done.
    mCreatedResources = true;
    mPrepared = true;
    // painting the screenshot as-is.
    if (mode == MODE_COOL_DOWN) {
        for (int i = 0; i < DEJANK_FRAMES; i++) {
            draw(1.0f);
        }
    }
    return true;
}
Also used : DisplayInfo(android.view.DisplayInfo)

Aggregations

DisplayInfo (android.view.DisplayInfo)186 Point (android.graphics.Point)53 Rect (android.graphics.Rect)29 RemoteException (android.os.RemoteException)19 Display (android.view.Display)11 Animation (android.view.animation.Animation)10 Bitmap (android.graphics.Bitmap)9 WindowManager (android.view.WindowManager)8 DividerSnapAlgorithm (com.android.internal.policy.DividerSnapAlgorithm)8 Canvas (android.graphics.Canvas)6 SurfaceControl (android.view.SurfaceControl)6 LayoutParams (android.view.WindowManager.LayoutParams)6 DisplayManager (android.hardware.display.DisplayManager)5 DisplayMetrics (android.util.DisplayMetrics)5 Surface (android.view.Surface)5 InputDevice (android.view.InputDevice)4 SnapTarget (com.android.internal.policy.DividerSnapAlgorithm.SnapTarget)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 OutOfResourcesException (android.view.Surface.OutOfResourcesException)3