diff options
author | 2013-08-20 12:09:32 +0000 | |
---|---|---|
committer | 2013-08-20 12:09:32 +0000 | |
commit | d7ca66176fb2397b1120e945e38f8ac0fb2d0508 (patch) | |
tree | 456e2ef91bfc6f97cffd156abf5f860e5f5e3475 /src | |
parent | 93a7145a2a7c1f9cc46831e9e77c37800ac79355 (diff) |
Update tiled bitmap path to respect bleed flag
https://codereview.chromium.org/23261003/
git-svn-id: http://skia.googlecode.com/svn/trunk@10803 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index ce461c6245..7a1aea2f6d 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1178,6 +1178,32 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw, } } +// This method outsets 'iRect' by 1 all around and then clamps its extents to +// 'clamp'. 'offset' is adjusted to remain positioned over the top-left corner +// of 'iRect' despite the possible outsets/clamps. +static inline void clamped_unit_outset_with_offset(SkIRect* iRect, SkPoint* offset, + const SkIRect& clamp) { + iRect->outset(1, 1); + + if (iRect->fLeft < clamp.fLeft) { + iRect->fLeft = clamp.fLeft; + } else { + offset->fX -= SK_Scalar1; + } + if (iRect->fTop < clamp.fTop) { + iRect->fTop = clamp.fTop; + } else { + offset->fY -= SK_Scalar1; + } + + if (iRect->fRight > clamp.fRight) { + iRect->fRight = clamp.fRight; + } + if (iRect->fBottom > clamp.fBottom) { + iRect->fBottom = clamp.fBottom; + } +} + // Break 'bitmap' into several tiles to draw it since it has already // been determined to be too large to fit in VRAM void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, @@ -1186,8 +1212,12 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, const GrTextureParams& params, const SkPaint& paint, SkCanvas::DrawBitmapRectFlags flags) { - // TODO: this method needs to be updated to respect the bleed flag - const int maxTextureSize = fContext->getMaxTextureSize(); + int maxTextureSize = fContext->getMaxTextureSize(); + if (SkPaint::kNone_FilterLevel != paint.getFilterLevel()) { + // We may need a skosh more room if we have to bump out the tile + // by 1 pixel all around + maxTextureSize -= 2; + } int tileSize = determine_tile_size(bitmap, srcRect, maxTextureSize); @@ -1228,12 +1258,31 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, SkBitmap tmpB; SkIRect iTileR; tileR.roundOut(&iTileR); + SkPoint offset = SkPoint::Make(SkIntToScalar(iTileR.fLeft), + SkIntToScalar(iTileR.fTop)); + + if (SkPaint::kNone_FilterLevel != paint.getFilterLevel()) { + SkIRect iClampRect; + + if (SkCanvas::kBleed_DrawBitmapRectFlag & flags) { + // In bleed mode we want to always expand the tile on all edges + // but stay within the bitmap bounds + iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height()); + } else { + // In texture-domain/clamp mode we only want to expand the + // tile on edges interior to "srcRect" (i.e., we want to + // not bleed across the original clamped edges) + srcRect.roundOut(&iClampRect); + } + + clamped_unit_outset_with_offset(&iTileR, &offset, iClampRect); + } + if (bitmap.extractSubset(&tmpB, iTileR)) { // now offset it to make it "local" to our tmp bitmap - tileR.offset(SkIntToScalar(-iTileR.fLeft), SkIntToScalar(-iTileR.fTop)); + tileR.offset(-offset.fX, -offset.fY); SkMatrix tmpM(m); - tmpM.preTranslate(SkIntToScalar(iTileR.fLeft), - SkIntToScalar(iTileR.fTop)); + tmpM.preTranslate(offset.fX, offset.fY); this->internalDrawBitmap(tmpB, tileR, tmpM, params, paint, flags); } |