From 68476aded8ead0cd120c80b6a7f3cd25681b82e3 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 25 Nov 2012 19:04:05 +0000 Subject: [PATCH] Renderer optimisations. --- .../native/juce_RenderingHelpers.h | 107 +++++++++++------- .../opengl/juce_OpenGLGraphicsContext.cpp | 4 + 2 files changed, 71 insertions(+), 40 deletions(-) diff --git a/modules/juce_graphics/native/juce_RenderingHelpers.h b/modules/juce_graphics/native/juce_RenderingHelpers.h index 24ed47d3e1..506da5808f 100644 --- a/modules/juce_graphics/native/juce_RenderingHelpers.h +++ b/modules/juce_graphics/native/juce_RenderingHelpers.h @@ -2153,6 +2153,11 @@ public: cloneClipIfMultiplyReferenced(); clip = clip->clipToRectangle (transform.translated (r)); } + else if (transform.isIntegerScaling) + { + cloneClipIfMultiplyReferenced(); + clip = clip->clipToRectangle (transform.transformed (r).getSmallestIntegerContainer()); + } else { Path p; @@ -2175,6 +2180,16 @@ public: offsetList.offsetAll (transform.xOffset, transform.yOffset); clip = clip->clipToRectangleList (offsetList); } + else if (transform.isIntegerScaling) + { + cloneClipIfMultiplyReferenced(); + RectangleList scaledList; + + for (const Rectangle* i = r.begin(), * const e = r.end(); i != e; ++i) + scaledList.add (transform.transformed (*i).getSmallestIntegerContainer()); + + clip = clip->clipToRectangleList (scaledList); + } else { clipToPath (r.toPath(), AffineTransform::identity); @@ -2194,6 +2209,10 @@ public: { clip = clip->excludeClipRectangle (transform.translated (r)); } + else if (transform.isIntegerScaling) + { + clip = clip->excludeClipRectangle (transform.transformed (r).getSmallestIntegerContainer()); + } else { Path p; @@ -2288,32 +2307,56 @@ public: } //============================================================================== + void fillTargetRect (const Rectangle& r, const bool replaceContents) + { + if (fillType.isColour()) + { + Image::BitmapData destData (image, Image::BitmapData::readWrite); + clip->fillRectWithColour (destData, r, fillType.colour.getPixelARGB(), replaceContents); + } + else + { + const Rectangle clipped (clip->getClipBounds().getIntersection (r)); + + if (! clipped.isEmpty()) + fillShape (new ClipRegions::RectangleListRegion (clipped), false); + } + } + + void fillTargetRect (const Rectangle& r) + { + if (fillType.isColour()) + { + Image::BitmapData destData (image, Image::BitmapData::readWrite); + clip->fillRectWithColour (destData, r, fillType.colour.getPixelARGB()); + } + else + { + const Rectangle clipped (clip->getClipBounds().toFloat().getIntersection (r)); + + if (! clipped.isEmpty()) + fillShape (new ClipRegions::EdgeTableRegion (clipped), false); + } + } + + template + void fillRectAsPath (const Rectangle& r) + { + Path p; + p.addRectangle (r); + fillPath (p, AffineTransform::identity); + } + void fillRect (const Rectangle& r, const bool replaceContents) { if (clip != nullptr) { if (transform.isOnlyTranslated) - { - if (fillType.isColour()) - { - Image::BitmapData destData (image, Image::BitmapData::readWrite); - clip->fillRectWithColour (destData, transform.translated (r), fillType.colour.getPixelARGB(), replaceContents); - } - else - { - const Rectangle totalClip (clip->getClipBounds()); - const Rectangle clipped (totalClip.getIntersection (transform.translated (r))); - - if (! clipped.isEmpty()) - fillShape (new ClipRegions::RectangleListRegion (clipped), false); - } - } + fillTargetRect (transform.translated (r), replaceContents); + else if (transform.isIntegerScaling) + fillTargetRect (transform.transformed (r).getSmallestIntegerContainer(), replaceContents); else - { - Path p; - p.addRectangle (r); - fillPath (p, AffineTransform::identity); - } + fillRectAsPath (r); } } @@ -2322,27 +2365,11 @@ public: if (clip != nullptr) { if (transform.isOnlyTranslated) - { - if (fillType.isColour()) - { - Image::BitmapData destData (image, Image::BitmapData::readWrite); - clip->fillRectWithColour (destData, transform.translated (r), fillType.colour.getPixelARGB()); - } - else - { - const Rectangle totalClip (clip->getClipBounds().toFloat()); - const Rectangle clipped (totalClip.getIntersection (transform.translated (r))); - - if (! clipped.isEmpty()) - fillShape (new ClipRegions::EdgeTableRegion (clipped), false); - } - } + fillTargetRect (transform.translated (r)); + else if (transform.isIntegerScaling) + fillTargetRect (transform.transformed (r)); else - { - Path p; - p.addRectangle (r); - fillPath (p, AffineTransform::identity); - } + fillRectAsPath (r); } } diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp index a5610976c4..2b1aa866ed 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp @@ -1889,6 +1889,10 @@ public: { clip = clip->excludeClipRectangle (transform.translated (r)); } + else if (transform.isIntegerScaling) + { + clip = clip->excludeClipRectangle (transform.transformed (r).getSmallestIntegerContainer()); + } else { Path p;