SkCanvas::SaveLayerStrategy SkGPipeCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags saveFlags) { NOTIFY_SETUP(this); size_t size = 0; unsigned opFlags = 0; if (bounds) { opFlags |= kSaveLayer_HasBounds_DrawOpFlag; size += sizeof(SkRect); } if (paint) { opFlags |= kSaveLayer_HasPaint_DrawOpFlag; this->writePaint(*paint); } if (this->needOpBytes(size)) { this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags); if (bounds) { fWriter.writeRect(*bounds); } } this->INHERITED::willSaveLayer(bounds, paint, saveFlags); // we don't create a layer return kNoLayer_SaveLayerStrategy; }
void SkGPipeCanvas::onDrawPaint(const SkPaint& paint) { NOTIFY_SETUP(this); this->writePaint(paint); if (this->needOpBytes()) { this->writeOp(kDrawPaint_DrawOp); } }
void SkGPipeCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) { NOTIFY_SETUP(this); this->writePaint(paint); // FIXME: this is inefficient but avoids duplicating the blob serialization logic. SkRefCntSet typefaceSet; SkWriteBuffer blobBuffer; blobBuffer.setTypefaceRecorder(&typefaceSet); blob->flatten(blobBuffer); // Unlike most draw ops (which only use one paint/typeface), text blobs may reference // an arbitrary number of typefaces. Since the one-paint-per-op model is not applicable, // we need to serialize these explicitly. TypefaceBuffer typefaceBuffer; size_t typefaceSize = is_cross_process(fFlags) ? this->getCrossProcessTypefaces(typefaceSet, &typefaceBuffer) : this->getInProcessTypefaces(typefaceSet, &typefaceBuffer); // blob byte count + typeface count + x + y + blob data + an index (cross-process) // or pointer (in-process) for each typeface size_t size = 2 * sizeof(uint32_t) + 2 * sizeof(SkScalar) + blobBuffer.bytesWritten() + typefaceSize; if (this->needOpBytes(size)) { this->writeOp(kDrawTextBlob_DrawOp); SkDEBUGCODE(size_t initialOffset = fWriter.bytesWritten();)
void SkGPipeCanvas::onDrawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRect& dst, const SkPaint* paint, SK_VIRTUAL_CONSTRAINT_TYPE legacyConstraint) { SrcRectConstraint constraint = (SrcRectConstraint)legacyConstraint; NOTIFY_SETUP(this); size_t opBytesNeeded = sizeof(SkRect); bool hasSrc = src != NULL; unsigned flags; if (hasSrc) { flags = kDrawBitmap_HasSrcRect_DrawOpFlag; opBytesNeeded += sizeof(int32_t) * 4; } else { flags = 0; } if (kFast_SrcRectConstraint == constraint) { flags |= kDrawBitmap_Bleed_DrawOpFlag; } if (this->commonDrawBitmap(bm, kDrawBitmapRect_DrawOp, flags, opBytesNeeded, paint)) { if (hasSrc) { fWriter.writeRect(*src); } fWriter.writeRect(dst); } }
void SkGPipeCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { NOTIFY_SETUP(this); this->writePaint(paint); if (this->needOpBytes(sizeof(SkRect))) { this->writeOp(kDrawOval_DrawOp); fWriter.writeRect(rect); } }
void SkGPipeCanvas::onClipRegion(const SkRegion& region, SkRegion::Op rgnOp) { NOTIFY_SETUP(this); if (this->needOpBytes(region.writeToMemory(nullptr))) { this->writeOp(kClipRegion_DrawOp, 0, rgnOp); fWriter.writeRegion(region); } this->INHERITED::onClipRegion(region, rgnOp); }
void SkGPipeCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { NOTIFY_SETUP(this); this->writePaint(paint); if (this->needOpBytes(path.writeToMemory(nullptr))) { this->writeOp(kDrawPath_DrawOp); fWriter.writePath(path); } }
void SkGPipeCanvas::didSetMatrix(const SkMatrix& matrix) { NOTIFY_SETUP(this); if (this->needOpBytes(matrix.writeToMemory(nullptr))) { this->writeOp(kSetMatrix_DrawOp); fWriter.writeMatrix(matrix); } this->INHERITED::didSetMatrix(matrix); }
void SkGPipeCanvas::willRestore() { NOTIFY_SETUP(this); if (this->needOpBytes()) { this->writeOp(kRestore_DrawOp); } this->INHERITED::willRestore(); }
void SkGPipeCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) { NOTIFY_SETUP(this); if (this->commonDrawImage(image, kDrawImage_DrawOp, 0, sizeof(SkScalar) * 2, paint)) { fWriter.writeScalar(x); fWriter.writeScalar(y); } }
void SkGPipeCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { NOTIFY_SETUP(this); this->writePaint(paint); if (this->needOpBytes(kSizeOfFlatRRect)) { this->writeOp(kDrawRRect_DrawOp); fWriter.writeRRect(rrect); } }
void SkGPipeCanvas::onDrawSprite(const SkBitmap& bm, int left, int top, const SkPaint* paint) { NOTIFY_SETUP(this); size_t opBytesNeeded = sizeof(int32_t) * 2; if (this->commonDrawBitmap(bm, kDrawSprite_DrawOp, 0, opBytesNeeded, paint)) { fWriter.write32(left); fWriter.write32(top); } }
void SkGPipeCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, const SkPaint* paint) { NOTIFY_SETUP(this); size_t opBytesNeeded = sizeof(SkIRect) + sizeof(SkRect); // center + dst if (this->commonDrawImage(image, kDrawImageNine_DrawOp, 0, opBytesNeeded, paint)) { fWriter.writeIRect(center); fWriter.writeRect(dst); } }
void SkGPipeCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { NOTIFY_SETUP(this); this->writePaint(paint); if (this->needOpBytes(kSizeOfFlatRRect * 2)) { this->writeOp(kDrawDRRect_DrawOp); fWriter.writeRRect(outer); fWriter.writeRRect(inner); } }
void SkGPipeCanvas::onDrawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, const SkPaint* paint) { NOTIFY_SETUP(this); size_t opBytesNeeded = sizeof(SkScalar) * 2; if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint)) { fWriter.writeScalar(left); fWriter.writeScalar(top); } }
void SkGPipeCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { if (count) { NOTIFY_SETUP(this); this->writePaint(paint); if (this->needOpBytes(4 + count * sizeof(SkPoint))) { this->writeOp(kDrawPoints_DrawOp, mode, 0); fWriter.write32(SkToU32(count)); fWriter.write(pts, count * sizeof(SkPoint)); } } }
void SkGPipeCanvas::onDrawBitmapNine(const SkBitmap& bm, const SkIRect& center, const SkRect& dst, const SkPaint* paint) { NOTIFY_SETUP(this); size_t opBytesNeeded = sizeof(int32_t) * 4 + sizeof(SkRect); if (this->commonDrawBitmap(bm, kDrawBitmapNine_DrawOp, 0, opBytesNeeded, paint)) { fWriter.write32(center.fLeft); fWriter.write32(center.fTop); fWriter.write32(center.fRight); fWriter.write32(center.fBottom); fWriter.writeRect(dst); } }
void SkGPipeCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op rgnOp, ClipEdgeStyle edgeStyle) { NOTIFY_SETUP(this); if (this->needOpBytes(kSizeOfFlatRRect)) { unsigned flags = 0; if (kSoft_ClipEdgeStyle == edgeStyle) { flags = kClip_HasAntiAlias_DrawOpFlag; } this->writeOp(kClipRRect_DrawOp, flags, rgnOp); fWriter.writeRRect(rrect); } this->INHERITED::onClipRRect(rrect, rgnOp, edgeStyle); }
void SkGPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { if (byteLength) { NOTIFY_SETUP(this); this->writePaint(paint); if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar))) { this->writeOp(kDrawText_DrawOp); fWriter.write32(SkToU32(byteLength)); fWriter.writePad(text, byteLength); fWriter.writeScalar(x); fWriter.writeScalar(y); } } }
void SkGPipeCanvas::onClipPath(const SkPath& path, SkRegion::Op rgnOp, ClipEdgeStyle edgeStyle) { NOTIFY_SETUP(this); if (this->needOpBytes(path.writeToMemory(nullptr))) { unsigned flags = 0; if (kSoft_ClipEdgeStyle == edgeStyle) { flags = kClip_HasAntiAlias_DrawOpFlag; } this->writeOp(kClipPath_DrawOp, flags, rgnOp); fWriter.writePath(path); } // we just pass on the bounds of the path this->INHERITED::onClipRect(path.getBounds(), rgnOp, edgeStyle); }
void SkGPipeCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkPaint& paint) { if (byteLength) { NOTIFY_SETUP(this); this->writePaint(paint); int count = paint.textToGlyphs(text, byteLength, nullptr); if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkPoint))) { this->writeOp(kDrawPosText_DrawOp); fWriter.write32(SkToU32(byteLength)); fWriter.writePad(text, byteLength); fWriter.write32(count); fWriter.write(pos, count * sizeof(SkPoint)); } } }
void SkGPipeCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, const SkPaint* paint) { NOTIFY_SETUP(this); unsigned flags = 0; size_t opBytesNeeded = sizeof(SkRect); // dst if (src) { flags |= kDrawBitmap_HasSrcRect_DrawOpFlag; opBytesNeeded += sizeof(SkRect); // src } if (this->commonDrawImage(image, kDrawImageRect_DrawOp, flags, opBytesNeeded, paint)) { if (src) { fWriter.writeRect(*src); } fWriter.writeRect(dst); } }
void SkGPipeCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkPaint& paint) { if (byteLength) { NOTIFY_SETUP(this); this->writePaint(paint); int count = paint.textToGlyphs(text, byteLength, NULL); if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkScalar) + 4)) { this->writeOp(kDrawPosTextH_DrawOp); fWriter.write32(SkToU32(byteLength)); fWriter.writePad(text, byteLength); fWriter.write32(count); fWriter.write(xpos, count * sizeof(SkScalar)); fWriter.writeScalar(constY); } } }
void SkGPipeCanvas::didConcat(const SkMatrix& matrix) { if (!matrix.isIdentity()) { NOTIFY_SETUP(this); switch (matrix.getType()) { case SkMatrix::kTranslate_Mask: this->recordTranslate(matrix); break; case SkMatrix::kScale_Mask: this->recordScale(matrix); break; default: this->recordConcat(matrix); break; } } this->INHERITED::didConcat(matrix); }
void SkGPipeCanvas::onDrawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRect& dst, const SkPaint* paint, DrawBitmapRectFlags dbmrFlags) { NOTIFY_SETUP(this); size_t opBytesNeeded = sizeof(SkRect); bool hasSrc = src != NULL; unsigned flags; if (hasSrc) { flags = kDrawBitmap_HasSrcRect_DrawOpFlag; opBytesNeeded += sizeof(int32_t) * 4; } else { flags = 0; } if (dbmrFlags & kBleed_DrawBitmapRectFlag) { flags |= kDrawBitmap_Bleed_DrawOpFlag; } if (this->commonDrawBitmap(bm, kDrawBitmapRectToRect_DrawOp, flags, opBytesNeeded, paint)) { if (hasSrc) { fWriter.writeRect(*src); } fWriter.writeRect(dst); } }
void SkGPipeCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { if (byteLength) { NOTIFY_SETUP(this); unsigned flags = 0; size_t size = 4 + SkAlign4(byteLength) + path.writeToMemory(nullptr); if (matrix) { flags |= kDrawTextOnPath_HasMatrix_DrawOpFlag; size += matrix->writeToMemory(nullptr); } this->writePaint(paint); if (this->needOpBytes(size)) { this->writeOp(kDrawTextOnPath_DrawOp, flags, 0); fWriter.write32(SkToU32(byteLength)); fWriter.writePad(text, byteLength); fWriter.writePath(path); if (matrix) { fWriter.writeMatrix(*matrix); } } } }