[Bf-blender-cvs] [93e4b15767c] master: Cleanup: clang-tidy for GHOST X11/SDL/Wayland/NULL backends

Campbell Barton noreply at git.blender.org
Sun May 29 05:35:48 CEST 2022


Commit: 93e4b15767cf958d5a07ba6acce25438f244bf22
Author: Campbell Barton
Date:   Sun May 29 13:23:19 2022 +1000
Branches: master
https://developer.blender.org/rB93e4b15767cf958d5a07ba6acce25438f244bf22

Cleanup: clang-tidy for GHOST X11/SDL/Wayland/NULL backends

Also early exit in some functions.

===================================================================

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_ContextEGL.cpp
M	intern/ghost/intern/GHOST_ContextGLX.cpp
M	intern/ghost/intern/GHOST_ContextSDL.cpp
M	intern/ghost/intern/GHOST_DisplayManager.cpp
M	intern/ghost/intern/GHOST_DisplayManagerSDL.cpp
M	intern/ghost/intern/GHOST_DisplayManagerX11.cpp
M	intern/ghost/intern/GHOST_DropTargetX11.cpp
M	intern/ghost/intern/GHOST_ISystem.cpp
M	intern/ghost/intern/GHOST_ISystemPaths.cpp
M	intern/ghost/intern/GHOST_Path-api.cpp
M	intern/ghost/intern/GHOST_System.cpp
M	intern/ghost/intern/GHOST_SystemNULL.h
M	intern/ghost/intern/GHOST_SystemPathsUnix.cpp
M	intern/ghost/intern/GHOST_SystemSDL.cpp
M	intern/ghost/intern/GHOST_SystemWayland.cpp
M	intern/ghost/intern/GHOST_SystemWayland.h
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	intern/ghost/intern/GHOST_TaskbarX11.cpp
M	intern/ghost/intern/GHOST_TimerTask.h
M	intern/ghost/intern/GHOST_WaylandCursorSettings.h
M	intern/ghost/intern/GHOST_Window.cpp
M	intern/ghost/intern/GHOST_WindowManager.cpp
M	intern/ghost/intern/GHOST_WindowNULL.h
M	intern/ghost/intern/GHOST_WindowSDL.cpp
M	intern/ghost/intern/GHOST_WindowWayland.cpp
M	intern/ghost/intern/GHOST_WindowX11.cpp

===================================================================

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index ec641938f1f..ae749eb3b8c 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -414,7 +414,7 @@ extern GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
  */
 extern GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
                                           GHOST_TGrabCursorMode mode,
-                                          GHOST_TAxisFlag warp_axis,
+                                          GHOST_TAxisFlag wrap_axis,
                                           int bounds[4],
                                           const int mouse_ungrab_xy[2]);
 
@@ -727,7 +727,7 @@ extern unsigned int GHOST_GetContextDefaultOpenGLFramebuffer(GHOST_ContextHandle
 /**
  * Get the OpenGL frame-buffer handle that serves as a default frame-buffer.
  */
-extern unsigned int GHOST_GetDefaultOpenGLFramebuffer(GHOST_WindowHandle windwHandle);
+extern unsigned int GHOST_GetDefaultOpenGLFramebuffer(GHOST_WindowHandle windowhandle);
 
 /**
  * Set which tablet API to use. Only affects Windows, other platforms have a single API.
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 93e94893162..9374d087408 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -7,8 +7,8 @@
  * C Api for GHOST
  */
 
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
 
 #include "GHOST_C-api.h"
 #include "GHOST_IEvent.h"
@@ -206,13 +206,15 @@ GHOST_WindowHandle GHOST_BeginFullScreen(GHOST_SystemHandle systemhandle,
                                          const int stereoVisual)
 {
   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
-  GHOST_IWindow *window = NULL;
+  GHOST_IWindow *window = nullptr;
   bool bstereoVisual;
 
-  if (stereoVisual)
+  if (stereoVisual) {
     bstereoVisual = true;
-  else
+  }
+  else {
     bstereoVisual = false;
+  }
 
   system->beginFullScreen(*setting, &window, bstereoVisual);
 
@@ -371,7 +373,7 @@ GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
   }
 
   return window->setCursorGrab(
-      mode, wrap_axis, bounds ? &bounds_rect : NULL, mouse_ungrab_xy ? mouse_xy : NULL);
+      mode, wrap_axis, bounds ? &bounds_rect : nullptr, mouse_ungrab_xy ? mouse_xy : nullptr);
 }
 
 GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle,
@@ -509,8 +511,8 @@ char *GHOST_GetTitle(GHOST_WindowHandle windowhandle)
 
   char *ctitle = (char *)malloc(title.size() + 1);
 
-  if (ctitle == NULL) {
-    return NULL;
+  if (ctitle == nullptr) {
+    return nullptr;
   }
 
   strcpy(ctitle, title.c_str());
@@ -521,7 +523,7 @@ char *GHOST_GetTitle(GHOST_WindowHandle windowhandle)
 GHOST_RectangleHandle GHOST_GetWindowBounds(GHOST_WindowHandle windowhandle)
 {
   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
-  GHOST_Rect *rectangle = NULL;
+  GHOST_Rect *rectangle = nullptr;
 
   rectangle = new GHOST_Rect();
   window->getWindowBounds(*rectangle);
@@ -532,7 +534,7 @@ GHOST_RectangleHandle GHOST_GetWindowBounds(GHOST_WindowHandle windowhandle)
 GHOST_RectangleHandle GHOST_GetClientBounds(GHOST_WindowHandle windowhandle)
 {
   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
-  GHOST_Rect *rectangle = NULL;
+  GHOST_Rect *rectangle = nullptr;
 
   rectangle = new GHOST_Rect();
   window->getClientBounds(*rectangle);
@@ -646,10 +648,8 @@ GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthandle)
   if (context) {
     return context->activateDrawingContext();
   }
-  else {
-    GHOST_PRINTF("%s: Context not valid\n", __func__);
-    return GHOST_kFailure;
-  }
+  GHOST_PRINTF("%s: Context not valid\n", __func__);
+  return GHOST_kFailure;
 }
 
 GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle)
@@ -717,9 +717,9 @@ GHOST_TSuccess GHOST_IsEmptyRectangle(GHOST_RectangleHandle rectanglehandle)
 {
   GHOST_TSuccess result = GHOST_kFailure;
 
-  if (((GHOST_Rect *)rectanglehandle)->isEmpty())
+  if (((GHOST_Rect *)rectanglehandle)->isEmpty()) {
     result = GHOST_kSuccess;
-
+  }
   return result;
 }
 
@@ -727,9 +727,9 @@ GHOST_TSuccess GHOST_IsValidRectangle(GHOST_RectangleHandle rectanglehandle)
 {
   GHOST_TSuccess result = GHOST_kFailure;
 
-  if (((GHOST_Rect *)rectanglehandle)->isValid())
+  if (((GHOST_Rect *)rectanglehandle)->isValid()) {
     result = GHOST_kSuccess;
-
+  }
   return result;
 }
 
@@ -753,9 +753,9 @@ GHOST_TSuccess GHOST_IsInsideRectangle(GHOST_RectangleHandle rectanglehandle, in
 {
   GHOST_TSuccess result = GHOST_kFailure;
 
-  if (((GHOST_Rect *)rectanglehandle)->isInside(x, y))
+  if (((GHOST_Rect *)rectanglehandle)->isInside(x, y)) {
     result = GHOST_kSuccess;
-
+  }
   return result;
 }
 
@@ -785,9 +785,9 @@ GHOST_TSuccess GHOST_ClipRectangle(GHOST_RectangleHandle rectanglehandle,
 {
   GHOST_TSuccess result = GHOST_kFailure;
 
-  if (((GHOST_Rect *)rectanglehandle)->clip(*(GHOST_Rect *)anotherrectanglehandle))
+  if (((GHOST_Rect *)rectanglehandle)->clip(*(GHOST_Rect *)anotherrectanglehandle)) {
     result = GHOST_kSuccess;
-
+  }
   return result;
 }
 
@@ -824,8 +824,9 @@ void GHOST_UseWindowFocus(int use_focus)
 float GHOST_GetNativePixelSize(GHOST_WindowHandle windowhandle)
 {
   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
-  if (window)
+  if (window) {
     return window->getNativePixelSize();
+  }
   return 1.0f;
 }
 
diff --git a/intern/ghost/intern/GHOST_ContextEGL.cpp b/intern/ghost/intern/GHOST_ContextEGL.cpp
index a2b58106f0d..8c44dfe0158 100644
--- a/intern/ghost/intern/GHOST_ContextEGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextEGL.cpp
@@ -40,7 +40,7 @@ static const char *get_egl_error_enum_string(EGLint error)
     CASE_CODE_RETURN_STR(EGL_BAD_NATIVE_WINDOW)
     CASE_CODE_RETURN_STR(EGL_CONTEXT_LOST)
     default:
-      return NULL;
+      return nullptr;
   }
 }
 
@@ -106,11 +106,14 @@ static const char *get_egl_error_message_string(EGLint error)
           "and objects to continue rendering.");
 
     default:
-      return NULL;
+      return nullptr;
   }
 }
 
-static bool egl_chk(bool result, const char *file = NULL, int line = 0, const char *text = NULL)
+static bool egl_chk(bool result,
+                    const char *file = nullptr,
+                    int line = 0,
+                    const char *text = nullptr)
 {
   if (!result) {
     const EGLint error = eglGetError();
@@ -158,7 +161,7 @@ static inline bool bindAPI(EGLenum api)
 }
 
 #ifdef WITH_GL_ANGLE
-HMODULE GHOST_ContextEGL::s_d3dcompiler = NULL;
+HMODULE GHOST_ContextEGL::s_d3dcompiler = nullptr;
 #endif
 
 EGLContext GHOST_ContextEGL::s_gl_sharedContext = EGL_NO_CONTEXT;
@@ -170,7 +173,9 @@ EGLint GHOST_ContextEGL::s_gles_sharedCount = 0;
 EGLContext GHOST_ContextEGL::s_vg_sharedContext = EGL_NO_CONTEXT;
 EGLint GHOST_ContextEGL::s_vg_sharedCount = 0;
 
-#pragma warning(disable : 4715)
+#ifdef _MSC_VER
+#  pragma warning(disable : 4715)
+#endif
 
 template<typename T> T &choose_api(EGLenum api, T &a, T &b, T &c)
 {
@@ -223,23 +228,24 @@ GHOST_ContextEGL::~GHOST_ContextEGL()
     bindAPI(m_api);
 
     if (m_context != EGL_NO_CONTEXT) {
-      if (m_context == ::eglGetCurrentContext())
+      if (m_context == ::eglGetCurrentContext()) {
         EGL_CHK(::eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
-
+      }
       if (m_context != m_sharedContext || m_sharedCount == 1) {
         assert(m_sharedCount > 0);
 
         m_sharedCount--;
 
-        if (m_sharedCount == 0)
+        if (m_sharedCount == 0) {
           m_sharedContext = EGL_NO_CONTEXT;
-
+        }
         EGL_CHK(::eglDestroyContext(m_display, m_context));
       }
     }
 
-    if (m_surface != EGL_NO_SURFACE)
+    if (m_surface != EGL_NO_SURFACE) {
       EGL_CHK(::eglDestroySurface(m_display, m_surface));
+    }
   }
 }
 
@@ -256,13 +262,9 @@ GHOST_TSuccess GHOST_ContextEGL::setSwapInterval(int interval)
 
       return GHOST_kSuccess;
     }
-    else {
-      return GHOST_kFailure;
-    }
-  }
-  else {
     return GHOST_kFailure;
   }
+  return GHOST_kFailure;
 }
 
 GHOST_TSuccess GHOST_ContextEGL::getSwapInterval(int &intervalOut)
@@ -293,13 +295,10 @@ GHOST_TSuccess GHOST_ContextEGL::activateDrawingContext()
 {
   if (m_display) {
     bindAPI(m_api);
-
     return EGL_CHK(::eglMakeCurrent(m_display, m_surface, m_surface, m_context)) ? GHOST_kSuccess :
                                                                                    GHOST_kFailure;
   }
-  else {
-    return GHOST_kFailure;
-  }
+  return GHOST_kFailure;
 }
 
 GHOST_TSuccess GHOST_ContextEGL::releaseDrawingContext()
@@ -311,9 +310,7 @@ GHOST_TSuccess GHOST_ContextEGL::releaseDrawingContext()
                GHOST_kSuccess :
                GHOST_kFailure;
   }
-  else {
-    return GHOST_kFailure;
-  }
+  return GHOST_kFailure;
 }
 
 bool GHOST_ContextEGL::initContextEGLEW()
@@ -322,7 +319,7 @@ bool GHOST_ContextEGL::initContextEGLEW()
    * it requires a display argument. glewInit() does the same, but we only want
    * to initialize EGLEW here. */
   eglGetDisplay = (PFNEGLGETDISPLAYPROC)eglGetProcAddress("eglGetDisplay");
-  if (eglGetDisplay == NULL) {
+  if (eglGetDisplay == nullptr) {
     return false;
   }
 
@@ -353,9 +350,9 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
   std::vector<EGLint> attrib_list;
   EGLint num_config = 0;
 
-  if (m_stereoVisual)
+  if (m_stereoVisual) {
     fprintf(stderr, "Warning! Stereo OpenGL ES contexts are not supported.\n");
-
+  }
   m_stereoVisual = false; /* It doesn't matter what the Window wants. */
 
   if (!initContextEGLEW()) {
@@ -364,12 +361,12 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
 
 #ifdef WITH_GL_ANGLE
   /* `d3dcompiler_XX.dll` needs to be loaded before ANGLE will work. */
-  if (s_d3dcompiler == NULL) {
+  if (s_d3dcompiler == nullptr) {
     s_d3dcompiler = LoadLibrary(D3DCOMPILER);
 
-    WIN32_CHK(s_d3dcompiler != NULL);
+    WIN32_CHK(s_d3dcompiler != nullptr);
 
-    if (s_d3dcompiler == NULL) {
+    if (s_d3dcompiler == nullptr) {
       fprintf(stderr, "LoadLibrary(\"" D3DCOMPILER "\") failed!\n");
       return GHOST_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list