Beispiel #1
0
void GfxImageLoaderEngine::abort(GfxImageLoader *out)
{
    lock.lock();
    ops.remove(out);
    completedops.remove(out);
    lock.unlock();
}
Beispiel #2
0
int
main (int argc, char *argv[])
{
    Ops inst = opsMake();
    int z = inst->add(1, 2);
    printf("%d + %d = %d\n", 1, 2, z);
    return 0;
}
Beispiel #3
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();
}
Beispiel #4
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);
    }
}
Beispiel #5
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;
        }
        */
    }
}
Beispiel #6
0
void GfxImageLoaderEngine::run()
{
    lock.lock();

    while(true) {
        if(ops.isEmpty()) {
            wait.wait(&lock);
        } else {
            Op op = *ops.begin();
            lock.unlock();

            runOp(op);

            lock.lock();
        }
    }
}
Beispiel #7
0
void GfxImageLoaderEngine::load(GfxImageLoader *out, const QString &filename, 
                                const QList<QSize> &sizes)
{
    lock.lock();

    bool wasEmpty = ops.isEmpty();
    Op op;
    op.filename = filename;
    op.sizes = sizes;
    op.id = id++;
    op.out = out;
    ops.insert(out, op);

    if(wasEmpty)
        wait.wakeAll();
    lock.unlock();
}
Beispiel #8
0
 void init() {
   SourceFile * code = new_source_file(SOURCE_PREFIX "ops.in");
   //const char * s = code.begin();
   parse_parse::Res r = parse_parse::parse(SourceStr(code));
   //printf(">.>%.*s<.<\n", r.end-s, s);
   //r.parse->print();
   //printf("\n");
   ops.parse_self(r.parse);
 }
Beispiel #9
0
void GrAuditTrail::addOp(const GrOp* op, GrRenderTargetProxy::UniqueID proxyID) {
    SkASSERT(fEnabled);
    Op* auditOp = new Op;
    fOpPool.emplace_back(auditOp);
    auditOp->fName = op->name();
    auditOp->fBounds = op->bounds();
    auditOp->fClientID = kGrAuditTrailInvalidID;
    auditOp->fOpListID = kGrAuditTrailInvalidID;
    auditOp->fChildID = kGrAuditTrailInvalidID;

    // consume the current stack trace if any
    auditOp->fStackTrace = fCurrentStackTrace;
    fCurrentStackTrace.reset();

    if (fClientID != kGrAuditTrailInvalidID) {
        auditOp->fClientID = fClientID;
        Ops** opsLookup = fClientIDLookup.find(fClientID);
        Ops* ops = nullptr;
        if (!opsLookup) {
            ops = new Ops;
            fClientIDLookup.set(fClientID, ops);
        } else {
            ops = *opsLookup;
        }

        ops->push_back(auditOp);
    }

    // Our algorithm doesn't bother to reorder inside of an OpNode so the ChildID will start at 0
    auditOp->fOpListID = fOpList.count();
    auditOp->fChildID = 0;

    // We use the op pointer as a key to find the OpNode we are 'glomming' ops onto
    fIDLookup.set(op->uniqueID(), auditOp->fOpListID);
    OpNode* opNode = new OpNode(proxyID);
    opNode->fBounds = op->bounds();
    opNode->fChildren.push_back(auditOp);
    fOpList.emplace_back(opNode);
}
Beispiel #10
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;
}
QVector<UInt8ArrayType::Pointer> makePoleFigures(PoleFigureConfiguration_t& config)
{
  Ops ops;
  return ops.generatePoleFigure(config);
}
Beispiel #12
0
 const Syntax * parse(const Syntax * p, const char * l_i) {
   //printf("ParseExpImpl::parse: %s %s\n", ~p->sample_w_loc(), ~p->to_string());
   opr_s.clear();
   val_s.clear();
   list_is = l_i;
   Op::Types prev = 0;
   try {
     for (parts_iterator i = p->args_begin(), e = p->args_end(); i != e; ++i) {
       const Syntax * pop = *i; // parsed op
       Op::Types cur = ops.lookup_types(pop);
       if (cur & Op::Special) {
         const Syntax * res = ops.try_special(pop, i, e);
         if (res) {
           pop = res;
           cur = ops.lookup_types(pop);
         } else {
           cur &= ~Op::Special;
         }
       } 
       assert(!(cur & Op::Special));
       if (prev == 0 || prev & (Op::Prefix | Op::Bin)) {
         cur &= (Op::Prefix | Op::Other);
         if (cur == 0) 
           throw error(pop, "Expected an operand or a prefix operator.");
       } else {
         cur &= (Op::Bin | Op::Postfix);
         if (cur == 0) 
           throw error(pop, "Expected a binary or postfix operator.");
       }
       //if (cur == (Op::Prefix | Op::Other)) {
       //  if (i + 1 == sz || (ops.lookup_types(p->arg(i+1)) & (Op::Postfix | Op::Bin))) {
       //    cur &= (Op::Postfix | Op::Other);
       //    if (cur == 0)
       //      throw error(pop, "Expected an operand or a postfix operator.");
       //  } else {
       //    cur &= (Op::Bin | Op::Prefix);
       //    if (cur == 0)
       //      throw error(pop, "Expected an binary or prefix operator.");
       //  }
       //}
       const Op * op = ops.lookup(pop, cur);
       
       if (op->type == Op::Other) {
         val_s.push_back(pop);
       } else {
         while (!opr_s.empty() && 
                (opr_s.back().op->level < op->level || 
                 (opr_s.back().op->level == op->level && op->assoc == Left)))
           reduce();
         if (!opr_s.empty() && opr_s.back().op->level == op->level && op->assoc == None)
           throw error(pop, "\"%s\" is non-associative.", 
                       op->what.c_str());
         opr_s.push_back(OpInfo(op, pop)); 
       }
       prev = cur;
     }
     while (!opr_s.empty())
       reduce();
     if (val_s.size() == 0)
       throw error(p, "Empty expression.");
     if (val_s.size() > 1)
       throw error(val_s[val_s.size()-2], "Extra operand(s).");
     assert(val_s.size() == 1);
     Syntax * res = val_s.front();
     if (!res->is_a("syntax") && !res->is_a("raw_syntax"))
       res->str_ = p->str();
     return res;
   } catch (Error * err) {
     //printf("?? %s %s\n", ~p->sample_w_loc(), ~p->to_string());
     //abort();
     err->msg.span.source = p->str().source;
     err->add_note(extra_parse_info(p->str(), "<op exp>"));
     throw err;
   }
 }