summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Haeberling <haeberling@google.com>2015-07-24 03:39:55 (GMT)
committerAndroid Git Automerger <android-git-automerger@android.com>2015-07-24 03:39:55 (GMT)
commite5f7f8831edf427cf00b17e48d1331e737d71275 (patch)
treedf3ceec784c5575c231a7ce2c4be34325e2c8de3
parent219d40829535d7b9d5a7f8d0e9cca9ba1f39f49a (diff)
parent471cd0b4dc45863b708db99596394ee9b080b755 (diff)
downloadandroid_packages_apps_Camera2-e5f7f8831edf427cf00b17e48d1331e737d71275.zip
android_packages_apps_Camera2-e5f7f8831edf427cf00b17e48d1331e737d71275.tar.gz
android_packages_apps_Camera2-e5f7f8831edf427cf00b17e48d1331e737d71275.tar.bz2
am 471cd0b4: am f0c8509b: am 1aaec6c0: am ae474d0b: [Haleakala] Change JPEG compression thread priority to BACKGROUND - 1.
* commit '471cd0b4dc45863b708db99596394ee9b080b755': [Haleakala] Change JPEG compression thread priority to BACKGROUND - 1.
-rw-r--r--src/com/android/camera/async/AndroidPriorityThread.java28
-rw-r--r--src/com/android/camera/processing/imagebackend/ImageBackend.java30
2 files changed, 44 insertions, 14 deletions
diff --git a/src/com/android/camera/async/AndroidPriorityThread.java b/src/com/android/camera/async/AndroidPriorityThread.java
new file mode 100644
index 0000000..f12bcb2
--- /dev/null
+++ b/src/com/android/camera/async/AndroidPriorityThread.java
@@ -0,0 +1,28 @@
+
+package com.android.camera.async;
+
+/**
+ * A thread that runs at the given Android thread priority.
+ */
+public class AndroidPriorityThread extends Thread {
+ private final int mAndroidThreadPriority;
+
+ /**
+ * Constructs the new thread.
+ *
+ * @param androidThreadPriority the android priority the thread should run
+ * at. This has to be one of the
+ * android.os.Process.THREAD_PRIORITY_* values.
+ * @param runnable the runnable to run at this thread priority.
+ */
+ public AndroidPriorityThread(int androidThreadPriority, Runnable runnable) {
+ super(runnable);
+ mAndroidThreadPriority = androidThreadPriority;
+ }
+
+ @Override
+ public void run() {
+ android.os.Process.setThreadPriority(mAndroidThreadPriority);
+ super.run();
+ }
+}
diff --git a/src/com/android/camera/processing/imagebackend/ImageBackend.java b/src/com/android/camera/processing/imagebackend/ImageBackend.java
index 3297ff5..fdfeea5 100644
--- a/src/com/android/camera/processing/imagebackend/ImageBackend.java
+++ b/src/com/android/camera/processing/imagebackend/ImageBackend.java
@@ -16,6 +16,9 @@
package com.android.camera.processing.imagebackend;
+import android.os.Process;
+
+import com.android.camera.async.AndroidPriorityThread;
import com.android.camera.debug.Log;
import com.android.camera.processing.ProcessingTaskConsumer;
import com.android.camera.processing.memory.ByteBufferDirectPool;
@@ -84,16 +87,18 @@ import java.util.concurrent.locks.ReentrantLock;
* already been completed should return immediately on its process call.
*/
public class ImageBackend implements ImageConsumer, ImageTaskManager {
- private final static Log.Tag TAG = new Log.Tag("ImageBackend");
-
- protected static final int FAST_THREAD_PRIORITY = Thread.MAX_PRIORITY;
- protected static final int AVERAGE_THREAD_PRIORITY = Thread.NORM_PRIORITY - 1;
- protected static final int SLOW_THREAD_PRIORITY = Thread.MIN_PRIORITY;
+ private static final Log.Tag TAG = new Log.Tag("ImageBackend");
protected static final int NUM_THREADS_FAST = 2;
protected static final int NUM_THREADS_AVERAGE = 2;
protected static final int NUM_THREADS_SLOW = 2;
+ private static final int FAST_THREAD_PRIORITY = Process.THREAD_PRIORITY_DISPLAY;
+ private static final int AVERAGE_THREAD_PRIORITY = Process.THREAD_PRIORITY_DEFAULT
+ + Process.THREAD_PRIORITY_LESS_FAVORABLE;
+ private static final int SLOW_THREAD_PRIORITY = Process.THREAD_PRIORITY_BACKGROUND
+ + Process.THREAD_PRIORITY_MORE_FAVORABLE;
+
private static final int IMAGE_BACKEND_HARD_REF_POOL_SIZE = 2;
protected final ProcessingTaskConsumer mProcessingTaskConsumer;
@@ -920,28 +925,25 @@ public class ImageBackend implements ImageConsumer, ImageTaskManager {
// Thread factories for a default constructor
private class FastThreadFactory implements ThreadFactory {
-
+ @Override
public Thread newThread(Runnable r) {
- Thread t = new Thread(r);
- t.setPriority(FAST_THREAD_PRIORITY);
+ Thread t = new AndroidPriorityThread(FAST_THREAD_PRIORITY, r);
return t;
}
}
private class AverageThreadFactory implements ThreadFactory {
-
+ @Override
public Thread newThread(Runnable r) {
- Thread t = new Thread(r);
- t.setPriority(AVERAGE_THREAD_PRIORITY);
+ Thread t = new AndroidPriorityThread(AVERAGE_THREAD_PRIORITY, r);
return t;
}
}
private class SlowThreadFactory implements ThreadFactory {
-
+ @Override
public Thread newThread(Runnable r) {
- Thread t = new Thread(r);
- t.setPriority(SLOW_THREAD_PRIORITY);
+ Thread t = new AndroidPriorityThread(SLOW_THREAD_PRIORITY, r);
return t;
}
}