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 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 
75  virtual void DrawBuffer( unsigned int aBufferHandle ) override;
76 
78  virtual void Present() override;
79 
80  void SetAntialiasingMode( CAIRO_ANTIALIASING_MODE aMode ); // clears all buffers
82  {
84  {
85  case CAIRO_ANTIALIAS_FAST:
87  case CAIRO_ANTIALIAS_GOOD:
89  case CAIRO_ANTIALIAS_BEST:
91  default:
93  }
94  }
95 
103  inline virtual void SetMainContext( cairo_t* aMainContext )
104  {
105  m_mainContext = aMainContext;
106 
107  // Use the context's transformation matrix
108  cairo_get_matrix( m_mainContext, &m_matrix );
109  }
110 
111 protected:
112  typedef uint32_t* BitmapPtr;
113  typedef struct
114  {
115  cairo_t* context;
116  cairo_surface_t* surface;
118  } CAIRO_BUFFER;
119 
120  unsigned int m_current;
121  typedef std::deque<CAIRO_BUFFER> CAIRO_BUFFERS;
122 
124  cairo_t** m_currentContext;
125 
127  cairo_t* m_mainContext;
128 
130  cairo_matrix_t m_matrix;
131 
134 
135  unsigned int m_stride;
136  unsigned int m_bufferSize;
137 
138  cairo_antialias_t m_currentAntialiasingMode;
139 
144  void clean();
145 
147  unsigned int usedBuffers()
148  {
149  return m_buffers.size();
150  }
151 };
152 } // namespace KIGFX
153 
154 #endif /* COMPOSITOR_H_ */
cairo_t * context
Main texture handle.
void clean()
Function clean() performs freeing of resources.
unsigned int m_stride
Stride to use given the desired format and width.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
CAIRO_ANTIALIASING_MODE GetAntialiasingMode() const
virtual void Begin() override
Function Begin() 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
Function Present() Call this to present the output buffer to the screen.
unsigned int usedBuffers()
Returns number of currently used buffers.
virtual void SetMainContext(cairo_t *aMainContext)
Function SetMainContext() Sets a context to be treated as the main context (ie.
virtual void ClearBuffer(const COLOR4D &aColor) override
Function ClearBuffer() clears the selected buffer (set by the SetBuffer() function).
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
unsigned int m_current
Currently used buffer handle.
virtual unsigned int GetBuffer() const override
Function GetBuffer() returns 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.
virtual void DrawBuffer(unsigned int aBufferHandle) override
Function DrawBuffer() draws the selected buffer to the output buffer.
void SetAntialiasingMode(CAIRO_ANTIALIASING_MODE aMode)
unsigned int m_bufferSize
Amount of memory needed to store a buffer.
virtual void Initialize() override
Function Reset() performs primary initialiation, necessary to use the object.
CAIRO_COMPOSITOR(cairo_t **aMainContext)
virtual void Resize(unsigned int aWidth, unsigned int aHeight) override
Function Resize() clears the state of COMPOSITOR, so it has to be reinitialized again with the new di...
cairo_matrix_t m_matrix
Transformation matrix.
cairo_t * m_mainContext
Rendering target used for compositing (the main display)
virtual unsigned int CreateBuffer() override
Function CreateBuffer() prepares a new buffer that may be used as a rendering target.
Class that handles multitarget rendering (ie.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39