1
0
Fork 0

Codechange: replace C-style memory management in MacOS code

pull/13657/head
Rubidium 2025-02-23 14:53:14 +01:00 committed by rubidium42
parent 416f6d54d2
commit f6ce8d1b10
2 changed files with 12 additions and 16 deletions

View File

@ -92,8 +92,8 @@ private:
class VideoDriver_CocoaQuartz : public VideoDriver_Cocoa {
private:
int buffer_depth; ///< Colour depth of used frame buffer
void *pixel_buffer; ///< used for direct pixel access
void *window_buffer; ///< Colour translation from palette to screen
std::unique_ptr<uint8_t[]> pixel_buffer; ///< used for direct pixel access
std::unique_ptr<uint32_t[]> window_buffer; ///< Colour translation from palette to screen
int window_width; ///< Current window width in pixel
int window_height; ///< Current window height in pixel
@ -123,7 +123,7 @@ protected:
NSView *AllocateDrawView() override;
void *GetVideoPointer() override { return this->buffer_depth == 8 ? this->pixel_buffer : this->window_buffer; }
void *GetVideoPointer() override { return this->buffer_depth == 8 ? static_cast<void *>(this->pixel_buffer.get()) : static_cast<void *>(this->window_buffer.get()); }
};
class FVideoDriver_CocoaQuartz : public DriverFactoryBase {

View File

@ -625,8 +625,8 @@ void VideoDriver_CocoaQuartz::Stop()
CGContextRelease(this->cgcontext);
free(this->window_buffer);
free(this->pixel_buffer);
this->window_buffer.reset();
this->pixel_buffer.reset();
}
NSView *VideoDriver_CocoaQuartz::AllocateDrawView()
@ -649,14 +649,13 @@ void VideoDriver_CocoaQuartz::AllocateBackingStore(bool)
this->buffer_depth = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
/* Create Core Graphics Context */
free(this->window_buffer);
this->window_buffer = malloc(this->window_pitch * this->window_height * sizeof(uint32_t));
this->window_buffer = std::make_unique<uint32_t[]>(this->window_pitch * this->window_height);
/* Initialize with opaque black. */
ClearWindowBuffer((uint32_t *)this->window_buffer, this->window_pitch, this->window_height);
ClearWindowBuffer(this->window_buffer.get(), this->window_pitch, this->window_height);
CGContextRelease(this->cgcontext);
this->cgcontext = CGBitmapContextCreate(
this->window_buffer, // data
this->window_buffer.get(), // data
this->window_width, // width
this->window_height, // height
8, // bits per component
@ -671,12 +670,9 @@ void VideoDriver_CocoaQuartz::AllocateBackingStore(bool)
CGContextSetInterpolationQuality(this->cgcontext, kCGInterpolationNone);
if (this->buffer_depth == 8) {
free(this->pixel_buffer);
this->pixel_buffer = malloc(this->window_width * this->window_height);
if (this->pixel_buffer == nullptr) UserError("Out of memory allocating pixel buffer");
this->pixel_buffer = std::make_unique<uint8_t[]>(this->window_width * this->window_height);
} else {
free(this->pixel_buffer);
this->pixel_buffer = nullptr;
this->pixel_buffer.reset();
}
/* Tell the game that the resolution has changed */
@ -701,8 +697,8 @@ void VideoDriver_CocoaQuartz::AllocateBackingStore(bool)
void VideoDriver_CocoaQuartz::BlitIndexedToView32(int left, int top, int right, int bottom)
{
const uint32_t *pal = this->palette;
const uint8_t *src = (uint8_t*)this->pixel_buffer;
uint32_t *dst = (uint32_t*)this->window_buffer;
const uint8_t *src = this->pixel_buffer.get();
uint32_t *dst = this->window_buffer.get();
uint width = this->window_width;
uint pitch = this->window_pitch;