Merge "Throttle calls to processLocalColors" into tm-qpr-dev am: 779584186e
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21335118 Change-Id: I0ffdc70e85aa837804bc077650d1d0ddf27c177e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -170,6 +170,7 @@ public abstract class WallpaperService extends Service {
|
|||||||
Float.NEGATIVE_INFINITY);
|
Float.NEGATIVE_INFINITY);
|
||||||
|
|
||||||
private static final int NOTIFY_COLORS_RATE_LIMIT_MS = 1000;
|
private static final int NOTIFY_COLORS_RATE_LIMIT_MS = 1000;
|
||||||
|
private static final int PROCESS_LOCAL_COLORS_INTERVAL_MS = 1000;
|
||||||
|
|
||||||
private static final boolean ENABLE_WALLPAPER_DIMMING =
|
private static final boolean ENABLE_WALLPAPER_DIMMING =
|
||||||
SystemProperties.getBoolean("persist.debug.enable_wallpaper_dimming", true);
|
SystemProperties.getBoolean("persist.debug.enable_wallpaper_dimming", true);
|
||||||
@@ -275,9 +276,13 @@ public abstract class WallpaperService extends Service {
|
|||||||
MotionEvent mPendingMove;
|
MotionEvent mPendingMove;
|
||||||
boolean mIsInAmbientMode;
|
boolean mIsInAmbientMode;
|
||||||
|
|
||||||
// Needed for throttling onComputeColors.
|
// used to throttle onComputeColors
|
||||||
private long mLastColorInvalidation;
|
private long mLastColorInvalidation;
|
||||||
private final Runnable mNotifyColorsChanged = this::notifyColorsChanged;
|
private final Runnable mNotifyColorsChanged = this::notifyColorsChanged;
|
||||||
|
|
||||||
|
// used to throttle processLocalColors
|
||||||
|
private long mLastProcessLocalColorsTimestamp;
|
||||||
|
private AtomicBoolean mProcessLocalColorsPending = new AtomicBoolean(false);
|
||||||
private final Supplier<Long> mClockFunction;
|
private final Supplier<Long> mClockFunction;
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
|
|
||||||
@@ -1591,7 +1596,26 @@ public abstract class WallpaperService extends Service {
|
|||||||
processLocalColors(xOffset, xOffsetStep);
|
processLocalColors(xOffset, xOffsetStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread-safe util to call {@link #processLocalColorsInternal} with a minimum interval of
|
||||||
|
* {@link #PROCESS_LOCAL_COLORS_INTERVAL_MS} between two calls.
|
||||||
|
*/
|
||||||
private void processLocalColors(float xOffset, float xOffsetStep) {
|
private void processLocalColors(float xOffset, float xOffsetStep) {
|
||||||
|
if (mProcessLocalColorsPending.compareAndSet(false, true)) {
|
||||||
|
final long now = mClockFunction.get();
|
||||||
|
final long timeSinceLastColorProcess = now - mLastProcessLocalColorsTimestamp;
|
||||||
|
final long timeToWait = Math.max(0,
|
||||||
|
PROCESS_LOCAL_COLORS_INTERVAL_MS - timeSinceLastColorProcess);
|
||||||
|
|
||||||
|
mHandler.postDelayed(() -> {
|
||||||
|
mLastProcessLocalColorsTimestamp = now + timeToWait;
|
||||||
|
mProcessLocalColorsPending.set(false);
|
||||||
|
processLocalColorsInternal(xOffset, xOffsetStep);
|
||||||
|
}, timeToWait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processLocalColorsInternal(float xOffset, float xOffsetStep) {
|
||||||
// implemented by the wallpaper
|
// implemented by the wallpaper
|
||||||
if (supportsLocalColorExtraction()) return;
|
if (supportsLocalColorExtraction()) return;
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -1625,40 +1649,39 @@ public abstract class WallpaperService extends Service {
|
|||||||
|
|
||||||
float finalXOffsetStep = xOffsetStep;
|
float finalXOffsetStep = xOffsetStep;
|
||||||
float finalXOffset = xOffset;
|
float finalXOffset = xOffset;
|
||||||
mHandler.post(() -> {
|
|
||||||
Trace.beginSection("WallpaperService#processLocalColors");
|
Trace.beginSection("WallpaperService#processLocalColors");
|
||||||
resetWindowPages();
|
resetWindowPages();
|
||||||
int xPage = xCurrentPage;
|
int xPage = xCurrentPage;
|
||||||
EngineWindowPage current;
|
EngineWindowPage current;
|
||||||
if (mWindowPages.length == 0 || (mWindowPages.length != xPages)) {
|
if (mWindowPages.length == 0 || (mWindowPages.length != xPages)) {
|
||||||
mWindowPages = new EngineWindowPage[xPages];
|
mWindowPages = new EngineWindowPage[xPages];
|
||||||
initWindowPages(mWindowPages, finalXOffsetStep);
|
initWindowPages(mWindowPages, finalXOffsetStep);
|
||||||
|
}
|
||||||
|
if (mLocalColorsToAdd.size() != 0) {
|
||||||
|
for (RectF colorArea : mLocalColorsToAdd) {
|
||||||
|
if (!isValid(colorArea)) continue;
|
||||||
|
mLocalColorAreas.add(colorArea);
|
||||||
|
int colorPage = getRectFPage(colorArea, finalXOffsetStep);
|
||||||
|
EngineWindowPage currentPage = mWindowPages[colorPage];
|
||||||
|
currentPage.setLastUpdateTime(0);
|
||||||
|
currentPage.removeColor(colorArea);
|
||||||
}
|
}
|
||||||
if (mLocalColorsToAdd.size() != 0) {
|
mLocalColorsToAdd.clear();
|
||||||
for (RectF colorArea : mLocalColorsToAdd) {
|
}
|
||||||
if (!isValid(colorArea)) continue;
|
if (xPage >= mWindowPages.length) {
|
||||||
mLocalColorAreas.add(colorArea);
|
if (DEBUG) {
|
||||||
int colorPage = getRectFPage(colorArea, finalXOffsetStep);
|
Log.e(TAG, "error xPage >= mWindowPages.length page: " + xPage);
|
||||||
EngineWindowPage currentPage = mWindowPages[colorPage];
|
Log.e(TAG, "error on page " + xPage + " out of " + xPages);
|
||||||
currentPage.setLastUpdateTime(0);
|
Log.e(TAG,
|
||||||
currentPage.removeColor(colorArea);
|
"error on xOffsetStep " + finalXOffsetStep
|
||||||
}
|
+ " xOffset " + finalXOffset);
|
||||||
mLocalColorsToAdd.clear();
|
|
||||||
}
|
}
|
||||||
if (xPage >= mWindowPages.length) {
|
xPage = mWindowPages.length - 1;
|
||||||
if (DEBUG) {
|
}
|
||||||
Log.e(TAG, "error xPage >= mWindowPages.length page: " + xPage);
|
current = mWindowPages[xPage];
|
||||||
Log.e(TAG, "error on page " + xPage + " out of " + xPages);
|
updatePage(current, xPage, xPages, finalXOffsetStep);
|
||||||
Log.e(TAG,
|
Trace.endSection();
|
||||||
"error on xOffsetStep " + finalXOffsetStep
|
|
||||||
+ " xOffset " + finalXOffset);
|
|
||||||
}
|
|
||||||
xPage = mWindowPages.length - 1;
|
|
||||||
}
|
|
||||||
current = mWindowPages[xPage];
|
|
||||||
updatePage(current, xPage, xPages, finalXOffsetStep);
|
|
||||||
Trace.endSection();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initWindowPages(EngineWindowPage[] windowPages, float step) {
|
private void initWindowPages(EngineWindowPage[] windowPages, float step) {
|
||||||
|
|||||||
Reference in New Issue
Block a user