TilingGM() : fLooper(SkIntToScalar(1), SkIntToScalar(2), SkIntToScalar(2), 0x88000000) { for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { makebm(&fTexture[i], gConfigs[i], gWidth, gHeight); } }
void onDelayedSetup() override { int w = 40; int h = 40; makebm(&fBmp, w, h); fBmShader = SkShader::CreateBitmapShader(fBmp, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); int offset = 2; int count = 0; for (int j = 0; j < NY; ++j) { for (int i = 0; i < NX; ++i) { int x = (w + offset) * i; int y = (h * offset) * j; if (kRect_DrawType == fDrawType) { fRects[count].set(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), SkIntToScalar(y + h)); } else { fPaths[count].moveTo(SkIntToScalar(x), SkIntToScalar(y)); fPaths[count].rLineTo(SkIntToScalar(w), 0); fPaths[count].rLineTo(0, SkIntToScalar(h)); fPaths[count].rLineTo(SkIntToScalar(-w + 1), 0); } if (0 == count % 2) { fColors[count] = fPattern1.fColor; fShaders[count] = fPattern1.fIsBitmap ? fBmShader : nullptr; } else { fColors[count] = fPattern2.fColor; fShaders[count] = fPattern2.fIsBitmap ? fBmShader : nullptr; } ++count; } } }
TilingView() : fLooper(SkBlurDrawLooper::Create(0x88000000, SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)), SkIntToScalar(2), SkIntToScalar(2))) { for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { makebm(&fTexture[i], gColorTypes[i], gWidth, gHeight); } }
static SkShader* MakeBitmapShader(SkShader::TileMode tx, SkShader::TileMode ty, int w, int h) { static SkBitmap bmp; if (bmp.isNull()) { makebm(&bmp, w/2, h/4); } return SkShader::CreateBitmapShader(bmp, tx, ty); }
void onDraw(SkCanvas* canvas) override { if (nullptr == fImage) { fImage = makebm(gSurfaceSize, gSurfaceSize); } const SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)}; const int kMaxSrcRectSize = 1 << (SkNextLog2(gSurfaceSize) + 2); constexpr int kPadX = 30; constexpr int kPadY = 40; int rowCount = 0; canvas->translate(SkIntToScalar(kPadX), SkIntToScalar(kPadY)); canvas->save(); SkRandom random; SkPaint paint; paint.setAntiAlias(fAA); for (int w = 1; w <= kMaxSrcRectSize; w *= 3) { for (int h = 1; h <= kMaxSrcRectSize; h *= 3) { const SkIRect srcRect = SkIRect::MakeXYWH((gSurfaceSize - w) / 2, (gSurfaceSize - h) / 2, w, h); canvas->save(); switch (random.nextU() % 3) { case 0: canvas->rotate(random.nextF() * 10.f); break; case 1: canvas->rotate(-random.nextF() * 10.f); break; case 2: // rect stays rect break; } canvas->drawImageRect(fImage.get(), srcRect, dstRect, &paint, SkCanvas::kFast_SrcRectConstraint); canvas->restore(); canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0); ++rowCount; if ((dstRect.width() + 2 * kPadX) * rowCount > gSize) { canvas->restore(); canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY); canvas->save(); rowCount = 0; } } } canvas->restore(); }
void onOnceBeforeDraw() override { fImage.reset(makebm(&fLargeBitmap, gBmpSize, gBmpSize)); }
void onDraw(SkCanvas* canvas) override { static const char kText[] = "SKIA"; static const int kTextLen = SK_ARRAY_COUNT(kText) - 1; static const int kPointSize = 55; SkTDArray<LabeledMatrix> matrices; matrices.append()->fMatrix.reset(); matrices.top().fLabel = "Identity"; matrices.append()->fMatrix.setScale(1.2f, 0.8f); matrices.top().fLabel = "Scale"; matrices.append()->fMatrix.setRotate(10.f); matrices.top().fLabel = "Rotate"; matrices.append()->fMatrix.reset(); matrices.top().fMatrix.setPerspX(-0.0015f); matrices.top().fMatrix.setPerspY(+0.0015f); matrices.top().fLabel = "Persp"; SkTDArray<LabeledMatrix> localMatrices; localMatrices.append()->fMatrix.reset(); localMatrices.top().fLabel = "Identity"; localMatrices.append()->fMatrix.setScale(2.5f, 0.2f); localMatrices.top().fLabel = "Scale"; localMatrices.append()->fMatrix.setRotate(45.f); localMatrices.top().fLabel = "Rotate"; localMatrices.append()->fMatrix.reset(); localMatrices.top().fMatrix.setPerspX(-0.007f); localMatrices.top().fMatrix.setPerspY(+0.008f); localMatrices.top().fLabel = "Persp"; static SkBitmap bmp; if (bmp.isNull()) { makebm(&bmp, kPointSize / 2, kPointSize / 2); } SkPaint fillPaint; fillPaint.setAntiAlias(true); sk_tool_utils::set_portable_typeface_always(&fillPaint); fillPaint.setTextSize(SkIntToScalar(kPointSize)); fillPaint.setFilterQuality(kLow_SkFilterQuality); SkPaint outlinePaint; outlinePaint.setAntiAlias(true); sk_tool_utils::set_portable_typeface_always(&outlinePaint); outlinePaint.setTextSize(SkIntToScalar(kPointSize)); outlinePaint.setStyle(SkPaint::kStroke_Style); outlinePaint.setStrokeWidth(0.f); SkScalar w = fillPaint.measureText(kText, kTextLen); static SkScalar kPadY = 0.5f * kPointSize; static SkScalar kPadX = 1.5f * kPointSize; SkPaint strokePaint(fillPaint); strokePaint.setStyle(SkPaint::kStroke_Style); strokePaint.setStrokeWidth(kPointSize * 0.1f); SkPaint labelPaint; labelPaint.setColor(0xff000000); labelPaint.setAntiAlias(true); sk_tool_utils::set_portable_typeface_always(&labelPaint); labelPaint.setTextSize(12.f); canvas->translate(15.f, 15.f); canvas->drawBitmap(bmp, 0, 0); canvas->translate(0, bmp.height() + labelPaint.getTextSize() + 15.f); static const char kLabelLabel[] = "localM / canvasM"; canvas->drawText(kLabelLabel, strlen(kLabelLabel), 0, 0, labelPaint); canvas->translate(0, 15.f); canvas->save(); SkScalar maxLabelW = 0; canvas->translate(0, kPadY / 2 + kPointSize); for (int lm = 0; lm < localMatrices.count(); ++lm) { canvas->drawText(matrices[lm].fLabel, strlen(matrices[lm].fLabel), 0, labelPaint.getTextSize() - 1, labelPaint); SkScalar labelW = labelPaint.measureText(matrices[lm].fLabel, strlen(matrices[lm].fLabel)); maxLabelW = SkMaxScalar(maxLabelW, labelW); canvas->translate(0.f, 2 * kPointSize + 2.5f * kPadY); } canvas->restore(); canvas->translate(maxLabelW + kPadX / 2.f, 0.f); for (int s = 0; s < 2; ++s) { SkPaint& paint = s ? strokePaint : fillPaint; SkScalar columnH = 0; for (int m = 0; m < matrices.count(); ++m) { columnH = 0; canvas->save(); canvas->drawText(matrices[m].fLabel, strlen(matrices[m].fLabel), 0, labelPaint.getTextSize() - 1, labelPaint); canvas->translate(0, kPadY / 2 + kPointSize); columnH += kPadY / 2 + kPointSize; for (int lm = 0; lm < localMatrices.count(); ++lm) { paint.setShader( SkShader::CreateBitmapShader(bmp, SkShader::kMirror_TileMode, SkShader::kRepeat_TileMode, &localMatrices[lm].fMatrix))->unref(); canvas->save(); canvas->concat(matrices[m].fMatrix); canvas->drawText(kText, kTextLen, 0, 0, paint); canvas->drawText(kText, kTextLen, 0, 0, outlinePaint); canvas->restore(); SkPath path; path.arcTo(SkRect::MakeXYWH(-0.1f * w, 0.f, 1.2f * w, 2.f * kPointSize), 225.f, 359.f, false); path.close(); canvas->translate(0.f, kPointSize + kPadY); columnH += kPointSize + kPadY; canvas->save(); canvas->concat(matrices[m].fMatrix); canvas->drawTextOnPath(kText, kTextLen, path, NULL, paint); canvas->drawTextOnPath(kText, kTextLen, path, NULL, outlinePaint); canvas->restore(); SkPaint stroke; stroke.setStyle(SkPaint::kStroke_Style); canvas->translate(0.f, kPointSize + kPadY); columnH += kPointSize + kPadY; } canvas->restore(); canvas->translate(w + kPadX, 0.f); } if (0 == s) { canvas->drawLine(0.f, -kPadY, 0.f, columnH + kPadY, outlinePaint); canvas->translate(kPadX / 2, 0.f); static const char kFillLabel[] = "Filled"; static const char kStrokeLabel[] = "Stroked"; SkScalar y = columnH + kPadY / 2; SkScalar fillX = -outlinePaint.measureText(kFillLabel, strlen(kFillLabel)) - kPadX; SkScalar strokeX = kPadX; canvas->drawText(kFillLabel, strlen(kFillLabel), fillX, y, labelPaint); canvas->drawText(kStrokeLabel, strlen(kStrokeLabel), strokeX, y, labelPaint); } } }
void onDraw(SkCanvas* canvas) override { float scale = 32.f/kPOTSize; int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; const char* gColorTypeNames[] = { "8888" , "565", "4444" }; constexpr SkFilterQuality gFilterQualitys[] = { kNone_SkFilterQuality, kLow_SkFilterQuality, kMedium_SkFilterQuality, kHigh_SkFilterQuality }; const char* gFilterNames[] = { "None", "Low", "Medium", "High" }; constexpr SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; const char* gModeNames[] = { "C", "R", "M" }; SkScalar y = SkIntToScalar(24); SkScalar x = SkIntToScalar(10)/scale; for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { SkPaint p; SkString str; p.setAntiAlias(true); sk_tool_utils::set_portable_typeface(&p); str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); p.setTextAlign(SkPaint::kCenter_Align); canvas->drawText(str.c_str(), str.size(), scale*(x + r.width()/2), y, p); x += r.width() * 4 / 3; } } y = SkIntToScalar(40) / scale; for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { for (size_t j = 0; j < SK_ARRAY_COUNT(gFilterQualitys); j++) { x = SkIntToScalar(10)/scale; for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { SkPaint paint; #if 1 // Temporary change to regen bitmap before each draw. This may help tracking down an issue // on SGX where resizing NPOT textures to POT textures exhibits a driver bug. if (!fPowerOfTwoSize) { makebm(&fTexture[i], gColorTypes[i], size, size); } #endif setup(&paint, fTexture[i], gFilterQualitys[j], gModes[kx], gModes[ky]); paint.setDither(true); canvas->save(); canvas->scale(scale,scale); canvas->translate(x, y); canvas->drawRect(r, paint); canvas->restore(); x += r.width() * 4 / 3; } } { SkPaint p; SkString str; p.setAntiAlias(true); sk_tool_utils::set_portable_typeface(&p); str.printf("%s, %s", gColorTypeNames[i], gFilterNames[j]); canvas->drawText(str.c_str(), str.size(), scale*x, scale*(y + r.height() * 2 / 3), p); } y += r.height() * 4 / 3; } } }
void onOnceBeforeDraw() override { int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { makebm(&fTexture[i], gColorTypes[i], size, size); } }
static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { SkBitmap bm; makebm(&bm, kN32_SkColorType, gWidth, gHeight); return SkShader::MakeBitmapShader(bm, tx, ty); }
void onDraw(SkCanvas* canvas) override { const char text[] = "Shaded Text"; const int textLen = SK_ARRAY_COUNT(text) - 1; const int pointSize = 36; const int w = pointSize * textLen; const int h = pointSize; SkPoint pts[2] = { { 0, 0 }, { SkIntToScalar(w), SkIntToScalar(h) } }; SkScalar textBase = SkIntToScalar(h/2); SkShader::TileMode tileModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; static const int gradCount = SK_ARRAY_COUNT(gGradData) * SK_ARRAY_COUNT(gGradMakers); static const int bmpCount = SK_ARRAY_COUNT(tileModes) * SK_ARRAY_COUNT(tileModes); sk_sp<SkShader> shaders[gradCount + bmpCount]; int shdIdx = 0; for (size_t d = 0; d < SK_ARRAY_COUNT(gGradData); ++d) { for (size_t m = 0; m < SK_ARRAY_COUNT(gGradMakers); ++m) { shaders[shdIdx++] = gGradMakers[m](pts, gGradData[d], SkShader::kClamp_TileMode); } } SkBitmap bm; makebm(&bm, w/16, h/4); for (size_t tx = 0; tx < SK_ARRAY_COUNT(tileModes); ++tx) { for (size_t ty = 0; ty < SK_ARRAY_COUNT(tileModes); ++ty) { shaders[shdIdx++] = SkShader::MakeBitmapShader(bm, tileModes[tx], tileModes[ty]); } } SkPaint paint; paint.setDither(true); paint.setAntiAlias(true); sk_tool_utils::set_portable_typeface(&paint); paint.setTextSize(SkIntToScalar(pointSize)); canvas->save(); canvas->translate(SkIntToScalar(20), SkIntToScalar(10)); SkPath path; path.arcTo(SkRect::MakeXYWH(SkIntToScalar(-40), SkIntToScalar(15), SkIntToScalar(300), SkIntToScalar(90)), SkIntToScalar(225), SkIntToScalar(90), false); path.close(); static const int testsPerCol = 8; static const int rowHeight = 60; static const int colWidth = 300; canvas->save(); for (int s = 0; s < static_cast<int>(SK_ARRAY_COUNT(shaders)); s++) { canvas->save(); int i = 2*s; canvas->translate(SkIntToScalar((i / testsPerCol) * colWidth), SkIntToScalar((i % testsPerCol) * rowHeight)); paint.setShader(shaders[s]); canvas->drawText(text, textLen, 0, textBase, paint); canvas->restore(); canvas->save(); ++i; canvas->translate(SkIntToScalar((i / testsPerCol) * colWidth), SkIntToScalar((i % testsPerCol) * rowHeight)); canvas->drawTextOnPath(text, textLen, path, nullptr, paint); canvas->restore(); } canvas->restore(); }
void onDraw(SkCanvas* canvas) override { int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; static const char* gConfigNames[] = { "8888", "565", "4444" }; static const bool gFilters[] = { false, true }; static const char* gFilterNames[] = { "point", "bilinear" }; static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; static const char* gModeNames[] = { "C", "R", "M" }; SkScalar y = SkIntToScalar(24); SkScalar x = SkIntToScalar(10); for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { SkPaint p; SkString str; p.setAntiAlias(true); sk_tool_utils::set_portable_typeface_always(&p); p.setDither(true); str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); p.setTextAlign(SkPaint::kCenter_Align); canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p); x += r.width() * 4 / 3; } } y += SkIntToScalar(16); for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { for (size_t j = 0; j < SK_ARRAY_COUNT(gFilters); j++) { x = SkIntToScalar(10); for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { SkPaint paint; #if 1 // Temporary change to regen bitmap before each draw. This may help tracking down an issue // on SGX where resizing NPOT textures to POT textures exhibits a driver bug. if (!fPowerOfTwoSize) { makebm(&fTexture[i], gColorTypes[i], size, size); } #endif setup(&paint, fTexture[i], gFilters[j], gModes[kx], gModes[ky]); paint.setDither(true); canvas->save(); canvas->translate(x, y); canvas->drawRect(r, paint); canvas->restore(); x += r.width() * 4 / 3; } } { SkPaint p; SkString str; p.setAntiAlias(true); sk_tool_utils::set_portable_typeface_always(&p); str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); canvas->drawText(str.c_str(), str.size(), x, y + r.height() * 2 / 3, p); } y += r.height() * 4 / 3; } } }
void setupImage(SkCanvas* canvas) { fImage = makebm(canvas, &fLargeBitmap, gBmpSize, gBmpSize); }
virtual void onDraw(SkCanvas* canvas) { static const int kBmpSize = 2048; if (fLargeBitmap.isNull()) { makebm(&fLargeBitmap, kBmpSize, kBmpSize); } SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)}; static const int kMaxSrcRectSize = 1 << (SkNextLog2(kBmpSize) + 2); static const int kPadX = 30; static const int kPadY = 40; SkPaint paint; paint.setAlpha(0x20); canvas->drawBitmapRect(fLargeBitmap, NULL, SkRect::MakeWH(gSize * SK_Scalar1, gSize * SK_Scalar1), &paint); canvas->translate(SK_Scalar1 * kPadX / 2, SK_Scalar1 * kPadY / 2); SkPaint blackPaint; SkScalar titleHeight = SK_Scalar1 * 24; blackPaint.setColor(SK_ColorBLACK); blackPaint.setTextSize(titleHeight); blackPaint.setAntiAlias(true); SkString title; title.printf("Bitmap size: %d x %d", kBmpSize, kBmpSize); canvas->drawText(title.c_str(), title.size(), 0, titleHeight, blackPaint); canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight); int rowCount = 0; canvas->save(); for (int w = 1; w <= kMaxSrcRectSize; w *= 4) { for (int h = 1; h <= kMaxSrcRectSize; h *= 4) { SkIRect srcRect = SkIRect::MakeXYWH((kBmpSize - w) / 2, (kBmpSize - h) / 2, w, h); canvas->drawBitmapRect(fLargeBitmap, &srcRect, dstRect); SkString label; label.appendf("%d x %d", w, h); blackPaint.setAntiAlias(true); blackPaint.setStyle(SkPaint::kFill_Style); blackPaint.setTextSize(SK_Scalar1 * 10); SkScalar baseline = dstRect.height() + blackPaint.getTextSize() + SK_Scalar1 * 3; canvas->drawText(label.c_str(), label.size(), 0, baseline, blackPaint); blackPaint.setStyle(SkPaint::kStroke_Style); blackPaint.setStrokeWidth(SK_Scalar1); blackPaint.setAntiAlias(false); canvas->drawRect(dstRect, blackPaint); canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0); ++rowCount; if ((dstRect.width() + kPadX) * rowCount > gSize) { canvas->restore(); canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY); canvas->save(); rowCount = 0; } } } { // test the following code path: // SkGpuDevice::drawPath() -> SkGpuDevice::drawWithMaskFilter() SkIRect srcRect; SkPaint paint; SkBitmap bm; bm = make_chessbm(5, 5); paint.setFilterLevel(SkPaint::kLow_FilterLevel); srcRect.setXYWH(1, 1, 3, 3); SkMaskFilter* mf = SkBlurMaskFilter::Create( kNormal_SkBlurStyle, SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), SkBlurMaskFilter::kHighQuality_BlurFlag | SkBlurMaskFilter::kIgnoreTransform_BlurFlag); paint.setMaskFilter(mf)->unref(); canvas->drawBitmapRect(bm, &srcRect, dstRect, &paint); } }