2013-07-25 12:40:04 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
2020-12-21 23:42:21 +00:00
|
|
|
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-07-25 12:40:04 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file cairo_compositor.h
|
2020-12-21 23:42:21 +00:00
|
|
|
* Class that handles multitarget rendering (ie. to different textures/surfaces) and
|
2013-07-25 12:40:04 +00:00
|
|
|
* later compositing into a single image (Cairo flavour).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CAIRO_COMPOSITOR_H_
|
|
|
|
#define CAIRO_COMPOSITOR_H_
|
|
|
|
|
|
|
|
#include <gal/compositor.h>
|
2018-01-04 12:13:00 +00:00
|
|
|
#include <gal/gal_display_options.h>
|
2013-07-25 12:40:04 +00:00
|
|
|
#include <cairo.h>
|
2019-08-29 02:28:40 +00:00
|
|
|
|
|
|
|
#include <cstdint>
|
2013-07-25 12:40:04 +00:00
|
|
|
#include <deque>
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
namespace KIGFX
|
2013-07-25 12:40:04 +00:00
|
|
|
{
|
|
|
|
class CAIRO_COMPOSITOR : public COMPOSITOR
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CAIRO_COMPOSITOR( cairo_t** aMainContext );
|
|
|
|
virtual ~CAIRO_COMPOSITOR();
|
|
|
|
|
|
|
|
/// @copydoc COMPOSITOR::Initialize()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void Initialize() override;
|
2013-07-25 12:40:04 +00:00
|
|
|
|
|
|
|
/// @copydoc COMPOSITOR::Resize()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void Resize( unsigned int aWidth, unsigned int aHeight ) override;
|
2013-07-25 12:40:04 +00:00
|
|
|
|
2013-08-19 09:02:38 +00:00
|
|
|
/// @copydoc COMPOSITOR::CreateBuffer()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual unsigned int CreateBuffer() override;
|
2013-08-19 09:02:38 +00:00
|
|
|
|
2013-07-25 12:40:04 +00:00
|
|
|
/// @copydoc COMPOSITOR::GetBuffer()
|
2016-09-24 18:53:15 +00:00
|
|
|
inline virtual unsigned int GetBuffer() const override
|
2013-08-19 09:02:38 +00:00
|
|
|
{
|
|
|
|
return m_current + 1;
|
|
|
|
}
|
2013-07-25 12:40:04 +00:00
|
|
|
|
|
|
|
/// @copydoc COMPOSITOR::SetBuffer()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void SetBuffer( unsigned int aBufferHandle ) override;
|
2013-07-25 12:40:04 +00:00
|
|
|
|
2016-12-22 17:58:29 +00:00
|
|
|
/// @copydoc COMPOSITOR::Begin()
|
|
|
|
virtual void Begin() override;
|
|
|
|
|
2013-07-25 12:40:04 +00:00
|
|
|
/// @copydoc COMPOSITOR::ClearBuffer()
|
2017-08-04 12:43:02 +00:00
|
|
|
virtual void ClearBuffer( const COLOR4D& aColor ) override;
|
2013-07-25 12:40:04 +00:00
|
|
|
|
|
|
|
/// @copydoc COMPOSITOR::DrawBuffer()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void DrawBuffer( unsigned int aBufferHandle ) override;
|
2013-07-25 12:40:04 +00:00
|
|
|
|
2016-12-22 17:58:29 +00:00
|
|
|
/// @copydoc COMPOSITOR::Present()
|
|
|
|
virtual void Present() override;
|
|
|
|
|
2018-01-04 12:13:00 +00:00
|
|
|
void SetAntialiasingMode( CAIRO_ANTIALIASING_MODE aMode ); // clears all buffers
|
|
|
|
CAIRO_ANTIALIASING_MODE GetAntialiasingMode() const
|
|
|
|
{
|
|
|
|
switch( m_currentAntialiasingMode )
|
|
|
|
{
|
|
|
|
case CAIRO_ANTIALIAS_FAST:
|
|
|
|
return CAIRO_ANTIALIASING_MODE::FAST;
|
|
|
|
case CAIRO_ANTIALIAS_GOOD:
|
|
|
|
return CAIRO_ANTIALIASING_MODE::GOOD;
|
|
|
|
case CAIRO_ANTIALIAS_BEST:
|
|
|
|
return CAIRO_ANTIALIASING_MODE::BEST;
|
|
|
|
default:
|
|
|
|
return CAIRO_ANTIALIASING_MODE::NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-19 09:02:38 +00:00
|
|
|
/**
|
2020-12-21 23:42:21 +00:00
|
|
|
* Set a context to be treated as the main context (ie. as a target of buffers rendering and
|
2013-08-19 09:02:38 +00:00
|
|
|
* as a source of settings for newly created buffers).
|
|
|
|
*
|
|
|
|
* @param aMainContext is the context that should be treated as the main one.
|
|
|
|
*/
|
|
|
|
inline virtual void SetMainContext( cairo_t* aMainContext )
|
|
|
|
{
|
|
|
|
m_mainContext = aMainContext;
|
|
|
|
|
|
|
|
// Use the context's transformation matrix
|
|
|
|
cairo_get_matrix( m_mainContext, &m_matrix );
|
|
|
|
}
|
|
|
|
|
2013-07-25 12:40:04 +00:00
|
|
|
protected:
|
2020-12-21 23:42:21 +00:00
|
|
|
/**
|
|
|
|
* Perform freeing of resources.
|
|
|
|
*/
|
|
|
|
void clean();
|
|
|
|
|
|
|
|
/// Return number of currently used buffers.
|
|
|
|
unsigned int usedBuffers()
|
|
|
|
{
|
|
|
|
return m_buffers.size();
|
|
|
|
}
|
|
|
|
|
2019-08-29 02:28:40 +00:00
|
|
|
typedef uint32_t* BitmapPtr;
|
2013-07-25 12:40:04 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2013-07-30 16:29:54 +00:00
|
|
|
cairo_t* context; ///< Main texture handle
|
|
|
|
cairo_surface_t* surface; ///< Point to which an image from texture is attached
|
|
|
|
BitmapPtr bitmap; ///< Pixel storage
|
2013-07-25 12:40:04 +00:00
|
|
|
} CAIRO_BUFFER;
|
|
|
|
|
2013-08-19 09:02:38 +00:00
|
|
|
unsigned int m_current; ///< Currently used buffer handle
|
2013-07-25 12:40:04 +00:00
|
|
|
typedef std::deque<CAIRO_BUFFER> CAIRO_BUFFERS;
|
|
|
|
|
|
|
|
/// Pointer to the current context, so it can be changed
|
2013-07-30 16:29:54 +00:00
|
|
|
cairo_t** m_currentContext;
|
2013-07-25 12:40:04 +00:00
|
|
|
|
|
|
|
/// Rendering target used for compositing (the main display)
|
2013-07-30 16:29:54 +00:00
|
|
|
cairo_t* m_mainContext;
|
2013-07-25 12:40:04 +00:00
|
|
|
|
|
|
|
/// Transformation matrix
|
2013-07-30 16:29:54 +00:00
|
|
|
cairo_matrix_t m_matrix;
|
2013-07-25 12:40:04 +00:00
|
|
|
|
|
|
|
/// Stores information about initialized buffers
|
2013-07-30 16:29:54 +00:00
|
|
|
CAIRO_BUFFERS m_buffers;
|
2013-07-25 12:40:04 +00:00
|
|
|
|
|
|
|
unsigned int m_stride; ///< Stride to use given the desired format and width
|
|
|
|
unsigned int m_bufferSize; ///< Amount of memory needed to store a buffer
|
|
|
|
|
2018-01-04 12:13:00 +00:00
|
|
|
cairo_antialias_t m_currentAntialiasingMode;
|
2013-07-25 12:40:04 +00:00
|
|
|
};
|
2013-10-14 14:13:35 +00:00
|
|
|
} // namespace KIGFX
|
2013-07-25 12:40:04 +00:00
|
|
|
|
|
|
|
#endif /* COMPOSITOR_H_ */
|