Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Unified Diff: src/gpu/SkGpuDevice.cpp

Issue 23172013: Third (and hopefully final) change to support bleed flag in Ganesh (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fixed comment Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/bleed.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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' 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,
« no previous file with comments | « gm/bleed.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698