Pass creation of Shadow sub class instance to Scene

Instead of having the Shadow factory method check the compositor type and
do the decision which Shadow sub class to create, a pure virtual method in
Scene is called which returns the specific Shadow sub class instance.
This commit is contained in:
Martin Gräßlin 2013-06-24 09:06:50 +02:00
parent 5d3d8834ab
commit 1a0e586b9c
6 changed files with 29 additions and 20 deletions

View file

@ -72,6 +72,15 @@ public:
* @param frame The EffectFrame this Scene::EffectFrame belongs to.
*/
virtual Scene::EffectFrame *createEffectFrame(EffectFrameImpl *frame) = 0;
/**
* @brief Creates the Scene specific Shadow subclass.
*
* An implementing class has to create a proper instance. It is not allowed to
* return @c null.
*
* @param toplevel The Toplevel for which the Shadow needs to be created.
*/
virtual Shadow *createShadow(Toplevel *toplevel) = 0;
/**
* Method invoked when the screen geometry is changed.
* Reimplementing classes should also invoke the parent method

View file

@ -641,6 +641,11 @@ Scene::EffectFrame *SceneOpenGL::createEffectFrame(EffectFrameImpl *frame)
return new SceneOpenGL::EffectFrame(frame, this);
}
Shadow *SceneOpenGL::createShadow(Toplevel *toplevel)
{
return new SceneOpenGLShadow(toplevel);
}
//****************************************
// SceneOpenGL2
//****************************************

View file

@ -51,6 +51,7 @@ public:
virtual void windowAdded(Toplevel*);
virtual void windowDeleted(Deleted*);
virtual Scene::EffectFrame *createEffectFrame(EffectFrameImpl *frame);
virtual Shadow *createShadow(Toplevel *toplevel);
virtual void screenGeometryChanged(const QSize &size);
virtual OverlayWindow *overlayWindow();
virtual bool blocksForRetrace() const;

View file

@ -293,6 +293,11 @@ Scene::EffectFrame *SceneXrender::createEffectFrame(EffectFrameImpl *frame)
return new SceneXrender::EffectFrame(frame);
}
Shadow *SceneXrender::createShadow(Toplevel *toplevel)
{
return new SceneXRenderShadow(toplevel);
}
//****************************************
// SceneXrender::Window
//****************************************

View file

@ -46,6 +46,7 @@ public:
virtual void windowAdded(Toplevel*);
virtual void windowDeleted(Deleted*);
virtual Scene::EffectFrame *createEffectFrame(EffectFrameImpl *frame);
virtual Shadow *createShadow(Toplevel *toplevel);
virtual void screenGeometryChanged(const QSize &size);
xcb_render_picture_t bufferPicture();
virtual OverlayWindow *overlayWindow() {

View file

@ -20,12 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "shadow.h"
// kwin
#include "atoms.h"
#include "composite.h"
#include "effects.h"
#include "toplevel.h"
#include "scene_opengl.h"
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
#include "scene_xrender.h"
#endif
namespace KWin
{
@ -48,23 +45,14 @@ Shadow *Shadow::createShadow(Toplevel *toplevel)
}
auto data = Shadow::readX11ShadowProperty(toplevel->window());
if (!data.isEmpty()) {
Shadow *shadow = NULL;
if (effects->isOpenGLCompositing()) {
shadow = new SceneOpenGLShadow(toplevel);
} else if (effects->compositingType() == XRenderCompositing) {
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
shadow = new SceneXRenderShadow(toplevel);
#endif
}
Shadow *shadow = Compositor::self()->scene()->createShadow(toplevel);
if (shadow) {
if (!shadow->init(data)) {
delete shadow;
return NULL;
}
if (toplevel->effectWindow() && toplevel->effectWindow()->sceneWindow()) {
toplevel->effectWindow()->sceneWindow()->updateShadow(shadow);
}
if (!shadow->init(data)) {
delete shadow;
return NULL;
}
if (toplevel->effectWindow() && toplevel->effectWindow()->sceneWindow()) {
toplevel->effectWindow()->sceneWindow()->updateShadow(shadow);
}
return shadow;
} else {