Skip to content

Commit 80193e7

Browse files
pixelflingerAndroid (Google) Code Review
authored andcommitted
Merge "add a (hidden) api on Surface to query if the consumer is running behind the producer"
2 parents ec04678 + c14bacf commit 80193e7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

core/java/android/view/Surface.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,15 @@ public int getGenerationId() {
323323
return mSurfaceGenerationId;
324324
}
325325

326+
327+
/**
328+
* Whether the consumer of this Surface is running behind the producer;
329+
* that is, isConsumerRunningBehind() returns true if the consumer is more
330+
* than one buffer ahead of the producer.
331+
* @hide
332+
*/
333+
public native boolean isConsumerRunningBehind();
334+
326335
/**
327336
* A Canvas class that can handle the compatibility mode. This does two
328337
* things differently.

core/jni/android_view_Surface.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ static jboolean Surface_isValid(JNIEnv* env, jobject clazz)
316316
return Surface::isValid(surface) ? JNI_TRUE : JNI_FALSE;
317317
}
318318

319+
static jboolean Surface_isConsumerRunningBehind(JNIEnv* env, jobject clazz)
320+
{
321+
int value = 0;
322+
const sp<Surface>& surface(getSurface(env, clazz));
323+
if (!Surface::isValid(surface)) {
324+
doThrowIAE(env);
325+
return 0;
326+
}
327+
ANativeWindow* anw = static_cast<ANativeWindow *>(surface.get());
328+
anw->query(anw, NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND, &value);
329+
return (jboolean)value;
330+
}
331+
319332
static inline SkBitmap::Config convertPixelFormat(PixelFormat format)
320333
{
321334
/* note: if PIXEL_FORMAT_RGBX_8888 means that all alpha bytes are 0xFF, then
@@ -875,6 +888,7 @@ static JNINativeMethod gSurfaceMethods[] = {
875888
{"setFreezeTint", "(I)V", (void*)Surface_setFreezeTint },
876889
{"readFromParcel", "(Landroid/os/Parcel;)V", (void*)Surface_readFromParcel },
877890
{"writeToParcel", "(Landroid/os/Parcel;I)V", (void*)Surface_writeToParcel },
891+
{"isConsumerRunningBehind", "()Z", (void*)Surface_isConsumerRunningBehind },
878892
};
879893

880894
void nativeClassInit(JNIEnv* env, jclass clazz)

0 commit comments

Comments
 (0)