2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkColorPriv.h"
14 * Want to ensure that our bitmap sampler (in bitmap shader) keeps plenty of
15 * precision when scaling very large images (where the dx might get very small.
21 class GiantBitmapGM : public skiagm::GM {
23 SkShader::TileMode fMode;
27 const SkBitmap& getBitmap() {
30 fBM->allocN32Pixels(W, H);
31 fBM->eraseColor(SK_ColorWHITE);
33 const SkColor colors[] = {
34 SK_ColorBLUE, SK_ColorRED, SK_ColorBLACK, SK_ColorGREEN
37 SkCanvas canvas(*fBM);
39 paint.setAntiAlias(true);
40 paint.setStrokeWidth(SkIntToScalar(20));
43 for (int y = -H*2; y < H; y += 50) {
44 SkScalar yy = SkIntToScalar(y);
45 paint.setColor(colors[y/50 & 0x3]);
46 canvas.drawLine(0, yy, SkIntToScalar(W), yy + SkIntToScalar(W),
50 for (int x = -W; x < W; x += 60) {
51 paint.setColor(colors[x/60 & 0x3]);
53 SkScalar xx = SkIntToScalar(x);
54 canvas.drawLine(xx, 0, xx, SkIntToScalar(H),
63 GiantBitmapGM(SkShader::TileMode mode, bool doFilter, bool doRotate) : fBM(NULL) {
69 virtual ~GiantBitmapGM() {
74 virtual uint32_t onGetFlags() const SK_OVERRIDE {
75 #ifdef SK_BUILD_FOR_ANDROID
76 return kSkipTiled_Flag;
78 if (fDoFilter && fDoRotate && fMode != SkShader::kClamp_TileMode) {
79 return kSkipTiled_Flag;
85 virtual SkString onShortName() {
86 SkString str("giantbitmap_");
88 case SkShader::kClamp_TileMode:
91 case SkShader::kRepeat_TileMode:
94 case SkShader::kMirror_TileMode:
100 str.append(fDoFilter ? "_bilerp" : "_point");
101 str.append(fDoRotate ? "_rotate" : "_scale");
105 virtual SkISize onISize() { return SkISize::Make(640, 480); }
107 virtual void onDraw(SkCanvas* canvas) {
112 // m.setRotate(SkIntToScalar(30), 0, 0);
113 m.setSkew(SK_Scalar1, 0, 0, 0);
114 // m.postScale(2*SK_Scalar1/3, 2*SK_Scalar1/3);
116 SkScalar scale = 11*SK_Scalar1/12;
117 m.setScale(scale, scale);
119 SkShader* s = SkShader::CreateBitmapShader(getBitmap(), fMode, fMode, &m);
121 paint.setShader(s)->unref();
122 paint.setFilterLevel(fDoFilter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
124 canvas->translate(SkIntToScalar(50), SkIntToScalar(50));
126 // SkRect r = SkRect::MakeXYWH(-50, -50, 32, 16);
127 // canvas->drawRect(r, paint); return;
128 canvas->drawPaint(paint);
132 typedef GM INHERITED;
135 ///////////////////////////////////////////////////////////////////////////////
137 static skiagm::GM* G000(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, false, false); }
138 static skiagm::GM* G100(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, false, false); }
139 static skiagm::GM* G200(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, false, false); }
140 static skiagm::GM* G010(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, true, false); }
141 static skiagm::GM* G110(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, true, false); }
142 static skiagm::GM* G210(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, true, false); }
144 static skiagm::GM* G001(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, false, true); }
145 static skiagm::GM* G101(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, false, true); }
146 static skiagm::GM* G201(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, false, true); }
147 static skiagm::GM* G011(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, true, true); }
148 static skiagm::GM* G111(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, true, true); }
149 static skiagm::GM* G211(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, true, true); }
151 static skiagm::GMRegistry reg000(G000);
152 static skiagm::GMRegistry reg100(G100);
153 static skiagm::GMRegistry reg200(G200);
154 static skiagm::GMRegistry reg010(G010);
155 static skiagm::GMRegistry reg110(G110);
156 static skiagm::GMRegistry reg210(G210);
158 static skiagm::GMRegistry reg001(G001);
159 static skiagm::GMRegistry reg101(G101);
160 static skiagm::GMRegistry reg201(G201);
161 static skiagm::GMRegistry reg011(G011);
162 static skiagm::GMRegistry reg111(G111);
163 static skiagm::GMRegistry reg211(G211);