Third (and hopefully final) change to support bleed flag in Ganesh
https://codereview.chromium.org/23172013/
git-svn-id: http://skia.googlecode.com/svn/trunk/src@10826 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/SkGpuDevice.cpp b/gpu/SkGpuDevice.cpp
index b18c782..d96ffb8 100644
--- a/gpu/SkGpuDevice.cpp
+++ b/gpu/SkGpuDevice.cpp
@@ -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' for all 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;
+ }
+}
+
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,