File indexing completed on 2025-03-23 11:13:59
0001 /* 0002 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kwineffects.h" 0010 0011 namespace KWin 0012 { 0013 0014 class GLShader; 0015 class OffscreenEffectPrivate; 0016 class CrossFadeEffectPrivate; 0017 class ShaderEffectPrivate; 0018 0019 /** 0020 * The OffscreenEffect class is the base class for effects that paint deformed windows. 0021 * 0022 * Under the hood, the OffscreenEffect will paint the window into an offscreen texture 0023 * and the offscreen texture will be transformed afterwards. 0024 * 0025 * The redirect() function must be called when the effect wants to transform a window. 0026 * Once the effect is no longer interested in the window, the unredirect() function 0027 * must be called. 0028 * 0029 * If a window is redirected into offscreen texture, the deform() function will be 0030 * called to transform the offscreen texture. 0031 */ 0032 class KWINEFFECTS_EXPORT OffscreenEffect : public Effect 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 explicit OffscreenEffect(QObject *parent = nullptr); 0038 ~OffscreenEffect() override; 0039 0040 static bool supported(); 0041 0042 protected: 0043 void drawWindow(EffectWindow *window, int mask, const QRegion ®ion, WindowPaintData &data) override; 0044 0045 /** 0046 * This function must be called when the effect wants to animate the specified 0047 * @a window. 0048 */ 0049 void redirect(EffectWindow *window); 0050 /** 0051 * This function must be called when the effect is done animating the specified 0052 * @a window. The window will be automatically unredirected if it's deleted. 0053 */ 0054 void unredirect(EffectWindow *window); 0055 0056 /** 0057 * Override this function to transform the window. 0058 */ 0059 virtual void apply(EffectWindow *window, int mask, WindowPaintData &data, WindowQuadList &quads); 0060 0061 /** 0062 * Allows to specify a @p shader to draw the redirected texture for @p window. 0063 * Can only be called once the window is redirected. 0064 **/ 0065 void setShader(EffectWindow *window, GLShader *shader); 0066 0067 /** 0068 * Set what mode to use to snap the vertices of this effect. 0069 * 0070 * @see RenderGeometry::VertexSnappingMode 0071 */ 0072 void setVertexSnappingMode(RenderGeometry::VertexSnappingMode mode); 0073 0074 private Q_SLOTS: 0075 void handleWindowDamaged(EffectWindow *window); 0076 void handleWindowDeleted(EffectWindow *window); 0077 0078 private: 0079 void setupConnections(); 0080 void destroyConnections(); 0081 0082 std::unique_ptr<OffscreenEffectPrivate> d; 0083 }; 0084 0085 /** 0086 * The CrossFadeEffect class is the base class for effects that paints crossfades 0087 * 0088 * Windows are snapshotted at the time we want to start crossfading from. Hereafter we draw both the new contents 0089 * and the old pixmap at the ratio defined by WindowPaintData::crossFadeProgress 0090 * 0091 * Subclasses are responsible for driving the animation and calling unredirect after animation completes. 0092 * 0093 * If window geometry changes shape after this point our "old" pixmap is resized to fit approximately matching 0094 * frame geometry 0095 */ 0096 class KWINEFFECTS_EXPORT CrossFadeEffect : public Effect 0097 { 0098 Q_OBJECT 0099 public: 0100 explicit CrossFadeEffect(QObject *parent = nullptr); 0101 ~CrossFadeEffect() override; 0102 0103 void drawWindow(EffectWindow *window, int mask, const QRegion ®ion, WindowPaintData &data) override; 0104 0105 /** 0106 * This function must be called when the effect wants to animate the specified 0107 * @a window. 0108 */ 0109 void redirect(EffectWindow *window); 0110 /** 0111 * This function must be called when the effect is done animating the specified 0112 * @a window. The window will be automatically unredirected if it's deleted. 0113 */ 0114 void unredirect(EffectWindow *window); 0115 0116 /** 0117 * Allows to specify a @p shader to draw the redirected texture for @p window. 0118 * Can only be called once the window is redirected. 0119 * @since 5.25 0120 **/ 0121 void setShader(EffectWindow *window, GLShader *shader); 0122 0123 static bool supported(); 0124 0125 private: 0126 void handleWindowDeleted(EffectWindow *window); 0127 std::unique_ptr<CrossFadeEffectPrivate> d; 0128 }; 0129 0130 } // namespace KWin