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>
35 #include <cairo.h>
36 #include <boost/smart_ptr/shared_array.hpp>
37 #include <deque>
38 
39 namespace KIGFX
40 {
42 {
43 public:
44  CAIRO_COMPOSITOR( cairo_t** aMainContext );
45  virtual ~CAIRO_COMPOSITOR();
46 
48  virtual void Initialize() override;
49 
51  virtual void Resize( unsigned int aWidth, unsigned int aHeight ) override;
52 
54  virtual unsigned int CreateBuffer() override;
55 
57  inline virtual unsigned int GetBuffer() const override
58  {
59  return m_current + 1;
60  }
61 
63  virtual void SetBuffer( unsigned int aBufferHandle ) override;
64 
66  virtual void Begin() override;
67 
69  virtual void ClearBuffer( const COLOR4D& aColor ) override;
70 
72  virtual void DrawBuffer( unsigned int aBufferHandle ) override;
73 
75  virtual void Present() override;
76 
84  inline virtual void SetMainContext( cairo_t* aMainContext )
85  {
86  m_mainContext = aMainContext;
87 
88  // Use the context's transformation matrix
89  cairo_get_matrix( m_mainContext, &m_matrix );
90  }
91 
92 protected:
93  typedef boost::shared_array<unsigned int> BitmapPtr;
94  typedef struct
95  {
96  cairo_t* context;
97  cairo_surface_t* surface;
98  BitmapPtr bitmap;
99  } CAIRO_BUFFER;
100 
101  unsigned int m_current;
102  typedef std::deque<CAIRO_BUFFER> CAIRO_BUFFERS;
103 
105  cairo_t** m_currentContext;
106 
108  cairo_t* m_mainContext;
109 
111  cairo_matrix_t m_matrix;
112 
114  CAIRO_BUFFERS m_buffers;
115 
116  unsigned int m_stride;
117  unsigned int m_bufferSize;
118 
123  void clean();
124 
126  unsigned int usedBuffers()
127  {
128  return m_buffers.size();
129  }
130 };
131 } // namespace KIGFX
132 
133 #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
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_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.
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