Merge "Move all the ImageWallpaper logic outside the main thread" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a90ccc4457
@@ -45,7 +45,6 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.systemui.dagger.qualifiers.Background;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.flags.FeatureFlags;
|
||||
import com.android.systemui.util.concurrency.DelayableExecutor;
|
||||
import com.android.systemui.wallpapers.canvas.WallpaperLocalColorExtractor;
|
||||
@@ -57,7 +56,6 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -88,17 +86,12 @@ public class ImageWallpaper extends WallpaperService {
|
||||
private final DelayableExecutor mBackgroundExecutor;
|
||||
private static final int DELAY_UNLOAD_BITMAP = 2000;
|
||||
|
||||
@Main
|
||||
private final Executor mMainExecutor;
|
||||
|
||||
@Inject
|
||||
public ImageWallpaper(FeatureFlags featureFlags,
|
||||
@Background DelayableExecutor backgroundExecutor,
|
||||
@Main Executor mainExecutor) {
|
||||
@Background DelayableExecutor backgroundExecutor) {
|
||||
super();
|
||||
mFeatureFlags = featureFlags;
|
||||
mBackgroundExecutor = backgroundExecutor;
|
||||
mMainExecutor = mainExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -662,13 +655,9 @@ public class ImageWallpaper extends WallpaperService {
|
||||
loadWallpaperAndDrawFrameInternal();
|
||||
} else {
|
||||
mBitmapUsages++;
|
||||
|
||||
// drawing is done on the main thread
|
||||
mMainExecutor.execute(() -> {
|
||||
drawFrameOnCanvas(mBitmap);
|
||||
reportEngineShown(false);
|
||||
unloadBitmapIfNotUsed();
|
||||
});
|
||||
drawFrameOnCanvas(mBitmap);
|
||||
reportEngineShown(false);
|
||||
unloadBitmapIfNotUsedInternal();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -706,11 +695,15 @@ public class ImageWallpaper extends WallpaperService {
|
||||
|
||||
private void unloadBitmapIfNotUsedSynchronized() {
|
||||
synchronized (mLock) {
|
||||
mBitmapUsages -= 1;
|
||||
if (mBitmapUsages <= 0) {
|
||||
mBitmapUsages = 0;
|
||||
unloadBitmapInternal();
|
||||
}
|
||||
unloadBitmapIfNotUsedInternal();
|
||||
}
|
||||
}
|
||||
|
||||
private void unloadBitmapIfNotUsedInternal() {
|
||||
mBitmapUsages -= 1;
|
||||
if (mBitmapUsages <= 0) {
|
||||
mBitmapUsages = 0;
|
||||
unloadBitmapInternal();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,6 @@ public class ImageWallpaperTest extends SysuiTestCase {
|
||||
private FeatureFlags mFeatureFlags;
|
||||
|
||||
FakeSystemClock mFakeSystemClock = new FakeSystemClock();
|
||||
FakeExecutor mFakeMainExecutor = new FakeExecutor(mFakeSystemClock);
|
||||
FakeExecutor mFakeBackgroundExecutor = new FakeExecutor(mFakeSystemClock);
|
||||
|
||||
private CountDownLatch mEventCountdown;
|
||||
@@ -163,7 +162,7 @@ public class ImageWallpaperTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
private ImageWallpaper createImageWallpaper() {
|
||||
return new ImageWallpaper(mFeatureFlags, mFakeBackgroundExecutor, mFakeMainExecutor) {
|
||||
return new ImageWallpaper(mFeatureFlags, mFakeBackgroundExecutor) {
|
||||
@Override
|
||||
public Engine onCreateEngine() {
|
||||
return new GLEngine(mHandler) {
|
||||
@@ -242,7 +241,7 @@ public class ImageWallpaperTest extends SysuiTestCase {
|
||||
|
||||
|
||||
private ImageWallpaper createImageWallpaperCanvas() {
|
||||
return new ImageWallpaper(mFeatureFlags, mFakeBackgroundExecutor, mFakeMainExecutor) {
|
||||
return new ImageWallpaper(mFeatureFlags, mFakeBackgroundExecutor) {
|
||||
@Override
|
||||
public Engine onCreateEngine() {
|
||||
return new CanvasEngine() {
|
||||
@@ -315,11 +314,10 @@ public class ImageWallpaperTest extends SysuiTestCase {
|
||||
assertThat(mFakeBackgroundExecutor.numPending()).isAtLeast(1);
|
||||
|
||||
int n = 0;
|
||||
while (mFakeBackgroundExecutor.numPending() + mFakeMainExecutor.numPending() >= 1) {
|
||||
while (mFakeBackgroundExecutor.numPending() >= 1) {
|
||||
n++;
|
||||
assertThat(n).isAtMost(10);
|
||||
mFakeBackgroundExecutor.runNextReady();
|
||||
mFakeMainExecutor.runNextReady();
|
||||
mFakeSystemClock.advanceTime(1000);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user