KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
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, see <https://www.gnu.org/licenses/>.
20 */
21
27
28#ifndef CAIRO_COMPOSITOR_H_
29#define CAIRO_COMPOSITOR_H_
30
31#include <gal/compositor.h>
33#include <cairo.h>
34
35#include <cstdint>
36#include <deque>
37
38namespace KIGFX
39{
41{
42public:
43 CAIRO_COMPOSITOR( cairo_t** aMainContext );
44 virtual ~CAIRO_COMPOSITOR();
45
47 virtual void Initialize() override;
48
50 virtual void Resize( unsigned int aWidth, unsigned int aHeight ) override;
51
53 virtual unsigned int CreateBuffer() override;
54
56 inline virtual unsigned int GetBuffer() const override
57 {
58 return m_current + 1;
59 }
60
62 virtual void SetBuffer( unsigned int aBufferHandle ) override;
63
65 virtual void Begin() override;
66
68 virtual void ClearBuffer( const COLOR4D& aColor ) override;
69
77 void DrawBuffer( unsigned int aSourceHandle, unsigned int aDestHandle, cairo_operator_t op );
78
80 virtual void DrawBuffer( unsigned int aBufferHandle ) override;
81
83 virtual void Present() override;
84
85 void SetAntialiasingMode( GAL_ANTIALIASING_MODE aMode ); // clears all buffers
87 {
89 {
90 case CAIRO_ANTIALIAS_FAST:
92 case CAIRO_ANTIALIAS_GOOD:
94 default:
96 }
97 }
98
105 inline virtual void SetMainContext( cairo_t* aMainContext )
106 {
107 m_mainContext = aMainContext;
108
109 // Use the context's transformation matrix
110 cairo_get_matrix( m_mainContext, &m_matrix );
111 }
112
113protected:
117 void clean();
118
120 unsigned int usedBuffers()
121 {
122 return m_buffers.size();
123 }
124
125 typedef uint8_t* BitmapPtr;
127 {
128 cairo_t* context;
129 cairo_surface_t* surface;
131 };
132
133 unsigned int m_current;
134 typedef std::deque<CAIRO_BUFFER> CAIRO_BUFFERS;
135
138
141
143 cairo_matrix_t m_matrix;
144
147
148 unsigned int m_stride;
149 unsigned int m_bufferSize;
150
151 cairo_antialias_t m_currentAntialiasingMode;
152};
153} // namespace KIGFX
154
155#endif /* COMPOSITOR_H_ */
unsigned int m_bufferSize
Amount of memory needed to store a buffer.
virtual void Present() override
Call this to present the output buffer to the screen.
unsigned int m_stride
Stride to use given the desired format and width.
GAL_ANTIALIASING_MODE GetAntialiasingMode() const
CAIRO_COMPOSITOR(cairo_t **aMainContext)
cairo_antialias_t m_currentAntialiasingMode
virtual unsigned int CreateBuffer() override
Prepare a new buffer that may be used as a rendering target.
void SetAntialiasingMode(GAL_ANTIALIASING_MODE aMode)
cairo_t * m_mainContext
Rendering target used for compositing (the main display)
virtual void ClearBuffer(const COLOR4D &aColor) override
Clear the selected buffer (set by the SetBuffer() function).
virtual void Begin() override
Call this at the beginning of each frame.
void clean()
Perform freeing of resources.
void DrawBuffer(unsigned int aSourceHandle, unsigned int aDestHandle, cairo_operator_t op)
Paints source to destination using the cairo operator.
unsigned int usedBuffers()
Return number of currently used buffers.
cairo_matrix_t m_matrix
Transformation matrix.
cairo_t ** m_currentContext
Pointer to the current context, so it can be changed.
std::deque< CAIRO_BUFFER > CAIRO_BUFFERS
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.
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.
virtual void SetMainContext(cairo_t *aMainContext)
Set a context to be treated as the main context (ie.
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
virtual void Initialize() override
Perform primary initialization, necessary to use the object.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Class that handles multitarget rendering (ie.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
cairo_surface_t * surface
Point to which an image from texture is attached.
cairo_t * context
Main texture handle.