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

Unified Diff: gm/bleed.cpp

Issue 1228083004: add src-rect-constraint to drawImageRect (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 5 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/bitmaprecttest.cpp ('k') | gm/convexpolyclip.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/bleed.cpp
diff --git a/gm/bleed.cpp b/gm/bleed.cpp
index a96917baa227439e26c18d50b2db13d477037b0f..5bef31dfc1f9c2bdfaeb3209c90b87f82c75bb06 100644
--- a/gm/bleed.cpp
+++ b/gm/bleed.cpp
@@ -9,12 +9,39 @@
#include "SkBlurMask.h"
#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
+#include "SkImage.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrContextOptions.h"
#endif
+static void draw_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkImage*,
+ const SkRect* src, const SkRect& dst,
+ const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) {
+ canvas->drawBitmapRect(bitmap, src, dst, paint, constraint);
+}
+
+static void draw_image_rect(SkCanvas* canvas, const SkBitmap&, const SkImage* image,
+ const SkRect* src, const SkRect& dst,
+ const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) {
+ canvas->drawImageRect(image, src, dst, paint, constraint);
+}
+
+enum BleedTest {
+ kUseBitmap_BleedTest,
+ kUseImage_BleedTest,
+};
+
+const struct {
+ const char* fName;
+ void (*fDraw)(SkCanvas*, const SkBitmap&, const SkImage*, const SkRect*, const SkRect&,
+ const SkPaint*, SkCanvas::SrcRectConstraint);
+} gBleedRec[] = {
+ { "bleed", draw_bitmap_rect },
+ { "bleed_image", draw_image_rect },
+};
+
// Create a black&white checked texture with 2 1-pixel rings
// around the outside edge. The inner ring is red and the outer ring is blue.
static void make_ringed_bitmap(SkBitmap* result, int width, int height) {
@@ -80,15 +107,15 @@ static void make_ringed_bitmap(SkBitmap* result, int width, int height) {
result->setImmutable();
}
-// This GM exercises the drawBitmapRectToRect "bleed" flag
+// This GM exercises the drawBitmapRect constraints
class BleedGM : public skiagm::GM {
public:
- BleedGM() {}
+ BleedGM(BleedTest bt) : fBT(bt) {}
protected:
SkString onShortName() override {
- return SkString("bleed");
+ return SkString(gBleedRec[fBT].fName);
}
SkISize onISize() override {
@@ -97,81 +124,75 @@ protected:
void onOnceBeforeDraw() override {
make_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSize);
+ fImageSmall.reset(SkImage::NewFromBitmap(fBitmapSmall));
// To exercise the GPU's tiling path we need a texture
// too big for the GPU to handle in one go
make_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize);
+ fImageBig.reset(SkImage::NewFromBitmap(fBitmapBig));
}
// Draw only the center of the small bitmap
void drawCase1(SkCanvas* canvas, int transX, int transY,
- SkCanvas::DrawBitmapRectFlags flags, SkFilterQuality filter) {
+ SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
SkIntToScalar(kSmallTextureSize-4),
SkIntToScalar(kSmallTextureSize-4));
- SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
+ SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
+ SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
SkPaint paint;
paint.setFilterQuality(filter);
- canvas->save();
- canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
- canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags);
- canvas->restore();
+ gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, &src, dst, &paint, constraint);
}
// Draw almost all of the large bitmap
void drawCase2(SkCanvas* canvas, int transX, int transY,
- SkCanvas::DrawBitmapRectFlags flags, SkFilterQuality filter) {
+ SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
SkIntToScalar(fBitmapBig.width()-4),
SkIntToScalar(fBitmapBig.height()-4));
- SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
+ SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
+ SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
SkPaint paint;
paint.setFilterQuality(filter);
- canvas->save();
- canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
- canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags);
- canvas->restore();
+ gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, &src, dst, &paint, constraint);
}
// Draw ~1/4 of the large bitmap
void drawCase3(SkCanvas* canvas, int transX, int transY,
- SkCanvas::DrawBitmapRectFlags flags, SkFilterQuality filter) {
+ SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
SkIntToScalar(fBitmapBig.width()/2-2),
SkIntToScalar(fBitmapBig.height()/2-2));
- SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
+ SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
+ SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
SkPaint paint;
paint.setFilterQuality(filter);
- canvas->save();
- canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
- canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags);
- canvas->restore();
+ gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, &src, dst, &paint, constraint);
}
// Draw the center of the small bitmap with a mask filter
void drawCase4(SkCanvas* canvas, int transX, int transY,
- SkCanvas::DrawBitmapRectFlags flags, SkFilterQuality filter) {
+ SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
SkIntToScalar(kSmallTextureSize-4),
SkIntToScalar(kSmallTextureSize-4));
- SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
+ SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
+ SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
SkPaint paint;
paint.setFilterQuality(filter);
SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
- SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3)));
+ SkBlurMask::ConvertRadiusToSigma(3));
paint.setMaskFilter(mf)->unref();
- canvas->save();
- canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
- canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags);
- canvas->restore();
+ gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, &src, dst, &paint, constraint);
}
void onDraw(SkCanvas* canvas) override {
@@ -190,40 +211,40 @@ protected:
}
// First draw a column with no bleeding and no filtering
- this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFlag, kNone_SkFilterQuality);
- this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFlag, kNone_SkFilterQuality);
- this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFlag, kNone_SkFilterQuality);
- this->drawCase4(canvas, kCol0X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, kNone_SkFilterQuality);
+ this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase4(canvas, kCol0X, kRow3Y, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
// Then draw a column with no bleeding and low filtering
- this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFlag, kLow_SkFilterQuality);
- this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFlag, kLow_SkFilterQuality);
- this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFlag, kLow_SkFilterQuality);
- this->drawCase4(canvas, kCol1X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, kLow_SkFilterQuality);
+ this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase4(canvas, kCol1X, kRow3Y, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
// Then draw a column with no bleeding and high filtering
- this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFlag, kHigh_SkFilterQuality);
- this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFlag, kHigh_SkFilterQuality);
- this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFlag, kHigh_SkFilterQuality);
- this->drawCase4(canvas, kCol2X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, kHigh_SkFilterQuality);
+ this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase4(canvas, kCol2X, kRow3Y, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
// Then draw a column with bleeding and no filtering (bleed should have no effect w/out blur)
- this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectFlag, kNone_SkFilterQuality);
- this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectFlag, kNone_SkFilterQuality);
- this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectFlag, kNone_SkFilterQuality);
- this->drawCase4(canvas, kCol3X, kRow3Y, SkCanvas::kBleed_DrawBitmapRectFlag, kNone_SkFilterQuality);
+ this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase4(canvas, kCol3X, kRow3Y, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
// Then draw a column with bleeding and low filtering
- this->drawCase1(canvas, kCol4X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectFlag, kLow_SkFilterQuality);
- this->drawCase2(canvas, kCol4X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectFlag, kLow_SkFilterQuality);
- this->drawCase3(canvas, kCol4X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectFlag, kLow_SkFilterQuality);
- this->drawCase4(canvas, kCol4X, kRow3Y, SkCanvas::kBleed_DrawBitmapRectFlag, kLow_SkFilterQuality);
+ this->drawCase1(canvas, kCol4X, kRow0Y, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase2(canvas, kCol4X, kRow1Y, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase3(canvas, kCol4X, kRow2Y, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase4(canvas, kCol4X, kRow3Y, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
// Finally draw a column with bleeding and high filtering
- this->drawCase1(canvas, kCol5X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectFlag, kHigh_SkFilterQuality);
- this->drawCase2(canvas, kCol5X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectFlag, kHigh_SkFilterQuality);
- this->drawCase3(canvas, kCol5X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectFlag, kHigh_SkFilterQuality);
- this->drawCase4(canvas, kCol5X, kRow3Y, SkCanvas::kBleed_DrawBitmapRectFlag, kHigh_SkFilterQuality);
+ this->drawCase1(canvas, kCol5X, kRow0Y, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase2(canvas, kCol5X, kRow1Y, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase3(canvas, kCol5X, kRow2Y, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase4(canvas, kCol5X, kRow3Y, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
canvas->restore();
}
@@ -257,8 +278,12 @@ private:
SkBitmap fBitmapSmall;
SkBitmap fBitmapBig;
+ SkAutoTUnref<SkImage> fImageSmall;
+ SkAutoTUnref<SkImage> fImageBig;
+ const BleedTest fBT;
typedef GM INHERITED;
};
-DEF_GM( return new BleedGM(); )
+DEF_GM( return new BleedGM(kUseBitmap_BleedTest); )
+DEF_GM( return new BleedGM(kUseImage_BleedTest); )
« no previous file with comments | « gm/bitmaprecttest.cpp ('k') | gm/convexpolyclip.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698