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

Commit 049978e6 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Fix wallpaper placement + performance improvement

Wallpaper would have the wrong placement during
first frame because it would be center aligned
in a surface that's not big enough.

Also removed old OpenGl implementation, in favor of new
hardware accelerated canvas.

Change-Id: Ic9c9eaa817e1f6494aa5431d8278f2c28b2c45a9
Fixes: 66926914
Test: set wallpapaer with different offsets, orientations and devices
parent 0b57d2f5
Loading
Loading
Loading
Loading
+23 −8
Original line number Original line Diff line number Diff line
@@ -388,11 +388,12 @@ public class WallpaperManager {


        public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault,
        public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault,
                @SetWallpaperFlags int which) {
                @SetWallpaperFlags int which) {
            return peekWallpaperBitmap(context, returnDefault, which, context.getUserId());
            return peekWallpaperBitmap(context, returnDefault, which, context.getUserId(),
                    false /* hardware */);
        }
        }


        public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault,
        public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault,
                @SetWallpaperFlags int which, int userId) {
                @SetWallpaperFlags int which, int userId, boolean hardware) {
            if (mService != null) {
            if (mService != null) {
                try {
                try {
                    if (!mService.isWallpaperSupported(context.getOpPackageName())) {
                    if (!mService.isWallpaperSupported(context.getOpPackageName())) {
@@ -409,7 +410,7 @@ public class WallpaperManager {
                mCachedWallpaper = null;
                mCachedWallpaper = null;
                mCachedWallpaperUserId = 0;
                mCachedWallpaperUserId = 0;
                try {
                try {
                    mCachedWallpaper = getCurrentWallpaperLocked(context, userId);
                    mCachedWallpaper = getCurrentWallpaperLocked(context, userId, hardware);
                    mCachedWallpaperUserId = userId;
                    mCachedWallpaperUserId = userId;
                } catch (OutOfMemoryError e) {
                } catch (OutOfMemoryError e) {
                    Log.w(TAG, "Out of memory loading the current wallpaper: " + e);
                    Log.w(TAG, "Out of memory loading the current wallpaper: " + e);
@@ -447,7 +448,7 @@ public class WallpaperManager {
            }
            }
        }
        }


        private Bitmap getCurrentWallpaperLocked(Context context, int userId) {
        private Bitmap getCurrentWallpaperLocked(Context context, int userId, boolean hardware) {
            if (mService == null) {
            if (mService == null) {
                Log.w(TAG, "WallpaperService not running");
                Log.w(TAG, "WallpaperService not running");
                return null;
                return null;
@@ -460,6 +461,9 @@ public class WallpaperManager {
                if (fd != null) {
                if (fd != null) {
                    try {
                    try {
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        if (hardware) {
                            options.inPreferredConfig = Bitmap.Config.HARDWARE;
                        }
                        return BitmapFactory.decodeFileDescriptor(
                        return BitmapFactory.decodeFileDescriptor(
                                fd.getFileDescriptor(), null, options);
                                fd.getFileDescriptor(), null, options);
                    } catch (OutOfMemoryError e) {
                    } catch (OutOfMemoryError e) {
@@ -814,12 +818,23 @@ public class WallpaperManager {
    }
    }


    /**
    /**
     * Like {@link #getDrawable()} but returns a Bitmap.
     * Like {@link #getDrawable()} but returns a Bitmap with default {@link Bitmap.Config}.
     *
     *
     * @hide
     * @hide
     */
     */
    public Bitmap getBitmap() {
    public Bitmap getBitmap() {
        return getBitmapAsUser(mContext.getUserId());
        return getBitmap(false);
    }

    /**
     * Like {@link #getDrawable()} but returns a Bitmap.
     *
     * @param hardware Asks for a hardware backed bitmap.
     * @see Bitmap.Config#HARDWARE
     * @hide
     */
    public Bitmap getBitmap(boolean hardware) {
        return getBitmapAsUser(mContext.getUserId(), hardware);
    }
    }


    /**
    /**
@@ -827,8 +842,8 @@ public class WallpaperManager {
     *
     *
     * @hide
     * @hide
     */
     */
    public Bitmap getBitmapAsUser(int userId) {
    public Bitmap getBitmapAsUser(int userId, boolean hardware) {
        return sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM, userId);
        return sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM, userId, hardware);
    }
    }


    /**
    /**
+78 −439

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Original line Diff line number Diff line
@@ -124,8 +124,8 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
        } else {
        } else {
            if (selectedUser != null) {
            if (selectedUser != null) {
                // Show the selected user's static wallpaper.
                // Show the selected user's static wallpaper.
                return LoaderResult.success(
                return LoaderResult.success(mWallpaperManager.getBitmapAsUser(
                        mWallpaperManager.getBitmapAsUser(selectedUser.getIdentifier()));
                        selectedUser.getIdentifier(), true /* hardware */));


            } else {
            } else {
                // When there is no selected user, show the system wallpaper
                // When there is no selected user, show the system wallpaper