From c695e954174e4a789631ea4d6e171bd7118ebc67 Mon Sep 17 00:00:00 2001 From: reed Date: Fri, 16 Jan 2015 05:01:16 -0800 Subject: [PATCH] add gm to show miplevels (patchset #2 id:20001 of https://codereview.chromium.org/849173004/)" fixed memory leak This reverts commit 04f07fcbfddbe8ca97d29053554a01c66d44ece2. BUG=skia: TBR= Review URL: https://codereview.chromium.org/854163002 --- gm/downsamplebitmap.cpp | 83 ++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 13 deletions(-) diff --git a/gm/downsamplebitmap.cpp b/gm/downsamplebitmap.cpp index ce10b47a84..600d2caee2 100644 --- a/gm/downsamplebitmap.cpp +++ b/gm/downsamplebitmap.cpp @@ -14,6 +14,22 @@ #include "SkStream.h" #include "SkPaint.h" +static void make_checker(SkBitmap* bm, int size, int numChecks) { + bm->allocN32Pixels(size, size); + for (int y = 0; y < size; ++y) { + for (int x = 0; x < size; ++x) { + SkPMColor* s = bm->getAddr32(x, y); + int cx = (x * numChecks) / size; + int cy = (y * numChecks) / size; + if ((cx+cy)%2) { + *s = 0xFFFFFFFF; + } else { + *s = 0xFF000000; + } + } + } +} + static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style style) { sk_tool_utils::set_portable_typeface(paint, name, style); } @@ -139,19 +155,7 @@ class DownsampleBitmapCheckerboardGM: public DownsampleBitmapGM { int fNumChecks; void make_bitmap() SK_OVERRIDE { - fBM.allocN32Pixels(fSize, fSize); - for (int y = 0; y < fSize; ++y) { - for (int x = 0; x < fSize; ++x) { - SkPMColor* s = fBM.getAddr32(x, y); - int cx = (x * fNumChecks) / fSize; - int cy = (y * fNumChecks) / fSize; - if ((cx+cy)%2) { - *s = 0xFFFFFFFF; - } else { - *s = 0xFF000000; - } - } - } + make_checker(&fBM, fSize, fNumChecks); } private: typedef DownsampleBitmapGM INHERITED; @@ -190,6 +194,59 @@ class DownsampleBitmapImageGM: public DownsampleBitmapGM { typedef DownsampleBitmapGM INHERITED; }; +#include "SkMipMap.h" +class ShowMipLevels : public skiagm::GM { +public: + SkBitmap fBM; + + ShowMipLevels() { + this->setBGColor(0xFFDDDDDD); + make_checker(&fBM, 512, 256); + } + +protected: +#if 0 + uint32_t onGetFlags() const SK_OVERRIDE { + return kSkipTiled_Flag; + } +#endif + + SkString onShortName() SK_OVERRIDE { + return SkString("showmiplevels"); + } + + SkISize onISize() SK_OVERRIDE { + return SkISize::Make(fBM.width() + 8, 2 * fBM.height() + 80); + } + + void onDraw(SkCanvas* canvas) SK_OVERRIDE { + SkScalar x = 4; + SkScalar y = 4; + canvas->drawBitmap(fBM, x, y, NULL); + y += fBM.height() + 4; + + SkAutoTUnref mm(SkMipMap::Build(fBM, NULL)); + + SkMipMap::Level level; + SkScalar scale = 0.5f; + while (mm->extractLevel(scale, &level)) { + SkImageInfo info = SkImageInfo::MakeN32Premul(level.fWidth, level.fHeight); + SkBitmap bm; + bm.installPixels(info, level.fPixels, level.fRowBytes); + canvas->drawBitmap(bm, x, y, NULL); + y += bm.height() + 4; + scale /= 2; + if (info.width() == 1 || info.height() == 1) { + break; + } + } + } + +private: + typedef skiagm::GM INHERITED; +}; +DEF_GM( return new ShowMipLevels; ) + ////////////////////////////////////////////////////////////////////////////// DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kHigh_FilterLevel); )