1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2013 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "gm/gm.h" 9cb93a386Sopenharmony_ci#include "include/core/SkBitmap.h" 10cb93a386Sopenharmony_ci#include "include/core/SkCanvas.h" 11cb93a386Sopenharmony_ci#include "include/core/SkImage.h" 12cb93a386Sopenharmony_ci#include "include/core/SkPaint.h" 13cb93a386Sopenharmony_ci#include "include/core/SkPath.h" 14cb93a386Sopenharmony_ci#include "include/core/SkRect.h" 15cb93a386Sopenharmony_ci#include "include/core/SkScalar.h" 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_cistatic sk_sp<SkImage> make_bm() { 18cb93a386Sopenharmony_ci SkBitmap bm; 19cb93a386Sopenharmony_ci bm.allocN32Pixels(60, 60); 20cb93a386Sopenharmony_ci bm.eraseColor(0); 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ci SkCanvas canvas(bm); 23cb93a386Sopenharmony_ci SkPaint paint; 24cb93a386Sopenharmony_ci canvas.drawPath(SkPath::Polygon({{6,6}, {6,54}, {30,54}}, false), paint); 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_ci paint.setStyle(SkPaint::kStroke_Style); 27cb93a386Sopenharmony_ci canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 59.5f, 59.5f), paint); 28cb93a386Sopenharmony_ci return bm.asImage(); 29cb93a386Sopenharmony_ci} 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ci// This creates a close, but imperfect concatenation of 32cb93a386Sopenharmony_ci// scaling the image up by its dst-rect 33cb93a386Sopenharmony_ci// scaling the image down by the matrix' scale 34cb93a386Sopenharmony_ci// The bug was that for cases like this, we were incorrectly trying to take a 35cb93a386Sopenharmony_ci// fast-path in the bitmapshader, but ended up drawing the last col of pixels 36cb93a386Sopenharmony_ci// twice. The fix resulted in (a) not taking the fast-path, but (b) drawing 37cb93a386Sopenharmony_ci// the image correctly. 38cb93a386Sopenharmony_ci// 39cb93a386Sopenharmony_ciDEF_SIMPLE_GM(bitmaprecttest, canvas, 320, 240) { 40cb93a386Sopenharmony_ci auto image = make_bm(); 41cb93a386Sopenharmony_ci 42cb93a386Sopenharmony_ci canvas->drawImage(image, 150, 45); 43cb93a386Sopenharmony_ci 44cb93a386Sopenharmony_ci SkScalar scale = 0.472560018f; 45cb93a386Sopenharmony_ci canvas->save(); 46cb93a386Sopenharmony_ci canvas->scale(scale, scale); 47cb93a386Sopenharmony_ci canvas->drawImageRect(image, SkRect::MakeXYWH(100, 100, 128, 128), SkSamplingOptions()); 48cb93a386Sopenharmony_ci canvas->restore(); 49cb93a386Sopenharmony_ci 50cb93a386Sopenharmony_ci canvas->scale(-1, 1); 51cb93a386Sopenharmony_ci canvas->drawImage(image, -310, 45); 52cb93a386Sopenharmony_ci} 53