Chromium Code Reviews| Index: src/gpu/SkGpuDevice.cpp |
| =================================================================== |
| --- src/gpu/SkGpuDevice.cpp (revision 10818) |
| +++ src/gpu/SkGpuDevice.cpp (working copy) |
| @@ -1086,6 +1086,32 @@ |
| SkCanvas::kNone_DrawBitmapRectFlag); |
| } |
| +// 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. |
|
bsalomon
2013/08/20 16:40:55
despite the -> for all ?
robertphillips
2013/08/20 16:51:39
Done.
|
| +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; |
| + } |
| +} |
| + |
| void SkGpuDevice::drawBitmapCommon(const SkDraw& draw, |
| const SkBitmap& bitmap, |
| const SkRect* srcRectPtr, |
| @@ -1102,8 +1128,6 @@ |
| } |
| if (paint.getMaskFilter()){ |
| - // TODO: this path needs to be updated to respect the bleed flag |
| - |
| // Convert the bitmap to a shader so that the rect can be drawn |
| // through drawRect, which supports mask filters. |
| SkMatrix newM(m); |
| @@ -1112,13 +1136,24 @@ |
| if (NULL != srcRectPtr) { |
| SkIRect iSrc; |
| srcRect.roundOut(&iSrc); |
| + |
| + SkPoint offset = SkPoint::Make(SkIntToScalar(iSrc.fLeft), |
| + SkIntToScalar(iSrc.fTop)); |
| + |
| + if (SkCanvas::kBleed_DrawBitmapRectFlag & flags) { |
| + // In bleed mode we want to expand the src rect on all sides |
| + // but stay within the bitmap bounds |
| + SkIRect iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| + clamped_unit_outset_with_offset(&iSrc, &offset, iClampRect); |
| + } |
| + |
| if (!bitmap.extractSubset(&tmp, iSrc)) { |
| return; // extraction failed |
| } |
| bitmapPtr = &tmp; |
| - srcRect.offset(SkIntToScalar(-iSrc.fLeft), SkIntToScalar(-iSrc.fTop)); |
| + srcRect.offset(-offset.fX, -offset.fY); |
| // The source rect has changed so update the matrix |
| - newM.preTranslate(SkIntToScalar(iSrc.fLeft), SkIntToScalar(iSrc.fTop)); |
| + newM.preTranslate(offset.fX, offset.fY); |
| } |
| SkPaint paintWithTexture(paint); |
| @@ -1178,32 +1213,6 @@ |
| } |
| } |
| -// 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, |