File indexing completed on 2025-04-13 05:00:00
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include "core/colorspace.h" 0013 #include "scene/scene.h" 0014 0015 namespace KWin 0016 { 0017 0018 namespace Decoration 0019 { 0020 class DecoratedClientImpl; 0021 } 0022 0023 class DecorationRenderer; 0024 class Deleted; 0025 class DragAndDropIconItem; 0026 class EffectWindow; 0027 class GLTexture; 0028 class Item; 0029 class RenderLoop; 0030 class WorkspaceScene; 0031 class Shadow; 0032 class ShadowItem; 0033 class ShadowTextureProvider; 0034 class SurfaceItem; 0035 class WindowItem; 0036 class WindowPaintData; 0037 0038 class KWIN_EXPORT WorkspaceScene : public Scene 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 explicit WorkspaceScene(std::unique_ptr<ItemRenderer> renderer); 0044 ~WorkspaceScene() override; 0045 0046 void initialize(); 0047 0048 Item *containerItem() const; 0049 0050 SurfaceItem *scanoutCandidate() const override; 0051 QRegion prePaint(SceneDelegate *delegate) override; 0052 void postPaint() override; 0053 void paint(const RenderTarget &renderTarget, const QRegion ®ion) override; 0054 void frame(SceneDelegate *delegate, OutputFrame *frame) override; 0055 0056 virtual bool makeOpenGLContextCurrent(); 0057 virtual void doneOpenGLContextCurrent(); 0058 virtual bool supportsNativeFence() const; 0059 0060 virtual std::unique_ptr<DecorationRenderer> createDecorationRenderer(Decoration::DecoratedClientImpl *) = 0; 0061 virtual std::unique_ptr<ShadowTextureProvider> createShadowTextureProvider(Shadow *shadow) = 0; 0062 0063 /** 0064 * Whether the Scene is able to drive animations. 0065 * This is used as a hint to the effects system which effects can be supported. 0066 * If the Scene performs software rendering it is supposed to return @c false, 0067 * if rendering is hardware accelerated it should return @c true. 0068 */ 0069 virtual bool animationsSupported() const = 0; 0070 0071 virtual std::pair<std::shared_ptr<GLTexture>, ColorDescription> textureForOutput(Output *output) const 0072 { 0073 return {nullptr, ColorDescription::sRGB}; 0074 } 0075 0076 Q_SIGNALS: 0077 void preFrameRender(); 0078 void frameRendered(); 0079 0080 protected: 0081 void createStackingOrder(); 0082 void clearStackingOrder(); 0083 friend class EffectsHandler; 0084 // called after all effects had their paintScreen() called 0085 void finalPaintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen); 0086 // shared implementation of painting the screen in the generic 0087 // (unoptimized) way 0088 void preparePaintGenericScreen(); 0089 void paintGenericScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, Output *screen); 0090 // shared implementation of painting the screen in an optimized way 0091 void preparePaintSimpleScreen(); 0092 void paintSimpleScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion); 0093 // called after all effects had their paintWindow() called 0094 void finalPaintWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, const QRegion ®ion, WindowPaintData &data); 0095 // shared implementation, starts painting the window 0096 void paintWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, WindowItem *w, int mask, const QRegion ®ion); 0097 // called after all effects had their drawWindow() called 0098 void finalDrawWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, const QRegion ®ion, WindowPaintData &data); 0099 0100 // saved data for 2nd pass of optimized screen painting 0101 struct Phase2Data 0102 { 0103 WindowItem *item = nullptr; 0104 QRegion region; 0105 QRegion opaque; 0106 int mask = 0; 0107 }; 0108 0109 struct PaintContext 0110 { 0111 QRegion damage; 0112 int mask = 0; 0113 QList<Phase2Data> phase2Data; 0114 }; 0115 0116 // The screen that is being currently painted 0117 Output *painted_screen = nullptr; 0118 SceneDelegate *painted_delegate = nullptr; 0119 0120 // windows in their stacking order 0121 QList<WindowItem *> stacking_order; 0122 0123 private: 0124 void createDndIconItem(); 0125 void destroyDndIconItem(); 0126 0127 std::chrono::milliseconds m_expectedPresentTimestamp = std::chrono::milliseconds::zero(); 0128 // how many times finalPaintScreen() has been called 0129 int m_paintScreenCount = 0; 0130 PaintContext m_paintContext; 0131 std::unique_ptr<Item> m_containerItem; 0132 std::unique_ptr<DragAndDropIconItem> m_dndIcon; 0133 }; 0134 0135 } // namespace