diff options
Diffstat (limited to 'cocoa')
| -rw-r--r-- | cocoa/PlatCocoa.h | 2 | ||||
| -rw-r--r-- | cocoa/PlatCocoa.mm | 52 | 
2 files changed, 54 insertions, 0 deletions
diff --git a/cocoa/PlatCocoa.h b/cocoa/PlatCocoa.h index 040821cb8..f8a941f95 100644 --- a/cocoa/PlatCocoa.h +++ b/cocoa/PlatCocoa.h @@ -75,11 +75,13 @@ private:  public:  	SurfaceImpl(); +	SurfaceImpl(const SurfaceImpl *surface, int width, int height);  	~SurfaceImpl() override;  	void Init(WindowID wid) override;  	void Init(SurfaceID sid, WindowID wid) override;  	void InitPixMap(int width, int height, Surface *surface_, WindowID wid) override; +	std::unique_ptr<Surface> AllocatePixMap(int width, int height) override;  	CGContextRef GetContext() { return gc; }  	void SetMode(SurfaceMode mode) override; 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_) {  | 
