tilemodes.cpp revision a90c6803865766d28e92091f56f718f5e41fe80f
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 "SkColorPriv.h" 141a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkColorFilter.h" 151a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkTypeface.h" 161a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 171a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com// effects 181a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkGradientShader.h" 191a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkUnitMappers.h" 201a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com#include "SkBlurDrawLooper.h" 211a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 22dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.orgstatic void makebm(SkBitmap* bm, SkColorType ct, int w, int h) { 23dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType)); 24dbfac8a72393eaf01670aeb3244de0e18d8faf98junov@google.com bm->eraseColor(SK_ColorTRANSPARENT); 25ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 261a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkCanvas canvas(*bm); 271a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(w), SkIntToScalar(h)} }; 281a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; 291a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; 301a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkPaint paint; 31ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 32ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com SkUnitMapper* um = NULL; 331a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 341a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com um = new SkCosineMapper; 351a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com// um = new SkDiscreteMapper(12); 361a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 371a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkAutoUnref au(um); 381a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 391a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com paint.setDither(true); 401a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, 411a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref(); 421a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com canvas.drawPaint(paint); 431a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com} 441a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 451a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.comstatic void setup(SkPaint* paint, const SkBitmap& bm, bool filter, 461a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkShader::TileMode tmx, SkShader::TileMode tmy) { 471a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy); 481a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com paint->setShader(shader)->unref(); 494469938e92d779dff05e745559e67907bbf21e78reed@google.com paint->setFilterLevel(filter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel); 501a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com} 511a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 52dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.orgstatic const SkColorType gColorTypes[] = { 5328fcae2ec77eb16a79e155f8d788b20457f1c951commit-bot@chromium.org kN32_SkColorType, 54dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org kRGB_565_SkColorType, 551a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com}; 561a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 57a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgclass TilingGM : public skiagm::GM { 581a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.compublic: 5937799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org TilingGM(bool powerOfTwoSize) 606db2ae21a39b64053e64d0057a3136fba5d7b44frobertphillips@google.com : fPowerOfTwoSize(powerOfTwoSize) { 611a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com } 621a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 63dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org SkBitmap fTexture[SK_ARRAY_COUNT(gColorTypes)]; 64ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 651a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.comprotected: 6637799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org 6737799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org enum { 6837799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org kPOTSize = 32, 6937799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org kNPOTSize = 21, 7037799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org }; 7137799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org 721a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkString onShortName() { 7337799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org SkString name("tilemodes"); 7437799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org if (!fPowerOfTwoSize) { 7537799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org name.append("_npot"); 7637799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org } 7737799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org return name; 781a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com } 79ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 80a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkISize onISize() { return SkISize::Make(880, 560); } 81ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 827775d66aa0e5958c9ea55ddb8317af4d9b019220reed@google.com virtual void onOnceBeforeDraw() SK_OVERRIDE { 8337799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; 84dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { 85dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org makebm(&fTexture[i], gColorTypes[i], size, size); 867775d66aa0e5958c9ea55ddb8317af4d9b019220reed@google.com } 877775d66aa0e5958c9ea55ddb8317af4d9b019220reed@google.com } 887775d66aa0e5958c9ea55ddb8317af4d9b019220reed@google.com 897775d66aa0e5958c9ea55ddb8317af4d9b019220reed@google.com virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 90ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 9137799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; 9237799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org 9337799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; 941a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 951a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com static const char* gConfigNames[] = { "8888", "565", "4444" }; 96ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 971a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com static const bool gFilters[] = { false, true }; 981a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com static const char* gFilterNames[] = { "point", "bilinear" }; 99ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 1001a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; 1011a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com static const char* gModeNames[] = { "C", "R", "M" }; 1021a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 1031a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkScalar y = SkIntToScalar(24); 1041a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkScalar x = SkIntToScalar(10); 1051a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 1061a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { 1071a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { 1081a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkPaint p; 1091a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkString str; 1101a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com p.setAntiAlias(true); 1111a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com p.setDither(true); 1121a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); 1131a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 1141a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com p.setTextAlign(SkPaint::kCenter_Align); 1151a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p); 116ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 1171a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com x += r.width() * 4 / 3; 1181a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com } 1191a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com } 120ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 1211a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com y += SkIntToScalar(16); 1221a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 123dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { 1241a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com for (size_t j = 0; j < SK_ARRAY_COUNT(gFilters); j++) { 1251a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com x = SkIntToScalar(10); 1261a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { 1271a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { 1281a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkPaint paint; 129ab3c67832f5cc7349ba452452ad8ad5ed92ea1c1bsalomon@google.com#if 1 // Temporary change to regen bitmap before each draw. This may help tracking down an issue 130ab3c67832f5cc7349ba452452ad8ad5ed92ea1c1bsalomon@google.com // on SGX where resizing NPOT textures to POT textures exhibits a driver bug. 131ab3c67832f5cc7349ba452452ad8ad5ed92ea1c1bsalomon@google.com if (!fPowerOfTwoSize) { 132dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org makebm(&fTexture[i], gColorTypes[i], size, size); 133ab3c67832f5cc7349ba452452ad8ad5ed92ea1c1bsalomon@google.com } 134ab3c67832f5cc7349ba452452ad8ad5ed92ea1c1bsalomon@google.com#endif 1351a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com setup(&paint, fTexture[i], gFilters[j], gModes[kx], gModes[ky]); 1361a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com paint.setDither(true); 137ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 1381a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com canvas->save(); 1391a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com canvas->translate(x, y); 1401a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com canvas->drawRect(r, paint); 1411a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com canvas->restore(); 142ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 1431a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com x += r.width() * 4 / 3; 1441a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com } 1451a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com } 1461a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com { 1471a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkPaint p; 1481a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com SkString str; 1491a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com p.setAntiAlias(true); 1501a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); 1511a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com canvas->drawText(str.c_str(), str.size(), x, y + r.height() * 2 / 3, p); 1521a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com } 1531a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 1541a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com y += r.height() * 4 / 3; 1551a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com } 1561a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com } 1571a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com } 158ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 1591a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.comprivate: 16037799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org bool fPowerOfTwoSize; 161a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org typedef skiagm::GM INHERITED; 1621a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com}; 1631a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 16437799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.orgstatic const int gWidth = 32; 16537799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.orgstatic const int gHeight = 32; 16637799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.org 167a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgstatic SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { 168a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkBitmap bm; 16928fcae2ec77eb16a79e155f8d788b20457f1c951commit-bot@chromium.org makebm(&bm, kN32_SkColorType, gWidth, gHeight); 170a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org return SkShader::CreateBitmapShader(bm, tx, ty); 171a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org} 1721a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 173a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgstatic SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { 174a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} }; 175a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; 176a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkScalar rad = SkIntToScalar(gWidth)/2; 177a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkColor colors[] = { 0xFFFF0000, 0xFF0044FF }; 178a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org 179a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org int index = (int)ty; 180a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org switch (index % 3) { 181a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org case 0: 182a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org return SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COUNT(colors), tx); 183a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org case 1: 184a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org return SkGradientShader::CreateRadial(center, rad, colors, NULL, SK_ARRAY_COUNT(colors), tx); 185a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org case 2: 186a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org return SkGradientShader::CreateSweep(center.fX, center.fY, colors, NULL, SK_ARRAY_COUNT(colors)); 187a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org } 18893f03324189f211db95c312b3cb08b435cc5ac34robertphillips@google.com 18993f03324189f211db95c312b3cb08b435cc5ac34robertphillips@google.com return NULL; 190a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org} 1911a2fec55d914f0a01cbee37077105ef6c8a7366freed@android.com 192a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgtypedef SkShader* (*ShaderProc)(SkShader::TileMode, SkShader::TileMode); 193a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org 194a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgclass Tiling2GM : public skiagm::GM { 195a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org ShaderProc fProc; 196a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkString fName; 197a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgpublic: 198a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org Tiling2GM(ShaderProc proc, const char name[]) : fProc(proc) { 199a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org fName.printf("tilemode_%s", name); 200a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org } 2016a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com 202a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgprotected: 203a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org virtual uint32_t onGetFlags() const SK_OVERRIDE { 204a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org return kSkipTiled_Flag; 205a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org } 206a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org 207a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkString onShortName() { 208a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org return fName; 209a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org } 2106a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com 211a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkISize onISize() { return SkISize::Make(880, 560); } 2126a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com 213a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org virtual void onDraw(SkCanvas* canvas) { 214a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org canvas->scale(SkIntToScalar(3)/2, SkIntToScalar(3)/2); 215a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org 216a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org const SkScalar w = SkIntToScalar(gWidth); 217a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org const SkScalar h = SkIntToScalar(gHeight); 218a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkRect r = { -w, -h, w*2, h*2 }; 219a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org 220a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org static const SkShader::TileMode gModes[] = { 221a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode 222a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org }; 223a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org static const char* gModeNames[] = { 224a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org "Clamp", "Repeat", "Mirror" 225a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org }; 2266a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com 227a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkScalar y = SkIntToScalar(24); 228a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkScalar x = SkIntToScalar(66); 2296a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com 230a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkPaint p; 231a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org p.setAntiAlias(true); 232a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org p.setTextAlign(SkPaint::kCenter_Align); 233a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org 234a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { 235a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkString str(gModeNames[kx]); 236a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p); 237a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org x += r.width() * 4 / 3; 238a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org } 2396a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com 240a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org y += SkIntToScalar(16) + h; 241a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org p.setTextAlign(SkPaint::kRight_Align); 242a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org 243a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { 244a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org x = SkIntToScalar(16) + w; 245a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org 246a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkString str(gModeNames[ky]); 247a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org canvas->drawText(str.c_str(), str.size(), x, y + h/2, p); 248a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org 249a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org x += SkIntToScalar(50); 250a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { 251a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org SkPaint paint; 252a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org paint.setShader(fProc(gModes[kx], gModes[ky]))->unref(); 2536a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com 254a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org canvas->save(); 255a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org canvas->translate(x, y); 256a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org canvas->drawRect(r, paint); 257a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org canvas->restore(); 2586a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com 259a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org x += r.width() * 4 / 3; 260a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org } 261a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org y += r.height() * 4 / 3; 262a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org } 263a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org } 2646a748ad8d82576c4ce59e9b2409d41a93bf05cdfskia.committer@gmail.com 265a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.orgprivate: 266a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org typedef skiagm::GM INHERITED; 267a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org}; 268a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org 269a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org////////////////////////////////////////////////////////////////////////////// 270a0591698fdc13f9923a5a71a108f06ed12f31c9dmike@reedtribe.org 27137799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.orgDEF_GM( return new TilingGM(true); ) 27237799e1f910877e6e87f43584325463efa4d6329commit-bot@chromium.orgDEF_GM( return new TilingGM(false); ) 2733934200b6719828d4d51a995eb36bc43e31d5eb5reed@google.comDEF_GM( return new Tiling2GM(make_bm, "bitmap"); ) 2743934200b6719828d4d51a995eb36bc43e31d5eb5reed@google.comDEF_GM( return new Tiling2GM(make_grad, "gradient"); ) 275