1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-11 23:54:18 +00:00

Component repaint optimisations.

This commit is contained in:
jules 2012-11-19 16:19:05 +00:00
parent b3c0df703f
commit 880fa4d673
3 changed files with 27 additions and 25 deletions

View file

@ -115,6 +115,7 @@ private:
void flip() const;
void applyTransform (const AffineTransform& transform) const;
void drawImage (const Image& sourceImage, const AffineTransform& transform, bool fillEntireClipAsTiles);
bool clipToRectangleListWithoutTest (const RectangleList&);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CoreGraphicsContext);
};

View file

@ -193,7 +193,7 @@ bool CoreGraphicsContext::clipToRectangle (const Rectangle<int>& r)
return ! isClipEmpty();
}
bool CoreGraphicsContext::clipToRectangleList (const RectangleList& clipRegion)
bool CoreGraphicsContext::clipToRectangleListWithoutTest (const RectangleList& clipRegion)
{
if (clipRegion.isEmpty())
{
@ -205,26 +205,28 @@ bool CoreGraphicsContext::clipToRectangleList (const RectangleList& clipRegion)
else
{
const int numRects = clipRegion.getNumRectangles();
HeapBlock <CGRect> rects (numRects);
for (int i = 0; i < numRects; ++i)
{
const Rectangle<int>& r = clipRegion.getRectangle(i);
rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
}
int i = 0;
for (const Rectangle<int>* r = clipRegion.begin(), * const e = clipRegion.end(); r != e; ++r)
rects[i++] = CGRectMake (r->getX(), flipHeight - r->getBottom(), r->getWidth(), r->getHeight());
CGContextClipToRects (context, rects, numRects);
lastClipRectIsValid = false;
return ! isClipEmpty();
return true;
}
}
bool CoreGraphicsContext::clipToRectangleList (const RectangleList& clipRegion)
{
return clipToRectangleList (clipRegion) && ! isClipEmpty();
}
void CoreGraphicsContext::excludeClipRectangle (const Rectangle<int>& r)
{
RectangleList remaining (getClipBounds());
remaining.subtract (r);
clipToRectangleList (remaining);
lastClipRectIsValid = false;
clipToRectangleListWithoutTest (remaining);
}
void CoreGraphicsContext::clipToPath (const Path& path, const AffineTransform& transform)
@ -297,9 +299,7 @@ void CoreGraphicsContext::restoreState()
{
CGContextRestoreGState (context);
SavedState* const top = stateStack.getLast();
if (top != nullptr)
if (SavedState* const top = stateStack.getLast())
{
state = top;
stateStack.removeLast (1, false);
@ -557,9 +557,7 @@ void CoreGraphicsContext::setFont (const Font& newFont)
state->fontRef = 0;
state->font = newFont;
OSXTypeface* osxTypeface = dynamic_cast <OSXTypeface*> (state->font.getTypeface());
if (osxTypeface != nullptr)
if (OSXTypeface* osxTypeface = dynamic_cast <OSXTypeface*> (state->font.getTypeface()))
{
state->fontRef = osxTypeface->fontRef;
CGContextSetFont (context, state->fontRef);
@ -791,11 +789,9 @@ Image juce_loadWithCoreImage (InputStream& input)
#if JUCE_IOS
JUCE_AUTORELEASEPOOL
UIImage* uiImage = [UIImage imageWithData: [NSData dataWithBytesNoCopy: data.getData()
length: data.getSize()
freeWhenDone: NO]];
if (uiImage != nil)
if (UIImage* uiImage = [UIImage imageWithData: [NSData dataWithBytesNoCopy: data.getData()
length: data.getSize()
freeWhenDone: NO]])
{
CGImageRef loadedImage = uiImage.CGImage;

View file

@ -295,8 +295,10 @@ struct Component::ComponentHelpers
return r;
}
static void clipObscuredRegions (const Component& comp, Graphics& g, const Rectangle<int>& clipRect, const Point<int>& delta)
static bool clipObscuredRegions (const Component& comp, Graphics& g, const Rectangle<int>& clipRect, const Point<int>& delta)
{
bool nothingChanged = true;
for (int i = comp.childComponentList.size(); --i >= 0;)
{
const Component& child = *comp.childComponentList.getUnchecked(i);
@ -310,15 +312,19 @@ struct Component::ComponentHelpers
if (child.isOpaque() && child.componentTransparency == 0)
{
g.excludeClipRegion (newClip + delta);
nothingChanged = false;
}
else
{
const Point<int> childPos (child.getPosition());
clipObscuredRegions (child, g, newClip - childPos, childPos + delta);
if (clipObscuredRegions (child, g, newClip - childPos, childPos + delta))
nothingChanged = false;
}
}
}
}
return nothingChanged;
}
static void subtractObscuredRegions (const Component& comp, RectangleList& result,
@ -1836,9 +1842,8 @@ void Component::paintComponentAndChildren (Graphics& g)
else
{
g.saveState();
ComponentHelpers::clipObscuredRegions (*this, g, clipBounds, Point<int>());
if (! g.isClipEmpty())
if (ComponentHelpers::clipObscuredRegions (*this, g, clipBounds, Point<int>()) || ! g.isClipEmpty())
paint (g);
g.restoreState();