SurfaceControl: add getAllowedDisplayConfigs

expose ISurfaceComposer::getAllowedDisplayConfigs to SurfaceControl.

Test: manual test to call getAllowedDisplayConfigs() from SurfaceControl
observe config change.
Bug: 122905403

Change-Id: I0587ac5ed2eb29788c2ce941d9c54ebfd215ddf9
This commit is contained in:
Ady Abraham
2019-02-26 14:13:39 -08:00
committed by Michael Wright
parent e4d662e470
commit 42f9a2fbbd
2 changed files with 36 additions and 0 deletions

View File

@@ -160,6 +160,7 @@ public final class SurfaceControl implements Parcelable {
private static native boolean nativeSetActiveConfig(IBinder displayToken, int id);
private static native boolean nativeSetAllowedDisplayConfigs(IBinder displayToken,
int[] allowedConfigs);
private static native int[] nativeGetAllowedDisplayConfigs(IBinder displayToken);
private static native int[] nativeGetDisplayColorModes(IBinder displayToken);
private static native SurfaceControl.DisplayPrimaries nativeGetDisplayNativePrimaries(
IBinder displayToken);
@@ -1535,6 +1536,16 @@ public final class SurfaceControl implements Parcelable {
return nativeSetAllowedDisplayConfigs(displayToken, allowedConfigs);
}
/**
* @hide
*/
public static int[] getAllowedDisplayConfigs(IBinder displayToken) {
if (displayToken == null) {
throw new IllegalArgumentException("displayToken must not be null");
}
return nativeGetAllowedDisplayConfigs(displayToken);
}
/**
* @hide
*/

View File

@@ -717,6 +717,29 @@ static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz,
return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
}
static jintArray nativeGetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, jobject tokenObj) {
sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
if (token == nullptr) return JNI_FALSE;
std::vector<int32_t> allowedConfigs;
size_t result = SurfaceComposerClient::getAllowedDisplayConfigs(token, &allowedConfigs);
if (result != NO_ERROR) {
return nullptr;
}
jintArray allowedConfigsArray = env->NewIntArray(allowedConfigs.size());
if (allowedConfigsArray == nullptr) {
jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
return nullptr;
}
jint* allowedConfigsArrayValues = env->GetIntArrayElements(allowedConfigsArray, 0);
for (size_t i = 0; i < allowedConfigs.size(); i++) {
allowedConfigsArrayValues[i] = static_cast<jint>(allowedConfigs[i]);
}
env->ReleaseIntArrayElements(allowedConfigsArray, allowedConfigsArrayValues, 0);
return allowedConfigsArray;
}
static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
if (token == NULL) return -1;
@@ -1215,6 +1238,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
(void*)nativeSetActiveConfig },
{"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
(void*)nativeSetAllowedDisplayConfigs },
{"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I",
(void*)nativeGetAllowedDisplayConfigs },
{"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
(void*)nativeGetDisplayColorModes},
{"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",