src/hbcore/ovgeffects/hbvgeffect.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    31 #include <QGraphicsScene>
    31 #include <QGraphicsScene>
    32 #include <QGraphicsItem>
    32 #include <QGraphicsItem>
    33 #include <QSet>
    33 #include <QSet>
    34 #include <hbmainwindow.h>
    34 #include <hbmainwindow.h>
    35 #include <hbmainwindow_p.h>
    35 #include <hbmainwindow_p.h>
       
    36 #include <hbinstance_p.h>
    36 
    37 
    37 /*!
    38 /*!
    38  * \class HbVgEffect
    39  * \class HbVgEffect
    39  *
    40  *
    40  * \brief Abstract base class for OpenVG effects.
    41  * \brief Abstract base class for OpenVG effects.
   102       rootEffect(0),
   103       rootEffect(0),
   103       sourceGraphicsItem(0),
   104       sourceGraphicsItem(0),
   104       mainWindow(0),
   105       mainWindow(0),
   105       lastUsedRotation(0),
   106       lastUsedRotation(0),
   106       lastRotationTransformAngle(0),
   107       lastRotationTransformAngle(0),
   107       forceSwMode(false)
   108       forceSwMode(false),
       
   109       alwaysClearPixmaps(true) // Enable it always for now, due to limited gpu memory.
   108 {
   110 {
   109 }
   111 }
   110 
   112 
   111 /*!
   113 /*!
   112  * \internal
   114  * \internal
   129         *pixmap = QPixmap(size);
   131         *pixmap = QPixmap(size);
   130     }
   132     }
   131     return qPixmapToVGImage(*pixmap);
   133     return qPixmapToVGImage(*pixmap);
   132 }
   134 }
   133 #endif
   135 #endif
       
   136 
       
   137 /*!
       
   138  * Clears all the pixmaps that live as member variables. This is not mandatory,
       
   139  * but helps reducing graphics memory usage.
       
   140  *
       
   141  * The downside is decreased performance due to new pixmap creation in the next
       
   142  * ensurePixmap() call.
       
   143  *
       
   144  * \internal
       
   145  */
       
   146 void HbVgEffectPrivate::clearPixmaps()
       
   147 {
       
   148     // Note: If the effect used tryCache() then the underlying pixmap data for
       
   149     // dstPixmap will not really be destroyed here due to implicit sharing.
       
   150     srcPixmap = dstPixmap = tmpPixmap = QPixmap();
       
   151 }
   134 
   152 
   135 /*!
   153 /*!
   136  * Invalidates the cache but only if it has not been done already.
   154  * Invalidates the cache but only if it has not been done already.
   137  *
   155  *
   138  * \internal
   156  * \internal
   396  *
   414  *
   397  * Note that the source pixmap is not requested and the painter's
   415  * Note that the source pixmap is not requested and the painter's
   398  * world transform is not reset before calling this, in contrast to
   416  * world transform is not reset before calling this, in contrast to
   399  * performEffect(). (this means that neither d->srcPixmap nor
   417  * performEffect(). (this means that neither d->srcPixmap nor
   400  * d->worldTransform is available).
   418  * d->worldTransform is available).
   401  */
   419  *
   402 void HbVgEffect::performEffectSw(QPainter *painter)
   420  * If the effect is able to render itself into a pixmap then it should do so
   403 {
   421  * when \a result and \a resultPos are not 0. In this case the effect should not
   404     drawSource(painter);
   422  * paint anything onto \a devicePainter but all its output should go into a
       
   423  * newly created pixmap starting at position (0, 0). This pixmap is then
       
   424  * returned to the caller in \a result. The offset that will be needed when
       
   425  * painting the pixmap onto the devicePainter is passed back in \a resultPos.
       
   426  */
       
   427 void HbVgEffect::performEffectSw(QPainter *devicePainter, QPixmap *result, QPointF *resultPos)
       
   428 {
       
   429     Q_UNUSED(result);
       
   430     Q_UNUSED(resultPos);
       
   431     drawSource(devicePainter);
   405 }
   432 }
   406 
   433 
   407 /*!
   434 /*!
   408  * \reimp
   435  * \reimp
   409  *
   436  *
   426     // is not using OpenVG.
   453     // is not using OpenVG.
   427     QPaintEngine *paintEngine = painter->paintEngine();
   454     QPaintEngine *paintEngine = painter->paintEngine();
   428     if (d->forceSwMode || !paintEngine || paintEngine->type() != QPaintEngine::OpenVG) {
   455     if (d->forceSwMode || !paintEngine || paintEngine->type() != QPaintEngine::OpenVG) {
   429         // No sourcePixmap() and world transform change here because
   456         // No sourcePixmap() and world transform change here because
   430         // in most cases we will just call drawSource().
   457         // in most cases we will just call drawSource().
   431         performEffectSw(painter);
   458         performEffectSw(painter, 0, 0);
   432         d->paramsChanged = d->cacheInvalidated = false;
   459         d->paramsChanged = d->cacheInvalidated = false;
   433         return;
   460         return;
   434     }
   461     }
   435 
   462 
   436 #ifdef HB_EFFECTS_OPENVG
   463 #ifdef HB_EFFECTS_OPENVG
   464     // Leave raw VG mode.
   491     // Leave raw VG mode.
   465     painter->endNativePainting();
   492     painter->endNativePainting();
   466 
   493 
   467     // Restore the painter's previously set transformations.
   494     // Restore the painter's previously set transformations.
   468     painter->setWorldTransform(d->worldTransform);
   495     painter->setWorldTransform(d->worldTransform);
       
   496 
       
   497     // Make sure we don't keep any unused pixmaps alive in case the application
       
   498     // wants to minimize gpu memory usage (on the expense of performance).
       
   499     if (d->alwaysClearPixmaps || HbInstancePrivate::d_ptr()->mDropHiddenIconData) {
       
   500         d->clearPixmaps();
       
   501     }
   469 
   502 
   470 #else
   503 #else
   471     // OpenVG code disabled => effect is not shown (but have the source drawn still).
   504     // OpenVG code disabled => effect is not shown (but have the source drawn still).
   472     drawSource(painter);
   505     drawSource(painter);
   473 #endif
   506 #endif
   618     Q_D(const HbVgEffect);
   651     Q_D(const HbVgEffect);
   619     return d->rootEffect ? d->rootEffect->sourceBoundingRect() : sourceBoundingRect();
   652     return d->rootEffect ? d->rootEffect->sourceBoundingRect() : sourceBoundingRect();
   620 }
   653 }
   621 
   654 
   622 /*!
   655 /*!
       
   656  * Calls sourcePixmap() for this effect, or, in case of chained effects, for the
       
   657  * root of the chain.
       
   658  */
       
   659 QPixmap HbVgEffect::sourcePixmapForRoot(Qt::CoordinateSystem system, QPoint *offset)
       
   660 {
       
   661     Q_D(HbVgEffect);
       
   662     return d->rootEffect
       
   663         ? d->rootEffect->sourcePixmapForRoot(system, offset)
       
   664         : sourcePixmap(system, offset);
       
   665 }
       
   666 
       
   667 /*!
   623  * Installs the effect on a given graphics item. This is merely a wrapper to
   668  * Installs the effect on a given graphics item. This is merely a wrapper to
   624  * QGraphicsItem::setGraphicsEffect(). To uninstall the effect use
   669  * QGraphicsItem::setGraphicsEffect(). To uninstall the effect use
   625  * setGraphicsEffect in the usual way (i.e. pass null). This function will do
   670  * setGraphicsEffect in the usual way (i.e. pass null). This function will do
   626  * nothing if \a item is null.
   671  * nothing if \a item is null.
   627  *
   672  *
   635         Q_D(HbVgEffect);
   680         Q_D(HbVgEffect);
   636         d->sourceGraphicsItem = item;
   681         d->sourceGraphicsItem = item;
   637         item->setGraphicsEffect(this);
   682         item->setGraphicsEffect(this);
   638     }
   683     }
   639 }
   684 }
       
   685 
       
   686 /*!
       
   687  * A sw-based mask effect should return ChainBehavAsSource. Anything else should
       
   688  * stick to the default ChainBehavNormal. There can only be 0 or 1 effect with
       
   689  * ChainBehavAsSource in a chain.
       
   690  */
       
   691 HbVgEffect::ChainBehavior HbVgEffect::chainBehavior() const
       
   692 {
       
   693     return ChainBehavNormal;
       
   694 }