static QByteArray generateTrueTypeCMap(QFontEngine *fe) { QByteArray cmap; const int glyphCount = fe->glyphCount(); if (!glyphCount) return cmap; // cmap header APPEND(quint16, 0); // table version number APPEND(quint16, 1); // number of tables // encoding record APPEND(quint16, 3); // platform-id APPEND(quint16, 10); // encoding-id (ucs-4) const int cmapOffset = cmap.size() + sizeof(quint32); APPEND(quint32, cmapOffset); // offset to sub-table APPEND(quint16, 4); // subtable format const int cmapTableLengthOffset = cmap.size(); APPEND(quint16, 0); // length in bytes, will fill in later APPEND(quint16, 0); // language field QList<CMapSegment> segments; CMapSegment currentSegment; currentSegment.start = 0xffff; currentSegment.end = 0; currentSegment.startGlyphIndex = 0; quint32 previousGlyphIndex = 0xfffffffe; bool inSegment = false; QGlyphLayoutArray<10> layout; for (uint uc = 0; uc < 0x10000; ++uc) { QChar ch(uc); int nglyphs = 10; bool validGlyph = fe->stringToCMap(&ch, 1, &layout, &nglyphs, /*flags*/ 0) && nglyphs == 1 && layout.glyphs[0]; // leaving a segment? if (inSegment && (!validGlyph || layout.glyphs[0] != previousGlyphIndex + 1)) { Q_ASSERT(currentSegment.start != 0xffff); // store the current segment currentSegment.end = uc - 1; segments.append(currentSegment); currentSegment.start = 0xffff; inSegment = false; } // entering a new segment? if (validGlyph && (!inSegment || layout.glyphs[0] != previousGlyphIndex + 1)) { currentSegment.start = uc; currentSegment.startGlyphIndex = layout.glyphs[0]; inSegment = true; } if (validGlyph) previousGlyphIndex = layout.glyphs[0]; else previousGlyphIndex = 0xfffffffe; } currentSegment.start = 0xffff; currentSegment.end = 0xffff; currentSegment.startGlyphIndex = 0; segments.append(currentSegment); if (QPF::debugVerbosity > 3) qDebug() << "segments:" << segments.count(); Q_ASSERT(!inSegment); const quint16 entrySelector = int(log2(segments.count())); const quint16 searchRange = 2 * (1 << entrySelector); const quint16 rangeShift = segments.count() * 2 - searchRange; if (QPF::debugVerbosity > 3) qDebug() << "entrySelector" << entrySelector << "searchRange" << searchRange << "rangeShift" << rangeShift; APPEND(quint16, segments.count() * 2); // segCountX2 APPEND(quint16, searchRange); APPEND(quint16, entrySelector); APPEND(quint16, rangeShift); // end character codes for (int i = 0; i < segments.count(); ++i) APPEND(quint16, segments.at(i).end); APPEND(quint16, 0); // pad // start character codes for (int i = 0; i < segments.count(); ++i) APPEND(quint16, segments.at(i).start); // id deltas for (int i = 0; i < segments.count(); ++i) APPEND(quint16, segments.at(i).startGlyphIndex - segments.at(i).start); // id range offsets for (int i = 0; i < segments.count(); ++i) APPEND(quint16, 0); uchar *lengthPtr = reinterpret_cast<uchar *>(cmap.data()) + cmapTableLengthOffset; qToBigEndian<quint16>(cmap.size() - cmapOffset, lengthPtr); return cmap; }
void SkRecorder::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) { INHERITED(onClipRRect, rrect, op, edgeStyle); SkRecords::ClipOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); APPEND(ClipRRect, this->getDeviceClipBounds(), rrect, opAA); }
void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) { INHERITED(onClipRegion, deviceRgn, op); APPEND(ClipRegion, this->getDeviceClipBounds(), deviceRgn, op); }
void SkRecorder::didRestore() { APPEND(Restore, this->getDeviceClipBounds(), this->getTotalMatrix()); }
void SkRecorder::didSetMatrix(const SkMatrix& matrix) { APPEND(SetMatrix, matrix); }
void SkRecorder::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { APPEND(DrawShadowRec, path, rec); }
void SkRecorder::onFlush() { APPEND(Flush); }
void SkRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) { APPEND(DrawOval, paint, oval); }
void SkRecorder::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint& paint) { APPEND(DrawArc, paint, oval, startAngle, sweepAngle, useCenter); }
void SkRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) { TRY_MINIRECORDER(drawRect, rect, paint); APPEND(DrawRect, paint, rect); }
void SkRecorder::onDrawRegion(const SkRegion& region, const SkPaint& paint) { APPEND(DrawRegion, paint, region); }
void SkRecorder::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { APPEND(DrawPoints, paint, mode, SkToUInt(count), this->copy(pts, count)); }
void SkRecorder::onDrawPaint(const SkPaint& paint) { APPEND(DrawPaint, paint); }
/* * Decode OCTET STRING type. */ asn_dec_rval_t OCTET_STRING_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, void **sptr, const void *buf_ptr, size_t size, int tag_mode) { asn_OCTET_STRING_specifics_t *specs = td->specifics ? (asn_OCTET_STRING_specifics_t *)td->specifics : &asn_DEF_OCTET_STRING_specs; BIT_STRING_t *st = (BIT_STRING_t *)*sptr; asn_dec_rval_t rval; asn_struct_ctx_t *ctx; ssize_t consumed_myself = 0; struct _stack *stck; /* Expectations stack structure */ struct _stack_el *sel = 0; /* Stack element */ int tlv_constr; enum asn_OS_Subvariant type_variant = specs->subvariant; ASN_DEBUG("Decoding %s as %s (frame %ld)", td->name, (type_variant == ASN_OSUBV_STR) ? "OCTET STRING" : "OS-SpecialCase", (long)size); /* * Create the string if does not exist. */ if(st == NULL) { st = (BIT_STRING_t *)(*sptr = CALLOC(1, specs->struct_size)); if(st == NULL) RETURN(RC_FAIL); } /* Restore parsing context */ ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset); switch(ctx->phase) { case 0: /* * Check tags. */ rval = ber_check_tags(opt_codec_ctx, td, ctx, buf_ptr, size, tag_mode, -1, &ctx->left, &tlv_constr); if(rval.code != RC_OK) return rval; if(tlv_constr) { /* * Complex operation, requires stack of expectations. */ ctx->ptr = _new_stack(); if(ctx->ptr) { stck = (struct _stack *)ctx->ptr; } else { RETURN(RC_FAIL); } } else { /* * Jump into stackless primitive decoding. */ _CH_PHASE(ctx, 3); if(type_variant == ASN_OSUBV_ANY && tag_mode != 1) APPEND(buf_ptr, rval.consumed); ADVANCE(rval.consumed); goto phase3; } NEXT_PHASE(ctx); /* Fall through */ case 1: phase1: /* * Fill the stack with expectations. */ stck = (struct _stack *)ctx->ptr; sel = stck->cur_ptr; do { ber_tlv_tag_t tlv_tag; ber_tlv_len_t tlv_len; ber_tlv_tag_t expected_tag; ssize_t tl, ll, tlvl; /* This one works even if (sel->left == -1) */ ssize_t Left = ((!sel||(size_t)sel->left >= size) ?(ssize_t)size:sel->left); ASN_DEBUG("%p, s->l=%ld, s->wn=%ld, s->g=%ld\n", sel, (long)(sel?sel->left:0), (long)(sel?sel->want_nulls:0), (long)(sel?sel->got:0) ); if(sel && sel->left <= 0 && sel->want_nulls == 0) { if(sel->prev) { struct _stack_el *prev = sel->prev; if(prev->left != -1) { if(prev->left < sel->got) RETURN(RC_FAIL); prev->left -= sel->got; } prev->got += sel->got; sel = stck->cur_ptr = prev; if(!sel) break; tlv_constr = 1; continue; } else { sel = stck->cur_ptr = 0; break; /* Nothing to wait */ } } tl = ber_fetch_tag(buf_ptr, Left, &tlv_tag); ASN_DEBUG("fetch tag(size=%ld,L=%ld), %sstack, left=%ld, wn=%ld, tl=%ld", (long)size, (long)Left, sel?"":"!", (long)(sel?sel->left:0), (long)(sel?sel->want_nulls:0), (long)tl); switch(tl) { case -1: RETURN(RC_FAIL); case 0: RETURN(RC_WMORE); } tlv_constr = BER_TLV_CONSTRUCTED(buf_ptr); ll = ber_fetch_length(tlv_constr, (const char *)buf_ptr + tl,Left - tl,&tlv_len); ASN_DEBUG("Got tag=%s, tc=%d, left=%ld, tl=%ld, len=%ld, ll=%ld", ber_tlv_tag_string(tlv_tag), tlv_constr, (long)Left, (long)tl, (long)tlv_len, (long)ll); switch(ll) { case -1: RETURN(RC_FAIL); case 0: RETURN(RC_WMORE); } if(sel && sel->want_nulls && ((const uint8_t *)buf_ptr)[0] == 0 && ((const uint8_t *)buf_ptr)[1] == 0) { ASN_DEBUG("Eat EOC; wn=%d--", sel->want_nulls); if(type_variant == ASN_OSUBV_ANY && (tag_mode != 1 || sel->cont_level)) APPEND("\0\0", 2); ADVANCE(2); sel->got += 2; if(sel->left != -1) { sel->left -= 2; /* assert(sel->left >= 2) */ } sel->want_nulls--; if(sel->want_nulls == 0) { /* Move to the next expectation */ sel->left = 0; tlv_constr = 1; } continue; } /* * Set up expected tags, * depending on ASN.1 type being decoded. */ switch(type_variant) { case ASN_OSUBV_BIT: /* X.690: 8.6.4.1, NOTE 2 */ /* Fall through */ case ASN_OSUBV_STR: default: if(sel) { int level = sel->cont_level; if(level < td->all_tags_count) { expected_tag = td->all_tags[level]; break; } else if(td->all_tags_count) { expected_tag = td->all_tags [td->all_tags_count - 1]; break; } /* else, Fall through */ } /* Fall through */ case ASN_OSUBV_ANY: expected_tag = tlv_tag; break; } if(tlv_tag != expected_tag) { char buf[2][32]; ber_tlv_tag_snprint(tlv_tag, buf[0], sizeof(buf[0])); ber_tlv_tag_snprint(td->tags[td->tags_count-1], buf[1], sizeof(buf[1])); ASN_DEBUG("Tag does not match expectation: %s != %s", buf[0], buf[1]); RETURN(RC_FAIL); } tlvl = tl + ll; /* Combined length of T and L encoding */ if((tlv_len + tlvl) < 0) { /* tlv_len value is too big */ ASN_DEBUG("TLV encoding + length (%ld) is too big", (long)tlv_len); RETURN(RC_FAIL); } /* * Append a new expectation. */ sel = OS__add_stack_el(stck); if(!sel) RETURN(RC_FAIL); sel->tag = tlv_tag; sel->want_nulls = (tlv_len==-1); if(sel->prev && sel->prev->left != -1) { /* Check that the parent frame is big enough */ if(sel->prev->left < tlvl + (tlv_len==-1?0:tlv_len)) RETURN(RC_FAIL); if(tlv_len == -1) sel->left = sel->prev->left - tlvl; else sel->left = tlv_len; } else { sel->left = tlv_len; } if(type_variant == ASN_OSUBV_ANY && (tag_mode != 1 || sel->cont_level)) APPEND(buf_ptr, tlvl); sel->got += tlvl; ADVANCE(tlvl); ASN_DEBUG("+EXPECT2 got=%ld left=%ld, wn=%d, clvl=%d", (long)sel->got, (long)sel->left, sel->want_nulls, sel->cont_level); } while(tlv_constr); if(sel == NULL) { /* Finished operation, "phase out" */ ASN_DEBUG("Phase out"); _CH_PHASE(ctx, +3); break; } NEXT_PHASE(ctx); /* Fall through */ case 2: stck = (struct _stack *)ctx->ptr; sel = stck->cur_ptr; ASN_DEBUG("Phase 2: Need %ld bytes, size=%ld, alrg=%ld, wn=%d", (long)sel->left, (long)size, (long)sel->got, sel->want_nulls); { ber_tlv_len_t len; assert(sel->left >= 0); len = ((ber_tlv_len_t)size < sel->left) ? (ber_tlv_len_t)size : sel->left; if(len > 0) { if(type_variant == ASN_OSUBV_BIT && sel->bits_chopped == 0) { /* Put the unused-bits-octet away */ st->bits_unused = *(const uint8_t *)buf_ptr; APPEND(((const char *)buf_ptr+1), (len - 1)); sel->bits_chopped = 1; } else { APPEND(buf_ptr, len); } ADVANCE(len); sel->left -= len; sel->got += len; } if(sel->left) { ASN_DEBUG("OS left %ld, size = %ld, wn=%d\n", (long)sel->left, (long)size, sel->want_nulls); RETURN(RC_WMORE); } PREV_PHASE(ctx); goto phase1; } break; case 3: phase3: /* * Primitive form, no stack required. */ assert(ctx->left >= 0); if(size < (size_t)ctx->left) { if(!size) RETURN(RC_WMORE); if(type_variant == ASN_OSUBV_BIT && !ctx->context) { st->bits_unused = *(const uint8_t *)buf_ptr; ctx->left--; ADVANCE(1); } APPEND(buf_ptr, size); assert(ctx->context > 0); ctx->left -= size; ADVANCE(size); RETURN(RC_WMORE); } else { if(type_variant == ASN_OSUBV_BIT && !ctx->context && ctx->left) { st->bits_unused = *(const uint8_t *)buf_ptr; ctx->left--; ADVANCE(1); } APPEND(buf_ptr, ctx->left); ADVANCE(ctx->left); ctx->left = 0; NEXT_PHASE(ctx); } break; } if(sel) { ASN_DEBUG("3sel p=%p, wn=%d, l=%ld, g=%ld, size=%ld", sel->prev, sel->want_nulls, (long)sel->left, (long)sel->got, (long)size); if(sel->prev || sel->want_nulls > 1 || sel->left > 0) { RETURN(RC_WMORE); } } /* * BIT STRING-specific processing. */ if(type_variant == ASN_OSUBV_BIT && st->size) { /* Finalize BIT STRING: zero out unused bits. */ st->buf[st->size-1] &= 0xff << st->bits_unused; } ASN_DEBUG("Took %ld bytes to encode %s: [%s]:%ld", (long)consumed_myself, td->name, (type_variant == ASN_OSUBV_STR) ? (char *)st->buf : "<data>", (long)st->size); RETURN(RC_OK); }
void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) { TRY_MINIRECORDER(drawTextBlob, blob, x, y, paint); APPEND(DrawTextBlob, paint, sk_ref_sp(blob), x, y); }
void SkRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { APPEND(DrawRRect, paint, rrect); }
void SkRecorder::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode bmode, const SkPaint& paint) { APPEND(DrawVertices, paint, sk_ref_sp(const_cast<SkVertices*>(vertices)), bmode); }
void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { APPEND(DrawDRRect, paint, outer, inner); }
void SkRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { APPEND(DrawAnnotation, rect, SkString(key), sk_ref_sp(value)); }
void SkRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) { TRY_MINIRECORDER(drawPath, path, paint); APPEND(DrawPath, paint, path); }
void SkRecorder::willSave() { APPEND(Save); }
void SkRecorder::onDrawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint) { APPEND(DrawImage, this->copy(paint), sk_ref_sp(image), left, top); }
void SkRecorder::didConcat(const SkMatrix& matrix) { APPEND(Concat, matrix); }
void SkRecorder::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, const SkPaint* paint, SrcRectConstraint constraint) { APPEND(DrawImageRect, this->copy(paint), sk_ref_sp(image), this->copy(src), dst, constraint); }
void SkRecorder::didTranslate(SkScalar dx, SkScalar dy) { APPEND(Translate, dx, dy); }
void SkRecorder::onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, const SkPaint* paint) { APPEND(DrawImageNine, this->copy(paint), sk_ref_sp(image), center, dst); }
void SkRecorder::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) { INHERITED(onClipPath, path, op, edgeStyle); SkRecords::ClipOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); APPEND(ClipPath, this->getDeviceClipBounds(), path, opAA); }
void SkRecorder::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { APPEND(DrawText, paint, this->copy((const char*)text, byteLength), byteLength, x, y); }
int main(int argc, char *argv[]) { ptl_handle_ni_t ni_logical; ptl_pt_index_t logical_pt_index; ptl_process_t myself; struct timeval start, stop; int potato = 0; ENTRY_T potato_catcher; HANDLE_T potato_catcher_handle; ptl_md_t potato_launcher; ptl_handle_md_t potato_launcher_handle; int num_procs; ptl_handle_eq_t pt_eq_handle; CHECK_RETURNVAL(PtlInit()); CHECK_RETURNVAL(libtest_init()); num_procs = libtest_get_size(); if (NULL != getenv("MAKELEVEL") && num_procs > 2) { return 77; } CHECK_RETURNVAL(PtlNIInit (PTL_IFACE_DEFAULT, NI_TYPE | PTL_NI_LOGICAL, PTL_PID_ANY, NULL, NULL, &ni_logical)); CHECK_RETURNVAL(PtlSetMap(ni_logical, num_procs, libtest_get_mapping(ni_logical))); CHECK_RETURNVAL(PtlGetId(ni_logical, &myself)); CHECK_RETURNVAL(PtlEQAlloc(ni_logical, 100, &pt_eq_handle)); CHECK_RETURNVAL(PtlPTAlloc (ni_logical, 0, pt_eq_handle, PTL_PT_ANY, &logical_pt_index)); assert(logical_pt_index == 0); /* Now do the initial setup on ni_logical */ potato_catcher.start = &potato; potato_catcher.length = sizeof(potato); potato_catcher.uid = PTL_UID_ANY; potato_catcher.options = OPTIONS; #if INTERFACE == 1 potato_catcher.match_id.rank = PTL_RANK_ANY; potato_catcher.match_bits = 1; potato_catcher.ignore_bits = ~potato_catcher.match_bits; #endif potato_catcher.ct_handle = PTL_CT_NONE; CHECK_RETURNVAL(APPEND (ni_logical, logical_pt_index, &potato_catcher, PTL_PRIORITY_LIST, NULL, &potato_catcher_handle)); { ptl_event_t event; CHECK_RETURNVAL(PtlEQWait(pt_eq_handle, &event)); // wait for link event assert(event.type == PTL_EVENT_LINK); } /* Now do a barrier (on ni_physical) to make sure that everyone has their * logical interface set up */ libtest_barrier(); /* now I can communicate between ranks with ni_logical */ /* set up the potato launcher */ potato_launcher.start = &potato; potato_launcher.length = sizeof(potato); potato_launcher.options = PTL_MD_EVENT_CT_ACK | PTL_MD_EVENT_CT_SEND; potato_launcher.eq_handle = PTL_EQ_NONE; // i.e. don't queue send events CHECK_RETURNVAL(PtlCTAlloc(ni_logical, &potato_launcher.ct_handle)); CHECK_RETURNVAL(PtlMDBind (ni_logical, &potato_launcher, &potato_launcher_handle)); /* rank 0 starts the potato going */ if (myself.rank == 0) { ptl_process_t nextrank; nextrank.rank = myself.rank + 1; nextrank.rank *= (nextrank.rank <= num_procs - 1); gettimeofday(&start, NULL); CHECK_RETURNVAL(PtlPut(potato_launcher_handle, 0, potato_launcher.length, (LOOPS == 1) ? PTL_OC_ACK_REQ : PTL_NO_ACK_REQ, nextrank, logical_pt_index, 1, 0, NULL, 1)); } { /* the potato-passing loop */ size_t waitfor; ptl_ct_event_t ctc; ptl_process_t nextrank; nextrank.rank = myself.rank + 1; nextrank.rank *= (nextrank.rank <= num_procs - 1); for (waitfor = 1; waitfor <= LOOPS; ++waitfor) { do { ptl_event_t event; CHECK_RETURNVAL(PtlEQWait(pt_eq_handle, &event)); // wait for potato if (event.type != PTL_EVENT_PUT) { printf("unexpected event: %i\n", (int)event.type); } else { break; } } while (1); /* I have the potato! */ ++potato; if (potato < LOOPS * (num_procs)) { // otherwise, the recipient may have exited /* Bomb's away! */ if (myself.rank == 0) { CHECK_RETURNVAL(PtlPut(potato_launcher_handle, 0, potato_launcher.length, (waitfor == (LOOPS - 1)) ? PTL_OC_ACK_REQ : PTL_NO_ACK_REQ, nextrank, logical_pt_index, 3, 0, NULL, 2)); } else { CHECK_RETURNVAL(PtlPut(potato_launcher_handle, 0, potato_launcher.length, (waitfor == LOOPS) ? PTL_OC_ACK_REQ : PTL_NO_ACK_REQ, nextrank, logical_pt_index, 3, 0, NULL, 2)); } } } // make sure that last send completed before exiting CHECK_RETURNVAL(PtlCTWait(potato_launcher.ct_handle, LOOPS + 1, &ctc)); assert(ctc.failure == 0); if (myself.rank == 0) { printf("Final value of potato = %i\n", potato); } } if (myself.rank == 0) { double accumulate = 0.0; gettimeofday(&stop, NULL); accumulate = (stop.tv_sec + stop.tv_usec * 1e-6) - (start.tv_sec + start.tv_usec * 1e-6); /* calculate the average time waiting */ printf("Total time: %g secs\n", accumulate); accumulate /= LOOPS; printf("Average time around the loop: %g microseconds\n", accumulate * 1e6); accumulate /= num_procs; printf("Average catch-to-toss latency: %g microseconds\n", accumulate * 1e6); } /* cleanup */ CHECK_RETURNVAL(PtlMDRelease(potato_launcher_handle)); CHECK_RETURNVAL(PtlCTFree(potato_launcher.ct_handle)); CHECK_RETURNVAL(UNLINK(potato_catcher_handle)); /* major cleanup */ CHECK_RETURNVAL(PtlPTFree(ni_logical, logical_pt_index)); CHECK_RETURNVAL(PtlEQFree(pt_eq_handle)); CHECK_RETURNVAL(PtlNIFini(ni_logical)); CHECK_RETURNVAL(libtest_fini()); PtlFini(); return 0; }
void IRenderPass::assignDrawBuffer(GLenum buf) { APPEND(_drawBuffers,buf); flags|=RP_SET_DRAW_BUFFERS; }