From 2c3c9e5d1804cdb49bcf01594c1a0611fe0867c7 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 23 May 2017 10:03:59 +0100 Subject: [PATCH] A bit more minor cleaning up --- .../native/juce_linux_X11_Windowing.cpp | 250 ++++++++---------- .../juce_opengl/native/juce_OpenGL_android.h | 2 +- .../native/juce_OpenGL_linux_X11.h | 50 ++-- modules/juce_opengl/native/juce_OpenGL_osx.h | 2 +- .../juce_opengl/native/juce_OpenGL_win32.h | 14 +- 5 files changed, 143 insertions(+), 175 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp index 455d9485b5..313620ad5b 100644 --- a/modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp @@ -164,13 +164,14 @@ const int KeyPress::rewindKey = ((int) 0xffeeff03) | Keys::extende namespace XSHMHelpers { static int trappedErrorCode = 0; + extern "C" int errorTrapHandler (Display*, XErrorEvent* err) { trappedErrorCode = err->error_code; return 0; } - static bool isShmAvailable(::Display* display) noexcept + static bool isShmAvailable (::Display* display) noexcept { static bool isChecked = false; static bool isAvailable = false; @@ -194,8 +195,8 @@ namespace XSHMHelpers XShmSegmentInfo segmentInfo; zerostruct (segmentInfo); - if (XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)), - 24, ZPixmap, 0, &segmentInfo, 50, 50)) + if (auto* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)), + 24, ZPixmap, 0, &segmentInfo, 50, 50)) { if ((segmentInfo.shmid = shmget (IPC_PRIVATE, (size_t) (xImage->bytes_per_line * xImage->height), @@ -467,12 +468,11 @@ namespace Visuals class XBitmapImage : public ImagePixelData { public: - XBitmapImage (::Display* _display, const Image::PixelFormat format, const int w, const int h, - const bool clearImage, const unsigned int imageDepth_, Visual* visual) + XBitmapImage (::Display* d, Image::PixelFormat format, int w, int h, + bool clearImage, unsigned int imageDepth_, Visual* visual) : ImagePixelData (format, w, h), imageDepth (imageDepth_), - gc (None), - display (_display) + display (d) { jassert (format == Image::RGB || format == Image::ARGB); @@ -661,7 +661,7 @@ public: for (int x = sx; x < sx + (int)dw; ++x) { - const PixelRGB* const pixel = (const PixelRGB*) p; + auto* pixel = (const PixelRGB*) p; p += srcData.pixelStride; XPutPixel (xImage, x, y, @@ -687,14 +687,14 @@ public: private: //============================================================================== - XImage* xImage; + XImage* xImage = {}; const unsigned int imageDepth; HeapBlock imageDataAllocated; HeapBlock imageData16Bit; int pixelStride, lineStride; - uint8* imageData; - GC gc; - ::Display* display; + uint8* imageData = {}; + GC gc = None; + ::Display* display = {}; #if JUCE_USE_XSHM XShmSegmentInfo segmentInfo; @@ -773,16 +773,16 @@ public: Array infos; //============================================================================== - ExtendedInfo& findDisplayForRect (const Rectangle& bounds, bool isScaledBounds) + ExtendedInfo& findDisplayForRect (Rectangle bounds, bool isScaledBounds) { int maxArea = -1; ExtendedInfo* retval = nullptr; for (int i = 0; i < infos.size(); ++i) { - ExtendedInfo& dpy = infos.getReference (i); + auto& dpy = infos.getReference (i); - Rectangle displayBounds = dpy.totalBounds; + auto displayBounds = dpy.totalBounds; if (isScaledBounds) displayBounds = (displayBounds.withZeroOrigin() / dpy.scale) + dpy.topLeftScaled; @@ -807,9 +807,9 @@ public: for (int i = 0; i < infos.size(); ++i) { - ExtendedInfo& dpy = infos.getReference (i); + auto& dpy = infos.getReference (i); - Rectangle displayBounds = dpy.totalBounds; + auto displayBounds = dpy.totalBounds; if (isScaledPoint) displayBounds = (displayBounds.withZeroOrigin() / dpy.scale) + dpy.topLeftScaled; @@ -829,39 +829,38 @@ public: } //============================================================================== - static Rectangle physicalToScaled (const Rectangle& physicalBounds) + static Rectangle physicalToScaled (Rectangle physicalBounds) { // first find with which display physicalBounds has the most overlap - ExtendedInfo& dpy = getInstance().findDisplayForRect (physicalBounds, false); + auto& dpy = getInstance().findDisplayForRect (physicalBounds, false); // convert to local screen bounds - Rectangle retval = physicalBounds - dpy.totalBounds.getTopLeft(); + physicalBounds -= dpy.totalBounds.getTopLeft(); // now we can safely scale the coordinates and convert to global again - return (retval / dpy.scale) + dpy.topLeftScaled; + return (physicalBounds / dpy.scale) + dpy.topLeftScaled; } - static Rectangle scaledToPhysical (const Rectangle& scaledBounds) + static Rectangle scaledToPhysical (Rectangle scaledBounds) { // first find with which display physicalBounds has the most overlap - ExtendedInfo& dpy = getInstance().findDisplayForRect (scaledBounds, true); + auto& dpy = getInstance().findDisplayForRect (scaledBounds, true); // convert to local screen bounds - Rectangle retval = scaledBounds - dpy.topLeftScaled; + scaledBounds -= dpy.topLeftScaled; // now we can safely scale the coordinates and convert to global again - return (retval * dpy.scale) + dpy.totalBounds.getTopLeft(); + return (scaledBounds * dpy.scale) + dpy.totalBounds.getTopLeft(); } //============================================================================== template - static Point physicalToScaled (const Point& physicalPoint) + static Point physicalToScaled (Point physicalPoint) { - ExtendedInfo& dpy = getInstance().findDisplayForPoint (physicalPoint.roundToInt(), false); - Point scaledTopLeft = - Point (dpy.topLeftScaled.getX(), dpy.topLeftScaled.getY()); - Point physicalTopLeft = - Point (dpy.totalBounds.getX(), dpy.totalBounds.getY()); + auto& dpy = getInstance().findDisplayForPoint (physicalPoint.roundToInt(), false); + + Point scaledTopLeft (dpy.topLeftScaled.getX(), dpy.topLeftScaled.getY()); + Point physicalTopLeft (dpy.totalBounds.getX(), dpy.totalBounds.getY()); return ((physicalPoint - physicalTopLeft) / dpy.scale) + scaledTopLeft; } @@ -869,11 +868,10 @@ public: template static Point scaledToPhysical (const Point& scaledPoint) { - ExtendedInfo& dpy = getInstance().findDisplayForPoint (scaledPoint.roundToInt(), true); - Point scaledTopLeft = - Point (dpy.topLeftScaled.getX(), dpy.topLeftScaled.getY()); - Point physicalTopLeft = - Point (dpy.totalBounds.getX(), dpy.totalBounds.getY()); + auto& dpy = getInstance().findDisplayForPoint (scaledPoint.roundToInt(), true); + + Point scaledTopLeft (dpy.topLeftScaled.getX(), dpy.topLeftScaled.getY()); + Point physicalTopLeft (dpy.totalBounds.getX(), dpy.totalBounds.getY()); return ((scaledPoint - scaledTopLeft) * dpy.scale) + physicalTopLeft; } @@ -929,7 +927,8 @@ private: if (isActiveFuncPtr != nullptr && xineramaQueryScreens != nullptr && isActiveFuncPtr (display) != 0) { int numScreens; - if (XineramaScreenInfo* xinfo = xineramaQueryScreens (display, &numScreens)) + + if (auto* xinfo = xineramaQueryScreens (display, &numScreens)) { Array infos (xinfo, numScreens); XFree (xinfo); @@ -939,7 +938,7 @@ private: } } - return Array(); + return {}; } #endif @@ -953,14 +952,6 @@ private: { private: XRandrWrapper() - : libXrandr (nullptr), - getScreenResourcesPtr (nullptr), - freeScreenResourcesPtr (nullptr), - getOutputInfoPtr (nullptr), - freeOutputInfoPtr (nullptr), - getCrtcInfoPtr (nullptr), - freeCrtcInfoPtr (nullptr), - getOutputPrimaryPtr (nullptr) { if (libXrandr == nullptr) { @@ -1061,14 +1052,14 @@ private: typedef void (*tXRRFreeCrtcInfo) (XRRCrtcInfo*); typedef RROutput (*tXRRGetOutputPrimary) (::Display*, ::Window); - void* libXrandr; - tXRRGetScreenResources getScreenResourcesPtr; - tXRRFreeScreenResources freeScreenResourcesPtr; - tXRRGetOutputInfo getOutputInfoPtr; - tXRRFreeOutputInfo freeOutputInfoPtr; - tXRRGetCrtcInfo getCrtcInfoPtr; - tXRRFreeCrtcInfo freeCrtcInfoPtr; - tXRRGetOutputPrimary getOutputPrimaryPtr; + void* libXrandr = nullptr; + tXRRGetScreenResources getScreenResourcesPtr = nullptr; + tXRRFreeScreenResources freeScreenResourcesPtr = nullptr; + tXRRGetOutputInfo getOutputInfoPtr = nullptr; + tXRRFreeOutputInfo freeOutputInfoPtr = nullptr; + tXRRGetCrtcInfo getCrtcInfoPtr = nullptr; + tXRRFreeCrtcInfo freeCrtcInfoPtr = nullptr; + tXRRGetOutputPrimary getOutputPrimaryPtr = nullptr; }; #endif @@ -1117,15 +1108,17 @@ private: { // Other gnome based distros now use gsettings for a global scale factor ChildProcess gsettings; - if (File ("/usr/bin/gsettings").existsAsFile() && - gsettings.start ("/usr/bin/gsettings get org.gnome.desktop.interface scaling-factor", ChildProcess::wantStdOut)) + + if (File ("/usr/bin/gsettings").existsAsFile() + && gsettings.start ("/usr/bin/gsettings get org.gnome.desktop.interface scaling-factor", ChildProcess::wantStdOut)) { if (gsettings.waitForProcessToFinish (200)) { - StringArray gsettingsOutput = StringArray::fromTokens (gsettings.readAllProcessOutput(), true); + auto gsettingsOutput = StringArray::fromTokens (gsettings.readAllProcessOutput(), true); + if (gsettingsOutput.size() >= 2 && gsettingsOutput[1].length() > 0) { - double scaleFactor = gsettingsOutput[1].getDoubleValue(); + auto scaleFactor = gsettingsOutput[1].getDoubleValue(); if (scaleFactor > 0.0) return scaleFactor; @@ -1291,8 +1284,7 @@ private: { bool sortByYCoordinate; - SortByCoordinate (bool byYCoordinate) - : sortByYCoordinate (byYCoordinate) + SortByCoordinate (bool byYCoordinate) : sortByYCoordinate (byYCoordinate) { } @@ -1330,12 +1322,12 @@ private: for (int i = 1; i < copy.size(); ++i) { - ExtendedInfo& current = *copy[i]; + auto& current = *copy[i]; // Is this screen's position aligned to any other previous display? for (int j = i - 1; j >= 0; --j) { - ExtendedInfo& other = *copy[j]; + auto& other = *copy[j]; int prevCoordinate = updateYCoordinates ? other.totalBounds.getBottom() : other.totalBounds.getRight(); int curCoordinate = updateYCoordinates ? current.totalBounds.getY() : current.totalBounds.getX(); if (prevCoordinate == curCoordinate) @@ -1470,11 +1462,7 @@ class LinuxComponentPeer : public ComponentPeer public: LinuxComponentPeer (Component& comp, const int windowStyleFlags, Window parentToAddTo) : ComponentPeer (comp, windowStyleFlags), - windowH (0), parentWindow (0), keyProxy (0), - fullScreen (false), mapped (false), focused (false), - visual (nullptr), depth (0), - isAlwaysOnTop (comp.isAlwaysOnTop()), - currentScaleFactor (1.0) + isAlwaysOnTop (comp.isAlwaysOnTop()) { // it's dangerous to create a window on a thread other than the message thread.. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager()); @@ -1601,8 +1589,7 @@ public: currentScaleFactor = DisplayGeometry::getInstance().findDisplayForRect (bounds, true).scale; - Rectangle physicalBounds = - DisplayGeometry::scaledToPhysical (bounds); + auto physicalBounds = DisplayGeometry::scaledToPhysical (bounds); WeakReference deletionChecker (&component); ScopedXLock xlock (display); @@ -1697,7 +1684,7 @@ public: void setFullScreen (const bool shouldBeFullScreen) override { - Rectangle r (lastNonFullscreenBounds); // (get a copy of this before de-minimising) + auto r = lastNonFullscreenBounds; // (get a copy of this before de-minimising) setMinimised (false); @@ -1797,12 +1784,12 @@ public: for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) { - Component* const c = Desktop::getInstance().getComponent (i); + auto* c = Desktop::getInstance().getComponent (i); if (c == &component) break; - if (ComponentPeer* peer = c->getPeer()) + if (auto* peer = c->getPeer()) if (peer->contains (localPos + bounds.getPosition() - peer->getBounds().getPosition(), true)) return false; } @@ -1825,7 +1812,7 @@ public: BorderSize getFrameSize() const override { - return BorderSize(); + return {}; } bool setAlwaysOnTop (bool /* alwaysOnTop */) override @@ -1867,7 +1854,7 @@ public: void toBehind (ComponentPeer* other) override { - if (LinuxComponentPeer* const otherPeer = dynamic_cast (other)) + if (auto* otherPeer = dynamic_cast (other)) { if (otherPeer->styleFlags & windowIsTemporary) return; @@ -1896,9 +1883,7 @@ public: Window getFocusWindow() { #if JUCE_X11_SUPPORTS_XEMBED - Window w = (Window) juce_getCurrentFocusWindow (this); - - if (w != 0) + if (Window w = (Window) juce_getCurrentFocusWindow (this)) return w; #endif @@ -1968,9 +1953,8 @@ public: void deleteIconPixmaps() { ScopedXLock xlock (display); - XWMHints* wmHints = XGetWMHints (display, windowH); - if (wmHints != nullptr) + if (auto* wmHints = XGetWMHints (display, windowH)) { if ((wmHints->flags & IconPixmapHint) != 0) { @@ -2043,7 +2027,7 @@ public: void handleKeyPressEvent (XKeyEvent& keyEvent) { - const ModifierKeys oldMods (currentModifiers); + auto oldMods = currentModifiers; char utf8 [64] = { 0 }; juce_wchar unicodeChar = 0; @@ -2188,7 +2172,7 @@ public: sym = XkbKeycodeToKeysym (display, (::KeyCode) keyEvent.keycode, 0, 0); } - const ModifierKeys oldMods (currentModifiers); + auto oldMods = currentModifiers; const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false); if (oldMods != currentModifiers) @@ -2375,18 +2359,14 @@ public: // if the native title bar is dragged, need to tell any active menus, etc. if ((styleFlags & windowHasTitleBar) != 0 - && component.isCurrentlyBlockedByAnotherModalComponent()) + && component.isCurrentlyBlockedByAnotherModalComponent()) { - if (Component* const currentModalComp = Component::getCurrentlyModalComponent()) - currentModalComp->inputAttemptWhenModal(); + if (auto* currentModalComp = Component::getCurrentlyModalComponent()) + currentModalComp->inputAttemptWhenModal(); } - if (confEvent.window == windowH - && confEvent.above != 0 - && isFrontWindow()) - { + if (confEvent.window == windowH && confEvent.above != 0 && isFrontWindow()) handleBroughtToFront(); - } } void handleReparentNotifyEvent() @@ -2506,10 +2486,8 @@ public: StringArray uriList; - for (int i = 0; i < files.size(); ++i) + for (auto& f : files) { - const String& f = files[i]; - if (f.matchesWildcard ("?*://*", false)) uriList.add (f); else @@ -2548,10 +2526,8 @@ public: void repaintOpenGLContexts() { for (int i = 0; i < glRepaintListeners.size(); ++i) - { - if (Component* c = glRepaintListeners [i]) + if (auto* c = glRepaintListeners [i]) c->handleCommandMessage (0); - } } //============================================================================== @@ -2610,13 +2586,10 @@ private: class LinuxRepaintManager : public Timer { public: - LinuxRepaintManager (LinuxComponentPeer& p, ::Display* _display) - : peer (p), lastTimeImageUsed (0), - display (_display) + LinuxRepaintManager (LinuxComponentPeer& p, ::Display* d) + : peer (p), display (d) { #if JUCE_USE_XSHM - shmPaintsPending = 0; - useARGBImagesForRendering = XSHMHelpers::isShmAvailable (display); if (useARGBImagesForRendering) @@ -2653,7 +2626,7 @@ private: } } - void repaint (const Rectangle& area) + void repaint (Rectangle area) { if (! isTimerRunning()) startTimer (repaintTimerPeriod); @@ -2682,7 +2655,7 @@ private: { #if JUCE_USE_XSHM image = Image (new XBitmapImage (display, useARGBImagesForRendering ? Image::ARGB - : Image::RGB, + : Image::RGB, #else image = Image (new XBitmapImage (display, Image::RGB, #endif @@ -2738,13 +2711,13 @@ private: LinuxComponentPeer& peer; Image image; - uint32 lastTimeImageUsed; + uint32 lastTimeImageUsed = 0; RectangleList regionsNeedingRepaint; ::Display* display; #if JUCE_USE_XSHM bool useARGBImagesForRendering; - int shmPaintsPending; + int shmPaintsPending = 0; #endif JUCE_DECLARE_NON_COPYABLE (LinuxRepaintManager) }; @@ -2753,15 +2726,15 @@ private: ScopedPointer repainter; friend class LinuxRepaintManager; - Window windowH, parentWindow, keyProxy; + Window windowH = {}, parentWindow = {}, keyProxy = {}; Rectangle bounds; Image taskbarImage; - bool fullScreen, mapped, focused; - Visual* visual; - int depth; + bool fullScreen = false, mapped = false, focused = false; + Visual* visual = {}; + int depth = 0; BorderSize windowBorder; bool isAlwaysOnTop; - double currentScaleFactor; + double currentScaleFactor = 1.0; Array glRepaintListeners; enum { KeyPressEventType = 2 }; static ::Display* display; @@ -3196,22 +3169,20 @@ private: //============================================================================== struct DragState { - DragState(::Display* _display) - : isText (false), dragging (false), expectingStatus (false), - canDrop (false), targetWindow (None), xdndVersion (-1) + DragState (::Display* d) { if (isText) - allowedTypes.add (Atoms::getCreating (_display, "text/plain")); + allowedTypes.add (Atoms::getCreating (d, "text/plain")); else - allowedTypes.add (Atoms::getCreating (_display, "text/uri-list")); + allowedTypes.add (Atoms::getCreating (d, "text/uri-list")); } - bool isText; - bool dragging; // currently performing outgoing external dnd as Xdnd source, have grabbed mouse - bool expectingStatus; // XdndPosition sent, waiting for XdndStatus - bool canDrop; // target window signals it will accept the drop - Window targetWindow; // potential drop target - int xdndVersion; // negotiated version with target + bool isText = false; + bool dragging = false; // currently performing outgoing external dnd as Xdnd source, have grabbed mouse + bool expectingStatus = false; // XdndPosition sent, waiting for XdndStatus + bool canDrop = false; // target window signals it will accept the drop + Window targetWindow = None; // potential drop target + int xdndVersion = -1; // negotiated version with target Rectangle silentRect; String textOrFiles; Array allowedTypes; @@ -3749,7 +3720,8 @@ Point LinuxComponentPeer::lastMousePos; ::Display* LinuxComponentPeer::display = nullptr; //============================================================================== -namespace WindowingHelpers { +namespace WindowingHelpers +{ static void windowMessageReceive (XEvent& event) { if (event.xany.window != None) @@ -4013,7 +3985,7 @@ bool Desktop::isScreenSaverEnabled() //============================================================================== Image juce_createIconForFile (const File& /* file */) { - return Image(); + return {}; } //============================================================================== @@ -4021,32 +3993,31 @@ void LookAndFeel::playAlertSound() { std::cout << "\a" << std::flush; } + //============================================================================== -Rectangle juce_LinuxScaledToPhysicalBounds (ComponentPeer* peer, const Rectangle& bounds) +Rectangle juce_LinuxScaledToPhysicalBounds (ComponentPeer* peer, Rectangle bounds) { - Rectangle retval = bounds; + if (auto* linuxPeer = dynamic_cast (peer)) + bounds *= linuxPeer->getCurrentScale(); - if (LinuxComponentPeer* linuxPeer = dynamic_cast (peer)) - retval *= linuxPeer->getCurrentScale(); - - return retval; + return bounds; } void juce_LinuxAddRepaintListener (ComponentPeer* peer, Component* dummy) { - if (LinuxComponentPeer* linuxPeer = dynamic_cast (peer)) + if (auto* linuxPeer = dynamic_cast (peer)) linuxPeer->addOpenGLRepaintListener (dummy); } void juce_LinuxRemoveRepaintListener (ComponentPeer* peer, Component* dummy) { - if (LinuxComponentPeer* linuxPeer = dynamic_cast (peer)) + if (auto* linuxPeer = dynamic_cast (peer)) linuxPeer->removeOpenGLRepaintListener (dummy); } unsigned long juce_createKeyProxyWindow (ComponentPeer* peer) { - if (LinuxComponentPeer* linuxPeer = dynamic_cast (peer)) + if (auto* linuxPeer = dynamic_cast (peer)) return linuxPeer->createKeyProxy(); return 0; @@ -4054,9 +4025,10 @@ unsigned long juce_createKeyProxyWindow (ComponentPeer* peer) void juce_deleteKeyProxyWindow (ComponentPeer* peer) { - if (LinuxComponentPeer* linuxPeer = dynamic_cast (peer)) + if (auto* linuxPeer = dynamic_cast (peer)) linuxPeer->deleteKeyProxy(); } + //============================================================================== #if JUCE_MODAL_LOOPS_PERMITTED void JUCE_CALLTYPE NativeMessageBox::showMessageBox (AlertWindow::AlertIconType iconType, @@ -4302,7 +4274,7 @@ void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType ty void MouseCursor::showInWindow (ComponentPeer* peer) const { - if (LinuxComponentPeer* const lp = dynamic_cast (peer)) + if (auto* lp = dynamic_cast (peer)) lp->showMouseCursor ((Cursor) getHandle()); } @@ -4319,9 +4291,9 @@ bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& fi if (files.size() == 0) return false; - if (MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0)) - if (Component* sourceComp = draggingSource->getComponentUnderMouse()) - if (LinuxComponentPeer* const lp = dynamic_cast (sourceComp->getPeer())) + if (auto* draggingSource = Desktop::getInstance().getDraggingMouseSource (0)) + if (auto* sourceComp = draggingSource->getComponentUnderMouse()) + if (auto* lp = dynamic_cast (sourceComp->getPeer())) return lp->externalDragFileInit (files, canMoveFiles); // This method must be called in response to a component's mouseDown or mouseDrag event! @@ -4334,9 +4306,9 @@ bool DragAndDropContainer::performExternalDragDropOfText (const String& text) if (text.isEmpty()) return false; - if (MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0)) - if (Component* sourceComp = draggingSource->getComponentUnderMouse()) - if (LinuxComponentPeer* const lp = dynamic_cast (sourceComp->getPeer())) + if (auto* draggingSource = Desktop::getInstance().getDraggingMouseSource (0)) + if (auto* sourceComp = draggingSource->getComponentUnderMouse()) + if (auto* lp = dynamic_cast (sourceComp->getPeer())) return lp->externalDragTextInit (text); // This method must be called in response to a component's mouseDown or mouseDrag event! diff --git a/modules/juce_opengl/native/juce_OpenGL_android.h b/modules/juce_opengl/native/juce_OpenGL_android.h index c5d65d36e4..776fe5647b 100644 --- a/modules/juce_opengl/native/juce_OpenGL_android.h +++ b/modules/juce_opengl/native/juce_OpenGL_android.h @@ -170,7 +170,7 @@ public: GLuint getFrameBufferID() const noexcept { return 0; } //============================================================================== - void updateWindowPosition (const Rectangle& bounds) + void updateWindowPosition (Rectangle bounds) { if (lastBounds != bounds) { diff --git a/modules/juce_opengl/native/juce_OpenGL_linux_X11.h b/modules/juce_opengl/native/juce_OpenGL_linux_X11.h index 92d3107cda..c65f358058 100644 --- a/modules/juce_opengl/native/juce_OpenGL_linux_X11.h +++ b/modules/juce_opengl/native/juce_OpenGL_linux_X11.h @@ -28,17 +28,16 @@ extern XContext windowHandleXContext; //============================================================================== // Defined juce_linux_Windowing.cpp -Rectangle juce_LinuxScaledToPhysicalBounds (ComponentPeer* peer, const Rectangle& bounds); -void juce_LinuxAddRepaintListener (ComponentPeer* peer, Component* dummy); -void juce_LinuxRemoveRepaintListener (ComponentPeer* peer, Component* dummy); +Rectangle juce_LinuxScaledToPhysicalBounds (ComponentPeer*, Rectangle); +void juce_LinuxAddRepaintListener (ComponentPeer*, Component* dummy); +void juce_LinuxRemoveRepaintListener (ComponentPeer*, Component* dummy); //============================================================================== class OpenGLContext::NativeContext { private: - class DummyComponent : public Component + struct DummyComponent : public Component { - public: DummyComponent (OpenGLContext::NativeContext& nativeParentContext) : native (nativeParentContext) { @@ -49,7 +48,7 @@ private: if (commandId == 0) native.triggerRepaint(); } - private: + OpenGLContext::NativeContext& native; }; @@ -59,8 +58,7 @@ public: void* shareContext, bool /*useMultisampling*/, OpenGLVersion) - : component (comp), renderContext (0), embeddedWindow (0), swapFrames (0), bestVisual (0), - contextToShareWith (shareContext), context (nullptr), dummy (*this) + : component (comp), contextToShareWith (shareContext), dummy (*this) { display = XWindowSystem::getInstance()->displayRef(); @@ -88,17 +86,19 @@ public: if (bestVisual == nullptr) return; - ComponentPeer* const peer = component.getPeer(); - Window windowH = (Window) peer->getNativeHandle(); + auto* peer = component.getPeer(); + jassert (peer != nullptr); + + auto windowH = (Window) peer->getNativeHandle(); + auto colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone); - Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone); XSetWindowAttributes swa; swa.colormap = colourMap; swa.border_pixel = 0; swa.event_mask = ExposureMask | StructureNotifyMask; - Rectangle glBounds (component.getTopLevelComponent() - ->getLocalArea (&component, component.getLocalBounds())); + auto glBounds = component.getTopLevelComponent() + ->getLocalArea (&component, component.getLocalBounds()); glBounds = juce_LinuxScaledToPhysicalBounds (peer, glBounds); @@ -177,12 +177,10 @@ public: glXSwapBuffers (display, embeddedWindow); } - void updateWindowPosition (const Rectangle& newBounds) + void updateWindowPosition (Rectangle newBounds) { bounds = newBounds; - - const Rectangle physicalBounds = - juce_LinuxScaledToPhysicalBounds (component.getPeer(), bounds); + auto physicalBounds = juce_LinuxScaledToPhysicalBounds (component.getPeer(), bounds); ScopedXLock xlock (display); XMoveResizeWindow (display, embeddedWindow, @@ -196,10 +194,8 @@ public: if (numFramesPerSwap == swapFrames) return true; - PFNGLXSWAPINTERVALSGIPROC GLXSwapIntervalSGI - = (PFNGLXSWAPINTERVALSGIPROC) OpenGLHelpers::getExtensionFunction ("glXSwapIntervalSGI"); - - if (GLXSwapIntervalSGI != nullptr) + if (auto GLXSwapIntervalSGI + = (PFNGLXSWAPINTERVALSGIPROC) OpenGLHelpers::getExtensionFunction ("glXSwapIntervalSGI")) { swapFrames = numFramesPerSwap; GLXSwapIntervalSGI (numFramesPerSwap); @@ -224,18 +220,18 @@ public: private: Component& component; - GLXContext renderContext; - Window embeddedWindow; + GLXContext renderContext = {}; + Window embeddedWindow = {}; - int swapFrames; + int swapFrames = 0; Rectangle bounds; - XVisualInfo* bestVisual; + XVisualInfo* bestVisual = {}; void* contextToShareWith; - OpenGLContext* context; + OpenGLContext* context = {}; DummyComponent dummy; - ::Display* display; + ::Display* display = {}; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeContext) }; diff --git a/modules/juce_opengl/native/juce_OpenGL_osx.h b/modules/juce_opengl/native/juce_OpenGL_osx.h index 783e9bde6f..3bc4bc5a10 100644 --- a/modules/juce_opengl/native/juce_OpenGL_osx.h +++ b/modules/juce_opengl/native/juce_OpenGL_osx.h @@ -192,7 +192,7 @@ public: lastSwapTime = now; } - void updateWindowPosition (const Rectangle&) {} + void updateWindowPosition (Rectangle) {} bool setSwapInterval (int numFramesPerSwap) { diff --git a/modules/juce_opengl/native/juce_OpenGL_win32.h b/modules/juce_opengl/native/juce_OpenGL_win32.h index 77f747b25c..40c9dedeb4 100644 --- a/modules/juce_opengl/native/juce_OpenGL_win32.h +++ b/modules/juce_opengl/native/juce_OpenGL_win32.h @@ -35,7 +35,6 @@ public: void* contextToShareWith, bool /*useMultisampling*/, OpenGLVersion) - : context (nullptr) { dummyComponent = new DummyComponent (*this); createNativeWindow (component); @@ -43,7 +42,8 @@ public: PIXELFORMATDESCRIPTOR pfd; initialisePixelFormatDescriptor (pfd, pixelFormat); - const int pixFormat = ChoosePixelFormat (dc, &pfd); + auto pixFormat = ChoosePixelFormat (dc, &pfd); + if (pixFormat != 0) SetPixelFormat (dc, pixFormat, &pfd); @@ -54,7 +54,7 @@ public: makeActive(); initialiseGLExtensions(); - const int wglFormat = wglChoosePixelFormatExtension (pixelFormat); + auto wglFormat = wglChoosePixelFormatExtension (pixelFormat); deactivateCurrentContext(); if (wglFormat != pixFormat && wglFormat != 0) @@ -106,7 +106,7 @@ public: return wglGetSwapIntervalEXT != nullptr ? wglGetSwapIntervalEXT() : 0; } - void updateWindowPosition (const Rectangle& bounds) + void updateWindowPosition (Rectangle bounds) { if (nativeWindow != nullptr) SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0, @@ -141,7 +141,7 @@ private: ScopedPointer nativeWindow; HGLRC renderContext; HDC dc; - OpenGLContext* context; + OpenGLContext* context = {}; #define JUCE_DECLARE_WGL_EXTENSION_FUNCTION(name, returnType, params) \ typedef returnType (__stdcall *type_ ## name) params; type_ ## name name; @@ -162,10 +162,10 @@ private: void createNativeWindow (Component& component) { - Component* topComp = component.getTopLevelComponent(); + auto* topComp = component.getTopLevelComponent(); nativeWindow = createNonRepaintingEmbeddedWindowsPeer (*dummyComponent, topComp->getWindowHandle()); - if (ComponentPeer* peer = topComp->getPeer()) + if (auto* peer = topComp->getPeer()) updateWindowPosition (peer->getAreaCoveredBy (component)); nativeWindow->setVisible (true);