Add GM to repro crbug.com/472795
This CL also adds a new parameter to SkBitmapSource which gives the user control of the filter quality. BUG=472795 Review URL: https://codereview.chromium.org/1072603002
This commit is contained in:
parent
f57546ec7f
commit
e275fdf812
90
gm/bitmapsource2.cpp
Normal file
90
gm/bitmapsource2.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Google Inc.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
|
* found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gm.h"
|
||||||
|
#include "SkBitmapSource.h"
|
||||||
|
|
||||||
|
namespace skiagm {
|
||||||
|
|
||||||
|
// This GM reproduces the issue in crbug.com/472795. The SkBitmapSource image
|
||||||
|
// is shifted for high quality mode between cpu and gpu.
|
||||||
|
class BitmapSourceGM : public GM {
|
||||||
|
public:
|
||||||
|
BitmapSourceGM(const char* suffix, SkFilterQuality filter) : fSuffix(suffix), fFilter(filter) {
|
||||||
|
this->setBGColor(0xFFFFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SkString onShortName() override {
|
||||||
|
SkString name("bitmapsrc2_");
|
||||||
|
name.append(fSuffix);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
SkISize onISize() override { return SkISize::Make(256, 256); }
|
||||||
|
|
||||||
|
// Create a bitmap with high frequency vertical stripes
|
||||||
|
void onOnceBeforeDraw() override {
|
||||||
|
static const SkPMColor gColors[] = {
|
||||||
|
SK_ColorRED, SK_ColorGRAY,
|
||||||
|
SK_ColorGREEN, SK_ColorGRAY,
|
||||||
|
SK_ColorBLUE, SK_ColorGRAY,
|
||||||
|
SK_ColorCYAN, SK_ColorGRAY,
|
||||||
|
SK_ColorMAGENTA, SK_ColorGRAY,
|
||||||
|
SK_ColorYELLOW, SK_ColorGRAY,
|
||||||
|
SK_ColorWHITE, SK_ColorGRAY,
|
||||||
|
};
|
||||||
|
|
||||||
|
fBM.allocN32Pixels(kImageSize, kImageSize, true);
|
||||||
|
|
||||||
|
SkCanvas canvas(fBM);
|
||||||
|
|
||||||
|
int curColor = 0;
|
||||||
|
|
||||||
|
for (int x = 0; x < kImageSize; x += 3) {
|
||||||
|
SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(0),
|
||||||
|
SkIntToScalar(3), SkIntToScalar(kImageSize));
|
||||||
|
SkPaint p;
|
||||||
|
p.setColor(gColors[curColor]);
|
||||||
|
canvas.drawRect(r, p);
|
||||||
|
|
||||||
|
curColor = (curColor+1) % SK_ARRAY_COUNT(gColors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onDraw(SkCanvas* canvas) override {
|
||||||
|
SkRect srcRect = SkRect::MakeLTRB(0, 0,
|
||||||
|
SkIntToScalar(kImageSize), SkIntToScalar(kImageSize));
|
||||||
|
SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
|
||||||
|
|
||||||
|
SkAutoTUnref<SkImageFilter> filter(SkBitmapSource::Create(fBM, srcRect, dstRect, fFilter));
|
||||||
|
|
||||||
|
SkPaint p;
|
||||||
|
p.setImageFilter(filter);
|
||||||
|
|
||||||
|
canvas->saveLayer(NULL, &p);
|
||||||
|
canvas->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const int kImageSize = 503;
|
||||||
|
|
||||||
|
SkString fSuffix;
|
||||||
|
SkFilterQuality fFilter;
|
||||||
|
SkBitmap fBM;
|
||||||
|
|
||||||
|
typedef GM INHERITED;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
DEF_GM( return SkNEW_ARGS(BitmapSourceGM, ("none", kNone_SkFilterQuality) ); )
|
||||||
|
DEF_GM( return SkNEW_ARGS(BitmapSourceGM, ("low", kLow_SkFilterQuality) ); )
|
||||||
|
DEF_GM( return SkNEW_ARGS(BitmapSourceGM, ("med", kMedium_SkFilterQuality) ); )
|
||||||
|
DEF_GM( return SkNEW_ARGS(BitmapSourceGM, ("high", kHigh_SkFilterQuality) ); )
|
||||||
|
|
||||||
|
}
|
@ -38,6 +38,7 @@
|
|||||||
'../gm/bitmapscroll.cpp',
|
'../gm/bitmapscroll.cpp',
|
||||||
'../gm/bitmapshader.cpp',
|
'../gm/bitmapshader.cpp',
|
||||||
'../gm/bitmapsource.cpp',
|
'../gm/bitmapsource.cpp',
|
||||||
|
'../gm/bitmapsource2.cpp',
|
||||||
'../gm/bleed.cpp',
|
'../gm/bleed.cpp',
|
||||||
'../gm/blurcircles.cpp',
|
'../gm/blurcircles.cpp',
|
||||||
'../gm/blurs.cpp',
|
'../gm/blurs.cpp',
|
||||||
|
@ -16,9 +16,10 @@ public:
|
|||||||
static SkBitmapSource* Create(const SkBitmap& bitmap) {
|
static SkBitmapSource* Create(const SkBitmap& bitmap) {
|
||||||
return SkNEW_ARGS(SkBitmapSource, (bitmap));
|
return SkNEW_ARGS(SkBitmapSource, (bitmap));
|
||||||
}
|
}
|
||||||
static SkBitmapSource* Create(const SkBitmap& bitmap, const SkRect& srcRect,
|
static SkBitmapSource* Create(const SkBitmap& bitmap,
|
||||||
const SkRect& dstRect) {
|
const SkRect& srcRect, const SkRect& dstRect,
|
||||||
return SkNEW_ARGS(SkBitmapSource, (bitmap, srcRect, dstRect));
|
SkFilterQuality filterQuality = kHigh_SkFilterQuality) {
|
||||||
|
return SkNEW_ARGS(SkBitmapSource, (bitmap, srcRect, dstRect, filterQuality));
|
||||||
}
|
}
|
||||||
void computeFastBounds(const SkRect& src, SkRect* dst) const override;
|
void computeFastBounds(const SkRect& src, SkRect* dst) const override;
|
||||||
|
|
||||||
@ -27,7 +28,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit SkBitmapSource(const SkBitmap& bitmap);
|
explicit SkBitmapSource(const SkBitmap& bitmap);
|
||||||
SkBitmapSource(const SkBitmap& bitmap, const SkRect& srcRect, const SkRect& dstRect);
|
SkBitmapSource(const SkBitmap& bitmap,
|
||||||
|
const SkRect& srcRect, const SkRect& dstRect,
|
||||||
|
SkFilterQuality filterQuality);
|
||||||
void flatten(SkWriteBuffer&) const override;
|
void flatten(SkWriteBuffer&) const override;
|
||||||
|
|
||||||
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
|
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
|
||||||
@ -36,6 +39,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
SkBitmap fBitmap;
|
SkBitmap fBitmap;
|
||||||
SkRect fSrcRect, fDstRect;
|
SkRect fSrcRect, fDstRect;
|
||||||
|
SkFilterQuality fFilterQuality;
|
||||||
|
|
||||||
typedef SkImageFilter INHERITED;
|
typedef SkImageFilter INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,13 +18,18 @@ SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap)
|
|||||||
, fSrcRect(SkRect::MakeWH(SkIntToScalar(bitmap.width()),
|
, fSrcRect(SkRect::MakeWH(SkIntToScalar(bitmap.width()),
|
||||||
SkIntToScalar(bitmap.height())))
|
SkIntToScalar(bitmap.height())))
|
||||||
, fDstRect(fSrcRect)
|
, fDstRect(fSrcRect)
|
||||||
{}
|
, fFilterQuality(kHigh_SkFilterQuality) {
|
||||||
|
}
|
||||||
|
|
||||||
SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap, const SkRect& srcRect, const SkRect& dstRect)
|
SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap,
|
||||||
|
const SkRect& srcRect, const SkRect& dstRect,
|
||||||
|
SkFilterQuality filterQuality)
|
||||||
: INHERITED(0, 0)
|
: INHERITED(0, 0)
|
||||||
, fBitmap(bitmap)
|
, fBitmap(bitmap)
|
||||||
, fSrcRect(srcRect)
|
, fSrcRect(srcRect)
|
||||||
, fDstRect(dstRect) {}
|
, fDstRect(dstRect)
|
||||||
|
, fFilterQuality(filterQuality) {
|
||||||
|
}
|
||||||
|
|
||||||
SkFlattenable* SkBitmapSource::CreateProc(SkReadBuffer& buffer) {
|
SkFlattenable* SkBitmapSource::CreateProc(SkReadBuffer& buffer) {
|
||||||
SkRect src, dst;
|
SkRect src, dst;
|
||||||
@ -71,12 +76,13 @@ bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const Context&
|
|||||||
// None filtering when it's translate-only
|
// None filtering when it's translate-only
|
||||||
paint.setFilterQuality(
|
paint.setFilterQuality(
|
||||||
fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height() ?
|
fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height() ?
|
||||||
kNone_SkFilterQuality : kHigh_SkFilterQuality);
|
kNone_SkFilterQuality : fFilterQuality);
|
||||||
canvas.drawBitmapRectToRect(fBitmap, &fSrcRect, dstRect, &paint);
|
canvas.drawBitmapRectToRect(fBitmap, &fSrcRect, dstRect, &paint);
|
||||||
|
|
||||||
*result = device.get()->accessBitmap(false);
|
*result = device.get()->accessBitmap(false);
|
||||||
offset->fX = dstIRect.fLeft;
|
offset->fX = dstIRect.fLeft;
|
||||||
offset->fY = dstIRect.fTop;
|
offset->fY = dstIRect.fTop;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user