forked from Blendman974/faceclaw
Phone CPU usage optimization
This commit is contained in:
1 parent
44eddedc01
commit
9560f3ac8d
26 files changed
+606
-167
No files matched your search
@@ -258,7 +258,9 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
// included in the newer composite).
|
||||
private long lastStoredCompositeSeq;
|
||||
|
||||
private final SurfaceCompositor compositor = new SurfaceCompositor();
|
||||
// Wire submissions need screenGray + the shell scene, never preview pixels.
|
||||
// Preview/screenshot/recording callers render those explicitly on demand.
|
||||
private final SurfaceCompositor compositor = new SurfaceCompositor(false);
|
||||
|
||||
// Phone-side model of the CFW's 192 KiB resource cache.
|
||||
// Reset whenever the image pipeline / EvenHub session is torn down: the
|
||||
@@ -4025,17 +4027,6 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
|
||||
private void logLine(String line) {
|
||||
Log.i(TAG, line);
|
||||
final FaceclawBleCommunicatorListener current = listener;
|
||||
if (current == null) {
|
||||
return;
|
||||
}
|
||||
mainHandler.post(() -> {
|
||||
try {
|
||||
current.onLog(line);
|
||||
} catch (Throwable t) {
|
||||
Log.w(TAG, "listener onLog failed", t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static String timestamp(long elapsedMs) {
|
||||
|
||||
@@ -111,7 +111,7 @@ public final class FaceclawPreviewCompositor {
|
||||
int frameId,
|
||||
java.nio.ByteBuffer glyphs
|
||||
) {
|
||||
compositor.applyAndComposite(
|
||||
compositor.submitSurface(
|
||||
surfaceId, new AndroidByteReader(pixels8bpp), rectX, rectY, rectWidth, rectHeight, contentFingerprint,
|
||||
glyphs == null ? null : new AndroidByteReader(glyphs));
|
||||
FrameTimings.getInstance().finishFrame(frameId, "composited (preview-only, no glasses)");
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.faceclaw.app;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
@@ -13,7 +15,7 @@ import java.security.MessageDigest;
|
||||
import java.security.SecureRandom;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/** Explicit-address, bounded, one-request-per-connection input port. JS polls on its own thread. */
|
||||
/** Explicit-address, bounded input port. Complete requests notify JS on the main thread. */
|
||||
public final class FaceclawRemoteInput {
|
||||
private static final FaceclawRemoteInput INSTANCE = new FaceclawRemoteInput();
|
||||
public static FaceclawRemoteInput getInstance() { return INSTANCE; }
|
||||
@@ -22,6 +24,22 @@ public final class FaceclawRemoteInput {
|
||||
private String pending, reply;
|
||||
private long nextId, requestId;
|
||||
private long deadline;
|
||||
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
private Runnable requestListener;
|
||||
|
||||
public synchronized void setRequestListener(Runnable listener) { requestListener = listener; }
|
||||
|
||||
private void notifyRequestReady(long id) {
|
||||
// Called with this monitor held; posting avoids entering JS on the socket thread.
|
||||
mainHandler.post(() -> {
|
||||
Runnable callback;
|
||||
synchronized (this) {
|
||||
if (requestId != id || pending == null || System.currentTimeMillis() >= deadline) return;
|
||||
callback = requestListener;
|
||||
}
|
||||
if (callback != null) callback.run();
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized String start(int port) { return startAddress(port, "127.0.0.1"); }
|
||||
public synchronized String startAddress(int port, String address) {
|
||||
@@ -81,6 +99,7 @@ public final class FaceclawRemoteInput {
|
||||
reply = null;
|
||||
pending = new JSONObject().put("id", requestId).put("expiresAt", deadline)
|
||||
.put("body", text).toString();
|
||||
notifyRequestReady(requestId);
|
||||
while (reply == null && server == listener && System.currentTimeMillis() < deadline) {
|
||||
wait(Math.max(1, deadline - System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user