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

Commit f7ccc82e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Using public APIs for hardware bitmaps" into ub-launcher3-master

parents 9027e6ad f3efc258
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -18,28 +18,22 @@ package com.android.launcher3.uioverrides;

import static com.android.launcher3.LauncherState.NORMAL;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.view.View.AccessibilityDelegate;

import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherStateManager.StateHandler;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.graphics.BitmapRenderer;
import com.android.launcher3.util.TouchController;
import com.android.quickstep.OverviewInteractionState;
import com.android.quickstep.RecentsModel;
import com.android.quickstep.RecentsView;
import com.android.systemui.shared.recents.view.RecentsTransition;

public class UiFactory {

    private static final String CONTROL_REMOTE_APP_TRANSITION_PERMISSION =
            "android.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS";

    public static final boolean USE_HARDWARE_BITMAP = false; // FeatureFlags.IS_DOGFOOD_BUILD;

    public static TouchController[] createTouchControllers(Launcher launcher) {
        if (FeatureFlags.ENABLE_TWO_SWIPE_TARGETS) {
            return new TouchController[] {
@@ -72,17 +66,6 @@ public class UiFactory {
                || !launcher.isInState(NORMAL) || !launcher.hasWindowFocus());
    }

    public static Bitmap createFromRenderer(int width, int height, boolean forceSoftwareRenderer,
            BitmapRenderer renderer) {
        if (USE_HARDWARE_BITMAP && !forceSoftwareRenderer) {
            return RecentsTransition.createHardwareBitmap(width, height, renderer::render);
        } else {
            Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            renderer.render(new Canvas(result));
            return result;
        }
    }

    public static void resetOverview(Launcher launcher) {
        RecentsView recents = launcher.getOverviewPanel();
        recents.reset();
+2 −4
Original line number Diff line number Diff line
@@ -45,12 +45,10 @@ import android.util.Log;

import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.graphics.BitmapInfo;
import com.android.launcher3.graphics.ColorExtractor;
import com.android.launcher3.graphics.BitmapRenderer;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.uioverrides.UiFactory;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.InstantAppResolver;
import com.android.launcher3.util.Preconditions;
@@ -126,7 +124,7 @@ public class IconCache {
        // automatically be loaded as ALPHA_8888.
        mLowResOptions.inPreferredConfig = Bitmap.Config.RGB_565;

        if (UiFactory.USE_HARDWARE_BITMAP) {
        if (BitmapRenderer.USE_HARDWARE_BITMAP) {
            mHighResOptions = new BitmapFactory.Options();
            mHighResOptions.inPreferredConfig = Bitmap.Config.HARDWARE;
        } else {
+2 −2
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.R;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.folder.PreviewBackground;
import com.android.launcher3.uioverrides.UiFactory;
import com.android.launcher3.graphics.BitmapRenderer;
import com.android.launcher3.util.Preconditions;

/**
@@ -113,7 +113,7 @@ public class FolderAdaptiveIcon extends AdaptiveIconDrawable {
        final float previewShiftX = shiftFactor * previewWidth;
        final float previewShiftY = shiftFactor * previewHeight;

        Bitmap previewBitmap = UiFactory.createFromRenderer(previewWidth, previewHeight, false,
        Bitmap previewBitmap = BitmapRenderer.createHardwareBitmap(previewWidth, previewHeight,
                (canvas) -> {
                    int count = canvas.save();
                    canvas.translate(previewShiftX, previewShiftY);
+33 −2
Original line number Diff line number Diff line
@@ -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);
     }
}
+6 −10
Original line number Diff line number Diff line
@@ -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) {
Loading