blob: 0f28c1e157c5da1c14c45ed4553e81af4011884d [file] [log] [blame]
humper535e3b22014-10-27 10:32:06 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed1a9b9642016-03-13 14:13:58 -07007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/core/SkBitmap.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkCanvas.h"
11#include "include/core/SkColor.h"
12#include "include/core/SkFilterQuality.h"
13#include "include/core/SkMatrix.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/core/SkPaint.h"
15#include "include/core/SkShader.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040016#include "include/core/SkSize.h"
17#include "include/core/SkString.h"
18#include "include/core/SkTileMode.h"
humper535e3b22014-10-27 10:32:06 -070019
humper535e3b22014-10-27 10:32:06 -070020 /***
21 *
22 * This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
23 * when fractional image scaling was ignored by the high quality bitmap scaler.
24 *
25 ***/
26
27namespace skiagm {
28
29class TiledScaledBitmapGM : public GM {
30public:
31
32 TiledScaledBitmapGM() {
33 }
34
35protected:
mtklein36352bf2015-03-25 18:17:31 -070036 SkString onShortName() override {
humper535e3b22014-10-27 10:32:06 -070037 return SkString("tiledscaledbitmap");
38 }
39
mtklein36352bf2015-03-25 18:17:31 -070040 SkISize onISize() override {
humper535e3b22014-10-27 10:32:06 -070041 return SkISize::Make(1016, 616);
42 }
43
tfarina752e7eb2014-12-20 06:53:43 -080044 static SkBitmap make_bm(int width, int height) {
humper535e3b22014-10-27 10:32:06 -070045 SkBitmap bm;
46 bm.allocN32Pixels(width, height);
47 bm.eraseColor(SK_ColorTRANSPARENT);
48 SkCanvas canvas(bm);
49 SkPaint paint;
50 paint.setAntiAlias(true);
51 canvas.drawCircle(width/2.f, height/2.f, width/4.f, paint);
tfarina752e7eb2014-12-20 06:53:43 -080052 return bm;
humper535e3b22014-10-27 10:32:06 -070053 }
54
mtklein36352bf2015-03-25 18:17:31 -070055 void onOnceBeforeDraw() override {
humper535e3b22014-10-27 10:32:06 -070056 fBitmap = make_bm(360, 288);
57 }
58
mtklein36352bf2015-03-25 18:17:31 -070059 void onDraw(SkCanvas* canvas) override {
humper535e3b22014-10-27 10:32:06 -070060 SkPaint paint;
61
62 paint.setAntiAlias(true);
reed93a12152015-03-16 10:08:34 -070063 paint.setFilterQuality(kHigh_SkFilterQuality);
humper535e3b22014-10-27 10:32:06 -070064
65 SkMatrix mat;
66 mat.setScale(121.f/360.f, 93.f/288.f);
67 mat.postTranslate(-72, -72);
68
Mike Reed50acf8f2019-04-08 13:20:23 -040069 paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &mat));
Mike Reed3661bc92017-02-22 13:21:42 -050070 canvas->drawRect({ 8, 8, 1008, 608 }, paint);
humper535e3b22014-10-27 10:32:06 -070071 }
72
73private:
74 SkBitmap fBitmap;
75
76 typedef GM INHERITED;
77};
78
79//////////////////////////////////////////////////////////////////////////////
80
halcanary385fe4d2015-08-26 13:07:48 -070081DEF_GM(return new TiledScaledBitmapGM;)
humper535e3b22014-10-27 10:32:06 -070082}