blob: daecbb05e23ce1d0ac34aada9e66b283b97565dd [file] [log] [blame]
humper535e3b22014-10-27 10:32:06 -07001
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#include "gm.h"
9
10#include "Resources.h"
11#include "SkBitmap.h"
12#include "SkImageDecoder.h"
13#include "SkPaint.h"
14#include "SkShader.h"
15#include "SkStream.h"
16
17
18 /***
19 *
20 * This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
21 * when fractional image scaling was ignored by the high quality bitmap scaler.
22 *
23 ***/
24
25namespace skiagm {
26
27class TiledScaledBitmapGM : public GM {
28public:
29
30 TiledScaledBitmapGM() {
31 }
32
33protected:
mtklein36352bf2015-03-25 18:17:31 -070034 SkString onShortName() override {
humper535e3b22014-10-27 10:32:06 -070035 return SkString("tiledscaledbitmap");
36 }
37
mtklein36352bf2015-03-25 18:17:31 -070038 SkISize onISize() override {
humper535e3b22014-10-27 10:32:06 -070039 return SkISize::Make(1016, 616);
40 }
41
tfarina752e7eb2014-12-20 06:53:43 -080042 static SkBitmap make_bm(int width, int height) {
humper535e3b22014-10-27 10:32:06 -070043 SkBitmap bm;
44 bm.allocN32Pixels(width, height);
45 bm.eraseColor(SK_ColorTRANSPARENT);
46 SkCanvas canvas(bm);
47 SkPaint paint;
48 paint.setAntiAlias(true);
49 canvas.drawCircle(width/2.f, height/2.f, width/4.f, paint);
tfarina752e7eb2014-12-20 06:53:43 -080050 return bm;
humper535e3b22014-10-27 10:32:06 -070051 }
52
mtklein36352bf2015-03-25 18:17:31 -070053 void onOnceBeforeDraw() override {
humper535e3b22014-10-27 10:32:06 -070054 fBitmap = make_bm(360, 288);
55 }
56
mtklein36352bf2015-03-25 18:17:31 -070057 void onDraw(SkCanvas* canvas) override {
humper535e3b22014-10-27 10:32:06 -070058 SkPaint paint;
59
60 paint.setAntiAlias(true);
reed93a12152015-03-16 10:08:34 -070061 paint.setFilterQuality(kHigh_SkFilterQuality);
humper535e3b22014-10-27 10:32:06 -070062
63 SkMatrix mat;
64 mat.setScale(121.f/360.f, 93.f/288.f);
65 mat.postTranslate(-72, -72);
66
67 SkShader *shader = SkShader::CreateBitmapShader(fBitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &mat);
68 paint.setShader(shader);
69
70 SkSafeUnref(shader);
71 canvas->drawRectCoords(8,8,1008, 608, paint);
72 }
73
74private:
75 SkBitmap fBitmap;
76
77 typedef GM INHERITED;
78};
79
80//////////////////////////////////////////////////////////////////////////////
81
halcanary385fe4d2015-08-26 13:07:48 -070082DEF_GM(return new TiledScaledBitmapGM;)
humper535e3b22014-10-27 10:32:06 -070083}