1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc.
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
81a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "gm.h"
91a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkPath.h"
101a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkRegion.h"
111a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkShader.h"
121a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkUtils.h"
131a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkColorFilter.h"
141a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
151a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com// effects
161a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkGradientShader.h"
171a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkBlurDrawLooper.h"
181a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
19dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.orgstatic void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
20dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org    bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType));
21dbfac8a72393eaf01670aeb3244de0e18d8faf98junov@google.com    bm->eraseColor(SK_ColorTRANSPARENT);
22ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
231a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    SkCanvas    canvas(*bm);
241a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    SkPoint     pts[] = { { 0, 0 }, { SkIntToScalar(w), SkIntToScalar(h)} };
251a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    SkColor     colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
261a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    SkScalar    pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
271a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    SkPaint     paint;
28ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
291a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    paint.setDither(true);
301a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
3183f23d87f1d67e6e73873e1ef7cda621c43703a0commit-bot@chromium.org                SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
321a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    canvas.drawPaint(paint);
331a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com}
341a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
351a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.comstatic void setup(SkPaint* paint, const SkBitmap& bm, bool filter,
361a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                  SkShader::TileMode tmx, SkShader::TileMode tmy) {
371a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy);
381a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    paint->setShader(shader)->unref();
3993a1215fe0ab007ce941c721f1fd3e9dcb5d4754reed    paint->setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
401a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com}
411a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
42dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.orgstatic const SkColorType gColorTypes[] = {
4328fcae2ec77eb16a79e155f8d788b20457f1c951commit-bot@chromium.org    kN32_SkColorType,
44dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org    kRGB_565_SkColorType,
451a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com};
461a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
47a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgclass TilingGM : public skiagm::GM {
481a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.compublic:
4937799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org    TilingGM(bool powerOfTwoSize)
506db2ae21a39b64053e64d0057a3136fba5d7b44frobertphillips@google.com            : fPowerOfTwoSize(powerOfTwoSize) {
511a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    }
521a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
53dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org    SkBitmap    fTexture[SK_ARRAY_COUNT(gColorTypes)];
54ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
551a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.comprotected:
5637799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org
5737799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org    enum {
5837799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org        kPOTSize = 32,
5937799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org        kNPOTSize = 21,
6037799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org    };
6137799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org
6236352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkString onShortName() override {
6337799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org        SkString name("tilemodes");
6437799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org        if (!fPowerOfTwoSize) {
6537799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org            name.append("_npot");
6637799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org        }
6737799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org        return name;
681a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    }
69ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
7036352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkISize onISize() override { return SkISize::Make(880, 560); }
71ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
7236352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void onOnceBeforeDraw() override {
7337799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org        int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize;
74dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org        for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
75dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org            makebm(&fTexture[i], gColorTypes[i], size, size);
767775d66aa0e5958c9ea55ddb8317af4d9b019220reed@google.com        }
777775d66aa0e5958c9ea55ddb8317af4d9b019220reed@google.com    }
787775d66aa0e5958c9ea55ddb8317af4d9b019220reed@google.com
7936352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void onDraw(SkCanvas* canvas) override {
80ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
8137799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org        int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize;
8237799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org
8337799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org        SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) };
841a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
851a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        static const char* gConfigNames[] = { "8888", "565", "4444" };
86ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
871a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        static const bool           gFilters[] = { false, true };
881a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        static const char*          gFilterNames[] = {     "point",                     "bilinear" };
89ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
901a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode };
911a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        static const char*          gModeNames[] = {    "C",                    "R",                   "M" };
921a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
931a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        SkScalar y = SkIntToScalar(24);
941a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        SkScalar x = SkIntToScalar(10);
951a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
961a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
971a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com            for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) {
981a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                SkPaint p;
991a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                SkString str;
1001a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                p.setAntiAlias(true);
1012880df2609eba09b555ca37be04b6ad89290c765Tom Hudson                sk_tool_utils::set_portable_typeface(&p);
1021a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                p.setDither(true);
1031a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]);
1041a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
1051a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                p.setTextAlign(SkPaint::kCenter_Align);
1061a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p);
107ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1081a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                x += r.width() * 4 / 3;
1091a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com            }
1101a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        }
111ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1121a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        y += SkIntToScalar(16);
1131a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
114dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org        for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
1151a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com            for (size_t j = 0; j < SK_ARRAY_COUNT(gFilters); j++) {
1161a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                x = SkIntToScalar(10);
1171a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
1181a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                    for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) {
1191a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                        SkPaint paint;
120ab3c67832f5cc7349ba452452ad8ad5ed92ea1c1bsalomon@google.com#if 1 // Temporary change to regen bitmap before each draw. This may help tracking down an issue
121ab3c67832f5cc7349ba452452ad8ad5ed92ea1c1bsalomon@google.com      // on SGX where resizing NPOT textures to POT textures exhibits a driver bug.
122ab3c67832f5cc7349ba452452ad8ad5ed92ea1c1bsalomon@google.com                        if (!fPowerOfTwoSize) {
123dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org                            makebm(&fTexture[i], gColorTypes[i], size, size);
124ab3c67832f5cc7349ba452452ad8ad5ed92ea1c1bsalomon@google.com                        }
125ab3c67832f5cc7349ba452452ad8ad5ed92ea1c1bsalomon@google.com#endif
1261a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                        setup(&paint, fTexture[i], gFilters[j], gModes[kx], gModes[ky]);
1271a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                        paint.setDither(true);
128ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1291a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                        canvas->save();
1301a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                        canvas->translate(x, y);
1311a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                        canvas->drawRect(r, paint);
1321a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                        canvas->restore();
133ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1341a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                        x += r.width() * 4 / 3;
1351a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                    }
1361a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                }
1371a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                {
1381a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                    SkPaint p;
1391a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                    SkString str;
1401a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                    p.setAntiAlias(true);
1412880df2609eba09b555ca37be04b6ad89290c765Tom Hudson                    sk_tool_utils::set_portable_typeface(&p);
1421a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                    str.printf("%s, %s", gConfigNames[i], gFilterNames[j]);
1431a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                    canvas->drawText(str.c_str(), str.size(), x, y + r.height() * 2 / 3, p);
1441a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                }
1451a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
1461a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com                y += r.height() * 4 / 3;
1471a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com            }
1481a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com        }
1491a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com    }
150ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1511a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.comprivate:
15237799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org    bool fPowerOfTwoSize;
153a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    typedef skiagm::GM INHERITED;
1541a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com};
1551a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
15637799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.orgstatic const int gWidth = 32;
15737799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.orgstatic const int gHeight = 32;
15837799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org
159a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgstatic SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
160a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    SkBitmap bm;
16128fcae2ec77eb16a79e155f8d788b20457f1c951commit-bot@chromium.org    makebm(&bm, kN32_SkColorType, gWidth, gHeight);
162a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    return SkShader::CreateBitmapShader(bm, tx, ty);
163a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org}
1641a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
165a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgstatic SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
166a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} };
167a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 };
168a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    SkScalar rad = SkIntToScalar(gWidth)/2;
1691e545b6915a2f2e59d917b7fa9695aa15467f61bcaryclark    SkColor colors[] = { 0xFFFF0000, sk_tool_utils::color_to_565(0xFF0044FF) };
170a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org
171a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    int index = (int)ty;
172a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    switch (index % 3) {
173a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        case 0:
1742880df2609eba09b555ca37be04b6ad89290c765Tom Hudson            return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
175a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        case 1:
1762880df2609eba09b555ca37be04b6ad89290c765Tom Hudson            return SkGradientShader::CreateRadial(center, rad, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
177a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        case 2:
1782880df2609eba09b555ca37be04b6ad89290c765Tom Hudson            return SkGradientShader::CreateSweep(center.fX, center.fY, colors, nullptr, SK_ARRAY_COUNT(colors));
179a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    }
18093f03324189f211db95c312b3cb08b435cc5ac34robertphillips@google.com
1812880df2609eba09b555ca37be04b6ad89290c765Tom Hudson    return nullptr;
182a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org}
1831a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com
184a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgtypedef SkShader* (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
185a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org
186a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgclass Tiling2GM : public skiagm::GM {
187a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    ShaderProc fProc;
188a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    SkString   fName;
189a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgpublic:
190a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    Tiling2GM(ShaderProc proc, const char name[]) : fProc(proc) {
191a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        fName.printf("tilemode_%s", name);
192a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    }
1936a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com
194a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgprotected:
195a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org
19636352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkString onShortName() override {
197a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        return fName;
198a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    }
1996a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com
20036352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkISize onISize() override { return SkISize::Make(880, 560); }
2016a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com
20236352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void onDraw(SkCanvas* canvas) override {
203a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        canvas->scale(SkIntToScalar(3)/2, SkIntToScalar(3)/2);
204a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org
205a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        const SkScalar w = SkIntToScalar(gWidth);
206a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        const SkScalar h = SkIntToScalar(gHeight);
207a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        SkRect r = { -w, -h, w*2, h*2 };
208a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org
209a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        static const SkShader::TileMode gModes[] = {
210a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode
211a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        };
212a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        static const char* gModeNames[] = {
213a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            "Clamp", "Repeat", "Mirror"
214a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        };
2156a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com
216a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        SkScalar y = SkIntToScalar(24);
217a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        SkScalar x = SkIntToScalar(66);
2186a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com
219a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        SkPaint p;
220a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        p.setAntiAlias(true);
2212880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        sk_tool_utils::set_portable_typeface(&p);
222a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        p.setTextAlign(SkPaint::kCenter_Align);
223a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org
224a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
225a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            SkString str(gModeNames[kx]);
226a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p);
227a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            x += r.width() * 4 / 3;
228a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        }
2296a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com
230a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        y += SkIntToScalar(16) + h;
231a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        p.setTextAlign(SkPaint::kRight_Align);
232a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org
233a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) {
234a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            x = SkIntToScalar(16) + w;
235a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org
236a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            SkString str(gModeNames[ky]);
237a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            canvas->drawText(str.c_str(), str.size(), x, y + h/2, p);
238a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org
239a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            x += SkIntToScalar(50);
240a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
241a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org                SkPaint paint;
242a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org                paint.setShader(fProc(gModes[kx], gModes[ky]))->unref();
2436a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com
244a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org                canvas->save();
245a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org                canvas->translate(x, y);
246a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org                canvas->drawRect(r, paint);
247a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org                canvas->restore();
2486a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com
249a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org                x += r.width() * 4 / 3;
250a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            }
251a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org            y += r.height() * 4 / 3;
252a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org        }
253a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    }
2546a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com
255a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgprivate:
256a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org    typedef skiagm::GM INHERITED;
257a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org};
258a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org
259a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org//////////////////////////////////////////////////////////////////////////////
260a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org
26137799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.orgDEF_GM( return new TilingGM(true); )
26237799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.orgDEF_GM( return new TilingGM(false); )
2633934200b6719828d4d51a995eb36bc43e31d5eb5reed@google.comDEF_GM( return new Tiling2GM(make_bm, "bitmap"); )
2643934200b6719828d4d51a995eb36bc43e31d5eb5reed@google.comDEF_GM( return new Tiling2GM(make_grad, "gradient"); )
265