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 KISDABCACHEUTILS_H
20 #define KISDABCACHEUTILS_H
21 
22 #include <QRect>
23 #include <QSize>
24 
25 #include "kis_types.h"
26 
27 #include <kis_pressure_mirror_option.h>
28 #include "kis_dab_shape.h"
29 
30 #include "kritapaintop_export.h"
31 #include <functional>
32 
33 class KisBrush;
34 typedef KisSharedPtr<KisBrush> KisBrushSP;
35 
36 class KisColorSource;
37 class KisPressureSharpnessOption;
38 class KisTextureProperties;
39 
40 
41 namespace KisDabCacheUtils
42 {
43 
44 struct PAINTOP_EXPORT DabRenderingResources
45 {
46     DabRenderingResources();
47     virtual ~DabRenderingResources();
48 
49     virtual void syncResourcesToSeqNo(int seqNo, const KisPaintInformation &info);
50 
51     KisBrushSP brush;
52     QScopedPointer<KisColorSource> colorSource;
53 
54     QScopedPointer<KisPressureSharpnessOption> sharpnessOption;
55     QScopedPointer<KisTextureProperties> textureOption;
56 
57     KisPaintDeviceSP colorSourceDevice;
58 
59 private:
60     DabRenderingResources(const DabRenderingResources &rhs) = delete;
61 };
62 
63 typedef std::function<DabRenderingResources*()> ResourcesFactory;
64 
65 struct PAINTOP_EXPORT DabRequestInfo
66 {
67     DabRequestInfo(const KoColor &_color,
68                    const QPointF &_cursorPoint,
69                    const KisDabShape &_shape,
70                    const KisPaintInformation &_info,
71                    qreal _softnessFactor,
72                    qreal _lightnessStrength = 1.0)
colorDabRequestInfo73         : color(_color),
74           cursorPoint(_cursorPoint),
75           shape(_shape),
76           info(_info),
77           softnessFactor(_softnessFactor),
78           lightnessStrength(_lightnessStrength)
79     {
80     }
81 
82     const KoColor &color;
83     const QPointF &cursorPoint;
84     const KisDabShape &shape;
85     const KisPaintInformation &info;
86     const qreal softnessFactor;
87     const qreal lightnessStrength;
88 
89 private:
90     DabRequestInfo(const DabRequestInfo &rhs);
91 };
92 
93 struct PAINTOP_EXPORT DabGenerationInfo
94 {
95     MirrorProperties mirrorProperties;
96     KisDabShape shape;
97     QRect dstDabRect;
98     QPointF subPixel;
99     bool solidColorFill = true;
100     KoColor paintColor;
101     KisPaintInformation info;
102     qreal softnessFactor = 1.0;
103     qreal lightnessStrength = 1.0;
104 
105     bool needsPostprocessing = false;
106 };
107 
108 PAINTOP_EXPORT QRect correctDabRectWhenFetchedFromCache(const QRect &dabRect,
109                                                         const QSize &realDabSize);
110 
111 PAINTOP_EXPORT void generateDab(const DabGenerationInfo &di,
112                                 DabRenderingResources *resources,
113                                 KisFixedPaintDeviceSP *dab);
114 
115 PAINTOP_EXPORT void postProcessDab(KisFixedPaintDeviceSP dab,
116                                    const QPoint &dabTopLeft,
117                                    const KisPaintInformation& info,
118                                    DabRenderingResources *resources);
119 
120 }
121 
122 template<class T> class QSharedPointer;
123 class KisDabRenderingJob;
124 typedef QSharedPointer<KisDabRenderingJob> KisDabRenderingJobSP;
125 
126 #endif // KISDABCACHEUTILS_H
127