Using public APIs for hardware bitmaps

Bug: 35428783
Change-Id: I4e7eeaa94e0cdfb1c76dce507a6f855e4eebbd6c
This commit is contained in:
Sunny Goyal
2018-03-06 10:28:34 -08:00
parent 46d259d9fb
commit f3efc25862
7 changed files with 44 additions and 52 deletions
@@ -15,9 +15,40 @@
*/
package com.android.launcher3.graphics;
import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Picture;
import android.os.Build;
public interface BitmapRenderer {
import com.android.launcher3.Utilities;
void render(Canvas out);
public class BitmapRenderer {
public static final boolean USE_HARDWARE_BITMAP = false && Utilities.ATLEAST_P;
public static Bitmap createSoftwareBitmap(int width, int height, Renderer renderer) {
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
renderer.draw(new Canvas(result));
return result;
}
@TargetApi(Build.VERSION_CODES.P)
public static Bitmap createHardwareBitmap(int width, int height, Renderer renderer) {
if (!USE_HARDWARE_BITMAP) {
return createSoftwareBitmap(width, height, renderer);
}
Picture picture = new Picture();
renderer.draw(picture.beginRecording(width, height));
picture.endRecording();
return Bitmap.createBitmap(picture);
}
/**
* Interface representing a bitmap draw operation.
*/
public interface Renderer {
void draw(Canvas out);
}
}