aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-20 16:51:20 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-20 16:51:20 +0000
commit2cc0b47a9b37e4727f3025ddb080ff98b1dc162c (patch)
treecfe0436f05f27042590a436c5c8be62a945ac84b /src
parent9e3074e968f52eb02fdc329bb9fbe7be5e674268 (diff)
Third (and hopefully final) change to support bleed flag in Ganesh
Diffstat (limited to 'src')
-rw-r--r--src/gpu/SkGpuDevice.cpp69
1 files changed, 39 insertions, 30 deletions
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index b18c78200c..d96ffb84a3 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1086,6 +1086,32 @@ void SkGpuDevice::drawBitmap(const SkDraw& draw,
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 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
}
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 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
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 @@ 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,