Removing non-native bitmap code, using common code for iOS and macOS
This commit is contained in:
committed by
Vadim Zeitlin
parent
bca583234e
commit
266f32493e
@@ -2764,6 +2764,7 @@ DECLARE_WXCOCOA_OBJC_CLASS(NSString);
|
||||
|
||||
typedef WX_NSWindow WXWindow;
|
||||
typedef WX_NSView WXWidget;
|
||||
typedef WX_NSImage WXImage;
|
||||
typedef WX_NSMenu WXHMENU;
|
||||
typedef WX_NSOpenGLPixelFormat WXGLPixelFormat;
|
||||
typedef WX_NSOpenGLContext WXGLContext;
|
||||
@@ -2771,6 +2772,7 @@ typedef WX_NSOpenGLContext WXGLContext;
|
||||
#elif wxOSX_USE_IPHONE
|
||||
|
||||
DECLARE_WXCOCOA_OBJC_CLASS(UIWindow);
|
||||
DECLARE_WXCOCOA_OBJC_CLASS(UImage);
|
||||
DECLARE_WXCOCOA_OBJC_CLASS(UIView);
|
||||
DECLARE_WXCOCOA_OBJC_CLASS(UIFont);
|
||||
DECLARE_WXCOCOA_OBJC_CLASS(UIImage);
|
||||
@@ -2781,6 +2783,7 @@ DECLARE_WXCOCOA_OBJC_CLASS(UIWebView);
|
||||
|
||||
typedef WX_UIWindow WXWindow;
|
||||
typedef WX_UIView WXWidget;
|
||||
typedef WX_UIImage WXImage;
|
||||
typedef WX_EAGLContext WXGLContext;
|
||||
typedef WX_NSString WXGLPixelFormat;
|
||||
typedef WX_UIWebView OSXWebViewPtr;
|
||||
|
@@ -118,7 +118,7 @@ public:
|
||||
|
||||
// creates an bitmap from the native image format
|
||||
wxBitmap(CGImageRef image, double scale = 1.0);
|
||||
wxBitmap(WX_NSImage image);
|
||||
wxBitmap(WXImage image);
|
||||
wxBitmap(CGContextRef bitmapcontext);
|
||||
|
||||
// Create a bitmap compatible with the given DC
|
||||
@@ -147,7 +147,7 @@ public:
|
||||
|
||||
virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
|
||||
bool Create( CGImageRef image, double scale = 1.0 );
|
||||
bool Create( WX_NSImage image );
|
||||
bool Create( WXImage image );
|
||||
bool Create( CGContextRef bitmapcontext);
|
||||
|
||||
// Create a bitmap compatible with the given DC, inheriting its magnification factor
|
||||
@@ -207,13 +207,16 @@ public:
|
||||
// returns a CGImageRef which must released after usage with CGImageRelease
|
||||
CGImageRef CreateCGImage() const ;
|
||||
|
||||
WXImage GetImage() const;
|
||||
#if wxOSX_USE_COCOA
|
||||
// returns an autoreleased version of the image
|
||||
WX_NSImage GetNSImage() const;
|
||||
WX_NSImage GetNSImage() const
|
||||
{ return GetImage(); }
|
||||
#endif
|
||||
#if wxOSX_USE_IPHONE
|
||||
// returns an autoreleased version of the image
|
||||
WX_UIImage GetUIImage() const;
|
||||
WX_UIImage GetUIImage() const
|
||||
{ return GetImage(); }
|
||||
#endif
|
||||
|
||||
#if WXWIN_COMPATIBILITY_3_0
|
||||
|
@@ -41,10 +41,6 @@ WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image, double
|
||||
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref );
|
||||
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetIconForType(OSType type );
|
||||
void WXDLLIMPEXP_CORE wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height);
|
||||
CGSize WXDLLIMPEXP_CORE wxOSXGetImageSize(WX_NSImage image);
|
||||
CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scale = NULL );
|
||||
CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromNSImage( WX_NSImage nsimage, CGRect* r, CGContextRef cg);
|
||||
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage, bool *isTemplate = NULL);
|
||||
|
||||
wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
|
||||
WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
|
||||
|
@@ -114,6 +114,15 @@ WXDLLIMPEXP_CORE CGColorSpaceRef wxMacGetGenericRGBColorSpace(void);
|
||||
|
||||
WXDLLIMPEXP_CORE double wxOSXGetMainScreenContentScaleFactor();
|
||||
|
||||
// UI
|
||||
|
||||
CGSize WXDLLIMPEXP_CORE wxOSXGetImageSize(WXImage image);
|
||||
CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromImage( WXImage nsimage, double *scale = NULL );
|
||||
CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromImage( WXImage nsimage, CGRect* r, CGContextRef cg);
|
||||
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromImage( WXImage nsimage, bool *isTemplate = NULL);
|
||||
WXImage WXDLLIMPEXP_CORE wxOSXGetImageFromCGImage( CGImageRef image, double scale = 1.0, bool isTemplate = false);
|
||||
|
||||
|
||||
class wxWindowMac;
|
||||
// to
|
||||
extern wxWindow* g_MacLastWindow;
|
||||
|
@@ -165,11 +165,6 @@ WXWindow wxOSXGetKeyWindow()
|
||||
|
||||
#if wxOSX_USE_IPHONE
|
||||
|
||||
WX_UIImage wxOSXGetUIImageFromCGImage( CGImageRef image )
|
||||
{
|
||||
return [UIImage imageWithCGImage:image];
|
||||
}
|
||||
|
||||
wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &client, const wxSize& size)
|
||||
{
|
||||
#if 1
|
||||
@@ -181,29 +176,11 @@ wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &client, c
|
||||
#endif
|
||||
}
|
||||
|
||||
double wxOSXGetMainScreenContentScaleFactor()
|
||||
{
|
||||
double scale;
|
||||
|
||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
|
||||
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
|
||||
{
|
||||
scale=[[UIScreen mainScreen] scale];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
scale=1.0;
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if wxOSX_USE_COCOA
|
||||
|
||||
WX_NSImage wxOSXGetSystemImage(const wxString& name)
|
||||
WXImage wxOSXGetSystemImage(const wxString& name)
|
||||
{
|
||||
wxCFStringRef cfname(name);
|
||||
NSImage* nsimage = [NSImage imageNamed:cfname.AsNSString()];
|
||||
@@ -222,38 +199,47 @@ wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &client, c
|
||||
return wxNullBitmap;
|
||||
}
|
||||
|
||||
WX_NSImage wxOSXGetNSImageFromCGImage( CGImageRef image, double scaleFactor, bool isTemplate )
|
||||
#endif
|
||||
|
||||
WXImage wxOSXGetImageFromCGImage( CGImageRef image, double scaleFactor, bool isTemplate )
|
||||
{
|
||||
NSRect imageRect = NSMakeRect(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
// Get the image dimensions.
|
||||
imageRect.size.height = CGImageGetHeight(image)/scaleFactor;
|
||||
imageRect.size.width = CGImageGetWidth(image)/scaleFactor;
|
||||
|
||||
NSImage* newImage = [[NSImage alloc] initWithCGImage:image size:imageRect.size];
|
||||
#if wxOSX_USE_COCOA
|
||||
NSSize sz;
|
||||
sz.height = CGImageGetHeight(image)/scaleFactor;
|
||||
sz.width = CGImageGetWidth(image)/scaleFactor;
|
||||
NSImage* newImage = [[NSImage alloc] initWithCGImage:image size:sz];
|
||||
|
||||
[newImage setTemplate:isTemplate];
|
||||
|
||||
[newImage autorelease];
|
||||
return( newImage );
|
||||
#else
|
||||
return [UIImage imageWithCGImage:image scale:scaleFactor orientation:UIImageOrientationUp];
|
||||
#endif
|
||||
}
|
||||
|
||||
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref )
|
||||
#if wxOSX_USE_ICONREF
|
||||
WXImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref )
|
||||
{
|
||||
NSImage *newImage = [[NSImage alloc] initWithIconRef:iconref];
|
||||
[newImage autorelease];
|
||||
return( newImage );
|
||||
}
|
||||
#endif
|
||||
|
||||
CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromNSImage( WX_NSImage nsimage, CGRect* r, CGContextRef cg)
|
||||
CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromImage( WXImage nsimage, CGRect* r, CGContextRef cg)
|
||||
{
|
||||
#if wxOSX_USE_COCOA
|
||||
NSRect nsRect = NSRectFromCGRect(*r);
|
||||
return [nsimage CGImageForProposedRect:&nsRect
|
||||
context:[NSGraphicsContext graphicsContextWithGraphicsPort:cg flipped:YES]
|
||||
hints:nil];
|
||||
#else
|
||||
return [nsimage CGImage];
|
||||
#endif
|
||||
}
|
||||
|
||||
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage, bool *isTemplate)
|
||||
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromImage( WXImage nsimage, bool *isTemplate)
|
||||
{
|
||||
// based on http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg18065.html
|
||||
|
||||
@@ -262,12 +248,17 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns
|
||||
{
|
||||
double scale = wxOSXGetMainScreenContentScaleFactor();
|
||||
|
||||
#if wxOSX_USE_COCOA
|
||||
NSSize imageSize = [nsimage size];
|
||||
#else
|
||||
CGSize imageSize = [nsimage size];
|
||||
#endif
|
||||
|
||||
hbitmap = CGBitmapContextCreate(NULL, imageSize.width*scale, imageSize.height*scale, 8, 0, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst);
|
||||
CGContextScaleCTM( hbitmap, scale, scale );
|
||||
CGContextClearRect(hbitmap,CGRectMake(0, 0, imageSize.width, imageSize.height));
|
||||
|
||||
#if wxOSX_USE_COCOA
|
||||
NSGraphicsContext *previousContext = [NSGraphicsContext currentContext];
|
||||
NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:hbitmap flipped:NO];
|
||||
[NSGraphicsContext setCurrentContext:nsGraphicsContext];
|
||||
@@ -276,6 +267,10 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns
|
||||
|
||||
if (isTemplate)
|
||||
*isTemplate = [nsimage isTemplate];
|
||||
#else
|
||||
wxUnusedVar(isTemplate);
|
||||
CGContextDrawImage(hbitmap,CGRectMake(0, 0, imageSize.width, imageSize.height),[nsimage CGImage]);
|
||||
#endif
|
||||
}
|
||||
return hbitmap;
|
||||
}
|
||||
@@ -283,7 +278,7 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns
|
||||
void WXDLLIMPEXP_CORE wxOSXDrawNSImage(
|
||||
CGContextRef inContext,
|
||||
const CGRect * inBounds,
|
||||
WX_NSImage inImage)
|
||||
WXImage inImage)
|
||||
{
|
||||
if (inImage != nil)
|
||||
{
|
||||
@@ -293,12 +288,15 @@ void WXDLLIMPEXP_CORE wxOSXDrawNSImage(
|
||||
r.origin.x = r.origin.y = 0;
|
||||
CGContextScaleCTM(inContext, 1, -1);
|
||||
|
||||
#if wxOSX_USE_COCOA
|
||||
NSGraphicsContext *previousContext = [NSGraphicsContext currentContext];
|
||||
NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:inContext flipped:NO];
|
||||
[NSGraphicsContext setCurrentContext:nsGraphicsContext];
|
||||
[inImage drawInRect:NSRectFromCGRect(r) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
|
||||
[NSGraphicsContext setCurrentContext:previousContext];
|
||||
|
||||
#else
|
||||
CGContextDrawImage(inContext, *inBounds, [inImage CGImage]);
|
||||
#endif
|
||||
CGContextRestoreGState(inContext);
|
||||
|
||||
}
|
||||
@@ -306,30 +304,50 @@ void WXDLLIMPEXP_CORE wxOSXDrawNSImage(
|
||||
|
||||
double wxOSXGetMainScreenContentScaleFactor()
|
||||
{
|
||||
#if wxOSX_USE_COCOA
|
||||
return [[NSScreen mainScreen] backingScaleFactor];
|
||||
#else
|
||||
return [[UIScreen mainScreen] scale];
|
||||
#endif
|
||||
}
|
||||
|
||||
WX_NSImage wxOSXGetIconForType(OSType type )
|
||||
WXImage wxOSXGetIconForType(OSType type )
|
||||
{
|
||||
#if wxOSX_USE_COCOA
|
||||
return [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode(type)];
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height)
|
||||
void wxOSXSetImageSize(WXImage image, CGFloat width, CGFloat height)
|
||||
{
|
||||
#if wxOSX_USE_COCOA
|
||||
[image setSize:NSMakeSize(width, height)];
|
||||
#else
|
||||
// TODO
|
||||
#endif
|
||||
}
|
||||
|
||||
CGSize wxOSXGetImageSize(WX_NSImage image)
|
||||
CGSize wxOSXGetImageSize(WXImage image)
|
||||
{
|
||||
#if wxOSX_USE_COCOA
|
||||
return NSSizeToCGSize([image size]);
|
||||
#else
|
||||
return [image size];
|
||||
#endif
|
||||
}
|
||||
|
||||
CGImageRef wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scaleptr )
|
||||
CGImageRef wxOSXCreateCGImageFromImage( WXImage nsimage, double *scaleptr )
|
||||
{
|
||||
CGImageRef image = NULL;
|
||||
if (nsimage != nil)
|
||||
{
|
||||
#if wxOSX_USE_COCOA
|
||||
image = [nsimage CGImageForProposedRect:nil context:nil hints:nil];
|
||||
#else
|
||||
image = [nsimage CGImage];
|
||||
#endif
|
||||
CFRetain(image);
|
||||
if ( scaleptr )
|
||||
*scaleptr = CGImageGetWidth(image)/[nsimage size].width;
|
||||
@@ -343,6 +361,8 @@ CGImageRef wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scaleptr )
|
||||
|
||||
// copied from cursor.mm
|
||||
|
||||
#if wxOSX_USE_COCOA
|
||||
|
||||
static NSCursor* wxGetStockCursor( short sIndex )
|
||||
{
|
||||
ClassicCursor* pCursor = &gMacCursors[sIndex];
|
||||
@@ -560,6 +580,7 @@ void wxMacCocoaShowCursor()
|
||||
{
|
||||
[NSCursor unhide];
|
||||
}
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------
|
||||
// helper functions for NSString<->wxString conversion
|
||||
@@ -588,6 +609,8 @@ NSString* wxNSStringWithWxString(const wxString &wxstring)
|
||||
// appearance in effect
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxOSX_USE_COCOA
|
||||
|
||||
wxOSXEffectiveAppearanceSetter::wxOSXEffectiveAppearanceSetter()
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
|
||||
|
@@ -49,7 +49,7 @@ public:
|
||||
wxBitmapRefData(int width , int height , int depth, double logicalscale = 1.0);
|
||||
wxBitmapRefData(CGContextRef context);
|
||||
wxBitmapRefData(CGImageRef image, double scale);
|
||||
wxBitmapRefData(WX_NSImage image);
|
||||
wxBitmapRefData(WXImage image);
|
||||
wxBitmapRefData();
|
||||
wxBitmapRefData(const wxBitmapRefData &tocopy);
|
||||
|
||||
@@ -59,24 +59,12 @@ public:
|
||||
|
||||
void Free();
|
||||
|
||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
||||
int GetWidth() const;
|
||||
int GetHeight() const;
|
||||
int GetDepth() const;
|
||||
int GetBytesPerRow() const;
|
||||
bool HasAlpha() const;
|
||||
WX_NSImage GetNSImage() const;
|
||||
#else
|
||||
void SetWidth( int width ) { m_width = width; }
|
||||
void SetHeight( int height ) { m_height = height; }
|
||||
void SetDepth( int depth ) { m_depth = depth; }
|
||||
|
||||
int GetWidth() const { return m_width; }
|
||||
int GetHeight() const { return m_height; }
|
||||
int GetDepth() const { return m_depth; }
|
||||
int GetBytesPerRow() const { return m_bytesPerRow; }
|
||||
bool HasAlpha() const { return m_hasAlpha; }
|
||||
#endif
|
||||
WXImage GetImage() const;
|
||||
double GetScaleFactor() const { return m_scaleFactor; }
|
||||
|
||||
const void *GetRawAccess() const;
|
||||
@@ -119,24 +107,14 @@ private :
|
||||
bool Create(int width , int height , int depth, double logicalscale);
|
||||
bool Create( CGImageRef image, double scale );
|
||||
bool Create( CGContextRef bitmapcontext);
|
||||
bool Create( WX_NSImage image);
|
||||
bool Create( WXImage image);
|
||||
void Init();
|
||||
|
||||
void EnsureBitmapExists() const;
|
||||
|
||||
void FreeDerivedRepresentations();
|
||||
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
int m_width;
|
||||
int m_height;
|
||||
int m_bytesPerRow;
|
||||
int m_depth;
|
||||
bool m_hasAlpha;
|
||||
wxMemoryBuffer m_memBuf;
|
||||
bool m_ok;
|
||||
#else
|
||||
WX_NSImage m_nsImage;
|
||||
#endif
|
||||
WXImage m_nsImage;
|
||||
int m_rawAccessCount;
|
||||
mutable CGImageRef m_cgImageRef;
|
||||
bool m_isTemplate;
|
||||
@@ -155,7 +133,7 @@ private :
|
||||
static const int kBestByteAlignement = 16;
|
||||
static const int kMaskBytesPerPixel = 1;
|
||||
|
||||
static int GetBestBytesPerRow( int rawBytes )
|
||||
static size_t GetBestBytesPerRow( size_t rawBytes )
|
||||
{
|
||||
return (((rawBytes)+kBestByteAlignement-1) & ~(kBestByteAlignement-1) );
|
||||
}
|
||||
@@ -176,15 +154,7 @@ CGImageRef wxMacCreateCGImageFromBitmap( const wxBitmap& bitmap )
|
||||
|
||||
void wxBitmapRefData::Init()
|
||||
{
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
m_width = 0 ;
|
||||
m_height = 0 ;
|
||||
m_depth = 0 ;
|
||||
m_bytesPerRow = 0;
|
||||
m_hasAlpha = false;
|
||||
#else
|
||||
m_nsImage = NULL;
|
||||
#endif
|
||||
m_bitmapMask = NULL ;
|
||||
m_cgImageRef = NULL ;
|
||||
m_isTemplate = false;
|
||||
@@ -238,7 +208,7 @@ wxBitmapRefData::wxBitmapRefData(CGImageRef image, double scale)
|
||||
Create( image, scale );
|
||||
}
|
||||
|
||||
wxBitmapRefData::wxBitmapRefData(WX_NSImage image)
|
||||
wxBitmapRefData::wxBitmapRefData(WXImage image)
|
||||
{
|
||||
Init();
|
||||
Create( image );
|
||||
@@ -249,12 +219,12 @@ void wxBitmapRefData::EnsureBitmapExists() const
|
||||
if ( ! m_hBitmap && m_nsImage)
|
||||
{
|
||||
wxBitmapRefData* t = const_cast<wxBitmapRefData*>(this);
|
||||
t->m_hBitmap = wxOSXCreateBitmapContextFromNSImage(m_nsImage, &t->m_isTemplate);
|
||||
t->m_hBitmap = wxOSXCreateBitmapContextFromImage(m_nsImage, &t->m_isTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool wxBitmapRefData::Create( WX_NSImage image )
|
||||
bool wxBitmapRefData::Create( WXImage image )
|
||||
{
|
||||
m_nsImage = image;
|
||||
|
||||
@@ -269,26 +239,15 @@ bool wxBitmapRefData::Create(CGImageRef image, double scale)
|
||||
{
|
||||
if (image != NULL)
|
||||
{
|
||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
||||
int m_width, m_height, m_depth, m_bytesPerRow;
|
||||
#endif
|
||||
m_width = CGImageGetWidth(image);
|
||||
m_height = CGImageGetHeight(image);
|
||||
m_depth = 32;
|
||||
size_t m_width = CGImageGetWidth(image);
|
||||
size_t m_height = CGImageGetHeight(image);
|
||||
|
||||
m_hBitmap = NULL;
|
||||
m_scaleFactor = scale;
|
||||
|
||||
m_bytesPerRow = GetBestBytesPerRow( m_width * 4 ) ;
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
size_t size = m_bytesPerRow * m_height ;
|
||||
void* data = m_memBuf.GetWriteBuf( size ) ;
|
||||
if ( data != NULL )
|
||||
{
|
||||
memset( data , 0 , size ) ;
|
||||
m_memBuf.UngetWriteBuf( size ) ;
|
||||
#else
|
||||
size_t m_bytesPerRow = GetBestBytesPerRow(m_width * 4);
|
||||
void* data = NULL;
|
||||
#endif
|
||||
|
||||
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image);
|
||||
if (alpha == kCGImageAlphaNone || alpha == kCGImageAlphaNoneSkipFirst || alpha == kCGImageAlphaNoneSkipLast)
|
||||
{
|
||||
@@ -296,9 +255,6 @@ bool wxBitmapRefData::Create(CGImageRef image, double scale)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
m_hasAlpha = true;
|
||||
#endif
|
||||
m_hBitmap = CGBitmapContextCreate((char*)data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst);
|
||||
}
|
||||
CGRect rect = CGRectMake(0, 0, m_width, m_height);
|
||||
@@ -307,9 +263,6 @@ bool wxBitmapRefData::Create(CGImageRef image, double scale)
|
||||
wxASSERT_MSG(m_hBitmap, wxT("Unable to create CGBitmapContext context"));
|
||||
CGContextTranslateCTM(m_hBitmap, 0, m_height);
|
||||
CGContextScaleCTM(m_hBitmap, 1 * m_scaleFactor, -1 * m_scaleFactor);
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
} /* data != NULL */
|
||||
#endif
|
||||
}
|
||||
return IsOk();
|
||||
}
|
||||
@@ -319,94 +272,47 @@ bool wxBitmapRefData::Create(CGContextRef context)
|
||||
if ( context != NULL && CGBitmapContextGetData(context) )
|
||||
{
|
||||
m_hBitmap = context;
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
m_bytesPerRow = CGBitmapContextGetBytesPerRow(context);
|
||||
m_width = CGBitmapContextGetWidth(context);
|
||||
m_height = CGBitmapContextGetHeight(context);
|
||||
m_depth = CGBitmapContextGetBitsPerPixel(context) ;
|
||||
#endif
|
||||
// our own contexts conform to this, always.
|
||||
wxASSERT( GetDepth() == 32 );
|
||||
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
size_t size = GetBytesPerRow() * GetHeight() ;
|
||||
void* data = m_memBuf.GetWriteBuf( size ) ;
|
||||
|
||||
memcpy( data , CGBitmapContextGetData(context) , size ) ;
|
||||
m_memBuf.UngetWriteBuf( size ) ;
|
||||
#endif
|
||||
|
||||
// determine content scale
|
||||
CGRect userrect = CGRectMake(0, 0, 10, 10);
|
||||
CGRect devicerect;
|
||||
devicerect = CGContextConvertRectToDeviceSpace(context, userrect);
|
||||
m_scaleFactor = devicerect.size.height / userrect.size.height;
|
||||
|
||||
CGImageAlphaInfo alpha = CGBitmapContextGetAlphaInfo(context);
|
||||
|
||||
if ( alpha == kCGImageAlphaNone || alpha == kCGImageAlphaNoneSkipFirst || alpha == kCGImageAlphaNoneSkipLast )
|
||||
{
|
||||
// no alpha
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
m_hasAlpha = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return IsOk() ;
|
||||
}
|
||||
|
||||
bool wxBitmapRefData::Create(int w, int h, int d, double logicalscale)
|
||||
{
|
||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
||||
int m_width, m_height, m_depth, m_bytesPerRow;
|
||||
#endif
|
||||
m_width = wxMax(1, w);
|
||||
m_height = wxMax(1, h);
|
||||
m_depth = d ;
|
||||
m_scaleFactor = logicalscale;
|
||||
size_t m_width = wxMax(1, w);
|
||||
size_t m_height = wxMax(1, h);
|
||||
|
||||
int m_scaleFactor = logicalscale;
|
||||
m_hBitmap = NULL;
|
||||
|
||||
m_bytesPerRow = GetBestBytesPerRow( m_width * 4 ) ;
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
size_t size = m_bytesPerRow * m_height ;
|
||||
void* data = m_memBuf.GetWriteBuf( size ) ;
|
||||
if ( data != NULL )
|
||||
{
|
||||
memset( data , 0 , size ) ;
|
||||
m_memBuf.UngetWriteBuf( size ) ;
|
||||
#else
|
||||
size_t m_bytesPerRow = GetBestBytesPerRow(m_width * 4);
|
||||
void* data = NULL;
|
||||
#endif
|
||||
m_hBitmap = CGBitmapContextCreate((char*)data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst);
|
||||
wxASSERT_MSG(m_hBitmap, wxT("Unable to create CGBitmapContext context"));
|
||||
CGContextTranslateCTM(m_hBitmap, 0, m_height);
|
||||
CGContextScaleCTM(m_hBitmap, 1 * GetScaleFactor(), -1 * GetScaleFactor());
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
} /* data != NULL */
|
||||
#endif
|
||||
|
||||
return IsOk();
|
||||
}
|
||||
|
||||
bool wxBitmapRefData::IsOk() const
|
||||
{
|
||||
return ( m_hBitmap.get() != NULL
|
||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
||||
|| m_nsImage != NULL
|
||||
#endif
|
||||
);
|
||||
return (m_hBitmap.get() != NULL || m_nsImage != NULL);
|
||||
}
|
||||
|
||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
||||
|
||||
int wxBitmapRefData::GetWidth() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
||||
|
||||
if ( m_hBitmap )
|
||||
return CGBitmapContextGetWidth(m_hBitmap);
|
||||
return (int) CGBitmapContextGetWidth(m_hBitmap);
|
||||
else
|
||||
return (int) wxOSXGetImageSize(m_nsImage).width;
|
||||
}
|
||||
@@ -416,7 +322,7 @@ int wxBitmapRefData::GetHeight() const
|
||||
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
||||
|
||||
if ( m_hBitmap )
|
||||
return CGBitmapContextGetHeight(m_hBitmap);
|
||||
return (int) CGBitmapContextGetHeight(m_hBitmap);
|
||||
else
|
||||
return (int) wxOSXGetImageSize(m_nsImage).height;
|
||||
}
|
||||
@@ -426,7 +332,7 @@ int wxBitmapRefData::GetDepth() const
|
||||
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
||||
|
||||
if ( m_hBitmap )
|
||||
return CGBitmapContextGetBitsPerPixel(m_hBitmap);
|
||||
return (int) CGBitmapContextGetBitsPerPixel(m_hBitmap);
|
||||
else
|
||||
return 32; // a bitmap converted from an nsimage would have this depth
|
||||
}
|
||||
@@ -435,9 +341,9 @@ int wxBitmapRefData::GetBytesPerRow() const
|
||||
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
||||
|
||||
if ( m_hBitmap )
|
||||
return CGBitmapContextGetBytesPerRow(m_hBitmap);
|
||||
return (int) CGBitmapContextGetBytesPerRow(m_hBitmap);
|
||||
else
|
||||
return GetBestBytesPerRow( GetWidth() * 4);
|
||||
return (int) GetBestBytesPerRow( GetWidth() * 4);
|
||||
}
|
||||
|
||||
bool wxBitmapRefData::HasAlpha() const
|
||||
@@ -455,22 +361,19 @@ bool wxBitmapRefData::HasAlpha() const
|
||||
}
|
||||
}
|
||||
|
||||
WX_NSImage wxBitmapRefData::GetNSImage() const
|
||||
WXImage wxBitmapRefData::GetImage() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
||||
|
||||
if ( !m_nsImage )
|
||||
{
|
||||
wxCFRef< CGImageRef > cgimage(CreateCGImage());
|
||||
return wxOSXGetNSImageFromCGImage( cgimage, GetScaleFactor(), IsTemplate() );
|
||||
return wxOSXGetImageFromCGImage( cgimage, GetScaleFactor(), IsTemplate() );
|
||||
}
|
||||
|
||||
return m_nsImage;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
void wxBitmapRefData::UseAlpha( bool use )
|
||||
{
|
||||
wxCHECK_RET( IsOk() , wxT("invalid bitmap") ) ;
|
||||
@@ -478,16 +381,10 @@ void wxBitmapRefData::UseAlpha( bool use )
|
||||
if ( HasAlpha() == use )
|
||||
return ;
|
||||
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
m_hasAlpha = use ;
|
||||
void *data = m_memBuf.GetData();
|
||||
#else
|
||||
void *data = NULL;
|
||||
#endif
|
||||
CGContextRef hBitmap = CGBitmapContextCreate(data, GetWidth(), GetHeight(), 8, GetBytesPerRow(), wxMacGetGenericRGBColorSpace(), use ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst );
|
||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
||||
CGContextRef hBitmap = CGBitmapContextCreate(NULL, GetWidth(), GetHeight(), 8, GetBytesPerRow(), wxMacGetGenericRGBColorSpace(), use ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst );
|
||||
|
||||
memcpy(CGBitmapContextGetData(hBitmap),CGBitmapContextGetData(m_hBitmap),GetBytesPerRow()*GetHeight());
|
||||
#endif
|
||||
|
||||
wxASSERT_MSG( hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
|
||||
CGContextTranslateCTM( hBitmap, 0, GetHeight() );
|
||||
CGContextScaleCTM( hBitmap, GetScaleFactor(), -GetScaleFactor() );
|
||||
@@ -501,11 +398,7 @@ const void *wxBitmapRefData::GetRawAccess() const
|
||||
|
||||
EnsureBitmapExists();
|
||||
|
||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
||||
return m_memBuf.GetData() ;
|
||||
#else
|
||||
return CGBitmapContextGetData(m_hBitmap);
|
||||
#endif
|
||||
}
|
||||
|
||||
void *wxBitmapRefData::GetRawAccess()
|
||||
@@ -773,7 +666,7 @@ CGImageRef wxBitmapRefData::CreateCGImage() const
|
||||
{
|
||||
if (m_nsImage)
|
||||
{
|
||||
image = wxOSXCreateCGImageFromNSImage(m_nsImage);
|
||||
image = wxOSXCreateCGImageFromImage(m_nsImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -957,27 +850,7 @@ wxBitmapRefData::~wxBitmapRefData()
|
||||
|
||||
bool wxBitmap::CopyFromIcon(const wxIcon& icon)
|
||||
{
|
||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
||||
return Create( icon.GetNSImage() );
|
||||
#else
|
||||
int w = icon.GetWidth() ;
|
||||
int h = icon.GetHeight() ;
|
||||
|
||||
if ( Create( w, h ) )
|
||||
{
|
||||
// Assume 32 bpp icon has transparency values
|
||||
UseAlpha(icon.GetDepth() == 32);
|
||||
|
||||
wxMemoryDC dc ;
|
||||
dc.SelectObject( *this ) ;
|
||||
dc.DrawIcon( icon , 0 , 0 ) ;
|
||||
dc.SelectObject( wxNullBitmap ) ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif
|
||||
return Create( icon.GetImage() );
|
||||
}
|
||||
|
||||
wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
|
||||
@@ -1109,14 +982,12 @@ IconRef wxBitmap::CreateIconRef() const
|
||||
}
|
||||
#endif
|
||||
|
||||
#if wxOSX_USE_COCOA
|
||||
|
||||
wxBitmap::wxBitmap(WX_NSImage image)
|
||||
wxBitmap::wxBitmap(WXImage image)
|
||||
{
|
||||
(void)Create(image);
|
||||
}
|
||||
|
||||
bool wxBitmap::Create(WX_NSImage image)
|
||||
bool wxBitmap::Create(WXImage image)
|
||||
{
|
||||
UnRef();
|
||||
|
||||
@@ -1139,22 +1010,11 @@ bool wxBitmap::Create(CGContextRef bitmapcontext)
|
||||
return GetBitmapData()->IsOk() ;
|
||||
}
|
||||
|
||||
WX_NSImage wxBitmap::GetNSImage() const
|
||||
WXImage wxBitmap::GetImage() const
|
||||
{
|
||||
return GetBitmapData()->GetNSImage();
|
||||
return GetBitmapData()->GetImage();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if wxOSX_USE_IPHONE
|
||||
|
||||
WX_UIImage wxBitmap::GetUIImage() const
|
||||
{
|
||||
wxCFRef< CGImageRef > cgimage(CreateCGImage());
|
||||
return wxOSXGetUIImageFromCGImage( cgimage );
|
||||
}
|
||||
|
||||
#endif
|
||||
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
|
||||
{
|
||||
wxCHECK_MSG( IsOk() &&
|
||||
|
Reference in New Issue
Block a user