void SkPictureRecord::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkXfermode::Mode mode, const SkRect* cull, const SkPaint* paint) { // [op + paint-index + atlas-index + flags + count] + [xform] + [tex] + [*colors + mode] + cull size_t size = 5 * kUInt32Size + count * sizeof(SkRSXform) + count * sizeof(SkRect); uint32_t flags = 0; if (colors) { flags |= DRAW_ATLAS_HAS_COLORS; size += count * sizeof(SkColor); size += sizeof(uint32_t); // xfermode::mode } if (cull) { flags |= DRAW_ATLAS_HAS_CULL; size += sizeof(SkRect); } size_t initialOffset = this->addDraw(DRAW_ATLAS, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_ATLAS, size) == fWriter.bytesWritten()); this->addPaintPtr(paint); this->addImage(atlas); this->addInt(flags); this->addInt(count); fWriter.write(xform, count * sizeof(SkRSXform)); fWriter.write(tex, count * sizeof(SkRect)); // write optional parameters if (colors) { fWriter.write(colors, count * sizeof(SkColor)); this->addInt(mode); } if (cull) { fWriter.write(cull, sizeof(SkRect)); } this->validate(initialOffset, size); }
void SkPictureRecord::onDrawPaint(const SkPaint& paint) { // op + paint index size_t size = 2 * kUInt32Size; size_t initialOffset = this->addDraw(DRAW_PAINT, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_PAINT, size) == fWriter.bytesWritten()); this->addPaint(paint); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawOval(const SkRect& oval, const SkPaint& paint) { // op + paint index + rect size_t size = 2 * kUInt32Size + sizeof(oval); size_t initialOffset = this->addDraw(DRAW_OVAL, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_OVAL, size) == fWriter.bytesWritten()); this->addPaint(paint); this->addRect(oval); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { // op + paint index + rrect size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory; size_t initialOffset = this->addDraw(DRAW_RRECT, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_RRECT, size) == fWriter.bytesWritten()); this->addPaint(paint); this->addRRect(rrect); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawPath(const SkPath& path, const SkPaint& paint) { fContentInfo.onDrawPath(path, paint); // op + paint index + path index size_t size = 3 * kUInt32Size; size_t initialOffset = this->addDraw(DRAW_PATH, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_PATH, size) == fWriter.bytesWritten()); this->addPaint(paint); this->addPath(path); this->validate(initialOffset, size); }
void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint = NULL) { // op + paint index + bitmap index + left + top size_t size = 5 * kUInt32Size; size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_SPRITE, size) == fWriter.bytesWritten()); this->addPaintPtr(paint); this->addBitmap(bitmap); this->addInt(left); this->addInt(top); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) { // op + paint_index + image_index + x + y size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); size_t initialOffset = this->addDraw(DRAW_IMAGE, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE, size) == fWriter.bytesWritten()); this->addPaintPtr(paint); this->addImage(image); this->addScalar(x); this->addScalar(y); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, const SkPaint* paint) { // op + paint index + bitmap id + center + dst rect size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_NINE, size) == fWriter.bytesWritten()); this->addPaintPtr(paint); this->addBitmap(bitmap); this->addIRect(center); this->addRect(dst); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, const SkPaint* paint) { // op + paint index + bitmap index + left + top size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP, size) == fWriter.bytesWritten()); this->addPaintPtr(paint); this->addBitmap(bitmap); this->addScalar(left); this->addScalar(top); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { // op + paint index + length + 'length' worth of data + path index + matrix const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.writeToMemory(nullptr); size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_TEXT_ON_PATH, size) == fWriter.bytesWritten()); this->addPaint(paint); this->addText(text, byteLength); this->addPath(path); this->addMatrix(m); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawImageNine(const SkImage* img, const SkIRect& center, const SkRect& dst, const SkPaint* paint) { // id + paint_index + image_index + center + dst size_t size = 3 * kUInt32Size + sizeof(SkIRect) + sizeof(SkRect); size_t initialOffset = this->addDraw(DRAW_IMAGE_NINE, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE_NINE, size) == fWriter.bytesWritten()); this->addPaintPtr(paint); this->addImage(img); this->addIRect(center); this->addRect(dst); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { // op + paint index + length + 'length' worth of chars + x + y size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar); DrawType op = DRAW_TEXT; size_t initialOffset = this->addDraw(op, &size); SkASSERT(initialOffset+get_paint_offset(op, size) == fWriter.bytesWritten()); this->addPaint(paint); this->addText(text, byteLength); this->addScalar(x); this->addScalar(y); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) { // op + paint index + blob index + x/y size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size); SkASSERT(initialOffset + get_paint_offset(DRAW_TEXT_BLOB, size) == fWriter.bytesWritten()); this->addPaint(paint); this->addTextBlob(blob); this->addScalar(x); this->addScalar(y); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { fContentInfo.onDrawPoints(count, paint); // op + paint index + mode + count + point data size_t size = 4 * kUInt32Size + count * sizeof(SkPoint); size_t initialOffset = this->addDraw(DRAW_POINTS, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_POINTS, size) == fWriter.bytesWritten()); this->addPaint(paint); this->addInt(mode); this->addInt(SkToInt(count)); fWriter.writeMul4(pts, count * sizeof(SkPoint)); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkPaint& paint) { int points = paint.countText(text, byteLength); // op + paint index + length + 'length' worth of data + num points + x&y point data size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + points * sizeof(SkPoint); DrawType op = DRAW_POS_TEXT; size_t initialOffset = this->addDraw(op, &size); SkASSERT(initialOffset+get_paint_offset(op, size) == fWriter.bytesWritten()); this->addPaint(paint); this->addText(text, byteLength); this->addInt(points); fWriter.writeMul4(pos, points * sizeof(SkPoint)); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, const SkPaint* paint, SrcRectConstraint constraint) { // id + paint index + bitmap index + bool for 'src' + flags size_t size = 5 * kUInt32Size; if (src) { size += sizeof(*src); // + rect } size += sizeof(dst); // + rect size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_RECT, size) == fWriter.bytesWritten()); this->addPaintPtr(paint); this->addBitmap(bitmap); this->addRectPtr(src); // may be null this->addRect(dst); this->addInt(constraint); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, const SkPaint* paint, SrcRectConstraint constraint) { // id + paint_index + image_index + bool_for_src + constraint size_t size = 5 * kUInt32Size; if (src) { size += sizeof(*src); // + rect } size += sizeof(dst); // + rect size_t initialOffset = this->addDraw(DRAW_IMAGE_RECT, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE_RECT, size) == fWriter.bytesWritten()); this->addPaintPtr(paint); this->addImage(image); this->addRectPtr(src); // may be null this->addRect(dst); this->addInt(constraint); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint) { // op + paint index + patch 12 control points + flag + patch 4 colors + 4 texture coordinates size_t size = 2 * kUInt32Size + SkPatchUtils::kNumCtrlPts * sizeof(SkPoint) + kUInt32Size; uint32_t flag = 0; if (colors) { flag |= DRAW_VERTICES_HAS_COLORS; size += SkPatchUtils::kNumCorners * sizeof(SkColor); } if (texCoords) { flag |= DRAW_VERTICES_HAS_TEXS; size += SkPatchUtils::kNumCorners * sizeof(SkPoint); } if (xmode) { SkXfermode::Mode mode; if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { flag |= DRAW_VERTICES_HAS_XFER; size += kUInt32Size; } } size_t initialOffset = this->addDraw(DRAW_PATCH, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_PATCH, size) == fWriter.bytesWritten()); this->addPaint(paint); this->addPatch(cubics); this->addInt(flag); // write optional parameters if (colors) { fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); } if (texCoords) { fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)); } if (flag & DRAW_VERTICES_HAS_XFER) { SkXfermode::Mode mode = SkXfermode::kModulate_Mode; xmode->asMode(&mode); this->addInt(mode); } this->validate(initialOffset, size); }
void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) { // op + picture index size_t size = 2 * kUInt32Size; size_t initialOffset; if (nullptr == matrix && nullptr == paint) { initialOffset = this->addDraw(DRAW_PICTURE, &size); this->addPicture(picture); } else { const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); size += m.writeToMemory(nullptr) + kUInt32Size; // matrix + paint initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); SkASSERT(initialOffset + get_paint_offset(DRAW_PICTURE_MATRIX_PAINT, size) == fWriter.bytesWritten()); this->addPaintPtr(paint); this->addMatrix(m); this->addPicture(picture); } this->validate(initialOffset, size); }
void SkPictureRecord::recordSaveLayer(const SaveLayerRec& rec) { fContentInfo.onSaveLayer(); // op + bool for 'bounds' size_t size = 2 * kUInt32Size; if (rec.fBounds) { size += sizeof(*rec.fBounds); // + rect } // + paint index + flags size += 2 * kUInt32Size; SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size); size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERFLAGS, &size); this->addRectPtr(rec.fBounds); SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER_SAVELAYERFLAGS, size) == fWriter.bytesWritten()); this->addPaintPtr(rec.fPaint); this->addInt(rec.fSaveLayerFlags); this->validate(initialOffset, size); }
void SkPictureRecord::onDrawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], SkXfermode* xfer, const uint16_t indices[], int indexCount, const SkPaint& paint) { uint32_t flags = 0; if (texs) { flags |= DRAW_VERTICES_HAS_TEXS; } if (colors) { flags |= DRAW_VERTICES_HAS_COLORS; } if (indexCount > 0) { flags |= DRAW_VERTICES_HAS_INDICES; } if (xfer) { SkXfermode::Mode mode; if (xfer->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { flags |= DRAW_VERTICES_HAS_XFER; } } // op + paint index + flags + vmode + vCount + vertices size_t size = 5 * kUInt32Size + vertexCount * sizeof(SkPoint); if (flags & DRAW_VERTICES_HAS_TEXS) { size += vertexCount * sizeof(SkPoint); // + uvs } if (flags & DRAW_VERTICES_HAS_COLORS) { size += vertexCount * sizeof(SkColor); // + vert colors } if (flags & DRAW_VERTICES_HAS_INDICES) { // + num indices + indices size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t)); } if (flags & DRAW_VERTICES_HAS_XFER) { size += kUInt32Size; // mode enum } size_t initialOffset = this->addDraw(DRAW_VERTICES, &size); SkASSERT(initialOffset+get_paint_offset(DRAW_VERTICES, size) == fWriter.bytesWritten()); this->addPaint(paint); this->addInt(flags); this->addInt(vmode); this->addInt(vertexCount); this->addPoints(vertices, vertexCount); if (flags & DRAW_VERTICES_HAS_TEXS) { this->addPoints(texs, vertexCount); } if (flags & DRAW_VERTICES_HAS_COLORS) { fWriter.writeMul4(colors, vertexCount * sizeof(SkColor)); } if (flags & DRAW_VERTICES_HAS_INDICES) { this->addInt(indexCount); fWriter.writePad(indices, indexCount * sizeof(uint16_t)); } if (flags & DRAW_VERTICES_HAS_XFER) { SkXfermode::Mode mode = SkXfermode::kModulate_Mode; (void)xfer->asMode(&mode); this->addInt(mode); } this->validate(initialOffset, size); }