From 507ead3c5adebd1b519857602d39c7666f98fe8b Mon Sep 17 00:00:00 2001 From: kgv Date: Mon, 13 Jun 2022 10:13:53 +0300 Subject: [PATCH] 0032991: Visualization, TKOpenGl - OpenGl_Window::Resize() ignores window virtual flag on macOS Added handling of Aspect_Window::IsVirtual() flag on macOS platform (7.6.x backport). --- src/Cocoa/Cocoa_Window.mm | 9 --- src/OpenGl/OpenGl_Window_1.mm | 69 +++++++++++++--------- src/ViewerTest/ViewerTest_EventManager.cxx | 4 +- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/Cocoa/Cocoa_Window.mm b/src/Cocoa/Cocoa_Window.mm index d491b11e17..cd42e414eb 100644 --- a/src/Cocoa/Cocoa_Window.mm +++ b/src/Cocoa/Cocoa_Window.mm @@ -436,15 +436,6 @@ void Cocoa_Window::InvalidateContent (const Handle(Aspect_DisplayConnection)& ) return; } - if ([NSThread isMainThread]) - { - #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE - [myHView setNeedsDisplay]; - #else - [myHView setNeedsDisplay: YES]; - #endif - } - else { [myHView performSelectorOnMainThread: @selector(invalidateContentOcct:) withObject: NULL diff --git a/src/OpenGl/OpenGl_Window_1.mm b/src/OpenGl/OpenGl_Window_1.mm index 49108d4f2b..03ecdab6a0 100644 --- a/src/OpenGl/OpenGl_Window_1.mm +++ b/src/OpenGl/OpenGl_Window_1.mm @@ -264,11 +264,20 @@ OpenGl_Window::~OpenGl_Window() void OpenGl_Window::Resize() { // If the size is not changed - do nothing - Standard_Integer aWidthPt = 0; - Standard_Integer aHeightPt = 0; - myPlatformWindow->Size (aWidthPt, aHeightPt); - if (myWidthPt == aWidthPt - && myHeightPt == aHeightPt) + Graphic3d_Vec2i aWinSize; + myPlatformWindow->Size (aWinSize.x(), aWinSize.y()); + if (myPlatformWindow->IsVirtual()) + { + if (myWidth == aWinSize.x() + && myHeight == aWinSize.y()) + { + return; + } + myWidth = aWinSize.x(); + myHeight = aWinSize.y(); + } + else if (myWidthPt == aWinSize.x() + && myHeightPt == aWinSize.y()) { #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE return; @@ -293,8 +302,8 @@ void OpenGl_Window::Resize() #endif } - myWidthPt = aWidthPt; - myHeightPt = aHeightPt; + myWidthPt = aWinSize.x(); + myHeightPt = aWinSize.y(); Init(); } @@ -356,35 +365,39 @@ void OpenGl_Window::Init() aDefFbo->BindBuffer (myGlContext); aDefFbo.Nullify(); #else - NSOpenGLContext* aGLCtx = myGlContext->myGContext; -Standard_DISABLE_DEPRECATION_WARNINGS - NSView* aView = [aGLCtx view]; -Standard_ENABLE_DEPRECATION_WARNINGS - NSRect aBounds = [aView bounds]; + if (!myPlatformWindow->IsVirtual()) + { + NSOpenGLContext* aGLCtx = myGlContext->myGContext; + Standard_DISABLE_DEPRECATION_WARNINGS + NSView* aView = [aGLCtx view]; + Standard_ENABLE_DEPRECATION_WARNINGS + NSRect aBounds = [aView bounds]; - // we should call this method each time when window is resized - [aGLCtx update]; + // we should call this method each time when window is resized + [aGLCtx update]; - if ([aView respondsToSelector: @selector(convertSizeToBacking:)]) - { - NSSize aRes = [aView convertSizeToBacking: aBounds.size]; - myWidth = Standard_Integer(aRes.width); - myHeight = Standard_Integer(aRes.height); - } - else - { - myWidth = Standard_Integer(aBounds.size.width); - myHeight = Standard_Integer(aBounds.size.height); + if ([aView respondsToSelector: @selector(convertSizeToBacking:)]) + { + NSSize aRes = [aView convertSizeToBacking: aBounds.size]; + myWidth = Standard_Integer(aRes.width); + myHeight = Standard_Integer(aRes.height); + } + else + { + myWidth = Standard_Integer(aBounds.size.width); + myHeight = Standard_Integer(aBounds.size.height); + } + myWidthPt = Standard_Integer(aBounds.size.width); + myHeightPt = Standard_Integer(aBounds.size.height); } - myWidthPt = Standard_Integer(aBounds.size.width); - myHeightPt = Standard_Integer(aBounds.size.height); #endif ::glDisable (GL_DITHER); ::glDisable (GL_SCISSOR_TEST); - ::glViewport (0, 0, myWidth, myHeight); + const Standard_Integer aViewport[4] = { 0, 0, myWidth, myHeight }; + myGlContext->ResizeViewport (aViewport); #if !defined(GL_ES_VERSION_2_0) - ::glDrawBuffer (GL_BACK); + myGlContext->SetDrawBuffer (GL_BACK); if (myGlContext->core11ffp != NULL) { ::glMatrixMode (GL_MODELVIEW); diff --git a/src/ViewerTest/ViewerTest_EventManager.cxx b/src/ViewerTest/ViewerTest_EventManager.cxx index 3335af811f..e0fc6f558a 100644 --- a/src/ViewerTest/ViewerTest_EventManager.cxx +++ b/src/ViewerTest/ViewerTest_EventManager.cxx @@ -196,7 +196,7 @@ void ViewerTest_EventManager::handleViewRedraw (const Handle(AIS_InteractiveCont && (!aRedrawer.IsStarted() || aRedrawer.IsPaused())) { myIsTmpContRedraw = true; - #if !defined(_WIN32) && !defined(__EMSCRIPTEN__) + #if !defined(_WIN32) && !defined(__EMSCRIPTEN__) && !defined(__APPLE__) aRedrawer.Start (theView, 60.0); #endif } @@ -210,7 +210,7 @@ void ViewerTest_EventManager::handleViewRedraw (const Handle(AIS_InteractiveCont else if (myIsTmpContRedraw) { myIsTmpContRedraw = false; - #ifndef _WIN32 + #if !defined(_WIN32) && !defined(__APPLE__) ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance(); aRedrawer.Pause(); #endif -- 2.39.5