1 /*
2  *  Copyright (c) 2017 Dmitry Kazakov <dimula73@gmail.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef KISSHAREDQIMAGEPYRAMID_H
20 #define KISSHAREDQIMAGEPYRAMID_H
21 
22 #include "kritabrush_export.h"
23 
24 #include <QSharedPointer>
25 #include <QMutex>
26 #include <QAtomicPointer>
27 
28 
29 class KisQImagePyramid;
30 class KisBrush;
31 
32 /**
33  * A special class for storing the shared brushes pyramid among different brushes,
34  * which can be used by different threads. All the calls to pyramid() are thread-safe.
35  *
36  * Please note, that one cannot alter the pyramid. If the brush alters the pyramid,
37  * it should just detach from this object and create a new, unshared one.
38  */
39 
40 class BRUSH_EXPORT KisSharedQImagePyramid
41 {
42 public:
43     KisSharedQImagePyramid();
44     ~KisSharedQImagePyramid();
45 
46 public:
47 
48     // lazy create and return the pyramid
49     const KisQImagePyramid* pyramid(const KisBrush *brush) const;
50 
51     // return true if the pyramid is already prepared
52     bool isNull() const;
53 
54 private:
55     mutable QMutex m_mutex;
56 
57     mutable QSharedPointer<const KisQImagePyramid> m_pyramid;
58     mutable QAtomicPointer<const KisQImagePyramid> m_cachedPyramidPointer;
59 };
60 
61 #endif // KISSHAREDQIMAGEPYRAMID_H
62