Cairo GAL: reduce buffer allocation sizes.

cairo_format_stride_for_width() result is in bytes.
Also removes unneeded extra width.
This commit is contained in:
Alex Shvartzkop 2024-02-28 03:43:50 +03:00
parent 5618a6925d
commit d359fb8ab9
3 changed files with 4 additions and 7 deletions

View File

@ -88,7 +88,7 @@ void CAIRO_COMPOSITOR::Resize( unsigned int aWidth, unsigned int aHeight )
unsigned int CAIRO_COMPOSITOR::CreateBuffer()
{
// Pixel storage
BitmapPtr bitmap = new uint32_t[m_bufferSize]();
BitmapPtr bitmap = new uint8_t[m_bufferSize]();
// Create the Cairo surface
cairo_surface_t* surface = cairo_image_surface_create_for_data(
@ -138,7 +138,7 @@ void CAIRO_COMPOSITOR::Begin()
void CAIRO_COMPOSITOR::ClearBuffer( const COLOR4D& aColor )
{
// Clear the pixel storage
memset( m_buffers[m_current].bitmap, 0x00, m_bufferSize * sizeof( int ) );
memset( m_buffers[m_current].bitmap, 0x00, m_bufferSize );
}

View File

@ -1596,15 +1596,12 @@ void CAIRO_GAL::allocateBitmaps()
{
m_wxBufferWidth = m_screenSize.x;
while( ( ( m_wxBufferWidth * 3 ) % 4 ) != 0 )
m_wxBufferWidth++;
// Create buffer, use the system independent Cairo context backend
m_stride = cairo_format_stride_for_width( GAL_FORMAT, m_wxBufferWidth );
m_bufferSize = m_stride * m_screenSize.y;
wxASSERT( m_bitmapBuffer == nullptr );
m_bitmapBuffer = new unsigned char[m_bufferSize * 4];
m_bitmapBuffer = new unsigned char[m_bufferSize];
wxASSERT( m_wxOutput == nullptr );
m_wxOutput = new unsigned char[m_wxBufferWidth * 3 * m_screenSize.y];

View File

@ -126,7 +126,7 @@ protected:
return m_buffers.size();
}
typedef uint32_t* BitmapPtr;
typedef uint8_t* BitmapPtr;
struct CAIRO_BUFFER
{
cairo_t* context; ///< Main texture handle