aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2016-08-15 12:03:33 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-15 12:03:33 -0700
commitc2ad65e94de8c7c178699a2cb211d3a768bfdb90 (patch)
tree021f3d4dcab6661b8b1b5a44e1abda3923f59d6a
parent6059dc32fe36358175cb81541c91e74a2a7e771a (diff)
add gm that exercises compose shader allocations
This gm triggers the assert in SkSmallAllocator.h commented out by this CL. PDFium constructs shaders that resemble the GM. R=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2249703002 Review-Url: https://codereview.chromium.org/2249703002
-rw-r--r--gm/composeshader.cpp38
-rw-r--r--src/core/SkSmallAllocator.h10
2 files changed, 44 insertions, 4 deletions
diff --git a/gm/composeshader.cpp b/gm/composeshader.cpp
index efcfe79afe..c029c98559 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; )
diff --git a/src/core/SkSmallAllocator.h b/src/core/SkSmallAllocator.h
index 22baa898ea..9095fa57fc 100644
--- a/src/core/SkSmallAllocator.h
+++ b/src/core/SkSmallAllocator.h
@@ -80,10 +80,12 @@ public:
const size_t storageRemaining = sizeof(fStorage) - fStorageUsed;
Rec* rec = &fRecs[fNumObjects];
if (storageRequired > storageRemaining) {
- // Allocate on the heap. Ideally we want to avoid this situation,
- // but we're not sure we can catch all callers, so handle it but
- // assert false in debug mode.
- SkASSERT(false);
+ // Allocate on the heap. Ideally we want to avoid this situation.
+
+ // With the gm composeshader_bitmap2, storage required is 4476
+ // and storage remaining is 3392. Increasing the base storage
+ // causes google 3 tests to fail.
+
rec->fStorageSize = 0;
rec->fHeapStorage = sk_malloc_throw(storageRequired);
rec->fObj = static_cast<void*>(rec->fHeapStorage);