Update bleed GM to use HQ filtering.

R=robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/61133002

git-svn-id: http://skia.googlecode.com/svn/trunk@12188 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2013-11-08 15:09:22 +00:00
parent 1b20a10f02
commit ec39b50f04
2 changed files with 117 additions and 69 deletions

View File

@ -62,3 +62,6 @@ strokes_round
# Added by sugoi in https://codereview.chromium.org/59173005
perlinnoise
# Added by bsalomon in support of adding HQ filter to GPU device drawBitmap
bleed

View File

@ -14,10 +14,15 @@
#include "GrContext.h"
#endif
// Create a black&white checked texture with a 1-pixel red ring
// around the outside edge
static void make_red_ringed_bitmap(SkBitmap* result, int width, int height) {
SkASSERT(0 == width % 2 && 0 == width % 2);
// 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) {
SkASSERT(0 == width % 2 && 0 == height % 2);
static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED);
static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE);
static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK);
static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE);
result->setConfig(SkBitmap::kARGB_8888_Config, width, height, 0,
kOpaque_SkAlphaType);
@ -26,36 +31,53 @@ static void make_red_ringed_bitmap(SkBitmap* result, int width, int height) {
SkPMColor* scanline = result->getAddr32(0, 0);
for (int x = 0; x < width; ++x) {
scanline[x] = SK_ColorRED;
scanline[x] = kBlue;
}
scanline = result->getAddr32(0, 1);
scanline[0] = kBlue;
for (int x = 1; x < width - 1; ++x) {
scanline[x] = kRed;
}
scanline[width-1] = kBlue;
for (int y = 2; y < height/2; ++y) {
scanline = result->getAddr32(0, y);
scanline[0] = kBlue;
scanline[1] = kRed;
for (int x = 2; x < width/2; ++x) {
scanline[x] = kBlack;
}
for (int x = width/2; x < width-2; ++x) {
scanline[x] = kWhite;
}
scanline[width-2] = kRed;
scanline[width-1] = kBlue;
}
for (int y = 1; y < height/2; ++y) {
for (int y = height/2; y < height-2; ++y) {
scanline = result->getAddr32(0, y);
scanline[0] = SK_ColorRED;
for (int x = 1; x < width/2; ++x) {
scanline[x] = SK_ColorBLACK;
scanline[0] = kBlue;
scanline[1] = kRed;
for (int x = 2; x < width/2; ++x) {
scanline[x] = kWhite;
}
for (int x = width/2; x < width-1; ++x) {
scanline[x] = SK_ColorWHITE;
for (int x = width/2; x < width-2; ++x) {
scanline[x] = kBlack;
}
scanline[width-1] = SK_ColorRED;
scanline[width-2] = kRed;
scanline[width-1] = kBlue;
}
for (int y = height/2; y < height-1; ++y) {
scanline = result->getAddr32(0, y);
scanline[0] = SK_ColorRED;
for (int x = 1; x < width/2; ++x) {
scanline[x] = SK_ColorWHITE;
}
for (int x = width/2; x < width-1; ++x) {
scanline[x] = SK_ColorBLACK;
}
scanline[width-1] = SK_ColorRED;
scanline = result->getAddr32(0, height-2);
scanline[0] = kBlue;
for (int x = 1; x < width - 1; ++x) {
scanline[x] = kRed;
}
scanline[width-1] = kBlue;
scanline = result->getAddr32(0, height-1);
for (int x = 0; x < width; ++x) {
scanline[x] = SK_ColorRED;
scanline[x] = kBlue;
}
result->setImmutable();
}
@ -75,23 +97,23 @@ protected:
}
virtual void onOnceBeforeDraw() SK_OVERRIDE {
make_red_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSize);
make_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSize);
// To exercise the GPU's tiling path we need a texture
// too big for the GPU to handle in one go
make_red_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize);
make_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize);
}
// 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);
SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
kSmallTextureSize-4,
kSmallTextureSize-4);
SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
SkPaint paint;
paint.setFilterLevel(filter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
paint.setFilterLevel(filter);
canvas->save();
canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
@ -101,14 +123,14 @@ protected:
// 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));
SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel 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));
SkPaint paint;
paint.setFilterLevel(filter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
paint.setFilterLevel(filter);
canvas->save();
canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
@ -118,14 +140,14 @@ protected:
// 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,
SkIntToScalar(fBitmapBig.width()/2-1),
SkIntToScalar(fBitmapBig.height()/2-1));
SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel 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));
SkPaint paint;
paint.setFilterLevel(filter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
paint.setFilterLevel(filter);
canvas->save();
canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
@ -135,14 +157,14 @@ protected:
// Draw the center of the small bitmap with a mask filter
void drawCase4(SkCanvas* canvas, int transX, int transY,
SkCanvas::DrawBitmapRectFlags flags, bool filter) {
SkRect src = SkRect::MakeXYWH(1, 1,
kSmallTextureSize-2,
kSmallTextureSize-2);
SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
kSmallTextureSize-4,
kSmallTextureSize-4);
SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
SkPaint paint;
paint.setFilterLevel(filter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
paint.setFilterLevel(filter);
SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_BlurStyle,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3)));
paint.setMaskFilter(mf)->unref();
@ -157,19 +179,27 @@ protected:
canvas->clear(SK_ColorGRAY);
// Currently there are no test cases with medium filtering since medium uses mip-mapping and
// these draws are always upscaling.
// 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);
this->drawCase4(canvas, kCol0X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, false);
// 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);
this->drawCase4(canvas, kCol1X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, true);
this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kNone_FilterLevel);
this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kNone_FilterLevel);
this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kNone_FilterLevel);
this->drawCase4(canvas, kCol0X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kNone_FilterLevel);
// Then draw a column with no bleeding or tiling but with low filtering
this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
this->drawCase4(canvas, kCol1X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
// Then draw a column with no bleeding or tiling but with high filtering
this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
this->drawCase4(canvas, kCol2X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
#if SK_SUPPORT_GPU
GrContext* ctx = GM::GetGr(canvas);
int oldMaxTextureSize = 0;
@ -180,17 +210,29 @@ protected:
}
#endif
// 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);
this->drawCase4(canvas, kCol2X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, true);
// Then draw a column with no bleeding but with tiling and low filtering
this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
this->drawCase4(canvas, kCol3X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
// 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);
this->drawCase4(canvas, kCol3X, kRow3Y, SkCanvas::kBleed_DrawBitmapRectFlag, true);
// Then draw a column with no bleeding but with tiling and high filtering
this->drawCase1(canvas, kCol4X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
this->drawCase2(canvas, kCol4X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
this->drawCase3(canvas, kCol4X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
this->drawCase4(canvas, kCol4X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
// Then draw a column with bleeding, tiling, and low filtering
this->drawCase1(canvas, kCol5X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
this->drawCase2(canvas, kCol5X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
this->drawCase3(canvas, kCol5X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
this->drawCase4(canvas, kCol5X, kRow3Y, SkCanvas::kBleed_DrawBitmapRectFlag, SkPaint::kLow_FilterLevel);
// Finally draw a column with bleeding, tiling, and high filtering
this->drawCase1(canvas, kCol6X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
this->drawCase2(canvas, kCol6X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
this->drawCase3(canvas, kCol6X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
this->drawCase4(canvas, kCol6X, kRow3Y, SkCanvas::kBleed_DrawBitmapRectFlag, SkPaint::kHigh_FilterLevel);
#if SK_SUPPORT_GPU
if (NULL != ctx) {
@ -200,14 +242,17 @@ protected:
}
private:
static const int kBlockSize = 90;
static const int kBlockSpacing = 10;
static const int kBlockSize = 70;
static const int kBlockSpacing = 5;
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 kCol4X = 5*kBlockSpacing + 4*kBlockSize;
static const int kCol5X = 6*kBlockSpacing + 5*kBlockSize;
static const int kCol6X = 7*kBlockSpacing + 6*kBlockSize;
static const int kWidth = 8*kBlockSpacing + 7*kBlockSize;
static const int kRow0Y = kBlockSpacing;
static const int kRow1Y = 2*kBlockSpacing + kBlockSize;
@ -215,7 +260,7 @@ private:
static const int kRow3Y = 4*kBlockSpacing + 3*kBlockSize;
static const int kHeight = 5*kBlockSpacing + 4*kBlockSize;
static const int kSmallTextureSize = 4;
static const int kSmallTextureSize = 6;
static const int kMaxTextureSize = 32;
SkBitmap fBitmapSmall;