示例#1
0
void GfxImageLoaderEngine::complete(GfxImageLoaderEvent *e)
{
    lock.lock();
    Ops::Iterator iter = completedops.find(e->out);
    bool exists = iter != completedops.end() && iter->id == e->id;
    if(iter != completedops.end()) 
        completedops.erase(iter);
    lock.unlock();
    if(exists) {
        e->out->_active = false;
        e->out->images(e->imgs);
    }
}
示例#2
0
void GfxImageLoaderEngine::runOp(const Op &op)
{
    QImage img;
    bool found = false;
    for(int ii = 0; ii < cache.count(); ++ii) {
        if(cache.at(ii).first == op.filename) {
            QPair<QString, QImage> p = cache.at(ii);
            cache.removeAt(ii);
            cache.append(p);
            img = p.second;
            found = true;
            break;
        }
    }
    if(!found) {
        img = QImage(op.filename);
        int contrib = img.height() * img.bytesPerLine();
        if(contrib <= maxCacheSize) {
            cacheSize += contrib;
            cache.append(qMakePair(op.filename, img));
        } 

        while(cacheSize > maxCacheSize) {
            int c = cache.first().second.bytesPerLine() * cache.first().second.height();
            cacheSize -= c;
            cache.removeFirst();
        }
    }

    QList<QImage> imgs;
    if(img.isNull()) {
        for(int ii = 0; ii < op.sizes.count(); ++ii)
            imgs << img;
    } else {
        for(int ii = 0; ii < op.sizes.count(); ++ii)
            imgs << img.scaled(op.sizes.at(ii), Qt::IgnoreAspectRatio, 
                               Qt::SmoothTransformation);
    }

    lock.lock();
    Ops::Iterator iter = ops.find(op.out);
    bool exists = iter != ops.end() && iter->id == op.id;
    if(exists) {
        op.out->filter(imgs);
        completedops.insert(op.out, op);
        ops.erase(iter);

        GfxImageLoaderEvent *e = new GfxImageLoaderEvent();
        e->out = op.out;
        e->id = op.id;
        e->imgs = imgs;
        QCoreApplication::instance()->postEvent(proxy, e);
    }
    lock.unlock();
}
示例#3
0
void QDeclarativeTimeLinePrivate::add(QDeclarativeTimeLineObject &g, const Op &o)
{
    if (g._t && g._t != q) {
        qWarning() << "QDeclarativeTimeLine: Cannot modify a QDeclarativeTimeLineValue owned by"
                   << "another timeline.";
        return;
    }
    g._t = q;

    Ops::Iterator iter = ops.find(&g);
    if (iter == ops.end()) {
        iter = ops.insert(&g, TimeLine());
        if (syncPoint > 0)
            q->pause(g, syncPoint);
    }
    if (!iter->ops.isEmpty() &&
       o.type == Op::Pause &&
       iter->ops.last().type == Op::Pause) {
        iter->ops.last().length += o.length;
        iter->length += o.length;
    } else {
        iter->ops.append(o);
        iter->length += o.length;
    }

    if (iter->length > length)
        length = iter->length;

    if (!clockRunning) {
        q->stop();
        prevTime = 0;
        clockRunning = true;

        if (syncMode == QDeclarativeTimeLine::LocalSync)  {
            syncAdj = -1;
        } else {
            syncAdj = 0;
        }
        q->start();
/*        q->tick(0);
        if (syncMode == QDeclarativeTimeLine::LocalSync)  {
            syncAdj = -1;
        } else {
            syncAdj = 0;
        }
        */
    }
}
示例#4
0
int QDeclarativeTimeLinePrivate::advance(int t)
{
    int pauseTime = -1;

    // XXX - surely there is a more efficient way?
    do {
        pauseTime = -1;
        // Minimal advance time
        int advanceTime = t;
        for (Ops::Iterator iter = ops.begin(); iter != ops.end(); ++iter) {
            TimeLine &tl = *iter;
            Op &op = tl.ops.first();
            int length = op.length - tl.consumedOpLength;
                
            if (length < advanceTime) {
                advanceTime = length;
                if (advanceTime == 0)
                    break;
            }
        }
        t -= advanceTime;

        // Process until then.  A zero length advance time will only process 
        // sets.
        QList<QPair<int, Update> > updates;

        for (Ops::Iterator iter = ops.begin(); iter != ops.end(); ) {
            QDeclarativeTimeLineValue *v = static_cast<QDeclarativeTimeLineValue *>(iter.key());
            TimeLine &tl = *iter;
            Q_ASSERT(!tl.ops.isEmpty());

            do {
                Op &op = tl.ops.first();
                if (advanceTime == 0 && op.length != 0)
                    continue;

                if (tl.consumedOpLength == 0 && 
                   op.type != Op::Pause && 
                   op.type != Op::Execute)
                    tl.base = v->value();

                if ((tl.consumedOpLength + advanceTime) == op.length) {
                    if (op.type == Op::Execute) {
                        updates << qMakePair(op.order, Update(op.event));
                    } else {
                        bool changed = false;
                        qreal val = value(op, op.length, tl.base, &changed);
                        if (changed)
                            updates << qMakePair(op.order, Update(v, val));
                    }
                    tl.length -= qMin(advanceTime, tl.length);
                    tl.consumedOpLength = 0;
                    tl.ops.removeFirst();
                } else {
                    tl.consumedOpLength += advanceTime;
                    bool changed = false;
                    qreal val = value(op, tl.consumedOpLength, tl.base, &changed);
                    if (changed)
                        updates << qMakePair(op.order, Update(v, val));
                    tl.length -= qMin(advanceTime, tl.length);
                    break;
                }

            } while(!tl.ops.isEmpty() && advanceTime == 0 && tl.ops.first().length == 0);


            if (tl.ops.isEmpty()) {
                iter = ops.erase(iter);
                v->_t = 0;
            } else {
                if (tl.ops.first().type == Op::Pause && pauseTime != 0) {
                    int opPauseTime = tl.ops.first().length - tl.consumedOpLength;
                    if (pauseTime == -1 || opPauseTime < pauseTime)
                        pauseTime = opPauseTime;
                } else {
                    pauseTime = 0;
                }
                ++iter;
            }
        }

        length -= qMin(length, advanceTime);
        syncPoint -= advanceTime;

        qSort(updates.begin(), updates.end());
        updateQueue = &updates;
        for (int ii = 0; ii < updates.count(); ++ii) {
            const Update &v = updates.at(ii).second;
            if (v.g) {
                v.g->setValue(v.v);
            } else {
                v.e.d0(v.e.d1);
            }
        }
        updateQueue = 0;
    } while(t);

    return pauseTime;
}