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

Unified Diff: gm/bleed.cpp

Issue 1423793002: Add more cases to bleed GM and more variants (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comment Created 5 years, 2 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 | « no previous file | no next file » | 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 12682c1023dd2b0413c511cd0a271316856736a1..5daa54e9ff92a062cda8c2e01b60a1e94208582c 100644
--- a/gm/bleed.cpp
+++ b/gm/bleed.cpp
@@ -9,6 +9,7 @@
#include "SkBlurMask.h"
#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
+#include "SkGradientShader.h"
#include "SkImage.h"
#if SK_SUPPORT_GPU
@@ -28,23 +29,9 @@ static void draw_image_rect(SkCanvas* canvas, const SkBitmap&, const SkImage* im
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) {
+static void make_ringed_color_bitmap(SkBitmap* result, int width, int height) {
SkASSERT(0 == width % 2 && 0 == height % 2);
static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED);
@@ -107,6 +94,106 @@ static void make_ringed_bitmap(SkBitmap* result, int width, int height) {
result->setImmutable();
}
+/** Makes a alpha bitmap with 1 wide rect/ring of 1s, an inset of 0s, and the interior is a 2x2
+ checker board of 3/4 and 1/2. The inner checkers are large enough to fill the interior with
+ the 2x2 checker grid. */
+static void make_ringed_alpha_bitmap(SkBitmap* result, int width, int height) {
+ SkASSERT(0 == width % 2 && 0 == height % 2);
+
+ static const SkPMColor kZero = 0x00;
+ static const SkPMColor kHalf = 0x80;
+ static const SkPMColor k3Q = 0xC0;
+ static const SkPMColor kOne = 0xFF;
+ SkImageInfo info = SkImageInfo::MakeA8(width, height);
+ // The 4 byte alignment seems to be necessary to allow this bmp to be converted
+ // to an image.
+ result->allocPixels(info, SkAlign4(width));
+
+ uint8_t* scanline = result->getAddr8(0, 0);
+ for (int x = 0; x < width; ++x) {
+ scanline[x] = kOne;
+ }
+ scanline = result->getAddr8(0, 1);
+ scanline[0] = kOne;
+ for (int x = 1; x < width - 1; ++x) {
+ scanline[x] = kZero;
+ }
+ scanline[width - 1] = kOne;
+
+ for (int y = 2; y < height / 2; ++y) {
+ scanline = result->getAddr8(0, y);
+ scanline[0] = kOne;
+ scanline[1] = kZero;
+ for (int x = 2; x < width / 2; ++x) {
+ scanline[x] = k3Q;
+ }
+ for (int x = width / 2; x < width - 2; ++x) {
+ scanline[x] = kHalf;
+ }
+ scanline[width - 2] = kZero;
+ scanline[width - 1] = kOne;
+ }
+
+ for (int y = height / 2; y < height - 2; ++y) {
+ scanline = result->getAddr8(0, y);
+ scanline[0] = kOne;
+ scanline[1] = kZero;
+ for (int x = 2; x < width / 2; ++x) {
+ scanline[x] = kHalf;
+ }
+ for (int x = width / 2; x < width - 2; ++x) {
+ scanline[x] = k3Q;
+ }
+ scanline[width - 2] = kZero;
+ scanline[width - 1] = kOne;
+ }
+
+ scanline = result->getAddr8(0, height - 2);
+ scanline[0] = kOne;
+ for (int x = 1; x < width - 1; ++x) {
+ scanline[x] = kZero;
+ }
+ scanline[width - 1] = kOne;
+
+ scanline = result->getAddr8(0, height - 1);
+ for (int x = 0; x < width; ++x) {
+ scanline[x] = kOne;
+ }
+ result->setImmutable();
+}
+
+static SkShader* make_shader() {
+ static const SkPoint pts[] = { {0, 0}, {20, 20} };
+ static const SkColor colors[] = { SK_ColorGREEN, SK_ColorYELLOW };
+ return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kMirror_TileMode);
+}
+
+static SkShader* make_null_shader() { return nullptr; }
+
+enum BleedTest {
+ kUseBitmap_BleedTest,
+ kUseImage_BleedTest,
+ kUseAlphaBitmap_BleedTest,
+ kUseAlphaImage_BleedTest,
+ kUseAlphaBitmapShader_BleedTest,
+ kUseAlphaImageShader_BleedTest,
+};
+
+const struct {
+ const char* fName;
+ void(*fBmpMaker)(SkBitmap* result, int width, int height);
+ SkShader*(*fShaderMaker)();
+ void(*fDraw)(SkCanvas*, const SkBitmap&, const SkImage*, const SkRect&, const SkRect&,
+ const SkPaint*, SkCanvas::SrcRectConstraint);
+} gBleedRec[] = {
+ { "bleed", make_ringed_color_bitmap, make_null_shader, draw_bitmap_rect },
+ { "bleed_image", make_ringed_color_bitmap, make_null_shader, draw_image_rect },
+ { "bleed_alpha_bmp", make_ringed_alpha_bitmap, make_null_shader, draw_bitmap_rect },
+ { "bleed_alpha_image", make_ringed_alpha_bitmap, make_null_shader, draw_image_rect },
+ { "bleed_alpha_bmp_shader", make_ringed_alpha_bitmap, make_shader, draw_bitmap_rect },
+ { "bleed_alpha_image_shader", make_ringed_alpha_bitmap, make_shader, draw_image_rect },
+};
+
// This GM exercises the drawBitmapRect constraints
class BleedGM : public skiagm::GM {
public:
@@ -119,21 +206,23 @@ protected:
}
SkISize onISize() override {
- return SkISize::Make(kWidth, 780);
+ return SkISize::Make(1050, 780);
}
void onOnceBeforeDraw() override {
- make_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSize);
+ gBleedRec[fBT].fBmpMaker(&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);
+ gBleedRec[fBT].fBmpMaker(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize);
fImageBig.reset(SkImage::NewFromBitmap(fBitmapBig));
+
+ fShader.reset(gBleedRec[fBT].fShaderMaker());
}
// Draw only the center of the small bitmap
- void drawCase1(SkCanvas* canvas, int transX, int transY,
+ void drawCase1(SkCanvas* canvas, int transX, int transY, bool aa,
SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
SkIntToScalar(kSmallTextureSize-4),
@@ -143,12 +232,15 @@ protected:
SkPaint paint;
paint.setFilterQuality(filter);
+ paint.setShader(fShader);
+ paint.setColor(SK_ColorBLUE);
+ paint.setAntiAlias(aa);
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,
+ void drawCase2(SkCanvas* canvas, int transX, int transY, bool aa,
SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
SkIntToScalar(fBitmapBig.width()-4),
@@ -158,12 +250,15 @@ protected:
SkPaint paint;
paint.setFilterQuality(filter);
+ paint.setShader(fShader);
+ paint.setColor(SK_ColorBLUE);
+ paint.setAntiAlias(aa);
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,
+ void drawCase3(SkCanvas* canvas, int transX, int transY, bool aa,
SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
SkIntToScalar(fBitmapBig.width()/2-2),
@@ -173,12 +268,15 @@ protected:
SkPaint paint;
paint.setFilterQuality(filter);
+ paint.setShader(fShader);
+ paint.setColor(SK_ColorBLUE);
+ paint.setAntiAlias(aa);
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,
+ void drawCase4(SkCanvas* canvas, int transX, int transY, bool aa,
SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
SkIntToScalar(kSmallTextureSize-4),
@@ -191,61 +289,89 @@ protected:
SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(3));
paint.setMaskFilter(mf)->unref();
+ paint.setShader(fShader);
+ paint.setColor(SK_ColorBLUE);
+ paint.setAntiAlias(aa);
gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, src, dst, &paint, constraint);
}
void onDraw(SkCanvas* canvas) override {
-
canvas->clear(SK_ColorGRAY);
-
- for (int m = 0; m < 2; ++m) {
+ SkTDArray<SkMatrix> matrices;
+ // Draw with identity
+ *matrices.append() = SkMatrix::I();
+
+ // Draw with rotation and scale down in x, up in y.
+ SkMatrix m;
+ static const SkScalar kBottom = SkIntToScalar(kRow3Y + kBlockSize + kBlockSpacing);
+ m.setTranslate(0, kBottom);
+ m.preRotate(15.f, 0, kBottom + kBlockSpacing);
+ m.preScale(0.71f, 1.22f);
+ *matrices.append() = m;
+
+ // Align the next set with the middle of the previous in y, translated to the right in x.
+ SkPoint corners[] = {{0, 0}, { 0, kBottom }, { kWidth, kBottom }, {kWidth, 0} };
+ matrices[matrices.count()-1].mapPoints(corners, 4);
+ SkScalar y = (corners[0].fY + corners[1].fY + corners[2].fY + corners[3].fY) / 4;
+ SkScalar x = SkTMax(SkTMax(corners[0].fX, corners[1].fX),
+ SkTMax(corners[2].fX, corners[3].fX));
+ m.setTranslate(x, y);
+ m.preScale(0.2f, 0.2f);
+ *matrices.append() = m;
+
+ SkScalar maxX = 0;
+ for (int antiAlias = 0; antiAlias < 2; ++antiAlias) {
canvas->save();
- if (m) {
- static const SkScalar kBottom = SkIntToScalar(kRow3Y + kBlockSize + kBlockSpacing);
- canvas->translate(0, kBottom);
- SkMatrix rotate;
- rotate.setRotate(15.f, 0, kBottom + kBlockSpacing);
- canvas->concat(rotate);
- canvas->scale(0.71f, 1.22f);
+ canvas->translate(maxX, 0);
+ for (int m = 0; m < matrices.count(); ++m) {
+ canvas->save();
+ canvas->concat(matrices[m]);
+ bool aa = SkToBool(antiAlias);
+
+ // First draw a column with no bleeding and no filtering
+ this->drawCase1(canvas, kCol0X, kRow0Y, aa, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase2(canvas, kCol0X, kRow1Y, aa, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase3(canvas, kCol0X, kRow2Y, aa, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase4(canvas, kCol0X, kRow3Y, aa, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
+
+ // Then draw a column with no bleeding and low filtering
+ this->drawCase1(canvas, kCol1X, kRow0Y, aa, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase2(canvas, kCol1X, kRow1Y, aa, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase3(canvas, kCol1X, kRow2Y, aa, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase4(canvas, kCol1X, kRow3Y, aa, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
+
+ // Then draw a column with no bleeding and high filtering
+ this->drawCase1(canvas, kCol2X, kRow0Y, aa, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase2(canvas, kCol2X, kRow1Y, aa, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase3(canvas, kCol2X, kRow2Y, aa, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase4(canvas, kCol2X, kRow3Y, aa, 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, aa, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase2(canvas, kCol3X, kRow1Y, aa, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase3(canvas, kCol3X, kRow2Y, aa, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
+ this->drawCase4(canvas, kCol3X, kRow3Y, aa, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
+
+ // Then draw a column with bleeding and low filtering
+ this->drawCase1(canvas, kCol4X, kRow0Y, aa, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase2(canvas, kCol4X, kRow1Y, aa, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase3(canvas, kCol4X, kRow2Y, aa, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
+ this->drawCase4(canvas, kCol4X, kRow3Y, aa, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
+
+ // Finally draw a column with bleeding and high filtering
+ this->drawCase1(canvas, kCol5X, kRow0Y, aa, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase2(canvas, kCol5X, kRow1Y, aa, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase3(canvas, kCol5X, kRow2Y, aa, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
+ this->drawCase4(canvas, kCol5X, kRow3Y, aa, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
+
+ SkPoint corners[] = { { 0, 0 },{ 0, kBottom },{ kWidth, kBottom },{ kWidth, 0 } };
+ matrices[m].mapPoints(corners, 4);
+ SkScalar x = kBlockSize + SkTMax(SkTMax(corners[0].fX, corners[1].fX),
+ SkTMax(corners[2].fX, corners[3].fX));
+ maxX = SkTMax(maxX, x);
+ canvas->restore();
}
-
- // First draw a column with no bleeding and no filtering
- 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::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::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::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::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::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();
}
}
@@ -280,6 +406,9 @@ private:
SkBitmap fBitmapBig;
SkAutoTUnref<SkImage> fImageSmall;
SkAutoTUnref<SkImage> fImageBig;
+
+ SkAutoTUnref<SkShader> fShader;
+
const BleedTest fBT;
typedef GM INHERITED;
@@ -287,3 +416,9 @@ private:
DEF_GM( return new BleedGM(kUseBitmap_BleedTest); )
DEF_GM( return new BleedGM(kUseImage_BleedTest); )
+DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); )
+DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); )
+#if 0 // Currently crashes GPU backend
+DEF_GM(return new BleedGM(kUseAlphaBitmapShader_BleedTest); )
+DEF_GM(return new BleedGM(kUseAlphaImageShader_BleedTest); )
+#endif
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698