From 4d332b6bb3a92dbf73675443899d582a97fe8333 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 2 Feb 2012 12:08:04 +0000 Subject: [PATCH] OpenGL fixes for flickering and rounding errors. RelativeCoordinate expression parsing work. Tweaks for AudioProcessorGraph params and OSX thread naming calls. --- .../Source/Utility/jucer_CodeHelpers.cpp | 4 +- .../processors/juce_AudioProcessorGraph.cpp | 4 +- .../processors/juce_AudioProcessorGraph.h | 2 +- .../juce_core/native/juce_posix_SharedCode.h | 4 +- .../juce_RelativeCoordinatePositioner.cpp | 186 +++++++++++------- .../juce_RelativeCoordinatePositioner.h | 1 - .../opengl/juce_OpenGLComponent.cpp | 11 +- .../opengl/juce_OpenGLGraphicsContext.cpp | 11 +- 8 files changed, 139 insertions(+), 84 deletions(-) diff --git a/extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp b/extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp index d4fe60b171..5cdd82df37 100644 --- a/extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp +++ b/extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp @@ -105,7 +105,7 @@ namespace CodeHelpers } static void writeEscapeChars (OutputStream& out, const char* utf8, const int numBytes, - const int maxCharsOnLine, const bool breakAtNewLines, + const int maxCharsOnLine, const bool breakAtNewLines, const bool replaceSingleQuotes, const bool allowStringBreaks) { int charsOnLine = 0; @@ -399,7 +399,7 @@ namespace CodeHelpers else { out << "\""; - writeEscapeChars (out, (const char*) data, (int) mb.getSize(), + writeEscapeChars (out, (const char*) data, (int) mb.getSize(), maxCharsOnLine, breakAtNewLines, false, allowStringBreaks); out << "\";"; } diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp index 7f6aa2e16e..6300c1584c 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp @@ -1138,8 +1138,10 @@ bool AudioProcessorGraph::disconnectNode (const uint32 nodeId) return doneAnything; } -bool AudioProcessorGraph::isConnectionLegal (Connection* const c) const +bool AudioProcessorGraph::isConnectionLegal (const Connection* const c) const { + jassert (c != nullptr); + const Node* const source = getNodeForId (c->sourceNodeId); const Node* const dest = getNodeForId (c->destNodeId); diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h index 0b2f88fa2f..ea64365b55 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h @@ -250,7 +250,7 @@ public: Even if a connection is valid when created, its status could change if a node changes its channel config. */ - bool isConnectionLegal (Connection* connection) const; + bool isConnectionLegal (const Connection* connection) const; /** Performs a sanity checks of all the connections. diff --git a/modules/juce_core/native/juce_posix_SharedCode.h b/modules/juce_core/native/juce_posix_SharedCode.h index 483ffca081..187c25b828 100644 --- a/modules/juce_core/native/juce_posix_SharedCode.h +++ b/modules/juce_core/native/juce_posix_SharedCode.h @@ -847,8 +847,8 @@ void Thread::killThread() void Thread::setCurrentThreadName (const String& name) { - #if JUCE_MAC && defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6 - pthread_setname_np (name.toUTF8()); + #if JUCE_IOS || (JUCE_MAC && defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) + [[NSThread currentThread] setName: juceStringToNS (name)]; #elif JUCE_LINUX prctl (PR_SET_NAME, name.toUTF8().getAddress(), 0, 0, 0); #endif diff --git a/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp b/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp index 4ca8139f76..def5f728ec 100644 --- a/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp +++ b/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp @@ -25,6 +25,76 @@ BEGIN_JUCE_NAMESPACE +//============================================================================== +class MarkerListScope : public Expression::Scope +{ +public: + MarkerListScope (Component& component_) : component (component_) {} + + Expression getSymbolValue (const String& symbol) const + { + switch (RelativeCoordinate::StandardStrings::getTypeOf (symbol)) + { + case RelativeCoordinate::StandardStrings::width: return Expression ((double) component.getWidth()); + case RelativeCoordinate::StandardStrings::height: return Expression ((double) component.getHeight()); + default: break; + } + + MarkerList* list; + const MarkerList::Marker* const marker = findMarker (component, symbol, list); + + if (marker != nullptr) + return Expression (marker->position.getExpression().evaluate (*this)); + + return Expression::Scope::getSymbolValue (symbol); + } + + void visitRelativeScope (const String& scopeName, Visitor& visitor) const + { + if (scopeName == RelativeCoordinate::Strings::parent) + { + Component* const parent = component.getParentComponent(); + + if (parent != nullptr) + { + visitor.visit (MarkerListScope (*parent)); + return; + } + } + + Expression::Scope::visitRelativeScope (scopeName, visitor); + } + + String getScopeUID() const + { + return String::toHexString ((pointer_sized_int) (void*) &component) + "m"; + } + + static const MarkerList::Marker* findMarker (Component& component, const String& name, MarkerList*& list) + { + const MarkerList::Marker* marker = nullptr; + list = component.getMarkers (true); + + if (list != nullptr) + marker = list->getMarker (name); + + if (marker == nullptr) + { + list = component.getMarkers (false); + + if (list != nullptr) + marker = list->getMarker (name); + } + + return marker; + } + +private: + Component& component; + + JUCE_DECLARE_NON_COPYABLE (MarkerListScope); +}; + //============================================================================== RelativeCoordinatePositionerBase::ComponentScope::ComponentScope (Component& component_) : component (component_) @@ -46,16 +116,18 @@ Expression RelativeCoordinatePositionerBase::ComponentScope::getSymbolValue (con default: break; } - MarkerList* list; - const MarkerList::Marker* const marker = findMarker (symbol, list); + Component* const parent = component.getParentComponent(); - if (marker != nullptr) + if (parent != nullptr) { - Component* const parent = component.getParentComponent(); - jassert (parent != nullptr); + MarkerList* list; + const MarkerList::Marker* const marker = MarkerListScope::findMarker (*parent, symbol, list); - ComponentScope scope (*parent); - return Expression (marker->position.getExpression().evaluate (scope)); + if (marker != nullptr) + { + MarkerListScope scope (*parent); + return Expression (marker->position.getExpression().evaluate (scope)); + } } return Expression::Scope::getSymbolValue (symbol); @@ -63,12 +135,9 @@ Expression RelativeCoordinatePositionerBase::ComponentScope::getSymbolValue (con void RelativeCoordinatePositionerBase::ComponentScope::visitRelativeScope (const String& scopeName, Visitor& visitor) const { - Component* targetComp = nullptr; - - if (scopeName == RelativeCoordinate::Strings::parent) - targetComp = component.getParentComponent(); - else - targetComp = findSiblingComponent (scopeName); + Component* const targetComp = (scopeName == RelativeCoordinate::Strings::parent) + ? component.getParentComponent() + : findSiblingComponent (scopeName); if (targetComp != nullptr) visitor.visit (ComponentScope (*targetComp)); @@ -78,41 +147,15 @@ void RelativeCoordinatePositionerBase::ComponentScope::visitRelativeScope (const String RelativeCoordinatePositionerBase::ComponentScope::getScopeUID() const { - return String::toHexString ((int) (pointer_sized_int) (void*) &component); + return String::toHexString ((pointer_sized_int) (void*) &component); } Component* RelativeCoordinatePositionerBase::ComponentScope::findSiblingComponent (const String& componentID) const { Component* const parent = component.getParentComponent(); - if (parent != nullptr) - return parent->findChildWithID (componentID); - - return nullptr; -} - -const MarkerList::Marker* RelativeCoordinatePositionerBase::ComponentScope::findMarker (const String& name, MarkerList*& list) const -{ - const MarkerList::Marker* marker = nullptr; - - Component* const parent = component.getParentComponent(); - - if (parent != nullptr) - { - list = parent->getMarkers (true); - if (list != nullptr) - marker = list->getMarker (name); - - if (marker == nullptr) - { - list = parent->getMarkers (false); - - if (list != nullptr) - marker = list->getMarker (name); - } - } - - return marker; + return parent != nullptr ? parent->findChildWithID (componentID) + : nullptr; } //============================================================================== @@ -126,29 +169,41 @@ public: Expression getSymbolValue (const String& symbol) const { - if (symbol == RelativeCoordinate::Strings::left || symbol == RelativeCoordinate::Strings::x - || symbol == RelativeCoordinate::Strings::width || symbol == RelativeCoordinate::Strings::right - || symbol == RelativeCoordinate::Strings::top || symbol == RelativeCoordinate::Strings::y - || symbol == RelativeCoordinate::Strings::height || symbol == RelativeCoordinate::Strings::bottom) + switch (RelativeCoordinate::StandardStrings::getTypeOf (symbol)) { - positioner.registerComponentListener (component); - } - else - { - MarkerList* list; - const MarkerList::Marker* const marker = findMarker (symbol, list); + case RelativeCoordinate::StandardStrings::x: + case RelativeCoordinate::StandardStrings::left: + case RelativeCoordinate::StandardStrings::y: + case RelativeCoordinate::StandardStrings::top: + case RelativeCoordinate::StandardStrings::width: + case RelativeCoordinate::StandardStrings::height: + case RelativeCoordinate::StandardStrings::right: + case RelativeCoordinate::StandardStrings::bottom: + positioner.registerComponentListener (component); + break; - if (marker != nullptr) + default: { - positioner.registerMarkerListListener (list); - } - else - { - // The marker we want doesn't exist, so watch all lists in case they change and the marker appears later.. - positioner.registerMarkerListListener (component.getMarkers (true)); - positioner.registerMarkerListListener (component.getMarkers (false)); - ok = false; + Component* const parent = component.getParentComponent(); + if (parent != nullptr) + { + MarkerList* list; + const MarkerList::Marker* marker = MarkerListScope::findMarker (*parent, symbol, list); + + if (marker != nullptr) + { + positioner.registerMarkerListListener (list); + } + else + { + // The marker we want doesn't exist, so watch all lists in case they change and the marker appears later.. + positioner.registerMarkerListListener (parent->getMarkers (true)); + positioner.registerMarkerListListener (parent->getMarkers (false)); + ok = false; + } + } } + break; } return ComponentScope::getSymbolValue (symbol); @@ -156,12 +211,9 @@ public: void visitRelativeScope (const String& scopeName, Visitor& visitor) const { - Component* targetComp = nullptr; - - if (scopeName == RelativeCoordinate::Strings::parent) - targetComp = component.getParentComponent(); - else - targetComp = findSiblingComponent (scopeName); + Component* const targetComp = (scopeName == RelativeCoordinate::Strings::parent) + ? component.getParentComponent() + : findSiblingComponent (scopeName); if (targetComp != nullptr) { diff --git a/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.h b/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.h index fbdc6c15b9..919ee53998 100644 --- a/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.h +++ b/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.h @@ -70,7 +70,6 @@ public: Component& component; Component* findSiblingComponent (const String& componentID) const; - const MarkerList::Marker* findMarker (const String& name, MarkerList*& list) const; private: JUCE_DECLARE_NON_COPYABLE (ComponentScope); diff --git a/modules/juce_opengl/opengl/juce_OpenGLComponent.cpp b/modules/juce_opengl/opengl/juce_OpenGLComponent.cpp index 5c567f9804..8bba960cce 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLComponent.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLComponent.cpp @@ -397,10 +397,8 @@ bool OpenGLComponent::performRender() renderOpenGL(); - if (needToRepaint && (flags & allowSubComponents) != 0) + if ((flags & allowSubComponents) != 0) { - needToRepaint = false; - contextLock.exit(); // (MM must be locked before the context lock) MessageManagerLock mmLock (renderThread); contextLock.enter(); @@ -414,7 +412,10 @@ bool OpenGLComponent::performRender() const Rectangle bounds (getLocalBounds()); OpenGLFrameBuffer& frameBuffer = cachedImage->getFrameBuffer (bounds.getWidth(), bounds.getHeight()); + if (needToRepaint) { + needToRepaint = false; + RectangleList invalid (bounds); invalid.subtract (cachedImage->validArea); cachedImage->validArea = bounds; @@ -442,8 +443,8 @@ bool OpenGLComponent::performRender() context->extensions.glActiveTexture (GL_TEXTURE0); glBindTexture (GL_TEXTURE_2D, frameBuffer.getTextureID()); - context->copyTexture (bounds, Rectangle (bounds.getWidth(), - bounds.getHeight())); + jassert (bounds.getPosition() == Point()); + context->copyTexture (bounds, bounds); glBindTexture (GL_TEXTURE_2D, 0); } diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp index 82c7d16486..4310b3d543 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp @@ -609,10 +609,11 @@ public: "void main()" "{" JUCE_HIGHP " vec2 texturePos = " JUCE_MATRIX_TIMES_FRAGCOORD ";" - "if (texturePos.x >= imageLimits.x" - "&& texturePos.y >= imageLimits.y" - "&& texturePos.x < imageLimits.z" - "&& texturePos.y < imageLimits.w)" + "const float roundingError = 0.00001;" + "if (texturePos.x >= imageLimits.x - roundingError" + "&& texturePos.y >= imageLimits.y - roundingError" + "&& texturePos.x <= imageLimits.z + roundingError" + "&& texturePos.y <= imageLimits.w + roundingError)" "gl_FragColor = frontColour * " JUCE_GET_IMAGE_PIXEL ".a;" "else " "gl_FragColor = vec4 (0, 0, 0, 0);" @@ -3208,7 +3209,7 @@ private: return fillType.transformed (transform.getTransform()); } - void fillEdgeTable (EdgeTable& et) + void fillEdgeTable (EdgeTable& et) const { clip->fillEdgeTable (et, getFillType()); }