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:
Seth Hillbrand 2019-08-28 19:28:40 -07:00
parent 678294b8a6
commit c3e07a5886
7 changed files with 15 additions and 78 deletions

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * 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() unsigned int CAIRO_COMPOSITOR::CreateBuffer()
{ {
// Pixel storage // Pixel storage
BitmapPtr bitmap( new unsigned int[m_bufferSize] ); BitmapPtr bitmap = new uint32_t[m_bufferSize]();
memset( bitmap.get(), 0x00, m_bufferSize * sizeof(int) );
// Create the Cairo surface // Create the Cairo surface
cairo_surface_t* surface = cairo_image_surface_create_for_data( cairo_surface_t* surface = cairo_image_surface_create_for_data(
(unsigned char*) bitmap.get(), (unsigned char*) bitmap,
CAIRO_FORMAT_ARGB32, m_width, CAIRO_FORMAT_ARGB32, m_width,
m_height, m_stride ); m_height, m_stride );
cairo_t* context = cairo_create( surface ); cairo_t* context = cairo_create( surface );
@ -144,7 +143,7 @@ void CAIRO_COMPOSITOR::Begin()
void CAIRO_COMPOSITOR::ClearBuffer( const COLOR4D& aColor ) void CAIRO_COMPOSITOR::ClearBuffer( const COLOR4D& aColor )
{ {
// Clear the pixel storage // 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_destroy( it->context );
cairo_surface_destroy( it->surface ); cairo_surface_destroy( it->surface );
delete it->bitmap;
} }
m_buffers.clear(); m_buffers.clear();

View File

@ -1257,6 +1257,7 @@ void CAIRO_GAL::endDrawing()
// Now translate the raw context data from the format stored // Now translate the raw context data from the format stored
// by cairo into a format understood by wxImage. // by cairo into a format understood by wxImage.
pixman_image_t* dstImg = pixman_image_create_bits( PIXMAN_r8g8b8, pixman_image_t* dstImg = pixman_image_create_bits( PIXMAN_r8g8b8,
screenSize.x, screenSize.y, (uint32_t*) wxOutput, wxBufferWidth * 3 ); screenSize.x, screenSize.y, (uint32_t*) wxOutput, wxBufferWidth * 3 );
pixman_image_t* srcImg = pixman_image_create_bits( PIXMAN_a8b8g8r8, 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( srcImg );
pixman_image_unref( dstImg ); pixman_image_unref( dstImg );
wxImage img( wxBufferWidth, screenSize.y, (unsigned char*) wxOutput, true ); wxImage img( wxBufferWidth, screenSize.y, wxOutput, true );
wxBitmap bmp( img ); wxBitmap bmp( img );
wxMemoryDC mdc( bmp ); wxMemoryDC mdc( bmp );
wxClientDC clientDC( this ); 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() int CAIRO_GAL::BeginGroup()
{ {
initSurface(); initSurface();
@ -1420,7 +1390,7 @@ void CAIRO_GAL::initSurface()
if( isInitialized ) if( isInitialized )
return; 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 ); wxBufferWidth, screenSize.y, stride );
context = cairo_create( surface ); context = cairo_create( surface );
@ -1458,8 +1428,7 @@ void CAIRO_GAL::allocateBitmaps()
stride = cairo_format_stride_for_width( GAL_FORMAT, wxBufferWidth ); stride = cairo_format_stride_for_width( GAL_FORMAT, wxBufferWidth );
bufferSize = stride * screenSize.y; bufferSize = stride * screenSize.y;
bitmapBuffer = new unsigned int[bufferSize]; bitmapBuffer = new unsigned char[bufferSize * 4];
bitmapBufferBackup = new unsigned int[bufferSize];
wxOutput = new unsigned char[wxBufferWidth * 3 * screenSize.y]; wxOutput = new unsigned char[wxBufferWidth * 3 * screenSize.y];
} }
@ -1467,7 +1436,6 @@ void CAIRO_GAL::allocateBitmaps()
void CAIRO_GAL::deleteBitmaps() void CAIRO_GAL::deleteBitmaps()
{ {
delete[] bitmapBuffer; delete[] bitmapBuffer;
delete[] bitmapBufferBackup;
delete[] wxOutput; delete[] wxOutput;
} }

View File

@ -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 ) void OPENGL_GAL::SetTarget( RENDER_TARGET aTarget )
{ {
switch( aTarget ) switch( aTarget )

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -34,7 +35,8 @@
#include <gal/compositor.h> #include <gal/compositor.h>
#include <gal/gal_display_options.h> #include <gal/gal_display_options.h>
#include <cairo.h> #include <cairo.h>
#include <boost/smart_ptr/shared_array.hpp>
#include <cstdint>
#include <deque> #include <deque>
namespace KIGFX namespace KIGFX
@ -107,7 +109,7 @@ public:
} }
protected: protected:
typedef boost::shared_array<unsigned int> BitmapPtr; typedef uint32_t* BitmapPtr;
typedef struct typedef struct
{ {
cairo_t* context; ///< Main texture handle cairo_t* context; ///< Main texture handle

View File

@ -341,7 +341,7 @@ protected:
/// Format used to store pixels /// 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 bool Show( bool aShow ) override;
virtual void SaveScreen() override;
virtual void RestoreScreen() override;
virtual int BeginGroup() override; virtual int BeginGroup() override;
virtual void EndGroup() override; virtual void EndGroup() override;
@ -433,8 +429,7 @@ protected:
unsigned char* wxOutput; ///< wxImage comaptible buffer unsigned char* wxOutput; ///< wxImage comaptible buffer
// Variables related to Cairo <-> wxWidgets // Variables related to Cairo <-> wxWidgets
unsigned int* bitmapBuffer; ///< Storage of the cairo image unsigned char* bitmapBuffer; ///< Storage of the cairo image
unsigned int* bitmapBufferBackup; ///< Backup storage of the cairo image
int stride; ///< Stride value for Cairo int stride; ///< Stride value for Cairo
int wxBufferWidth; int wxBufferWidth;
bool isInitialized; ///< Are Cairo image & surface ready to use bool isInitialized; ///< Are Cairo image & surface ready to use

View File

@ -800,16 +800,6 @@ public:
// Buffer manipulation methods // 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. * @brief Sets the target for rendering.
* *

View File

@ -218,12 +218,6 @@ public:
// Handling the world <-> screen transformation // Handling the world <-> screen transformation
// -------------------------------------------------------- // --------------------------------------------------------
/// @copydoc GAL::SaveScreen()
virtual void SaveScreen() override;
/// @copydoc GAL::RestoreScreen()
virtual void RestoreScreen() override;
/// @copydoc GAL::SetTarget() /// @copydoc GAL::SetTarget()
virtual void SetTarget( RENDER_TARGET aTarget ) override; virtual void SetTarget( RENDER_TARGET aTarget ) override;