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

Commit 713e1bb9 authored by Romain Guy's avatar Romain Guy
Browse files

Add API to enable mipmaps on Bitmap

Bug #7353771

This API can be used when scaling large images down to a small size
to get nicer looking results.

Change-Id: If09087eed36077eee5355f6047a3ca67747d7d9e
parent d43b22da
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -8263,6 +8263,7 @@ package android.graphics {
    method public int getScaledWidth(int);
    method public final int getWidth();
    method public final boolean hasAlpha();
    method public final boolean hasMipMap();
    method public final boolean isMutable();
    method public final boolean isPremultiplied();
    method public final boolean isRecycled();
@@ -8271,6 +8272,7 @@ package android.graphics {
    method public boolean sameAs(android.graphics.Bitmap);
    method public void setDensity(int);
    method public void setHasAlpha(boolean);
    method public final void setHasMipMap(boolean);
    method public void setPixel(int, int, int);
    method public void setPixels(int[], int, int, int, int, int, int);
    method public void writeToParcel(android.os.Parcel, int);
+12 −1
Original line number Diff line number Diff line
@@ -353,6 +353,15 @@ static void Bitmap_setHasAlpha(JNIEnv* env, jobject, SkBitmap* bitmap,
    bitmap->setIsOpaque(!hasAlpha);
}

static jboolean Bitmap_hasMipMap(JNIEnv* env, jobject, SkBitmap* bitmap) {
    return bitmap->hasHardwareMipMap();
}

static void Bitmap_setHasMipMap(JNIEnv* env, jobject, SkBitmap* bitmap,
                                jboolean hasMipMap) {
    bitmap->setHasHardwareMipMap(hasMipMap);
}

///////////////////////////////////////////////////////////////////////////////

static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
@@ -666,6 +675,8 @@ static JNINativeMethod gBitmapMethods[] = {
    {   "nativeConfig",             "(I)I", (void*)Bitmap_config },
    {   "nativeHasAlpha",           "(I)Z", (void*)Bitmap_hasAlpha },
    {   "nativeSetHasAlpha",        "(IZ)V", (void*)Bitmap_setHasAlpha },
    {   "nativeHasMipMap",          "(I)Z", (void*)Bitmap_hasMipMap },
    {   "nativeSetHasMipMap",       "(IZ)V", (void*)Bitmap_setHasMipMap },
    {   "nativeCreateFromParcel",
        "(Landroid/os/Parcel;)Landroid/graphics/Bitmap;",
        (void*)Bitmap_createFromParcel },
+48 −1
Original line number Diff line number Diff line
@@ -1029,6 +1029,51 @@ public final class Bitmap implements Parcelable {
        nativeSetHasAlpha(mNativeBitmap, hasAlpha);
    }

    /**
     * Indicates whether the renderer responsible for drawing this
     * bitmap should attempt to use mipmaps when this bitmap is drawn
     * scaled down.
     * 
     * If you know that you are going to draw this bitmap at less than
     * 50% of its original size, you may be able to obtain a higher
     * quality
     * 
     * This property is only a suggestion that can be ignored by the
     * renderer. It is not guaranteed to have any effect.
     * 
     * @return true if the renderer should attempt to use mipmaps,
     *         false otherwise
     * 
     * @see #setHasMipMap(boolean)
     */
    public final boolean hasMipMap() {
        return nativeHasMipMap(mNativeBitmap);
    }

    /**
     * Set a hint for the renderer responsible for drawing this bitmap
     * indicating that it should attempt to use mipmaps when this bitmap
     * is drawn scaled down.
     *
     * If you know that you are going to draw this bitmap at less than
     * 50% of its original size, you may be able to obtain a higher
     * quality by turning this property on.
     * 
     * Note that if the renderer respects this hint it might have to
     * allocate extra memory to hold the mipmap levels for this bitmap.
     *
     * This property is only a suggestion that can be ignored by the
     * renderer. It is not guaranteed to have any effect.
     *
     * @param hasMipMap indicates whether the renderer should attempt
     *                  to use mipmaps
     *
     * @see #hasMipMap()
     */
    public final void setHasMipMap(boolean hasMipMap) {
        nativeSetHasMipMap(mNativeBitmap, hasMipMap);
    }

    /**
     * Fills the bitmap's pixels with the specified {@link Color}.
     *
@@ -1356,7 +1401,6 @@ public final class Bitmap implements Parcelable {
    private static native int nativeHeight(int nativeBitmap);
    private static native int nativeRowBytes(int nativeBitmap);
    private static native int nativeConfig(int nativeBitmap);
    private static native boolean nativeHasAlpha(int nativeBitmap);

    private static native int nativeGetPixel(int nativeBitmap, int x, int y);
    private static native void nativeGetPixels(int nativeBitmap, int[] pixels,
@@ -1385,7 +1429,10 @@ public final class Bitmap implements Parcelable {
                                                    int[] offsetXY);

    private static native void nativePrepareToDraw(int nativeBitmap);
    private static native boolean nativeHasAlpha(int nativeBitmap);
    private static native void nativeSetHasAlpha(int nBitmap, boolean hasAlpha);
    private static native boolean nativeHasMipMap(int nativeBitmap);
    private static native void nativeSetHasMipMap(int nBitmap, boolean hasMipMap);
    private static native boolean nativeSameAs(int nb0, int nb1);
    
    /* package */ final int ni() {
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ namespace uirenderer {

#define ALPHA_THRESHOLD 0

#define FILTER(paint) (paint && paint->isFilterBitmap() ? GL_LINEAR : GL_NEAREST)
#define FILTER(paint) (!paint || paint->isFilterBitmap() ? GL_LINEAR : GL_NEAREST)

///////////////////////////////////////////////////////////////////////////////
// Globals
+9 −1
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ struct Texture {
        minFilter = GL_NEAREST;
        magFilter = GL_NEAREST;

        mipMap = false;

        firstFilter = true;
        firstWrap = true;

@@ -83,6 +85,8 @@ struct Texture {
                glBindTexture(renderTarget, id);
            }

            if (mipMap && min == GL_LINEAR) min = GL_LINEAR_MIPMAP_LINEAR;

            glTexParameteri(renderTarget, GL_TEXTURE_MIN_FILTER, min);
            glTexParameteri(renderTarget, GL_TEXTURE_MAG_FILTER, mag);
        }
@@ -116,7 +120,12 @@ struct Texture {
     * Optional, size of the original bitmap.
     */
    uint32_t bitmapSize;
    /**
     * Indicates whether this texture will use trilinear filtering.
     */
    bool mipMap;

private:
    /**
     * Last wrap modes set on this texture. Defaults to GL_CLAMP_TO_EDGE.
     */
@@ -129,7 +138,6 @@ struct Texture {
    GLenum minFilter;
    GLenum magFilter;

private:
    bool firstFilter;
    bool firstWrap;
}; // struct Texture
Loading