Combining the Thumbnail bitmap with the background to fix background spilling in the front.
What's happening is that we first draw a background,
on top of it, we then draw the Task and because we
have a curvature the corners have pixels with transparency,
and those pixels get combined with the background pixels.
Most tasks have a transparent background or background
of the same color as the task so we don't see this
but for example, Telegram has a white background and
you can see this in the corners.
Fixed by creating a bitmap, drawing the background on it
and then drawing the thumbnail on top of it then using
that bitmap to draw it on the canvas.
Test: Put Telegram in recent Task (shouldn't be the first one) and you won't see a white border. Also when a task was in multitask the backgroudn should be draw.
Fix: 146521490
Change-Id: Id02a64ef472eb07900b0c7c5522d931d5b08f94e
diff --git a/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java b/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java
index 60b0d17..11f9ddd 100644
--- a/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java
+++ b/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java
@@ -50,6 +50,7 @@
import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Utilities;
+import com.android.launcher3.icons.BitmapRenderer;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.SystemUiController;
import com.android.quickstep.TaskOverlayFactory.TaskOverlay;
@@ -161,6 +162,23 @@
setThumbnail(task, thumbnailData, true /* refreshNow */);
}
+ /**
+ * By combining the two in a single bitmap then we only have to do a single draw
+ * call in the onDraw function. Also, this fixes a bug where the background was
+ * visible in the corners because of anti-aliasing.
+ */
+ public Bitmap combineThumbnailAndBackground(Bitmap bm) {
+ return BitmapRenderer.createHardwareBitmap(bm.getWidth(), bm.getHeight(), c -> {
+ final boolean drawBackgroundOnly = mTask == null || mTask.isLocked;
+ if (drawBackgroundOnly) {
+ c.drawPaint(mBackgroundPaint);
+ } else {
+ c.drawPaint(mBackgroundPaint);
+ c.drawBitmap(bm, 0, 0, null);
+ }
+ });
+ }
+
/** Updates the shader, paint, matrix to redraw. */
public void refresh() {
refresh(false);
@@ -173,6 +191,7 @@
private void refresh(boolean shouldRefreshOverlay) {
if (mThumbnailData != null && mThumbnailData.thumbnail != null) {
Bitmap bm = mThumbnailData.thumbnail;
+ bm = combineThumbnailAndBackground(bm);
bm.prepareToDraw();
mBitmapShader = new BitmapShader(bm, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mPaint.setShader(mBitmapShader);
@@ -194,7 +213,6 @@
* <p>
* If dimAlpha is 0, no dimming is applied; if dimAlpha is 1, the thumbnail will be the
* extracted background color.
- *
*/
public void setDimAlpha(float dimAlpha) {
mDimAlpha = dimAlpha;
@@ -296,18 +314,6 @@
return;
}
}
-
- // Always draw the background since the snapshots might be translucent or partially empty
- // (For example, tasks been reparented out of dismissing split root when drag-to-dismiss
- // split screen).
- canvas.drawRoundRect(x, y, width, height, cornerRadius, cornerRadius, mBackgroundPaint);
-
- final boolean drawBackgroundOnly = mTask == null || mTask.isLocked || mBitmapShader == null
- || mThumbnailData == null;
- if (drawBackgroundOnly) {
- return;
- }
-
canvas.drawRoundRect(x, y, width, height, cornerRadius, cornerRadius, mPaint);
}
@@ -338,7 +344,6 @@
private void updateThumbnailPaintFilter() {
ColorFilter filter = getColorFilter(mDimAlpha);
- mBackgroundPaint.setColorFilter(filter);
int alpha = (int) (mDimAlpha * 255);
mDimmingPaintAfterClearing.setAlpha(alpha);
if (mBitmapShader != null) {