int SkPipeDeduper::findOrDefineTypeface(SkTypeface* typeface) { if (!typeface) { return 0; // default } int index = fTypefaces.find(typeface->uniqueID()); SkASSERT(index >= 0); if (index) { if (show_deduper_traffic) { SkDebugf(" reuseTypeface(%d)\n", index - 1); } return index; } sk_sp<SkData> data = fTFSerializer ? fTFSerializer->serialize(typeface) : encode(typeface); if (data) { index = fTypefaces.add(typeface->uniqueID()); SkASSERT(index > 0); SkASSERT(fits_in(index, 24)); fStream->write32(pack_verb(SkPipeVerb::kDefineTypeface, index)); uint32_t len = SkToU32(data->size()); fStream->write32(SkAlign4(len)); write_pad(fStream, data->data(), len); if (show_deduper_traffic) { SkDebugf(" defineTypeface(%d) %d\n", index - 1, len); } return index; } SkDebugf("+++ failed to encode typeface %d\n", typeface->uniqueID()); return 0; // failed to encode }
void SkPipeCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], const SkRect* cull, const SkPaint& paint) { SkASSERT(byteLength); bool compact = fits_in(byteLength, 23); unsigned extra = compact ? (byteLength << 1) : 0; if (cull) { extra |= 1; } SkPipeWriter writer(this); writer.write32(pack_verb(SkPipeVerb::kDrawTextRSXform, extra)); if (!compact) { writer.write32(SkToU32(byteLength)); } write_pad(&writer, text, byteLength); int count = paint.countText(text, byteLength); writer.write32(count); // maybe we can/should store this in extra as well? writer.write(xform, count * sizeof(SkRSXform)); if (cull) { writer.writeRect(*cull); } write_paint(writer, paint, kText_PaintUsage); }
int SkPipeDeduper::findOrDefineImage(SkImage* image) { int index = fImages.find(image->uniqueID()); SkASSERT(index >= 0); if (index) { if (show_deduper_traffic) { SkDebugf(" reuseImage(%d)\n", index - 1); } return index; } sk_sp<SkData> data = fIMSerializer ? fIMSerializer->serialize(image) : default_image_serializer(image); if (data) { index = fImages.add(image->uniqueID()); SkASSERT(index > 0); SkASSERT(fits_in(index, 24)); fStream->write32(pack_verb(SkPipeVerb::kDefineImage, index)); uint32_t len = SkToU32(data->size()); fStream->write32(SkAlign4(len)); write_pad(fStream, data->data(), len); if (show_deduper_traffic) { int size = image->width() * image->height() << 2; SkDebugf(" defineImage(%d) %d -> %d\n", index - 1, size, len); } return index; } SkDebugf("+++ failed to encode image [%d %d]\n", image->width(), image->height()); return 0; // failed to encode }
void SkPipeCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkPaint& paint) { SkASSERT(byteLength); bool compact = fits_in(byteLength, 24); SkPipeWriter writer(this); writer.write32(pack_verb(SkPipeVerb::kDrawPosText, compact ? (unsigned)byteLength : 0)); if (!compact) { writer.write32(SkToU32(byteLength)); } write_pad(&writer, text, byteLength); writer.writePointArray(pos, paint.countText(text, byteLength)); write_paint(writer, paint, kText_PaintUsage); }
void SkPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { SkASSERT(byteLength); bool compact = fits_in(byteLength, 24); SkPipeWriter writer(this); writer.write32(pack_verb(SkPipeVerb::kDrawText, compact ? (unsigned)byteLength : 0)); if (!compact) { writer.write32(SkToU32(byteLength)); } write_pad(&writer, text, byteLength); writer.writeScalar(x); writer.writeScalar(y); write_paint(writer, paint, kText_PaintUsage); }
/*! @brief Update game state forward a frame. */ void game_frame(int c) { int j; int *backup; if (c == 0) { if (fits_in (shape, pos + B_COLS)) { pos += B_COLS; } else { place(shape, pos, get_col(shape)); ++points; for (j = 0; j < 252; j = B_COLS * (j / B_COLS + 1)) { for (; board[++j];) { if (j % B_COLS == 10) { linesCleared++; for (; j % B_COLS; board[j--] = 0); update(); for (; --j; board[j + B_COLS] = board[j]); update(); } } } shape = next_shape(); if (!fits_in (shape, pos = 17)) c = keys[KEY_QUIT]; } } if (c == keys[KEY_LEFT]) { if (!fits_in (shape, --pos)) ++pos; } if (c == keys[KEY_ROTATE]) { backup = shape; shape = &shapes[4 * *shape]; /* Rotate */ /* Check if it fits, if not restore shape from backup. */ if (!fits_in (shape, pos)) shape = backup; } if (c == keys[KEY_RIGHT]) { if (!fits_in (shape, ++pos)) --pos; } if (c == keys[KEY_DROP]) { for (; fits_in (shape, pos + B_COLS); ++points) pos += B_COLS; } if (c == keys[KEY_PAUSE] || c == keys[KEY_QUIT]) { exitGame = 1; return; } place(shape, pos, get_col(shape)); update(); place(shape, pos, RESETATTR); }
void SkPipeCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) { size_t size = region.writeToMemory(nullptr); unsigned extra = 0; if (fits_in(size, 24)) { extra = SkToUInt(size); } SkPipeWriter writer(this); writer.write32(pack_verb(SkPipeVerb::kDrawRegion, extra)); if (0 == extra) { writer.write32(size); } SkAutoSMalloc<2048> storage(size); region.writeToMemory(storage.get()); write_pad(&writer, storage.get(), size); write_paint(writer, paint, kGeometry_PaintUsage); }
void SkPipeCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* data) { const size_t len = strlen(key) + 1; // must write the trailing 0 bool compact = fits_in(len, 23); uint32_t extra = compact ? (unsigned)len : 0; extra <<= 1; // make room for has_data_sentinel if (data) { extra |= 1; } fStream->write32(pack_verb(SkPipeVerb::kDrawAnnotation, extra)); fStream->write(&rect, sizeof(SkRect)); if (!compact) { fStream->write32(SkToU32(len)); } write_pad(fStream, key, len); if (data) { fStream->write32(SkToU32(data->size())); write_pad(fStream, data->data(), data->size()); } }