Cleaning Cairo GAL
Removed extra allocations that were not used. Removed unneeded shared pointer Corrected storage type from RGB to ARGB
This commit is contained in:
parent
678294b8a6
commit
c3e07a5886
|
@ -2,6 +2,7 @@
|
|||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2013 CERN
|
||||
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -93,13 +94,11 @@ void CAIRO_COMPOSITOR::Resize( unsigned int aWidth, unsigned int aHeight )
|
|||
unsigned int CAIRO_COMPOSITOR::CreateBuffer()
|
||||
{
|
||||
// Pixel storage
|
||||
BitmapPtr bitmap( new unsigned int[m_bufferSize] );
|
||||
|
||||
memset( bitmap.get(), 0x00, m_bufferSize * sizeof(int) );
|
||||
BitmapPtr bitmap = new uint32_t[m_bufferSize]();
|
||||
|
||||
// Create the Cairo surface
|
||||
cairo_surface_t* surface = cairo_image_surface_create_for_data(
|
||||
(unsigned char*) bitmap.get(),
|
||||
(unsigned char*) bitmap,
|
||||
CAIRO_FORMAT_ARGB32, m_width,
|
||||
m_height, m_stride );
|
||||
cairo_t* context = cairo_create( surface );
|
||||
|
@ -144,7 +143,7 @@ void CAIRO_COMPOSITOR::Begin()
|
|||
void CAIRO_COMPOSITOR::ClearBuffer( const COLOR4D& aColor )
|
||||
{
|
||||
// Clear the pixel storage
|
||||
memset( m_buffers[m_current].bitmap.get(), 0x00, m_bufferSize * sizeof(int) );
|
||||
memset( m_buffers[m_current].bitmap, 0x00, m_bufferSize * sizeof(int) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -177,6 +176,7 @@ void CAIRO_COMPOSITOR::clean()
|
|||
{
|
||||
cairo_destroy( it->context );
|
||||
cairo_surface_destroy( it->surface );
|
||||
delete it->bitmap;
|
||||
}
|
||||
|
||||
m_buffers.clear();
|
||||
|
|
|
@ -1257,6 +1257,7 @@ void CAIRO_GAL::endDrawing()
|
|||
|
||||
// Now translate the raw context data from the format stored
|
||||
// by cairo into a format understood by wxImage.
|
||||
|
||||
pixman_image_t* dstImg = pixman_image_create_bits( PIXMAN_r8g8b8,
|
||||
screenSize.x, screenSize.y, (uint32_t*) wxOutput, wxBufferWidth * 3 );
|
||||
pixman_image_t* srcImg = pixman_image_create_bits( PIXMAN_a8b8g8r8,
|
||||
|
@ -1269,7 +1270,7 @@ void CAIRO_GAL::endDrawing()
|
|||
pixman_image_unref( srcImg );
|
||||
pixman_image_unref( dstImg );
|
||||
|
||||
wxImage img( wxBufferWidth, screenSize.y, (unsigned char*) wxOutput, true );
|
||||
wxImage img( wxBufferWidth, screenSize.y, wxOutput, true );
|
||||
wxBitmap bmp( img );
|
||||
wxMemoryDC mdc( bmp );
|
||||
wxClientDC clientDC( this );
|
||||
|
@ -1310,37 +1311,6 @@ bool CAIRO_GAL::Show( bool aShow )
|
|||
}
|
||||
|
||||
|
||||
void CAIRO_GAL::SaveScreen()
|
||||
{
|
||||
// Copy the current bitmap to the backup buffer
|
||||
int offset = 0;
|
||||
|
||||
for( int j = 0; j < screenSize.y; j++ )
|
||||
{
|
||||
for( int i = 0; i < stride; i++ )
|
||||
{
|
||||
bitmapBufferBackup[offset + i] = bitmapBuffer[offset + i];
|
||||
offset += stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CAIRO_GAL::RestoreScreen()
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
for( int j = 0; j < screenSize.y; j++ )
|
||||
{
|
||||
for( int i = 0; i < stride; i++ )
|
||||
{
|
||||
bitmapBuffer[offset + i] = bitmapBufferBackup[offset + i];
|
||||
offset += stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CAIRO_GAL::BeginGroup()
|
||||
{
|
||||
initSurface();
|
||||
|
@ -1420,7 +1390,7 @@ void CAIRO_GAL::initSurface()
|
|||
if( isInitialized )
|
||||
return;
|
||||
|
||||
surface = cairo_image_surface_create_for_data( (unsigned char*) bitmapBuffer, GAL_FORMAT,
|
||||
surface = cairo_image_surface_create_for_data( bitmapBuffer, GAL_FORMAT,
|
||||
wxBufferWidth, screenSize.y, stride );
|
||||
|
||||
context = cairo_create( surface );
|
||||
|
@ -1458,8 +1428,7 @@ void CAIRO_GAL::allocateBitmaps()
|
|||
stride = cairo_format_stride_for_width( GAL_FORMAT, wxBufferWidth );
|
||||
bufferSize = stride * screenSize.y;
|
||||
|
||||
bitmapBuffer = new unsigned int[bufferSize];
|
||||
bitmapBufferBackup = new unsigned int[bufferSize];
|
||||
bitmapBuffer = new unsigned char[bufferSize * 4];
|
||||
wxOutput = new unsigned char[wxBufferWidth * 3 * screenSize.y];
|
||||
}
|
||||
|
||||
|
@ -1467,7 +1436,6 @@ void CAIRO_GAL::allocateBitmaps()
|
|||
void CAIRO_GAL::deleteBitmaps()
|
||||
{
|
||||
delete[] bitmapBuffer;
|
||||
delete[] bitmapBufferBackup;
|
||||
delete[] wxOutput;
|
||||
}
|
||||
|
||||
|
|
|
@ -1526,18 +1526,6 @@ void OPENGL_GAL::ClearCache()
|
|||
}
|
||||
|
||||
|
||||
void OPENGL_GAL::SaveScreen()
|
||||
{
|
||||
wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
|
||||
}
|
||||
|
||||
|
||||
void OPENGL_GAL::RestoreScreen()
|
||||
{
|
||||
wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
|
||||
}
|
||||
|
||||
|
||||
void OPENGL_GAL::SetTarget( RENDER_TARGET aTarget )
|
||||
{
|
||||
switch( aTarget )
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2013 CERN
|
||||
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -34,7 +35,8 @@
|
|||
#include <gal/compositor.h>
|
||||
#include <gal/gal_display_options.h>
|
||||
#include <cairo.h>
|
||||
#include <boost/smart_ptr/shared_array.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
|
||||
namespace KIGFX
|
||||
|
@ -107,7 +109,7 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
typedef boost::shared_array<unsigned int> BitmapPtr;
|
||||
typedef uint32_t* BitmapPtr;
|
||||
typedef struct
|
||||
{
|
||||
cairo_t* context; ///< Main texture handle
|
||||
|
|
|
@ -341,7 +341,7 @@ protected:
|
|||
|
||||
|
||||
/// Format used to store pixels
|
||||
static constexpr cairo_format_t GAL_FORMAT = CAIRO_FORMAT_RGB24;
|
||||
static constexpr cairo_format_t GAL_FORMAT = CAIRO_FORMAT_ARGB32;
|
||||
};
|
||||
|
||||
|
||||
|
@ -379,10 +379,6 @@ public:
|
|||
|
||||
virtual bool Show( bool aShow ) override;
|
||||
|
||||
virtual void SaveScreen() override;
|
||||
|
||||
virtual void RestoreScreen() override;
|
||||
|
||||
virtual int BeginGroup() override;
|
||||
|
||||
virtual void EndGroup() override;
|
||||
|
@ -433,8 +429,7 @@ protected:
|
|||
unsigned char* wxOutput; ///< wxImage comaptible buffer
|
||||
|
||||
// Variables related to Cairo <-> wxWidgets
|
||||
unsigned int* bitmapBuffer; ///< Storage of the cairo image
|
||||
unsigned int* bitmapBufferBackup; ///< Backup storage of the cairo image
|
||||
unsigned char* bitmapBuffer; ///< Storage of the cairo image
|
||||
int stride; ///< Stride value for Cairo
|
||||
int wxBufferWidth;
|
||||
bool isInitialized; ///< Are Cairo image & surface ready to use
|
||||
|
|
|
@ -800,16 +800,6 @@ public:
|
|||
// Buffer manipulation methods
|
||||
// ---------------------------
|
||||
|
||||
/**
|
||||
* @brief Save the screen contents.
|
||||
*/
|
||||
virtual void SaveScreen() {};
|
||||
|
||||
/**
|
||||
* @brief Restore the screen contents.
|
||||
*/
|
||||
virtual void RestoreScreen() {};
|
||||
|
||||
/**
|
||||
* @brief Sets the target for rendering.
|
||||
*
|
||||
|
|
|
@ -218,12 +218,6 @@ public:
|
|||
// Handling the world <-> screen transformation
|
||||
// --------------------------------------------------------
|
||||
|
||||
/// @copydoc GAL::SaveScreen()
|
||||
virtual void SaveScreen() override;
|
||||
|
||||
/// @copydoc GAL::RestoreScreen()
|
||||
virtual void RestoreScreen() override;
|
||||
|
||||
/// @copydoc GAL::SetTarget()
|
||||
virtual void SetTarget( RENDER_TARGET aTarget ) override;
|
||||
|
||||
|
|
Loading…
Reference in New Issue