diff options
Diffstat (limited to 'src/com/android/launcher3/graphics/BitmapRenderer.java')
-rw-r--r-- | src/com/android/launcher3/graphics/BitmapRenderer.java | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/com/android/launcher3/graphics/BitmapRenderer.java b/src/com/android/launcher3/graphics/BitmapRenderer.java index 4652ded16..f2a9f7c99 100644 --- a/src/com/android/launcher3/graphics/BitmapRenderer.java +++ b/src/com/android/launcher3/graphics/BitmapRenderer.java @@ -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); + } } |