Changing imageFilter GM tests to use drawBitmap instead of drawSprite

The motivation is be able to test the filters with scaled SkPicture playback in isolation from the issues that surround usage of drawSprite
Review URL: https://codereview.appspot.com/7060071

git-svn-id: http://skia.googlecode.com/svn/trunk@7152 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
junov@chromium.org 2013-01-14 16:27:50 +00:00
parent 47ebbcc7ab
commit ff06af20fd
6 changed files with 48 additions and 17 deletions

View File

@ -63,6 +63,14 @@ protected:
return make_isize(500, 100);
}
void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x) {
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), 0,
SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
canvas->drawBitmap(fBitmap, SkIntToScalar(x), 0, &paint);
canvas->restore();
}
virtual void onDraw(SkCanvas* canvas) {
if (!fInitialized) {
make_bitmap();
@ -73,15 +81,15 @@ protected:
SkPaint paint;
SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard)));
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kNormal_Mode, background)))->unref();
canvas->drawSprite(fBitmap, 0, 0, &paint);
drawClippedBitmap(canvas, paint, 0);
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kMultiply_Mode, background)))->unref();
canvas->drawSprite(fBitmap, 100, 0, &paint);
drawClippedBitmap(canvas, paint, 100);
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kScreen_Mode, background)))->unref();
canvas->drawSprite(fBitmap, 200, 0, &paint);
drawClippedBitmap(canvas, paint, 200);
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kDarken_Mode, background)))->unref();
canvas->drawSprite(fBitmap, 300, 0, &paint);
drawClippedBitmap(canvas, paint, 300);
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kLighten_Mode, background)))->unref();
canvas->drawSprite(fBitmap, 400, 0, &paint);
drawClippedBitmap(canvas, paint, 400);
}
private:

11
gm/gm.h
View File

@ -34,11 +34,12 @@ namespace skiagm {
virtual ~GM();
enum Flags {
kSkipPDF_Flag = 1 << 0,
kSkipPicture_Flag = 1 << 1,
kSkipPipe_Flag = 1 << 2,
kSkipTiled_Flag = 1 << 3,
kSkip565_Flag = 1 << 4,
kSkipPDF_Flag = 1 << 0,
kSkipPicture_Flag = 1 << 1,
kSkipPipe_Flag = 1 << 2,
kSkipTiled_Flag = 1 << 3,
kSkip565_Flag = 1 << 4,
kSkipScaledReplay_Flag = 1 << 5,
};
void draw(SkCanvas*);

View File

@ -1402,6 +1402,8 @@ int tool_main(int argc, char** argv) {
if (!(gmFlags & GM::kSkipPicture_Flag) && doTileGrid) {
for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) {
SkScalar replayScale = tileGridReplayScales[scaleIndex];
if ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1)
continue;
// We record with the reciprocal scale to obtain a replay
// result that can be validated against comparisonBitmap.
SkScalar recordScale = SkScalarInvert(replayScale);

View File

@ -165,6 +165,14 @@ protected:
canvas->drawRect(r, paint);
}
virtual uint32_t onGetFlags() const {
// Because of the use of drawSprite, this test is excluded
// from scaled replay tests because drawSprite ignores the
// reciprocal scale that is applied at record time, which is
// the intended behavior of drawSprite.
return kSkipScaledReplay_Flag;
}
virtual void onDraw(SkCanvas* canvas) {
void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
draw_paint,

View File

@ -42,6 +42,14 @@ protected:
return make_isize(WIDTH, HEIGHT);
}
void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y) {
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint);
canvas->restore();
}
virtual void onDraw(SkCanvas* canvas) {
if (!fInitialized) {
make_bitmap();
@ -76,17 +84,17 @@ protected:
SkColor white(0xFFFFFFFF);
SkPaint paint;
paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd))->unref();
canvas->drawSprite(fBitmap, 0, 0, &paint);
drawClippedBitmap(canvas, paint, 0, 0);
paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(distantDirection, white, surfaceScale, kd))->unref();
canvas->drawSprite(fBitmap, 110, 0, &paint);
drawClippedBitmap(canvas, paint, 110, 0);
paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd))->unref();
canvas->drawSprite(fBitmap, 220, 0, &paint);
drawClippedBitmap(canvas, paint, 220, 0);
paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(pointLocation, white, surfaceScale, ks, shininess))->unref();
canvas->drawSprite(fBitmap, 0, 110, &paint);
drawClippedBitmap(canvas, paint, 0, 110);
paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular(distantDirection, white, surfaceScale, ks, shininess))->unref();
canvas->drawSprite(fBitmap, 110, 110, &paint);
drawClippedBitmap(canvas, paint, 110, 110);
paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shininess))->unref();
canvas->drawSprite(fBitmap, 220, 110, &paint);
drawClippedBitmap(canvas, paint, 220, 110);
}
private:

View File

@ -58,7 +58,11 @@ protected:
SkPaint paint;
SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(SkMatrixConvolutionImageFilter, (kernelSize, kernel, gain, bias, target, tileMode, convolveAlpha)));
paint.setImageFilter(filter);
canvas->drawSprite(fBitmap, x, y, &paint);
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint);
canvas->restore();
}
virtual void onDraw(SkCanvas* canvas) {