diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2018-03-06 10:28:34 -0800 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2018-03-06 15:16:21 -0800 |
commit | f3efc25862f45faf65f3651b6b45d36e87f6783f (patch) | |
tree | 237c428e46cde22716573c716569e63003bc114c /src/com/android/launcher3/graphics/BitmapRenderer.java | |
parent | 46d259d9fb7b918ee5fee773ee615dd9111aa89f (diff) | |
download | android_packages_apps_Trebuchet-f3efc25862f45faf65f3651b6b45d36e87f6783f.tar.gz android_packages_apps_Trebuchet-f3efc25862f45faf65f3651b6b45d36e87f6783f.tar.bz2 android_packages_apps_Trebuchet-f3efc25862f45faf65f3651b6b45d36e87f6783f.zip |
Using public APIs for hardware bitmaps
Bug: 35428783
Change-Id: I4e7eeaa94e0cdfb1c76dce507a6f855e4eebbd6c
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); + } } |