diff options
| author | Neil Hodgson <nyamatongwe@gmail.com> | 2017-05-07 09:06:34 +1000 | 
|---|---|---|
| committer | Neil Hodgson <nyamatongwe@gmail.com> | 2017-05-07 09:06:34 +1000 | 
| commit | e83b93832fa5d40d2543c8a967c256d9439fe041 (patch) | |
| tree | dfd8021d17bba40882cddc97ba141e743b494cba | |
| parent | 0f63b24bcd3e119783c163e4fc24fa94003040af (diff) | |
| download | scintilla-mirror-e83b93832fa5d40d2543c8a967c256d9439fe041.tar.gz | |
Use unique_ptr on Cocoa.
| -rw-r--r-- | cocoa/PlatCocoa.h | 4 | ||||
| -rw-r--r-- | cocoa/PlatCocoa.mm | 29 | ||||
| -rw-r--r-- | cocoa/ScintillaCocoa.mm | 5 | 
3 files changed, 17 insertions, 21 deletions
| diff --git a/cocoa/PlatCocoa.h b/cocoa/PlatCocoa.h index 5d0789407..f8f1bd698 100644 --- a/cocoa/PlatCocoa.h +++ b/cocoa/PlatCocoa.h @@ -47,12 +47,12 @@ private:    CGContextRef gc;    /** The text layout instance */ -  QuartzTextLayout*	textLayout; +  std::unique_ptr<QuartzTextLayout> textLayout;    int codePage;    int verticalDeviceResolution;    /** If the surface is a bitmap context, contains a reference to the bitmap data. */ -  uint8_t* bitmapData; +  std::unique_ptr<uint8_t[]> bitmapData;    /** If the surface is a bitmap context, stores the dimensions of the bitmap. */    int bitmapWidth;    int bitmapHeight; diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 761a64463..7a65d3d41 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -153,11 +153,11 @@ SurfaceImpl::SurfaceImpl()    y = 0;    gc = NULL; -  textLayout = new QuartzTextLayout(NULL); +  textLayout.reset(new QuartzTextLayout(nullptr));    codePage = 0;    verticalDeviceResolution = 0; -  bitmapData = NULL; // Release will try and delete bitmapData if != NULL +  bitmapData.reset(); // Release will try and delete bitmapData if != nullptr    bitmapWidth = 0;    bitmapHeight = 0; @@ -169,22 +169,20 @@ SurfaceImpl::SurfaceImpl()  SurfaceImpl::~SurfaceImpl()  {    Release(); -  delete textLayout;  }  //--------------------------------------------------------------------------------------------------  void SurfaceImpl::Release()  { -  textLayout->setContext (NULL); -  if ( bitmapData != NULL ) +  textLayout->setContext(nullptr); +  if (bitmapData)    { -    delete[] bitmapData; +    bitmapData.reset();      // We only "own" the graphics context if we are a bitmap context -    if (gc != NULL) +    if (gc)        CGContextRelease(gc);    } -  bitmapData = NULL;    gc = NULL;    bitmapWidth = 0; @@ -243,9 +241,9 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface* surface_, WindowID      return;    // Create the bitmap. -  bitmapData = new uint8_t[bitmapByteCount]; +  bitmapData.reset(new uint8_t[bitmapByteCount]);    // create the context -  gc = CGBitmapContextCreate(bitmapData, +  gc = CGBitmapContextCreate(bitmapData.get(),                               width,                               height,                               BITS_PER_COMPONENT, @@ -257,15 +255,14 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface* surface_, WindowID    {      // the context couldn't be created for some reason,      // and we have no use for the bitmap without the context -    delete[] bitmapData; -    bitmapData = NULL; +    bitmapData.reset();    }    textLayout->setContext (gc);    // the context retains the color space, so we can release it    CGColorSpaceRelease(colorSpace); -  if (gc != NULL && bitmapData != NULL) +  if (gc && bitmapData)    {      // "Erase" to white.      CGContextClearRect( gc, CGRectMake( 0, 0, width, height ) ); @@ -319,8 +316,8 @@ void SurfaceImpl::FillColour(const ColourDesired& back)  CGImageRef SurfaceImpl::GetImage()  {    // For now, assume that GetImage can only be called on PixMap surfaces. -  if (bitmapData == NULL) -    return NULL; +  if (!bitmapData) +    return nullptr;    CGContextFlush(gc); @@ -334,7 +331,7 @@ CGImageRef SurfaceImpl::GetImage()    // Make a copy of the bitmap data for the image creation and divorce it    // From the SurfaceImpl lifetime -  CFDataRef dataRef = CFDataCreate(kCFAllocatorDefault, bitmapData, bitmapByteCount); +  CFDataRef dataRef = CFDataCreate(kCFAllocatorDefault, bitmapData.get(), bitmapByteCount);    // Create a data provider.    CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(dataRef); diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 5c89ed765..64dffbd4f 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -1844,7 +1844,7 @@ void ScintillaCocoa::PaintMargin(NSRect aRect)    PRectangle rc = NSRectToPRectangle(aRect);    rcPaint = rc; -  Surface *sw = Surface::Allocate(SC_TECHNOLOGY_DEFAULT); +  std::unique_ptr<Surface> sw(Surface::Allocate(SC_TECHNOLOGY_DEFAULT));    if (sw)    {      CGContextSetAllowsAntialiasing(gc, @@ -1855,9 +1855,8 @@ void ScintillaCocoa::PaintMargin(NSRect aRect)                                                vs.extraFontFlag == SC_EFF_QUALITY_DEFAULT ||                                                vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED);      sw->Init(gc, wMargin.GetID()); -    PaintSelMargin(sw, rc); +    PaintSelMargin(sw.get(), rc);      sw->Release(); -    delete sw;    }  } | 
