From 3582edb1856d8e863417c0e8f53e153c24a4d0f0 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop <dudesuchamazing@gmail.com> Date: Wed, 28 Feb 2024 03:43:50 +0300 Subject: [PATCH] Cairo GAL: reduce buffer allocation sizes. cairo_format_stride_for_width() result is in bytes. Also removes unneeded extra width. (cherry picked from commit d359fb8ab90937d3a5b4dc4cfbabf7dc04da2952) --- common/gal/cairo/cairo_compositor.cpp | 4 ++-- common/gal/cairo/cairo_gal.cpp | 5 +---- include/gal/cairo/cairo_compositor.h | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/common/gal/cairo/cairo_compositor.cpp b/common/gal/cairo/cairo_compositor.cpp index ea56cc5d74..5fa8f6739b 100644 --- a/common/gal/cairo/cairo_compositor.cpp +++ b/common/gal/cairo/cairo_compositor.cpp @@ -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 ); } diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index a10a815265..554a3279b4 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -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]; diff --git a/include/gal/cairo/cairo_compositor.h b/include/gal/cairo/cairo_compositor.h index 3d28c419e2..e27fb942eb 100644 --- a/include/gal/cairo/cairo_compositor.h +++ b/include/gal/cairo/cairo_compositor.h @@ -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