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

Commit c39e8e89 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Add OpenGL backend to ImageWallpaper Bug #5204874"

parents 19bc995e 407ec78b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13974,6 +13974,7 @@ package android.opengl {
  }
  public final class GLUtils {
    method public static java.lang.String getEGLErrorString(int);
    method public static int getInternalFormat(android.graphics.Bitmap);
    method public static int getType(android.graphics.Bitmap);
    method public static void texImage2D(int, int, int, android.graphics.Bitmap, int);
+37 −29
Original line number Diff line number Diff line
@@ -107,19 +107,22 @@ public class WallpaperManager {
        private final int mHeight;
        private int mDrawLeft;
        private int mDrawTop;
        private final Paint mPaint;

        private FastBitmapDrawable(Bitmap bitmap) {
            mBitmap = bitmap;
            mWidth = bitmap.getWidth();
            mHeight = bitmap.getHeight();

            setBounds(0, 0, mWidth, mHeight);

            mPaint = new Paint();
            mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
        }

        @Override
        public void draw(Canvas canvas) {
            Paint paint = new Paint();
            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
            canvas.drawBitmap(mBitmap, mDrawLeft, mDrawTop, paint);
            canvas.drawBitmap(mBitmap, mDrawLeft, mDrawTop, mPaint);
        }

        @Override
@@ -133,34 +136,24 @@ public class WallpaperManager {
            mDrawTop = top + (bottom-top - mHeight) / 2;
        }

        @Override
        public void setBounds(Rect bounds) {
            // TODO Auto-generated method stub
            super.setBounds(bounds);
        }

        @Override
        public void setAlpha(int alpha) {
            throw new UnsupportedOperationException(
                    "Not supported with this drawable");
            throw new UnsupportedOperationException("Not supported with this drawable");
        }

        @Override
        public void setColorFilter(ColorFilter cf) {
            throw new UnsupportedOperationException(
                    "Not supported with this drawable");
            throw new UnsupportedOperationException("Not supported with this drawable");
        }

        @Override
        public void setDither(boolean dither) {
            throw new UnsupportedOperationException(
                    "Not supported with this drawable");
            throw new UnsupportedOperationException("Not supported with this drawable");
        }

        @Override
        public void setFilterBitmap(boolean filter) {
            throw new UnsupportedOperationException(
                    "Not supported with this drawable");
            throw new UnsupportedOperationException("Not supported with this drawable");
        }

        @Override
@@ -230,7 +223,7 @@ public class WallpaperManager {
                }
                mWallpaper = null;
                try {
                    mWallpaper = getCurrentWallpaperLocked(context);
                    mWallpaper = getCurrentWallpaperLocked();
                } catch (OutOfMemoryError e) {
                    Log.w(TAG, "No memory load current wallpaper", e);
                }
@@ -253,7 +246,7 @@ public class WallpaperManager {
            }
        }

        private Bitmap getCurrentWallpaperLocked(Context context) {
        private Bitmap getCurrentWallpaperLocked() {
            try {
                Bundle params = new Bundle();
                ParcelFileDescriptor fd = mService.getWallpaper(this, params);
@@ -265,17 +258,19 @@ public class WallpaperManager {
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        Bitmap bm = BitmapFactory.decodeFileDescriptor(
                                fd.getFileDescriptor(), null, options);
                        return generateBitmap(context, bm, width, height);
                        return generateBitmap(bm, width, height);
                    } catch (OutOfMemoryError e) {
                        Log.w(TAG, "Can't decode file", e);
                    } finally {
                        try {
                            fd.close();
                        } catch (IOException e) {
                            // Ignore
                        }
                    }
                }
            } catch (RemoteException e) {
                // Ignore
            }
            return null;
        }
@@ -291,27 +286,29 @@ public class WallpaperManager {
                    try {
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        Bitmap bm = BitmapFactory.decodeStream(is, null, options);
                        return generateBitmap(context, bm, width, height);
                        return generateBitmap(bm, width, height);
                    } catch (OutOfMemoryError e) {
                        Log.w(TAG, "Can't decode stream", e);
                    } finally {
                        try {
                            is.close();
                        } catch (IOException e) {
                            // Ignore
                        }
                    }
                }
            } catch (RemoteException e) {
                // Ignore
            }
            return null;
        }
    }
    
    private static Object mSync = new Object();
    private static final Object sSync = new Object[0];
    private static Globals sGlobals;

    static void initGlobals(Looper looper) {
        synchronized (mSync) {
        synchronized (sSync) {
            if (sGlobals == null) {
                sGlobals = new Globals(looper);
            }
@@ -390,8 +387,7 @@ public class WallpaperManager {
    public Drawable getFastDrawable() {
        Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true);
        if (bm != null) {
            Drawable dr = new FastBitmapDrawable(bm);
            return dr;
            return new FastBitmapDrawable(bm);
        }
        return null;
    }
@@ -406,12 +402,20 @@ public class WallpaperManager {
    public Drawable peekFastDrawable() {
        Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false);
        if (bm != null) {
            Drawable dr = new FastBitmapDrawable(bm);
            return dr;
            return new FastBitmapDrawable(bm);
        }
        return null;
    }

    /**
     * Like {@link #getDrawable()} but returns a Bitmap.
     * 
     * @hide
     */
    public Bitmap getBitmap() {
        return sGlobals.peekWallpaperBitmap(mContext, true);
    }

    /**
     * Remove all internal references to the last loaded wallpaper.  Useful
     * for apps that want to reduce memory usage when they only temporarily
@@ -464,6 +468,7 @@ public class WallpaperManager {
                }
            }
        } catch (RemoteException e) {
            // Ignore
        }
    }
    
@@ -493,6 +498,7 @@ public class WallpaperManager {
                }
            }
        } catch (RemoteException e) {
            // Ignore
        }
    }

@@ -524,6 +530,7 @@ public class WallpaperManager {
                }
            }
        } catch (RemoteException e) {
            // Ignore
        }
    }

@@ -594,6 +601,7 @@ public class WallpaperManager {
        try {
            sGlobals.mService.setDimensionHints(minimumWidth, minimumHeight);
        } catch (RemoteException e) {
            // Ignore
        }
    }
    
@@ -690,7 +698,7 @@ public class WallpaperManager {
        setResource(com.android.internal.R.drawable.default_wallpaper);
    }
    
    static Bitmap generateBitmap(Context context, Bitmap bm, int width, int height) {
    static Bitmap generateBitmap(Bitmap bm, int width, int height) {
        if (bm == null) {
            return null;
        }
@@ -717,7 +725,7 @@ public class WallpaperManager {

            if (deltaw > 0 || deltah > 0) {
                // We need to scale up so it covers the entire area.
                float scale = 1.0f;
                float scale;
                if (deltaw > deltah) {
                    scale = width / (float)targetRect.right;
                } else {
+8 −52
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.ComponentCallbacks2;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.opengl.GLUtils;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.util.Log;
@@ -401,51 +402,6 @@ public abstract class HardwareRenderer {
            return mDirtyRegionsEnabled;
        }

        /**
         * Return a string for the EGL error code, or the hex representation
         * if the error is unknown.
         * 
         * @param error The EGL error to convert into a String.
         * 
         * @return An error string correponding to the EGL error code.
         */
        static String getEGLErrorString(int error) {
            switch (error) {
                case EGL_SUCCESS:
                    return "EGL_SUCCESS";
                case EGL_NOT_INITIALIZED:
                    return "EGL_NOT_INITIALIZED";
                case EGL_BAD_ACCESS:
                    return "EGL_BAD_ACCESS";
                case EGL_BAD_ALLOC:
                    return "EGL_BAD_ALLOC";
                case EGL_BAD_ATTRIBUTE:
                    return "EGL_BAD_ATTRIBUTE";
                case EGL_BAD_CONFIG:
                    return "EGL_BAD_CONFIG";
                case EGL_BAD_CONTEXT:
                    return "EGL_BAD_CONTEXT";
                case EGL_BAD_CURRENT_SURFACE:
                    return "EGL_BAD_CURRENT_SURFACE";
                case EGL_BAD_DISPLAY:
                    return "EGL_BAD_DISPLAY";
                case EGL_BAD_MATCH:
                    return "EGL_BAD_MATCH";
                case EGL_BAD_NATIVE_PIXMAP:
                    return "EGL_BAD_NATIVE_PIXMAP";
                case EGL_BAD_NATIVE_WINDOW:
                    return "EGL_BAD_NATIVE_WINDOW";
                case EGL_BAD_PARAMETER:
                    return "EGL_BAD_PARAMETER";
                case EGL_BAD_SURFACE:
                    return "EGL_BAD_SURFACE";
                case EGL11.EGL_CONTEXT_LOST:
                    return "EGL_CONTEXT_LOST";
                default:
                    return "0x" + Integer.toHexString(error);
            }
        }

        /**
         * Checks for OpenGL errors. If an error has occured, {@link #destroy(boolean)}
         * is invoked and the requested flag is turned off. The error code is
@@ -458,7 +414,7 @@ public abstract class HardwareRenderer {
                    // something bad has happened revert to
                    // normal rendering.
                    fallback(error != EGL11.EGL_CONTEXT_LOST);
                    Log.w(LOG_TAG, "EGL error: " + getEGLErrorString(error));
                    Log.w(LOG_TAG, "EGL error: " + GLUtils.getEGLErrorString(error));
                }
            }
        }
@@ -523,14 +479,14 @@ public abstract class HardwareRenderer {
                    
                    if (sEglDisplay == EGL_NO_DISPLAY) {
                        throw new RuntimeException("eglGetDisplay failed "
                                + getEGLErrorString(sEgl.eglGetError()));
                                + GLUtils.getEGLErrorString(sEgl.eglGetError()));
                    }
                    
                    // We can now initialize EGL for that display
                    int[] version = new int[2];
                    if (!sEgl.eglInitialize(sEglDisplay, version)) {
                        throw new RuntimeException("eglInitialize failed " +
                                getEGLErrorString(sEgl.eglGetError()));
                                GLUtils.getEGLErrorString(sEgl.eglGetError()));
                    }
        
                    sEglConfig = chooseEglConfig();
@@ -579,7 +535,7 @@ public abstract class HardwareRenderer {

            if (!sEgl.eglChooseConfig(sEglDisplay, configSpec, configs, 1, configsCount)) {
                throw new IllegalArgumentException("eglChooseConfig failed " +
                        getEGLErrorString(sEgl.eglGetError()));
                        GLUtils.getEGLErrorString(sEgl.eglGetError()));
            } else if (configsCount[0] > 0) {
                if ("choice".equalsIgnoreCase(debug)) {
                    printConfig(configs[0]);
@@ -647,7 +603,7 @@ public abstract class HardwareRenderer {
             */
            if (!sEgl.eglMakeCurrent(sEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
                throw new Surface.OutOfResourcesException("eglMakeCurrent failed "
                        + getEGLErrorString(sEgl.eglGetError()));
                        + GLUtils.getEGLErrorString(sEgl.eglGetError()));
            }

            // If mDirtyRegions is set, this means we have an EGL configuration
@@ -734,7 +690,7 @@ public abstract class HardwareRenderer {
                    return false;
                }
                throw new RuntimeException("createWindowSurface failed "
                        + getEGLErrorString(error));
                        + GLUtils.getEGLErrorString(error));
            }
            return true;
        }
@@ -856,7 +812,7 @@ public abstract class HardwareRenderer {
                if (!sEgl.eglMakeCurrent(sEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
                    fallback(true);
                    Log.e(LOG_TAG, "eglMakeCurrent failed " +
                            getEGLErrorString(sEgl.eglGetError()));
                            GLUtils.getEGLErrorString(sEgl.eglGetError()));
                    return SURFACE_STATE_ERROR;
                } else {
                    return SURFACE_STATE_UPDATED;
+48 −1
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package android.opengl;

import javax.microedition.khronos.opengles.GL10;
import android.graphics.Bitmap;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGL11;

/**
 *
 * Utility class to help bridging OpenGL ES and Android APIs.
@@ -222,6 +224,51 @@ public final class GLUtils {
        }
    }

    /**
     * Return a string for the EGL error code, or the hex representation
     * if the error is unknown.
     * 
     * @param error The EGL error to convert into a String.
     * 
     * @return An error string corresponding to the EGL error code.
     */
    public static String getEGLErrorString(int error) {
        switch (error) {
            case EGL10.EGL_SUCCESS:
                return "EGL_SUCCESS";
            case EGL10.EGL_NOT_INITIALIZED:
                return "EGL_NOT_INITIALIZED";
            case EGL10.EGL_BAD_ACCESS:
                return "EGL_BAD_ACCESS";
            case EGL10.EGL_BAD_ALLOC:
                return "EGL_BAD_ALLOC";
            case EGL10.EGL_BAD_ATTRIBUTE:
                return "EGL_BAD_ATTRIBUTE";
            case EGL10.EGL_BAD_CONFIG:
                return "EGL_BAD_CONFIG";
            case EGL10.EGL_BAD_CONTEXT:
                return "EGL_BAD_CONTEXT";
            case EGL10.EGL_BAD_CURRENT_SURFACE:
                return "EGL_BAD_CURRENT_SURFACE";
            case EGL10.EGL_BAD_DISPLAY:
                return "EGL_BAD_DISPLAY";
            case EGL10.EGL_BAD_MATCH:
                return "EGL_BAD_MATCH";
            case EGL10.EGL_BAD_NATIVE_PIXMAP:
                return "EGL_BAD_NATIVE_PIXMAP";
            case EGL10.EGL_BAD_NATIVE_WINDOW:
                return "EGL_BAD_NATIVE_WINDOW";
            case EGL10.EGL_BAD_PARAMETER:
                return "EGL_BAD_PARAMETER";
            case EGL10.EGL_BAD_SURFACE:
                return "EGL_BAD_SURFACE";
            case EGL11.EGL_CONTEXT_LOST:
                return "EGL_CONTEXT_LOST";
            default:
                return "0x" + Integer.toHexString(error);
        }
    }

    native private static void nativeClassInit();

    native private static int native_getInternalFormat(Bitmap bitmap);
+352 −41

File changed.

Preview size limit exceeded, changes collapsed.

Loading