diff options
Diffstat (limited to 'cocoa/PlatCocoa.mm')
-rw-r--r-- | cocoa/PlatCocoa.mm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index b5e1da79b..4020c3f09 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -364,6 +364,54 @@ SurfaceImpl::SurfaceImpl() { Release(); } +SurfaceImpl::SurfaceImpl(const SurfaceImpl *surface, int width, int height) { + x = 0; + y = 0; + + textLayout.reset(new QuartzTextLayout()); + + // Create a new bitmap context, along with the RAM for the bitmap itself + bitmapWidth = width; + bitmapHeight = height; + + const int bitmapBytesPerRow = (width * BYTES_PER_PIXEL); + const int bitmapByteCount = (bitmapBytesPerRow * height); + + // Create an RGB color space. + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + if (colorSpace == NULL) + return; + + // Create the bitmap. + bitmapData.reset(new uint8_t[bitmapByteCount]); + // create the context + gc = CGBitmapContextCreate(bitmapData.get(), + width, + height, + BITS_PER_COMPONENT, + bitmapBytesPerRow, + colorSpace, + kCGImageAlphaPremultipliedLast); + + if (gc == NULL) { + // the context couldn't be created for some reason, + // and we have no use for the bitmap without the context + bitmapData.reset(); + } + + // the context retains the color space, so we can release it + CGColorSpaceRelease(colorSpace); + + if (gc && bitmapData) { + // "Erase" to white. + CGContextClearRect(gc, CGRectMake(0, 0, width, height)); + CGContextSetRGBFillColor(gc, 1.0, 1.0, 1.0, 1.0); + CGContextFillRect(gc, CGRectMake(0, 0, width, height)); + } + + mode = surface->mode; +} + //-------------------------------------------------------------------------------------------------- SurfaceImpl::~SurfaceImpl() { @@ -478,6 +526,10 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface *surface_, WindowID } } +std::unique_ptr<Surface> SurfaceImpl::AllocatePixMap(int width, int height) { + return std::make_unique<SurfaceImpl>(this, width, height); +} + //-------------------------------------------------------------------------------------------------- void SurfaceImpl::SetMode(SurfaceMode mode_) { |