From 9d56e2990d54ef320df26422255a01d19a50e9d2 Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 3 Nov 2017 13:51:37 +0000 Subject: [PATCH] Optimised the GL renderer to avoid splitting large rectangles into horizontal strips unnecessarily --- .../juce_graphics/geometry/juce_EdgeTable.cpp | 4 +- .../juce_graphics/geometry/juce_EdgeTable.h | 4 +- .../native/juce_RenderingHelpers.h | 542 ++++++++++-------- .../opengl/juce_OpenGLGraphicsContext.cpp | 254 ++++---- .../opengl/juce_OpenGLGraphicsContext.h | 2 +- .../juce_opengl/opengl/juce_OpenGLHelpers.cpp | 2 +- .../juce_opengl/opengl/juce_OpenGLHelpers.h | 2 +- 7 files changed, 450 insertions(+), 360 deletions(-) diff --git a/modules/juce_graphics/geometry/juce_EdgeTable.cpp b/modules/juce_graphics/geometry/juce_EdgeTable.cpp index 43caa9ece6..723a20ec4e 100644 --- a/modules/juce_graphics/geometry/juce_EdgeTable.cpp +++ b/modules/juce_graphics/geometry/juce_EdgeTable.cpp @@ -679,7 +679,7 @@ void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) //============================================================================== -void EdgeTable::clipToRectangle (const Rectangle& r) +void EdgeTable::clipToRectangle (Rectangle r) { auto clipped = r.getIntersection (bounds); @@ -718,7 +718,7 @@ void EdgeTable::clipToRectangle (const Rectangle& r) } } -void EdgeTable::excludeRectangle (const Rectangle& r) +void EdgeTable::excludeRectangle (Rectangle r) { auto clipped = r.getIntersection (bounds); diff --git a/modules/juce_graphics/geometry/juce_EdgeTable.h b/modules/juce_graphics/geometry/juce_EdgeTable.h index e72ee6e07d..50161fab50 100644 --- a/modules/juce_graphics/geometry/juce_EdgeTable.h +++ b/modules/juce_graphics/geometry/juce_EdgeTable.h @@ -72,8 +72,8 @@ public: ~EdgeTable(); //============================================================================== - void clipToRectangle (const Rectangle& r); - void excludeRectangle (const Rectangle& r); + void clipToRectangle (Rectangle r); + void excludeRectangle (Rectangle r); void clipToEdgeTable (const EdgeTable&); void clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels); bool isEmpty() noexcept; diff --git a/modules/juce_graphics/native/juce_RenderingHelpers.h b/modules/juce_graphics/native/juce_RenderingHelpers.h index 987fba713a..605ab925db 100644 --- a/modules/juce_graphics/native/juce_RenderingHelpers.h +++ b/modules/juce_graphics/native/juce_RenderingHelpers.h @@ -106,27 +106,27 @@ public: complexTransform = complexTransform.translated (delta); } - Rectangle translated (const Rectangle& r) const noexcept + Rectangle translated (Rectangle r) const noexcept { jassert (isOnlyTranslated); return r + offset; } - Rectangle translated (const Rectangle& r) const noexcept + Rectangle translated (Rectangle r) const noexcept { jassert (isOnlyTranslated); return r + offset.toFloat(); } template - RectangleOrPoint transformed (const RectangleOrPoint& r) const noexcept + RectangleOrPoint transformed (RectangleOrPoint r) const noexcept { jassert (! isOnlyTranslated); return r.transformedBy (complexTransform); } template - Rectangle deviceSpaceToUserSpace (const Rectangle& r) const noexcept + Rectangle deviceSpaceToUserSpace (Rectangle r) const noexcept { return isOnlyTranslated ? r - offset : r.transformedBy (complexTransform.inverted()); @@ -317,7 +317,7 @@ public: */ struct FloatRectangleRasterisingInfo { - FloatRectangleRasterisingInfo (const Rectangle& area) + FloatRectangleRasterisingInfo (Rectangle area) : left (roundToInt (256.0f * area.getX())), top (roundToInt (256.0f * area.getY())), right (roundToInt (256.0f * area.getRight())), @@ -575,10 +575,9 @@ namespace EdgeTableFillers { /** Fills an edge-table with a solid colour. */ template - class SolidColour + struct SolidColour { - public: - SolidColour (const Image::BitmapData& image, const PixelARGB colour) + SolidColour (const Image::BitmapData& image, PixelARGB colour) : destData (image), sourceColour (colour) { if (sizeof (PixelType) == 3 && destData.pixelStride == sizeof (PixelType)) @@ -596,12 +595,12 @@ namespace EdgeTableFillers } } - forcedinline void setEdgeTableYPos (const int y) noexcept + forcedinline void setEdgeTableYPos (int y) noexcept { linePixels = (PixelType*) destData.getLinePointer (y); } - forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const noexcept + forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const noexcept { if (replaceExisting) getPixel (x)->set (sourceColour); @@ -609,7 +608,7 @@ namespace EdgeTableFillers getPixel (x)->blend (sourceColour, (uint32) alphaLevel); } - forcedinline void handleEdgeTablePixelFull (const int x) const noexcept + forcedinline void handleEdgeTablePixelFull (int x) const noexcept { if (replaceExisting) getPixel (x)->set (sourceColour); @@ -617,12 +616,12 @@ namespace EdgeTableFillers getPixel (x)->blend (sourceColour); } - forcedinline void handleEdgeTableLine (const int x, const int width, const int alphaLevel) const noexcept + forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const noexcept { - PixelARGB p (sourceColour); + auto p = sourceColour; p.multiplyAlpha (alphaLevel); - PixelType* dest = getPixel (x); + auto* dest = getPixel (x); if (replaceExisting || p.getAlpha() >= 0xff) replaceLine (dest, p, width); @@ -632,7 +631,7 @@ namespace EdgeTableFillers forcedinline void handleEdgeTableLineFull (const int x, const int width) const noexcept { - PixelType* dest = getPixel (x); + auto* dest = getPixel (x); if (replaceExisting || sourceColour.getAlpha() >= 0xff) replaceLine (dest, sourceColour, width); @@ -640,6 +639,37 @@ namespace EdgeTableFillers blendLine (dest, sourceColour, width); } + void handleEdgeTableRectangle (int x, int y, int width, int height, int alphaLevel) noexcept + { + auto p = sourceColour; + p.multiplyAlpha (alphaLevel); + + setEdgeTableYPos (y); + auto* dest = getPixel (x); + + if (replaceExisting || p.getAlpha() >= 0xff) + { + while (--height >= 0) + { + replaceLine (dest, p, width); + dest = addBytesToPointer (dest, destData.lineStride); + } + } + else + { + while (--height >= 0) + { + blendLine (dest, p, width); + dest = addBytesToPointer (dest, destData.lineStride); + } + } + } + + void handleEdgeTableRectangleFull (int x, int y, int width, int height) noexcept + { + handleEdgeTableRectangle (x, y, width, height, 255); + } + private: const Image::BitmapData& destData; PixelType* linePixels; @@ -652,12 +682,12 @@ namespace EdgeTableFillers return addBytesToPointer (linePixels, x * destData.pixelStride); } - inline void blendLine (PixelType* dest, const PixelARGB colour, int width) const noexcept + inline void blendLine (PixelType* dest, PixelARGB colour, int width) const noexcept { JUCE_PERFORM_PIXEL_OP_LOOP (blend (colour)) } - forcedinline void replaceLine (PixelRGB* dest, const PixelARGB colour, int width) const noexcept + forcedinline void replaceLine (PixelRGB* dest, PixelARGB colour, int width) const noexcept { if (destData.pixelStride == sizeof (*dest)) { @@ -721,35 +751,34 @@ namespace EdgeTableFillers //============================================================================== /** Fills an edge-table with a gradient. */ template - class Gradient : public GradientType + struct Gradient : public GradientType { - public: Gradient (const Image::BitmapData& dest, const ColourGradient& gradient, const AffineTransform& transform, - const PixelARGB* const colours, const int numColours) + const PixelARGB* colours, int numColours) : GradientType (gradient, transform, colours, numColours - 1), destData (dest) { } - forcedinline void setEdgeTableYPos (const int y) noexcept + forcedinline void setEdgeTableYPos (int y) noexcept { linePixels = (PixelType*) destData.getLinePointer (y); GradientType::setY (y); } - forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const noexcept + forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const noexcept { getPixel (x)->blend (GradientType::getPixel (x), (uint32) alphaLevel); } - forcedinline void handleEdgeTablePixelFull (const int x) const noexcept + forcedinline void handleEdgeTablePixelFull (int x) const noexcept { getPixel (x)->blend (GradientType::getPixel (x)); } - void handleEdgeTableLine (int x, int width, const int alphaLevel) const noexcept + void handleEdgeTableLine (int x, int width, int alphaLevel) const noexcept { - PixelType* dest = getPixel (x); + auto* dest = getPixel (x); if (alphaLevel < 0xff) JUCE_PERFORM_PIXEL_OP_LOOP (blend (GradientType::getPixel (x++), (uint32) alphaLevel)) @@ -759,15 +788,33 @@ namespace EdgeTableFillers void handleEdgeTableLineFull (int x, int width) const noexcept { - PixelType* dest = getPixel (x); + auto* dest = getPixel (x); JUCE_PERFORM_PIXEL_OP_LOOP (blend (GradientType::getPixel (x++))) } + void handleEdgeTableRectangle (int x, int y, int width, int height, int alphaLevel) noexcept + { + while (--height >= 0) + { + setEdgeTableYPos (y++); + handleEdgeTableLine (x, width, alphaLevel); + } + } + + void handleEdgeTableRectangleFull (int x, int y, int width, int height) noexcept + { + while (--height >= 0) + { + setEdgeTableYPos (y++); + handleEdgeTableLineFull (x, width); + } + } + private: const Image::BitmapData& destData; PixelType* linePixels; - forcedinline PixelType* getPixel (const int x) const noexcept + forcedinline PixelType* getPixel (int x) const noexcept { return addBytesToPointer (linePixels, x * destData.pixelStride); } @@ -778,11 +825,9 @@ namespace EdgeTableFillers //============================================================================== /** Fills an edge-table with a non-transformed image. */ template - class ImageFill + struct ImageFill { - public: - ImageFill (const Image::BitmapData& dest, const Image::BitmapData& src, - const int alpha, const int x, const int y) + ImageFill (const Image::BitmapData& dest, const Image::BitmapData& src, int alpha, int x, int y) : destData (dest), srcData (src), extraAlpha (alpha + 1), @@ -794,8 +839,8 @@ namespace EdgeTableFillers forcedinline void setEdgeTableYPos (int y) noexcept { linePixels = (DestPixelType*) destData.getLinePointer (y); - y -= yOffset; + if (repeatPattern) { jassert (y >= 0); @@ -805,21 +850,21 @@ namespace EdgeTableFillers sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y); } - forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) const noexcept + forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const noexcept { alphaLevel = (alphaLevel * extraAlpha) >> 8; getDestPixel (x)->blend (*getSrcPixel (repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)), (uint32) alphaLevel); } - forcedinline void handleEdgeTablePixelFull (const int x) const noexcept + forcedinline void handleEdgeTablePixelFull (int x) const noexcept { getDestPixel (x)->blend (*getSrcPixel (repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)), (uint32) extraAlpha); } void handleEdgeTableLine (int x, int width, int alphaLevel) const noexcept { - DestPixelType* dest = getDestPixel (x); + auto* dest = getDestPixel (x); alphaLevel = (alphaLevel * extraAlpha) >> 8; x -= xOffset; @@ -843,7 +888,7 @@ namespace EdgeTableFillers void handleEdgeTableLineFull (int x, int width) const noexcept { - DestPixelType* dest = getDestPixel (x); + auto* dest = getDestPixel (x); x -= xOffset; if (repeatPattern) @@ -864,11 +909,29 @@ namespace EdgeTableFillers } } + void handleEdgeTableRectangle (int x, int y, int width, int height, int alphaLevel) noexcept + { + while (--height >= 0) + { + setEdgeTableYPos (y++); + handleEdgeTableLine (x, width, alphaLevel); + } + } + + void handleEdgeTableRectangleFull (int x, int y, int width, int height) noexcept + { + while (--height >= 0) + { + setEdgeTableYPos (y++); + handleEdgeTableLineFull (x, width); + } + } + void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) { jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width); - SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset); - uint8* mask = (uint8*) (s + x - xOffset); + auto* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset); + auto* mask = (uint8*) (s + x - xOffset); if (sizeof (SrcPixelType) == sizeof (PixelARGB)) mask += PixelARGB::indexA; @@ -895,8 +958,8 @@ namespace EdgeTableFillers forcedinline void copyRow (DestPixelType* dest, SrcPixelType const* src, int width) const noexcept { - const int destStride = destData.pixelStride; - const int srcStride = srcData.pixelStride; + auto destStride = destData.pixelStride; + auto srcStride = srcData.pixelStride; if (destStride == srcStride && srcData.pixelFormat == Image::RGB @@ -921,11 +984,10 @@ namespace EdgeTableFillers //============================================================================== /** Fills an edge-table with a transformed image. */ template - class TransformedImageFill + struct TransformedImageFill { - public: TransformedImageFill (const Image::BitmapData& dest, const Image::BitmapData& src, - const AffineTransform& transform, const int alpha, const Graphics::ResamplingQuality q) + const AffineTransform& transform, int alpha, Graphics::ResamplingQuality q) : interpolator (transform, q != Graphics::lowResamplingQuality ? 0.5f : 0.0f, q != Graphics::lowResamplingQuality ? -128 : 0), @@ -934,19 +996,18 @@ namespace EdgeTableFillers extraAlpha (alpha + 1), quality (q), maxX (src.width - 1), - maxY (src.height - 1), - scratchSize (2048) + maxY (src.height - 1) { scratchBuffer.malloc (scratchSize); } - forcedinline void setEdgeTableYPos (const int newY) noexcept + forcedinline void setEdgeTableYPos (int newY) noexcept { - y = newY; + currentY = newY; linePixels = (DestPixelType*) destData.getLinePointer (newY); } - forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) noexcept + forcedinline void handleEdgeTablePixel (int x, int alphaLevel) noexcept { SrcPixelType p; generate (&p, x, 1); @@ -954,7 +1015,7 @@ namespace EdgeTableFillers getDestPixel (x)->blend (p, (uint32) (alphaLevel * extraAlpha) >> 8); } - forcedinline void handleEdgeTablePixelFull (const int x) noexcept + forcedinline void handleEdgeTablePixelFull (int x) noexcept { SrcPixelType p; generate (&p, x, 1); @@ -962,7 +1023,7 @@ namespace EdgeTableFillers getDestPixel (x)->blend (p, (uint32) extraAlpha); } - void handleEdgeTableLine (const int x, int width, int alphaLevel) noexcept + void handleEdgeTableLine (int x, int width, int alphaLevel) noexcept { if (width > (int) scratchSize) { @@ -973,7 +1034,7 @@ namespace EdgeTableFillers SrcPixelType* span = scratchBuffer; generate (span, x, width); - DestPixelType* dest = getDestPixel (x); + auto* dest = getDestPixel (x); alphaLevel *= extraAlpha; alphaLevel >>= 8; @@ -983,12 +1044,30 @@ namespace EdgeTableFillers JUCE_PERFORM_PIXEL_OP_LOOP (blend (*span++)) } - forcedinline void handleEdgeTableLineFull (const int x, int width) noexcept + forcedinline void handleEdgeTableLineFull (int x, int width) noexcept { handleEdgeTableLine (x, width, 255); } - void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) + void handleEdgeTableRectangle (int x, int y, int width, int height, int alphaLevel) noexcept + { + while (--height >= 0) + { + setEdgeTableYPos (y++); + handleEdgeTableLine (x, width, alphaLevel); + } + } + + void handleEdgeTableRectangleFull (int x, int y, int width, int height) noexcept + { + while (--height >= 0) + { + setEdgeTableYPos (y++); + handleEdgeTableLineFull (x, width); + } + } + + void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) { if (width > (int) scratchSize) { @@ -996,25 +1075,25 @@ namespace EdgeTableFillers scratchBuffer.malloc (scratchSize); } - y = y_; + currentY = y; generate (scratchBuffer.get(), x, width); - et.clipLineToMask (x, y_, + et.clipLineToMask (x, y, reinterpret_cast (scratchBuffer.get()) + SrcPixelType::indexA, sizeof (SrcPixelType), width); } private: - forcedinline DestPixelType* getDestPixel (const int x) const noexcept + forcedinline DestPixelType* getDestPixel (int x) const noexcept { return addBytesToPointer (linePixels, x * destData.pixelStride); } //============================================================================== template - void generate (PixelType* dest, const int x, int numPixels) noexcept + void generate (PixelType* dest, int x, int numPixels) noexcept { - this->interpolator.setStartOfLine ((float) x, (float) y, numPixels); + this->interpolator.setStartOfLine ((float) x, (float) currentY, numPixels); do { @@ -1086,11 +1165,11 @@ namespace EdgeTableFillers } //============================================================================== - void render4PixelAverage (PixelARGB* const dest, const uint8* src, const int subPixelX, const int subPixelY) noexcept + void render4PixelAverage (PixelARGB* dest, const uint8* src, int subPixelX, int subPixelY) noexcept { uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 }; - uint32 weight = (uint32) ((256 - subPixelX) * (256 - subPixelY)); + auto weight = (uint32) ((256 - subPixelX) * (256 - subPixelY)); c[0] += weight * src[0]; c[1] += weight * src[1]; c[2] += weight * src[2]; @@ -1126,7 +1205,7 @@ namespace EdgeTableFillers (uint8) (c[PixelARGB::indexB] >> 16)); } - void render2PixelAverageX (PixelARGB* const dest, const uint8* src, const uint32 subPixelX) noexcept + void render2PixelAverageX (PixelARGB* dest, const uint8* src, uint32 subPixelX) noexcept { uint32 c[4] = { 128, 128, 128, 128 }; @@ -1150,7 +1229,7 @@ namespace EdgeTableFillers (uint8) (c[PixelARGB::indexB] >> 8)); } - void render2PixelAverageY (PixelARGB* const dest, const uint8* src, const uint32 subPixelY) noexcept + void render2PixelAverageY (PixelARGB* dest, const uint8* src, uint32 subPixelY) noexcept { uint32 c[4] = { 128, 128, 128, 128 }; @@ -1175,7 +1254,7 @@ namespace EdgeTableFillers } //============================================================================== - void render4PixelAverage (PixelRGB* const dest, const uint8* src, const uint32 subPixelX, const uint32 subPixelY) noexcept + void render4PixelAverage (PixelRGB* dest, const uint8* src, uint32 subPixelX, uint32 subPixelY) noexcept { uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 }; @@ -1211,7 +1290,7 @@ namespace EdgeTableFillers (uint8) (c[PixelRGB::indexB] >> 16)); } - void render2PixelAverageX (PixelRGB* const dest, const uint8* src, const uint32 subPixelX) noexcept + void render2PixelAverageX (PixelRGB* dest, const uint8* src, uint32 subPixelX) noexcept { uint32 c[3] = { 128, 128, 128 }; @@ -1232,7 +1311,7 @@ namespace EdgeTableFillers (uint8) (c[PixelRGB::indexB] >> 8)); } - void render2PixelAverageY (PixelRGB* const dest, const uint8* src, const uint32 subPixelY) noexcept + void render2PixelAverageY (PixelRGB* dest, const uint8* src, uint32 subPixelY) noexcept { uint32 c[3] = { 128, 128, 128 }; @@ -1254,7 +1333,7 @@ namespace EdgeTableFillers } //============================================================================== - void render4PixelAverage (PixelAlpha* const dest, const uint8* src, const uint32 subPixelX, const uint32 subPixelY) noexcept + void render4PixelAverage (PixelAlpha* dest, const uint8* src, uint32 subPixelX, uint32 subPixelY) noexcept { uint32 c = 256 * 128; c += src[0] * ((256 - subPixelX) * (256 - subPixelY)); @@ -1269,7 +1348,7 @@ namespace EdgeTableFillers *((uint8*) dest) = (uint8) (c >> 16); } - void render2PixelAverageX (PixelAlpha* const dest, const uint8* src, const uint32 subPixelX) noexcept + void render2PixelAverageX (PixelAlpha* dest, const uint8* src, uint32 subPixelX) noexcept { uint32 c = 128; c += src[0] * (256 - subPixelX); @@ -1278,7 +1357,7 @@ namespace EdgeTableFillers *((uint8*) dest) = (uint8) (c >> 8); } - void render2PixelAverageY (PixelAlpha* const dest, const uint8* src, const uint32 subPixelY) noexcept + void render2PixelAverageY (PixelAlpha* dest, const uint8* src, uint32 subPixelY) noexcept { uint32 c = 128; c += src[0] * (256 - subPixelY); @@ -1288,22 +1367,20 @@ namespace EdgeTableFillers } //============================================================================== - class TransformedImageSpanInterpolator + struct TransformedImageSpanInterpolator { - public: - TransformedImageSpanInterpolator (const AffineTransform& transform, - const float offsetFloat, const int offsetInt) noexcept + TransformedImageSpanInterpolator (const AffineTransform& transform, float offsetFloat, int offsetInt) noexcept : inverseTransform (transform.inverted()), pixelOffset (offsetFloat), pixelOffsetInt (offsetInt) {} - void setStartOfLine (float sx, float sy, const int numPixels) noexcept + void setStartOfLine (float sx, float sy, int numPixels) noexcept { jassert (numPixels > 0); sx += pixelOffset; sy += pixelOffset; - float x1 = sx, y1 = sy; + auto x1 = sx, y1 = sy; sx += (float) numPixels; inverseTransform.transformPoints (x1, y1, sx, sy); @@ -1318,12 +1395,11 @@ namespace EdgeTableFillers } private: - class BresenhamInterpolator + struct BresenhamInterpolator { - public: BresenhamInterpolator() noexcept {} - void set (const int n1, const int n2, const int steps, const int offsetInt) noexcept + void set (int n1, int n2, int steps, int offsetInt) noexcept { numSteps = steps; step = (n2 - n1) / numSteps; @@ -1373,10 +1449,10 @@ namespace EdgeTableFillers const int extraAlpha; const Graphics::ResamplingQuality quality; const int maxX, maxY; - int y; + int currentY; DestPixelType* linePixels; HeapBlock scratchBuffer; - size_t scratchSize; + size_t scratchSize = 2048; JUCE_DECLARE_NON_COPYABLE (TransformedImageFill) }; @@ -1385,7 +1461,7 @@ namespace EdgeTableFillers //============================================================================== template void renderImageTransformed (Iterator& iter, const Image::BitmapData& destData, const Image::BitmapData& srcData, - const int alpha, const AffineTransform& transform, Graphics::ResamplingQuality quality, bool tiledFill) + int alpha, const AffineTransform& transform, Graphics::ResamplingQuality quality, bool tiledFill) { switch (destData.pixelFormat) { @@ -1446,7 +1522,7 @@ namespace EdgeTableFillers } template - void renderImageUntransformed (Iterator& iter, const Image::BitmapData& destData, const Image::BitmapData& srcData, const int alpha, int x, int y, bool tiledFill) + void renderImageUntransformed (Iterator& iter, const Image::BitmapData& destData, const Image::BitmapData& srcData, int alpha, int x, int y, bool tiledFill) { switch (destData.pixelFormat) { @@ -1507,7 +1583,7 @@ namespace EdgeTableFillers } template - void renderSolidFill (Iterator& iter, const Image::BitmapData& destData, const PixelARGB fillColour, const bool replaceContents, DestPixelType*) + void renderSolidFill (Iterator& iter, const Image::BitmapData& destData, PixelARGB fillColour, bool replaceContents, DestPixelType*) { if (replaceContents) { @@ -1523,7 +1599,7 @@ namespace EdgeTableFillers template void renderGradient (Iterator& iter, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform, - const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) + const PixelARGB* lookupTable, int numLookupEntries, bool isIdentity, DestPixelType*) { if (g.isRadial) { @@ -1550,9 +1626,8 @@ namespace EdgeTableFillers template struct ClipRegions { - class Base : public SingleThreadedReferenceCountedObject + struct Base : public SingleThreadedReferenceCountedObject { - public: Base() {} virtual ~Base() {} @@ -1561,49 +1636,48 @@ struct ClipRegions virtual Ptr clone() const = 0; virtual Ptr applyClipTo (const Ptr& target) const = 0; - virtual Ptr clipToRectangle (const Rectangle&) = 0; + virtual Ptr clipToRectangle (Rectangle) = 0; virtual Ptr clipToRectangleList (const RectangleList&) = 0; - virtual Ptr excludeClipRectangle (const Rectangle&) = 0; + virtual Ptr excludeClipRectangle (Rectangle) = 0; virtual Ptr clipToPath (const Path&, const AffineTransform&) = 0; virtual Ptr clipToEdgeTable (const EdgeTable& et) = 0; virtual Ptr clipToImageAlpha (const Image&, const AffineTransform&, const Graphics::ResamplingQuality) = 0; virtual void translate (Point delta) = 0; - virtual bool clipRegionIntersects (const Rectangle&) const = 0; + virtual bool clipRegionIntersects (Rectangle) const = 0; virtual Rectangle getClipBounds() const = 0; - virtual void fillRectWithColour (SavedStateType&, const Rectangle&, const PixelARGB colour, bool replaceContents) const = 0; - virtual void fillRectWithColour (SavedStateType&, const Rectangle&, const PixelARGB colour) const = 0; - virtual void fillAllWithColour (SavedStateType&, const PixelARGB colour, bool replaceContents) const = 0; + virtual void fillRectWithColour (SavedStateType&, Rectangle, PixelARGB colour, bool replaceContents) const = 0; + virtual void fillRectWithColour (SavedStateType&, Rectangle, PixelARGB colour) const = 0; + virtual void fillAllWithColour (SavedStateType&, PixelARGB colour, bool replaceContents) const = 0; virtual void fillAllWithGradient (SavedStateType&, ColourGradient&, const AffineTransform&, bool isIdentity) const = 0; - virtual void renderImageTransformed (SavedStateType&, const Image&, const int alpha, const AffineTransform&, Graphics::ResamplingQuality, bool tiledFill) const = 0; - virtual void renderImageUntransformed (SavedStateType&, const Image&, const int alpha, int x, int y, bool tiledFill) const = 0; + virtual void renderImageTransformed (SavedStateType&, const Image&, int alpha, const AffineTransform&, Graphics::ResamplingQuality, bool tiledFill) const = 0; + virtual void renderImageUntransformed (SavedStateType&, const Image&, int alpha, int x, int y, bool tiledFill) const = 0; }; //============================================================================== - class EdgeTableRegion : public Base + struct EdgeTableRegion : public Base { - public: EdgeTableRegion (const EdgeTable& e) : edgeTable (e) {} - EdgeTableRegion (const Rectangle& r) : edgeTable (r) {} - EdgeTableRegion (const Rectangle& r) : edgeTable (r) {} + EdgeTableRegion (Rectangle r) : edgeTable (r) {} + EdgeTableRegion (Rectangle r) : edgeTable (r) {} EdgeTableRegion (const RectangleList& r) : edgeTable (r) {} EdgeTableRegion (const RectangleList& r) : edgeTable (r) {} - EdgeTableRegion (const Rectangle& bounds, const Path& p, const AffineTransform& t) : edgeTable (bounds, p, t) {} + EdgeTableRegion (Rectangle bounds, const Path& p, const AffineTransform& t) : edgeTable (bounds, p, t) {} EdgeTableRegion (const EdgeTableRegion& other) : Base(), edgeTable (other.edgeTable) {} typedef typename Base::Ptr Ptr; - Ptr clone() const { return new EdgeTableRegion (*this); } - Ptr applyClipTo (const Ptr& target) const { return target->clipToEdgeTable (edgeTable); } + Ptr clone() const override { return new EdgeTableRegion (*this); } + Ptr applyClipTo (const Ptr& target) const override { return target->clipToEdgeTable (edgeTable); } - Ptr clipToRectangle (const Rectangle& r) + Ptr clipToRectangle (Rectangle r) override { edgeTable.clipToRectangle (r); return edgeTable.isEmpty() ? nullptr : this; } - Ptr clipToRectangleList (const RectangleList& r) + Ptr clipToRectangleList (const RectangleList& r) override { RectangleList inverse (edgeTable.getMaximumBounds()); @@ -1614,39 +1688,39 @@ struct ClipRegions return edgeTable.isEmpty() ? nullptr : this; } - Ptr excludeClipRectangle (const Rectangle& r) + Ptr excludeClipRectangle (Rectangle r) override { edgeTable.excludeRectangle (r); return edgeTable.isEmpty() ? nullptr : this; } - Ptr clipToPath (const Path& p, const AffineTransform& transform) + Ptr clipToPath (const Path& p, const AffineTransform& transform) override { EdgeTable et (edgeTable.getMaximumBounds(), p, transform); edgeTable.clipToEdgeTable (et); return edgeTable.isEmpty() ? nullptr : this; } - Ptr clipToEdgeTable (const EdgeTable& et) + Ptr clipToEdgeTable (const EdgeTable& et) override { edgeTable.clipToEdgeTable (et); return edgeTable.isEmpty() ? nullptr : this; } - Ptr clipToImageAlpha (const Image& image, const AffineTransform& transform, const Graphics::ResamplingQuality quality) + Ptr clipToImageAlpha (const Image& image, const AffineTransform& transform, Graphics::ResamplingQuality quality) override { const Image::BitmapData srcData (image, Image::BitmapData::readOnly); if (transform.isOnlyTranslation()) { // If our translation doesn't involve any distortion, just use a simple blit.. - const int tx = (int) (transform.getTranslationX() * 256.0f); - const int ty = (int) (transform.getTranslationY() * 256.0f); + auto tx = (int) (transform.getTranslationX() * 256.0f); + auto ty = (int) (transform.getTranslationY() * 256.0f); if (quality == Graphics::lowResamplingQuality || ((tx | ty) & 224) == 0) { - const int imageX = ((tx + 128) >> 8); - const int imageY = ((ty + 128) >> 8); + auto imageX = ((tx + 128) >> 8); + auto imageY = ((ty + 128) >> 8); if (image.getFormat() == Image::ARGB) straightClipImage (srcData, imageX, imageY, (PixelARGB*) 0); @@ -1678,25 +1752,25 @@ struct ClipRegions return edgeTable.isEmpty() ? nullptr : this; } - void translate (Point delta) + void translate (Point delta) override { edgeTable.translate ((float) delta.x, delta.y); } - bool clipRegionIntersects (const Rectangle& r) const + bool clipRegionIntersects (Rectangle r) const override { return edgeTable.getMaximumBounds().intersects (r); } - Rectangle getClipBounds() const + Rectangle getClipBounds() const override { return edgeTable.getMaximumBounds(); } - void fillRectWithColour (SavedStateType& state, const Rectangle& area, const PixelARGB colour, bool replaceContents) const + void fillRectWithColour (SavedStateType& state, Rectangle area, PixelARGB colour, bool replaceContents) const override { - const Rectangle totalClip (edgeTable.getMaximumBounds()); - const Rectangle clipped (totalClip.getIntersection (area)); + auto totalClip = edgeTable.getMaximumBounds(); + auto clipped = totalClip.getIntersection (area); if (! clipped.isEmpty()) { @@ -1706,10 +1780,10 @@ struct ClipRegions } } - void fillRectWithColour (SavedStateType& state, const Rectangle& area, const PixelARGB colour) const + void fillRectWithColour (SavedStateType& state, Rectangle area, PixelARGB colour) const override { - const Rectangle totalClip (edgeTable.getMaximumBounds().toFloat()); - const Rectangle clipped (totalClip.getIntersection (area)); + auto totalClip = edgeTable.getMaximumBounds().toFloat(); + auto clipped = totalClip.getIntersection (area); if (! clipped.isEmpty()) { @@ -1719,22 +1793,22 @@ struct ClipRegions } } - void fillAllWithColour (SavedStateType& state, const PixelARGB colour, bool replaceContents) const + void fillAllWithColour (SavedStateType& state, PixelARGB colour, bool replaceContents) const override { state.fillWithSolidColour (edgeTable, colour, replaceContents); } - void fillAllWithGradient (SavedStateType& state, ColourGradient& gradient, const AffineTransform& transform, bool isIdentity) const + void fillAllWithGradient (SavedStateType& state, ColourGradient& gradient, const AffineTransform& transform, bool isIdentity) const override { state.fillWithGradient (edgeTable, gradient, transform, isIdentity); } - void renderImageTransformed (SavedStateType& state, const Image& src, const int alpha, const AffineTransform& transform, Graphics::ResamplingQuality quality, bool tiledFill) const + void renderImageTransformed (SavedStateType& state, const Image& src, int alpha, const AffineTransform& transform, Graphics::ResamplingQuality quality, bool tiledFill) const override { state.renderImageTransformed (edgeTable, src, alpha, transform, quality, tiledFill); } - void renderImageUntransformed (SavedStateType& state, const Image& src, const int alpha, int x, int y, bool tiledFill) const + void renderImageUntransformed (SavedStateType& state, const Image& src, int alpha, int x, int y, bool tiledFill) const override { state.renderImageUntransformed (edgeTable, src, alpha, x, y, tiledFill); } @@ -1743,7 +1817,7 @@ struct ClipRegions private: template - void transformedClipImage (const Image::BitmapData& srcData, const AffineTransform& transform, const Graphics::ResamplingQuality quality, const SrcPixelType*) + void transformedClipImage (const Image::BitmapData& srcData, const AffineTransform& transform, Graphics::ResamplingQuality quality, const SrcPixelType*) { EdgeTableFillers::TransformedImageFill renderer (srcData, srcData, transform, 255, quality); @@ -1771,73 +1845,73 @@ struct ClipRegions class RectangleListRegion : public Base { public: - RectangleListRegion (const Rectangle& r) : clip (r) {} + RectangleListRegion (Rectangle r) : clip (r) {} RectangleListRegion (const RectangleList& r) : clip (r) {} RectangleListRegion (const RectangleListRegion& other) : Base(), clip (other.clip) {} typedef typename Base::Ptr Ptr; - Ptr clone() const { return new RectangleListRegion (*this); } - Ptr applyClipTo (const Ptr& target) const { return target->clipToRectangleList (clip); } + Ptr clone() const override { return new RectangleListRegion (*this); } + Ptr applyClipTo (const Ptr& target) const override { return target->clipToRectangleList (clip); } - Ptr clipToRectangle (const Rectangle& r) + Ptr clipToRectangle (Rectangle r) override { clip.clipTo (r); return clip.isEmpty() ? nullptr : this; } - Ptr clipToRectangleList (const RectangleList& r) + Ptr clipToRectangleList (const RectangleList& r) override { clip.clipTo (r); return clip.isEmpty() ? nullptr : this; } - Ptr excludeClipRectangle (const Rectangle& r) + Ptr excludeClipRectangle (Rectangle r) override { clip.subtract (r); return clip.isEmpty() ? nullptr : this; } - Ptr clipToPath (const Path& p, const AffineTransform& transform) { return toEdgeTable()->clipToPath (p, transform); } - Ptr clipToEdgeTable (const EdgeTable& et) { return toEdgeTable()->clipToEdgeTable (et); } + Ptr clipToPath (const Path& p, const AffineTransform& transform) override { return toEdgeTable()->clipToPath (p, transform); } + Ptr clipToEdgeTable (const EdgeTable& et) override { return toEdgeTable()->clipToEdgeTable (et); } - Ptr clipToImageAlpha (const Image& image, const AffineTransform& transform, const Graphics::ResamplingQuality quality) + Ptr clipToImageAlpha (const Image& image, const AffineTransform& transform, Graphics::ResamplingQuality quality) override { return toEdgeTable()->clipToImageAlpha (image, transform, quality); } - void translate (Point delta) { clip.offsetAll (delta); } - bool clipRegionIntersects (const Rectangle& r) const { return clip.intersects (r); } - Rectangle getClipBounds() const { return clip.getBounds(); } + void translate (Point delta) override { clip.offsetAll (delta); } + bool clipRegionIntersects (Rectangle r) const override { return clip.intersects (r); } + Rectangle getClipBounds() const override { return clip.getBounds(); } - void fillRectWithColour (SavedStateType& state, const Rectangle& area, const PixelARGB colour, bool replaceContents) const + void fillRectWithColour (SavedStateType& state, Rectangle area, PixelARGB colour, bool replaceContents) const override { SubRectangleIterator iter (clip, area); state.fillWithSolidColour (iter, colour, replaceContents); } - void fillRectWithColour (SavedStateType& state, const Rectangle& area, const PixelARGB colour) const + void fillRectWithColour (SavedStateType& state, Rectangle area, PixelARGB colour) const override { SubRectangleIteratorFloat iter (clip, area); state.fillWithSolidColour (iter, colour, false); } - void fillAllWithColour (SavedStateType& state, const PixelARGB colour, bool replaceContents) const + void fillAllWithColour (SavedStateType& state, PixelARGB colour, bool replaceContents) const override { state.fillWithSolidColour (*this, colour, replaceContents); } - void fillAllWithGradient (SavedStateType& state, ColourGradient& gradient, const AffineTransform& transform, bool isIdentity) const + void fillAllWithGradient (SavedStateType& state, ColourGradient& gradient, const AffineTransform& transform, bool isIdentity) const override { state.fillWithGradient (*this, gradient, transform, isIdentity); } - void renderImageTransformed (SavedStateType& state, const Image& src, const int alpha, const AffineTransform& transform, Graphics::ResamplingQuality quality, bool tiledFill) const + void renderImageTransformed (SavedStateType& state, const Image& src, int alpha, const AffineTransform& transform, Graphics::ResamplingQuality quality, bool tiledFill) const override { state.renderImageTransformed (*this, src, alpha, transform, quality, tiledFill); } - void renderImageUntransformed (SavedStateType& state, const Image& src, const int alpha, int x, int y, bool tiledFill) const + void renderImageUntransformed (SavedStateType& state, const Image& src, int alpha, int x, int y, bool tiledFill) const override { state.renderImageUntransformed (*this, src, alpha, x, y, tiledFill); } @@ -1850,10 +1924,10 @@ struct ClipRegions { for (auto& i : clip) { - const int x = i.getX(); - const int w = i.getWidth(); + auto x = i.getX(); + auto w = i.getWidth(); jassert (w > 0); - const int bottom = i.getBottom(); + auto bottom = i.getBottom(); for (int y = i.getY(); y < bottom; ++y) { @@ -1868,7 +1942,7 @@ struct ClipRegions class SubRectangleIterator { public: - SubRectangleIterator (const RectangleList& clipList, const Rectangle& clipBounds) + SubRectangleIterator (const RectangleList& clipList, Rectangle clipBounds) : clip (clipList), area (clipBounds) {} @@ -1880,17 +1954,7 @@ struct ClipRegions auto rect = i.getIntersection (area); if (! rect.isEmpty()) - { - const int x = rect.getX(); - const int w = rect.getWidth(); - const int bottom = rect.getBottom(); - - for (int y = rect.getY(); y < bottom; ++y) - { - r.setEdgeTableYPos (y); - r.handleEdgeTableLineFull (x, w); - } - } + r.handleEdgeTableRectangleFull (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); } } @@ -1905,7 +1969,7 @@ struct ClipRegions class SubRectangleIteratorFloat { public: - SubRectangleIteratorFloat (const RectangleList& clipList, const Rectangle& clipBounds) noexcept + SubRectangleIteratorFloat (const RectangleList& clipList, Rectangle clipBounds) noexcept : clip (clipList), area (clipBounds) { } @@ -1917,10 +1981,10 @@ struct ClipRegions for (auto& i : clip) { - const int clipLeft = i.getX(); - const int clipRight = i.getRight(); - const int clipTop = i.getY(); - const int clipBottom = i.getBottom(); + auto clipLeft = i.getX(); + auto clipRight = i.getRight(); + auto clipTop = i.getY(); + auto clipBottom = i.getBottom(); if (f.totalBottom > clipTop && f.totalTop < clipBottom && f.totalRight > clipLeft && f.totalLeft < clipRight) @@ -1933,12 +1997,12 @@ struct ClipRegions r.handleEdgeTablePixel (f.left, f.topAlpha); } - const int endY = jmin (f.bottom, clipBottom); - for (int y = jmax (clipTop, f.top); y < endY; ++y) - { - r.setEdgeTableYPos (y); - r.handleEdgeTablePixelFull (f.left); - } + auto y1 = jmax (clipTop, f.top); + auto y2 = jmin (f.bottom, clipBottom); + auto h = y2 - y1; + + if (h > 0) + r.handleEdgeTableRectangleFull (f.left, y1, 1, h); if (f.bottomAlpha != 0 && f.bottom < clipBottom) { @@ -1948,10 +2012,10 @@ struct ClipRegions } else { - const int clippedLeft = jmax (f.left, clipLeft); - const int clippedWidth = jmin (f.right, clipRight) - clippedLeft; - const bool doLeftAlpha = f.leftAlpha != 0 && f.totalLeft >= clipLeft; - const bool doRightAlpha = f.rightAlpha != 0 && f.right < clipRight; + auto clippedLeft = jmax (f.left, clipLeft); + auto clippedWidth = jmin (f.right, clipRight) - clippedLeft; + bool doLeftAlpha = f.leftAlpha != 0 && f.totalLeft >= clipLeft; + bool doRightAlpha = f.rightAlpha != 0 && f.right < clipRight; if (f.topAlpha != 0 && f.totalTop >= clipTop) { @@ -1962,14 +2026,26 @@ struct ClipRegions if (doRightAlpha) r.handleEdgeTablePixel (f.right, f.getTopRightCornerAlpha()); } - const int endY = jmin (f.bottom, clipBottom); - for (int y = jmax (clipTop, f.top); y < endY; ++y) - { - r.setEdgeTableYPos (y); + auto y1 = jmax (clipTop, f.top); + auto y2 = jmin (f.bottom, clipBottom); + auto h = y2 - y1; - if (doLeftAlpha) r.handleEdgeTablePixel (f.totalLeft, f.leftAlpha); - if (clippedWidth > 0) r.handleEdgeTableLineFull (clippedLeft, clippedWidth); - if (doRightAlpha) r.handleEdgeTablePixel (f.right, f.rightAlpha); + if (h > 0) + { + if (h == 1) + { + r.setEdgeTableYPos (y1); + + if (doLeftAlpha) r.handleEdgeTablePixel (f.totalLeft, f.leftAlpha); + if (clippedWidth > 0) r.handleEdgeTableLineFull (clippedLeft, clippedWidth); + if (doRightAlpha) r.handleEdgeTablePixel (f.right, f.rightAlpha); + } + else + { + if (doLeftAlpha) r.handleEdgeTableRectangle (f.totalLeft, y1, 1, h, f.leftAlpha); + if (clippedWidth > 0) r.handleEdgeTableRectangleFull (clippedLeft, y1, clippedWidth, h); + if (doRightAlpha) r.handleEdgeTableRectangle (f.right, y1, 1, h, f.rightAlpha); + } } if (f.bottomAlpha != 0 && f.bottom < clipBottom) @@ -1987,7 +2063,7 @@ struct ClipRegions private: const RectangleList& clip; - const Rectangle& area; + Rectangle area; JUCE_DECLARE_NON_COPYABLE (SubRectangleIteratorFloat) }; @@ -2007,7 +2083,7 @@ public: typedef typename ClipRegions::EdgeTableRegion EdgeTableRegionType; typedef typename ClipRegions::RectangleListRegion RectangleListRegionType; - SavedStateBase (const Rectangle& initialClip) + SavedStateBase (Rectangle initialClip) : clip (new RectangleListRegionType (initialClip)), transform (Point()), interpolationQuality (Graphics::mediumResamplingQuality), transparencyLayerAlpha (1.0f) { @@ -2028,7 +2104,7 @@ public: SavedStateType& getThis() noexcept { return *static_cast (this); } - bool clipToRectangle (const Rectangle& r) + bool clipToRectangle (Rectangle r) { if (clip != nullptr) { @@ -2085,15 +2161,15 @@ public: static Rectangle getLargestIntegerWithin (Rectangle r) { - const int x1 = (int) std::ceil (r.getX()); - const int y1 = (int) std::ceil (r.getY()); - const int x2 = (int) std::floor (r.getRight()); - const int y2 = (int) std::floor (r.getBottom()); + auto x1 = (int) std::ceil (r.getX()); + auto y1 = (int) std::ceil (r.getY()); + auto x2 = (int) std::floor (r.getRight()); + auto y2 = (int) std::floor (r.getBottom()); - return Rectangle (x1, y1, x2 - x1, y2 - y1); + return { x1, y1, x2 - x1, y2 - y1 }; } - bool excludeClipRectangle (const Rectangle& r) + bool excludeClipRectangle (Rectangle r) { if (clip != nullptr) { @@ -2148,7 +2224,7 @@ public: } } - bool clipRegionIntersects (const Rectangle& r) const + bool clipRegionIntersects (Rectangle r) const { if (clip != nullptr) { @@ -2172,7 +2248,7 @@ public: fillType = newFill; } - void fillTargetRect (const Rectangle& r, const bool replaceContents) + void fillTargetRect (Rectangle r, bool replaceContents) { if (fillType.isColour()) { @@ -2180,14 +2256,14 @@ public: } else { - const Rectangle clipped (clip->getClipBounds().getIntersection (r)); + auto clipped = clip->getClipBounds().getIntersection (r); if (! clipped.isEmpty()) fillShape (new RectangleListRegionType (clipped), false); } } - void fillTargetRect (const Rectangle& r) + void fillTargetRect (Rectangle r) { if (fillType.isColour()) { @@ -2195,7 +2271,7 @@ public: } else { - const Rectangle clipped (clip->getClipBounds().toFloat().getIntersection (r)); + auto clipped = clip->getClipBounds().toFloat().getIntersection (r); if (! clipped.isEmpty()) fillShape (new EdgeTableRegionType (clipped), false); @@ -2203,14 +2279,14 @@ public: } template - void fillRectAsPath (const Rectangle& r) + void fillRectAsPath (Rectangle r) { Path p; p.addRectangle (r); fillPath (p, AffineTransform()); } - void fillRect (const Rectangle& r, const bool replaceContents) + void fillRect (Rectangle r, bool replaceContents) { if (clip != nullptr) { @@ -2230,7 +2306,7 @@ public: } } - void fillRect (const Rectangle& r) + void fillRect (Rectangle r) { if (clip != nullptr) { @@ -2247,6 +2323,9 @@ public: { if (clip != nullptr) { + if (list.getNumRectangles() == 1) + return fillRect (*list.begin()); + if (! transform.isRotated) { RectangleList transformed (list); @@ -2269,24 +2348,24 @@ public: { if (clip != nullptr) { - const AffineTransform trans (transform.getTransformWith (t)); - const Rectangle clipRect (clip->getClipBounds()); + auto trans = transform.getTransformWith (t); + auto clipRect = clip->getClipBounds(); if (path.getBoundsTransformed (trans).getSmallestIntegerContainer().intersects (clipRect)) fillShape (new EdgeTableRegionType (clipRect, path, trans), false); } } - void fillEdgeTable (const EdgeTable& edgeTable, const float x, const int y) + void fillEdgeTable (const EdgeTable& edgeTable, float x, int y) { if (clip != nullptr) { - EdgeTableRegionType* edgeTableClip = new EdgeTableRegionType (edgeTable); + auto* edgeTableClip = new EdgeTableRegionType (edgeTable); edgeTableClip->edgeTable.translate (x, y); if (fillType.isColour()) { - float brightness = fillType.colour.getBrightness() - 0.5f; + auto brightness = fillType.colour.getBrightness() - 0.5f; if (brightness > 0.0f) edgeTableClip->edgeTable.multiplyLevels (1.0f + 1.6f * brightness); @@ -2311,24 +2390,22 @@ public: static bool isOnlyTranslationAllowingError (const AffineTransform& t) { - return (std::abs (t.mat01) < 0.002) - && (std::abs (t.mat10) < 0.002) - && (std::abs (t.mat00 - 1.0f) < 0.002) - && (std::abs (t.mat11 - 1.0f) < 0.002); + return std::abs (t.mat01) < 0.002 + && std::abs (t.mat10) < 0.002 + && std::abs (t.mat00 - 1.0f) < 0.002 + && std::abs (t.mat11 - 1.0f) < 0.002; } - void renderImage (const Image& sourceImage, const AffineTransform& trans, - const BaseRegionType* const tiledFillClipRegion) + void renderImage (const Image& sourceImage, const AffineTransform& trans, const BaseRegionType* tiledFillClipRegion) { auto t = transform.getTransformWith (trans); - - const int alpha = fillType.colour.getAlpha(); + auto alpha = fillType.colour.getAlpha(); if (isOnlyTranslationAllowingError (t)) { // If our translation doesn't involve any distortion, just use a simple blit.. - int tx = (int) (t.getTranslationX() * 256.0f); - int ty = (int) (t.getTranslationY() * 256.0f); + auto tx = (int) (t.getTranslationX() * 256.0f); + auto ty = (int) (t.getTranslationY() * 256.0f); if (interpolationQuality == Graphics::lowResamplingQuality || ((tx | ty) & 224) == 0) { @@ -2345,7 +2422,7 @@ public: area = area.getIntersection (getThis().getMaximumBounds()); if (! area.isEmpty()) - if (typename BaseRegionType::Ptr c = clip->applyClipTo (new EdgeTableRegionType (area))) + if (auto c = clip->applyClipTo (new EdgeTableRegionType (area))) c->renderImageUntransformed (getThis(), sourceImage, alpha, tx, ty, false); } @@ -2372,10 +2449,9 @@ public: } } - void fillShape (typename BaseRegionType::Ptr shapeToFill, const bool replaceContents) + void fillShape (typename BaseRegionType::Ptr shapeToFill, bool replaceContents) { jassert (clip != nullptr); - shapeToFill = clip->applyClipTo (shapeToFill); if (shapeToFill != nullptr) @@ -2388,7 +2464,7 @@ public: g2.multiplyOpacity (fillType.getOpacity()); auto t = transform.getTransformWith (fillType.transform).translated (-0.5f, -0.5f); - const bool isIdentity = t.isOnlyTranslation(); + bool isIdentity = t.isOnlyTranslation(); if (isIdentity) { @@ -2430,7 +2506,7 @@ class SoftwareRendererSavedState : public SavedStateBase BaseClass; public: - SoftwareRendererSavedState (const Image& im, const Rectangle& clipBounds) + SoftwareRendererSavedState (const Image& im, Rectangle clipBounds) : BaseClass (clipBounds), image (im) { } @@ -2447,11 +2523,11 @@ public: SoftwareRendererSavedState* beginTransparencyLayer (float opacity) { - SoftwareRendererSavedState* s = new SoftwareRendererSavedState (*this); + auto* s = new SoftwareRendererSavedState (*this); if (clip != nullptr) { - const Rectangle layerBounds (clip->getClipBounds()); + auto layerBounds = clip->getClipBounds(); s->image = Image (Image::ARGB, layerBounds.getWidth(), layerBounds.getHeight(), true); s->transparencyLayerAlpha = opacity; @@ -2467,7 +2543,7 @@ public: { if (clip != nullptr) { - const Rectangle layerBounds (clip->getClipBounds()); + auto layerBounds = clip->getClipBounds(); const ScopedPointer g (image.createLowLevelContext()); g->setOpacity (finishedLayerState.transparencyLayerAlpha); @@ -2489,8 +2565,7 @@ public: { if (trans.isOnlyTranslation() && ! transform.isRotated) { - GlyphCacheType& cache = GlyphCacheType::getInstance(); - + auto& cache = GlyphCacheType::getInstance(); Point pos (trans.getTranslationX(), trans.getTranslationY()); if (transform.isOnlyTranslated) @@ -2504,7 +2579,8 @@ public: Font f (font); f.setHeight (font.getHeight() * transform.complexTransform.mat11); - const float xScale = transform.complexTransform.mat00 / transform.complexTransform.mat11; + auto xScale = transform.complexTransform.mat00 / transform.complexTransform.mat11; + if (std::abs (xScale - 1.0f) > 0.01f) f.setHorizontalScale (xScale); @@ -2513,14 +2589,12 @@ public: } else { - const float fontHeight = font.getHeight(); + auto fontHeight = font.getHeight(); - AffineTransform t (transform.getTransformWith (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight) - .followedBy (trans))); + auto t = transform.getTransformWith (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight) + .followedBy (trans)); - const ScopedPointer et (font.getTypeface()->getEdgeTableForGlyph (glyphNumber, t, fontHeight)); - - if (et != nullptr) + if (ScopedPointer et = font.getTypeface()->getEdgeTableForGlyph (glyphNumber, t, fontHeight)) fillShape (new EdgeTableRegionType (*et), false); } } @@ -2530,7 +2604,7 @@ public: //============================================================================== template - void renderImageTransformed (IteratorType& iter, const Image& src, const int alpha, const AffineTransform& trans, Graphics::ResamplingQuality quality, bool tiledFill) const + void renderImageTransformed (IteratorType& iter, const Image& src, int alpha, const AffineTransform& trans, Graphics::ResamplingQuality quality, bool tiledFill) const { Image::BitmapData destData (image, Image::BitmapData::readWrite); const Image::BitmapData srcData (src, Image::BitmapData::readOnly); @@ -2538,7 +2612,7 @@ public: } template - void renderImageUntransformed (IteratorType& iter, const Image& src, const int alpha, int x, int y, bool tiledFill) const + void renderImageUntransformed (IteratorType& iter, const Image& src, int alpha, int x, int y, bool tiledFill) const { Image::BitmapData destData (image, Image::BitmapData::readWrite); const Image::BitmapData srcData (src, Image::BitmapData::readOnly); @@ -2546,7 +2620,7 @@ public: } template - void fillWithSolidColour (IteratorType& iter, const PixelARGB colour, bool replaceContents) const + void fillWithSolidColour (IteratorType& iter, PixelARGB colour, bool replaceContents) const { Image::BitmapData destData (image, Image::BitmapData::readWrite); @@ -2562,7 +2636,7 @@ public: void fillWithGradient (IteratorType& iter, ColourGradient& gradient, const AffineTransform& trans, bool isIdentity) const { HeapBlock lookupTable; - const int numLookupEntries = gradient.createLookupTable (trans, lookupTable); + auto numLookupEntries = gradient.createLookupTable (trans, lookupTable); jassert (numLookupEntries > 0); Image::BitmapData destData (image, Image::BitmapData::readWrite); @@ -2588,7 +2662,7 @@ template class SavedStateStack { public: - SavedStateStack (StateObjectType* const initialState) noexcept + SavedStateStack (StateObjectType* initialState) noexcept : currentState (initialState) {} @@ -2609,7 +2683,7 @@ public: void restore() { - if (StateObjectType* const top = stack.getLast()) + if (auto* top = stack.getLast()) { currentState = top; stack.removeLast (1, false); diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp index d3be472ca5..a9b883ee02 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp @@ -259,10 +259,9 @@ struct Target }; //============================================================================== -class PositionedTexture +struct PositionedTexture { -public: - PositionedTexture (OpenGLTexture& texture, const EdgeTable& et, const Rectangle& clipRegion) + PositionedTexture (OpenGLTexture& texture, const EdgeTable& et, Rectangle clipRegion) : clip (clipRegion.getIntersection (et.getMaximumBounds())) { if (clip.contains (et.getMaximumBounds())) @@ -277,7 +276,7 @@ public: } } - PositionedTexture (GLuint texture, const Rectangle r, const Rectangle clipRegion) noexcept + PositionedTexture (GLuint texture, Rectangle r, Rectangle clipRegion) noexcept : textureID (texture), area (r), clip (clipRegion) {} @@ -328,6 +327,24 @@ private: memset (currentLine + x, 255, (size_t) width); } + void handleEdgeTableRectangle (int x, int y, int width, int height, int alphaLevel) noexcept + { + while (--height >= 0) + { + setEdgeTableYPos (y++); + handleEdgeTableLine (x, width, alphaLevel); + } + } + + void handleEdgeTableRectangleFull (int x, int y, int width, int height) noexcept + { + while (--height >= 0) + { + setEdgeTableYPos (y++); + handleEdgeTableLineFull (x, width); + } + } + HeapBlock data; const Rectangle area; @@ -339,9 +356,8 @@ private: }; //============================================================================== -class ShaderPrograms : public ReferenceCountedObject +struct ShaderPrograms : public ReferenceCountedObject { -public: ShaderPrograms (OpenGLContext& context) : solidColourProgram (context), solidColourMasked (context), @@ -409,7 +425,7 @@ public: screenBounds (program, "screenBounds") {} - void set2DBounds (const Rectangle& bounds) + void set2DBounds (Rectangle bounds) { screenBounds.set (bounds.getX(), bounds.getY(), 0.5f * bounds.getWidth(), 0.5f * bounds.getHeight()); } @@ -441,7 +457,7 @@ public: maskBounds (program, "maskBounds") {} - void setBounds (const Rectangle& area, const Target& target, const GLint textureIndex) const + void setBounds (Rectangle area, const Target& target, GLint textureIndex) const { maskTexture.set (textureIndex); maskBounds.set (area.getX() - target.bounds.getX(), @@ -492,11 +508,11 @@ public: matrix (program, "matrix") {} - void setMatrix (const Point p1, const Point p2, const Point p3) + void setMatrix (Point p1, Point p2, Point p3) { - const AffineTransform t (AffineTransform::fromTargetPoints (p1.x, p1.y, 0.0f, 0.0f, - p2.x, p2.y, 1.0f, 0.0f, - p3.x, p3.y, 0.0f, 1.0f)); + auto t = AffineTransform::fromTargetPoints (p1.x, p1.y, 0.0f, 0.0f, + p2.x, p2.y, 1.0f, 0.0f, + p3.x, p3.y, 0.0f, 1.0f); const GLfloat m[] = { t.mat00, t.mat01, t.mat02, t.mat10, t.mat11, t.mat12 }; matrix.set (m, 6); } @@ -637,15 +653,13 @@ public: imageLimits (program, "imageLimits") {} - void setMatrix (const AffineTransform& trans, - const int imageWidth, const int imageHeight, + void setMatrix (const AffineTransform& trans, int imageWidth, int imageHeight, float fullWidthProportion, float fullHeightProportion, - const float targetX, const float targetY, - const bool isForTiling) const + float targetX, float targetY, bool isForTiling) const { - const AffineTransform t (trans.translated (-targetX, -targetY) - .inverted().scaled (fullWidthProportion / imageWidth, - fullHeightProportion / imageHeight)); + auto t = trans.translated (-targetX, -targetY) + .inverted().scaled (fullWidthProportion / imageWidth, + fullHeightProportion / imageHeight); const GLfloat m[] = { t.mat00, t.mat01, t.mat02, t.mat10, t.mat11, t.mat12 }; matrix.set (m, 6); @@ -660,8 +674,7 @@ public: } void setMatrix (const AffineTransform& trans, const TextureInfo& textureInfo, - const float targetX, const float targetY, - bool isForTiling) const + float targetX, float targetY, bool isForTiling) const { setMatrix (trans, textureInfo.imageWidth, textureInfo.imageHeight, @@ -828,13 +841,13 @@ struct StateHelpers srcFunction = dstFunction = 0; } - template + template void setPremultipliedBlendingMode (QuadQueueType& quadQueue) noexcept { setBlendFunc (quadQueue, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } - template + template void setBlendFunc (QuadQueueType& quadQueue, GLenum src, GLenum dst) { if (! blendingEnabled) @@ -853,7 +866,7 @@ struct StateHelpers } } - template + template void disableBlend (QuadQueueType& quadQueue) noexcept { if (blendingEnabled) @@ -864,8 +877,8 @@ struct StateHelpers } } - template - void setBlendMode (QuadQueueType& quadQueue, const bool replaceExistingContents) noexcept + template + void setBlendMode (QuadQueueType& quadQueue, bool replaceExistingContents) noexcept { if (replaceExistingContents) disableBlend (quadQueue); @@ -879,42 +892,54 @@ struct StateHelpers }; //============================================================================== - template + template struct EdgeTableRenderer { - EdgeTableRenderer (QuadQueueType& q, const PixelARGB c) noexcept + EdgeTableRenderer (QuadQueueType& q, PixelARGB c) noexcept : quadQueue (q), colour (c) {} - void setEdgeTableYPos (const int y) noexcept + void setEdgeTableYPos (int y) noexcept { currentY = y; } - void handleEdgeTablePixel (const int x, const int alphaLevel) noexcept + void handleEdgeTablePixel (int x, int alphaLevel) noexcept { - PixelARGB c (colour); + auto c = colour; c.multiplyAlpha (alphaLevel); quadQueue.add (x, currentY, 1, 1, c); } - void handleEdgeTablePixelFull (const int x) noexcept + void handleEdgeTablePixelFull (int x) noexcept { quadQueue.add (x, currentY, 1, 1, colour); } - void handleEdgeTableLine (const int x, const int width, const int alphaLevel) noexcept + void handleEdgeTableLine (int x, int width, int alphaLevel) noexcept { - PixelARGB c (colour); + auto c = colour; c.multiplyAlpha (alphaLevel); quadQueue.add (x, currentY, width, 1, c); } - void handleEdgeTableLineFull (const int x, const int width) noexcept + void handleEdgeTableLineFull (int x, int width) noexcept { quadQueue.add (x, currentY, width, 1, colour); } + void handleEdgeTableRectangle (int x, int y, int width, int height, int alphaLevel) noexcept + { + auto c = colour; + c.multiplyAlpha (alphaLevel); + quadQueue.add (x, y, width, height, c); + } + + void handleEdgeTableRectangleFull (int x, int y, int width, int height) noexcept + { + quadQueue.add (x, y, width, height, colour); + } + private: QuadQueueType& quadQueue; const PixelARGB colour; @@ -923,14 +948,14 @@ struct StateHelpers JUCE_DECLARE_NON_COPYABLE (EdgeTableRenderer) }; - template + template struct FloatRectangleRenderer { - FloatRectangleRenderer (QuadQueueType& q, const PixelARGB c) noexcept + FloatRectangleRenderer (QuadQueueType& q, PixelARGB c) noexcept : quadQueue (q), colour (c) {} - void operator() (const int x, const int y, const int w, const int h, const int alpha) noexcept + void operator() (int x, int y, int w, int h, int alpha) noexcept { if (w > 0 && h > 0) { @@ -959,8 +984,8 @@ struct StateHelpers zeromem (currentTextureID, sizeof (currentTextureID)); } - template - void setTexturesEnabled (QuadQueueType& quadQueue, const int textureIndexMask) noexcept + template + void setTexturesEnabled (QuadQueueType& quadQueue, int textureIndexMask) noexcept { if (texturesEnabled != textureIndexMask) { @@ -991,20 +1016,20 @@ struct StateHelpers } } - template + template void disableTextures (QuadQueueType& quadQueue) noexcept { setTexturesEnabled (quadQueue, 0); } - template + template void setSingleTextureMode (QuadQueueType& quadQueue) noexcept { setTexturesEnabled (quadQueue, 1); setActiveTexture (0); } - template + template void setTwoTextureMode (QuadQueueType& quadQueue, GLuint texture1, GLuint texture2) { JUCE_CHECK_OPENGL_ERROR @@ -1026,7 +1051,7 @@ struct StateHelpers JUCE_CHECK_OPENGL_ERROR } - void setActiveTexture (const int index) noexcept + void setActiveTexture (int index) noexcept { if (currentActiveTexture != index) { @@ -1036,13 +1061,13 @@ struct StateHelpers } } - void bindTexture (const GLuint textureID) noexcept + void bindTexture (GLuint textureID) noexcept { jassert (currentActiveTexture >= 0); - if (currentTextureID [currentActiveTexture] != textureID) + if (currentTextureID[currentActiveTexture] != textureID) { - currentTextureID [currentActiveTexture] = textureID; + currentTextureID[currentActiveTexture] = textureID; glBindTexture (GL_TEXTURE_2D, textureID); JUCE_CHECK_OPENGL_ERROR } @@ -1057,7 +1082,7 @@ struct StateHelpers } private: - GLuint currentTextureID [3]; + GLuint currentTextureID[3]; int texturesEnabled, currentActiveTexture; const OpenGLContext& context; @@ -1067,9 +1092,7 @@ struct StateHelpers //============================================================================== struct TextureCache { - TextureCache() noexcept - : activeGradientIndex (0), gradientNeedsRefresh (true) - {} + TextureCache() noexcept {} OpenGLTexture* getTexture (ActiveTextures& activeTextures, int w, int h) { @@ -1081,7 +1104,8 @@ struct StateHelpers for (int i = 0; i < numTexturesToCache - 2; ++i) { - const OpenGLTexture* const t = textures.getUnchecked(i); + auto* t = textures.getUnchecked(i); + if (t->getWidth() == w && t->getHeight() == h) return textures.removeAndReturn (i); } @@ -1112,7 +1136,7 @@ struct StateHelpers } JUCE_CHECK_OPENGL_ERROR; - PixelARGB lookup [gradientTextureSize]; + PixelARGB lookup[gradientTextureSize]; gradient.createLookupTable (lookup, gradientTextureSize); gradientTextures.getUnchecked (activeGradientIndex)->loadARGB (lookup, gradientTextureSize, 1); } @@ -1125,15 +1149,14 @@ struct StateHelpers private: enum { numTexturesToCache = 8, numGradientTexturesToCache = 10 }; OwnedArray textures, gradientTextures; - int activeGradientIndex; - bool gradientNeedsRefresh; + int activeGradientIndex = 0; + bool gradientNeedsRefresh = true; }; //============================================================================== struct ShaderQuadQueue { - ShaderQuadQueue (const OpenGLContext& c) noexcept - : context (c), numVertices (0) + ShaderQuadQueue (const OpenGLContext& c) noexcept : context (c) {} ~ShaderQuadQueue() noexcept @@ -1147,6 +1170,7 @@ struct StateHelpers void initialise() noexcept { JUCE_CHECK_OPENGL_ERROR + for (int i = 0, v = 0; i < numQuads * 6; i += 6, v += 4) { indexData[i] = (GLushort) v; @@ -1163,22 +1187,22 @@ struct StateHelpers JUCE_CHECK_OPENGL_ERROR } - void add (const int x, const int y, const int w, const int h, const PixelARGB colour) noexcept + void add (int x, int y, int w, int h, PixelARGB colour) noexcept { jassert (w > 0 && h > 0); - VertexInfo* const v = vertexData + numVertices; + auto* v = vertexData + numVertices; v[0].x = v[2].x = (GLshort) x; v[0].y = v[1].y = (GLshort) y; v[1].x = v[3].x = (GLshort) (x + w); v[2].y = v[3].y = (GLshort) (y + h); #if JUCE_BIG_ENDIAN - const GLuint rgba = (GLuint) ((colour.getRed() << 24) | (colour.getGreen() << 16) - | (colour.getBlue() << 8) | colour.getAlpha()); + auto rgba = (GLuint) ((colour.getRed() << 24) | (colour.getGreen() << 16) + | (colour.getBlue() << 8) | colour.getAlpha()); #else - const GLuint rgba = (GLuint) ((colour.getAlpha() << 24) | (colour.getBlue() << 16) - | (colour.getGreen() << 8) | colour.getRed()); + auto rgba = (GLuint) ((colour.getAlpha() << 24) | (colour.getBlue() << 16) + | (colour.getGreen() << 8) | colour.getRed()); #endif v[0].colour = rgba; @@ -1192,24 +1216,24 @@ struct StateHelpers draw(); } - void add (const Rectangle& r, const PixelARGB colour) noexcept + void add (Rectangle r, PixelARGB colour) noexcept { add (r.getX(), r.getY(), r.getWidth(), r.getHeight(), colour); } - void add (const Rectangle& r, const PixelARGB colour) noexcept + void add (Rectangle r, PixelARGB colour) noexcept { FloatRectangleRenderer frr (*this, colour); RenderingHelpers::FloatRectangleRasterisingInfo (r).iterate (frr); } - void add (const RectangleList& list, const PixelARGB colour) noexcept + void add (const RectangleList& list, PixelARGB colour) noexcept { for (auto& i : list) add (i, colour); } - void add (const RectangleList& list, const Rectangle& clip, const PixelARGB colour) noexcept + void add (const RectangleList& list, Rectangle clip, PixelARGB colour) noexcept { for (auto& i : list) { @@ -1220,8 +1244,8 @@ struct StateHelpers } } - template - void add (const IteratorType& et, const PixelARGB colour) + template + void add (const IteratorType& et, PixelARGB colour) { EdgeTableRenderer etr (*this, colour); et.iterate (etr); @@ -1243,10 +1267,10 @@ struct StateHelpers enum { numQuads = 256 }; GLuint buffers[2]; - VertexInfo vertexData [numQuads * 4]; - GLushort indexData [numQuads * 6]; + VertexInfo vertexData[numQuads * 4]; + GLushort indexData[numQuads * 6]; const OpenGLContext& context; - int numVertices; + int numVertices = 0; void draw() noexcept { @@ -1264,10 +1288,9 @@ struct StateHelpers //============================================================================== struct CurrentShader { - CurrentShader (OpenGLContext& c) noexcept - : context (c), activeShader (nullptr) + CurrentShader (OpenGLContext& c) noexcept : context (c) { - const char programValueID[] = "GraphicsContextPrograms"; + auto programValueID = "GraphicsContextPrograms"; programs = static_cast (context.getAssociatedObject (programValueID)); if (programs == nullptr) @@ -1282,7 +1305,7 @@ struct StateHelpers jassert (activeShader == nullptr); } - void setShader (const Rectangle& bounds, ShaderQuadQueue& quadQueue, ShaderPrograms::ShaderBase& shader) + void setShader (Rectangle bounds, ShaderQuadQueue& quadQueue, ShaderPrograms::ShaderBase& shader) { if (activeShader != &shader) { @@ -1324,7 +1347,7 @@ struct StateHelpers ShaderPrograms::Ptr programs; private: - ShaderPrograms::ShaderBase* activeShader; + ShaderPrograms::ShaderBase* activeShader = nullptr; Rectangle currentBounds; CurrentShader& operator= (const CurrentShader&); @@ -1332,9 +1355,8 @@ struct StateHelpers }; //============================================================================== -class GLState +struct GLState { -public: GLState (const Target& t) noexcept : target (t), activeTextures (t.context), @@ -1375,7 +1397,7 @@ public: } void setShaderForGradientFill (const ColourGradient& g, const AffineTransform& transform, - const int maskTextureID, const Rectangle* const maskArea) + int maskTextureID, const Rectangle* maskArea) { JUCE_CHECK_OPENGL_ERROR activeTextures.disableTextures (shaderQuadQueue); @@ -1396,12 +1418,12 @@ public: textureCache.bindTextureForGradient (activeTextures, g); } - const AffineTransform t (transform.translated (0.5f - target.bounds.getX(), - 0.5f - target.bounds.getY())); - Point p1 (g.point1.transformedBy (t)); - const Point p2 (g.point2.transformedBy (t)); - const Point p3 (Point (g.point1.x + (g.point2.y - g.point1.y), - g.point1.y - (g.point2.x - g.point1.x)).transformedBy (t)); + auto t = transform.translated (0.5f - target.bounds.getX(), + 0.5f - target.bounds.getY()); + auto p1 = g.point1.transformedBy (t); + auto p2 = g.point2.transformedBy (t); + auto p3 = Point (g.point1.x + (g.point2.y - g.point1.y), + g.point1.y - (g.point2.x - g.point1.x)).transformedBy (t); ShaderPrograms* const programs = currentShader.programs; const ShaderPrograms::MaskedShaderParams* maskParams = nullptr; @@ -1476,7 +1498,7 @@ public: } void setShaderForTiledImageFill (const TextureInfo& textureInfo, const AffineTransform& transform, - const int maskTextureID, const Rectangle* const maskArea, bool isTiledFill) + int maskTextureID, const Rectangle* maskArea, bool isTiledFill) { blendMode.setPremultipliedBlendingMode (shaderQuadQueue); @@ -1540,29 +1562,26 @@ private: }; //============================================================================== -class SavedState : public RenderingHelpers::SavedStateBase +struct SavedState : public RenderingHelpers::SavedStateBase { typedef RenderingHelpers::SavedStateBase BaseClass; -public: - SavedState (GLState* const s) - : BaseClass (s->target.bounds), state (s), isUsingCustomShader (false) + SavedState (GLState* s) : BaseClass (s->target.bounds), state (s) {} SavedState (const SavedState& other) - : BaseClass (other), font (other.font), - state (other.state), isUsingCustomShader (false), + : BaseClass (other), font (other.font), state (other.state), transparencyLayer (other.transparencyLayer), previousTarget (other.previousTarget.createCopy()) {} SavedState* beginTransparencyLayer (float opacity) { - SavedState* const s = new SavedState (*this); + auto* s = new SavedState (*this); if (clip != nullptr) { - const Rectangle clipBounds (clip->getClipBounds()); + auto clipBounds = clip->getClipBounds(); state->flush(); s->transparencyLayer = Image (OpenGLImageType().create (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true)); @@ -1588,7 +1607,7 @@ public: finishedLayerState.previousTarget.reset(); state->target.makeActive(); - const Rectangle clipBounds (clip->getClipBounds()); + auto clipBounds = clip->getClipBounds(); clip->renderImageUntransformed (*this, finishedLayerState.transparencyLayer, (int) (finishedLayerState.transparencyLayerAlpha * 255.0f), @@ -1604,8 +1623,7 @@ public: { if (trans.isOnlyTranslation() && ! transform.isRotated) { - GlyphCacheType& cache = GlyphCacheType::getInstance(); - + auto& cache = GlyphCacheType::getInstance(); Point pos (trans.getTranslationX(), trans.getTranslationY()); if (transform.isOnlyTranslated) @@ -1619,7 +1637,8 @@ public: Font f (font); f.setHeight (font.getHeight() * transform.complexTransform.mat11); - const float xScale = transform.complexTransform.mat00 / transform.complexTransform.mat11; + auto xScale = transform.complexTransform.mat00 / transform.complexTransform.mat11; + if (std::abs (xScale - 1.0f) > 0.01f) f.setHorizontalScale (xScale); @@ -1628,10 +1647,10 @@ public: } else { - const float fontHeight = font.getHeight(); + auto fontHeight = font.getHeight(); - AffineTransform t (transform.getTransformWith (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight) - .followedBy (trans))); + auto t = transform.getTransformWith (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight) + .followedBy (trans)); const ScopedPointer et (font.getTypeface()->getEdgeTableForGlyph (glyphNumber, t, fontHeight)); @@ -1651,7 +1670,7 @@ public: //============================================================================== template - void renderImageTransformed (IteratorType& iter, const Image& src, const int alpha, + void renderImageTransformed (IteratorType& iter, const Image& src, int alpha, const AffineTransform& trans, Graphics::ResamplingQuality, bool tiledFill) const { state->shaderQuadQueue.flush(); @@ -1664,14 +1683,14 @@ public: } template - void renderImageUntransformed (IteratorType& iter, const Image& src, const int alpha, int x, int y, bool tiledFill) const + void renderImageUntransformed (IteratorType& iter, const Image& src, int alpha, int x, int y, bool tiledFill) const { renderImageTransformed (iter, src, alpha, AffineTransform::translation ((float) x, (float) y), Graphics::lowResamplingQuality, tiledFill); } template - void fillWithSolidColour (IteratorType& iter, const PixelARGB colour, bool replaceContents) const + void fillWithSolidColour (IteratorType& iter, PixelARGB colour, bool replaceContents) const { if (! isUsingCustomShader) { @@ -1690,7 +1709,7 @@ public: state->shaderQuadQueue.add (iter, fillType.colour.getPixelARGB()); } - void fillRectWithCustomShader (OpenGLRendering::ShaderPrograms::ShaderBase& shader, const Rectangle& area) + void fillRectWithCustomShader (OpenGLRendering::ShaderPrograms::ShaderBase& shader, Rectangle area) { state->setShader (shader); isUsingCustomShader = true; @@ -1704,7 +1723,7 @@ public: //============================================================================== Font font; GLState* state; - bool isUsingCustomShader; + bool isUsingCustomShader = false; private: Image transparencyLayer; @@ -1715,15 +1734,14 @@ private: //============================================================================== -class ShaderContext : public RenderingHelpers::StackBasedLowLevelGraphicsContext +struct ShaderContext : public RenderingHelpers::StackBasedLowLevelGraphicsContext { -public: ShaderContext (const Target& target) : glState (target) { stack.initialise (new SavedState (&glState)); } - void fillRectWithCustomShader (ShaderPrograms::ShaderBase& shader, const Rectangle& area) + void fillRectWithCustomShader (ShaderPrograms::ShaderBase& shader, Rectangle area) { static_cast (*stack).fillRectWithCustomShader (shader, area); } @@ -1733,9 +1751,8 @@ public: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ShaderContext) }; -class NonShaderContext : public LowLevelGraphicsSoftwareRenderer +struct NonShaderContext : public LowLevelGraphicsSoftwareRenderer { -public: NonShaderContext (const Target& t, const Image& im) : LowLevelGraphicsSoftwareRenderer (im), target (t), image (im) {} @@ -1743,7 +1760,7 @@ public: ~NonShaderContext() { JUCE_CHECK_OPENGL_ERROR - const GLuint previousFrameBufferTarget = OpenGLFrameBuffer::getCurrentFrameBufferTarget(); + auto previousFrameBufferTarget = OpenGLFrameBuffer::getCurrentFrameBufferTarget(); #if ! JUCE_ANDROID target.context.extensions.glActiveTexture (GL_TEXTURE0); @@ -1803,7 +1820,7 @@ LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext& context, in LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext& context, OpenGLFrameBuffer& target) { - return OpenGLRendering::createOpenGLContext (OpenGLRendering::Target (context, target, Point())); + return OpenGLRendering::createOpenGLContext (OpenGLRendering::Target (context, target, {})); } LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext& context, unsigned int frameBufferID, int width, int height) @@ -1822,7 +1839,7 @@ struct CustomProgram : public ReferenceCountedObject, static CustomProgram* get (const String& hashName) { - if (OpenGLContext* c = OpenGLContext::getCurrentContext()) + if (auto* c = OpenGLContext::getCurrentContext()) return static_cast (c->getAssociatedObject (hashName.toRawUTF8())); return nullptr; @@ -1830,13 +1847,12 @@ struct CustomProgram : public ReferenceCountedObject, static CustomProgram* getOrCreate (LowLevelGraphicsContext& gc, const String& hashName, const String& code, String& errorMessage) { - if (CustomProgram* c = get (hashName)) + if (auto* c = get (hashName)) return c; - if (OpenGLRendering::ShaderContext* sc = dynamic_cast (&gc)) + if (auto* sc = dynamic_cast (&gc)) { ReferenceCountedObjectPtr c (new CustomProgram (*sc, code)); - errorMessage = c->lastError; if (errorMessage.isEmpty()) @@ -1879,7 +1895,7 @@ OpenGLShaderProgram* OpenGLGraphicsContextCustomShader::getProgram (LowLevelGrap return nullptr; } -void OpenGLGraphicsContextCustomShader::fillRect (LowLevelGraphicsContext& gc, const Rectangle& area) const +void OpenGLGraphicsContextCustomShader::fillRect (LowLevelGraphicsContext& gc, Rectangle area) const { String errorMessage; diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.h b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.h index 10176ec423..adf168040e 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.h +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.h @@ -79,7 +79,7 @@ struct JUCE_API OpenGLGraphicsContextCustomShader OpenGLShaderProgram* getProgram (LowLevelGraphicsContext&) const; /** Applies the shader to a rectangle within the graphics context. */ - void fillRect (LowLevelGraphicsContext&, const Rectangle& area) const; + void fillRect (LowLevelGraphicsContext&, Rectangle area) const; /** Attempts to compile the program if necessary, and returns an error message if it fails. */ Result checkCompilation (LowLevelGraphicsContext&); diff --git a/modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp b/modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp index 23f3b7aeda..a6c93365dd 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp @@ -76,7 +76,7 @@ void OpenGLHelpers::clear (Colour colour) glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } -void OpenGLHelpers::enableScissorTest (const Rectangle& clip) +void OpenGLHelpers::enableScissorTest (Rectangle clip) { glEnable (GL_SCISSOR_TEST); glScissor (clip.getX(), clip.getY(), clip.getWidth(), clip.getHeight()); diff --git a/modules/juce_opengl/opengl/juce_OpenGLHelpers.h b/modules/juce_opengl/opengl/juce_OpenGLHelpers.h index 0a64e48b5e..dbc683e6d1 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLHelpers.h +++ b/modules/juce_opengl/opengl/juce_OpenGLHelpers.h @@ -43,7 +43,7 @@ public: /** Clears the current context using the given colour. */ static void clear (Colour colour); - static void enableScissorTest (const Rectangle& clip); + static void enableScissorTest (Rectangle clip); /** Checks whether the current context supports the specified extension. */ static bool isExtensionSupported (const char* extensionName);