src/hbcore/image/hbframedrawerpool.cpp
changeset 5 627c4a0fd0e7
parent 0 16d8024aca5e
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    42 /*!
    42 /*!
    43   \class HbFrameDrawerPoolKey
    43   \class HbFrameDrawerPoolKey
    44 
    44 
    45   \internal
    45   \internal
    46  */
    46  */
    47 struct HbFrameDrawerPoolKey
    47 struct HbFrameDrawerPoolKey {
    48 {
       
    49 public:
    48 public:
    50     HbFrameDrawerPoolKey(const QString &name,
    49     HbFrameDrawerPoolKey(const QString &name,
    51                          HbFrameDrawer::FrameType type,
    50                          HbFrameDrawer::FrameType type,
    52                          const QSizeF &size = QSizeF())
    51                          const QSizeF &size = QSizeF())
    53         : frameGraphicsName(name), frameGraphicsType(type), frameSize(size) { }
    52         : frameGraphicsName(name), frameGraphicsType(type), frameSize(size) { }
    54     QString frameGraphicsName;
    53     QString frameGraphicsName;
    55     HbFrameDrawer::FrameType frameGraphicsType;
    54     HbFrameDrawer::FrameType frameGraphicsType;
    56     QSizeF frameSize;
    55     QSizeF frameSize;
    57     bool operator==(const HbFrameDrawerPoolKey &other) const {
    56     bool operator==(const HbFrameDrawerPoolKey &other) const {
    58         return other.frameGraphicsName == frameGraphicsName
    57         return other.frameGraphicsName == frameGraphicsName
    59             && other.frameGraphicsType == frameGraphicsType
    58                && other.frameGraphicsType == frameGraphicsType
    60             && other.frameSize == frameSize;
    59                && other.frameSize == frameSize;
    61     }
    60     }
    62 };
    61 };
    63 
    62 
    64 /*!
    63 /*!
    65   \class HbFrameDrawerPoolValue
    64   \class HbFrameDrawerPoolValue
    66 
    65 
    67   \internal
    66   \internal
    68  */
    67  */
    69 struct HbFrameDrawerPoolValue
    68 struct HbFrameDrawerPoolValue {
    70 {
       
    71     HbFrameDrawerPoolValue()
    69     HbFrameDrawerPoolValue()
    72         : frameDrawer(0), refCount(0) { }
    70         : frameDrawer(0), refCount(0) { }
    73     HbFrameDrawerPoolValue(HbFrameDrawer *drawer)
    71     HbFrameDrawerPoolValue(HbFrameDrawer *drawer)
    74         : frameDrawer(drawer), refCount(1) { }
    72         : frameDrawer(drawer), refCount(1) { }
    75     HbFrameDrawer *frameDrawer;
    73     HbFrameDrawer *frameDrawer;
    83 
    81 
    84 typedef QHash<HbFrameDrawerPoolKey, HbFrameDrawerPoolValue> HbFrameDrawerPoolData;
    82 typedef QHash<HbFrameDrawerPoolKey, HbFrameDrawerPoolValue> HbFrameDrawerPoolData;
    85 Q_GLOBAL_STATIC(HbFrameDrawerPoolData, poolData)
    83 Q_GLOBAL_STATIC(HbFrameDrawerPoolData, poolData)
    86 
    84 
    87 /*!  Returns a new or an existing HbFrameDrawer instance. Ownership of the
    85 /*!  Returns a new or an existing HbFrameDrawer instance. Ownership of the
    88     pointer is NOT transfered to the caller. The returned pointer must never be
    86     pointer is NOT transferred to the caller. The returned pointer must never be
    89     destroyed with delete, use release() instead.
    87     destroyed with delete, use release() instead.
    90 
    88 
    91     \a frameSize is optional, if the default constructed QSizeF is
    89     \a frameSize is optional, if the default constructed QSizeF is
    92     used then it is ignored. Otherwise only framedrawers requested for
    90     used then it is ignored. Otherwise only framedrawers requested for
    93     the same size are shared (meaning that requesting a framedrawer
    91     the same size are shared (meaning that requesting a framedrawer
   125  */
   123  */
   126 void HbFrameDrawerPool::release(HbFrameDrawer *frameDrawer)
   124 void HbFrameDrawerPool::release(HbFrameDrawer *frameDrawer)
   127 {
   125 {
   128     bool inPool = false;
   126     bool inPool = false;
   129     HbFrameDrawerPoolData *pool = poolData();
   127     HbFrameDrawerPoolData *pool = poolData();
   130     foreach (const HbFrameDrawerPoolKey &key, pool->keys()) {
   128     QList<HbFrameDrawerPoolKey> keys = pool->keys();
       
   129     foreach(const HbFrameDrawerPoolKey & key, keys) {
   131         HbFrameDrawerPoolValue value = pool->value(key);
   130         HbFrameDrawerPoolValue value = pool->value(key);
   132         if (value.frameDrawer == frameDrawer) {
   131         if (value.frameDrawer == frameDrawer) {
   133             if (!--value.refCount) {
   132             if (!--value.refCount) {
   134                 delete frameDrawer;
   133                 delete frameDrawer;
   135                 pool->remove(key);
   134                 pool->remove(key);