diff --git a/modules/juce_audio_plugin_client/Unity/juce_Unity_Wrapper.cpp b/modules/juce_audio_plugin_client/Unity/juce_Unity_Wrapper.cpp index c4ebfb15c9..f39efc46cd 100644 --- a/modules/juce_audio_plugin_client/Unity/juce_Unity_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/Unity/juce_Unity_Wrapper.cpp @@ -145,8 +145,15 @@ private: { } - ImageType* createType() const override { return new SoftwareImageType(); } - LowLevelGraphicsContext* createLowLevelContext() override { return new LowLevelGraphicsSoftwareRenderer (Image (this)); } + std::unique_ptr createType() const override + { + return std::make_unique(); + } + + std::unique_ptr createLowLevelContext() override + { + return std::make_unique (Image (this)); + } void initialiseBitmapData (Image::BitmapData& bitmap, int x, int y, Image::BitmapData::ReadWriteMode mode) override { diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp index d8b06703fe..bab4475ca0 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp @@ -51,8 +51,8 @@ LowLevelGraphicsContext::~LowLevelGraphicsContext() {} //============================================================================== Graphics::Graphics (const Image& imageToDrawOnto) - : context (*imageToDrawOnto.createLowLevelContext()), - contextToDelete (&context) + : contextHolder (imageToDrawOnto.createLowLevelContext()), + context (*contextHolder) { jassert (imageToDrawOnto.isValid()); // Can't draw into a null image! } diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.h b/modules/juce_graphics/contexts/juce_GraphicsContext.h index 1c2a293a8b..5b503f0a58 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.h +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.h @@ -741,8 +741,8 @@ public: private: //============================================================================== + std::unique_ptr contextHolder; LowLevelGraphicsContext& context; - std::unique_ptr contextToDelete; bool saveStatePending = false; void saveStateIfPending(); diff --git a/modules/juce_graphics/images/juce_Image.cpp b/modules/juce_graphics/images/juce_Image.cpp index 1673b25867..b3ac8fe8fa 100644 --- a/modules/juce_graphics/images/juce_Image.cpp +++ b/modules/juce_graphics/images/juce_Image.cpp @@ -55,7 +55,7 @@ ImageType::~ImageType() {} Image ImageType::convert (const Image& source) const { - if (source.isNull() || getTypeID() == (std::unique_ptr (source.getPixelData()->createType())->getTypeID())) + if (source.isNull() || getTypeID() == source.getPixelData()->createType()->getTypeID()) return source; const Image::BitmapData src (source, Image::BitmapData::readOnly); @@ -90,10 +90,10 @@ public: imageData.allocate ((size_t) lineStride * (size_t) jmax (1, h), clearImage); } - LowLevelGraphicsContext* createLowLevelContext() override + std::unique_ptr createLowLevelContext() override { sendDataChangeMessage(); - return new LowLevelGraphicsSoftwareRenderer (Image (*this)); + return std::make_unique (Image (*this)); } void initialiseBitmapData (Image::BitmapData& bitmap, int x, int y, Image::BitmapData::ReadWriteMode mode) override @@ -114,7 +114,7 @@ public: return *s; } - ImageType* createType() const override { return new SoftwareImageType(); } + std::unique_ptr createType() const override { return std::make_unique(); } private: HeapBlock imageData; @@ -162,9 +162,9 @@ public: { } - LowLevelGraphicsContext* createLowLevelContext() override + std::unique_ptr createLowLevelContext() override { - LowLevelGraphicsContext* g = sourceImage->createLowLevelContext(); + auto g = sourceImage->createLowLevelContext(); g->clipToRectangle (area); g->setOrigin (area.getPosition()); return g; @@ -181,7 +181,7 @@ public: ImagePixelData::Ptr clone() override { jassert (getReferenceCount() > 0); // (This method can't be used on an unowned pointer, as it will end up self-deleting) - const std::unique_ptr type (createType()); + auto type = createType(); Image newImage (type->create (pixelFormat, area.getWidth(), area.getHeight(), pixelFormat != Image::RGB)); @@ -193,7 +193,7 @@ public: return *newImage.getPixelData(); } - ImageType* createType() const override { return sourceImage->createType(); } + std::unique_ptr createType() const override { return sourceImage->createType(); } /* as we always hold a reference to image, don't double count */ int getSharedCount() const noexcept override { return getReferenceCount() + sourceImage->getSharedCount() - 1; } @@ -278,9 +278,12 @@ bool Image::isRGB() const noexcept { return getFormat() == bool Image::isSingleChannel() const noexcept { return getFormat() == SingleChannel; } bool Image::hasAlphaChannel() const noexcept { return getFormat() != RGB; } -LowLevelGraphicsContext* Image::createLowLevelContext() const +std::unique_ptr Image::createLowLevelContext() const { - return image == nullptr ? nullptr : image->createLowLevelContext(); + if (image != nullptr) + return image->createLowLevelContext(); + + return {}; } void Image::duplicateIfShared() @@ -302,7 +305,7 @@ Image Image::rescaled (int newWidth, int newHeight, Graphics::ResamplingQuality if (image == nullptr || (image->width == newWidth && image->height == newHeight)) return *this; - const std::unique_ptr type (image->createType()); + auto type = image->createType(); Image newImage (type->create (image->pixelFormat, newWidth, newHeight, hasAlphaChannel())); Graphics g (newImage); @@ -319,7 +322,7 @@ Image Image::convertedToFormat (PixelFormat newFormat) const auto w = image->width, h = image->height; - const std::unique_ptr type (image->createType()); + auto type = image->createType(); Image newImage (type->create (newFormat, w, h, false)); if (newFormat == SingleChannel) @@ -450,7 +453,7 @@ void Image::clear (const Rectangle& area, Colour colourToClearTo) { if (image != nullptr) { - const std::unique_ptr g (image->createLowLevelContext()); + auto g = image->createLowLevelContext(); g->setFill (colourToClearTo); g->fillRect (area, true); } diff --git a/modules/juce_graphics/images/juce_Image.h b/modules/juce_graphics/images/juce_Image.h index 742e3f51a4..5e3b6700e5 100644 --- a/modules/juce_graphics/images/juce_Image.h +++ b/modules/juce_graphics/images/juce_Image.h @@ -398,7 +398,7 @@ public: /** Creates a context suitable for drawing onto this image. Don't call this method directly! It's used internally by the Graphics class. */ - LowLevelGraphicsContext* createLowLevelContext() const; + std::unique_ptr createLowLevelContext() const; /** Returns the number of Image objects which are currently referring to the same internal shared image data. @@ -449,11 +449,11 @@ public: using Ptr = ReferenceCountedObjectPtr; /** Creates a context that will draw into this image. */ - virtual LowLevelGraphicsContext* createLowLevelContext() = 0; + virtual std::unique_ptr createLowLevelContext() = 0; /** Creates a copy of this image. */ virtual Ptr clone() = 0; /** Creates an instance of the type of this image. */ - virtual ImageType* createType() const = 0; + virtual std::unique_ptr createType() const = 0; /** Initialises a BitmapData object. */ virtual void initialiseBitmapData (Image::BitmapData&, int x, int y, Image::BitmapData::ReadWriteMode) = 0; /** Returns the number of Image objects which are currently referring to the same internal diff --git a/modules/juce_graphics/native/juce_RenderingHelpers.h b/modules/juce_graphics/native/juce_RenderingHelpers.h index 10bd64e145..0d1ce924a8 100644 --- a/modules/juce_graphics/native/juce_RenderingHelpers.h +++ b/modules/juce_graphics/native/juce_RenderingHelpers.h @@ -2504,7 +2504,7 @@ public: { auto layerBounds = clip->getClipBounds(); - const std::unique_ptr g (image.createLowLevelContext()); + auto g = image.createLowLevelContext(); g->setOpacity (finishedLayerState.transparencyLayerAlpha); g->drawImage (finishedLayerState.image, AffineTransform::translation (layerBounds.getPosition())); } diff --git a/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm b/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm index 4869c13b5b..6d0c2e7010 100644 --- a/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm +++ b/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm @@ -63,11 +63,11 @@ public: CGContextRelease (context); } - LowLevelGraphicsContext* createLowLevelContext() override + std::unique_ptr createLowLevelContext() override { freeCachedImageRef(); sendDataChangeMessage(); - return new CoreGraphicsContext (context, height, 1.0f); + return std::make_unique (context, height, 1.0f); } void initialiseBitmapData (Image::BitmapData& bitmap, int x, int y, Image::BitmapData::ReadWriteMode mode) override @@ -91,7 +91,7 @@ public: return *im; } - ImageType* createType() const override { return new NativeImageType(); } + std::unique_ptr createType() const override { return std::make_unique(); } //============================================================================== static CGImageRef getCachedImageRef (const Image& juceImage, CGColorSpaceRef colourSpace) diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp index 6a1e196173..245c1285f7 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp @@ -168,10 +168,11 @@ MouseCursor LookAndFeel::getMouseCursorFor (Component& component) return cursor; } -LowLevelGraphicsContext* LookAndFeel::createGraphicsContext (const Image& imageToRenderOn, const Point& origin, - const RectangleList& initialClip) +std::unique_ptr LookAndFeel::createGraphicsContext (const Image& imageToRenderOn, + Point origin, + RectangleList initialClip) { - return new LowLevelGraphicsSoftwareRenderer (imageToRenderOn, origin, initialClip); + return std::make_unique (imageToRenderOn, origin, initialClip); } //============================================================================== diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h index 13be6de840..a75af12c78 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h @@ -196,9 +196,9 @@ public: //============================================================================== /** Creates a new graphics context object. */ - virtual LowLevelGraphicsContext* createGraphicsContext (const Image& imageToRenderOn, - const Point& origin, - const RectangleList& initialClip); + virtual std::unique_ptr createGraphicsContext (const Image& imageToRenderOn, + Point origin, + RectangleList initialClip); void setUsingNativeAlertWindows (bool shouldUseNativeAlerts); bool isUsingNativeAlertWindows(); diff --git a/modules/juce_gui_basics/native/juce_android_Windowing.cpp b/modules/juce_gui_basics/native/juce_android_Windowing.cpp index 6803b9a356..ba83e4e40e 100644 --- a/modules/juce_gui_basics/native/juce_android_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_android_Windowing.cpp @@ -241,7 +241,7 @@ class AndroidComponentPeer : public ComponentPeer, private Timer { public: - AndroidComponentPeer (Component& comp, const int windowStyleFlags, void* nativeViewHandle) + AndroidComponentPeer (Component& comp, int windowStyleFlags, void* nativeViewHandle) : ComponentPeer (comp, windowStyleFlags), fullScreen (false), navBarsHidden (false), @@ -424,7 +424,7 @@ public: class ViewMover : public CallbackMessage { public: - ViewMover (const GlobalRef& v, const Rectangle& boundsToUse) : view (v), bounds (boundsToUse) {} + ViewMover (const GlobalRef& v, Rectangle boundsToUse) : view (v), bounds (boundsToUse) {} void messageCallback() override { @@ -925,7 +925,7 @@ private: struct PreallocatedImage : public ImagePixelData { - PreallocatedImage (const int width_, const int height_, jint* data_, bool hasAlpha_) + PreallocatedImage (int width_, int height_, jint* data_, bool hasAlpha_) : ImagePixelData (Image::ARGB, width_, height_), data (data_), hasAlpha (hasAlpha_) { if (hasAlpha_) @@ -936,7 +936,7 @@ private: { if (hasAlpha) { - PixelARGB* pix = (PixelARGB*) data; + auto pix = (PixelARGB*) data; for (int i = width * height; --i >= 0;) { @@ -946,8 +946,15 @@ private: } } - ImageType* createType() const override { return new SoftwareImageType(); } - LowLevelGraphicsContext* createLowLevelContext() override { return new LowLevelGraphicsSoftwareRenderer (Image (this)); } + std::unique_ptr createType() const override + { + return std::make_unique(); + } + + std::unique_ptr createLowLevelContext() override + { + return std::make_unique (Image (this)); + } void initialiseBitmapData (Image::BitmapData& bm, int x, int y, Image::BitmapData::ReadWriteMode /*mode*/) override { @@ -959,7 +966,7 @@ private: ImagePixelData::Ptr clone() override { - PreallocatedImage* s = new PreallocatedImage (width, height, 0, hasAlpha); + auto s = new PreallocatedImage (width, height, 0, hasAlpha); s->allocatedData.malloc (sizeof (jint) * static_cast (width * height)); s->data = s->allocatedData; memcpy (s->data, data, sizeof (jint) * static_cast (width * height)); @@ -1060,7 +1067,7 @@ void MouseInputSource::setRawMousePosition (Point) } //============================================================================== -bool KeyPress::isKeyCurrentlyDown (const int /*keyCode*/) +bool KeyPress::isKeyCurrentlyDown (int /*keyCode*/) { // TODO return false; @@ -1242,7 +1249,7 @@ int JUCE_CALLTYPE NativeMessageBox::showYesNoBox (AlertWindow::AlertIconType /*i //============================================================================== static bool androidScreenSaverEnabled = false; -void Desktop::setScreenSaverEnabled (const bool shouldEnable) +void Desktop::setScreenSaverEnabled (bool shouldEnable) { constexpr auto FLAG_KEEP_SCREEN_ON = 0x80; @@ -1486,15 +1493,15 @@ Image juce_createIconForFile (const File& /*file*/) } //============================================================================== -void* CustomMouseCursorInfo::create() const { return nullptr; } -void* MouseCursor::createStandardMouseCursor (const MouseCursor::StandardCursorType) { return nullptr; } -void MouseCursor::deleteMouseCursor (void* const /*cursorHandle*/, const bool /*isStandard*/) {} +void* CustomMouseCursorInfo::create() const { return nullptr; } +void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType) { return nullptr; } +void MouseCursor::deleteMouseCursor (void* /*cursorHandle*/, bool /*isStandard*/) {} //============================================================================== void MouseCursor::showInWindow (ComponentPeer*) const {} //============================================================================== -bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& /*files*/, const bool /*canMove*/, +bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& /*files*/, bool /*canMove*/, Component* /*srcComp*/, std::function /*callback*/) { jassertfalse; // no such thing on Android! 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 e68619cb70..79e8bf220d 100644 --- a/modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp @@ -620,10 +620,10 @@ public: } } - LowLevelGraphicsContext* createLowLevelContext() override + std::unique_ptr createLowLevelContext() override { sendDataChangeMessage(); - return new LowLevelGraphicsSoftwareRenderer (Image (this)); + return std::make_unique (Image (this)); } void initialiseBitmapData (Image::BitmapData& bitmap, int x, int y, @@ -644,7 +644,7 @@ public: return nullptr; } - ImageType* createType() const override { return new NativeImageType(); } + std::unique_ptr createType() const override { return std::make_unique(); } void blitToWindow (Window window, int dx, int dy, unsigned int dw, unsigned int dh, int sx, int sy) @@ -2305,8 +2305,9 @@ private: image.clear (i - totalArea.getPosition()); { - std::unique_ptr context (peer.getComponent().getLookAndFeel() - .createGraphicsContext (image, -totalArea.getPosition(), adjustedList)); + auto context = peer.getComponent().getLookAndFeel() + .createGraphicsContext (image, -totalArea.getPosition(), adjustedList); + context->addTransform (AffineTransform::scale ((float) peer.currentScaleFactor)); peer.handlePaint (*context); } diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index c0cad5af62..9c25b98da1 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -876,8 +876,8 @@ public: if (intScale != 1) clip.scaleAll (intScale); - std::unique_ptr context (component.getLookAndFeel() - .createGraphicsContext (temp, offset * intScale, clip)); + auto context = component.getLookAndFeel() + .createGraphicsContext (temp, offset * intScale, clip); if (intScale != 1) context->addTransform (AffineTransform::scale (displayScale)); diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 14420ab442..3d7ffbcfef 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -763,12 +763,12 @@ public: DeleteObject (hBitmap); } - ImageType* createType() const override { return new NativeImageType(); } + std::unique_ptr createType() const override { return std::make_unique(); } - LowLevelGraphicsContext* createLowLevelContext() override + std::unique_ptr createLowLevelContext() override { sendDataChangeMessage(); - return new LowLevelGraphicsSoftwareRenderer (Image (this)); + return std::make_unique (Image (this)); } void initialiseBitmapData (Image::BitmapData& bitmap, int x, int y, Image::BitmapData::ReadWriteMode mode) override @@ -2441,8 +2441,8 @@ private: offscreenImage.clear (i); { - std::unique_ptr context (component.getLookAndFeel() - .createGraphicsContext (offscreenImage, Point (-x, -y), contextClip)); + auto context = component.getLookAndFeel() + .createGraphicsContext (offscreenImage, { -x, -y }, contextClip); context->addTransform (AffineTransform::scale ((float) getPlatformScaleFactor())); handlePaint (*context); diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp index 6731ef9f44..68d614b643 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp @@ -1804,31 +1804,31 @@ static void clearOpenGLGlyphCacheCallback() SavedState::GlyphCacheType::getInstance().reset(); } -static LowLevelGraphicsContext* createOpenGLContext (const Target& target) +static std::unique_ptr createOpenGLContext (const Target& target) { clearOpenGLGlyphCache = clearOpenGLGlyphCacheCallback; if (target.context.areShadersAvailable()) - return new ShaderContext (target); + return std::make_unique (target); Image tempImage (Image::ARGB, target.bounds.getWidth(), target.bounds.getHeight(), true, SoftwareImageType()); - return new NonShaderContext (target, tempImage); + return std::make_unique (target, tempImage); } } //============================================================================== -LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext& context, int width, int height) +std::unique_ptr createOpenGLGraphicsContext (OpenGLContext& context, int width, int height) { return createOpenGLGraphicsContext (context, context.getFrameBufferID(), width, height); } -LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext& context, OpenGLFrameBuffer& target) +std::unique_ptr createOpenGLGraphicsContext (OpenGLContext& context, OpenGLFrameBuffer& target) { return OpenGLRendering::createOpenGLContext (OpenGLRendering::Target (context, target, {})); } -LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext& context, unsigned int frameBufferID, int width, int height) +std::unique_ptr createOpenGLGraphicsContext (OpenGLContext& context, unsigned int frameBufferID, int width, int height) { return OpenGLRendering::createOpenGLContext (OpenGLRendering::Target (context, frameBufferID, width, height)); } diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.h b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.h index 25b0187b45..f4317beb9d 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.h +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.h @@ -30,20 +30,20 @@ namespace juce /** Creates a graphics context object that will render into the given OpenGL target. The caller is responsible for deleting this object when no longer needed. */ -LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext&, int width, int height); +std::unique_ptr createOpenGLGraphicsContext (OpenGLContext&, int width, int height); /** Creates a graphics context object that will render into the given OpenGL framebuffer. The caller is responsible for deleting this object when no longer needed. */ -LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext&, OpenGLFrameBuffer&); +std::unique_ptr createOpenGLGraphicsContext (OpenGLContext&, OpenGLFrameBuffer&); /** Creates a graphics context object that will render into the given OpenGL framebuffer, with the given size. The caller is responsible for deleting this object when no longer needed. */ -LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext&, - unsigned int frameBufferID, - int width, int height); +std::unique_ptr createOpenGLGraphicsContext (OpenGLContext&, + unsigned int frameBufferID, + int width, int height); //============================================================================== diff --git a/modules/juce_opengl/opengl/juce_OpenGLImage.cpp b/modules/juce_opengl/opengl/juce_OpenGLImage.cpp index 36e21092ba..f8220e7619 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLImage.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLImage.cpp @@ -43,13 +43,13 @@ public: return frameBuffer.initialise (context, width, height); } - LowLevelGraphicsContext* createLowLevelContext() override + std::unique_ptr createLowLevelContext() override { sendDataChangeMessage(); return createOpenGLGraphicsContext (context, frameBuffer); } - ImageType* createType() const override { return new OpenGLImageType(); } + std::unique_ptr createType() const override { return std::make_unique(); } ImagePixelData::Ptr clone() override {