Improve performance of Scene::Window

Replace dynamic_casts to check the type for for Toplevel by isFoo()
calls and use static_casts in such blocks.

Furthermore method shape() returns now a constant reference instead of a
copy of the QRegion.

REVIEW: 106364
icc-effect-5.14.5
Martin Gräßlin 2012-09-07 09:40:44 +02:00
parent 4240494130
commit 967be8b95a
2 changed files with 15 additions and 15 deletions

View File

@ -490,7 +490,7 @@ void Scene::Window::discardShape()
// Find out the shape of the window using the XShape extension
// or if shape is not set then simply it's the window geometry.
QRegion Scene::Window::shape() const
const QRegion &Scene::Window::shape() const
{
if (!shape_valid) {
Client* c = dynamic_cast< Client* >(toplevel);
@ -519,29 +519,28 @@ QRegion Scene::Window::shape() const
QRegion Scene::Window::clientShape() const
{
Client *c = dynamic_cast< Client* >(toplevel);
if (c && c->isShade())
return QRegion();
if (toplevel->isClient()) {
Client *c = static_cast< Client * > (toplevel);
if (c->isShade())
return QRegion();
}
// TODO: cache
const QRegion r = shape() & QRect(toplevel->clientPos(), toplevel->clientSize());
return r.isEmpty() ? QRegion() : r;
}
bool Scene::Window::isVisible() const
{
if (dynamic_cast< Deleted* >(toplevel) != NULL)
if (toplevel->isDeleted())
return false;
if (!toplevel->isOnCurrentDesktop())
return false;
if (!toplevel->isOnCurrentActivity())
return false;
if (Client* c = dynamic_cast< Client* >(toplevel))
return c->isShown(true);
if (toplevel->isClient())
return (static_cast< Client *>(toplevel))->isShown(true);
return true; // Unmanaged is always visible
// TODO there may be transformations, so ignore this for now
return !toplevel->geometry()
.intersected(QRect(0, 0, displayWidth(), displayHeight()))
.isEmpty();
}
bool Scene::Window::isOpaque() const
@ -557,13 +556,14 @@ bool Scene::Window::isPaintingEnabled() const
void Scene::Window::resetPaintingEnabled()
{
disable_painting = 0;
if (dynamic_cast< Deleted* >(toplevel) != NULL)
if (toplevel->isDeleted())
disable_painting |= PAINT_DISABLED_BY_DELETE;
if (!toplevel->isOnCurrentDesktop())
disable_painting |= PAINT_DISABLED_BY_DESKTOP;
if (!toplevel->isOnCurrentActivity())
disable_painting |= PAINT_DISABLED_BY_ACTIVITY;
if (Client* c = dynamic_cast< Client* >(toplevel)) {
if (toplevel->isClient()) {
Client *c = static_cast<Client*>(toplevel);
if (c->isMinimized())
disable_painting |= PAINT_DISABLED_BY_MINIMIZE;
if (c->tabGroup() && c != c->tabGroup()->current())
@ -612,7 +612,7 @@ WindowQuadList Scene::Window::buildQuads(bool force) const
if (m_shadow) {
ret << m_shadow->shadowQuads();
}
effects->buildQuads(static_cast<Client*>(toplevel)->effectWindow(), ret);
effects->buildQuads(toplevel->effectWindow(), ret);
cached_quad_list = new WindowQuadList(ret);
return ret;
}

View File

@ -207,7 +207,7 @@ public:
// is the window fully opaque
bool isOpaque() const;
// shape of the window
QRegion shape() const;
const QRegion &shape() const;
QRegion clientShape() const;
void discardShape();
void updateToplevel(Toplevel* c);