diff options
-rw-r--r-- | gm/lattice.cpp | 50 | ||||
-rw-r--r-- | include/core/SkCanvas.h | 28 | ||||
-rw-r--r-- | include/private/SkRecords.h | 1 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 24 | ||||
-rw-r--r-- | src/core/SkDevice.cpp | 4 | ||||
-rw-r--r-- | src/core/SkLatticeIter.cpp | 69 | ||||
-rw-r--r-- | src/core/SkLatticeIter.h | 3 | ||||
-rw-r--r-- | src/core/SkLiteDL.cpp | 16 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.cpp | 3 | ||||
-rw-r--r-- | src/core/SkPictureRecord.cpp | 4 | ||||
-rw-r--r-- | src/core/SkRecordDraw.cpp | 1 | ||||
-rw-r--r-- | src/core/SkRecorder.cpp | 3 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 2 | ||||
-rw-r--r-- | src/pdf/SkPDFCanvas.cpp | 4 | ||||
-rw-r--r-- | src/pipe/SkPipeCanvas.cpp | 2 | ||||
-rw-r--r-- | src/pipe/SkPipeReader.cpp | 1 |
16 files changed, 143 insertions, 72 deletions
diff --git a/gm/lattice.cpp b/gm/lattice.cpp index 919fb3588e..46c5a94989 100644 --- a/gm/lattice.cpp +++ b/gm/lattice.cpp @@ -8,31 +8,39 @@ #include "gm.h" #include "SkSurface.h" -static sk_sp<SkSurface> make_surface(SkCanvas* root, int N) { - SkImageInfo info = SkImageInfo::MakeN32Premul(N, N); +static sk_sp<SkSurface> make_surface(SkCanvas* root, int N, int padLeft, int padTop, + int padRight, int padBottom) { + SkImageInfo info = SkImageInfo::MakeN32Premul(N + padLeft + padRight, N + padTop + padBottom); auto surface = root->makeSurface(info); if (!surface) { surface = SkSurface::MakeRaster(info); } + return surface; } -static sk_sp<SkImage> make_image(SkCanvas* root, int* xDivs, int* yDivs) { +static sk_sp<SkImage> make_image(SkCanvas* root, int* xDivs, int* yDivs, int padLeft, int padTop, + int padRight, int padBottom) { const int kCap = 28; const int kMid = 8; const int kSize = 2*kCap + 3*kMid; - auto surface(make_surface(root, kSize)); + auto surface(make_surface(root, kSize, padLeft, padTop, padRight, padBottom)); SkCanvas* canvas = surface->getCanvas(); + canvas->translate((float) padLeft, (float) padTop); SkRect r = SkRect::MakeWH(SkIntToScalar(kSize), SkIntToScalar(kSize)); const SkScalar strokeWidth = SkIntToScalar(6); const SkScalar radius = SkIntToScalar(kCap) - strokeWidth/2; - xDivs[0] = yDivs[0] = kCap; - xDivs[1] = yDivs[1] = kCap + kMid; - xDivs[2] = yDivs[2] = kCap + 2 * kMid; - xDivs[3] = yDivs[3] = kCap + 3 * kMid; + xDivs[0] = kCap + padLeft; + yDivs[0] = kCap + padTop; + xDivs[1] = kCap + kMid + padLeft; + yDivs[1] = kCap + kMid + padTop; + xDivs[2] = kCap + 2 * kMid + padLeft; + yDivs[2] = kCap + 2 * kMid + padTop; + xDivs[3] = kCap + 3 * kMid + padLeft; + yDivs[3] = kCap + 3 * kMid + padTop; SkPaint paint; paint.setAntiAlias(true); @@ -83,17 +91,20 @@ protected: } SkISize onISize() override { - return SkISize::Make(800, 400); + return SkISize::Make(800, 800); } - void onDraw(SkCanvas* canvas) override { + void onDrawHelper(SkCanvas* canvas, int padLeft, int padTop, int padRight, int padBottom) { + canvas->save(); + int xDivs[5]; int yDivs[5]; - xDivs[0] = 0; - yDivs[0] = 0; + xDivs[0] = padLeft; + yDivs[0] = padTop; SkBitmap bitmap; - sk_sp<SkImage> image = make_image(canvas, xDivs + 1, yDivs + 1); + sk_sp<SkImage> image = make_image(canvas, xDivs + 1, yDivs + 1, padLeft, padTop, + padRight, padBottom); image_to_bitmap(image.get(), &bitmap); const SkTSize<SkScalar> size[] = { @@ -115,6 +126,11 @@ protected: lattice.fYDivs = yDivs + 1; lattice.fFlags = nullptr; + SkIRect bounds = SkIRect::MakeLTRB(padLeft, padTop, + image->width() - padRight, image->height() - padBottom); + lattice.fBounds = (bounds == SkIRect::MakeWH(image->width(), image->height())) ? + nullptr : &bounds; + for (int iy = 0; iy < 2; ++iy) { for (int ix = 0; ix < 2; ++ix) { int i = ix * 2 + iy; @@ -149,6 +165,14 @@ protected: canvas->drawImageLattice(image.get(), lattice, r); } } + + canvas->restore(); + } + + void onDraw(SkCanvas* canvas) override { + this->onDrawHelper(canvas, 0, 0, 0, 0); + canvas->translate(0.0f, 400.0f); + this->onDrawHelper(canvas, 3, 7, 4, 11); } private: diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index dc4289d36f..8d98e5024f 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -948,6 +948,9 @@ public: /** * Specifies coordinates to divide a bitmap into (xCount*yCount) rects. + * + * If the lattice divs or bounds are invalid, the entire lattice + * struct will be ignored on the draw call. */ struct Lattice { enum Flags : uint8_t { @@ -956,29 +959,34 @@ public: }; // An array of x-coordinates that divide the bitmap vertically. - // These must be unique, increasing, and in the set [0, width). + // These must be unique, increasing, and in the set [fBounds.fLeft, fBounds.fRight). // Does not have ownership. - const int* fXDivs; + const int* fXDivs; // An array of y-coordinates that divide the bitmap horizontally. - // These must be unique, increasing, and in the set [0, height). + // These must be unique, increasing, and in the set [fBounds.fTop, fBounds.fBottom). // Does not have ownership. - const int* fYDivs; + const int* fYDivs; // If non-null, the length of this array must be equal to // (fXCount + 1) * (fYCount + 1). Note that we allow the first rect - // in each direction to empty (divs[0] = 0). In this case, the - // caller still must specify a flag (as a placeholder) for these - // empty rects. + // in each direction to be empty (ex: fXDivs[0] = fBounds.fLeft). + // In this case, the caller still must specify a flag (as a placeholder) + // for these empty rects. // The flags correspond to the rects in the lattice, first moving // left to right and then top to bottom. - const Flags* fFlags; + const Flags* fFlags; // The number of fXDivs. - int fXCount; + int fXCount; // The number of fYDivs. - int fYCount; + int fYCount; + + // The bound to draw from. Must be contained by the src that is being drawn, + // non-empty, and non-inverted. + // If nullptr, the bounds are the entire src. + const SkIRect* fBounds; }; /** diff --git a/include/private/SkRecords.h b/include/private/SkRecords.h index e08bf772ea..05f935b3ce 100644 --- a/include/private/SkRecords.h +++ b/include/private/SkRecords.h @@ -244,6 +244,7 @@ RECORD(DrawImageLattice, kDraw_Tag|kHasImage_Tag|kHasPaint_Tag, PODArray<int> yDivs; int flagCount; PODArray<SkCanvas::Lattice::Flags> flags; + SkIRect src; SkRect dst); RECORD(DrawImageRect, kDraw_Tag|kHasImage_Tag|kHasPaint_Tag, Optional<SkPaint> paint; diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 6a0d5e6da6..7597c7a07a 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1999,8 +1999,16 @@ void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, co if (dst.isEmpty()) { return; } - if (SkLatticeIter::Valid(image->width(), image->height(), lattice)) { - this->onDrawImageLattice(image, lattice, dst, paint); + + SkIRect bounds; + Lattice latticePlusBounds = lattice; + if (!latticePlusBounds.fBounds) { + bounds = SkIRect::MakeWH(image->width(), image->height()); + latticePlusBounds.fBounds = &bounds; + } + + if (SkLatticeIter::Valid(image->width(), image->height(), latticePlusBounds)) { + this->onDrawImageLattice(image, latticePlusBounds, dst, paint); } else { this->drawImageRect(image, dst, paint); } @@ -2049,8 +2057,16 @@ void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, if (bitmap.drawsNothing() || dst.isEmpty()) { return; } - if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), lattice)) { - this->onDrawBitmapLattice(bitmap, lattice, dst, paint); + + SkIRect bounds; + Lattice latticePlusBounds = lattice; + if (!latticePlusBounds.fBounds) { + bounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); + latticePlusBounds.fBounds = &bounds; + } + + if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), latticePlusBounds)) { + this->onDrawBitmapLattice(bitmap, latticePlusBounds, dst, paint); } else { this->drawBitmapRect(bitmap, dst, paint); } diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 8a9fa96926..70eabab736 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -219,7 +219,7 @@ void SkBaseDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, co void SkBaseDevice::drawImageLattice(const SkDraw& draw, const SkImage* image, const SkCanvas::Lattice& lattice, const SkRect& dst, const SkPaint& paint) { - SkLatticeIter iter(image->width(), image->height(), lattice, dst); + SkLatticeIter iter(lattice, dst); SkRect srcR, dstR; while (iter.next(&srcR, &dstR)) { @@ -230,7 +230,7 @@ void SkBaseDevice::drawImageLattice(const SkDraw& draw, const SkImage* image, void SkBaseDevice::drawBitmapLattice(const SkDraw& draw, const SkBitmap& bitmap, const SkCanvas::Lattice& lattice, const SkRect& dst, const SkPaint& paint) { - SkLatticeIter iter(bitmap.width(), bitmap.height(), lattice, dst); + SkLatticeIter iter(lattice, dst); SkRect srcR, dstR; while (iter.next(&srcR, &dstR)) { diff --git a/src/core/SkLatticeIter.cpp b/src/core/SkLatticeIter.cpp index 38ef2828bd..4fe9352d0a 100644 --- a/src/core/SkLatticeIter.cpp +++ b/src/core/SkLatticeIter.cpp @@ -11,10 +11,10 @@ /** * Divs must be in increasing order with no duplicates. */ -static bool valid_divs(const int* divs, int count, int len) { - int prev = -1; +static bool valid_divs(const int* divs, int count, int start, int end) { + int prev = start - 1; for (int i = 0; i < count; i++) { - if (prev >= divs[i] || divs[i] >= len) { + if (prev >= divs[i] || divs[i] >= end) { return false; } } @@ -23,29 +23,38 @@ static bool valid_divs(const int* divs, int count, int len) { } bool SkLatticeIter::Valid(int width, int height, const SkCanvas::Lattice& lattice) { - bool zeroXDivs = lattice.fXCount <= 0 || (1 == lattice.fXCount && 0 == lattice.fXDivs[0]); - bool zeroYDivs = lattice.fYCount <= 0 || (1 == lattice.fYCount && 0 == lattice.fYDivs[0]); + SkIRect totalBounds = SkIRect::MakeWH(width, height); + SkASSERT(lattice.fBounds); + const SkIRect latticeBounds = *lattice.fBounds; + if (!totalBounds.contains(latticeBounds)) { + return false; + } + + bool zeroXDivs = lattice.fXCount <= 0 || (1 == lattice.fXCount && + latticeBounds.fLeft == lattice.fXDivs[0]); + bool zeroYDivs = lattice.fYCount <= 0 || (1 == lattice.fYCount && + latticeBounds.fTop == lattice.fYDivs[0]); if (zeroXDivs && zeroYDivs) { return false; } - return valid_divs(lattice.fXDivs, lattice.fXCount, width) && - valid_divs(lattice.fYDivs, lattice.fYCount, height); + return valid_divs(lattice.fXDivs, lattice.fXCount, latticeBounds.fLeft, latticeBounds.fRight) + && valid_divs(lattice.fYDivs, lattice.fYCount, latticeBounds.fTop, latticeBounds.fBottom); } /** * Count the number of pixels that are in "scalable" patches. */ static int count_scalable_pixels(const int32_t* divs, int numDivs, bool firstIsScalable, - int length) { + int start, int end) { if (0 == numDivs) { - return firstIsScalable ? length : 0; + return firstIsScalable ? end - start : 0; } int i; int count; if (firstIsScalable) { - count = divs[0]; + count = divs[0] - start; i = 1; } else { count = 0; @@ -56,7 +65,7 @@ static int count_scalable_pixels(const int32_t* divs, int numDivs, bool firstIsS // Alternatively, we could use |top| and |bottom| as variable names, instead of // |left| and |right|. int left = divs[i]; - int right = (i + 1 < numDivs) ? divs[i + 1] : length; + int right = (i + 1 < numDivs) ? divs[i + 1] : end; count += right - left; } @@ -67,10 +76,10 @@ static int count_scalable_pixels(const int32_t* divs, int numDivs, bool firstIsS * Set points for the src and dst rects on subsequent draw calls. */ static void set_points(float* dst, float* src, const int* divs, int divCount, int srcFixed, - int srcScalable, float dstStart, float dstStop, bool isScalable) { + int srcScalable, float srcStart, float srcEnd, float dstStart, float dstEnd, + bool isScalable) { - float dstLen = dstStop - dstStart; - int srcLen = srcFixed + srcScalable; + float dstLen = dstEnd - dstStart; float scale; if (srcFixed <= dstLen) { // This is the "normal" case, where we scale the "scalable" patches and leave @@ -81,7 +90,7 @@ static void set_points(float* dst, float* src, const int* divs, int divCount, in scale = dstLen / ((float) srcFixed); } - src[0] = 0.0f; + src[0] = srcStart; dst[0] = dstStart; for (int i = 0; i < divCount; i++) { src[i + 1] = (float) (divs[i]); @@ -98,17 +107,17 @@ static void set_points(float* dst, float* src, const int* divs, int divCount, in isScalable = !isScalable; } - src[divCount + 1] = (float) srcLen; - dst[divCount + 1] = dstStop; + src[divCount + 1] = srcEnd; + dst[divCount + 1] = dstEnd; } -SkLatticeIter::SkLatticeIter(int srcWidth, int srcHeight, const SkCanvas::Lattice& lattice, - const SkRect& dst) -{ +SkLatticeIter::SkLatticeIter(const SkCanvas::Lattice& lattice, const SkRect& dst) { const int* xDivs = lattice.fXDivs; const int origXCount = lattice.fXCount; const int* yDivs = lattice.fYDivs; const int origYCount = lattice.fYCount; + SkASSERT(lattice.fBounds); + const SkIRect src = *lattice.fBounds; // In the x-dimension, the first rectangle always starts at x = 0 and is "scalable". // If xDiv[0] is 0, it indicates that the first rectangle is degenerate, so the @@ -121,36 +130,36 @@ SkLatticeIter::SkLatticeIter(int srcWidth, int srcHeight, const SkCanvas::Lattic // patches will be "fixed" or "scalable" in the y-direction. int xCount = origXCount; int yCount = origYCount; - bool xIsScalable = (xCount > 0 && 0 == xDivs[0]); + bool xIsScalable = (xCount > 0 && src.fLeft == xDivs[0]); if (xIsScalable) { // Once we've decided that the first patch is "scalable", we don't need the - // xDiv. It is always implied that we start at zero. + // xDiv. It is always implied that we start at the edge of the bounds. xDivs++; xCount--; } - bool yIsScalable = (yCount > 0 && 0 == yDivs[0]); + bool yIsScalable = (yCount > 0 && src.fTop == yDivs[0]); if (yIsScalable) { // Once we've decided that the first patch is "scalable", we don't need the - // yDiv. It is always implied that we start at zero. + // yDiv. It is always implied that we start at the edge of the bounds. yDivs++; yCount--; } // Count "scalable" and "fixed" pixels in each dimension. - int xCountScalable = count_scalable_pixels(xDivs, xCount, xIsScalable, srcWidth); - int xCountFixed = srcWidth - xCountScalable; - int yCountScalable = count_scalable_pixels(yDivs, yCount, yIsScalable, srcHeight); - int yCountFixed = srcHeight - yCountScalable; + int xCountScalable = count_scalable_pixels(xDivs, xCount, xIsScalable, src.fLeft, src.fRight); + int xCountFixed = src.width() - xCountScalable; + int yCountScalable = count_scalable_pixels(yDivs, yCount, yIsScalable, src.fTop, src.fBottom); + int yCountFixed = src.height() - yCountScalable; fSrcX.reset(xCount + 2); fDstX.reset(xCount + 2); set_points(fDstX.begin(), fSrcX.begin(), xDivs, xCount, xCountFixed, xCountScalable, - dst.fLeft, dst.fRight, xIsScalable); + src.fLeft, src.fRight, dst.fLeft, dst.fRight, xIsScalable); fSrcY.reset(yCount + 2); fDstY.reset(yCount + 2); set_points(fDstY.begin(), fSrcY.begin(), yDivs, yCount, yCountFixed, yCountScalable, - dst.fTop, dst.fBottom, yIsScalable); + src.fTop, src.fBottom, dst.fTop, dst.fBottom, yIsScalable); fCurrX = fCurrY = 0; fNumRectsInLattice = (xCount + 1) * (yCount + 1); diff --git a/src/core/SkLatticeIter.h b/src/core/SkLatticeIter.h index deb2fe95eb..f3d37e6688 100644 --- a/src/core/SkLatticeIter.h +++ b/src/core/SkLatticeIter.h @@ -23,8 +23,7 @@ public: static bool Valid(int imageWidth, int imageHeight, const SkCanvas::Lattice& lattice); - SkLatticeIter(int imageWidth, int imageHeight, const SkCanvas::Lattice& lattice, - const SkRect& dst); + SkLatticeIter(const SkCanvas::Lattice& lattice, const SkRect& dst); static bool Valid(int imageWidth, int imageHeight, const SkIRect& center); diff --git a/src/core/SkLiteDL.cpp b/src/core/SkLiteDL.cpp index 8e64ae0a7d..701e9bd38f 100644 --- a/src/core/SkLiteDL.cpp +++ b/src/core/SkLiteDL.cpp @@ -353,12 +353,13 @@ namespace { struct DrawImageLattice final : Op { static const auto kType = Type::DrawImageLattice; DrawImageLattice(sk_sp<const SkImage>&& image, int xs, int ys, int fs, - const SkRect& dst, const SkPaint* paint) - : image(std::move(image)), xs(xs), ys(ys), fs(fs), dst(dst) { + const SkIRect& src, const SkRect& dst, const SkPaint* paint) + : image(std::move(image)), xs(xs), ys(ys), fs(fs), src(src), dst(dst) { if (paint) { this->paint = *paint; } } sk_sp<const SkImage> image; int xs, ys, fs; + SkIRect src; SkRect dst; SkPaint paint; void draw(SkCanvas* c, const SkMatrix&) { @@ -366,7 +367,7 @@ namespace { ydivs = pod<int>(this, xs*sizeof(int)); auto flags = (0 == fs) ? nullptr : pod<SkCanvas::Lattice::Flags>(this, (xs+ys)*sizeof(int)); - c->drawImageLattice(image.get(), {xdivs, ydivs, flags, xs, ys}, dst, &paint); + c->drawImageLattice(image.get(), {xdivs, ydivs, flags, xs, ys, &src}, dst, &paint); } }; @@ -669,8 +670,9 @@ void SkLiteDL::drawBitmapLattice(const SkBitmap& bm, const SkCanvas::Lattice& la int xs = lattice.fXCount, ys = lattice.fYCount; int fs = lattice.fFlags ? (xs + 1) * (ys + 1) : 0; size_t bytes = (xs + ys) * sizeof(int) + fs * sizeof(SkCanvas::Lattice::Flags); - void* pod = this->push<DrawImageLattice>(bytes, SkImage::MakeFromBitmap(bm), xs, ys, fs, dst, - paint); + SkASSERT(lattice.fBounds); + void* pod = this->push<DrawImageLattice>(bytes, SkImage::MakeFromBitmap(bm), xs, ys, fs, + *lattice.fBounds, dst, paint); copy_v(pod, lattice.fXDivs, xs, lattice.fYDivs, ys, lattice.fFlags, fs); @@ -692,7 +694,9 @@ void SkLiteDL::drawImageLattice(const SkImage* image, const SkCanvas::Lattice& l int xs = lattice.fXCount, ys = lattice.fYCount; int fs = lattice.fFlags ? (xs + 1) * (ys + 1) : 0; size_t bytes = (xs + ys) * sizeof(int) + fs * sizeof(SkCanvas::Lattice::Flags); - void* pod = this->push<DrawImageLattice>(bytes, sk_ref_sp(image), xs, ys, fs, dst, paint); + SkASSERT(lattice.fBounds); + void* pod = this->push<DrawImageLattice>(bytes, sk_ref_sp(image), xs, ys, fs, *lattice.fBounds, + dst, paint); copy_v(pod, lattice.fXDivs, xs, lattice.fYDivs, ys, lattice.fFlags, fs); diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 1aa4712d4f..a246a306e6 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -327,6 +327,9 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader, int flagCount = reader->readInt(); lattice.fFlags = (0 == flagCount) ? nullptr : (const SkCanvas::Lattice::Flags*) reader->skip(SkAlign4(flagCount * sizeof(SkCanvas::Lattice::Flags))); + SkIRect src; + reader->readIRect(&src); + lattice.fBounds = &src; SkRect dst; reader->readRect(&dst); canvas->drawImageLattice(image, lattice, dst, paint); diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 4cba3b067f..6325edae00 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -540,7 +540,7 @@ void SkPictureRecord::onDrawImageLattice(const SkImage* image, const Lattice& la // xCount + xDivs + yCount+ yDivs int flagCount = (nullptr == lattice.fFlags) ? 0 : (lattice.fXCount + 1) * (lattice.fYCount + 1); size_t latticeSize = (1 + lattice.fXCount + 1 + lattice.fYCount + 1) * kUInt32Size + - SkAlign4(flagCount * sizeof(SkCanvas::Lattice::Flags)); + SkAlign4(flagCount * sizeof(SkCanvas::Lattice::Flags)) + sizeof(SkIRect); // op + paint index + image index + lattice + dst rect size_t size = 3 * kUInt32Size + latticeSize + sizeof(dst); @@ -553,6 +553,8 @@ void SkPictureRecord::onDrawImageLattice(const SkImage* image, const Lattice& la fWriter.writePad(lattice.fYDivs, lattice.fYCount * kUInt32Size); this->addInt(flagCount); fWriter.writePad(lattice.fFlags, flagCount * sizeof(SkCanvas::Lattice::Flags)); + SkASSERT(lattice.fBounds); + this->addIRect(*lattice.fBounds); this->addRect(dst); this->validate(initialOffset, size); } diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp index 2952591319..ca9c1b6f78 100644 --- a/src/core/SkRecordDraw.cpp +++ b/src/core/SkRecordDraw.cpp @@ -107,6 +107,7 @@ template <> void Draw::draw(const DrawImageLattice& r) { lattice.fYCount = r.yCount; lattice.fYDivs = r.yDivs; lattice.fFlags = (0 == r.flagCount) ? nullptr : r.flags; + lattice.fBounds = &r.src; fCanvas->drawImageLattice(r.image.get(), lattice, r.dst, r.paint); } diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp index 0c236716bc..08c73700d8 100644 --- a/src/core/SkRecorder.cpp +++ b/src/core/SkRecorder.cpp @@ -239,10 +239,11 @@ void SkRecorder::onDrawImageNine(const SkImage* image, const SkIRect& center, void SkRecorder::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, const SkPaint* paint) { int flagCount = lattice.fFlags ? (lattice.fXCount + 1) * (lattice.fYCount + 1) : 0; + SkASSERT(lattice.fBounds); APPEND(DrawImageLattice, this->copy(paint), sk_ref_sp(image), lattice.fXCount, this->copy(lattice.fXDivs, lattice.fXCount), lattice.fYCount, this->copy(lattice.fYDivs, lattice.fYCount), - flagCount, this->copy(lattice.fFlags, flagCount), dst); + flagCount, this->copy(lattice.fFlags, flagCount), *lattice.fBounds, dst); } void SkRecorder::onDrawText(const void* text, size_t byteLength, diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index a50b5c6bd6..d4d361d4fb 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1501,7 +1501,7 @@ void SkGpuDevice::drawProducerLattice(const SkDraw& draw, GrTextureProducer* pro } std::unique_ptr<SkLatticeIter> iter( - new SkLatticeIter(producer->width(), producer->height(), lattice, dst)); + new SkLatticeIter(lattice, dst)); fDrawContext->drawImageLattice(fClip, grPaint, *draw.fMatrix, producer->width(), producer->height(), std::move(iter), dst); } diff --git a/src/pdf/SkPDFCanvas.cpp b/src/pdf/SkPDFCanvas.cpp index 13fcb55dbf..c7e39259ce 100644 --- a/src/pdf/SkPDFCanvas.cpp +++ b/src/pdf/SkPDFCanvas.cpp @@ -77,7 +77,7 @@ void SkPDFCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, const SkPaint* paint) { - SkLatticeIter iter(image->width(), image->height(), lattice, dst); + SkLatticeIter iter(lattice, dst); SkRect srcR, dstR; while (iter.next(&srcR, &dstR)) { this->drawImageRect(image, srcR, dstR, paint); @@ -88,7 +88,7 @@ void SkPDFCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, const SkPaint* paint) { - SkLatticeIter iter(bitmap.width(), bitmap.height(), lattice, dst); + SkLatticeIter iter(lattice, dst); SkRect srcR, dstR; while (iter.next(&srcR, &dstR)) { this->drawBitmapRect(bitmap, srcR, dstR, paint); diff --git a/src/pipe/SkPipeCanvas.cpp b/src/pipe/SkPipeCanvas.cpp index 21b7267d74..a01237fbbb 100644 --- a/src/pipe/SkPipeCanvas.cpp +++ b/src/pipe/SkPipeCanvas.cpp @@ -582,6 +582,8 @@ void SkPipeCanvas::onDrawImageLattice(const SkImage* image, const Lattice& latti SkASSERT(count > 0); write_pad(&writer, lattice.fFlags, count); } + SkASSERT(lattice.fBounds); + writer.write(&lattice.fBounds, sizeof(*lattice.fBounds)); writer.write(&dst, sizeof(dst)); if (paint) { write_paint(writer, *paint, kImage_PaintUsage); diff --git a/src/pipe/SkPipeReader.cpp b/src/pipe/SkPipeReader.cpp index 715781304d..8840da1c83 100644 --- a/src/pipe/SkPipeReader.cpp +++ b/src/pipe/SkPipeReader.cpp @@ -559,6 +559,7 @@ static void drawImageLattice_handler(SkPipeReader& reader, uint32_t packedVerb, } else { lattice.fFlags = nullptr; } + lattice.fBounds = skip<SkIRect>(reader); const SkRect* dst = skip<SkRect>(reader); SkPaint paintStorage, *paint = nullptr; |