[Mesa-dev] [PATCH mesa 1/2] egl/display: only detect the platform once
Eric Engestrom
eric.engestrom at imgtec.com
Thu Jun 1 11:15:05 UTC 2017
My refactor missed the fact that `native_platform` is static.
Add the proper guard before the first detection method, as it might not
be necessary, and only print the debug message when a detection was
actually performed.
Reported-by: Grazvydas Ignotas <notasas at gmail.com>
Fixes: 7adb9b094894a512c019 ("egl/display: remove unnecessary code and
make it easier to read")
Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
---
src/egl/main/egldisplay.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 2a1f02738d..3f7752f53d 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -180,11 +180,13 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
_EGLPlatformType
_eglGetNativePlatform(void *nativeDisplay)
{
- static _EGLPlatformType native_platform;
- char *detection_method;
+ static _EGLPlatformType native_platform = _EGL_INVALID_PLATFORM;
+ char *detection_method = NULL;
- native_platform = _eglGetNativePlatformFromEnv();
- detection_method = "environment overwrite";
+ if (native_platform == _EGL_INVALID_PLATFORM) {
+ native_platform = _eglGetNativePlatformFromEnv();
+ detection_method = "environment overwrite";
+ }
if (native_platform == _EGL_INVALID_PLATFORM) {
native_platform = _eglNativePlatformDetectNativeDisplay(nativeDisplay);
@@ -196,8 +198,10 @@ _eglGetNativePlatform(void *nativeDisplay)
detection_method = "build-time configuration";
}
- _eglLog(_EGL_DEBUG, "Native platform type: %s (%s)",
- egl_platforms[native_platform].name, detection_method);
+ if (detection_method != NULL) {
+ _eglLog(_EGL_DEBUG, "Native platform type: %s (%s)",
+ egl_platforms[native_platform].name, detection_method);
+ }
return native_platform;
}
--
Cheers,
Eric
More information about the mesa-dev
mailing list