diff options
Diffstat (limited to 'src/com/android/launcher3/graphics')
3 files changed, 40 insertions, 14 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); + } } diff --git a/src/com/android/launcher3/graphics/DragPreviewProvider.java b/src/com/android/launcher3/graphics/DragPreviewProvider.java index b77078582..e60a2c70b 100644 --- a/src/com/android/launcher3/graphics/DragPreviewProvider.java +++ b/src/com/android/launcher3/graphics/DragPreviewProvider.java @@ -24,19 +24,17 @@ import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; -import android.graphics.Region.Op; import android.graphics.drawable.Drawable; import android.os.Handler; import android.view.View; import com.android.launcher3.BubbleTextView; import com.android.launcher3.Launcher; -import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.R; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.folder.FolderIcon; -import com.android.launcher3.uioverrides.UiFactory; import com.android.launcher3.util.UiThreadHelper; +import com.android.launcher3.widget.LauncherAppWidgetHostView; import java.nio.ByteBuffer; @@ -119,28 +117,26 @@ public class DragPreviewProvider { * Responsibility for the bitmap is transferred to the caller. */ public Bitmap createDragBitmap() { - float scale = 1f; int width = mView.getWidth(); int height = mView.getHeight(); - boolean forceSoftwareRenderer = false; if (mView instanceof BubbleTextView) { Drawable d = ((BubbleTextView) mView).getIcon(); Rect bounds = getDrawableBounds(d); width = bounds.width(); height = bounds.height(); } else if (mView instanceof LauncherAppWidgetHostView) { - scale = ((LauncherAppWidgetHostView) mView).getScaleToFit(); + float scale = ((LauncherAppWidgetHostView) mView).getScaleToFit(); width = (int) (mView.getWidth() * scale); height = (int) (mView.getHeight() * scale); // Use software renderer for widgets as we know that they already work - forceSoftwareRenderer = true; + return BitmapRenderer.createSoftwareBitmap(width + blurSizeOutline, + height + blurSizeOutline, (c) -> drawDragView(c, scale)); } - final float scaleFinal = scale; - return UiFactory.createFromRenderer(width + blurSizeOutline, height + blurSizeOutline, - forceSoftwareRenderer, (c) -> drawDragView(c, scaleFinal)); + return BitmapRenderer.createHardwareBitmap(width + blurSizeOutline, + height + blurSizeOutline, (c) -> drawDragView(c, 1)); } public final void generateDragOutline(Bitmap preview) { diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java index 8abfdeae8..4a9cdd9a0 100644 --- a/src/com/android/launcher3/graphics/LauncherIcons.java +++ b/src/com/android/launcher3/graphics/LauncherIcons.java @@ -52,7 +52,6 @@ import com.android.launcher3.Utilities; import com.android.launcher3.model.PackageItemInfo; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.ShortcutInfoCompat; -import com.android.launcher3.uioverrides.UiFactory; import com.android.launcher3.util.Provider; import com.android.launcher3.util.Themes; @@ -349,7 +348,7 @@ public class LauncherIcons implements AutoCloseable { final ItemInfoWithIcon badge = getShortcutInfoBadge(shortcutInfo, cache); result.color = badge.iconColor; - result.icon = UiFactory.createFromRenderer(mIconBitmapSize, mIconBitmapSize, false, (c) -> { + result.icon = BitmapRenderer.createHardwareBitmap(mIconBitmapSize, mIconBitmapSize, (c) -> { getShadowGenerator().recreateIcon(unbadgedfinal, c); badgeWithDrawable(c, new FastBitmapDrawable(badge)); }); |