blob: 3ea110c44f6da21304638cb662c92a5e6c560b8b [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:
34 virtual SkString onShortName() {
35 return SkString("tiledscaledbitmap");
36 }
37
38 virtual SkISize onISize() {
39 return SkISize::Make(1016, 616);
40 }
41
42 virtual uint32_t onGetFlags() const SK_OVERRIDE {
43 return kSkipTiled_Flag;
44 }
45
46 static SkBitmap make_bm(int width, int height) {
47 SkBitmap bm;
48 bm.allocN32Pixels(width, height);
49 bm.eraseColor(SK_ColorTRANSPARENT);
50 SkCanvas canvas(bm);
51 SkPaint paint;
52 paint.setAntiAlias(true);
53 canvas.drawCircle(width/2.f, height/2.f, width/4.f, paint);
54 return bm;
55 }
56
57 virtual void onOnceBeforeDraw() SK_OVERRIDE {
58 fBitmap = make_bm(360, 288);
59 }
60
61 virtual void onDraw(SkCanvas* canvas) {
62 SkPaint paint;
63
64 paint.setAntiAlias(true);
65 paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
66
67 SkMatrix mat;
68 mat.setScale(121.f/360.f, 93.f/288.f);
69 mat.postTranslate(-72, -72);
70
71 SkShader *shader = SkShader::CreateBitmapShader(fBitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &mat);
72 paint.setShader(shader);
73
74 SkSafeUnref(shader);
75 canvas->drawRectCoords(8,8,1008, 608, paint);
76 }
77
78private:
79 SkBitmap fBitmap;
80
81 typedef GM INHERITED;
82};
83
84//////////////////////////////////////////////////////////////////////////////
85
86DEF_GM(return SkNEW(TiledScaledBitmapGM);)
87
88}