aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/bleed.cpp131
-rw-r--r--src/gpu/SkGpuDevice.cpp59
2 files changed, 137 insertions, 53 deletions
diff --git a/gm/bleed.cpp b/gm/bleed.cpp
index 7e90e6d919..1a7e188ec1 100644
--- a/gm/bleed.cpp
+++ b/gm/bleed.cpp
@@ -88,67 +88,91 @@ protected:
make_red_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize);
}
- virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
-#if SK_SUPPORT_GPU
- GrContext* ctx = skiagm::GetGr();
- int oldMaxTextureSize = 0;
- if (NULL != ctx) {
- // shrink the max texture size so all our textures can be reasonably sized
- oldMaxTextureSize = ctx->getMaxTextureSize();
- ctx->setMaxTextureSizeOverride(kMaxTextureSize);
- }
-#endif
+ // Draw only the center of the small bitmap
+ void drawCase1(SkCanvas* canvas, int transX, int transY,
+ SkCanvas::DrawBitmapRectFlags flags, bool filter) {
+ SkRect src = SkRect::MakeXYWH(1, 1,
+ kSmallTextureSize-2,
+ kSmallTextureSize-2);
+ SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
- canvas->clear(SK_ColorGRAY);
+ SkPaint paint;
+ paint.setFilterBitmap(filter);
+
+ canvas->save();
+ canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
+ canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags);
+ canvas->restore();
+ }
+
+ // Draw almost all of the large bitmap
+ void drawCase2(SkCanvas* canvas, int transX, int transY,
+ SkCanvas::DrawBitmapRectFlags flags, bool filter) {
+ SkRect src = SkRect::MakeXYWH(1, 1,
+ SkIntToScalar(fBitmapBig.width()-2),
+ SkIntToScalar(fBitmapBig.height()-2));
+ SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
SkPaint paint;
+ paint.setFilterBitmap(filter);
- // Bleeding only comes into play when filtering
- paint.setFilterBitmap(true);
+ canvas->save();
+ canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
+ canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags);
+ canvas->restore();
+ }
- // carve out the center of the small bitmap
+ // Draw ~1/4 of the large bitmap
+ void drawCase3(SkCanvas* canvas, int transX, int transY,
+ SkCanvas::DrawBitmapRectFlags flags, bool filter) {
SkRect src = SkRect::MakeXYWH(1, 1,
- kSmallTextureSize-2,
- kSmallTextureSize-2);
- SkRect dst = SkRect::MakeXYWH(10, 10, 100, 100);
+ SkIntToScalar(fBitmapBig.width()/2-1),
+ SkIntToScalar(fBitmapBig.height()/2-1));
+ SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
- // first draw without bleeding
- canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint);
+ SkPaint paint;
+ paint.setFilterBitmap(filter);
- // then draw with bleeding
- dst = SkRect::MakeXYWH(120, 10, 100, 100);
- canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint,
- SkCanvas::kBleed_DrawBitmapRectFlag);
+ canvas->save();
+ canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
+ canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags);
+ canvas->restore();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
- // Next test out the GPU's tiling of large textures
+ canvas->clear(SK_ColorGRAY);
- // first draw almost the whole thing
- src = SkRect::MakeXYWH(1, 1,
- SkIntToScalar(fBitmapBig.width()-2),
- SkIntToScalar(fBitmapBig.height()-2));
- dst = SkRect::MakeXYWH(10, 120, 100, 100);
+ // First draw a column with no bleeding, tiling, or filtering
+ this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kNone_DrawBitmapRectflag, false);
+ this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kNone_DrawBitmapRectflag, false);
+ this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kNone_DrawBitmapRectflag, false);
- // first without bleeding
- canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint);
+ // Then draw a column with no bleeding or tiling but with filtering
+ this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kNone_DrawBitmapRectflag, true);
+ this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kNone_DrawBitmapRectflag, true);
+ this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kNone_DrawBitmapRectflag, true);
- // then with bleeding
- dst = SkRect::MakeXYWH(120, 120, 100, 100);
- canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint,
- SkCanvas::kBleed_DrawBitmapRectFlag);
- // next draw ~1/4 of the bitmap
- src = SkRect::MakeXYWH(1, 1,
- SkIntToScalar(fBitmapBig.width()/2-1),
- SkIntToScalar(fBitmapBig.height()/2-1));
- dst = SkRect::MakeXYWH(10, 230, 100, 100);
+#if SK_SUPPORT_GPU
+ GrContext* ctx = skiagm::GetGr();
+ int oldMaxTextureSize = 0;
+ if (NULL != ctx) {
+ // shrink the max texture size so all our textures can be reasonably sized
+ oldMaxTextureSize = ctx->getMaxTextureSize();
+ ctx->setMaxTextureSizeOverride(kMaxTextureSize);
+ }
+#endif
- // first without bleeding
- canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint);
+ // Then draw a column with no bleeding but with tiling and filtering
+ this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kNone_DrawBitmapRectflag, true);
+ this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kNone_DrawBitmapRectflag, true);
+ this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kNone_DrawBitmapRectflag, true);
- // then with bleeding
- dst = SkRect::MakeXYWH(120, 230, 100, 100);
- canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint,
- SkCanvas::kBleed_DrawBitmapRectFlag);
+ // Finally draw a column with all three (bleeding, tiling, and filtering)
+ this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectFlag, true);
+ this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectFlag, true);
+ this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectFlag, true);
#if SK_SUPPORT_GPU
if (NULL != ctx) {
@@ -158,8 +182,19 @@ protected:
}
private:
- static const int kWidth = 230;
- static const int kHeight = 340;
+ static const int kBlockSize = 90;
+ static const int kBlockSpacing = 10;
+
+ static const int kCol0X = kBlockSpacing;
+ static const int kCol1X = 2*kBlockSpacing + kBlockSize;
+ static const int kCol2X = 3*kBlockSpacing + 2*kBlockSize;
+ static const int kCol3X = 4*kBlockSpacing + 3*kBlockSize;
+ static const int kWidth = 5*kBlockSpacing + 4*kBlockSize;
+
+ static const int kRow0Y = kBlockSpacing;
+ static const int kRow1Y = 2*kBlockSpacing + kBlockSize;
+ static const int kRow2Y = 3*kBlockSpacing + 2*kBlockSize;
+ static const int kHeight = 4*kBlockSpacing + 3*kBlockSize;
static const int kSmallTextureSize = 4;
static const int kMaxTextureSize = 32;
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);
}