Add virtual Scene::scenePainter method

Summary:
So far EffectsHandlerImpl directly accessed SceneQPainter::painter
through a dynamic cast. If in future the QPainter based compositor should
be moved into a plugin we cannot access it through a dynamic cast.

To solve this problem the painter method is moved into Scene as
a virtual method returning a sane default value.

Reviewers: #kwin, #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D7214
This commit is contained in:
Martin Flöser 2017-08-09 06:56:23 +02:00
parent c1892e6c0f
commit ad4a3107d5
5 changed files with 16 additions and 10 deletions

View file

@ -32,7 +32,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "group.h" #include "group.h"
#include "osd.h" #include "osd.h"
#include "pointer_input.h" #include "pointer_input.h"
#include "scene_qpainter.h"
#include "unmanaged.h" #include "unmanaged.h"
#ifdef KWIN_BUILD_TABBOX #ifdef KWIN_BUILD_TABBOX
#include "tabbox.h" #include "tabbox.h"
@ -1328,11 +1327,7 @@ unsigned long EffectsHandlerImpl::xrenderBufferPicture()
QPainter *EffectsHandlerImpl::scenePainter() QPainter *EffectsHandlerImpl::scenePainter()
{ {
if (SceneQPainter *s = dynamic_cast<SceneQPainter*>(m_scene)) { return m_scene->scenePainter();
return s->painter();
} else {
return NULL;
}
} }
void EffectsHandlerImpl::toggleEffect(const QString& name) void EffectsHandlerImpl::toggleEffect(const QString& name)

View file

@ -657,6 +657,11 @@ xcb_render_picture_t Scene::xrenderBufferPicture() const
return XCB_RENDER_PICTURE_NONE; return XCB_RENDER_PICTURE_NONE;
} }
QPainter *Scene::scenePainter() const
{
return nullptr;
}
//**************************************** //****************************************
// Scene::Window // Scene::Window
//**************************************** //****************************************

View file

@ -163,6 +163,12 @@ public:
**/ **/
virtual xcb_render_picture_t xrenderBufferPicture() const; virtual xcb_render_picture_t xrenderBufferPicture() const;
/**
* The QPainter used by a QPainter based compositor scene.
* Default implementation returns @c nullptr;
**/
virtual QPainter *scenePainter() const;
Q_SIGNALS: Q_SIGNALS:
void frameRendered(); void frameRendered();

View file

@ -281,7 +281,7 @@ void SceneQPainter::Window::performPaint(int mask, QRegion region, WindowPaintDa
toplevel->resetDamage(); toplevel->resetDamage();
} }
QPainter *scenePainter = m_scene->painter(); QPainter *scenePainter = m_scene->scenePainter();
QPainter *painter = scenePainter; QPainter *painter = scenePainter;
painter->save(); painter->save();
painter->setClipRegion(region); painter->setClipRegion(region);
@ -523,7 +523,7 @@ void QPainterEffectFrame::render(QRegion region, double opacity, double frameOpa
if (m_effectFrame->geometry().isEmpty()) { if (m_effectFrame->geometry().isEmpty()) {
return; // Nothing to display return; // Nothing to display
} }
QPainter *painter = m_scene->painter(); QPainter *painter = m_scene->scenePainter();
// Render the actual frame // Render the actual frame

View file

@ -123,7 +123,7 @@ public:
return false; return false;
} }
QPainter *painter(); QPainter *scenePainter() const override;
QPainterBackend *backend() const { QPainterBackend *backend() const {
return m_backend.data(); return m_backend.data();
@ -252,7 +252,7 @@ OverlayWindow* SceneQPainter::overlayWindow()
} }
inline inline
QPainter* SceneQPainter::painter() QPainter* SceneQPainter::scenePainter() const
{ {
return m_painter.data(); return m_painter.data();
} }