From f786901ff03f78c86962a2a1ed227f1533d16d2b Mon Sep 17 00:00:00 2001 From: reed Date: Mon, 1 Dec 2014 13:54:01 -0800 Subject: add gm to test rounding between clips and drawBitmapRect BUG=skia:3179 Review URL: https://codereview.chromium.org/766333002 --- gm/bitmaprect.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'gm/bitmaprect.cpp') diff --git a/gm/bitmaprect.cpp b/gm/bitmaprect.cpp index badffb9a93..53a855e778 100644 --- a/gm/bitmaprect.cpp +++ b/gm/bitmaprect.cpp @@ -233,6 +233,49 @@ private: typedef skiagm::GM INHERITED; }; +class BitmapRectRounding : public skiagm::GM { + SkBitmap fBM; + +public: + BitmapRectRounding() {} + +protected: + SkString onShortName() SK_OVERRIDE { + SkString str; + str.printf("bitmaprect_rounding"); + return str; + } + + SkISize onISize() SK_OVERRIDE { + return SkISize::Make(640, 480); + } + + void onOnceBeforeDraw() SK_OVERRIDE { + fBM.allocN32Pixels(10, 10); + fBM.eraseColor(SK_ColorBLUE); + } + + // This choice of coordinates and matrix land the bottom edge of the clip (and bitmap dst) + // at exactly 1/2 pixel boundary. However, drawBitmapRect may lose precision along the way. + // If it does, we may see a red-line at the bottom, instead of the bitmap exactly matching + // the clip (in which case we should see all blue). + // The correct image should be all blue. + void onDraw(SkCanvas* canvas) SK_OVERRIDE { + SkPaint paint; + paint.setColor(SK_ColorRED); + + const SkRect r = SkRect::MakeXYWH(1, 1, 110, 114); + canvas->scale(0.9f, 0.9f); + + // the drawRect shows the same problem as clipRect(r) followed by drawcolor(red) + canvas->drawRect(r, paint); + canvas->drawBitmapRect(fBM, NULL, r, NULL); + } + +private: + typedef skiagm::GM INHERITED; +}; + ////////////////////////////////////////////////////////////////////////////// static skiagm::GM* MyFactory0(void*) { return new DrawBitmapRect2(false); } @@ -254,3 +297,5 @@ static skiagm::GMRegistry reg2(MyFactory2); static skiagm::GMRegistry reg3(MyFactory3); static skiagm::GMRegistry reg4(MyFactory4); #endif + +DEF_GM( return new BitmapRectRounding; ) -- cgit v1.2.3