Merge "Use a process queue pattern to eliminate concurrency bugs" into sc-v2-dev
This commit is contained in:
@@ -24,7 +24,6 @@ import android.util.ArraySet;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a page of a launcher page used by the wallpaper
|
* This class represents a page of a launcher page used by the wallpaper
|
||||||
@@ -84,11 +83,6 @@ public class EngineWindowPage {
|
|||||||
return mCallbackAreas;
|
return mCallbackAreas;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** run operations on this page */
|
|
||||||
public synchronized void execSync(Consumer<EngineWindowPage> run) {
|
|
||||||
run.accept(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** nullify the area color */
|
/** nullify the area color */
|
||||||
public void removeColor(RectF colorArea) {
|
public void removeColor(RectF colorArea) {
|
||||||
mRectFColors.remove(colorArea);
|
mRectFColors.remove(colorArea);
|
||||||
|
|||||||
@@ -1490,7 +1490,7 @@ public abstract class WallpaperService extends Service {
|
|||||||
//below is the default implementation
|
//below is the default implementation
|
||||||
if (xOffset % xOffsetStep > MIN_PAGE_ALLOWED_MARGIN
|
if (xOffset % xOffsetStep > MIN_PAGE_ALLOWED_MARGIN
|
||||||
|| !mSurfaceHolder.getSurface().isValid()) return;
|
|| !mSurfaceHolder.getSurface().isValid()) return;
|
||||||
int xPage;
|
int xCurrentPage;
|
||||||
int xPages;
|
int xPages;
|
||||||
if (!validStep(xOffsetStep)) {
|
if (!validStep(xOffsetStep)) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -1498,30 +1498,34 @@ public abstract class WallpaperService extends Service {
|
|||||||
}
|
}
|
||||||
xOffset = 0;
|
xOffset = 0;
|
||||||
xOffsetStep = 1;
|
xOffsetStep = 1;
|
||||||
xPage = 0;
|
xCurrentPage = 0;
|
||||||
xPages = 1;
|
xPages = 1;
|
||||||
} else {
|
} else {
|
||||||
xPages = Math.round(1 / xOffsetStep) + 1;
|
xPages = Math.round(1 / xOffsetStep) + 1;
|
||||||
xOffsetStep = (float) 1 / (float) xPages;
|
xOffsetStep = (float) 1 / (float) xPages;
|
||||||
float shrink = (float) (xPages - 1) / (float) xPages;
|
float shrink = (float) (xPages - 1) / (float) xPages;
|
||||||
xOffset *= shrink;
|
xOffset *= shrink;
|
||||||
xPage = Math.round(xOffset / xOffsetStep);
|
xCurrentPage = Math.round(xOffset / xOffsetStep);
|
||||||
}
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "xPages " + xPages + " xPage " + xPage);
|
Log.d(TAG, "xPages " + xPages + " xPage " + xCurrentPage);
|
||||||
Log.d(TAG, "xOffsetStep " + xOffsetStep + " xOffset " + xOffset);
|
Log.d(TAG, "xOffsetStep " + xOffsetStep + " xOffset " + xOffset);
|
||||||
}
|
}
|
||||||
EngineWindowPage current;
|
|
||||||
synchronized (mLock) {
|
float finalXOffsetStep = xOffsetStep;
|
||||||
|
float finalXOffset = xOffset;
|
||||||
|
mHandler.post(() -> {
|
||||||
|
int xPage = xCurrentPage;
|
||||||
|
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, xOffsetStep);
|
initWindowPages(mWindowPages, finalXOffsetStep);
|
||||||
}
|
}
|
||||||
if (mLocalColorsToAdd.size() != 0) {
|
if (mLocalColorsToAdd.size() != 0) {
|
||||||
for (RectF colorArea : mLocalColorsToAdd) {
|
for (RectF colorArea : mLocalColorsToAdd) {
|
||||||
if (!isValid(colorArea)) continue;
|
if (!isValid(colorArea)) continue;
|
||||||
mLocalColorAreas.add(colorArea);
|
mLocalColorAreas.add(colorArea);
|
||||||
int colorPage = getRectFPage(colorArea, xOffsetStep);
|
int colorPage = getRectFPage(colorArea, finalXOffsetStep);
|
||||||
EngineWindowPage currentPage = mWindowPages[colorPage];
|
EngineWindowPage currentPage = mWindowPages[colorPage];
|
||||||
if (currentPage == null) {
|
if (currentPage == null) {
|
||||||
currentPage = new EngineWindowPage();
|
currentPage = new EngineWindowPage();
|
||||||
@@ -1539,7 +1543,8 @@ public abstract class WallpaperService extends Service {
|
|||||||
Log.e(TAG, "error xPage >= mWindowPages.length page: " + xPage);
|
Log.e(TAG, "error xPage >= mWindowPages.length page: " + xPage);
|
||||||
Log.e(TAG, "error on page " + xPage + " out of " + xPages);
|
Log.e(TAG, "error on page " + xPage + " out of " + xPages);
|
||||||
Log.e(TAG,
|
Log.e(TAG,
|
||||||
"error on xOffsetStep " + xOffsetStep + " xOffset " + xOffset);
|
"error on xOffsetStep " + finalXOffsetStep
|
||||||
|
+ " xOffset " + finalXOffset);
|
||||||
}
|
}
|
||||||
xPage = mWindowPages.length - 1;
|
xPage = mWindowPages.length - 1;
|
||||||
}
|
}
|
||||||
@@ -1547,13 +1552,14 @@ public abstract class WallpaperService extends Service {
|
|||||||
if (current == null) {
|
if (current == null) {
|
||||||
if (DEBUG) Log.d(TAG, "making page " + xPage + " out of " + xPages);
|
if (DEBUG) Log.d(TAG, "making page " + xPage + " out of " + xPages);
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "xOffsetStep " + xOffsetStep + " xOffset " + xOffset);
|
Log.d(TAG, "xOffsetStep " + finalXOffsetStep + " xOffset "
|
||||||
|
+ finalXOffset);
|
||||||
}
|
}
|
||||||
current = new EngineWindowPage();
|
current = new EngineWindowPage();
|
||||||
mWindowPages[xPage] = current;
|
mWindowPages[xPage] = current;
|
||||||
}
|
}
|
||||||
}
|
updatePage(current, xPage, xPages, finalXOffsetStep);
|
||||||
updatePage(current, xPage, xPages, xOffsetStep);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initWindowPages(EngineWindowPage[] windowPages, float step) {
|
private void initWindowPages(EngineWindowPage[] windowPages, float step) {
|
||||||
@@ -1603,10 +1609,8 @@ public abstract class WallpaperService extends Service {
|
|||||||
if (DEBUG) Log.d(TAG, "result of pixel copy is " + res);
|
if (DEBUG) Log.d(TAG, "result of pixel copy is " + res);
|
||||||
if (res != PixelCopy.SUCCESS) {
|
if (res != PixelCopy.SUCCESS) {
|
||||||
Bitmap lastBitmap = currentPage.getBitmap();
|
Bitmap lastBitmap = currentPage.getBitmap();
|
||||||
currentPage.execSync((p) -> {
|
// assign the last bitmap taken for now
|
||||||
// assign the last bitmap taken for now
|
currentPage.setBitmap(mLastScreenshot);
|
||||||
p.setBitmap(mLastScreenshot);
|
|
||||||
});
|
|
||||||
Bitmap lastScreenshot = mLastScreenshot;
|
Bitmap lastScreenshot = mLastScreenshot;
|
||||||
if (lastScreenshot != null && !lastScreenshot.isRecycled()
|
if (lastScreenshot != null && !lastScreenshot.isRecycled()
|
||||||
&& !Objects.equals(lastBitmap, lastScreenshot)) {
|
&& !Objects.equals(lastBitmap, lastScreenshot)) {
|
||||||
@@ -1615,10 +1619,8 @@ public abstract class WallpaperService extends Service {
|
|||||||
} else {
|
} else {
|
||||||
mLastScreenshot = finalScreenShot;
|
mLastScreenshot = finalScreenShot;
|
||||||
// going to hold this lock for a while
|
// going to hold this lock for a while
|
||||||
currentPage.execSync((p) -> {
|
currentPage.setBitmap(finalScreenShot);
|
||||||
p.setBitmap(finalScreenShot);
|
currentPage.setLastUpdateTime(current);
|
||||||
p.setLastUpdateTime(current);
|
|
||||||
});
|
|
||||||
updatePageColors(currentPage, pageIndx, numPages, xOffsetStep);
|
updatePageColors(currentPage, pageIndx, numPages, xOffsetStep);
|
||||||
}
|
}
|
||||||
}, mHandler);
|
}, mHandler);
|
||||||
@@ -1698,16 +1700,14 @@ public abstract class WallpaperService extends Service {
|
|||||||
private void resetWindowPages() {
|
private void resetWindowPages() {
|
||||||
if (supportsLocalColorExtraction()) return;
|
if (supportsLocalColorExtraction()) return;
|
||||||
mLastWindowPage = -1;
|
mLastWindowPage = -1;
|
||||||
synchronized (mLock) {
|
mHandler.post(() -> {
|
||||||
for (int i = 0; i < mWindowPages.length; i++) {
|
for (int i = 0; i < mWindowPages.length; i++) {
|
||||||
EngineWindowPage page = mWindowPages[i];
|
EngineWindowPage page = mWindowPages[i];
|
||||||
if (page != null) {
|
if (page != null) {
|
||||||
page.execSync((p) -> {
|
page.setLastUpdateTime(0L);
|
||||||
p.setLastUpdateTime(0L);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getRectFPage(RectF area, float step) {
|
private int getRectFPage(RectF area, float step) {
|
||||||
@@ -1730,10 +1730,10 @@ public abstract class WallpaperService extends Service {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "addLocalColorsAreas adding local color areas " + regions);
|
Log.d(TAG, "addLocalColorsAreas adding local color areas " + regions);
|
||||||
}
|
}
|
||||||
float step = mPendingXOffsetStep;
|
|
||||||
|
|
||||||
List<WallpaperColors> colors = getLocalWallpaperColors(regions);
|
List<WallpaperColors> colors = getLocalWallpaperColors(regions);
|
||||||
synchronized (mLock) {
|
mHandler.post(() -> {
|
||||||
|
float step = mPendingXOffsetStep;
|
||||||
if (!validStep(step)) {
|
if (!validStep(step)) {
|
||||||
step = 0;
|
step = 0;
|
||||||
}
|
}
|
||||||
@@ -1749,26 +1749,25 @@ public abstract class WallpaperService extends Service {
|
|||||||
page.addArea(area);
|
page.addArea(area);
|
||||||
WallpaperColors color = colors.get(i);
|
WallpaperColors color = colors.get(i);
|
||||||
if (color != null && !color.equals(page.getColors(area))) {
|
if (color != null && !color.equals(page.getColors(area))) {
|
||||||
page.execSync(p -> {
|
page.addWallpaperColors(area, color);
|
||||||
p.addWallpaperColors(area, color);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mLocalColorsToAdd.add(area);
|
mLocalColorsToAdd.add(area);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
for (int i = 0; i < colors.size() && colors.get(i) != null; i++) {
|
||||||
|
try {
|
||||||
for (int i = 0; i < colors.size() && colors.get(i) != null; i++) {
|
mConnection.onLocalWallpaperColorsChanged(regions.get(i), colors.get(i),
|
||||||
try {
|
mDisplayContext.getDisplayId());
|
||||||
mConnection.onLocalWallpaperColorsChanged(regions.get(i), colors.get(i),
|
} catch (RemoteException e) {
|
||||||
mDisplayContext.getDisplayId());
|
Log.e(TAG, "Error calling Connection.onLocalWallpaperColorsChanged", e);
|
||||||
} catch (RemoteException e) {
|
return;
|
||||||
Log.e(TAG, "Error calling Connection.onLocalWallpaperColorsChanged", e);
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
processLocalColors(mPendingXOffset, mPendingYOffset);
|
||||||
processLocalColors(mPendingXOffset, mPendingYOffset);
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1778,7 +1777,7 @@ public abstract class WallpaperService extends Service {
|
|||||||
*/
|
*/
|
||||||
public void removeLocalColorsAreas(@NonNull List<RectF> regions) {
|
public void removeLocalColorsAreas(@NonNull List<RectF> regions) {
|
||||||
if (supportsLocalColorExtraction()) return;
|
if (supportsLocalColorExtraction()) return;
|
||||||
synchronized (mLock) {
|
mHandler.post(() -> {
|
||||||
float step = mPendingXOffsetStep;
|
float step = mPendingXOffsetStep;
|
||||||
mLocalColorsToAdd.removeAll(regions);
|
mLocalColorsToAdd.removeAll(regions);
|
||||||
mLocalColorAreas.removeAll(regions);
|
mLocalColorAreas.removeAll(regions);
|
||||||
@@ -1792,12 +1791,10 @@ public abstract class WallpaperService extends Service {
|
|||||||
// no page should be null
|
// no page should be null
|
||||||
EngineWindowPage page = mWindowPages[pageInx];
|
EngineWindowPage page = mWindowPages[pageInx];
|
||||||
if (page != null) {
|
if (page != null) {
|
||||||
page.execSync(p -> {
|
page.removeArea(area);
|
||||||
p.removeArea(area);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private @NonNull List<WallpaperColors> getLocalWallpaperColors(@NonNull List<RectF> areas) {
|
private @NonNull List<WallpaperColors> getLocalWallpaperColors(@NonNull List<RectF> areas) {
|
||||||
|
|||||||
Reference in New Issue
Block a user