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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
31 #ifndef CAIRO_COMPOSITOR_H_
32 #define CAIRO_COMPOSITOR_H_
33 
34 #include <gal/compositor.h>
36 #include <cairo.h>
37 #include <boost/smart_ptr/shared_array.hpp>
38 #include <deque>
39 
40 namespace KIGFX
41 {
43 {
44 public:
45  CAIRO_COMPOSITOR( cairo_t** aMainContext );
46  virtual ~CAIRO_COMPOSITOR();
47 
49  virtual void Initialize() override;
50 
52  virtual void Resize( unsigned int aWidth, unsigned int aHeight ) override;
53 
55  virtual unsigned int CreateBuffer() override;
56 
58  inline virtual unsigned int GetBuffer() const override
59  {
60  return m_current + 1;
61  }
62 
64  virtual void SetBuffer( unsigned int aBufferHandle ) override;
65 
67  virtual void Begin() override;
68 
70  virtual void ClearBuffer( const COLOR4D& aColor ) override;
71 
73  virtual void DrawBuffer( unsigned int aBufferHandle ) override;
74 
76  virtual void Present() override;
77 
78  void SetAntialiasingMode( CAIRO_ANTIALIASING_MODE aMode ); // clears all buffers
80  {
82  {
83  case CAIRO_ANTIALIAS_FAST:
85  case CAIRO_ANTIALIAS_GOOD:
87  case CAIRO_ANTIALIAS_BEST:
89  default:
91  }
92  }
93 
101  inline virtual void SetMainContext( cairo_t* aMainContext )
102  {
103  m_mainContext = aMainContext;
104 
105  // Use the context's transformation matrix
106  cairo_get_matrix( m_mainContext, &m_matrix );
107  }
108 
109 protected:
110  typedef boost::shared_array<unsigned int> BitmapPtr;
111  typedef struct
112  {
113  cairo_t* context;
114  cairo_surface_t* surface;
116  } CAIRO_BUFFER;
117 
118  unsigned int m_current;
119  typedef std::deque<CAIRO_BUFFER> CAIRO_BUFFERS;
120 
122  cairo_t** m_currentContext;
123 
125  cairo_t* m_mainContext;
126 
128  cairo_matrix_t m_matrix;
129 
132 
133  unsigned int m_stride;
134  unsigned int m_bufferSize;
135 
136  cairo_antialias_t m_currentAntialiasingMode;
137 
142  void clean();
143 
145  unsigned int usedBuffers()
146  {
147  return m_buffers.size();
148  }
149 };
150 } // namespace KIGFX
151 
152 #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.
boost::shared_array< unsigned int > BitmapPtr
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