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

Commit 49affdc4 authored by Owen Lin's avatar Owen Lin
Browse files

Limit the size of a ScreenNail.

bug:6528366
This bug was happened because we are trying to make a texture beyond the
max size allowed in GL.

Here is what we do in this CL:
1. Limit the size of a screen nail
2. Print warning message, if we try to allocate a texture beyond the size
3. Don't show fall-back animation if the image is not loaded yet.

Change-Id: I004b1138efd0eef7ba11aa89556f67743ca46745
parent 21c2e665
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -415,7 +415,7 @@ public class PhotoDataAdapter implements PhotoPage.Model {


        // Create a default ScreenNail if the real one is not available yet.
        // Create a default ScreenNail if the real one is not available yet.
        if (entry.screenNail == null) {
        if (entry.screenNail == null) {
            entry.screenNail = newDefaultScreenNail(item);
            entry.screenNail = newPlaceholderScreenNail(item);
            if (offset == 0) updateTileProvider(entry);
            if (offset == 0) updateTileProvider(entry);
        }
        }


@@ -632,7 +632,7 @@ public class PhotoDataAdapter implements PhotoPage.Model {
            // If this is a temporary item, don't try to get its bitmap because
            // If this is a temporary item, don't try to get its bitmap because
            // it won't be available. We will get its bitmap after a data reload.
            // it won't be available. We will get its bitmap after a data reload.
            if (isTemporaryItem(mItem)) {
            if (isTemporaryItem(mItem)) {
                return newDefaultScreenNail(mItem);
                return newPlaceholderScreenNail(mItem);
            }
            }


            Bitmap bitmap = mItem.requestImage(MediaItem.TYPE_THUMBNAIL).run(jc);
            Bitmap bitmap = mItem.requestImage(MediaItem.TYPE_THUMBNAIL).run(jc);
@@ -687,7 +687,7 @@ public class PhotoDataAdapter implements PhotoPage.Model {
    // Create a default ScreenNail when a ScreenNail is needed, but we don't yet
    // Create a default ScreenNail when a ScreenNail is needed, but we don't yet
    // have one available (because the image data is still being saved, or the
    // have one available (because the image data is still being saved, or the
    // Bitmap is still being loaded.
    // Bitmap is still being loaded.
    private ScreenNail newDefaultScreenNail(MediaItem item) {
    private ScreenNail newPlaceholderScreenNail(MediaItem item) {
        int width = item.getWidth();
        int width = item.getWidth();
        int height = item.getHeight();
        int height = item.getHeight();
        return new BitmapScreenNail(width, height);
        return new BitmapScreenNail(width, height);
+6 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,8 @@ abstract class BasicTexture implements Texture {
    protected static final int STATE_LOADED = 1;
    protected static final int STATE_LOADED = 1;
    protected static final int STATE_ERROR = -1;
    protected static final int STATE_ERROR = -1;


    private static final int MAX_TEXTURE_SIZE = 2048;

    protected int mId;
    protected int mId;
    protected int mState;
    protected int mState;


@@ -75,6 +77,10 @@ abstract class BasicTexture implements Texture {
        mHeight = height;
        mHeight = height;
        mTextureWidth = Utils.nextPowerOf2(width);
        mTextureWidth = Utils.nextPowerOf2(width);
        mTextureHeight = Utils.nextPowerOf2(height);
        mTextureHeight = Utils.nextPowerOf2(height);
        if (mTextureWidth > MAX_TEXTURE_SIZE || mTextureHeight > MAX_TEXTURE_SIZE) {
            Log.w(TAG, String.format("texture is too large: %d x %d",
                    mTextureWidth, mTextureHeight), new Exception());
        }
    }
    }


    public int getId() {
    public int getId() {
+15 −6
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.gallery3d.ui;


import android.graphics.Bitmap;
import android.graphics.Bitmap;
import android.graphics.RectF;
import android.graphics.RectF;
import android.util.Log;


import com.android.gallery3d.common.Utils;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.data.MediaItem;
@@ -35,6 +34,9 @@ public class BitmapScreenNail implements ScreenNail {
    private static final int PLACEHOLDER_COLOR = 0xFF222222;
    private static final int PLACEHOLDER_COLOR = 0xFF222222;
    // The duration of the fading animation in milliseconds
    // The duration of the fading animation in milliseconds
    private static final int DURATION = 180;
    private static final int DURATION = 180;

    private static final int MAX_SIDE = 640;

    // These are special values for mAnimationStartTime
    // These are special values for mAnimationStartTime
    private static final long ANIMATION_NOT_NEEDED = -1;
    private static final long ANIMATION_NOT_NEEDED = -1;
    private static final long ANIMATION_NEEDED = -2;
    private static final long ANIMATION_NEEDED = -2;
@@ -44,7 +46,6 @@ public class BitmapScreenNail implements ScreenNail {
    private int mHeight;
    private int mHeight;
    private Bitmap mBitmap;
    private Bitmap mBitmap;
    private BitmapTexture mTexture;
    private BitmapTexture mTexture;
    private FadeInTexture mFadeInTexture;
    private long mAnimationStartTime = ANIMATION_NOT_NEEDED;
    private long mAnimationStartTime = ANIMATION_NOT_NEEDED;


    public BitmapScreenNail(Bitmap bitmap) {
    public BitmapScreenNail(Bitmap bitmap) {
@@ -56,12 +57,17 @@ public class BitmapScreenNail implements ScreenNail {
    }
    }


    public BitmapScreenNail(int width, int height) {
    public BitmapScreenNail(int width, int height) {
        setSize(width, height);
    }

    private void setSize(int width, int height) {
        if (width == 0 || height == 0) {
        if (width == 0 || height == 0) {
            width = 640;
            width = 640;
            height = 480;
            height = 480;
        }
        }
        mWidth = width;
        float scale = Math.min(1, (float) MAX_SIDE / Math.max(width, height));
        mHeight = height;
        mWidth = Math.round(scale * width);
        mHeight = Math.round(scale * height);
    }
    }


    // Combines the two ScreenNails.
    // Combines the two ScreenNails.
@@ -101,8 +107,7 @@ public class BitmapScreenNail implements ScreenNail {
    public void updatePlaceholderSize(int width, int height) {
    public void updatePlaceholderSize(int width, int height) {
        if (mBitmap != null) return;
        if (mBitmap != null) return;
        if (width == 0 || height == 0) return;
        if (width == 0 || height == 0) return;
        mWidth = width;
        setSize(width, height);
        mHeight = height;
    }
    }


    @Override
    @Override
@@ -189,4 +194,8 @@ public class BitmapScreenNail implements ScreenNail {
        float r = (float)(now() - mAnimationStartTime) / DURATION;
        float r = (float)(now() - mAnimationStartTime) / DURATION;
        return Utils.clamp(1.0f - r, 0.0f, 1.0f);
        return Utils.clamp(1.0f - r, 0.0f, 1.0f);
    }
    }

    public boolean isShowingPlaceholder() {
        return (mBitmap == null) || isAnimating();
    }
}
}
+4 −1
Original line number Original line Diff line number Diff line
@@ -1334,7 +1334,10 @@ public class PhotoView extends GLView {
            MediaItem item = mModel.getMediaItem(i);
            MediaItem item = mModel.getMediaItem(i);
            if (item == null) continue;
            if (item == null) continue;
            ScreenNail sc = mModel.getScreenNail(i);
            ScreenNail sc = mModel.getScreenNail(i);
            if (sc == null) continue;
            if (!(sc instanceof BitmapScreenNail)
                    || ((BitmapScreenNail) sc).isShowingPlaceholder()) continue;

            // Now, sc is BitmapScreenNail and is not showing placeholder
            Rect rect = new Rect(getPhotoRect(i));
            Rect rect = new Rect(getPhotoRect(i));
            if (!Rect.intersects(fullRect, rect)) continue;
            if (!Rect.intersects(fullRect, rect)) continue;
            rect.offset(location.left, location.top);
            rect.offset(location.left, location.top);
+1 −1

File changed.

Contains only whitespace changes.