From d58bdf9b9fcbcc8c941cf5b0565865c89b3400bb Mon Sep 17 00:00:00 2001 From: Sihua Ma Date: Mon, 9 May 2022 20:12:17 +0000 Subject: [PATCH] Upload bitmap to GPU in RemoteViews Upload the bitmap to GPU when the RemoteView intends to use it. Test: Manually verified that widget drawing method is accelerated by approximately 2 micro seconds. The longest drawing time down from 52 micro seconds to 47 micro seconds. Fix: 226298376 Change-Id: If57f3127dfa0c01550c8388a43a79acac37fcfb7 --- core/java/android/widget/RemoteViews.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index 18874f7689295..3165654d806d1 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -1780,6 +1780,21 @@ public class RemoteViews implements Parcelable, Filter { Object value = getParameterValue(view); try { MethodHandle method = getMethod(view, this.methodName, param, true /* async */); + // Upload the bitmap to GPU if the parameter is of type Bitmap or Icon. + // Since bitmaps in framework are seldomly modified, this is supposed to accelerate + // the operations. + if (value instanceof Bitmap bitmap) { + bitmap.prepareToDraw(); + } + + if (value instanceof Icon icon + && (icon.getType() == Icon.TYPE_BITMAP + || icon.getType() == Icon.TYPE_ADAPTIVE_BITMAP)) { + Bitmap bitmap = icon.getBitmap(); + if (bitmap != null) { + bitmap.prepareToDraw(); + } + } if (method != null) { Runnable endAction = (Runnable) method.invoke(view, value);