diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkCanvas.h | 45 | ||||
-rw-r--r-- | include/core/SkDevice.h | 4 | ||||
-rw-r--r-- | include/private/SkRecords.h | 9 |
3 files changed, 56 insertions, 2 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 3f9b034946..c3f8599db4 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -938,7 +938,7 @@ public: SrcRectConstraint = kStrict_SrcRectConstraint); /** - * Draw the bitmap stretched differentially to fit into dst. + * Draw the bitmap stretched or shrunk differentially to fit into dst. * center is a rect within the bitmap, and logically divides the bitmap * into 9 sections (3x3). For example, if the middle pixel of a [5x5] * bitmap is the "center", then the center-rect should be [2, 2, 3, 3]. @@ -954,6 +954,47 @@ public: void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, const SkPaint* paint = NULL); + /** + * Specifies coordinates to divide a bitmap into (xCount*yCount) rects. + */ + struct Lattice { + // An array of x-coordinates that divide the bitmap vertically. + // These must be unique, increasing, and in the set [0, width]. + // Does not have ownership. + const int* fXDivs; + + // The number of fXDivs. + int fXCount; + + // An array of y-coordinates that divide the bitmap horizontally. + // These must be unique, increasing, and in the set [0, height]. + // Does not have ownership. + const int* fYDivs; + + // The number of fYDivs. + int fYCount; + }; + + /** + * Draw the bitmap stretched or shrunk differentially to fit into dst. + * + * Moving horizontally across the bitmap, alternating rects will be "scalable" + * (in the x-dimension) to fit into dst or must be left "fixed". The first rect + * is treated as "fixed", but it's possible to specify an empty first rect by + * making lattice.fXDivs[0] = 0. + * + * The scale factor for all "scalable" rects will be the same, and may be greater + * than or less than 1 (meaning we can stretch or shrink). If the number of + * "fixed" pixels is greater than the width of the dst, we will collapse all of + * the "scalable" regions and appropriately downscale the "fixed" regions. + * + * The same interpretation also applies to the y-dimension. + */ + void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, + const SkPaint* paint = nullptr); + void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, + const SkPaint* paint = nullptr); + /** Draw the text, with origin at (x,y), using the specified paint. The origin is interpreted based on the Align setting in the paint. @param text The text to be drawn @@ -1435,6 +1476,8 @@ protected: SrcRectConstraint); virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, const SkPaint*); + virtual void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst, + const SkPaint*); enum ClipEdgeStyle { kHard_ClipEdgeStyle, diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index f3b484e4be..99018df182 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -197,13 +197,15 @@ protected: const SkPaint& paint, SkCanvas::SrcRectConstraint) = 0; virtual void drawBitmapNine(const SkDraw&, const SkBitmap&, const SkIRect& center, - const SkRect& dst, const SkPaint&); + const SkRect& dst, const SkPaint&); virtual void drawImage(const SkDraw&, const SkImage*, SkScalar x, SkScalar y, const SkPaint&); virtual void drawImageRect(const SkDraw&, const SkImage*, const SkRect* src, const SkRect& dst, const SkPaint&, SkCanvas::SrcRectConstraint); virtual void drawImageNine(const SkDraw&, const SkImage*, const SkIRect& center, const SkRect& dst, const SkPaint&); + virtual void drawImageLattice(const SkDraw&, const SkImage*, const SkCanvas::Lattice&, + const SkRect& dst, const SkPaint&); /** * Does not handle text decoration. diff --git a/include/private/SkRecords.h b/include/private/SkRecords.h index 32da3dd377..a095452d1c 100644 --- a/include/private/SkRecords.h +++ b/include/private/SkRecords.h @@ -55,6 +55,7 @@ namespace SkRecords { M(ClipRegion) \ M(DrawDrawable) \ M(DrawImage) \ + M(DrawImageLattice) \ M(DrawImageRect) \ M(DrawImageNine) \ M(DrawDRRect) \ @@ -222,6 +223,14 @@ RECORD(DrawImage, kDraw_Tag|kHasImage_Tag|kHasPaint_Tag, sk_sp<const SkImage> image; SkScalar left; SkScalar top); +RECORD(DrawImageLattice, kDraw_Tag|kHasImage_Tag|kHasPaint_Tag, + Optional<SkPaint> paint; + sk_sp<const SkImage> image; + int xCount; + PODArray<int> xDivs; + int yCount; + PODArray<int> yDivs; + SkRect dst); RECORD(DrawImageRect, kDraw_Tag|kHasImage_Tag|kHasPaint_Tag, Optional<SkPaint> paint; sk_sp<const SkImage> image; |