diff options
author | Samuel Freilich <sfreilich@google.com> | 2024-05-08 09:08:47 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-05-08 09:09:37 -0700 |
commit | 3cdc3f1616e85dfb5542a09409b49891bcc5b8b6 (patch) | |
tree | 66aca9e364f1f0ec3e92d45b7f049f7fed116ae3 | |
parent | 123e31a02ff7b88941ade8299dc19c518fb1f0ae (diff) | |
download | robolectric-3cdc3f1616e85dfb5542a09409b49891bcc5b8b6.tar.gz |
Allow the configs parameter for eglChooseConfig to be null in shadow
Most of the time, the output parameters for EGL methods are
expected to be non-null. But the `configs` parameter of
`eglChooseConfig` is one of the exceptions. When `configs` is
not null, `eglChooseConfig` fills that with the first
`configSize` configs and fills `numConfig` with the number of
returned configs (no more than `configsSize`). But when `configs`
is_ `null` it fills `numConfigs` with the number of _matching_
configs, ignoring `configsSize`:
https://registry.khronos.org/EGL/sdk/docs/man/html/eglChooseConfig.xhtml
The Android code wrapping this API checks that `attrib_list` and
`num_configs` output arrays are not null, but allows `configs`
to be null (see frameworks/base/core/jni/android_opengl_EGL14.cpp).
PiperOrigin-RevId: 631820937
-rw-r--r-- | robolectric/src/test/java/org/robolectric/shadows/ShadowEGL14Test.java | 14 | ||||
-rw-r--r-- | shadows/framework/src/main/java/org/robolectric/shadows/ShadowEGL14.java | 6 |
2 files changed, 18 insertions, 2 deletions
diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowEGL14Test.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowEGL14Test.java index 4da4963cd..459b75b65 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowEGL14Test.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowEGL14Test.java @@ -27,8 +27,10 @@ public final class ShadowEGL14Test { } @Test - public void eglChooseConfig() { + public void eglChooseConfig_retrieveConfigs() { EGLDisplay display = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); + // When the config array is not null, numConfig is filled with the number of configs returned + // (up to the size of the config array). EGLConfig[] configs = new EGLConfig[1]; int[] numConfig = new int[1]; assertThat(EGL14.eglChooseConfig(display, new int[0], 0, configs, 0, 1, numConfig, 0)).isTrue(); @@ -37,6 +39,16 @@ public final class ShadowEGL14Test { } @Test + public void eglChooseConfig_countMatching() { + EGLDisplay display = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); + // When the config array is null, numConfig is filled with the total number of configs matched. + EGLConfig[] configs = null; + int[] numConfig = new int[1]; + assertThat(EGL14.eglChooseConfig(display, new int[0], 0, configs, 0, 0, numConfig, 0)).isTrue(); + assertThat(numConfig[0]).isGreaterThan(0); + } + + @Test public void eglCreateContext_v2() { EGLDisplay display = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); int[] attribList = {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE}; diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowEGL14.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowEGL14.java index 4f488b571..547b9f1ff 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowEGL14.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowEGL14.java @@ -37,7 +37,11 @@ public class ShadowEGL14 { int configSize, int[] numConfig, int numConfigOffset) { - configs[configsOffset] = createEglConfig(); + // The configs array here can be null, in which case the numConfig output is supposed to be + // set to the number of matching configs instead of the number of returned configs. + if (configs != null) { + configs[configsOffset] = createEglConfig(); + } numConfig[numConfigOffset] = 1; return true; } |