Fixing wxGLCanvas under 10.14, preparing for layer based drawing

see https://github.com/wxWidgets/wxWidgets/pull/846 , thanks to dkulp
This commit is contained in:
Stefan Csomor
2018-06-30 16:57:57 +02:00
parent 24dbe9775c
commit 2ab430965c
6 changed files with 364 additions and 72 deletions

View File

@@ -158,7 +158,6 @@ public:
// implementation-only from now on // implementation-only from now on
protected: protected:
#if wxOSX_USE_IPHONE
bool DoCreate(wxWindow *parent, bool DoCreate(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxPoint& pos, const wxPoint& pos,
@@ -166,7 +165,6 @@ protected:
long style, long style,
const wxString& name); const wxString& name);
#endif
WXGLPixelFormat m_glFormat; WXGLPixelFormat m_glFormat;
wxGLAttributes m_GLAttrs; wxGLAttributes m_GLAttrs;

View File

@@ -0,0 +1,265 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objects = {
/* Begin PBXBuildFile section */
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765FC0DF74451002DB57D /* CoreGraphics.framework */; };
407A98E11370835D00E92356 /* minimal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 407A98E01370835D00E92356 /* minimal.cpp */; };
407EE18312F04CD500D0F171 /* libwx_osx_iphone.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4074F5E912ED969C00693A3F /* libwx_osx_iphone.a */; };
407EE18A12F04CF900D0F171 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 407EE18912F04CF900D0F171 /* AudioToolbox.framework */; };
40803704158A894A00EC5CA7 /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 40803703158A894A00EC5CA7 /* CoreText.framework */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
4074F5E812ED969C00693A3F /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 404BECC510EBDB420080E2B8 /* wxiphone.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = B4DEA098A05736AE94F01926;
remoteInfo = static;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
1D6058910D05DD3D006BFB54 /* minimal_iphone.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = minimal_iphone.app; sourceTree = BUILT_PRODUCTS_DIR; };
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
288765FC0DF74451002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
404BECC510EBDB420080E2B8 /* wxiphone.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = wxiphone.xcodeproj; path = ../../build/osx/wxiPhone.xcodeproj; sourceTree = SOURCE_ROOT; };
404BEE0510EC7BF20080E2B8 /* wxiphone.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = wxiphone.xcconfig; path = ../../build/osx/wxiphone.xcconfig; sourceTree = SOURCE_ROOT; };
407A98E01370835D00E92356 /* minimal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = minimal.cpp; sourceTree = "<group>"; };
407A98FA137084FB00E92356 /* Info_iphone.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info_iphone.plist; sourceTree = "<group>"; };
407EE18912F04CF900D0F171 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
40803703158A894A00EC5CA7 /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = System/Library/Frameworks/CoreText.framework; sourceTree = SDKROOT; };
409CBDC913B13C7100AB1F39 /* wxdebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = wxdebug.xcconfig; path = ../../build/osx/wxdebug.xcconfig; sourceTree = SOURCE_ROOT; };
409CBDCA13B13C7100AB1F39 /* wxrelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = wxrelease.xcconfig; path = ../../build/osx/wxrelease.xcconfig; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
1D60588F0D05DD3D006BFB54 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */,
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */,
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */,
407EE18312F04CD500D0F171 /* libwx_osx_iphone.a in Frameworks */,
407EE18A12F04CF900D0F171 /* AudioToolbox.framework in Frameworks */,
40803704158A894A00EC5CA7 /* CoreText.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
1D6058910D05DD3D006BFB54 /* minimal_iphone.app */,
);
name = Products;
sourceTree = "<group>";
};
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
407A98FA137084FB00E92356 /* Info_iphone.plist */,
404BEE0510EC7BF20080E2B8 /* wxiphone.xcconfig */,
409CBDC913B13C7100AB1F39 /* wxdebug.xcconfig */,
409CBDCA13B13C7100AB1F39 /* wxrelease.xcconfig */,
404BECC510EBDB420080E2B8 /* wxiphone.xcodeproj */,
404BECD110EBDC6F0080E2B8 /* src */,
29B97317FDCFA39411CA2CEA /* Resources */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
);
name = CustomTemplate;
sourceTree = "<group>";
};
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
);
name = Resources;
sourceTree = "<group>";
};
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */,
1D30AB110D05D00D00671497 /* Foundation.framework */,
288765FC0DF74451002DB57D /* CoreGraphics.framework */,
407EE18912F04CF900D0F171 /* AudioToolbox.framework */,
40803703158A894A00EC5CA7 /* CoreText.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
404BECC610EBDB420080E2B8 /* Products */ = {
isa = PBXGroup;
children = (
4074F5E912ED969C00693A3F /* libwx_osx_iphone.a */,
);
name = Products;
sourceTree = "<group>";
};
404BECD110EBDC6F0080E2B8 /* src */ = {
isa = PBXGroup;
children = (
407A98E01370835D00E92356 /* minimal.cpp */,
);
name = src;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
1D6058900D05DD3D006BFB54 /* static */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "static" */;
buildPhases = (
1D60588D0D05DD3D006BFB54 /* Resources */,
1D60588E0D05DD3D006BFB54 /* Sources */,
1D60588F0D05DD3D006BFB54 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = static;
productName = minimal_iphone;
productReference = 1D6058910D05DD3D006BFB54 /* minimal_iphone.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "minimal_iphone" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
Japanese,
French,
German,
);
mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = 404BECC610EBDB420080E2B8 /* Products */;
ProjectRef = 404BECC510EBDB420080E2B8 /* wxiphone.xcodeproj */;
},
);
projectRoot = "";
targets = (
1D6058900D05DD3D006BFB54 /* static */,
);
};
/* End PBXProject section */
/* Begin PBXReferenceProxy section */
4074F5E912ED969C00693A3F /* libwx_osx_iphone.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libwx_osx_iphone.a;
remoteRef = 4074F5E812ED969C00693A3F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */
/* Begin PBXResourcesBuildPhase section */
1D60588D0D05DD3D006BFB54 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
1D60588E0D05DD3D006BFB54 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
407A98E11370835D00E92356 /* minimal.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
1D6058940D05DD3E006BFB54 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 404BEE0510EC7BF20080E2B8 /* wxiphone.xcconfig */;
buildSettings = {
OTHER_LDFLAGS = "";
PRODUCT_NAME = minimal_iphone;
};
name = Debug;
};
1D6058950D05DD3E006BFB54 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 404BEE0510EC7BF20080E2B8 /* wxiphone.xcconfig */;
buildSettings = {
PRODUCT_NAME = minimal_iphone;
};
name = Release;
};
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 409CBDC913B13C7100AB1F39 /* wxdebug.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = Info_iphone.plist;
PROVISIONING_PROFILE = "";
WXROOT = "$(PROJECT_DIR)/../..";
};
name = Debug;
};
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 409CBDCA13B13C7100AB1F39 /* wxrelease.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Distribution";
INFOPLIST_FILE = Info_iphone.plist;
PROVISIONING_PROFILE = "";
WXROOT = "$(PROJECT_DIR)/../..";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "static" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1D6058940D05DD3E006BFB54 /* Debug */,
1D6058950D05DD3E006BFB54 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "minimal_iphone" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4F08A954540054247B /* Debug */,
C01FCF5008A954540054247B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
}

View File

@@ -152,7 +152,6 @@ wxPaintDCImpl::wxPaintDCImpl( wxDC *owner )
wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *window ) : wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *window ) :
wxWindowDCImpl( owner, window ) wxWindowDCImpl( owner, window )
{ {
wxASSERT_MSG( window->MacGetCGContextRef() != NULL, wxT("using wxPaintDC without being in a native paint event") );
wxPoint origin = window->GetClientAreaOrigin() ; wxPoint origin = window->GetClientAreaOrigin() ;
m_window->GetClientSize( &m_width , &m_height); m_window->GetClientSize( &m_width , &m_height);
SetDeviceOrigin( origin.x, origin.y ); SetDeviceOrigin( origin.x, origin.y );

View File

@@ -112,9 +112,8 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *GLAttrs,
return [[NSOpenGLPixelFormat alloc] initWithAttributes:(NSOpenGLPixelFormatAttribute*) attribs]; return [[NSOpenGLPixelFormat alloc] initWithAttributes:(NSOpenGLPixelFormatAttribute*) attribs];
} }
@interface wxNSCustomOpenGLView : NSView @interface wxNSCustomOpenGLView : NSOpenGLView
{ {
NSOpenGLContext* context;
} }
@end @end
@@ -138,6 +137,30 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *GLAttrs,
@end @end
bool wxGLCanvas::DoCreate(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
DontCreatePeer();
if ( !wxWindow::Create(parent, id, pos, size, style, name) )
return false;
NSRect r = wxOSXGetFrameForControl( this, pos , size ) ;
wxNSCustomOpenGLView* v = [[wxNSCustomOpenGLView alloc] initWithFrame:r];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( this, v, false, true );
SetPeer(c);
MacPostControlCreate(pos, size) ;
return true;
}
wxGLCanvas::~wxGLCanvas() wxGLCanvas::~wxGLCanvas()
{ {
if ( m_glFormat ) if ( m_glFormat )

View File

@@ -2291,8 +2291,11 @@ void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
wxpeer->GetUpdateRegion() = updateRgn; wxpeer->GetUpdateRegion() = updateRgn;
// setting up the drawing context // setting up the drawing context
// note that starting from 10.14 this may be NULL in certain views
CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
wxpeer->MacSetCGContextRef( context );
if ( context != NULL )
{
CGContextSaveGState( context ); CGContextSaveGState( context );
#if OSX_DEBUG_DRAWING #if OSX_DEBUG_DRAWING
@@ -2315,22 +2318,30 @@ void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height ); CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
CGContextScaleCTM( context, 1, -1 ); CGContextScaleCTM( context, 1, -1 );
} }
}
wxpeer->MacSetCGContextRef( context );
bool handled = wxpeer->MacDoRedraw( 0 ); bool handled = wxpeer->MacDoRedraw( 0 );
if ( context != NULL )
{
CGContextRestoreGState( context ); CGContextRestoreGState( context );
CGContextSaveGState( context ); CGContextSaveGState( context );
}
if ( !handled ) if ( !handled )
{ {
// call super // call super
SEL _cmd = @selector(drawRect:); SEL _cmd = @selector(drawRect:);
wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd]; wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
superimpl(slf, _cmd, *(NSRect*)rect); superimpl(slf, _cmd, *(NSRect*)rect);
if ( context != NULL )
{
CGContextRestoreGState( context ); CGContextRestoreGState( context );
CGContextSaveGState( context ); CGContextSaveGState( context );
} }
}
if ( context != NULL )
{
// as we called restore above, we have to flip again if necessary // as we called restore above, we have to flip again if necessary
if ( ![slf isFlipped] ) if ( ![slf isFlipped] )
{ {
@@ -2367,8 +2378,9 @@ void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
} }
wxpeer->MacPaintChildrenBorders(); wxpeer->MacPaintChildrenBorders();
wxpeer->MacSetCGContextRef( NULL );
CGContextRestoreGState( context ); CGContextRestoreGState( context );
}
wxpeer->MacSetCGContextRef( NULL );
} }
void wxWidgetCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender)) void wxWidgetCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))

View File

@@ -501,13 +501,8 @@ bool wxGLCanvas::Create(wxWindow *parent,
// Make a copy of attributes. Will use at wxGLContext ctor // Make a copy of attributes. Will use at wxGLContext ctor
m_GLAttrs = dispAttrs; m_GLAttrs = dispAttrs;
#if wxOSX_USE_IPHONE
if ( !wxGLCanvas::DoCreate(parent,id,pos,size,style,name) ) if ( !wxGLCanvas::DoCreate(parent,id,pos,size,style,name) )
return false; return false;
#else
if ( !wxWindow::Create(parent, id, pos, size, style, name) )
return false;
#endif
return true; return true;
} }