Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f303ff63 authored by chilun_huang's avatar chilun_huang Committed by Steve Kondik
Browse files

[AssetAtlas]: Fix AssetAtlas not consider all size of texture.

Symptom:
Atlas service get exception because the result is null.

Root Cause:
The original logic will miss the largest width in each thread.
Take two processors as an example, first thread will miss 2048, second thread will miss 1984.
With some condition, only 2048*2048 or 1984*2048 can exceed the mThreshold.
In this case, the mResults is empty and cause crash when trying to use the first result.

Solution:
Adjust the boundary and the condition so that it can consider all size of texture.

Change-Id: Id54de57cd1501ed7355f2237f05726d2965aed6d
parent dbcee9e5
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -402,12 +402,12 @@ public class AssetAtlasService extends IAssetAtlas.Stub {
            new ComputeWorker(MIN_SIZE, MAX_SIZE, STEP, bitmaps, pixelCount, results, null).run();
        } else {
            int start = MIN_SIZE;
            int end = MAX_SIZE - (cpuCount - 1) * STEP;
            int end = MAX_SIZE;
            int step = STEP * cpuCount;

            final CountDownLatch signal = new CountDownLatch(cpuCount);

            for (int i = 0; i < cpuCount; i++, start += STEP, end += STEP) {
            for (int i = 0; i < cpuCount; i++, start += STEP) {
                ComputeWorker worker = new ComputeWorker(start, end, step,
                        bitmaps, pixelCount, results, signal);
                new Thread(worker, "Atlas Worker #" + (i + 1)).start();
@@ -421,6 +421,13 @@ public class AssetAtlasService extends IAssetAtlas.Stub {
            }
        }

        if (results.size() == 0) {
            // This should not happend.
            // If it happens, it means all bitmaps can't fit max size of texture.
            Log.e(LOG_TAG, "Could not find any configuration!!!");
            return null;
        }

        // Maximize the number of packed bitmaps, minimize the texture size
        Collections.sort(results, new Comparator<WorkerResult>() {
            @Override
@@ -697,8 +704,8 @@ public class AssetAtlasService extends IAssetAtlas.Stub {

            Atlas.Entry entry = new Atlas.Entry();
            for (Atlas.Type type : Atlas.Type.values()) {
                for (int width = mStart; width < mEnd; width += mStep) {
                    for (int height = MIN_SIZE; height < MAX_SIZE; height += STEP) {
                for (int width = mStart; width <= mEnd; width += mStep) {
                    for (int height = MIN_SIZE; height <= MAX_SIZE; height += STEP) {
                        // If the atlas is not big enough, skip it
                        if (width * height <= mThreshold) continue;