Merge "Reenable task snapshots without using RenderThread in SystemServer."
This commit is contained in:
committed by
Android (Google) Code Review
commit
1d4578fed1
@@ -133,7 +133,7 @@ public class ActivityManager {
|
||||
public final static boolean ENABLE_TASK_SNAPSHOTS;
|
||||
|
||||
static {
|
||||
ENABLE_TASK_SNAPSHOTS = SystemProperties.getBoolean("persist.enable_task_snapshots", false);
|
||||
ENABLE_TASK_SNAPSHOTS = SystemProperties.getBoolean("persist.enable_task_snapshots", true);
|
||||
}
|
||||
|
||||
static final class UidObserver extends IUidObserver.Stub {
|
||||
|
||||
@@ -19,6 +19,7 @@ package android.view;
|
||||
import android.annotation.IntDef;
|
||||
import android.content.res.CompatibilityInfo.Translator;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.GraphicBuffer;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.SurfaceTexture;
|
||||
@@ -72,6 +73,7 @@ public class Surface implements Parcelable {
|
||||
private static native int nativeSetScalingMode(long nativeObject, int scalingMode);
|
||||
private static native void nativeSetBuffersTransform(long nativeObject, long transform);
|
||||
private static native int nativeForceScopedDisconnect(long nativeObject);
|
||||
private static native int nativeAttachAndQueueBuffer(long nativeObject, GraphicBuffer buffer);
|
||||
|
||||
public static final Parcelable.Creator<Surface> CREATOR =
|
||||
new Parcelable.Creator<Surface>() {
|
||||
@@ -561,6 +563,21 @@ public class Surface implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer ownership of buffer and present it on the Surface.
|
||||
* @hide
|
||||
*/
|
||||
public void attachAndQueueBuffer(GraphicBuffer buffer) {
|
||||
synchronized (mLock) {
|
||||
checkNotReleasedLocked();
|
||||
int err = nativeAttachAndQueueBuffer(mNativeObject, buffer);
|
||||
if (err != 0) {
|
||||
throw new RuntimeException(
|
||||
"Failed to attach and queue buffer to Surface (bad object?)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this Surface is backed by a single-buffered SurfaceTexture
|
||||
* @hide
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "jni.h"
|
||||
#include "JNIHelp.h"
|
||||
#include "android_os_Parcel.h"
|
||||
#include "android/graphics/GraphicBuffer.h"
|
||||
#include "android/graphics/GraphicsJNI.h"
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
@@ -496,6 +497,30 @@ static jint nativeForceScopedDisconnect(JNIEnv *env, jclass clazz, jlong nativeO
|
||||
return surface->disconnect(-1, IGraphicBufferProducer::DisconnectMode::AllLocal);
|
||||
}
|
||||
|
||||
static jint nativeAttachAndQueueBuffer(JNIEnv *env, jclass clazz, jlong nativeObject,
|
||||
jobject graphicBuffer) {
|
||||
Surface* surface = reinterpret_cast<Surface*>(nativeObject);
|
||||
sp<GraphicBuffer> bp = graphicBufferForJavaObject(env, graphicBuffer);
|
||||
if (bp == nullptr) {
|
||||
return BAD_VALUE;
|
||||
}
|
||||
int err = ((ANativeWindow*)surface)->perform(surface, NATIVE_WINDOW_API_CONNECT,
|
||||
NATIVE_WINDOW_API_CPU);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
err = surface->attachBuffer(bp->getNativeBuffer());
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
err = ((ANativeWindow*)surface)->queueBuffer(surface, bp->getNativeBuffer(), -1);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
err = surface->disconnect(NATIVE_WINDOW_API_CPU);
|
||||
return err;
|
||||
}
|
||||
|
||||
namespace uirenderer {
|
||||
|
||||
using namespace android::uirenderer::renderthread;
|
||||
@@ -574,6 +599,7 @@ static const JNINativeMethod gSurfaceMethods[] = {
|
||||
{"nativeGetNextFrameNumber", "(J)J", (void*)nativeGetNextFrameNumber },
|
||||
{"nativeSetScalingMode", "(JI)I", (void*)nativeSetScalingMode },
|
||||
{"nativeForceScopedDisconnect", "(J)I", (void*)nativeForceScopedDisconnect},
|
||||
{"nativeAttachAndQueueBuffer", "(JLandroid/graphics/GraphicBuffer;)I", (void*)nativeAttachAndQueueBuffer},
|
||||
|
||||
// HWUI context
|
||||
{"nHwuiCreate", "(JJ)J", (void*) hwui::create },
|
||||
|
||||
@@ -151,21 +151,7 @@ class TaskSnapshotSurface implements StartingSurface {
|
||||
}
|
||||
|
||||
private void drawSnapshot(GraphicBuffer snapshot) {
|
||||
|
||||
// TODO: Just wrap the buffer here without any copying.
|
||||
final Canvas c = mSurface.lockHardwareCanvas();
|
||||
final Bitmap b = Bitmap.createHardwareBitmap(snapshot);
|
||||
fillEmptyBackground(c, b);
|
||||
c.drawBitmap(b, 0, 0, null);
|
||||
mSurface.unlockCanvasAndPost(c);
|
||||
final boolean reportNextDraw;
|
||||
synchronized (mService.mWindowMap) {
|
||||
mHasDrawn = true;
|
||||
reportNextDraw = mReportNextDraw;
|
||||
}
|
||||
if (reportNextDraw) {
|
||||
reportDrawn();
|
||||
}
|
||||
mSurface.attachAndQueueBuffer(snapshot);
|
||||
mSurface.release();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user