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

Commit 6013cf64 authored by Sergey Vasilinets's avatar Sergey Vasilinets Committed by Android (Google) Code Review
Browse files

Merge "Fix premultiplied flag for hardware bitmaps"

parents 2cda00e2 656117be
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -643,7 +643,7 @@ static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle,
        if (!bitmap.get()) {
            return NULL;
        }
        return createBitmap(env, bitmap.release(), kBitmapCreateFlag_None);
        return createBitmap(env, bitmap.release(), getPremulBitmapCreateFlags(isMutable));
    }

    SkColorType dstCT = GraphicsJNI::legacyBitmapConfigToColorType(dstConfigHandle);
@@ -1306,7 +1306,7 @@ static jobject Bitmap_copyPreserveInternalConfig(JNIEnv* env, jobject, jlong bit
        doThrowRE(env, "Could not copy a hardware bitmap.");
        return NULL;
    }
    return createBitmap(env, allocator.getStorageObjAndReset(), kBitmapCreateFlag_None);
    return createBitmap(env, allocator.getStorageObjAndReset(), getPremulBitmapCreateFlags(false));
}

static jobject Bitmap_createHardwareBitmap(JNIEnv* env, jobject, jobject graphicBuffer) {
@@ -1316,7 +1316,7 @@ static jobject Bitmap_createHardwareBitmap(JNIEnv* env, jobject, jobject graphic
        ALOGW("failed to create hardware bitmap from graphic buffer");
        return NULL;
    }
    return bitmap::createBitmap(env, bitmap.release(), android::bitmap::kBitmapCreateFlag_None);
    return bitmap::createBitmap(env, bitmap.release(), getPremulBitmapCreateFlags(false));
}

static jobject Bitmap_createGraphicBufferHandle(JNIEnv* env, jobject, jlong bitmapPtr) {
+25 −13
Original line number Diff line number Diff line
@@ -38,11 +38,11 @@ public class BitmapTest extends TestCase {

        assertEquals("rowbytes", 400, bm1.getRowBytes());
        assertEquals("rowbytes", 200, bm2.getRowBytes());
        assertEquals("rowbytes", 200, bm3.getRowBytes());
        assertEquals("rowbytes", 400, bm3.getRowBytes());

        assertEquals("byteCount", 80000, bm1.getByteCount());
        assertEquals("byteCount", 40000, bm2.getByteCount());
        assertEquals("byteCount", 40000, bm3.getByteCount());
        assertEquals("byteCount", 80000, bm3.getByteCount());

        assertEquals("height", 200, bm1.getHeight());
        assertEquals("height", 200, bm2.getHeight());
@@ -54,7 +54,7 @@ public class BitmapTest extends TestCase {

        assertTrue("getConfig", bm1.getConfig() == Bitmap.Config.ARGB_8888);
        assertTrue("getConfig", bm2.getConfig() == Bitmap.Config.RGB_565);
        assertTrue("getConfig", bm3.getConfig() == Bitmap.Config.ARGB_4444);
        assertTrue("getConfig", bm3.getConfig() == Bitmap.Config.ARGB_8888);
    }

    @SmallTest
@@ -231,4 +231,16 @@ public class BitmapTest extends TestCase {
            }
        }
    }

    @SmallTest
    public void testCreateHardwareBitmapFromGraphicBuffer() {
        GraphicBuffer buffer = GraphicBuffer.create(10, 10, PixelFormat.RGBA_8888,
                GraphicBuffer.USAGE_HW_TEXTURE | GraphicBuffer.USAGE_SOFTWARE_MASK);
        Canvas canvas = buffer.lockCanvas();
        canvas.drawColor(Color.YELLOW);
        buffer.unlockCanvasAndPost(canvas);
        Bitmap hardwareBitmap = Bitmap.createHardwareBitmap(buffer);
        assertTrue(hardwareBitmap.isPremultiplied());
        assertFalse(hardwareBitmap.isMutable());
    }
}