window: use std::unique_ptr to manage the shadow

This commit is contained in:
Xaver Hugl 2023-01-07 21:43:09 +01:00
parent 6e87fae7f7
commit 3c8d2d6f18
10 changed files with 27 additions and 40 deletions

View file

@ -49,7 +49,6 @@ Deleted::~Deleted()
}
deleteEffectWindow();
deleteItem();
deleteShadow();
}
WindowItem *Deleted::createItem(Scene *scene)

View file

@ -65,7 +65,7 @@ public:
*
* @param window The Window for which the Shadow needs to be created.
*/
virtual Shadow *createShadow(Window *window) = 0;
virtual std::unique_ptr<Shadow> createShadow(Window *window) = 0;
virtual bool makeOpenGLContextCurrent();
virtual void doneOpenGLContextCurrent();

View file

@ -69,9 +69,9 @@ bool WorkspaceSceneOpenGL::supportsNativeFence() const
return m_backend->supportsNativeFence();
}
Shadow *WorkspaceSceneOpenGL::createShadow(Window *window)
std::unique_ptr<Shadow> WorkspaceSceneOpenGL::createShadow(Window *window)
{
return new SceneOpenGLShadow(window);
return std::make_unique<SceneOpenGLShadow>(window);
}
DecorationRenderer *WorkspaceSceneOpenGL::createDecorationRenderer(Decoration::DecoratedClientImpl *impl)

View file

@ -30,7 +30,7 @@ public:
explicit WorkspaceSceneOpenGL(OpenGLBackend *backend);
~WorkspaceSceneOpenGL() override;
Shadow *createShadow(Window *window) override;
std::unique_ptr<Shadow> createShadow(Window *window) override;
bool makeOpenGLContextCurrent() override;
void doneOpenGLContextCurrent() override;
bool supportsNativeFence() const override;

View file

@ -36,9 +36,9 @@ WorkspaceSceneQPainter::~WorkspaceSceneQPainter()
{
}
Shadow *WorkspaceSceneQPainter::createShadow(Window *window)
std::unique_ptr<Shadow> WorkspaceSceneQPainter::createShadow(Window *window)
{
return new SceneQPainterShadow(window);
return std::make_unique<SceneQPainterShadow>(window);
}
DecorationRenderer *WorkspaceSceneQPainter::createDecorationRenderer(Decoration::DecoratedClientImpl *impl)

View file

@ -25,7 +25,7 @@ public:
explicit WorkspaceSceneQPainter(QPainterBackend *backend);
~WorkspaceSceneQPainter() override;
Shadow *createShadow(Window *window) override;
std::unique_ptr<Shadow> createShadow(Window *window) override;
DecorationRenderer *createDecorationRenderer(Decoration::DecoratedClientImpl *impl) override;
bool animationsSupported() const override

View file

@ -41,9 +41,9 @@ Shadow::~Shadow()
{
}
Shadow *Shadow::createShadow(Window *window)
std::unique_ptr<Shadow> Shadow::createShadow(Window *window)
{
Shadow *shadow = createShadowFromDecoration(window);
auto shadow = createShadowFromDecoration(window);
if (!shadow && waylandServer()) {
shadow = createShadowFromWayland(window);
}
@ -56,14 +56,12 @@ Shadow *Shadow::createShadow(Window *window)
return shadow;
}
Shadow *Shadow::createShadowFromX11(Window *window)
std::unique_ptr<Shadow> Shadow::createShadowFromX11(Window *window)
{
auto data = Shadow::readX11ShadowProperty(window->window());
if (!data.isEmpty()) {
Shadow *shadow = Compositor::self()->scene()->createShadow(window);
auto shadow = Compositor::self()->scene()->createShadow(window);
if (!shadow->init(data)) {
delete shadow;
return nullptr;
}
return shadow;
@ -72,20 +70,19 @@ Shadow *Shadow::createShadowFromX11(Window *window)
}
}
Shadow *Shadow::createShadowFromDecoration(Window *window)
std::unique_ptr<Shadow> Shadow::createShadowFromDecoration(Window *window)
{
if (!window->decoration()) {
return nullptr;
}
Shadow *shadow = Compositor::self()->scene()->createShadow(window);
auto shadow = Compositor::self()->scene()->createShadow(window);
if (!shadow->init(window->decoration())) {
delete shadow;
return nullptr;
}
return shadow;
}
Shadow *Shadow::createShadowFromWayland(Window *window)
std::unique_ptr<Shadow> Shadow::createShadowFromWayland(Window *window)
{
auto surface = window->surface();
if (!surface) {
@ -95,15 +92,14 @@ Shadow *Shadow::createShadowFromWayland(Window *window)
if (!s) {
return nullptr;
}
Shadow *shadow = Compositor::self()->scene()->createShadow(window);
auto shadow = Compositor::self()->scene()->createShadow(window);
if (!shadow->init(s)) {
delete shadow;
return nullptr;
}
return shadow;
}
Shadow *Shadow::createShadowFromInternalWindow(Window *window)
std::unique_ptr<Shadow> Shadow::createShadowFromInternalWindow(Window *window)
{
const InternalWindow *internalWindow = qobject_cast<InternalWindow *>(window);
if (!internalWindow) {
@ -113,9 +109,8 @@ Shadow *Shadow::createShadowFromInternalWindow(Window *window)
if (!handle) {
return nullptr;
}
Shadow *shadow = Compositor::self()->scene()->createShadow(window);
auto shadow = Compositor::self()->scene()->createShadow(window);
if (!shadow->init(handle)) {
delete shadow;
return nullptr;
}
return shadow;

View file

@ -71,7 +71,7 @@ public:
* @param window The Window for which the shadow should be created
* @return Created Shadow or @c NULL in case there is no shadow defined.
*/
static Shadow *createShadow(Window *window);
static std::unique_ptr<Shadow> createShadow(Window *window);
Window *window() const;
/**
@ -134,10 +134,10 @@ protected:
void setShadowElement(const QPixmap &shadow, ShadowElements element);
private:
static Shadow *createShadowFromX11(Window *window);
static Shadow *createShadowFromDecoration(Window *window);
static Shadow *createShadowFromWayland(Window *window);
static Shadow *createShadowFromInternalWindow(Window *window);
static std::unique_ptr<Shadow> createShadowFromX11(Window *window);
static std::unique_ptr<Shadow> createShadowFromDecoration(Window *window);
static std::unique_ptr<Shadow> createShadowFromWayland(Window *window);
static std::unique_ptr<Shadow> createShadowFromInternalWindow(Window *window);
static QVector<uint32_t> readX11ShadowProperty(xcb_window_t id);
bool init(const QVector<uint32_t> &data);
bool init(KDecoration2::Decoration *decoration);

View file

@ -191,7 +191,7 @@ void Window::copyToDeleted(Window *c)
m_effectWindow->setWindow(this);
}
m_windowItem = std::exchange(c->m_windowItem, nullptr);
m_shadow = std::exchange(c->m_shadow, nullptr);
m_shadow = std::move(c->m_shadow);
if (m_shadow) {
m_shadow->setWindow(this);
}
@ -366,7 +366,7 @@ void Window::finishCompositing(ReleaseReason releaseReason)
item->destroyDamage();
}
}
deleteShadow();
m_shadow.reset();
deleteEffectWindow();
deleteItem();
}
@ -400,12 +400,6 @@ void Window::setReadyForPainting()
}
}
void Window::deleteShadow()
{
delete m_shadow;
m_shadow = nullptr;
}
void Window::deleteEffectWindow()
{
delete m_effectWindow;
@ -448,7 +442,7 @@ bool Window::isOnOutput(Output *output) const
Shadow *Window::shadow() const
{
return m_shadow;
return m_shadow.get();
}
void Window::updateShadow()
@ -458,7 +452,7 @@ void Window::updateShadow()
}
if (m_shadow) {
if (!m_shadow->updateShadow()) {
deleteShadow();
m_shadow.reset();
}
Q_EMIT shadowChanged();
} else {

View file

@ -1590,7 +1590,6 @@ protected:
void getSkipCloseAnimation();
void copyToDeleted(Window *c);
void disownDataPassedToDeleted();
void deleteShadow();
void deleteEffectWindow();
void setDepth(int depth);
@ -1922,7 +1921,7 @@ private:
bool is_shape;
EffectWindowImpl *m_effectWindow;
WindowItem *m_windowItem = nullptr;
Shadow *m_shadow = nullptr;
std::unique_ptr<Shadow> m_shadow;
QString resource_name;
QString resource_class;
ClientMachine *m_clientMachine;