From 3d63de9a21c8a61c013354538dd026299dece65b Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Thu, 27 Jul 2023 19:59:15 -0600 Subject: [PATCH] Add iOS clang-tidy job --- .github/workflows/ci.yml | 1 + src/SFML/Graphics/RenderTextureImplFBO.cpp | 2 +- src/SFML/Window/iOS/ClipboardImpl.mm | 17 +++++---- src/SFML/Window/iOS/EaglContext.hpp | 2 +- src/SFML/Window/iOS/EaglContext.mm | 43 +++++++++++----------- src/SFML/Window/iOS/SFView.mm | 2 +- src/SFML/Window/iOS/SensorImpl.mm | 4 +- src/SFML/Window/iOS/VideoModeImpl.mm | 4 +- src/SFML/Window/iOS/WindowImplUIKit.hpp | 1 - src/SFML/Window/iOS/WindowImplUIKit.mm | 12 +++--- 10 files changed, 46 insertions(+), 42 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ac95da3..ac19a0f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -239,6 +239,7 @@ jobs: - { name: Linux, os: ubuntu-22.04 } - { name: Linux DRM, os: ubuntu-22.04, flags: -DSFML_USE_DRM=TRUE } - { name: macOS, os: macos-12 } + - { name: iOS, os: macos-12, flags: -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=arm64 } - { name: Android, os: ubuntu-22.04, flags: -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_SYSTEM_NAME=Android -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$GITHUB_WORKSPACE/android-ndk-r23b -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_ANDROID_STL_TYPE=c++_shared -DCMAKE_ANDROID_API=26 } steps: diff --git a/src/SFML/Graphics/RenderTextureImplFBO.cpp b/src/SFML/Graphics/RenderTextureImplFBO.cpp index e035f30e..afb9b108 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.cpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.cpp @@ -118,7 +118,7 @@ unsigned int RenderTextureImplFBO::getMaximumAntialiasingLevel() { const TransientContextLock lock; - GLint samples = 0; + GLint samples = 0; // NOLINT(misc-const-correctness) #ifndef SFML_OPENGL_ES diff --git a/src/SFML/Window/iOS/ClipboardImpl.mm b/src/SFML/Window/iOS/ClipboardImpl.mm index f18dc646..52aa6880 100644 --- a/src/SFML/Window/iOS/ClipboardImpl.mm +++ b/src/SFML/Window/iOS/ClipboardImpl.mm @@ -37,13 +37,13 @@ namespace sf::priv //////////////////////////////////////////////////////////// String ClipboardImpl::getString() { - UIPasteboard* pboard = [UIPasteboard generalPasteboard]; + UIPasteboard* const pboard = [UIPasteboard generalPasteboard]; if (pboard.hasStrings) { - NSString* data = pboard.string; + const NSString* const data = pboard.string; - const char* utf8 = [data cStringUsingEncoding:NSUTF8StringEncoding]; - NSUInteger length = [data lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + const char* utf8 = [data cStringUsingEncoding:NSUTF8StringEncoding]; + const NSUInteger length = [data lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; return String::fromUtf8(utf8, utf8 + length); } @@ -58,10 +58,13 @@ String ClipboardImpl::getString() void ClipboardImpl::setString(const String& text) { std::basic_string utf8 = text.toUtf8(); - NSString* data = [[NSString alloc] initWithBytes:utf8.data() length:utf8.length() encoding:NSUTF8StringEncoding]; + NSString* const data = [[NSString alloc] + initWithBytes:utf8.data() + length:utf8.length() + encoding:NSUTF8StringEncoding]; - UIPasteboard* pboard = [UIPasteboard generalPasteboard]; - pboard.string = data; + UIPasteboard* const pboard = [UIPasteboard generalPasteboard]; + pboard.string = data; } } // namespace sf::priv diff --git a/src/SFML/Window/iOS/EaglContext.hpp b/src/SFML/Window/iOS/EaglContext.hpp index 8a0fab14..471e6297 100644 --- a/src/SFML/Window/iOS/EaglContext.hpp +++ b/src/SFML/Window/iOS/EaglContext.hpp @@ -85,7 +85,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~EaglContext(); + ~EaglContext() override; //////////////////////////////////////////////////////////// /// \brief Get the address of an OpenGL function diff --git a/src/SFML/Window/iOS/EaglContext.mm b/src/SFML/Window/iOS/EaglContext.mm index a9b058f9..8db9be8c 100644 --- a/src/SFML/Window/iOS/EaglContext.mm +++ b/src/SFML/Window/iOS/EaglContext.mm @@ -45,16 +45,16 @@ namespace { -PFNGLBINDFRAMEBUFFEROESPROC glBindFramebufferOESFunc = 0; -PFNGLBINDRENDERBUFFEROESPROC glBindRenderbufferOESFunc = 0; -PFNGLCHECKFRAMEBUFFERSTATUSOESPROC glCheckFramebufferStatusOESFunc = 0; -PFNGLDELETEFRAMEBUFFERSOESPROC glDeleteFramebuffersOESFunc = 0; -PFNGLDELETERENDERBUFFERSOESPROC glDeleteRenderbuffersOESFunc = 0; -PFNGLFRAMEBUFFERRENDERBUFFEROESPROC glFramebufferRenderbufferOESFunc = 0; -PFNGLGENFRAMEBUFFERSOESPROC glGenFramebuffersOESFunc = 0; -PFNGLGENRENDERBUFFERSOESPROC glGenRenderbuffersOESFunc = 0; -PFNGLGETRENDERBUFFERPARAMETERIVOESPROC glGetRenderbufferParameterivOESFunc = 0; -PFNGLRENDERBUFFERSTORAGEOESPROC glRenderbufferStorageOESFunc = 0; +PFNGLBINDFRAMEBUFFEROESPROC glBindFramebufferOESFunc = nullptr; +PFNGLBINDRENDERBUFFEROESPROC glBindRenderbufferOESFunc = nullptr; +PFNGLCHECKFRAMEBUFFERSTATUSOESPROC glCheckFramebufferStatusOESFunc = nullptr; +PFNGLDELETEFRAMEBUFFERSOESPROC glDeleteFramebuffersOESFunc = nullptr; +PFNGLDELETERENDERBUFFERSOESPROC glDeleteRenderbuffersOESFunc = nullptr; +PFNGLFRAMEBUFFERRENDERBUFFEROESPROC glFramebufferRenderbufferOESFunc = nullptr; +PFNGLGENFRAMEBUFFERSOESPROC glGenFramebuffersOESFunc = nullptr; +PFNGLGENRENDERBUFFERSOESPROC glGenRenderbuffersOESFunc = nullptr; +PFNGLGETRENDERBUFFERPARAMETERIVOESPROC glGetRenderbufferParameterivOESFunc = nullptr; +PFNGLRENDERBUFFERSTORAGEOESPROC glRenderbufferStorageOESFunc = nullptr; void ensureInit() @@ -137,7 +137,7 @@ EaglContext::~EaglContext() if (m_context) { // Activate the context, so that we can destroy the buffers - EAGLContext* previousContext = [EAGLContext currentContext]; + EAGLContext* const previousContext = [EAGLContext currentContext]; [EAGLContext setCurrentContext:m_context]; // Destroy the buffers @@ -160,23 +160,23 @@ EaglContext::~EaglContext() //////////////////////////////////////////////////////////// GlFunctionPointer EaglContext::getFunction(const char* name) { - static void* module = 0; + static void* module = nullptr; const int libCount = 3; const char* libs[libCount] = {"libGLESv1_CM.dylib", "/System/Library/Frameworks/OpenGLES.framework/OpenGLES", "OpenGLES.framework/OpenGLES"}; - for (int i = 0; i < libCount; ++i) + for (auto& lib : libs) { if (!module) - module = dlopen(libs[i], RTLD_LAZY | RTLD_LOCAL); + module = dlopen(lib, RTLD_LAZY | RTLD_LOCAL); } if (module) return reinterpret_cast(reinterpret_cast(dlsym(module, name))); - return 0; + return nullptr; } @@ -184,7 +184,7 @@ GlFunctionPointer EaglContext::getFunction(const char* name) void EaglContext::recreateRenderBuffers(SFView* glView) { // Activate the context - EAGLContext* previousContext = [EAGLContext currentContext]; + EAGLContext* const previousContext = [EAGLContext currentContext]; [EAGLContext setCurrentContext:m_context]; // Bind the frame buffer @@ -207,12 +207,13 @@ void EaglContext::recreateRenderBuffers(SFView* glView) if (m_settings.depthBits > 0) { // Find the best internal format - GLenum format = m_settings.depthBits > 16 - ? (m_settings.stencilBits == 0 ? GL_DEPTH_COMPONENT24_OES : GL_DEPTH24_STENCIL8_OES) - : GL_DEPTH_COMPONENT16_OES; + const GLenum format = m_settings.depthBits > 16 + ? (m_settings.stencilBits == 0 ? GL_DEPTH_COMPONENT24_OES : GL_DEPTH24_STENCIL8_OES) + : GL_DEPTH_COMPONENT16_OES; // Get the size of the color-buffer (which fits the current size of the GL view) - GLint width, height; + GLint width; + GLint height; glGetRenderbufferParameterivOESFunc(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width); glGetRenderbufferParameterivOESFunc(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height); @@ -226,7 +227,7 @@ void EaglContext::recreateRenderBuffers(SFView* glView) } // Make sure that everything's ok - GLenum status = glCheckFramebufferStatusOESFunc(GL_FRAMEBUFFER_OES); + const GLenum status = glCheckFramebufferStatusOESFunc(GL_FRAMEBUFFER_OES); if (status != GL_FRAMEBUFFER_COMPLETE_OES) err() << "Failed to create a valid frame buffer (error code: " << status << ")" << std::endl; diff --git a/src/SFML/Window/iOS/SFView.mm b/src/SFML/Window/iOS/SFView.mm index 71ee667f..25943235 100644 --- a/src/SFML/Window/iOS/SFView.mm +++ b/src/SFML/Window/iOS/SFView.mm @@ -192,7 +192,7 @@ self.touches = [NSMutableArray array]; // Configure the EAGL layer - CAEAGLLayer* eaglLayer = static_cast(self.layer); + auto* eaglLayer = static_cast(self.layer); eaglLayer.opaque = YES; eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE], diff --git a/src/SFML/Window/iOS/SensorImpl.mm b/src/SFML/Window/iOS/SensorImpl.mm index 463eb4fb..b3ef3f54 100644 --- a/src/SFML/Window/iOS/SensorImpl.mm +++ b/src/SFML/Window/iOS/SensorImpl.mm @@ -132,8 +132,8 @@ void SensorImpl::close() //////////////////////////////////////////////////////////// Vector3f SensorImpl::update() { - Vector3f value; - CMMotionManager* manager = [SFAppDelegate getInstance].motionManager; + Vector3f value; + CMMotionManager* const manager = [SFAppDelegate getInstance].motionManager; switch (m_sensor) { diff --git a/src/SFML/Window/iOS/VideoModeImpl.mm b/src/SFML/Window/iOS/VideoModeImpl.mm index 4bff95bc..b8712e8b 100644 --- a/src/SFML/Window/iOS/VideoModeImpl.mm +++ b/src/SFML/Window/iOS/VideoModeImpl.mm @@ -45,8 +45,8 @@ std::vector VideoModeImpl::getFullscreenModes() //////////////////////////////////////////////////////////// VideoMode VideoModeImpl::getDesktopMode() { - CGRect bounds = [[UIScreen mainScreen] bounds]; - double backingScale = [SFAppDelegate getInstance].backingScaleFactor; + const CGRect bounds = [[UIScreen mainScreen] bounds]; + const double backingScale = [SFAppDelegate getInstance].backingScaleFactor; return VideoMode({static_cast(bounds.size.width * backingScale), static_cast(bounds.size.height * backingScale)}); } diff --git a/src/SFML/Window/iOS/WindowImplUIKit.hpp b/src/SFML/Window/iOS/WindowImplUIKit.hpp index c90a05cf..0bcd9406 100644 --- a/src/SFML/Window/iOS/WindowImplUIKit.hpp +++ b/src/SFML/Window/iOS/WindowImplUIKit.hpp @@ -197,7 +197,6 @@ public: //////////////////////////////////////////////////////////// bool hasFocus() const override; -public: //////////////////////////////////////////////////////////// /// \brief Notify an event /// diff --git a/src/SFML/Window/iOS/WindowImplUIKit.mm b/src/SFML/Window/iOS/WindowImplUIKit.mm index 7152047f..fbdb2425 100644 --- a/src/SFML/Window/iOS/WindowImplUIKit.mm +++ b/src/SFML/Window/iOS/WindowImplUIKit.mm @@ -61,14 +61,14 @@ WindowImplUIKit::WindowImplUIKit(VideoMode mode, const String& /* title */, unsi [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; // Create the window - CGRect frame = [UIScreen mainScreen].bounds; // Ignore user size, it wouldn't make sense to use something else - m_window = [[UIWindow alloc] initWithFrame:frame]; - m_hasFocus = true; + const CGRect frame = [UIScreen mainScreen].bounds; // Ignore user size, it wouldn't make sense to use something else + m_window = [[UIWindow alloc] initWithFrame:frame]; + m_hasFocus = true; // Assign it to the application delegate [SFAppDelegate getInstance].sfWindow = this; - CGRect viewRect = frame; + const CGRect viewRect = frame; // Create the view m_view = [[SFView alloc] initWithFrame:viewRect andContentScaleFactor:(static_cast(m_backingScale))]; @@ -108,7 +108,7 @@ WindowHandle WindowImplUIKit::getSystemHandle() const //////////////////////////////////////////////////////////// Vector2i WindowImplUIKit::getPosition() const { - CGPoint origin = m_window.frame.origin; + const CGPoint origin = m_window.frame.origin; return Vector2i(static_cast(origin.x * static_cast(m_backingScale)), static_cast(origin.y * static_cast(m_backingScale))); } @@ -123,7 +123,7 @@ void WindowImplUIKit::setPosition(const Vector2i& /* position */) //////////////////////////////////////////////////////////// Vector2u WindowImplUIKit::getSize() const { - CGRect physicalFrame = m_window.frame; + const CGRect physicalFrame = m_window.frame; return Vector2u(static_cast(physicalFrame.size.width * static_cast(m_backingScale)), static_cast(physicalFrame.size.height * static_cast(m_backingScale))); }