From 30eebd8190520f0a3f8e0a640ce6b9bfddc8b650 Mon Sep 17 00:00:00 2001 From: Space Lord Date: Fri, 4 Nov 2016 13:11:36 +0100 Subject: [PATCH] Replace CGDataProviderCreateDirect with ...CreateWithData Since it even more ... 'direct' and does not need weird callbacks to copy data (not sure why I was using 'CreateDirect' in the first place). --- graf2d/cocoa/src/QuartzPixmap.mm | 82 +++++++------------------------- 1 file changed, 17 insertions(+), 65 deletions(-) diff --git a/graf2d/cocoa/src/QuartzPixmap.mm b/graf2d/cocoa/src/QuartzPixmap.mm index 01e77691c2f13..b3e270e04a047 100644 --- a/graf2d/cocoa/src/QuartzPixmap.mm +++ b/graf2d/cocoa/src/QuartzPixmap.mm @@ -25,32 +25,6 @@ #include "CocoaUtils.h" #include "X11Colors.h" -//Call backs for data provider. -extern "C" { - -//______________________________________________________________________________ -const void* ROOT_QuartzImage_GetBytePointer(void *info) -{ - assert(info != 0 && "ROOT_QuartzImage_GetBytePointer, info parameter is null"); - return info; -} - -//______________________________________________________________________________ -void ROOT_QuartzImage_ReleaseBytePointer(void *, const void *) -{ - //Do nothing. -} - -//______________________________________________________________________________ -std::size_t ROOT_QuartzImage_GetBytesAtPosition(void *info, void *buffer, off_t position, - std::size_t count) -{ - std::copy((char *)info + position, (char *)info + position + count, (char*)buffer); - return count; -} - -} - namespace X11 = ROOT::MacOSX::X11; namespace Util = ROOT::MacOSX::Util; namespace Quartz = ROOT::Quartz; @@ -144,19 +118,14 @@ - (CGImageRef) createImageFromPixmap : (X11::Rectangle) cropArea assert(cropArea.fWidth <= fWidth && "createImageFromPixmap:, bad cropArea.fWidth"); assert(cropArea.fHeight <= fHeight && "createImageFromPixmap:, bad cropArea.fHeight"); - // - const CGDataProviderDirectCallbacks providerCallbacks = {0, ROOT_QuartzImage_GetBytePointer, - ROOT_QuartzImage_ReleaseBytePointer, - ROOT_QuartzImage_GetBytesAtPosition, 0}; - const unsigned scaledW = fWidth * fScaleFactor; const unsigned scaledH = fHeight * fScaleFactor; - const Util::CFScopeGuard provider(CGDataProviderCreateDirect(&fData[0], - scaledW * scaledH * 4, &providerCallbacks)); + const Util::CFScopeGuard provider(CGDataProviderCreateWithData(nullptr, &fData[0], + scaledW * scaledH * 4, nullptr)); if (!provider.Get()) { - NSLog(@"QuartzPixmap: -pixmapToImage, CGDataProviderCreateDirect failed"); + NSLog(@"QuartzPixmap: -pixmapToImage, CGDataProviderCreateWithData failed"); return 0; } @@ -463,14 +432,10 @@ - (id) initWithW : (unsigned) width H : (unsigned) height data : (unsigned char std::copy(data, data + width * height * 4, &fImageData[0]); fIsStippleMask = NO; - const CGDataProviderDirectCallbacks providerCallbacks = {0, ROOT_QuartzImage_GetBytePointer, - ROOT_QuartzImage_ReleaseBytePointer, - ROOT_QuartzImage_GetBytesAtPosition, 0}; - const Util::CFScopeGuard - provider(CGDataProviderCreateDirect(&fImageData[0], width * height * 4, &providerCallbacks)); + provider(CGDataProviderCreateWithData(nullptr, &fImageData[0], width * height * 4, nullptr)); if (!provider.Get()) { - NSLog(@"QuartzImage: -initWithW:H:data: CGDataProviderCreateDirect failed"); + NSLog(@"QuartzImage: -initWithW:H:data: CGDataProviderCreateWithData failed"); return nil; } @@ -521,15 +486,10 @@ - (id) initMaskWithW : (unsigned) width H : (unsigned) height bitmapMask : (unsi std::copy(mask, mask + width * height, &fImageData[0]); fIsStippleMask = YES; - const CGDataProviderDirectCallbacks providerCallbacks = {0, ROOT_QuartzImage_GetBytePointer, - ROOT_QuartzImage_ReleaseBytePointer, - ROOT_QuartzImage_GetBytesAtPosition, 0}; - - - const Util::CFScopeGuard provider(CGDataProviderCreateDirect(&fImageData[0], - width * height, &providerCallbacks)); + const Util::CFScopeGuard provider(CGDataProviderCreateWithData(nullptr, &fImageData[0], + width * height, nullptr)); if (!provider.Get()) { - NSLog(@"QuartzImage: -initMaskWithW:H:bitmapMask: CGDataProviderCreateDirect failed"); + NSLog(@"QuartzImage: -initMaskWithW:H:bitmapMask: CGDataProviderCreateWithData failed"); return nil; } @@ -568,14 +528,10 @@ - (id) initMaskWithW : (unsigned) width H : (unsigned) height } fIsStippleMask = YES; - const CGDataProviderDirectCallbacks providerCallbacks = {0, ROOT_QuartzImage_GetBytePointer, - ROOT_QuartzImage_ReleaseBytePointer, - ROOT_QuartzImage_GetBytesAtPosition, 0}; - - const Util::CFScopeGuard provider(CGDataProviderCreateDirect(&fImageData[0], - width * height, &providerCallbacks)); + const Util::CFScopeGuard provider(CGDataProviderCreateWithData(nullptr, &fImageData[0], + width * height, nullptr)); if (!provider.Get()) { - NSLog(@"QuartzImage: -initMaskWithW:H: CGDataProviderCreateDirect failed"); + NSLog(@"QuartzImage: -initMaskWithW:H: CGDataProviderCreateWithData failed"); return nil; } @@ -648,16 +604,12 @@ - (id) initFromImageFlipped : (QuartzImage *) image std::copy(sourceLine, sourceLine + lineSize, dstLine); } - const CGDataProviderDirectCallbacks providerCallbacks = {0, ROOT_QuartzImage_GetBytePointer, - ROOT_QuartzImage_ReleaseBytePointer, - ROOT_QuartzImage_GetBytesAtPosition, 0}; - if (bpp == 1) { fIsStippleMask = YES; - const Util::CFScopeGuard provider(CGDataProviderCreateDirect(&fImageData[0], - width * height, &providerCallbacks)); + const Util::CFScopeGuard provider(CGDataProviderCreateWithData(nullptr, &fImageData[0], + width * height, nullptr)); if (!provider.Get()) { - NSLog(@"QuartzImage: -initFromImageFlipped:, CGDataProviderCreateDirect failed"); + NSLog(@"QuartzImage: -initFromImageFlipped:, CGDataProviderCreateWithData failed"); return nil; } @@ -669,10 +621,10 @@ - (id) initFromImageFlipped : (QuartzImage *) image } } else { fIsStippleMask = NO; - const Util::CFScopeGuard provider(CGDataProviderCreateDirect(&fImageData[0], - width * height * 4, &providerCallbacks)); + const Util::CFScopeGuard provider(CGDataProviderCreateWithData(nullptr, &fImageData[0], + width * height * 4, nullptr)); if (!provider.Get()) { - NSLog(@"QuartzImage: -initFromImageFlipped:, CGDataProviderCreateDirect failed"); + NSLog(@"QuartzImage: -initFromImageFlipped:, CGDataProviderCreateWithData failed"); return nil; }