Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: gm/composeshader.cpp

Issue 2249703002: add gm that exercises compose shader allocations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/core/SkSmallAllocator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/composeshader.cpp
diff --git a/gm/composeshader.cpp b/gm/composeshader.cpp
index efcfe79afe5abd97dfeae770507e54444aa40972..c029c9855959f0d2949c03212a76a7964d2aceab 100644
--- a/gm/composeshader.cpp
+++ b/gm/composeshader.cpp
@@ -221,6 +221,44 @@ private:
typedef GM INHERITED;
};
+DEF_SIMPLE_GM(composeshader_bitmap2, canvas, 200, 200) {
+ int width = 255;
+ int height = 255;
+ SkTDArray<uint8_t> dst8Storage;
+ dst8Storage.setCount(width * height);
+ SkTDArray<uint32_t> dst32Storage;
+ dst32Storage.setCount(width * height * sizeof(int32_t));
+ for (int y = 0; y < height; ++y) {
+ for (int x = 0; x < width; ++x) {
+ dst8Storage[y * width + x] = (y + x) / 2;
+ dst32Storage[y * width + x] = SkPackARGB32(0xFF, x, y, 0);
+ }
+ }
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(SK_ColorBLUE);
+ SkRect r = {0, 0, SkIntToScalar(width), SkIntToScalar(height)};
+ canvas->drawRect(r, paint);
+ SkBitmap skBitmap, skMask;
+ SkImageInfo imageInfo = SkImageInfo::Make(width, height,
+ SkColorType::kN32_SkColorType, kPremul_SkAlphaType);
+ skBitmap.installPixels(imageInfo, dst32Storage.begin(), width * sizeof(int32_t),
+ nullptr, nullptr, nullptr);
+ imageInfo = SkImageInfo::Make(width, height,
+ SkColorType::kAlpha_8_SkColorType, kPremul_SkAlphaType);
+ skMask.installPixels(imageInfo, dst8Storage.begin(), width, nullptr, nullptr, nullptr);
+ sk_sp<SkImage> skSrc = SkImage::MakeFromBitmap(skBitmap);
+ sk_sp<SkShader> skSrcShader =
+ skSrc->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
+ sk_sp<SkImage> skMaskImage = SkImage::MakeFromBitmap(skMask);
+ sk_sp<SkShader> skMaskShader = skMaskImage->makeShader(
+ SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
+ sk_sp<SkXfermode> dstInMode = SkXfermode::Make(SkXfermode::kSrcIn_Mode);
+ paint.setShader(
+ SkShader::MakeComposeShader(skMaskShader, skSrcShader, dstInMode));
+ canvas->drawRect(r, paint);
+}
+
//////////////////////////////////////////////////////////////////////////////
DEF_GM( return new ComposeShaderGM; )
« no previous file with comments | « no previous file | src/core/SkSmallAllocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698