KiCad PCB EDA Suite
cairo_compositor.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 CERN
5  * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
32 #ifndef CAIRO_COMPOSITOR_H_
33 #define CAIRO_COMPOSITOR_H_
34 
35 #include <gal/compositor.h>
37 #include <cairo.h>
38 
39 #include <cstdint>
40 #include <deque>
41 
42 namespace KIGFX
43 {
45 {
46 public:
47  CAIRO_COMPOSITOR( cairo_t** aMainContext );
48  virtual ~CAIRO_COMPOSITOR();
49 
51  virtual void Initialize() override;
52 
54  virtual void Resize( unsigned int aWidth, unsigned int aHeight ) override;
55 
57  virtual unsigned int CreateBuffer() override;
58 
60  inline virtual unsigned int GetBuffer() const override
61  {
62  return m_current + 1;
63  }
64 
66  virtual void SetBuffer( unsigned int aBufferHandle ) override;
67 
69  virtual void Begin() override;
70 
72  virtual void ClearBuffer( const COLOR4D& aColor ) override;
73 
81  void DrawBuffer( unsigned int aSourceHandle, unsigned int aDestHandle, cairo_operator_t op );
82 
84  virtual void DrawBuffer( unsigned int aBufferHandle ) override;
85 
87  virtual void Present() override;
88 
89  void SetAntialiasingMode( CAIRO_ANTIALIASING_MODE aMode ); // clears all buffers
91  {
93  {
94  case CAIRO_ANTIALIAS_FAST:
96  case CAIRO_ANTIALIAS_GOOD:
98  default:
100  }
101  }
102 
109  inline virtual void SetMainContext( cairo_t* aMainContext )
110  {
111  m_mainContext = aMainContext;
112 
113  // Use the context's transformation matrix
114  cairo_get_matrix( m_mainContext, &m_matrix );
115  }
116 
117 protected:
121  void clean();
122 
124  unsigned int usedBuffers()
125  {
126  return m_buffers.size();
127  }
128 
129  typedef uint32_t* BitmapPtr;
131  {
132  cairo_t* context;
133  cairo_surface_t* surface;
135  };
136 
137  unsigned int m_current;
138  typedef std::deque<CAIRO_BUFFER> CAIRO_BUFFERS;
139 
141  cairo_t** m_currentContext;
142 
144  cairo_t* m_mainContext;
145 
147  cairo_matrix_t m_matrix;
148 
151 
152  unsigned int m_stride;
153  unsigned int m_bufferSize;
154 
155  cairo_antialias_t m_currentAntialiasingMode;
156 };
157 } // namespace KIGFX
158 
159 #endif /* COMPOSITOR_H_ */
cairo_t * context
Main texture handle.
void clean()
Perform freeing of resources.
unsigned int m_stride
Stride to use given the desired format and width.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
CAIRO_ANTIALIASING_MODE GetAntialiasingMode() const
virtual void Begin() override
Call this at the beginning of each frame.
cairo_surface_t * surface
Point to which an image from texture is attached.
virtual void Present() override
Call this to present the output buffer to the screen.
unsigned int usedBuffers()
Return number of currently used buffers.
virtual void SetMainContext(cairo_t *aMainContext)
Set a context to be treated as the main context (ie.
virtual void ClearBuffer(const COLOR4D &aColor) override
Clear the selected buffer (set by the SetBuffer() function).
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
unsigned int m_current
Currently used buffer handle.
virtual unsigned int GetBuffer() const override
Return currently used buffer handle.
CAIRO_BUFFERS m_buffers
Stores information about initialized buffers.
std::deque< CAIRO_BUFFER > CAIRO_BUFFERS
cairo_antialias_t m_currentAntialiasingMode
cairo_t ** m_currentContext
Pointer to the current context, so it can be changed.
void DrawBuffer(unsigned int aSourceHandle, unsigned int aDestHandle, cairo_operator_t op)
Paints source to destination using the cairo operator.
void SetAntialiasingMode(CAIRO_ANTIALIASING_MODE aMode)
unsigned int m_bufferSize
Amount of memory needed to store a buffer.
virtual void Initialize() override
Perform primary initialization, necessary to use the object.
CAIRO_COMPOSITOR(cairo_t **aMainContext)
virtual void Resize(unsigned int aWidth, unsigned int aHeight) override
Clear the state of COMPOSITOR, so it has to be reinitialized again with the new dimensions.
cairo_matrix_t m_matrix
Transformation matrix.
cairo_t * m_mainContext
Rendering target used for compositing (the main display)
virtual unsigned int CreateBuffer() override
Prepare a new buffer that may be used as a rendering target.
Class that handles multitarget rendering (ie.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103